5#ifndef ADA_URL_PATTERN_INIT_H
6#define ADA_URL_PATTERN_INIT_H
8#include "ada/expected.h"
20#if ADA_INCLUDE_URL_PATTERN
27concept url_pattern_encoding_callback =
requires(F f, std::string_view sv) {
28 { f(sv) } -> std::same_as<tl::expected<std::string, errors>>;
38struct url_pattern_init {
39 enum class process_type : uint8_t {
44 friend std::ostream&
operator<<(std::ostream& os, process_type type) {
46 case process_type::url:
48 case process_type::pattern:
49 return os <<
"pattern";
51 return os <<
"unknown";
57 static tl::expected<url_pattern_init, errors> process(
58 const url_pattern_init& init, process_type type,
59 std::optional<std::string_view> protocol = std::nullopt,
60 std::optional<std::string_view> username = std::nullopt,
61 std::optional<std::string_view> password = std::nullopt,
62 std::optional<std::string_view> hostname = std::nullopt,
63 std::optional<std::string_view> port = std::nullopt,
64 std::optional<std::string_view> pathname = std::nullopt,
65 std::optional<std::string_view> search = std::nullopt,
66 std::optional<std::string_view> hash = std::nullopt);
69 static tl::expected<std::string, errors> process_protocol(
70 std::string_view value, process_type type);
73 static tl::expected<std::string, errors> process_username(
74 std::string_view value, process_type type);
77 static tl::expected<std::string, errors> process_password(
78 std::string_view value, process_type type);
81 static tl::expected<std::string, errors> process_hostname(
82 std::string_view value, process_type type);
85 static tl::expected<std::string, errors> process_port(
86 std::string_view port, std::string_view protocol, process_type type);
89 static tl::expected<std::string, errors> process_pathname(
90 std::string_view value, std::string_view protocol, process_type type);
93 static tl::expected<std::string, errors> process_search(
94 std::string_view value, process_type type);
97 static tl::expected<std::string, errors> process_hash(std::string_view value,
101 friend void PrintTo(
const url_pattern_init& init, std::ostream* os) {
102 *os <<
"protocol: '" << init.protocol.value_or(
"undefined") <<
"', ";
103 *os <<
"username: '" << init.username.value_or(
"undefined") <<
"', ";
104 *os <<
"password: '" << init.password.value_or(
"undefined") <<
"', ";
105 *os <<
"hostname: '" << init.hostname.value_or(
"undefined") <<
"', ";
106 *os <<
"port: '" << init.port.value_or(
"undefined") <<
"', ";
107 *os <<
"pathname: '" << init.pathname.value_or(
"undefined") <<
"', ";
108 *os <<
"search: '" << init.search.value_or(
"undefined") <<
"', ";
109 *os <<
"hash: '" << init.hash.value_or(
"undefined") <<
"', ";
110 *os <<
"base_url: '" << init.base_url.value_or(
"undefined") <<
"', ";
114 bool operator==(
const url_pattern_init&)
const;
116 std::optional<std::string> protocol{};
118 std::optional<std::string> username{};
120 std::optional<std::string> password{};
122 std::optional<std::string> hostname{};
124 std::optional<std::string> port{};
126 std::optional<std::string> pathname{};
128 std::optional<std::string> search{};
130 std::optional<std::string> hash{};
132 std::optional<std::string> base_url{};
Error type definitions for URL parsing.
std::ostream & operator<<(std::ostream &out, const ada::url &u)