5#ifndef RUNTIME_PLATFORM_UNICODE_H_
6#define RUNTIME_PLATFORM_UNICODE_H_
24 return (code_point >= 0) && (code_point <= 0xFF);
27 static bool IsBmp(int32_t code_point) {
28 return (code_point >= 0) && (code_point <= 0xFFFF);
32 return (code_point > 0xFFFF) && (code_point <=
kMaxCodePoint);
57 static bool IsValid(
const uint8_t* utf8_array, intptr_t array_len);
59 static intptr_t
Length(int32_t ch);
62 static intptr_t
Encode(int32_t ch,
char*
dst);
65 static intptr_t
Decode(
const uint8_t* utf8_array,
92 static bool IsTrailByte(uint8_t code_unit) {
93 return (code_unit & 0xC0) == 0x80;
96 static bool IsNonShortestForm(uint32_t code_point,
size_t num_code_units) {
97 return code_point < kOverlongMinimum[num_code_units];
100 static bool IsLatin1SequenceStart(uint8_t code_unit) {
102 return (code_unit <= 0xC3);
105 static bool IsSupplementarySequenceStart(uint8_t code_unit) {
107 return (code_unit >= 0xF0);
110 static const int8_t kTrailBytes[];
111 static const uint32_t kMagicBits[];
112 static const uint32_t kOverlongMinimum[];
123 static bool IsSurrogate(uint32_t ch) {
return (ch & 0xFFFFF800) == 0xD800; }
127 return (ch & 0xFFFFFC00) == 0xD800;
132 return (ch & 0xFFFFFC00) == 0xDC00;
137 static int32_t
Next(
const uint16_t* characters, intptr_t*
i, intptr_t
len) {
151 static int32_t
Decode(uint16_t lead, uint16_t trail) {
152 return 0x10000 + ((lead & 0x000003FF) << 10) + (trail & 0x3FF);
156 static void Encode(int32_t codepoint, uint16_t*
dst);
165 static constexpr int32_t kLeadSurrogateOffset = (0xD800 - (0x10000 >> 10));
167 static constexpr int32_t kSurrogateOffset =
168 (0x10000 - (0xD800 << 10) - 0xDC00);
175 return Convert(code_point, kUppercase);
180 return Convert(code_point, kLowercase);
185 static constexpr int32_t kUppercase = 1;
188 static constexpr int32_t kLowercase = 2;
191 static constexpr int32_t kException = 3;
194 static constexpr int32_t kTypeShift = 2;
195 static constexpr int32_t kTypeMask = 3;
199 static constexpr intptr_t kStage1Size = 261;
202 static constexpr intptr_t kBlockSizeLog2 = 8;
203 static constexpr intptr_t kBlockSize = 1 << kBlockSizeLog2;
205 static int32_t Convert(int32_t ch, int32_t mapping) {
207 int32_t
info = stage2_[ch];
208 if ((
info & kTypeMask) == mapping) {
211 }
else if (ch <= (kStage1Size << kBlockSizeLog2)) {
212 int16_t
offset = stage1_[ch >> kBlockSizeLog2] << kBlockSizeLog2;
213 int32_t
info = stage2_[
offset + (ch & (kBlockSize - 1))];
215 if (
type == mapping) {
217 }
else if (
type == kException) {
225 static const uint8_t stage1_[];
228 static const int16_t stage2_[];
231 static const int32_t stage2_exception_[][2];
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
static int32_t ToLower(int32_t code_point)
static int32_t ToUpper(int32_t code_point)
static constexpr int32_t kMaxChar
static uint16_t TryConvertToLatin1(uint16_t c)
static bool IsSurrogate(uint32_t ch)
static constexpr int32_t kLeadSurrogateStart
static constexpr int32_t kMaxCodeUnit
static int32_t Decode(uint16_t lead, uint16_t trail)
static constexpr int32_t kTrailSurrogateStart
static void Encode(int32_t codepoint, uint16_t *dst)
static bool IsLeadSurrogate(uint32_t ch)
static intptr_t Length(int32_t ch)
static bool IsTrailSurrogate(uint32_t ch)
static constexpr int32_t kTrailSurrogateEnd
static int32_t Next(const uint16_t *characters, intptr_t *i, intptr_t len)
static constexpr int32_t kLeadSurrogateEnd
static bool DecodeCStringToUTF32(const char *str, int32_t *dst, intptr_t len)
static intptr_t Length(int32_t ch)
static bool DecodeToUTF32(const uint8_t *utf8_array, intptr_t array_len, int32_t *dst, intptr_t len)
static constexpr int32_t kMaxTwoByteChar
static constexpr int32_t kMaxFourByteChar
static intptr_t CodeUnitCount(const uint8_t *utf8_array, intptr_t array_len, Type *type)
static intptr_t ReportInvalidByte(const uint8_t *utf8_array, intptr_t array_len, intptr_t len)
static constexpr int32_t kMaxThreeByteChar
static bool IsValid(const uint8_t *utf8_array, intptr_t array_len)
static bool DecodeToUTF16(const uint8_t *utf8_array, intptr_t array_len, uint16_t *dst, intptr_t len)
static intptr_t Decode(const uint8_t *utf8_array, intptr_t array_len, int32_t *ch)
static bool DecodeToLatin1(const uint8_t *utf8_array, intptr_t array_len, uint8_t *dst, intptr_t len)
static intptr_t Encode(int32_t ch, char *dst)
static constexpr int32_t kMaxOneByteChar
static constexpr int32_t kReplacementChar
static bool IsSupplementary(int32_t code_point)
static bool IsOutOfRange(int32_t code_point)
static constexpr int32_t kMaxCodePoint
static bool IsBmp(int32_t code_point)
static constexpr int32_t kInvalidChar
static bool IsLatin1(int32_t code_point)
static T LoadUnaligned(const T *ptr)