| 284 | } |
| 285 | |
| 286 | std::string PrintableString(const char* utf) { |
| 287 | std::string result; |
| 288 | result += '"'; |
| 289 | const char* p = utf; |
| 290 | size_t char_count = CountModifiedUtf8Chars(p); |
| 291 | for (size_t i = 0; i < char_count; ++i) { |
| 292 | uint32_t ch = GetUtf16FromUtf8(&p); |
| 293 | if (ch == '\\') { |
| 294 | result += "\\\\"; |
| 295 | } else if (ch == '\n') { |
| 296 | result += "\\n"; |
| 297 | } else if (ch == '\r') { |
| 298 | result += "\\r"; |
| 299 | } else if (ch == '\t') { |
| 300 | result += "\\t"; |
| 301 | } else { |
| 302 | const uint16_t leading = GetLeadingUtf16Char(ch); |
| 303 | |
| 304 | if (NeedsEscaping(leading)) { |
| 305 | StringAppendF(&result, "\\u%04x", leading); |
| 306 | } else { |
| 307 | result += static_cast<std::string::value_type>(leading); |
| 308 | } |
| 309 | |
| 310 | const uint32_t trailing = GetTrailingUtf16Char(ch); |
| 311 | if (trailing != 0) { |
| 312 | // All high surrogates will need escaping. |
| 313 | StringAppendF(&result, "\\u%04x", trailing); |
| 314 | } |
| 315 | } |
| 316 | } |
| 317 | result += '"'; |
| 318 | return result; |
| 319 | } |
| 320 | |
| 321 | } // namespace art_lkchan |
no test coverage detected