SkUnichar SkUTF::NextUTF8(constchar** ptr, constchar* end) { if (!ptr || !end ) { return -1;
} const uint8_t* p = (const uint8_t*)*ptr; if (!p || p >= (const uint8_t*)end) { return next_fail(ptr, end);
} int c = *p; int hic = c << 24;
if (!utf8_type_is_valid_leading_byte(utf8_byte_type(c))) { return next_fail(ptr, end);
} if (hic < 0) {
uint32_t mask = (uint32_t)~0x3F;
hic = left_shift(hic, 1); do {
++p; if (p >= (const uint8_t*)end) { return next_fail(ptr, end);
} // check before reading off end of array.
uint8_t nextByte = *p; if (!utf8_byte_is_continuation(nextByte)) { return next_fail(ptr, end);
}
c = (c << 6) | (nextByte & 0x3F);
mask <<= 5;
} while ((hic = left_shift(hic, 1)) < 0);
c &= ~mask;
}
*ptr = (constchar*)p + 1; return c;
}
SkUnichar SkUTF::NextUTF8WithReplacement(constchar** ptr, constchar* end) {
SkUnichar val = SkUTF::NextUTF8(ptr, end); return val < 0 ? 0xFFFD : val;
}
SkUnichar SkUTF::NextUTF16(const uint16_t** ptr, const uint16_t* end) { if (!ptr || !end ) { return -1;
} const uint16_t* src = *ptr; if (!src || src + 1 > end || !is_align2(intptr_t(src))) { return next_fail(ptr, end);
}
uint16_t c = *src++;
SkUnichar result = c; if (utf16_is_low_surrogate(c)) { return next_fail(ptr, end); // srcPtr should never point at low surrogate.
} if (utf16_is_high_surrogate(c)) { if (src + 1 > end) { return next_fail(ptr, end); // Truncated string.
}
uint16_t low = *src++; if (!utf16_is_low_surrogate(low)) { return next_fail(ptr, end);
} /* [paraphrased from wikipedia] Take the high surrogate and subtract 0xD800, then multiply by 0x400. Take the low surrogate and subtract 0xDC00. Add these two results together, and finally add 0x10000 to get the final decoded codepoint.
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.