MCPcopy Create free account
hub / github.com/ada-url/ada / process

Method process

src/url_pattern.cpp:11–259  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9namespace ada {
10
11tl::expected<url_pattern_init, errors> url_pattern_init::process(
12 const url_pattern_init& init, url_pattern_init::process_type type,
13 std::optional<std::string_view> protocol,
14 std::optional<std::string_view> username,
15 std::optional<std::string_view> password,
16 std::optional<std::string_view> hostname,
17 std::optional<std::string_view> port,
18 std::optional<std::string_view> pathname,
19 std::optional<std::string_view> search,
20 std::optional<std::string_view> hash) {
21 // Let result be the result of creating a new URLPatternInit.
22 auto result = url_pattern_init{};
23
24 // If protocol is not null, set result["protocol"] to protocol.
25 if (protocol.has_value()) result.protocol = *protocol;
26
27 // If username is not null, set result["username"] to username.
28 if (username.has_value()) result.username = *username;
29
30 // If password is not null, set result["password"] to password.
31 if (password.has_value()) result.password = *password;
32
33 // If hostname is not null, set result["hostname"] to hostname.
34 if (hostname.has_value()) result.hostname = *hostname;
35
36 // If port is not null, set result["port"] to port.
37 if (port.has_value()) result.port = *port;
38
39 // If pathname is not null, set result["pathname"] to pathname.
40 if (pathname.has_value()) result.pathname = *pathname;
41
42 // If search is not null, set result["search"] to search.
43 if (search.has_value()) result.search = *search;
44
45 // If hash is not null, set result["hash"] to hash.
46 if (hash.has_value()) result.hash = *hash;
47
48 // Let baseURL be null.
49 std::optional<url_aggregator> base_url{};
50
51 // If init["baseURL"] exists:
52 if (init.base_url.has_value()) {
53 // Set baseURL to the result of parsing init["baseURL"].
54 auto parsing_result = ada::parse<url_aggregator>(*init.base_url);
55 // If baseURL is failure, then throw a TypeError.
56 if (!parsing_result) {
57 return tl::unexpected(errors::type_error);
58 }
59 base_url = std::move(*parsing_result);
60
61 // If init["protocol"] does not exist, then set result["protocol"] to the
62 // result of processing a base URL string given baseURL's scheme and type.
63 if (!init.protocol.has_value()) {
64 ADA_ASSERT_TRUE(base_url.has_value());
65 std::string_view base_url_protocol = base_url->get_protocol();
66 if (base_url_protocol.ends_with(":")) base_url_protocol.remove_suffix(1);
67 result.protocol =
68 url_pattern_helpers::process_base_url_string(base_url_protocol, type);

Callers

nothing calls this directly

Calls 13

unexpectedClass · 0.85
process_base_url_stringFunction · 0.85
is_absolute_pathnameFunction · 0.85
appendMethod · 0.80
has_valueMethod · 0.45
get_protocolMethod · 0.45
get_usernameMethod · 0.45
get_passwordMethod · 0.45
get_hostnameMethod · 0.45
get_portMethod · 0.45
get_pathnameMethod · 0.45
get_searchMethod · 0.45

Tested by

no test coverage detected