MCPcopy Create free account
hub / github.com/ada-url/ada / escape_pattern_string

Function escape_pattern_string

src/url_pattern_helpers.cpp:903–926  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

901} // namespace
902
903std::string escape_pattern_string(std::string_view input) {
904 ada_log("escape_pattern_string called with input=", input);
905 if (input.empty()) [[unlikely]] {
906 return "";
907 }
908 // Assert: input is an ASCII string.
909 ADA_ASSERT_TRUE(ada::idna::is_ascii(input));
910 // Let result be the empty string.
911 std::string result{};
912 // Reserve extra space for potential escapes
913 result.reserve(input.size() * 2);
914
915 // While index is less than input's length:
916 for (const char c : input) {
917 if (should_escape_pattern_char(c)) {
918 // Append U+005C (\) to the end of result.
919 result.push_back('\\');
920 }
921 // Append c to the end of result.
922 result.push_back(c);
923 }
924 // Return result.
925 return result;
926}
927
928namespace {
929constexpr std::array<uint8_t, 256> escape_regexp_table = []() consteval {

Callers 2

process_base_url_stringFunction · 0.85
generate_pattern_stringFunction · 0.85

Calls 4

reserveMethod · 0.80
sizeMethod · 0.80
is_asciiFunction · 0.70

Tested by

no test coverage detected