31 result[0] =
static_cast<char>(cp);
32 }
else if (cp <= 0x7FF) {
34 result[1] =
static_cast<char>(0x80 | (0x3f & cp));
35 result[0] =
static_cast<char>(0xC0 | (cp >> 6));
36 }
else if (cp <= 0xFFFF) {
38 result[2] =
static_cast<char>(0x80 | (0x3f & cp));
39 result[1] = (0x80 |
static_cast<char>((0x3f & (cp >> 6))));
40 result[0] = (0xE0 |
static_cast<char>(cp >> 12));
41 }
else if (cp <= 0x10FFFF) {
43 result[3] =
static_cast<char>(0x80 | (0x3f & cp));
44 result[2] =
static_cast<char>(0x80 | (0x3f & (cp >> 6)));
45 result[1] =
static_cast<char>(0x80 | (0x3f & (cp >> 12)));
46 result[0] =
static_cast<char>(0xF0 | (cp >> 18));
53 const unsigned char*& p,
54 const unsigned char*
const e,
66 const auto skip = [&] {
75 throw std::runtime_error(
"folly::utf8ToCodePoint empty/invalid string");
78 unsigned char fst = *p;
94 if ((fst & 0xC0) != 0xC0) {
98 throw std::runtime_error(
99 to<std::string>(
"folly::utf8ToCodePoint i=0 d=", d));
104 for (
unsigned int i = 1;
i != 4 && p +
i < e; ++
i) {
105 const unsigned char tmp = p[
i];
107 if ((tmp & 0xC0) != 0x80) {
111 throw std::runtime_error(to<std::string>(
112 "folly::utf8ToCodePoint i=",
i,
" tmp=", (
uint32_t)tmp));
115 d = (d << 6) | (tmp & 0x3F);
122 if ((d & ~bitMask[
i - 1]) == 0) {
126 throw std::runtime_error(
127 to<std::string>(
"folly::utf8ToCodePoint i=",
i,
" d=", d));
132 if ((d >= 0xD800 && d <= 0xDFFF) || d > 0x10FFFF) {
136 throw std::runtime_error(
137 to<std::string>(
"folly::utf8ToCodePoint i=",
i,
" d=", d));
149 throw std::runtime_error(
"folly::utf8ToCodePoint encoding length maxed out");
char32_t utf8ToCodePoint(const unsigned char *&p, const unsigned char *const e, bool skipOnError)
—— Concurrent Priority Queue Implementation ——
detail::Skip skip(size_t count)
std::string codePointToUtf8(char32_t cp)