Ada 3.4.0
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 noexcept override;
96
104 [[nodiscard]] constexpr std::string_view get_href() const noexcept
106
114 [[nodiscard]] std::string_view get_username() const noexcept
116
124 [[nodiscard]] std::string_view get_password() const noexcept
126
134 [[nodiscard]] std::string_view get_port() const noexcept ada_lifetime_bound;
135
143 [[nodiscard]] std::string_view get_hash() const noexcept ada_lifetime_bound;
144
152 [[nodiscard]] std::string_view get_host() const noexcept ada_lifetime_bound;
153
161 [[nodiscard]] std::string_view get_hostname() const noexcept
163
171 [[nodiscard]] constexpr std::string_view get_pathname() const noexcept
173
179 [[nodiscard]] ada_really_inline uint32_t get_pathname_length() const noexcept;
180
188 [[nodiscard]] std::string_view get_search() const noexcept ada_lifetime_bound;
189
197 [[nodiscard]] std::string_view get_protocol() const noexcept
199
204 [[nodiscard]] ada_really_inline constexpr bool has_credentials()
205 const noexcept;
206
226 [[nodiscard]] ada_really_inline const url_components &get_components()
227 const noexcept;
228
233 [[nodiscard]] std::string to_string() const override;
234
240 [[nodiscard]] std::string to_diagram() const;
241
246 [[nodiscard]] constexpr bool validate() const noexcept;
247
252 [[nodiscard]] constexpr bool has_empty_hostname() const noexcept;
253
258 [[nodiscard]] constexpr bool has_hostname() const noexcept;
259
264 [[nodiscard]] constexpr bool has_non_empty_username() const noexcept;
265
270 [[nodiscard]] constexpr bool has_non_empty_password() const noexcept;
271
276 [[nodiscard]] constexpr bool has_port() const noexcept;
277
282 [[nodiscard]] constexpr bool has_password() const noexcept;
283
288 [[nodiscard]] constexpr bool has_hash() const noexcept override;
289
294 [[nodiscard]] constexpr bool has_search() const noexcept override;
295
299 inline void clear_port();
300
304 inline void clear_hash();
305
309 inline void clear_search() override;
310
311 private:
312 // helper methods
314 url_aggregator &url) noexcept;
315 // parse_url methods
317 std::string_view, const url_aggregator *);
318
320 std::string_view, const url_aggregator *);
322 std::string_view, const url_aggregator *);
323
324#if ADA_INCLUDE_URL_PATTERN
325 // url_pattern methods
326 template <url_pattern_regex::regex_concept regex_provider>
327 friend tl::expected<url_pattern<regex_provider>, errors>
328 parse_url_pattern_impl(
329 std::variant<std::string_view, url_pattern_init> &&input,
330 const std::string_view *base_url, const url_pattern_options *options);
331#endif // ADA_INCLUDE_URL_PATTERN
332
333 std::string buffer{};
334 url_components components{};
335
341 [[nodiscard]] ada_really_inline bool is_at_path() const noexcept;
342
343 inline void add_authority_slashes_if_needed() noexcept;
344
349 constexpr void reserve(uint32_t capacity);
350
351 ada_really_inline size_t parse_port(
352 std::string_view view, bool check_trailing_content) noexcept override;
353
354 ada_really_inline size_t parse_port(std::string_view view) noexcept override {
355 return this->parse_port(view, false);
356 }
357
364 [[nodiscard]] bool parse_ipv4(std::string_view input, bool in_place);
365
370 [[nodiscard]] bool parse_ipv6(std::string_view input);
371
376 [[nodiscard]] bool parse_opaque_host(std::string_view input);
377
378 ada_really_inline void parse_path(std::string_view input);
379
384 [[nodiscard]] constexpr bool cannot_have_credentials_or_port() const;
385
386 template <bool override_hostname = false>
387 bool set_host_or_hostname(std::string_view input);
388
389 ada_really_inline bool parse_host(std::string_view input);
390
391 inline void update_base_authority(std::string_view base_buffer,
392 const url_components &base);
393 inline void update_unencoded_base_hash(std::string_view input);
394 inline void update_base_hostname(std::string_view input);
395 inline void update_base_search(std::string_view input);
396 inline void update_base_search(std::string_view input,
397 const uint8_t *query_percent_encode_set);
398 inline void update_base_pathname(std::string_view input);
399 inline void update_base_username(std::string_view input);
400 inline void append_base_username(std::string_view input);
401 inline void update_base_password(std::string_view input);
402 inline void append_base_password(std::string_view input);
403 inline void update_base_port(uint32_t input);
404 inline void append_base_pathname(std::string_view input);
405 [[nodiscard]] inline uint32_t retrieve_base_port() const;
406 constexpr void clear_hostname();
407 constexpr void clear_password();
408 constexpr void clear_pathname() override;
409 [[nodiscard]] constexpr bool has_dash_dot() const noexcept;
410 void delete_dash_dot();
411 inline void consume_prepared_path(std::string_view input);
412 template <bool has_state_override = false>
413 [[nodiscard]] ada_really_inline bool parse_scheme_with_colon(
414 std::string_view input);
415 ada_really_inline uint32_t replace_and_resize(uint32_t start, uint32_t end,
416 std::string_view input);
417 [[nodiscard]] constexpr bool has_authority() const noexcept;
418 constexpr void set_protocol_as_file();
419 inline void set_scheme(std::string_view new_scheme) noexcept;
424 inline void set_scheme_from_view_with_colon(
425 std::string_view new_scheme_with_colon) noexcept;
426 inline void copy_scheme(const url_aggregator &u) noexcept;
427
428 inline void update_host_to_base_host(const std::string_view input) noexcept;
429
430}; // url_aggregator
431
432inline std::ostream &operator<<(std::ostream &out, const url &u);
433} // namespace ada
434
435#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
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
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)
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.