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

Method set_host_or_hostname

test-app/runtime/src/main/cpp/ada/ada.cpp:12678–12789  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12676
12677template <bool override_hostname>
12678bool url::set_host_or_hostname(const std::string_view input) {
12679 if (has_opaque_path) {
12680 return false;
12681 }
12682
12683 std::optional<std::string> previous_host = host;
12684 std::optional<uint16_t> previous_port = port;
12685
12686 size_t host_end_pos = input.find('#');
12687 std::string _host(input.data(), host_end_pos != std::string_view::npos
12688 ? host_end_pos
12689 : input.size());
12690 helpers::remove_ascii_tab_or_newline(_host);
12691 std::string_view new_host(_host);
12692
12693 // If url's scheme is "file", then set state to file host state, instead of
12694 // host state.
12695 if (type != ada::scheme::type::FILE) {
12696 std::string_view host_view(_host.data(), _host.length());
12697 auto [location, found_colon] =
12698 helpers::get_host_delimiter_location(is_special(), host_view);
12699
12700 // Otherwise, if c is U+003A (:) and insideBrackets is false, then:
12701 // Note: the 'found_colon' value is true if and only if a colon was
12702 // encountered while not inside brackets.
12703 if (found_colon) {
12704 // If buffer is the empty string, host-missing validation error, return
12705 // failure.
12706 std::string_view buffer = host_view.substr(0, location);
12707 if (buffer.empty()) {
12708 return false;
12709 }
12710
12711 // If state override is given and state override is hostname state, then
12712 // return failure.
12713 if constexpr (override_hostname) {
12714 return false;
12715 }
12716
12717 // Let host be the result of host parsing buffer with url is not special.
12718 bool succeeded = parse_host(buffer);
12719 if (!succeeded) {
12720 host = std::move(previous_host);
12721 update_base_port(previous_port);
12722 return false;
12723 }
12724
12725 // Set url's host to host, buffer to the empty string, and state to port
12726 // state.
12727 std::string_view port_buffer = new_host.substr(location + 1);
12728 if (!port_buffer.empty()) {
12729 set_port(port_buffer);
12730 }
12731 return true;
12732 }
12733 // Otherwise, if one of the following is true:
12734 // - c is the EOF code point, U+002F (/), U+003F (?), or U+0023 (#)
12735 // - url is special and c is U+005C (\)

Callers

nothing calls this directly

Calls 9

is_specialFunction · 0.85
overlapsFunction · 0.85
findMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
lengthMethod · 0.45
emptyMethod · 0.45
has_valueMethod · 0.45

Tested by

no test coverage detected