Escapes a string so it can be safely matched within JSON-serialized text.
| 89 | |
| 90 | // Escapes a string so it can be safely matched within JSON-serialized text. |
| 91 | static string JsonEscapeString(const string_view& input) { |
| 92 | StringBuffer buffer; |
| 93 | Writer<StringBuffer> writer(buffer); |
| 94 | writer.String(input.data(), static_cast<rapidjson::SizeType>(input.size())); |
| 95 | const char* p = buffer.GetString(); |
| 96 | const size_t n = buffer.GetSize(); |
| 97 | const size_t start = n >= 1 && p[0] == '"' ? 1 : 0; |
| 98 | const size_t end = n >= 1 && p[n - 1] == '"' ? n - 1 : n; |
| 99 | if (end < start) return ""; |
| 100 | return string(p + start, end - start); |
| 101 | } |
| 102 | |
| 103 | // Collects unique regex matches from text for the requested capture group. |
| 104 | static vector<string> CollectRegexMatches( |