MCPcopy Create free account
hub / github.com/PlayFab/gsdk / codePointToUTF8

Function codePointToUTF8

cpp/cppsdk/jsoncpp.cpp:125–151  ·  view source on GitHub ↗

Converts a unicode code-point to UTF-8.

Source from the content-addressed store, hash-verified

123
124/// Converts a unicode code-point to UTF-8.
125static inline JSONCPP_STRING codePointToUTF8(unsigned int cp) {
126 JSONCPP_STRING result;
127
128 // based on description from http://en.wikipedia.org/wiki/UTF-8
129
130 if (cp <= 0x7f) {
131 result.resize(1);
132 result[0] = static_cast<char>(cp);
133 } else if (cp <= 0x7FF) {
134 result.resize(2);
135 result[1] = static_cast<char>(0x80 | (0x3f & cp));
136 result[0] = static_cast<char>(0xC0 | (0x1f & (cp >> 6)));
137 } else if (cp <= 0xFFFF) {
138 result.resize(3);
139 result[2] = static_cast<char>(0x80 | (0x3f & cp));
140 result[1] = static_cast<char>(0x80 | (0x3f & (cp >> 6)));
141 result[0] = static_cast<char>(0xE0 | (0xf & (cp >> 12)));
142 } else if (cp <= 0x10FFFF) {
143 result.resize(4);
144 result[3] = static_cast<char>(0x80 | (0x3f & cp));
145 result[2] = static_cast<char>(0x80 | (0x3f & (cp >> 6)));
146 result[1] = static_cast<char>(0x80 | (0x3f & (cp >> 12)));
147 result[0] = static_cast<char>(0xF0 | (0x7 & (cp >> 18)));
148 }
149
150 return result;
151}
152
153enum {
154 /// Constant that specify the size of the buffer that must be passed to

Callers 1

decodeStringMethod · 0.85

Calls 1

resizeMethod · 0.80

Tested by

no test coverage detected