Ada 2.8.0
Fast spec-compliant URL parser
Loading...
Searching...
No Matches
url_components.cpp
Go to the documentation of this file.
1#include "ada.h"
2#include "ada/helpers.h"
4
5#include <numeric>
6#include <string>
7
8namespace ada {
9
10[[nodiscard]] bool url_components::check_offset_consistency() const noexcept {
23 // These conditions can be made more strict.
24 uint32_t index = 0;
25
27 return false;
28 }
29 if (protocol_end < index) {
30 return false;
31 }
32 index = protocol_end;
33
35 return false;
36 }
37 if (username_end < index) {
38 return false;
39 }
40 index = username_end;
41
43 return false;
44 }
45 if (host_start < index) {
46 return false;
47 }
48 index = host_start;
49
51 if (port > 0xffff) {
52 return false;
53 }
54 uint32_t port_length = helpers::fast_digit_count(port) + 1;
55 if (index + port_length < index) {
56 return false;
57 }
58 index += port_length;
59 }
60
62 return false;
63 }
64 if (pathname_start < index) {
65 return false;
66 }
67 index = pathname_start;
68
70 if (search_start < index) {
71 return false;
72 }
73 index = search_start;
74 }
75
77 if (hash_start < index) {
78 return false;
79 }
80 }
81
82 return true;
83}
84
85[[nodiscard]] std::string url_components::to_string() const {
86 std::string answer;
87 auto back = std::back_insert_iterator(answer);
88 answer.append("{\n");
89
90 answer.append("\t\"protocol_end\":\"");
91 helpers::encode_json(std::to_string(protocol_end), back);
92 answer.append("\",\n");
93
94 answer.append("\t\"username_end\":\"");
95 helpers::encode_json(std::to_string(username_end), back);
96 answer.append("\",\n");
97
98 answer.append("\t\"host_start\":\"");
99 helpers::encode_json(std::to_string(host_start), back);
100 answer.append("\",\n");
101
102 answer.append("\t\"host_end\":\"");
103 helpers::encode_json(std::to_string(host_end), back);
104 answer.append("\",\n");
105
106 answer.append("\t\"port\":\"");
107 helpers::encode_json(std::to_string(port), back);
108 answer.append("\",\n");
109
110 answer.append("\t\"pathname_start\":\"");
111 helpers::encode_json(std::to_string(pathname_start), back);
112 answer.append("\",\n");
113
114 answer.append("\t\"search_start\":\"");
115 helpers::encode_json(std::to_string(search_start), back);
116 answer.append("\",\n");
117
118 answer.append("\t\"hash_start\":\"");
119 helpers::encode_json(std::to_string(hash_start), back);
120 answer.append("\",\n");
121
122 answer.append("\n}");
123 return answer;
124}
125
126} // namespace ada
Includes all definitions for Ada.
Definitions for helper functions used within Ada.
Definition ada_idna.h:13
bool check_offset_consistency() const noexcept
std::string to_string() const
static constexpr uint32_t omitted
Declaration for the URL Components.