| 82 | } |
| 83 | |
| 84 | std::string StringRefId::toDebugString() const |
| 85 | { |
| 86 | std::string result; |
| 87 | result.reserve(2 + mValue->size()); |
| 88 | result.push_back('"'); |
| 89 | const unsigned char* ptr = reinterpret_cast<const unsigned char*>(mValue->data()); |
| 90 | const unsigned char* const end = reinterpret_cast<const unsigned char*>(mValue->data() + mValue->size()); |
| 91 | while (ptr != end) |
| 92 | { |
| 93 | if (Utf8Stream::isAscii(*ptr)) |
| 94 | { |
| 95 | if (std::isprint(*ptr) && *ptr != '\t' && *ptr != '\n' && *ptr != '\r') |
| 96 | result.push_back(*ptr); |
| 97 | else |
| 98 | addHex(*ptr, result); |
| 99 | ++ptr; |
| 100 | continue; |
| 101 | } |
| 102 | const auto [octets, first] = Utf8Stream::getOctetCount(*ptr); |
| 103 | const auto [chr, next] = Utf8Stream::decode(ptr + 1, end, first, octets); |
| 104 | if (chr == Utf8Stream::sBadChar()) |
| 105 | { |
| 106 | while (ptr != std::min(end, ptr + octets)) |
| 107 | { |
| 108 | addHex(*ptr, result); |
| 109 | ++ptr; |
| 110 | } |
| 111 | continue; |
| 112 | } |
| 113 | result.append(ptr, next); |
| 114 | ptr = next; |
| 115 | } |
| 116 | result.push_back('"'); |
| 117 | return result; |
| 118 | } |
| 119 | |
| 120 | bool StringRefId::startsWith(std::string_view prefix) const |
| 121 | { |