| 186 | static const char32_t MAX_CODEPOINT = 0x10ffff; |
| 187 | |
| 188 | Utf32Type 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 | |
| 213 | std::string hexStringFromUtf32(Utf32Type character) { |
| 214 | if (character > MAX_CODEPOINT) |
no test coverage detected