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

Method parse_scheme

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

Source from the content-addressed store, hash-verified

12339
12340template <bool has_state_override>
12341ada_really_inline bool url::parse_scheme(const std::string_view input) {
12342 auto parsed_type = ada::scheme::get_scheme_type(input);
12343 bool is_input_special = (parsed_type != ada::scheme::NOT_SPECIAL);
12344 /**
12345 * In the common case, we will immediately recognize a special scheme (e.g.,
12346 *http, https), in which case, we can go really fast.
12347 **/
12348 if (is_input_special) { // fast path!!!
12349 if constexpr (has_state_override) {
12350 // If url's scheme is not a special scheme and buffer is a special scheme,
12351 // then return.
12352 if (is_special() != is_input_special) {
12353 return false;
12354 }
12355
12356 // If url includes credentials or has a non-null port, and buffer is
12357 // "file", then return.
12358 if ((has_credentials() || port.has_value()) &&
12359 parsed_type == ada::scheme::type::FILE) {
12360 return false;
12361 }
12362
12363 // If url's scheme is "file" and its host is an empty host, then return.
12364 // An empty host is the empty string.
12365 if (type == ada::scheme::type::FILE && host.has_value() &&
12366 host.value().empty()) {
12367 return false;
12368 }
12369 }
12370
12371 type = parsed_type;
12372
12373 if constexpr (has_state_override) {
12374 // This is uncommon.
12375 uint16_t urls_scheme_port = get_special_port();
12376
12377 if (urls_scheme_port) {
12378 // If url's port is url's scheme's default port, then set url's port to
12379 // null.
12380 if (port.has_value() && *port == urls_scheme_port) {
12381 port = std::nullopt;
12382 }
12383 }
12384 }
12385 } else { // slow path
12386 std::string _buffer(input);
12387 // Next function is only valid if the input is ASCII and returns false
12388 // otherwise, but it seems that we always have ascii content so we do not
12389 // need to check the return value.
12390 // bool is_ascii =
12391 unicode::to_lower_ascii(_buffer.data(), _buffer.size());
12392
12393 if constexpr (has_state_override) {
12394 // If url's scheme is a special scheme and buffer is not a special scheme,
12395 // then return. If url's scheme is not a special scheme and buffer is a
12396 // special scheme, then return.
12397 if (is_special() != ada::scheme::is_special(_buffer)) {
12398 return true;

Callers 1

parse_url_implFunction · 0.80

Calls 9

get_scheme_typeFunction · 0.85
is_specialFunction · 0.85
get_special_portFunction · 0.85
to_lower_asciiFunction · 0.85
valueMethod · 0.80
has_valueMethod · 0.45
emptyMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected