21 constexpr char no =
static_cast<char>(-1);
24 no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
25 no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
26 no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
27 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
no,
no,
no,
no,
no,
no,
28 no, 10, 11, 12, 13, 14, 15,
no,
no,
no,
no,
no,
no,
no,
no,
no,
29 no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
30 no, 10, 11, 12, 13, 14, 15,
no,
no,
no,
no,
no,
no,
no,
no,
no,
31 no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
no,
38 int32_t codepoint_ = 0;
41 for (
const char* s = input; *s != 0; ++s)
43 codepoint_ = (codepoint_ << shift) | details::ASCIIHexToInt[static_cast<std::size_t>(*s)];
50 if (codepoint_ >= 0x0000 && codepoint_ <= 0x007f)
52 if (codepoint_ > 0x007f && codepoint_ <= 0x07ff)
54 if (codepoint_ > 0x07ff && codepoint_ <= 0xffff)
56 if (codepoint_ > 0xffff && codepoint_ <= 0x10ffff)
67 inline void decode(
const char* input,
char* dest)
80 dest[0] =
static_cast<char>(cdp);
87 dest[0] =
static_cast<char>((0xc0 | ((c1 & 0x7) << 2)) | ((c2 & 0xc) >> 2));
88 dest[1] =
static_cast<char>((0x80 | ((c2 & 0x3) << 4)) | c3);
95 dest[0] =
static_cast<char>(0xe0 | c0);
96 dest[1] =
static_cast<char>((0x80 | (c1 << 2)) | ((c2 & 0xc) >> 2));
97 dest[2] =
static_cast<char>((0x80 | ((c2 & 0x3) << 4)) | c3);
108 dest[0] =
static_cast<char>(0xf0 | ((c0 & 0xc) >> 2));
109 dest[1] =
static_cast<char>((0x80 | ((c0 & 0x3) << 4)) | c1);
110 dest[2] =
static_cast<char>((0x80 | (c2 << 2)) | ((c3 & 0xc) >> 2));
111 dest[3] =
static_cast<char>((0x80 | ((c3 & 0x3) << 4)) | c4);
118 dest[0] =
static_cast<char>((0xf0 | ((c0 & 0x1) << 2)) | ((c1 & 0xc) >> 2));
119 dest[1] =
static_cast<char>(((0x80 | ((c1 & 0x3) << 4)) | ((c1 & 0xc) >> 2)) | c2);
120 dest[2] =
static_cast<char>((0x80 | (c3 << 2)) | ((c4 & 0xc) >> 2));
121 dest[3] =
static_cast<char>((0x80 | ((c4 & 0x3) << 4)) | c5);
147 if (0xf0 == (0xf8 & *s))
149 if ((0x80 != (0xc0 & s[1])) || (0x80 != (0xc0 & s[2])) || (0x80 != (0xc0 & s[3])))
151 if (0x80 == (0xc0 & s[4]))
153 if ((0 == (0x07 & s[0])) && (0 == (0x30 & s[1])))
157 else if (0xe0 == (0xf0 & *s))
159 if ((0x80 != (0xc0 & s[1])) || (0x80 != (0xc0 & s[2])))
161 if (0x80 == (0xc0 & s[3]))
163 if ((0 == (0x0f & s[0])) && (0 == (0x20 & s[1])))
167 else if (0xc0 == (0xe0 & *s))
169 if (0x80 != (0xc0 & s[1]))
171 if (0x80 == (0xc0 & s[2]))
173 if (0 == (0x1e & s[0]))
177 else if (0x00 == (0x80 & *s))
186 inline std::size_t
length(
const char* str)
188 std::size_t count = 0;
196 if (0xf0 == (0xf8 & *s))
201 else if (0xe0 == (0xf0 & *s))
206 else if (0xc0 == (0xe0 & *s))
211 else if (0x00 == (0x80 & *s))
236 if (0xf0 == (0xf8 & *s))
237 c = ((0x07 & s[0]) << 18) | ((0x3f & s[1]) << 12) | ((0x3f & s[2]) << 6) | (0x3f & s[3]);
238 else if (0xe0 == (0xf0 & *s))
239 c = ((0x0f & s[0]) << 12) | ((0x3f & s[1]) << 6) | (0x3f & s[2]);
240 else if (0xc0 == (0xe0 & *s))
241 c = ((0x1f & s[0]) << 6) | (0x3f & s[1]);
242 else if (0x00 == (0x80 & *s))
265 dest[0] =
static_cast<char>(-128);
267 dest[0] |=
static_cast<char>((
codepoint >> 6));
268 dest[0] |=
static_cast<char>(((
codepoint & 0xc0) >> 6));
269 dest[1] =
static_cast<char>(0x80 | (
codepoint & 0x3f));
274 dest[0] =
static_cast<char>(-32);
276 dest[0] |=
static_cast<char>(((
codepoint & 0xf000) >> 12));
277 dest[1] =
static_cast<char>((0x80 | ((
codepoint & 0xf00) >> 6)) | ((
codepoint & 0xf0) >> 6));
283 dest[0] =
static_cast<char>(-16);
285 dest[0] |=
static_cast<char>(((
codepoint & 0x100000) >> 18));
286 dest[0] |=
static_cast<char>(((
codepoint & 0xc0000) >> 18));
287 dest[1] =
static_cast<char>((0x80 | ((
codepoint & 0x30000) >> 12)) | ((
codepoint & 0xf000) >> 12));
288 dest[2] =
static_cast<char>((0x80 | ((
codepoint & 0xf00) >> 6)) | ((
codepoint & 0xc0) >> 6));
constexpr std::array< char, 128 > ASCIIHexToInt
Utf8Type utf8type(const char *input, int32_t *out=nullptr)
std::size_t length(const char *str)
void codepointToUtf8(const int32_t codepoint, char *dest)
Generate an UTF8 character from a given codepoint.
int32_t codepoint(const char *str)
Compute the UTF8 codepoint for a given UTF8 char.
bool isValid(const char *str)
Check the validity of a given string in UTF8.
void decode(const char *input, char *dest)
Convert hex string to utf8 string.