Ada 4.1.1
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 <cstddef>
15#include <cstdint>
16#include <ostream>
17#include <string>
18#include <string_view>
19#include <variant>
20
21#include "ada/common_defs.h"
22#include "ada/url_base.h"
23#include "ada/url_components.h"
24
25namespace ada {
26
27namespace parser {}
28
49 url_aggregator() = default;
50 url_aggregator(const url_aggregator& u) = default;
51 url_aggregator(url_aggregator&& u) noexcept = default;
52 url_aggregator& operator=(url_aggregator&& u) noexcept = default;
54 ~url_aggregator() override = default;
55
75 bool set_href(std::string_view input);
76 bool set_host(std::string_view input);
77 bool set_hostname(std::string_view input);
78 bool set_protocol(std::string_view input);
79 bool set_username(std::string_view input);
80 bool set_password(std::string_view input);
81 bool set_port(std::string_view input);
82 bool set_pathname(std::string_view input);
83 void set_search(std::string_view input);
84 void set_hash(std::string_view input);
85
90 [[nodiscard]] bool has_valid_domain() const noexcept override;
91
97 [[nodiscard]] std::string get_origin() const override;
98
106 [[nodiscard]] constexpr std::string_view get_href() const noexcept
108
113 [[nodiscard]] constexpr size_t get_href_size() const noexcept;
114
122 [[nodiscard]] std::string_view get_username() const ada_lifetime_bound;
123
131 [[nodiscard]] std::string_view get_password() const ada_lifetime_bound;
132
140 [[nodiscard]] std::string_view get_port() const ada_lifetime_bound;
141
149 [[nodiscard]] std::string_view get_hash() const ada_lifetime_bound;
150
158 [[nodiscard]] std::string_view get_host() const ada_lifetime_bound;
159
167 [[nodiscard]] std::string_view get_hostname() const ada_lifetime_bound;
168
176 [[nodiscard]] constexpr std::string_view get_pathname() const
178
184 [[nodiscard]] ada_really_inline uint32_t get_pathname_length() const noexcept;
185
193 [[nodiscard]] std::string_view get_search() const ada_lifetime_bound;
194
202 [[nodiscard]] std::string_view get_protocol() const ada_lifetime_bound;
203
208 [[nodiscard]] ada_really_inline constexpr bool has_credentials()
209 const noexcept;
210
230 [[nodiscard]] ada_really_inline const url_components& get_components()
231 const noexcept;
232
237 [[nodiscard]] std::string to_string() const override;
238
244 [[nodiscard]] std::string to_diagram() const;
245
250 [[nodiscard]] constexpr bool validate() const noexcept;
251
256 [[nodiscard]] constexpr bool has_empty_hostname() const noexcept;
257
262 [[nodiscard]] constexpr bool has_hostname() const noexcept;
263
268 [[nodiscard]] constexpr bool has_non_empty_username() const noexcept;
269
274 [[nodiscard]] constexpr bool has_non_empty_password() const noexcept;
275
280 [[nodiscard]] constexpr bool has_port() const noexcept;
281
286 [[nodiscard]] constexpr bool has_password() const noexcept;
287
292 [[nodiscard]] constexpr bool has_hash() const noexcept override;
293
298 [[nodiscard]] constexpr bool has_search() const noexcept override;
299
303 inline void clear_port();
304
308 inline void clear_hash();
309
313 inline void clear_search() override;
314
315 private:
316 // helper methods
319 // parse_url methods
321 std::string_view, const url_aggregator*);
322
324 std::string_view, const url_aggregator*);
326 std::string_view, const url_aggregator*);
327 template <class result_type>
328 friend bool parser::try_parse_simple_absolute(std::string_view, result_type&);
329 template <class result_type>
330 friend bool parser::finish_simple_absolute_with_port(std::string_view,
331 result_type&,
332 ada::scheme::type,
333 uint32_t, size_t, size_t,
334 size_t, bool);
335 template <class result_type>
336 friend bool parser::try_parse_simple_relative(std::string_view,
337 const result_type&,
338 result_type&);
339
340#if ADA_INCLUDE_URL_PATTERN
341 // url_pattern methods
342 template <url_pattern_regex::regex_concept regex_provider>
343 friend tl::expected<url_pattern<regex_provider>, errors>
344 parse_url_pattern_impl(
345 std::variant<std::string_view, url_pattern_init>&& input,
346 const std::string_view* base_url, const url_pattern_options* options);
347#endif // ADA_INCLUDE_URL_PATTERN
348
349 // components is declared before buffer so that the offset fields land
350 // close to url_base in memory, improving cache locality for getter calls.
351 // Note: exact cache-line placement is implementation- and platform-dependent.
352 url_components components{};
353 std::string buffer{};
354
360 [[nodiscard]] ada_really_inline bool is_at_path() const noexcept;
361
362 inline void add_authority_slashes_if_needed();
363
368 constexpr void reserve(uint32_t capacity);
369
370 ada_really_inline size_t parse_port(std::string_view view,
371 bool check_trailing_content) override;
372
373 ada_really_inline size_t parse_port(std::string_view view) override {
374 return this->parse_port(view, false);
375 }
376
383 [[nodiscard]] bool parse_ipv4(std::string_view input, bool in_place);
384
389 [[nodiscard]] bool parse_ipv6(std::string_view input);
390
395 [[nodiscard]] bool parse_opaque_host(std::string_view input);
396
397 ada_really_inline void parse_path(std::string_view input);
398
403 [[nodiscard]] constexpr bool cannot_have_credentials_or_port() const;
404
414 [[nodiscard]] bool needs_rollback_snapshot(size_t input_len) const noexcept;
415
416 template <bool override_hostname = false>
417 bool set_host_or_hostname(std::string_view input);
418
419 ada_really_inline bool parse_host(std::string_view input);
420
421 inline void update_base_authority(std::string_view base_buffer,
422 const url_components& base);
423 inline void update_unencoded_base_hash(std::string_view input);
424 inline void update_base_hostname(std::string_view input);
425 inline void update_base_search(std::string_view input);
426 inline void update_base_search(std::string_view input,
427 const uint8_t* query_percent_encode_set);
428 inline void update_base_pathname(std::string_view input);
429 inline void update_base_username(std::string_view input);
430 inline void append_base_username(std::string_view input);
431 inline void update_base_password(std::string_view input);
432 inline void append_base_password(std::string_view input);
433 inline void update_base_port(uint32_t input);
434 inline void append_base_pathname(std::string_view input);
435 [[nodiscard]] inline uint32_t retrieve_base_port() const;
436 constexpr void clear_hostname();
437 constexpr void clear_password();
438 constexpr void clear_pathname() override;
439 [[nodiscard]] constexpr bool has_dash_dot() const noexcept;
440 void delete_dash_dot();
441 inline void consume_prepared_path(std::string_view input);
442 template <bool has_state_override = false>
443 [[nodiscard]] ada_really_inline bool parse_scheme_with_colon(
444 std::string_view input);
445 ada_really_inline uint32_t replace_and_resize(uint32_t start, uint32_t end,
446 std::string_view input);
447 [[nodiscard]] constexpr bool has_authority() const noexcept;
448 constexpr void set_protocol_as_file();
449 inline void set_scheme(std::string_view new_scheme);
454 inline void set_scheme_from_view_with_colon(
455 std::string_view new_scheme_with_colon);
456 inline void copy_scheme(const url_aggregator& u);
457
458 inline void update_host_to_base_host(const std::string_view input);
459
460}; // url_aggregator
461
462inline std::ostream& operator<<(std::ostream& out, const url& u);
463} // namespace ada
464
465#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:18
URL scheme utilities and constants.
Definition scheme-inl.h:14
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 size_t get_href_size() const noexcept
constexpr bool validate() const noexcept
friend bool parser::finish_simple_absolute_with_port(std::string_view, result_type &, ada::scheme::type, uint32_t, size_t, size_t, size_t, bool)
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
friend bool parser::try_parse_simple_relative(std::string_view, const result_type &, result_type &)
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
friend bool parser::try_parse_simple_absolute(std::string_view, result_type &)
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:51
Stores byte offsets for URL components within a buffer.
Represents a parsed URL with individual string components.
Definition url.h:64
Base class and common definitions for URL types.
Declaration for the URL Components.