MCPcopy Create free account
hub / github.com/Samsung/ONE / codePointToUTF8

Function codePointToUTF8

runtime/3rdparty/jsoncpp/jsoncpp.cpp:121–155  ·  view source on GitHub ↗

Converts a unicode code-point to UTF-8.

Source from the content-addressed store, hash-verified

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

Callers 1

decodeStringMethod · 0.85

Calls 1

resizeMethod · 0.45

Tested by

no test coverage detected