| 241 | } |
| 242 | |
| 243 | UArray *UArray_asUCS4(const UArray *self) { |
| 244 | int convertToUtf8First = !UArray_isUTF8Compatible(self); |
| 245 | const UArray *utf8Array = convertToUtf8First ? UArray_asUTF8(self) : self; |
| 246 | size_t countedChars = UArray_numberOfCharacters(self); |
| 247 | size_t numChars; |
| 248 | |
| 249 | UArray *out = UArray_new(); |
| 250 | UArray_setItemType_(out, CTYPE_uint32_t); |
| 251 | UArray_setEncoding_(out, CENCODING_UCS4); |
| 252 | UArray_setSize_(out, countedChars * 2); |
| 253 | |
| 254 | numChars = ucs4decode((ucs4 *)out->data, out->size, utf8Array->data); |
| 255 | |
| 256 | if ((numChars > 0) && (numChars > countedChars * 2)) { |
| 257 | printf("UArray_asUCS4 error: numChars %i != countedChars %i\n", |
| 258 | (int)numChars, (int)countedChars); |
| 259 | exit(-1); |
| 260 | } |
| 261 | |
| 262 | UArray_setSize_(out, numChars); |
| 263 | |
| 264 | if (convertToUtf8First) |
| 265 | UArray_free((UArray *)utf8Array); |
| 266 | return out; |
| 267 | } |
| 268 | |
| 269 | void UArray_convertToUTF8(UArray *self) { |
| 270 | UArray *a = UArray_asUTF8(self); |
no test coverage detected