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 "architecture.hpp"
8#include <string_view>
9#include <string>
10#include <vector>
11#include <functional>
12
13namespace hi::inline v1 {
14
15constexpr char native_path_seperator = (operating_system::current == operating_system::windows) ? '\\' : '/';
16
17constexpr bool is_urlchar_alpha(char c)
18{
19 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
20}
21
22constexpr bool is_urlchar_digit(char c)
23{
24 return (c >= '0' && c <= '9');
25}
26
27constexpr bool is_urlchar_gen_delims(char c)
28{
29 return c == ':' || c == '/' || c == '?' || c == '#' || c == '[' || c == ']' || c == '@';
30}
31
32constexpr bool is_urlchar_sub_delims(char c)
33{
34 return c == '!' || c == '$' || c == '&' || c == '\'' || c == '(' || c == ')' || c == '*' || c == '+' || c == ',' ||
35 c == ';' || c == '=';
36}
37
38constexpr bool is_urlchar_unreserved(char c)
39{
40 return is_urlchar_alpha(c) || is_urlchar_digit(c) || c == '-' || c == '.' || c == '_' || c == '~';
41}
42
43constexpr bool is_urlchar_reserved(char c)
44{
45 return is_urlchar_gen_delims(c) || is_urlchar_sub_delims(c);
46}
47
48constexpr bool is_urlchar_pchar(char c)
49{
50 return is_urlchar_unreserved(c) || is_urlchar_sub_delims(c) || c == ':' || c == '@';
51}
52
53constexpr bool is_urlchar_pchar_forward(char c)
54{
55 return is_urlchar_pchar(c) || c == '/';
56}
57
58constexpr bool is_urlchar_pchar_backward(char c)
59{
60 return is_urlchar_pchar(c) || c == '\\';
61}
62
69std::string url_encode_part(std::string_view input, std::function<bool(char)> unreserved_char_check) noexcept;
70
71inline std::string url_encode(std::string_view input) noexcept
72{
73 return url_encode_part(input, is_urlchar_unreserved);
74}
75
85std::string url_decode(std::string_view input, bool plus_to_space = false) noexcept;
86
90struct url_parts {
91 std::string_view scheme;
92 std::string_view authority;
93 std::string_view drive;
94 bool absolute;
96 std::string_view query;
97 std::string_view fragment;
98};
99
105url_parts parse_url(std::string_view url) noexcept;
106
119url_parts parse_path(std::string_view path, std::string &encodedPath) noexcept;
120
121std::string generate_url(url_parts const &parts) noexcept;
122
123std::string generate_path(url_parts const &parts, char sep = '/') noexcept;
124
125std::string generate_native_path(url_parts const &parts) noexcept;
126
129void normalize_url_path(url_parts &parts) noexcept;
130
133std::string normalize_url(std::string_view url) noexcept;
134
138url_parts concatenate_url_path(url_parts lhs, url_parts const &rhs) noexcept;
139
143std::string concatenate_url_path(std::string_view lhs, std::string_view rhs) noexcept;
144
147std::string concatenate_url_filename(url_parts lhs, std::string_view rhs) noexcept;
148
151std::string concatenate_url_filename(std::string_view lhs, std::string_view rhs) noexcept;
152
155std::string filename_from_path(std::string_view path) noexcept;
156
157} // namespace hi::inline v1
Functions and macros for handling architectural difference between compilers, CPUs and operating syst...
STL namespace.
Definition url_parser.hpp:90