Helper routine to encode "s" and append to "*dest", escaping special characters.
| 161 | // Helper routine to encode "s" and append to "*dest", escaping special |
| 162 | // characters. |
| 163 | inline static void EncodeStringFragment(string* dest, StringPiece s) { |
| 164 | const char* p = s.data(); |
| 165 | const char* limit = p + s.size(); |
| 166 | const char* copy_start = p; |
| 167 | while (true) { |
| 168 | p = SkipToNextSpecialByte(p, limit); |
| 169 | if (p >= limit) break; // No more special characters that need escaping |
| 170 | char c = *(p++); |
| 171 | DCHECK(IsSpecialByte(c)); |
| 172 | if (c == kEscape1) { |
| 173 | AppendBytes(dest, copy_start, p - copy_start - 1); |
| 174 | dest->push_back(kEscape1); |
| 175 | dest->push_back(kNullCharacter); |
| 176 | copy_start = p; |
| 177 | } else { |
| 178 | assert(c == kEscape2); |
| 179 | AppendBytes(dest, copy_start, p - copy_start - 1); |
| 180 | dest->push_back(kEscape2); |
| 181 | dest->push_back(kFFCharacter); |
| 182 | copy_start = p; |
| 183 | } |
| 184 | } |
| 185 | if (p > copy_start) { |
| 186 | AppendBytes(dest, copy_start, p - copy_start); |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | void OrderedCode::WriteString(string* dest, StringPiece s) { |
| 191 | EncodeStringFragment(dest, s); |
no test coverage detected