5#ifndef ADA_URL_PATTERN_INIT_H
6#define ADA_URL_PATTERN_INIT_H
8#include "ada/expected.h"
22#if ADA_INCLUDE_URL_PATTERN
29concept url_pattern_encoding_callback =
requires(F f, std::string_view sv) {
30 { f(sv) } -> std::same_as<tl::expected<std::string, errors>>;
40struct url_pattern_init {
41 enum class process_type : uint8_t {
46 friend std::ostream&
operator<<(std::ostream& os, process_type type) {
48 case process_type::url:
50 case process_type::pattern:
51 return os <<
"pattern";
53 return os <<
"unknown";
59 static tl::expected<url_pattern_init, errors> process(
60 const url_pattern_init& init, process_type type,
61 std::optional<std::string_view> protocol = std::nullopt,
62 std::optional<std::string_view> username = std::nullopt,
63 std::optional<std::string_view> password = std::nullopt,
64 std::optional<std::string_view> hostname = std::nullopt,
65 std::optional<std::string_view> port = std::nullopt,
66 std::optional<std::string_view> pathname = std::nullopt,
67 std::optional<std::string_view> search = std::nullopt,
68 std::optional<std::string_view> hash = std::nullopt);
71 static tl::expected<std::string, errors> process_protocol(
72 std::string_view value, process_type type);
75 static tl::expected<std::string, errors> process_username(
76 std::string_view value, process_type type);
79 static tl::expected<std::string, errors> process_password(
80 std::string_view value, process_type type);
83 static tl::expected<std::string, errors> process_hostname(
84 std::string_view value, process_type type);
87 static tl::expected<std::string, errors> process_port(
88 std::string_view port, std::string_view protocol, process_type type);
91 static tl::expected<std::string, errors> process_pathname(
92 std::string_view value, std::string_view protocol, process_type type);
95 static tl::expected<std::string, errors> process_search(
96 std::string_view value, process_type type);
99 static tl::expected<std::string, errors> process_hash(std::string_view value,
103 friend void PrintTo(
const url_pattern_init& init, std::ostream* os) {
104 *os <<
"protocol: '" << init.protocol.value_or(
"undefined") <<
"', ";
105 *os <<
"username: '" << init.username.value_or(
"undefined") <<
"', ";
106 *os <<
"password: '" << init.password.value_or(
"undefined") <<
"', ";
107 *os <<
"hostname: '" << init.hostname.value_or(
"undefined") <<
"', ";
108 *os <<
"port: '" << init.port.value_or(
"undefined") <<
"', ";
109 *os <<
"pathname: '" << init.pathname.value_or(
"undefined") <<
"', ";
110 *os <<
"search: '" << init.search.value_or(
"undefined") <<
"', ";
111 *os <<
"hash: '" << init.hash.value_or(
"undefined") <<
"', ";
112 *os <<
"base_url: '" << init.base_url.value_or(
"undefined") <<
"', ";
116 bool operator==(
const url_pattern_init&)
const;
118 std::optional<std::string> protocol{};
120 std::optional<std::string> username{};
122 std::optional<std::string> password{};
124 std::optional<std::string> hostname{};
126 std::optional<std::string> port{};
128 std::optional<std::string> pathname{};
130 std::optional<std::string> search{};
132 std::optional<std::string> hash{};
134 std::optional<std::string> base_url{};
Error type definitions for URL parsing.
std::ostream & operator<<(std::ostream &out, const ada::url &u)