diff --git a/src/app/browser/main/tab/page.cpp b/src/app/browser/main/tab/page.cpp index a4a57eca..ac5108e1 100644 --- a/src/app/browser/main/tab/page.cpp +++ b/src/app/browser/main/tab/page.cpp @@ -88,7 +88,7 @@ void Page::update() ); // Request - const std::string request = navbar->get_request() + "\r\n"; + const Glib::ustring request = navbar->get_request() + "\r\n"; socket_connection->get_output_stream()->write_async( request.data(), @@ -117,15 +117,13 @@ void Page::update() // Scheme not found but host provided, redirect to gemini:// else if (!navbar->get_request_host().empty()) { - std::string request = "gemini://"; + Glib::ustring request = "gemini://"; request += navbar->get_request_host(); // @TODO validate if (!navbar->get_request_port().empty()) { - request += std::stoi( - navbar->get_request_port() - ); + request += navbar->get_request_port(); } request += navbar->get_request_path(); diff --git a/src/app/browser/main/tab/page.hpp b/src/app/browser/main/tab/page.hpp index 538f2c20..206abb87 100644 --- a/src/app/browser/main/tab/page.hpp +++ b/src/app/browser/main/tab/page.hpp @@ -8,10 +8,9 @@ #include #include #include +#include #include -#include - namespace app::browser::main::tab { namespace page diff --git a/src/app/browser/main/tab/page/content.cpp b/src/app/browser/main/tab/page/content.cpp index bccdacef..a1e4311e 100644 --- a/src/app/browser/main/tab/page/content.cpp +++ b/src/app/browser/main/tab/page/content.cpp @@ -1,7 +1,6 @@ #include "content.hpp" using namespace app::browser::main::tab::page; -using namespace std; Content::Content() { @@ -17,7 +16,7 @@ Content::Content() Content::~Content() = default; void Content::set( - const string & buffer + const Glib::ustring & buffer ) { // @TODO } diff --git a/src/app/browser/main/tab/page/content.hpp b/src/app/browser/main/tab/page/content.hpp index 14067f30..0df029ce 100644 --- a/src/app/browser/main/tab/page/content.hpp +++ b/src/app/browser/main/tab/page/content.hpp @@ -2,8 +2,7 @@ #define APP_BROWSER_MAIN_TAB_PAGE_CONTENT_HPP #include - -#include +#include namespace app::browser::main::tab::page { @@ -16,7 +15,7 @@ namespace app::browser::main::tab::page ~Content(); void set( - const std::string & buffer + const Glib::ustring & buffer ); }; } diff --git a/src/app/browser/main/tab/page/navbar.cpp b/src/app/browser/main/tab/page/navbar.cpp index b8c95b0a..f077e73e 100644 --- a/src/app/browser/main/tab/page/navbar.cpp +++ b/src/app/browser/main/tab/page/navbar.cpp @@ -90,7 +90,7 @@ void Navbar::refresh() { // Toggle base button sensibility base->set_sensitive( - !empty(request->get_host()) && !empty(request->get_path()) + !request->get_host().empty() && !request->get_path().empty() ); // Toggle update button sensibility @@ -101,7 +101,7 @@ void Navbar::refresh() // Setters void Navbar::set_request( - const std::string value + const Glib::ustring value ) { request->set_text( value @@ -116,27 +116,27 @@ Glib::ustring Navbar::get_request() return request->get_text(); } -std::string Navbar::get_request_scheme() +Glib::ustring Navbar::get_request_scheme() { return request->get_scheme(); } -std::string Navbar::get_request_host() +Glib::ustring Navbar::get_request_host() { return request->get_host(); } -std::string Navbar::get_request_path() +Glib::ustring Navbar::get_request_path() { return request->get_path(); } -std::string Navbar::get_request_query() +Glib::ustring Navbar::get_request_query() { return request->get_query(); } -std::string Navbar::get_request_port() +Glib::ustring Navbar::get_request_port() { return request->get_port(); } \ No newline at end of file diff --git a/src/app/browser/main/tab/page/navbar.hpp b/src/app/browser/main/tab/page/navbar.hpp index 9b026a90..125df009 100644 --- a/src/app/browser/main/tab/page/navbar.hpp +++ b/src/app/browser/main/tab/page/navbar.hpp @@ -5,7 +5,6 @@ #include #include #include -#include namespace app::browser::main::tab::page { @@ -44,17 +43,17 @@ namespace app::browser::main::tab::page // Setters void set_request( - const std::string value + const Glib::ustring value ); // Getters Glib::ustring get_request(); - std::string get_request_scheme(); - std::string get_request_host(); - std::string get_request_port(); - std::string get_request_path(); - std::string get_request_query(); + Glib::ustring get_request_scheme(); + Glib::ustring get_request_host(); + Glib::ustring get_request_port(); + Glib::ustring get_request_path(); + Glib::ustring get_request_query(); }; } diff --git a/src/app/browser/main/tab/page/navbar/request.cpp b/src/app/browser/main/tab/page/navbar/request.cpp index 4df7bec2..cfdf22e9 100644 --- a/src/app/browser/main/tab/page/navbar/request.cpp +++ b/src/app/browser/main/tab/page/navbar/request.cpp @@ -1,7 +1,6 @@ #include "request.hpp" using namespace app::browser::main::tab::page::navbar; -using namespace std; // Construct Request::Request() @@ -42,27 +41,27 @@ Request::Request() Request::~Request() = default; // Getters -string Request::get_scheme() +Glib::ustring Request::get_scheme() { return scheme; } -string Request::get_host() +Glib::ustring Request::get_host() { return host; } -string Request::get_port() +Glib::ustring Request::get_port() { return port; } -string Request::get_path() +Glib::ustring Request::get_path() { return path; } -string Request::get_query() +Glib::ustring Request::get_query() { return path; } @@ -70,23 +69,30 @@ string Request::get_query() // Private helpers void Request::parse() { - string subject = get_text(); + auto match = Glib::Regex::split_simple( + R"regex(^((\w+)?:\/\/)?([^:\/]+)?(:(\d+)?)?([^\?$]+)?(\?(.*)?)?)regex", + get_text() + ); - smatch results; + scheme = ""; + host = ""; + port = ""; + path = ""; + query = ""; - static const regex pattern( // @TODO user:password@#fragment? - R"regex(^((\w+)?:\/\/)?([^:\/]+)?(:(\d+)?)?([^\?$]+)?(\?(.*)?)?)regex" - ); + int index = 0; - regex_search( - subject, - results, - pattern - ); + for (const Glib::ustring & value : match) + { + switch (index) + { + case 2: scheme = value; break; + case 3: host = value; break; + case 5: port = value; break; + case 6: path = value; break; + case 8: query = value; break; + } - scheme = results[2]; - host = results[3]; - port = results[5]; - path = results[6]; - query = results[8]; + index++; + } } \ No newline at end of file diff --git a/src/app/browser/main/tab/page/navbar/request.hpp b/src/app/browser/main/tab/page/navbar/request.hpp index 43e34af0..cfc1a6fa 100644 --- a/src/app/browser/main/tab/page/navbar/request.hpp +++ b/src/app/browser/main/tab/page/navbar/request.hpp @@ -2,20 +2,19 @@ #define APP_BROWSER_MAIN_TAB_PAGE_NAVBAR_REQUEST_HPP #include +#include +#include #include -#include -#include - namespace app::browser::main::tab::page::navbar { class Request : public Gtk::Entry { - std::string scheme, - host, - port, - path, - query; + Glib::ustring scheme, + host, + port, + path, + query; void parse(); @@ -25,11 +24,11 @@ namespace app::browser::main::tab::page::navbar ~Request(); - std::string get_scheme(); - std::string get_host(); - std::string get_port(); - std::string get_path(); - std::string get_query(); + Glib::ustring get_scheme(); + Glib::ustring get_host(); + Glib::ustring get_port(); + Glib::ustring get_path(); + Glib::ustring get_query(); }; }