Browse Source

draft url parser lib

CPP-GTK4
yggverse 3 months ago
parent
commit
83def8fb85
  1. 3
      Makefile
  2. 1
      po/POTFILES.in
  3. 28
      src/lib/url.cpp
  4. 27
      src/lib/url.hpp

3
Makefile

@ -24,7 +24,8 @@ SRCS = src/main.cpp\
src/app/browser/main/tab/data/navbar/update.cpp\ src/app/browser/main/tab/data/navbar/update.cpp\
src/app/browser/main/tab/label.cpp\ src/app/browser/main/tab/label.cpp\
src/lib/database.cpp\ src/lib/database.cpp\
src/lib/database/session.cpp src/lib/database/session.cpp\
src/lib/url.cpp
OBJS = $(SRCS:.cpp=.o) OBJS = $(SRCS:.cpp=.o)

1
po/POTFILES.in

@ -17,4 +17,5 @@ src/app/browser/main/tab/data/navbar/update.cpp
src/app/browser/main/tab/label.cpp src/app/browser/main/tab/label.cpp
src/lib/database.cpp src/lib/database.cpp
src/lib/database/session.cpp src/lib/database/session.cpp
src/lib/url.cpp
src/main.cpp src/main.cpp

28
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;

27
src/lib/url.hpp

@ -0,0 +1,27 @@
#ifndef LIB_URL_HPP
#define LIB_URL_HPP
#include <regex>
#include <string>
namespace lib
{
class Url
{
public:
std::string scheme,
host,
port,
path,
query;
Url(
std::string subject
);
~Url();
};
}
#endif // LIB_URL_HPP
Loading…
Cancel
Save