| 76 | } |
| 77 | |
| 78 | std::string strip_jsonc_comments(std::string_view text) { |
| 79 | std::string out; |
| 80 | out.reserve(text.size()); |
| 81 | bool in_string = false; |
| 82 | bool escaped = false; |
| 83 | for (size_t index = 0; index < text.size(); ++index) { |
| 84 | const char ch = text[index]; |
| 85 | if (in_string) { |
| 86 | out.push_back(ch); |
| 87 | if (escaped) { |
| 88 | escaped = false; |
| 89 | } else if (ch == '\\') { |
| 90 | escaped = true; |
| 91 | } else if (ch == '"') { |
| 92 | in_string = false; |
| 93 | } |
| 94 | continue; |
| 95 | } |
| 96 | if (ch == '"') { |
| 97 | in_string = true; |
| 98 | out.push_back(ch); |
| 99 | continue; |
| 100 | } |
| 101 | if (ch == '/' && index + 1 < text.size() && text[index + 1] == '/') { |
| 102 | while (index < text.size() && text[index] != '\n') { |
| 103 | ++index; |
| 104 | } |
| 105 | if (index < text.size()) { |
| 106 | out.push_back('\n'); |
| 107 | } |
| 108 | continue; |
| 109 | } |
| 110 | out.push_back(ch); |
| 111 | } |
| 112 | return out; |
| 113 | } |
| 114 | |
| 115 | std::string strip_jsonc_trailing_commas(std::string_view text) { |
| 116 | std::string out; |
| 117 | out.reserve(text.size()); |
| 118 | bool in_string = false; |
| 119 | bool escaped = false; |
no test coverage detected