MCPcopy Create free account
hub / github.com/cocos/cocos-engine / UTF8ToUTF16

Function UTF8ToUTF16

native/cocos/base/UTF8.cpp:221–245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

219}
220
221bool UTF8ToUTF16(const ccstd::string &utf8, std::u16string &outUtf16) { //NOLINT
222#if CC_USE_SIMD_UTF
223 bool validutf8 = simdutf::validate_utf8(utf8.c_str(), utf8.length());
224 if (!validutf8) {
225 outUtf16.clear();
226 return false;
227 }
228
229 // We need a buffer of size where to write the UTF-16LE words.
230 size_t expectedUtf16words = simdutf::utf16_length_from_utf8(utf8.c_str(), utf8.length());
231 outUtf16.resize(expectedUtf16words);
232
233 // convert to UTF-16LE
234 size_t utf16words = simdutf::convert_utf8_to_utf16le(utf8.c_str(), utf8.length(), outUtf16.data());
235 bool validutf16 = simdutf::validate_utf16le(outUtf16.c_str(), utf16words);
236 if (!validutf16) {
237 outUtf16.clear();
238 return false;
239 }
240
241 return true;
242#else
243 return utfConvert(utf8, outUtf16, ConvertUTF8toUTF16);
244#endif
245}
246
247bool UTF8ToUTF32(const ccstd::string &utf8, std::u32string &outUtf32) { //NOLINT
248 return utfConvert(utf8, outUtf32, ConvertUTF8toUTF32);

Callers 14

showMessageBoxMethod · 0.85
setTitleMethod · 0.85
addItemMethod · 0.85
setFontMethod · 0.85
saveFileMethod · 0.85
openDirectoryMethod · 0.85
parseExtensionsMethod · 0.85
openMultipleInternalMethod · 0.85
runInTerminalMethod · 0.85
makeCommandLineMethod · 0.85
updateWindowTitleMethod · 0.85
newStringUTFJNIFunction · 0.85

Calls 5

utfConvertFunction · 0.85
clearMethod · 0.65
lengthMethod · 0.45
resizeMethod · 0.45
dataMethod · 0.45

Tested by 1

Utf8ToStringViewFunction · 0.68