// Four byte encodings need special handling. We'll have // to convert them into a surrogate pair. const uint8_t four = *(*utf8_data_in)++;
// Since this is a 4 byte UTF-8 sequence, it will lie between // U+10000 and U+1FFFFF. // // TODO: What do we do about values in (U+10FFFF, U+1FFFFF) ? The // spec says they're invalid but nobody appears to check for them. const uint32_t code_point = ((one & 0x0f) << 18) | ((two & 0x3f) << 12)
| ((three & 0x3f) << 6) | (four & 0x3f);
uint32_t surrogate_pair = 0; // Step two: Write out the high (leading) surrogate to the bottom 16 bits // of the of the 32 bit type.
surrogate_pair |= ((code_point >> 10) + 0xd7c0) & 0xffff; // Step three : Write out the low (trailing) surrogate to the top 16 bits.
surrogate_pair |= ((code_point & 0x03ff) + 0xdc00) << 16;
return surrogate_pair;
}
// Note: This is a copy of the code in `libdexfile`. template <bool kUseShortZero, bool kUse4ByteSequence, bool kReplaceBadSurrogates, typename Append> inlinevoid ConvertUtf16ToUtf8(const uint16_t* utf16, size_t char_count, Append&& append) {
static_assert(kUse4ByteSequence || !kReplaceBadSurrogates);
// Use local helpers instead of macros from `libicu` to avoid the dependency on `libicu`. auto is_lead = [](uint16_t ch) ALWAYS_INLINE { return (ch & 0xfc00u) == 0xd800u; }; auto is_trail = [](uint16_t ch) ALWAYS_INLINE { return (ch & 0xfc00u) == 0xdc00u; }; auto is_surrogate = [](uint16_t ch) ALWAYS_INLINE { return (ch & 0xf800u) == 0xd800u; }; auto is_surrogate_lead = [](uint16_t ch) ALWAYS_INLINE { return (ch & 0x0400u) == 0u; }; auto get_supplementary = [](uint16_t lead, uint16_t trail) ALWAYS_INLINE {
constexpr uint32_t offset = (0xd800u << 10) + 0xdc00u - 0x10000u; return (static_cast<uint32_t>(lead) << 10) + static_cast<uint32_t>(trail) - offset;
};
for (size_t i = 0u; i < char_count; ++i) { auto has_trail = [&]() { return i + 1u != char_count && is_trail(utf16[i + 1u]); };
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.