MCPcopy Create free account
hub / github.com/IoLanguage/io / UArray_asUCS4

Function UArray_asUCS4

libs/basekit/source/UArray_utf.c:243–267  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

241}
242
243UArray *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
269void UArray_convertToUTF8(UArray *self) {
270 UArray *a = UArray_asUTF8(self);

Callers 2

UArray_convertToUCS4Function · 0.85
IoSeq_immutable.cFile · 0.85

Calls 9

UArray_isUTF8CompatibleFunction · 0.85
UArray_asUTF8Function · 0.85
UArray_newFunction · 0.85
UArray_setItemType_Function · 0.85
UArray_setEncoding_Function · 0.85
UArray_setSize_Function · 0.85
ucs4decodeFunction · 0.85
UArray_freeFunction · 0.85

Tested by

no test coverage detected