MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / code_point_to_utf8

Function code_point_to_utf8

extlibs/sol3/include/sol/sol.hpp:11455–11487  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11453 };
11454
11455 inline encoded_result<char> code_point_to_utf8(char32_t codepoint) {
11456 encoded_result<char> er;
11457 er.error = error_code::ok;
11458 if (codepoint <= unicode_detail::last_1byte_value) {
11459 er.code_units_size = 1;
11460 er.code_units = std::array<char, 4>{ { static_cast<char>(codepoint) } };
11461 }
11462 else if (codepoint <= unicode_detail::last_2byte_value) {
11463 er.code_units_size = 2;
11464 er.code_units = std::array<char, 4>{{
11465 static_cast<char>(0xC0 | ((codepoint & 0x7C0) >> 6)),
11466 static_cast<char>(0x80 | (codepoint & 0x3F)),
11467 }};
11468 }
11469 else if (codepoint <= unicode_detail::last_3byte_value) {
11470 er.code_units_size = 3;
11471 er.code_units = std::array<char, 4>{{
11472 static_cast<char>(0xE0 | ((codepoint & 0xF000) >> 12)),
11473 static_cast<char>(0x80 | ((codepoint & 0xFC0) >> 6)),
11474 static_cast<char>(0x80 | (codepoint & 0x3F)),
11475 }};
11476 }
11477 else {
11478 er.code_units_size = 4;
11479 er.code_units = std::array<char, 4>{ {
11480 static_cast<char>(0xF0 | ((codepoint & 0x1C0000) >> 18)),
11481 static_cast<char>(0x80 | ((codepoint & 0x3F000) >> 12)),
11482 static_cast<char>(0x80 | ((codepoint & 0xFC0) >> 6)),
11483 static_cast<char>(0x80 | (codepoint & 0x3F)),
11484 } };
11485 }
11486 return er;
11487 }
11488
11489 inline encoded_result<char16_t> code_point_to_utf16(char32_t codepoint) {
11490 encoded_result<char16_t> er;

Callers 4

convert_intoMethod · 0.85
pushMethod · 0.85
convert_intoMethod · 0.85
pushMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected