14template <
class result_type,
bool store_values>
23 std::is_same<ada::url, result_type>::value;
25 std::is_same<ada::url_aggregator, result_type>::value;
39 if (
user_input.size() > std::numeric_limits<uint32_t>::max()) {
71 if (unicode::has_tabs_or_newline(
user_input)) {
75 helpers::remove_ascii_tab_or_newline(
tmp_buffer);
84 helpers::trim_c0_whitespace(
url_data);
132 ada_log(
"SCHEME the scheme should be ",
140 if (!url.parse_scheme_with_colon(
145 ada_log(
"SCHEME the scheme is ", url.get_protocol());
148 if (url.type == ada::scheme::type::FILE) {
155 else if (url.is_special() &&
base_url !=
nullptr &&
162 else if (url.is_special()) {
195 ada_log(
"NO_SCHEME validation error");
196 url.is_valid =
false;
204 ada_log(
"NO_SCHEME opaque base with fragment");
206 url.has_opaque_path =
base_url->has_opaque_path;
212 url.update_base_pathname(
base_url->get_pathname());
213 url.update_base_search(
base_url->get_search());
215 url.update_unencoded_base_hash(*
fragment);
220 else if (
base_url->type != ada::scheme::type::FILE) {
221 ada_log(
"NO_SCHEME non-file relative path");
226 ada_log(
"NO_SCHEME file base type");
259 url.is_special() ? helpers::find_authority_delimiter_special(
view)
260 : helpers::find_authority_delimiter(
view);
270 url.password +=
"%40";
272 url.append_base_password(
"%40");
276 url.username +=
"%40";
278 url.append_base_username(
"%40");
293 url.username += unicode::percent_encode(
297 url.append_base_username(unicode::percent_encode(
303 url.username += unicode::percent_encode(
306 url.password += unicode::percent_encode(
310 url.append_base_username(unicode::percent_encode(
313 url.append_base_password(unicode::percent_encode(
321 url.password += unicode::percent_encode(
324 url.append_base_password(unicode::percent_encode(
339 url.is_valid =
false;
348 url.update_unencoded_base_hash(*
fragment);
359 ada_log(
"SPECIAL_RELATIVE_OR_AUTHORITY ",
404 "RELATIVE_SCHEME if c is U+002F (/), then set state to relative "
412 "RELATIVE_SCHEME if url is special and c is U+005C, validation "
413 "error, set state to relative slash state");
416 ada_log(
"RELATIVE_SCHEME otherwise");
427 url.has_opaque_path =
base_url->has_opaque_path;
431 url.update_base_authority(
base_url->get_href(),
435 url.set_hostname(
base_url->get_hostname());
436 url.update_base_port(
base_url->retrieve_base_port());
438 url.has_opaque_path =
base_url->has_opaque_path;
439 url.update_base_pathname(
base_url->get_pathname());
440 url.update_base_search(
base_url->get_search());
443 url.has_opaque_path =
base_url->has_opaque_path;
457 helpers::shorten_path(url.path, url.type);
459 std::string_view path = url.get_pathname();
460 if (helpers::shorten_path(path, url.type)) {
461 url.update_base_pathname(std::string(path));
501 url.update_base_authority(
base_url->get_href(),
505 url.set_hostname(
base_url->get_hostname());
506 url.update_base_port(
base_url->retrieve_base_port());
516 ada_log(
"SPECIAL_AUTHORITY_SLASHES ",
530 ada_log(
"SPECIAL_AUTHORITY_IGNORE_SLASHES ",
558 ada_log(
"QUERY update_base_search completed ");
560 url.update_unencoded_base_hash(*
fragment);
571 helpers::get_host_delimiter_location(url.is_special(),
host_view);
586 ada_log(
"HOST parsing results in ", url.get_hostname());
600 if (url.is_special() &&
host_view.empty()) {
601 url.is_valid =
false;
608 url.update_base_hostname(
"");
612 ada_log(
"HOST parsing results in ", url.get_hostname(),
613 " href=", url.get_href());
627 if (
location != std::string_view::npos) {
634 url.has_opaque_path =
true;
637 url.update_base_pathname(unicode::percent_encode(
657 if (url.is_special()) {
665 url.update_base_pathname(
"/");
667 url.update_unencoded_base_hash(*
fragment);
716 helpers::parse_prepared_path(
view, url.type, url.path);
718 url.consume_prepared_path(
view);
731 ada_log(
"FILE_SLASH c is U+002F or U+005C");
736 ada_log(
"FILE_SLASH otherwise");
741 base_url->type == ada::scheme::type::FILE) {
753 if (!
base_url->get_pathname().empty()) {
759 if (
loc != std::string_view::npos) {
768 url.append_base_pathname(
798 url.update_base_hostname(
"");
813 if (url.host.has_value() && url.host.value() ==
"localhost") {
817 if (url.get_hostname() ==
"localhost") {
818 url.update_base_hostname(
"");
833 url.set_protocol_as_file();
838 url.update_base_hostname(
"");
844 ada_log(
"FILE c is U+002F or U+005C");
850 base_url->type == ada::scheme::type::FILE) {
861 url.set_hostname(
base_url->get_hostname());
862 url.update_base_pathname(
base_url->get_pathname());
863 url.update_base_search(
base_url->get_search());
865 url.has_opaque_path =
base_url->has_opaque_path;
880 helpers::shorten_path(url.path, url.type);
882 std::string_view path = url.get_pathname();
883 if (helpers::shorten_path(path, url.type)) {
884 url.update_base_pathname(std::string(path));
891 url.clear_pathname();
892 url.has_opaque_path =
true;
916 url.update_unencoded_base_hash(*
fragment);
927template <
class result_type>
Definitions of the character sets used by unicode functions.
Common definitions for cross-platform compiler support.
#define ADA_ASSERT_TRUE(COND)
constexpr uint8_t C0_CONTROL_PERCENT_ENCODE[32]
constexpr uint8_t USERINFO_PERCENT_ENCODE[32]
constexpr uint8_t SPECIAL_QUERY_PERCENT_ENCODE[32]
constexpr uint8_t QUERY_PERCENT_ENCODE[32]
constexpr bool is_normalized_windows_drive_letter(std::string_view input) noexcept
constexpr bool is_windows_drive_letter(std::string_view input) noexcept
constexpr bool is_alpha(char x) noexcept
ada_really_inline bool begins_with(std::string_view view, std::string_view prefix)
Includes the definitions for supported parsers.
template url parse_url< url >(std::string_view user_input, const url *base_url)
result_type parse_url(std::string_view user_input, const result_type *base_url=nullptr)
template url_aggregator parse_url< url_aggregator >(std::string_view user_input, const url_aggregator *base_url)
result_type parse_url_impl(std::string_view user_input, const result_type *base_url=nullptr)
ada_warn_unused std::string to_string(encoding_type type)
@ SPECIAL_RELATIVE_OR_AUTHORITY
@ SPECIAL_AUTHORITY_SLASHES
@ SPECIAL_AUTHORITY_IGNORE_SLASHES
ada_warn_unused ada::result< result_type > parse(std::string_view input, const result_type *base_url=nullptr)
Definitions for the parser.
Definitions for all unicode specific functions.