From 83def8fb85354689cadcd16104039e64bcec3973 Mon Sep 17 00:00:00 2001 From: yggverse Date: Wed, 14 Aug 2024 20:47:29 +0300 Subject: [PATCH] draft url parser lib --- Makefile | 3 ++- po/POTFILES.in | 1 + src/lib/url.cpp | 28 ++++++++++++++++++++++++++++ src/lib/url.hpp | 27 +++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/lib/url.cpp create mode 100644 src/lib/url.hpp diff --git a/Makefile b/Makefile index ca9eafb..86d1c54 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,8 @@ SRCS = src/main.cpp\ src/app/browser/main/tab/data/navbar/update.cpp\ src/app/browser/main/tab/label.cpp\ src/lib/database.cpp\ - src/lib/database/session.cpp + src/lib/database/session.cpp\ + src/lib/url.cpp OBJS = $(SRCS:.cpp=.o) diff --git a/po/POTFILES.in b/po/POTFILES.in index 39bfdfc..1f5e1eb 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -17,4 +17,5 @@ src/app/browser/main/tab/data/navbar/update.cpp src/app/browser/main/tab/label.cpp src/lib/database.cpp src/lib/database/session.cpp +src/lib/url.cpp src/main.cpp diff --git a/src/lib/url.cpp b/src/lib/url.cpp new file mode 100644 index 0000000..fd50ebf --- /dev/null +++ b/src/lib/url.cpp @@ -0,0 +1,28 @@ +#include "url.hpp" + +using namespace lib; +using namespace std; + +Url::Url( + string subject +) { + smatch results; + + static const regex pattern( // @TODO user:password@#fragment? + R"regex(^(\w+)://([^:\/]+):?(\d+)?\/?([^\?]+)?\??(.*)?$)regex" + ); + + regex_search( + subject, + results, + pattern + ); + + scheme = results[1]; + host = results[2]; + port = results[3]; + path = results[4]; + query = results[5]; +} + +Url::~Url() = default; \ No newline at end of file diff --git a/src/lib/url.hpp b/src/lib/url.hpp new file mode 100644 index 0000000..d775610 --- /dev/null +++ b/src/lib/url.hpp @@ -0,0 +1,27 @@ +#ifndef LIB_URL_HPP +#define LIB_URL_HPP + +#include +#include + +namespace lib +{ + class Url + { + public: + + std::string scheme, + host, + port, + path, + query; + + Url( + std::string subject + ); + + ~Url(); + }; +} + +#endif // LIB_URL_HPP \ No newline at end of file