25 lines
576 B
C++
25 lines
576 B
C++
//
|
|
// Created by maxine on 6/23/25.
|
|
//
|
|
|
|
#pragma once
|
|
|
|
#include <regex>
|
|
#include <cstdlib>
|
|
|
|
namespace Desktop::Browser {
|
|
const std::regex URLPattern("((http|https)://)(www.)?[a-zA-Z0-9@:%._\\+~#?&//=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%._\\+~#?&//=]*)");
|
|
|
|
int OpenURL(std::string url) {
|
|
if (url.empty())
|
|
throw std::invalid_argument("No url provided");
|
|
|
|
if(!regex_match(url, URLPattern))
|
|
throw std::invalid_argument("Invalid url");
|
|
|
|
std::string cmd = "xdg-open " + url;
|
|
|
|
return std::system(cmd.c_str());
|
|
}
|
|
}
|