MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / codePointToUTF8

Function codePointToUTF8

json/jsoncpp.cpp:127–153  ·  view source on GitHub ↗

Converts a unicode code-point to UTF-8.

Source from the content-addressed store, hash-verified

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