MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / hexStringToUtf32

Function hexStringToUtf32

source/core/StarUnicode.cpp:188–211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

186static const char32_t MAX_CODEPOINT = 0x10ffff;
187
188Utf32Type hexStringToUtf32(std::string const& codepoint, Maybe<Utf32Type> previousCodepoint) {
189 bool continuation = false;
190 if (previousCodepoint && isUtf16LeadSurrogate(*previousCodepoint)) {
191 continuation = true;
192 }
193
194 auto hexBytes = hexDecode(codepoint);
195 if (hexBytes.size() < sizeof(Utf32Type)) {
196 ByteArray newHexBytes{(size_t)(sizeof(Utf32Type) - hexBytes.size()), (char)'\0'};
197 newHexBytes.append(hexBytes);
198 hexBytes = newHexBytes;
199 }
200
201 if (hexBytes.size() > sizeof(Utf32Type))
202 throw UnicodeException("Codepoint size is too big in parseUnicodeCodepoint");
203
204 auto res = fromBigEndian(*(Utf32Type*)hexBytes.ptr());
205
206 if (continuation) {
207 res = utf32FromUtf16SurrogatePair(*previousCodepoint, res);
208 }
209
210 return res;
211}
212
213std::string hexStringFromUtf32(Utf32Type character) {
214 if (character > MAX_CODEPOINT)

Callers 2

parseStringMethod · 0.85

Calls 7

isUtf16LeadSurrogateFunction · 0.85
hexDecodeFunction · 0.85
fromBigEndianFunction · 0.85
sizeMethod · 0.45
appendMethod · 0.45
ptrMethod · 0.45

Tested by

no test coverage detected