HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
url_parser.hpp
1// Copyright Take Vos 2019-2020.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "os_detect.hpp"
8#include <string_view>
9#include <string>
10#include <vector>
11#include <functional>
12
13namespace tt {
14
15constexpr char native_path_seperator = (OperatingSystem::current == OperatingSystem::Windows) ? '\\' : '/';
16
17constexpr bool is_urlchar_alpha(char c) {
18 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
19}
20
21constexpr bool is_urlchar_digit(char c) {
22 return (c >= '0' && c <= '9');
23}
24
25constexpr bool is_urlchar_gen_delims(char c) {
26 return c == ':' || c == '/' || c == '?' || c == '#' || c == '[' || c == ']' || c == '@';
27}
28
29constexpr bool is_urlchar_sub_delims(char c) {
30 return
31 c == '!' || c == '$' || c == '&' || c == '\'' || c == '(' || c == ')' ||
32 c == '*' || c == '+' || c == ',' || c == ';' || c == '=';
33}
34
35constexpr bool is_urlchar_unreserved(char c) {
36 return is_urlchar_alpha(c) || is_urlchar_digit(c) || c == '-' || c == '.' || c == '_' || c == '~';
37}
38
39constexpr bool is_urlchar_reserved(char c) {
40 return is_urlchar_gen_delims(c) || is_urlchar_sub_delims(c);
41}
42
43constexpr bool is_urlchar_pchar(char c) {
44 return is_urlchar_unreserved(c) || is_urlchar_sub_delims(c) || c == ':' || c == '@';
45}
46
47constexpr bool is_urlchar_pchar_forward(char c) {
48 return is_urlchar_pchar(c) || c == '/';
49}
50
51constexpr bool is_urlchar_pchar_backward(char c) {
52 return is_urlchar_pchar(c) || c == '\\';
53}
54
61std::string url_encode_part(std::string_view input, std::function<bool(char)> unreserved_char_check) noexcept;
62
63inline std::string url_encode(std::string_view input) noexcept {
64 return url_encode_part(input, is_urlchar_unreserved);
65}
66
67
77std::string url_decode(std::string_view input, bool plus_to_space=false) noexcept;
78
82struct url_parts {
83 std::string_view scheme;
84 std::string_view authority;
85 std::string_view drive;
86 bool absolute;
88 std::string_view query;
89 std::string_view fragment;
90};
91
97url_parts parse_url(std::string_view url) noexcept;
98
111url_parts parse_path(std::string_view path, std::string &encodedPath) noexcept;
112
113std::string generate_url(url_parts const &parts) noexcept;
114
115std::string generate_path(url_parts const &parts, char sep='/') noexcept;
116
117std::string generate_native_path(url_parts const &parts) noexcept;
118
121void normalize_url_path(url_parts &parts) noexcept;
122
125std::string normalize_url(std::string_view url) noexcept;
126
130url_parts concatenate_url_path(url_parts lhs, url_parts const &rhs) noexcept;
131
135std::string concatenate_url_path(std::string_view lhs, std::string_view rhs) noexcept;
136
139std::string concatenate_url_filename(url_parts lhs, std::string_view rhs) noexcept;
140
143std::string concatenate_url_filename(std::string_view lhs, std::string_view rhs) noexcept;
144
147std::string filename_from_path(std::string_view path) noexcept;
148
149}
STL namespace.
Definition url_parser.hpp:82