MCPcopy Create free account
hub / github.com/antvis/F2Native / oneUtf8Convert2Utf16

Function oneUtf8Convert2Utf16

core/android/JNIUtil.cpp:121–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119}
120
121static int oneUtf8Convert2Utf16(const std::string &utf8Str, int start, char *output) {
122 char b1, b2, b3;
123 int utf8Len = getutf8Length(utf8Str[start]);
124 // assert(utf8Len >= 1 && utf8Len <= 3);
125 if(utf8Len == 1) {
126 *output = utf8Str[start];
127 } else if(utf8Len == 2) {
128 b1 = utf8Str[start];
129 b2 = utf8Str[start + 1];
130 if((b2 & 0xE0) != 0x80)
131 return utf8Len;
132 *output = (b1 << 6) + (b2 & 0x3F);
133 *(output + 1) = (b1 >> 2) & 0x07;
134 } else if(utf8Len == 3) {
135 b1 = utf8Str[start];
136 b2 = utf8Str[start + 1];
137 b3 = utf8Str[start + 2];
138 if(((b2 & 0xC0) != 0x80) || ((b3 & 0xC0) != 0x80))
139 return utf8Len;
140 *output = (b2 << 6) + (b3 & 0x3F);
141 *(output + 1) = (b1 << 4) + ((b2 >> 2) & 0x0F);
142 }
143 return utf8Len;
144}
145
146static std::u16string utf8Couver2Utf16(const std::string &utf8str) {
147 std::u16string ret;

Callers 1

utf8Couver2Utf16Function · 0.85

Calls 1

getutf8LengthFunction · 0.85

Tested by

no test coverage detected