// This is used only from debugger and test code.
size_t CountModifiedUtf8Chars(constchar* utf8) { return CountModifiedUtf8Chars(utf8, strlen(utf8));
}
/* *ThisdoesnotvalidateUTF8rules(nordidoldercode).Butitgetstherightanswer *forvalidUTF-8andthat'sfinebecauseit'susedonlytosizeabufferforlater *conversion. * *ModifiedUTF-8consistsofaseriesofbytesupto21bitUnicodecodepointsasfollows: *U+0001-U+007F0xxxxxxx *U+0080-U+07FF110xxxxx10xxxxxx *U+0800-U+FFFF1110xxxx10xxxxxx10xxxxxx *U+10000-U+1FFFFF11110xxx10xxxxxx10xxxxxx10xxxxxx * *U+0000isencodedusingthe2ndformtoavoidnullsinsidestrings(thisdiffersfrom *standardUTF-8). *Thefourbyteencodingconvertstotwoutf16characters.
*/
size_t CountModifiedUtf8Chars(constchar* utf8, size_t byte_count) {
DCHECK_LE(byte_count, strlen(utf8));
size_t len = 0; constchar* end = utf8 + byte_count; for (; utf8 < end; ++utf8) { int ic = *utf8;
len++; if (LIKELY((ic & 0x80) == 0)) { // One-byte encoding. continue;
} // Two- or three-byte encoding.
utf8++; if ((ic & 0x20) == 0) { // Two-byte encoding. continue;
}
utf8++; if ((ic & 0x10) == 0) { // Three-byte encoding. continue;
}
// Four-byte encoding: needs to be converted into a surrogate // pair.
utf8++;
len++;
} return len;
}
// This is used only from debugger and test code. void ConvertModifiedUtf8ToUtf16(uint16_t* utf16_data_out, constchar* utf8_data_in) { while (*utf8_data_in != '\0') { const uint32_t ch = GetUtf16FromUtf8(&utf8_data_in); const uint16_t leading = GetLeadingUtf16Char(ch); const uint16_t trailing = GetTrailingUtf16Char(ch);
if (LIKELY(out_chars == in_bytes)) { // Common case where all characters are ASCII. for (constchar *p = in_start; p < in_end;) { // Safe even if char is signed because ASCII characters always have // the high bit cleared.
*out_p++ = dchecked_integral_cast<uint16_t>(*p++);
} return;
}
// String contains non-ASCII characters. for (constchar *p = in_start; p < in_end;) { const uint32_t ch = GetUtf16FromUtf8(&p); const uint16_t leading = GetLeadingUtf16Char(ch); const uint16_t trailing = GetTrailingUtf16Char(ch);
// First compare the leading utf16 char. const uint16_t lhs = GetLeadingUtf16Char(pair); const uint16_t rhs = *utf16++;
--utf16_length; if (lhs != rhs) { return lhs > rhs ? 1 : -1;
}
// Then compare the trailing utf16 char. First check if there // are any characters left to consume. const uint16_t lhs2 = GetTrailingUtf16Char(pair); if (lhs2 != 0) { if (utf16_length == 0) { return1;
}
std::string PrintableChar(uint16_t ch) {
std::string result;
result += '\''; if (NeedsEscaping(ch)) {
StringAppendF(&result, "\\u%04x", ch);
} else {
result += static_cast<std::string::value_type>(ch);
}
result += '\''; return result;
}
std::string PrintableString(constchar* utf8) {
std::string result;
result += '"'; constchar* p = utf8;
size_t char_count = CountModifiedUtf8Chars(p); for (size_t i = 0; i < char_count; ++i) {
uint32_t ch = GetUtf16FromUtf8(&p); if (ch == '\\') {
result += "\\\\";
} elseif (ch == '\n') {
result += "\\n";
} elseif (ch == '\r') {
result += "\\r";
} elseif (ch == '\t') {
result += "\\t";
} else { const uint16_t leading = GetLeadingUtf16Char(ch);
if (NeedsEscaping(leading)) {
StringAppendF(&result, "\\u%04x", leading);
} else {
result += static_cast<std::string::value_type>(leading);
}
const uint32_t trailing = GetTrailingUtf16Char(ch); if (trailing != 0) { // All high surrogates will need escaping.
StringAppendF(&result, "\\u%04x", trailing); // Account for the surrogate pair.
++i;
DCHECK_LT(i, char_count);
}
}
}
result += '"'; return result;
}
} // namespace art
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet am 2026-06-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.