Ada 3.4.3
Fast spec-compliant URL parser
Loading...
Searching...
No Matches
url_aggregator.h
Go to the documentation of this file.
1
11#ifndef ADA_URL_AGGREGATOR_H
12#define ADA_URL_AGGREGATOR_H
13
14#include <ostream>
15#include <string>
16#include <string_view>
17#include <variant>
18
19#include "ada/common_defs.h"
20#include "ada/url_base.h"
21#include "ada/url_components.h"
22
23namespace ada {
24
25namespace parser {}
26
47 url_aggregator() = default;
48 url_aggregator(const url_aggregator &u) = default;
49 url_aggregator(url_aggregator &&u) noexcept = default;
50 url_aggregator &operator=(url_aggregator &&u) noexcept = default;
52 ~url_aggregator() override = default;
53
73 bool set_href(std::string_view input);
74 bool set_host(std::string_view input);
75 bool set_hostname(std::string_view input);
76 bool set_protocol(std::string_view input);
77 bool set_username(std::string_view input);
78 bool set_password(std::string_view input);
79 bool set_port(std::string_view input);
80 bool set_pathname(std::string_view input);
81 void set_search(std::string_view input);
82 void set_hash(std::string_view input);
83
88 [[nodiscard]] bool has_valid_domain() const noexcept override;
89
95 [[nodiscard]] std::string get_origin() const override;
96
104 [[nodiscard]] constexpr std::string_view get_href() const noexcept
106
114 [[nodiscard]] std::string_view get_username() const ada_lifetime_bound;
115
123 [[nodiscard]] std::string_view get_password() const ada_lifetime_bound;
124
132 [[nodiscard]] std::string_view get_port() const ada_lifetime_bound;
133
141 [[nodiscard]] std::string_view get_hash() const ada_lifetime_bound;
142
150 [[nodiscard]] std::string_view get_host() const ada_lifetime_bound;
151
159 [[nodiscard]] std::string_view get_hostname() const ada_lifetime_bound;
160
168 [[nodiscard]] constexpr std::string_view get_pathname() const
170
176 [[nodiscard]] ada_really_inline uint32_t get_pathname_length() const noexcept;
177
185 [[nodiscard]] std::string_view get_search() const ada_lifetime_bound;
186
194 [[nodiscard]] std::string_view get_protocol() const ada_lifetime_bound;
195
200 [[nodiscard]] ada_really_inline constexpr bool has_credentials()
201 const noexcept;
202
222 [[nodiscard]] ada_really_inline const url_components &get_components()
223 const noexcept;
224
229 [[nodiscard]] std::string to_string() const override;
230
236 [[nodiscard]] std::string to_diagram() const;
237
242 [[nodiscard]] constexpr bool validate() const noexcept;
243
248 [[nodiscard]] constexpr bool has_empty_hostname() const noexcept;
249
254 [[nodiscard]] constexpr bool has_hostname() const noexcept;
255
260 [[nodiscard]] constexpr bool has_non_empty_username() const noexcept;
261
266 [[nodiscard]] constexpr bool has_non_empty_password() const noexcept;
267
272 [[nodiscard]] constexpr bool has_port() const noexcept;
273
278 [[nodiscard]] constexpr bool has_password() const noexcept;
279
284 [[nodiscard]] constexpr bool has_hash() const noexcept override;
285
290 [[nodiscard]] constexpr bool has_search() const noexcept override;
291
295 inline void clear_port();
296
300 inline void clear_hash();
301
305 inline void clear_search() override;
306
307 private:
308 // helper methods
311 // parse_url methods
313 std::string_view, const url_aggregator *);
314
316 std::string_view, const url_aggregator *);
318 std::string_view, const url_aggregator *);
319
320#if ADA_INCLUDE_URL_PATTERN
321 // url_pattern methods
322 template <url_pattern_regex::regex_concept regex_provider>
323 friend tl::expected<url_pattern<regex_provider>, errors>
324 parse_url_pattern_impl(
325 std::variant<std::string_view, url_pattern_init> &&input,
326 const std::string_view *base_url, const url_pattern_options *options);
327#endif // ADA_INCLUDE_URL_PATTERN
328
329 std::string buffer{};
330 url_components components{};
331
337 [[nodiscard]] ada_really_inline bool is_at_path() const noexcept;
338
339 inline void add_authority_slashes_if_needed();
340
345 constexpr void reserve(uint32_t capacity);
346
347 ada_really_inline size_t parse_port(std::string_view view,
348 bool check_trailing_content) override;
349
350 ada_really_inline size_t parse_port(std::string_view view) override {
351 return this->parse_port(view, false);
352 }
353
360 [[nodiscard]] bool parse_ipv4(std::string_view input, bool in_place);
361
366 [[nodiscard]] bool parse_ipv6(std::string_view input);
367
372 [[nodiscard]] bool parse_opaque_host(std::string_view input);
373
374 ada_really_inline void parse_path(std::string_view input);
375
380 [[nodiscard]] constexpr bool cannot_have_credentials_or_port() const;
381
382 template <bool override_hostname = false>
383 bool set_host_or_hostname(std::string_view input);
384
385 ada_really_inline bool parse_host(std::string_view input);
386
387 inline void update_base_authority(std::string_view base_buffer,
388 const url_components &base);
389 inline void update_unencoded_base_hash(std::string_view input);
390 inline void update_base_hostname(std::string_view input);
391 inline void update_base_search(std::string_view input);
392 inline void update_base_search(std::string_view input,
393 const uint8_t *query_percent_encode_set);
394 inline void update_base_pathname(std::string_view input);
395 inline void update_base_username(std::string_view input);
396 inline void append_base_username(std::string_view input);
397 inline void update_base_password(std::string_view input);
398 inline void append_base_password(std::string_view input);
399 inline void update_base_port(uint32_t input);
400 inline void append_base_pathname(std::string_view input);
401 [[nodiscard]] inline uint32_t retrieve_base_port() const;
402 constexpr void clear_hostname();
403 constexpr void clear_password();
404 constexpr void clear_pathname() override;
405 [[nodiscard]] constexpr bool has_dash_dot() const noexcept;
406 void delete_dash_dot();
407 inline void consume_prepared_path(std::string_view input);
408 template <bool has_state_override = false>
409 [[nodiscard]] ada_really_inline bool parse_scheme_with_colon(
410 std::string_view input);
411 ada_really_inline uint32_t replace_and_resize(uint32_t start, uint32_t end,
412 std::string_view input);
413 [[nodiscard]] constexpr bool has_authority() const noexcept;
414 constexpr void set_protocol_as_file();
415 inline void set_scheme(std::string_view new_scheme);
420 inline void set_scheme_from_view_with_colon(
421 std::string_view new_scheme_with_colon);
422 inline void copy_scheme(const url_aggregator &u);
423
424 inline void update_host_to_base_host(const std::string_view input);
425
426}; // url_aggregator
427
428inline std::ostream &operator<<(std::ostream &out, const url &u);
429} // namespace ada
430
431#endif
Cross-platform compiler macros and common definitions.
#define ada_lifetime_bound
#define ada_really_inline
Definition common_defs.h:85
Includes the definitions for helper functions.
Internal URL parsing implementation.
Definition parser-inl.h:16
Definition ada_idna.h:13
errors
Error codes for URL parsing operations.
Definition errors.h:17
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
std::string_view get_search() const ada_lifetime_bound
url_aggregator()=default
friend url_aggregator parser::parse_url(std::string_view, const url_aggregator *)
std::string_view get_hash() const ada_lifetime_bound
friend void helpers::strip_trailing_spaces_from_opaque_path(url_aggregator &url)
std::string to_string() const override
std::string_view get_password() const ada_lifetime_bound
std::string_view get_host() const ada_lifetime_bound
std::string_view get_username() const ada_lifetime_bound
friend url_aggregator parser::parse_url_impl(std::string_view, const url_aggregator *)
std::string_view get_port() const ada_lifetime_bound
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 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
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
bool set_pathname(std::string_view input)
bool set_href(std::string_view input)
constexpr bool has_hash() const noexcept override
constexpr std::string_view get_pathname() const ada_lifetime_bound
void set_search(std::string_view input)
std::string_view get_hostname() const ada_lifetime_bound
std::string_view get_protocol() const 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)
bool set_port(std::string_view input)
url_aggregator(const url_aggregator &u)=default
constexpr bool has_non_empty_username() const noexcept
bool set_username(std::string_view input)
Abstract base class for URL representations.
Definition url_base.h:49
Stores byte offsets for URL components within a buffer.
Represents a parsed URL with individual string components.
Definition url.h:62
Base class and common definitions for URL types.
Declaration for the URL Components.