Ada 3.1.0
Fast spec-compliant URL parser
Loading...
Searching...
No Matches
url_aggregator.h
Go to the documentation of this file.
1
5#ifndef ADA_URL_AGGREGATOR_H
6#define ADA_URL_AGGREGATOR_H
7
8#include <ostream>
9#include <string>
10#include <string_view>
11#include <variant>
12
13#include "ada/common_defs.h"
14#include "ada/url_base.h"
15#include "ada/url_components.h"
16
17namespace ada {
18
19namespace parser {}
20
30 url_aggregator() = default;
31 url_aggregator(const url_aggregator &u) = default;
32 url_aggregator(url_aggregator &&u) noexcept = default;
33 url_aggregator &operator=(url_aggregator &&u) noexcept = default;
35 ~url_aggregator() override = default;
36
37 bool set_href(std::string_view input);
38 bool set_host(std::string_view input);
39 bool set_hostname(std::string_view input);
40 bool set_protocol(std::string_view input);
41 bool set_username(std::string_view input);
42 bool set_password(std::string_view input);
43 bool set_port(std::string_view input);
44 bool set_pathname(std::string_view input);
45 void set_search(std::string_view input);
46 void set_hash(std::string_view input);
47
48 [[nodiscard]] bool has_valid_domain() const noexcept override;
55 [[nodiscard]] std::string get_origin() const noexcept override;
64 [[nodiscard]] constexpr std::string_view get_href() const noexcept
72 [[nodiscard]] std::string_view get_username() const noexcept
80 [[nodiscard]] std::string_view get_password() const noexcept
88 [[nodiscard]] std::string_view get_port() const noexcept ada_lifetime_bound;
95 [[nodiscard]] std::string_view get_hash() const noexcept ada_lifetime_bound;
104 [[nodiscard]] std::string_view get_host() const noexcept ada_lifetime_bound;
112 [[nodiscard]] std::string_view get_hostname() const noexcept
121 [[nodiscard]] constexpr std::string_view get_pathname() const noexcept
129 [[nodiscard]] ada_really_inline uint32_t get_pathname_length() const noexcept;
136 [[nodiscard]] std::string_view get_search() const noexcept ada_lifetime_bound;
144 [[nodiscard]] std::string_view get_protocol() const noexcept
146
151 [[nodiscard]] ada_really_inline constexpr bool has_credentials()
152 const noexcept;
153
175 [[nodiscard]] ada_really_inline const url_components &get_components()
176 const noexcept;
180 [[nodiscard]] std::string to_string() const override;
184 [[nodiscard]] std::string to_diagram() const;
185
191 [[nodiscard]] constexpr bool validate() const noexcept;
192
194 [[nodiscard]] constexpr bool has_empty_hostname() const noexcept;
196 [[nodiscard]] constexpr bool has_hostname() const noexcept;
198 [[nodiscard]] constexpr bool has_non_empty_username() const noexcept;
200 [[nodiscard]] constexpr bool has_non_empty_password() const noexcept;
202 [[nodiscard]] constexpr bool has_port() const noexcept;
204 [[nodiscard]] constexpr bool has_password() const noexcept;
206 [[nodiscard]] constexpr bool has_hash() const noexcept override;
208 [[nodiscard]] constexpr bool has_search() const noexcept override;
209
210 inline void clear_port();
211 inline void clear_hash();
212 inline void clear_search() override;
213
214 private:
215 // helper methods
217 url_aggregator &url) noexcept;
218 // parse_url methods
220 std::string_view, const url_aggregator *);
221
223 std::string_view, const url_aggregator *);
225 std::string_view, const url_aggregator *);
226 // url_pattern methods
227 template <url_pattern_regex::regex_concept regex_provider>
228 friend tl::expected<url_pattern<regex_provider>, errors>
229 parse_url_pattern_impl(std::variant<std::string_view, url_pattern_init> input,
230 const std::string_view *base_url,
231 const url_pattern_options *options);
232
233 std::string buffer{};
234 url_components components{};
235
241 [[nodiscard]] ada_really_inline bool is_at_path() const noexcept;
242
243 inline void add_authority_slashes_if_needed() noexcept;
244
249 constexpr void reserve(uint32_t capacity);
250
251 ada_really_inline size_t parse_port(
252 std::string_view view, bool check_trailing_content) noexcept override;
253
254 ada_really_inline size_t parse_port(std::string_view view) noexcept override {
255 return this->parse_port(view, false);
256 }
257
264 [[nodiscard]] bool parse_ipv4(std::string_view input, bool in_place);
265
270 [[nodiscard]] bool parse_ipv6(std::string_view input);
271
276 [[nodiscard]] bool parse_opaque_host(std::string_view input);
277
278 ada_really_inline void parse_path(std::string_view input);
279
284 [[nodiscard]] constexpr bool cannot_have_credentials_or_port() const;
285
286 template <bool override_hostname = false>
287 bool set_host_or_hostname(std::string_view input);
288
289 ada_really_inline bool parse_host(std::string_view input);
290
291 inline void update_base_authority(std::string_view base_buffer,
292 const url_components &base);
293 inline void update_unencoded_base_hash(std::string_view input);
294 inline void update_base_hostname(std::string_view input);
295 inline void update_base_search(std::string_view input);
296 inline void update_base_search(std::string_view input,
297 const uint8_t *query_percent_encode_set);
298 inline void update_base_pathname(std::string_view input);
299 inline void update_base_username(std::string_view input);
300 inline void append_base_username(std::string_view input);
301 inline void update_base_password(std::string_view input);
302 inline void append_base_password(std::string_view input);
303 inline void update_base_port(uint32_t input);
304 inline void append_base_pathname(std::string_view input);
305 [[nodiscard]] inline uint32_t retrieve_base_port() const;
306 constexpr void clear_hostname();
307 constexpr void clear_password();
308 constexpr void clear_pathname() override;
309 [[nodiscard]] constexpr bool has_dash_dot() const noexcept;
310 void delete_dash_dot();
311 inline void consume_prepared_path(std::string_view input);
312 template <bool has_state_override = false>
313 [[nodiscard]] ada_really_inline bool parse_scheme_with_colon(
314 std::string_view input);
315 ada_really_inline uint32_t replace_and_resize(uint32_t start, uint32_t end,
316 std::string_view input);
317 [[nodiscard]] constexpr bool has_authority() const noexcept;
318 constexpr void set_protocol_as_file();
319 inline void set_scheme(std::string_view new_scheme) noexcept;
324 inline void set_scheme_from_view_with_colon(
325 std::string_view new_scheme_with_colon) noexcept;
326 inline void copy_scheme(const url_aggregator &u) noexcept;
327
328 inline void update_host_to_base_host(const std::string_view input) noexcept;
329
330}; // url_aggregator
331
332inline std::ostream &operator<<(std::ostream &out, const url &u);
333} // namespace ada
334
335#endif
Common definitions for cross-platform compiler support.
#define ada_lifetime_bound
#define ada_really_inline
Definition common_defs.h:81
Includes the definitions for helper functions.
Includes the definitions for supported parsers.
Definition parser-inl.h:16
Definition ada_idna.h:13
errors
Definition errors.h:10
url_aggregator & operator=(const url_aggregator &u)=default
url_aggregator & operator=(url_aggregator &&u) noexcept=default
ada_really_inline const url_components & get_components() const noexcept
constexpr bool has_non_empty_password() const noexcept
void set_hash(std::string_view input)
constexpr bool validate() const noexcept
void clear_search() override
friend void helpers::strip_trailing_spaces_from_opaque_path(url_aggregator &url) noexcept
url_aggregator()=default
friend url_aggregator parser::parse_url(std::string_view, const url_aggregator *)
std::string_view get_hostname() const noexcept ada_lifetime_bound
std::string to_string() const override
std::string_view get_hash() const noexcept ada_lifetime_bound
friend url_aggregator parser::parse_url_impl(std::string_view, const url_aggregator *)
std::string to_diagram() const
constexpr bool has_hostname() const noexcept
bool set_protocol(std::string_view input)
constexpr bool has_search() const noexcept override
std::string get_origin() const noexcept override
constexpr std::string_view get_href() const noexcept ada_lifetime_bound
constexpr bool has_empty_hostname() const noexcept
constexpr bool has_password() const noexcept
std::string_view get_search() const noexcept ada_lifetime_bound
ada_really_inline uint32_t get_pathname_length() const noexcept
bool has_valid_domain() const noexcept override
bool set_hostname(std::string_view input)
bool set_password(std::string_view input)
~url_aggregator() override=default
constexpr std::string_view get_pathname() const noexcept ada_lifetime_bound
friend tl::expected< url_pattern< regex_provider >, errors > parse_url_pattern_impl(std::variant< std::string_view, url_pattern_init > input, const std::string_view *base_url, const url_pattern_options *options)
Definition parser-inl.h:18
bool set_pathname(std::string_view input)
std::string_view get_protocol() const noexcept ada_lifetime_bound
std::string_view get_password() const noexcept ada_lifetime_bound
bool set_href(std::string_view input)
constexpr bool has_hash() const noexcept override
void set_search(std::string_view input)
std::string_view get_port() const noexcept ada_lifetime_bound
constexpr bool has_port() const noexcept
ada_really_inline constexpr bool has_credentials() const noexcept
url_aggregator(url_aggregator &&u) noexcept=default
bool set_host(std::string_view input)
std::string_view get_host() const noexcept ada_lifetime_bound
bool set_port(std::string_view input)
url_aggregator(const url_aggregator &u)=default
constexpr bool has_non_empty_username() const noexcept
std::string_view get_username() const noexcept ada_lifetime_bound
bool set_username(std::string_view input)
Base class of URL implementations.
Definition url_base.h:44
URL Component representations using offsets.
Generic URL struct reliant on std::string instantiation.
Definition url.h:45
Declaration for the basic URL definitions.
Declaration for the URL Components.
ada::url_pattern_regex::std_regex_provider regex_provider
Definition url_pattern.cc:9