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

Function escape_pattern_string

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

Source from the content-addressed store, hash-verified

16622}
16623
16624std::string escape_pattern_string(std::string_view input) {
16625 ada_log("escape_pattern_string called with input=", input);
16626 if (input.empty()) [[unlikely]] {
16627 return "";
16628 }
16629 // Assert: input is an ASCII string.
16630 ADA_ASSERT_TRUE(ada::idna::is_ascii(input));
16631 // Let result be the empty string.
16632 std::string result{};
16633 result.reserve(input.size());
16634
16635 // TODO: Optimization opportunity: Use a lookup table
16636 constexpr auto should_escape = [](const char c) {
16637 return c == '+' || c == '*' || c == '?' || c == ':' || c == '{' ||
16638 c == '}' || c == '(' || c == ')' || c == '\\';
16639 };
16640
16641 // While index is less than input's length:
16642 for (const auto& c : input) {
16643 if (should_escape(c)) {
16644 // then append U+005C (\) to the end of result.
16645 result.append("\\");
16646 }
16647
16648 // Append c to the end of result.
16649 result += c;
16650 }
16651 // Return result.
16652 return result;
16653}
16654
16655namespace {
16656constexpr std::array<uint8_t, 256> escape_regexp_table = []() consteval {

Callers 2

process_base_url_stringFunction · 0.85
generate_pattern_stringFunction · 0.85

Calls 5

is_asciiFunction · 0.85
appendMethod · 0.65
emptyMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected