replace std constructions with glib

This commit is contained in:
yggverse 2024-08-17 12:45:43 +03:00
parent a064778d68
commit cbf786ce4c
8 changed files with 60 additions and 61 deletions

View File

@ -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();

View File

@ -8,10 +8,9 @@
#include <giomm/socketclient.h>
#include <giomm/socketconnection.h>
#include <glibmm/refptr.h>
#include <glibmm/ustring.h>
#include <gtkmm/box.h>
#include <string>
namespace app::browser::main::tab
{
namespace page

View File

@ -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
}

View File

@ -2,8 +2,7 @@
#define APP_BROWSER_MAIN_TAB_PAGE_CONTENT_HPP
#include <gtkmm/box.h>
#include <string>
#include <glibmm/ustring.h>
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
);
};
}

View File

@ -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();
}

View File

@ -5,7 +5,6 @@
#include <glibmm/refptr.h>
#include <glibmm/ustring.h>
#include <gtkmm/box.h>
#include <string>
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();
};
}

View File

@ -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();
smatch results;
static const regex pattern( // @TODO user:password@#fragment?
R"regex(^((\w+)?:\/\/)?([^:\/]+)?(:(\d+)?)?([^\?$]+)?(\?(.*)?)?)regex"
auto match = Glib::Regex::split_simple(
R"regex(^((\w+)?:\/\/)?([^:\/]+)?(:(\d+)?)?([^\?$]+)?(\?(.*)?)?)regex",
get_text()
);
regex_search(
subject,
results,
pattern
);
scheme = "";
host = "";
port = "";
path = "";
query = "";
scheme = results[2];
host = results[3];
port = results[5];
path = results[6];
query = results[8];
int index = 0;
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;
}
index++;
}
}

View File

@ -2,20 +2,19 @@
#define APP_BROWSER_MAIN_TAB_PAGE_NAVBAR_REQUEST_HPP
#include <glibmm/i18n.h>
#include <glibmm/regex.h>
#include <glibmm/ustring.h>
#include <gtkmm/entry.h>
#include <regex>
#include <string>
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();
};
}