MCPcopy Create free account
hub / github.com/cuberite/cuberite / codePointToUTF8

Function codePointToUTF8

lib/jsoncpp/src/lib_json/json_reader.cpp:69–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

67}
68
69static std::string codePointToUTF8(unsigned int cp)
70{
71 std::string result;
72
73 // based on description from http://en.wikipedia.org/wiki/UTF-8
74
75 if (cp <= 0x7f)
76 {
77 result.resize(1);
78 result[0] = static_cast<char>(cp);
79 }
80 else if (cp <= 0x7FF)
81 {
82 result.resize(2);
83 result[1] = static_cast<char>(0x80 | (0x3f & cp));
84 result[0] = static_cast<char>(0xC0 | (0x1f & (cp >> 6)));
85 }
86 else if (cp <= 0xFFFF)
87 {
88 result.resize(3);
89 result[2] = static_cast<char>(0x80 | (0x3f & cp));
90 result[1] = 0x80 | static_cast<char>((0x3f & (cp >> 6)));
91 result[0] = 0xE0 | static_cast<char>((0xf & (cp >> 12)));
92 }
93 else if (cp <= 0x10FFFF)
94 {
95 result.resize(4);
96 result[3] = static_cast<char>(0x80 | (0x3f & cp));
97 result[2] = static_cast<char>(0x80 | (0x3f & (cp >> 6)));
98 result[1] = static_cast<char>(0x80 | (0x3f & (cp >> 12)));
99 result[0] = static_cast<char>(0xF0 | (0x7 & (cp >> 18)));
100 }
101
102 return result;
103}
104
105
106// Class Reader

Callers 1

decodeStringMethod · 0.85

Calls 1

resizeMethod · 0.80

Tested by

no test coverage detected