MCPcopy Create free account
hub / github.com/Kitware/CMake / codePointToUTF8

Function codePointToUTF8

Utilities/cmjsoncpp/src/lib_json/json_tool.h:39–65  ·  view source on GitHub ↗

Converts a unicode code-point to UTF-8.

Source from the content-addressed store, hash-verified

37
38/// Converts a unicode code-point to UTF-8.
39static inline String codePointToUTF8(unsigned int cp) {
40 String result;
41
42 // based on description from http://en.wikipedia.org/wiki/UTF-8
43
44 if (cp <= 0x7f) {
45 result.resize(1);
46 result[0] = static_cast<char>(cp);
47 } else if (cp <= 0x7FF) {
48 result.resize(2);
49 result[1] = static_cast<char>(0x80 | (0x3f & cp));
50 result[0] = static_cast<char>(0xC0 | (0x1f & (cp >> 6)));
51 } else if (cp <= 0xFFFF) {
52 result.resize(3);
53 result[2] = static_cast<char>(0x80 | (0x3f & cp));
54 result[1] = static_cast<char>(0x80 | (0x3f & (cp >> 6)));
55 result[0] = static_cast<char>(0xE0 | (0xf & (cp >> 12)));
56 } else if (cp <= 0x10FFFF) {
57 result.resize(4);
58 result[3] = static_cast<char>(0x80 | (0x3f & cp));
59 result[2] = static_cast<char>(0x80 | (0x3f & (cp >> 6)));
60 result[1] = static_cast<char>(0x80 | (0x3f & (cp >> 12)));
61 result[0] = static_cast<char>(0xF0 | (0x7 & (cp >> 18)));
62 }
63
64 return result;
65}
66
67enum {
68 /// Constant that specify the size of the buffer that must be passed to

Callers 1

decodeStringMethod · 0.85

Calls 1

resizeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…