| 901 | } // namespace |
| 902 | |
| 903 | std::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 | |
| 928 | namespace { |
| 929 | constexpr std::array<uint8_t, 256> escape_regexp_table = []() consteval { |
no test coverage detected