5#ifndef ADA_URL_AGGREGATOR_INL_H
6#define ADA_URL_AGGREGATOR_INL_H
22inline void url_aggregator::update_base_authority(
26 ada_log(
"url_aggregator::update_base_authority ",
input);
36 input.remove_prefix(2);
57 }
else if (!
input.empty()) {
67 if (buffer.size() >
base.host_start && buffer[
base.host_start] !=
'@') {
81inline void url_aggregator::update_unencoded_base_hash(std::string_view
input) {
82 ada_log(
"url_aggregator::update_unencoded_base_hash ",
input,
" [",
83 input.size(),
" bytes], buffer is '", buffer,
"' [", buffer.size(),
84 " bytes] components.hash_start = ", components.
hash_start);
99 ada_log(
"url_aggregator::update_unencoded_base_hash final buffer is '",
100 buffer,
"' [", buffer.size(),
" bytes]");
125inline void url_aggregator::update_base_hostname(
const std::string_view
input) {
127 " bytes], buffer is '", buffer,
"' [", buffer.size(),
" bytes]");
132 add_authority_slashes_if_needed();
155 ada_log(
"url_aggregator::get_pathname_length");
170inline void url_aggregator::update_base_search(std::string_view
input) {
179 if (
input[0] ==
'?') {
180 input.remove_prefix(1);
191 buffer.append(
input);
209inline void url_aggregator::update_base_search(
229 buffer.append(
input);
262inline void url_aggregator::update_base_pathname(
const std::string_view
input) {
301inline void url_aggregator::append_base_pathname(
const std::string_view
input) {
306#if ADA_DEVELOPMENT_CHECKS
325#if ADA_DEVELOPMENT_CHECKS
329 "append_base_pathname problem after inserting " + std::string(
input));
334inline void url_aggregator::update_base_username(
const std::string_view
input) {
340 add_authority_slashes_if_needed();
372inline void url_aggregator::append_base_username(
const std::string_view
input) {
373 ada_log(
"url_aggregator::append_base_username ",
input);
376#if ADA_DEVELOPMENT_CHECKS
381 add_authority_slashes_if_needed();
407#if ADA_DEVELOPMENT_CHECKS
411 "append_base_username problem after inserting " + std::string(
input));
416constexpr void url_aggregator::clear_password() {
436inline void url_aggregator::update_base_password(
const std::string_view
input) {
437 ada_log(
"url_aggregator::update_base_password ",
input);
441 add_authority_slashes_if_needed();
449 update_base_username(
"");
490inline void url_aggregator::append_base_password(
const std::string_view
input) {
495#if ADA_DEVELOPMENT_CHECKS
500 add_authority_slashes_if_needed();
533#if ADA_DEVELOPMENT_CHECKS
537 "append_base_password problem after inserting " + std::string(
input));
542inline void url_aggregator::update_base_port(
uint32_t input) {
543 ada_log(
"url_aggregator::update_base_port");
551 std::string value = helpers::concat(
":", std::to_string(
input));
560 buffer.insert(components.
host_end, value);
573 ada_log(
"url_aggregator::clear_port");
579 buffer.erase(components.
host_end, length);
592 ada_log(
"url_aggregator::retrieve_base_port");
593 return components.
port;
597 ada_log(
"url_aggregator::clear_search");
613#if ADA_DEVELOPMENT_CHECKS
615 "search should have been cleared on buffer=" + buffer +
622 ada_log(
"url_aggregator::clear_hash");
630#if ADA_DEVELOPMENT_CHECKS
632 "hash should have been cleared on buffer=" + buffer +
638constexpr void url_aggregator::clear_pathname() {
639 ada_log(
"url_aggregator::clear_pathname");
651 buffer[components.
host_end] ==
'/' &&
652 buffer[components.
host_end + 1] ==
'.') {
654 buffer.erase(components.
host_end, 2);
663 ada_log(
"url_aggregator::clear_pathname completed, running checks...");
664#if ADA_DEVELOPMENT_CHECKS
666 "pathname should have been cleared on buffer=" + buffer +
670 ada_log(
"url_aggregator::clear_pathname completed, running checks... ok");
673constexpr void url_aggregator::clear_hostname() {
674 ada_log(
"url_aggregator::clear_hostname");
676 if (!has_authority()) {
698#if ADA_DEVELOPMENT_CHECKS
700 "hostname should have been cleared on buffer=" + buffer +
705 "hostname should have been cleared on buffer=" + buffer +
711 ada_log(
"url_aggregator::has_hash");
716 ada_log(
"url_aggregator::has_search");
721 ada_log(
"url_aggregator::has_credentials");
725constexpr bool url_aggregator::cannot_have_credentials_or_port()
const {
726 ada_log(
"url_aggregator::cannot_have_credentials_or_port");
736[[
nodiscard]]
constexpr bool ada::url_aggregator::has_authority()
738 ada_log(
"url_aggregator::has_authority");
741 return components.protocol_end + 2 <= components.host_start &&
742 helpers::substring(buffer, components.protocol_end,
743 components.protocol_end + 2) ==
"//";
746inline void ada::url_aggregator::add_authority_slashes_if_needed() {
747 ada_log(
"url_aggregator::add_authority_slashes_if_needed");
752 if (has_authority()) {
758 buffer.insert(components.protocol_end,
"//");
759 components.username_end += 2;
760 components.host_start += 2;
761 components.host_end += 2;
762 components.pathname_start += 2;
764 components.search_start += 2;
767 components.hash_start += 2;
777 ada_log(
"url_aggregator::has_non_empty_username");
782 ada_log(
"url_aggregator::has_non_empty_password");
787 ada_log(
"url_aggregator::has_password");
807 return has_authority();
811 ada_log(
"url_aggregator::has_port");
821 ada_log(
"url_aggregator::has_dash_dot");
822#if ADA_DEVELOPMENT_CHECKS
828 buffer[components.
host_end + 1] ==
'.') ||
829 (buffer[components.
host_end] ==
':' &&
833 buffer[components.
host_end] ==
'/' &&
834 buffer[components.
host_end + 1] ==
'.') {
846 buffer[components.
host_end + 1] ==
'.';
851 ada_log(
"url_aggregator::get_href");
858 if (!
view.empty() &&
view[0] ==
'-') {
859 ada_log(
"parse_port: view[0] == '0' && view.size() > 1");
865 if (
r.ec == std::errc::result_out_of_range) {
866 ada_log(
"parse_port: r.ec == std::errc::result_out_of_range");
880 ada_log(
"parse_port",
r.ec == std::errc());
894constexpr void url_aggregator::set_protocol_as_file() {
895 ada_log(
"url_aggregator::set_protocol_as_file ");
902 if (buffer.empty()) {
903 buffer.append(
"file:");
906 buffer.insert(0,
"file:");
929 ada_log(
"url_aggregator::validate inconsistent components \n",
980 if (components.
host_end > buffer.size()) {
985 ada_log(
"url_aggregator::validate pathname_start overflow \n",
993 "url_aggregator::validate missing : at the end of the protocol \n",
1004 "url_aggregator::validate missing : or @ at the end of the username "
1011 if (components.
host_start != buffer.size()) {
1015 "url_aggregator::validate missing @ at the end of the password \n",
1025 "url_aggregator::validate missing // between protocol and host "
1034 "url_aggregator::validate missing @ at the end of the username "
1042 ada_log(
"url_aggregator::validate expected omitted host \n",
1048 if (components.
host_end != buffer.size() &&
1051 buffer[components.
host_end] ==
'/' &&
1052 buffer[components.
host_end + 1] ==
'.') {
1057 "url_aggregator::validate expected the path to begin with // \n",
1061 }
else if (buffer[components.
host_end] !=
':') {
1062 ada_log(
"url_aggregator::validate missing : at the port \n",
1071 ada_log(
"url_aggregator::validate missing / at the path \n",
1078 ada_log(
"url_aggregator::validate missing ? at the search \n",
1085 ada_log(
"url_aggregator::validate missing # at the hash \n",
1096 ada_log(
"url_aggregator::get_pathname pathname_start = ",
1098 " components.search_start = ", components.
search_start,
1099 " components.hash_start = ", components.
hash_start);
1111 return out <<
u.to_string();
1114void url_aggregator::update_host_to_base_host(
const std::string_view
input) {
1115 ada_log(
"url_aggregator::update_host_to_base_host ",
input);
1123 }
else if (has_dash_dot()) {
1124 add_authority_slashes_if_needed();
1130 update_base_hostname(
input);
Definitions of the character sets used by unicode functions.
#define ADA_ASSERT_TRUE(COND)
#define ada_lifetime_bound
#define ADA_ASSERT_EQUAL(LHS, RHS, MESSAGE)
#define ada_really_inline
Definitions for helper functions used within Ada.
constexpr uint8_t FRAGMENT_PERCENT_ENCODE[32]
constexpr bool is_digit(char x) noexcept
type
Enumeration of URL scheme types.
ada_really_inline size_t percent_encode_index(const std::string_view input, const uint8_t character_set[])
std::ostream & operator<<(std::ostream &out, const ada::url &u)
ada_warn_unused ada::result< result_type > parse(std::string_view input, const result_type *base_url=nullptr)
URL scheme type definitions and utilities.
Memory-efficient URL representation using a single buffer.
ada_really_inline const url_components & get_components() const noexcept
constexpr bool has_non_empty_password() const noexcept
constexpr bool validate() const noexcept
void clear_search() override
std::string_view get_search() const ada_lifetime_bound
std::string_view get_hash() const ada_lifetime_bound
std::string to_string() const override
std::string_view get_password() const ada_lifetime_bound
std::string_view get_username() const ada_lifetime_bound
std::string to_diagram() const
constexpr bool has_hostname() const noexcept
constexpr bool has_search() 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
ada_really_inline uint32_t get_pathname_length() const noexcept
constexpr bool has_hash() const noexcept override
constexpr std::string_view get_pathname() const ada_lifetime_bound
std::string_view get_hostname() const ada_lifetime_bound
constexpr bool has_port() const noexcept
ada_really_inline constexpr bool has_credentials() const noexcept
constexpr bool has_non_empty_username() const noexcept
ada_really_inline constexpr bool is_special() const noexcept
Stores byte offsets for URL components within a buffer.
std::string to_string() const
static constexpr uint32_t omitted
constexpr bool check_offset_consistency() const noexcept
Definitions for unicode operations.
Declaration for the ada::url_aggregator class.
Declaration for the URL Components.