MCPcopy Create free account
hub / github.com/NativeScript/android / parse_url_pattern_impl

Function parse_url_pattern_impl

test-app/runtime/src/main/cpp/ada/ada.h:5796–6046  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5794#if ADA_INCLUDE_URL_PATTERN
5795template <url_pattern_regex::regex_concept regex_provider>
5796tl::expected<url_pattern<regex_provider>, errors> parse_url_pattern_impl(
5797 std::variant<std::string_view, url_pattern_init>&& input,
5798 const std::string_view* base_url, const url_pattern_options* options) {
5799 // Let init be null.
5800 url_pattern_init init;
5801
5802 // If input is a scalar value string then:
5803 if (std::holds_alternative<std::string_view>(input)) {
5804 // Set init to the result of running parse a constructor string given input.
5805 auto parse_result =
5806 url_pattern_helpers::constructor_string_parser<regex_provider>::parse(
5807 std::get<std::string_view>(input));
5808 if (!parse_result) {
5809 ada_log("constructor_string_parser::parse failed");
5810 return tl::unexpected(parse_result.error());
5811 }
5812 init = std::move(*parse_result);
5813 // If baseURL is null and init["protocol"] does not exist, then throw a
5814 // TypeError.
5815 if (!base_url && !init.protocol) {
5816 ada_log("base url is null and protocol is not set");
5817 return tl::unexpected(errors::type_error);
5818 }
5819
5820 // If baseURL is not null, set init["baseURL"] to baseURL.
5821 if (base_url) {
5822 init.base_url = std::string(*base_url);
5823 }
5824 } else {
5825 // Assert: input is a URLPatternInit.
5826 ADA_ASSERT_TRUE(std::holds_alternative<url_pattern_init>(input));
5827 // If baseURL is not null, then throw a TypeError.
5828 if (base_url) {
5829 ada_log("base url is not null");
5830 return tl::unexpected(errors::type_error);
5831 }
5832 // Optimization: Avoid copy by moving the input value.
5833 // Set init to input.
5834 init = std::move(std::get<url_pattern_init>(input));
5835 }
5836
5837 // Let processedInit be the result of process a URLPatternInit given init,
5838 // "pattern", null, null, null, null, null, null, null, and null.
5839 auto processed_init =
5840 url_pattern_init::process(init, url_pattern_init::process_type::pattern);
5841 if (!processed_init) {
5842 ada_log("url_pattern_init::process failed for init and 'pattern'");
5843 return tl::unexpected(processed_init.error());
5844 }
5845
5846 // For each componentName of "protocol", "username", "password", "hostname",
5847 // "port", "pathname", "search", "hash" If processedInit[componentName] does
5848 // not exist, then set processedInit[componentName] to "*".
5849 ADA_ASSERT_TRUE(processed_init.has_value());
5850 if (!processed_init->protocol) processed_init->protocol = "*";
5851 if (!processed_init->username) processed_init->username = "*";
5852 if (!processed_init->password) processed_init->password = "*";
5853 if (!processed_init->hostname) processed_init->hostname = "*";

Callers

nothing calls this directly

Calls 8

unexpectedClass · 0.85
is_specialFunction · 0.85
to_stringFunction · 0.85
get_special_portFunction · 0.85
is_ipv6_addressFunction · 0.85
valueMethod · 0.80
clearMethod · 0.65
has_valueMethod · 0.45

Tested by

no test coverage detected