HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
url_parser.hpp
1// Copyright 2019 Pokitec
2// All rights reserved.
3
4#pragma once
5
6#include "TTauri/Foundation/os_detect.hpp"
7#include <string_view>
8#include <string>
9#include <vector>
10#include <functional>
11
12namespace tt {
13
14constexpr char native_path_seperator = (OperatingSystem::current == OperatingSystem::Windows) ? '\\' : '/';
15
16constexpr bool is_urlchar_alpha(char c) {
17 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
18}
19
20constexpr bool is_urlchar_digit(char c) {
21 return (c >= '0' && c <= '9');
22}
23
24constexpr bool is_urlchar_gen_delims(char c) {
25 return c == ':' || c == '/' || c == '?' || c == '#' || c == '[' || c == ']' || c == '@';
26}
27
28constexpr bool is_urlchar_sub_delims(char c) {
29 return
30 c == '!' || c == '$' || c == '&' || c == '\'' || c == '(' || c == ')' ||
31 c == '*' || c == '+' || c == ',' || c == ';' || c == '=';
32}
33
34constexpr bool is_urlchar_unreserved(char c) {
35 return is_urlchar_alpha(c) || is_urlchar_digit(c) || c == '-' || c == '.' || c == '_' || c == '~';
36}
37
38constexpr bool is_urlchar_reserved(char c) {
39 return is_urlchar_gen_delims(c) || is_urlchar_sub_delims(c);
40}
41
42constexpr bool is_urlchar_pchar(char c) {
43 return is_urlchar_unreserved(c) || is_urlchar_sub_delims(c) || c == ':' || c == '@';
44}
45
46constexpr bool is_urlchar_pchar_forward(char c) {
47 return is_urlchar_pchar(c) || c == '/';
48}
49
50constexpr bool is_urlchar_pchar_backward(char c) {
51 return is_urlchar_pchar(c) || c == '\\';
52}
53
60std::string url_encode_part(std::string_view input, std::function<bool(char)> unreserved_char_check) noexcept;
61
62inline std::string url_encode(std::string_view input) noexcept {
63 return url_encode_part(input, is_urlchar_unreserved);
64}
65
66
76std::string url_decode(std::string_view input, bool plus_to_space=false) noexcept;
77
81struct url_parts {
82 std::string_view scheme;
83 std::string_view authority;
84 std::string_view drive;
85 bool absolute;
87 std::string_view query;
88 std::string_view fragment;
89};
90
96url_parts parse_url(std::string_view url) noexcept;
97
110url_parts parse_path(std::string_view path, std::string &encodedPath) noexcept;
111
112std::string generate_url(url_parts const &parts) noexcept;
113
114std::string generate_path(url_parts const &parts, char sep='/') noexcept;
115
116std::string generate_native_path(url_parts const &parts) noexcept;
117
120void normalize_url_parts(url_parts &parts) noexcept;
121
124std::string normalize_url(std::string_view url) noexcept;
125
128url_parts concatenate_url_parts(url_parts const &lhs, url_parts const &rhs) noexcept;
129
132std::string concatenate_url(std::string_view const lhs, std::string_view const rhs) noexcept;
133
136std::string filename_from_path(std::string_view path) noexcept;
137
138}
STL namespace.
Definition url_parser.hpp:81