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

Function canonicalize_pathname

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

Source from the content-addressed store, hash-verified

16229}
16230
16231tl::expected<std::string, errors> canonicalize_pathname(
16232 std::string_view input) {
16233 // If value is the empty string, then return value.
16234 if (input.empty()) [[unlikely]] {
16235 return "";
16236 }
16237 // Let leading slash be true if the first code point in value is U+002F (/)
16238 // and otherwise false.
16239 const bool leading_slash = input.starts_with("/");
16240 // Let modified value be "/-" if leading slash is false and otherwise the
16241 // empty string.
16242 const auto modified_value = leading_slash ? "" : "/-";
16243 const auto full_url =
16244 std::string("fake://fake-url") + modified_value + std::string(input);
16245 if (auto url = ada::parse<url_aggregator>(full_url, nullptr)) {
16246 const auto pathname = url->get_pathname();
16247 // If leading slash is false, then set result to the code point substring
16248 // from 2 to the end of the string within result.
16249 return leading_slash ? std::string(pathname)
16250 : std::string(pathname.substr(2));
16251 }
16252 // If parseResult is failure, then throw a TypeError.
16253 return tl::unexpected(errors::type_error);
16254}
16255
16256tl::expected<std::string, errors> canonicalize_opaque_pathname(
16257 std::string_view input) {

Callers 1

process_pathnameMethod · 0.85

Calls 3

unexpectedClass · 0.85
get_pathnameMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected