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

Method set_port

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

Source from the content-addressed store, hash-verified

12815}
12816
12817bool url::set_port(const std::string_view input) {
12818 if (cannot_have_credentials_or_port()) {
12819 return false;
12820 }
12821
12822 if (input.empty()) {
12823 port = std::nullopt;
12824 return true;
12825 }
12826
12827 std::string trimmed(input);
12828 helpers::remove_ascii_tab_or_newline(trimmed);
12829
12830 if (trimmed.empty()) {
12831 return true;
12832 }
12833
12834 // Input should not start with a non-digit character.
12835 if (!ada::unicode::is_ascii_digit(trimmed.front())) {
12836 return false;
12837 }
12838
12839 // Find the first non-digit character to determine the length of digits
12840 auto first_non_digit =
12841 std::ranges::find_if_not(trimmed, ada::unicode::is_ascii_digit);
12842 std::string_view digits_to_parse =
12843 std::string_view(trimmed.data(), first_non_digit - trimmed.begin());
12844
12845 // Revert changes if parse_port fails.
12846 std::optional<uint16_t> previous_port = port;
12847 parse_port(digits_to_parse);
12848 if (is_valid) {
12849 return true;
12850 }
12851 port = std::move(previous_port);
12852 is_valid = true;
12853 return false;
12854}
12855
12856void url::set_hash(const std::string_view input) {
12857 if (input.empty()) {

Callers 4

SetPortMethod · 0.80
canonicalize_portFunction · 0.80
ada_set_portFunction · 0.80

Calls 7

is_ascii_digitFunction · 0.85
overlapsFunction · 0.85
frontMethod · 0.80
emptyMethod · 0.45
dataMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected