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

Function UArray_asUCS2

libs/basekit/source/UArray_utf.c:215–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

213}
214
215UArray *UArray_asUCS2(const UArray *self) {
216 int convertToUtf8First = !UArray_isUTF8Compatible(self);
217 const UArray *utf8Array = convertToUtf8First ? UArray_asUTF8(self) : self;
218 size_t countedChars = UArray_numberOfCharacters(self);
219 size_t numChars;
220
221 UArray *out = UArray_new();
222 UArray_setItemType_(out, CTYPE_uint16_t);
223 UArray_setEncoding_(out, CENCODING_UCS2);
224 UArray_setSize_(out, countedChars * 2);
225
226 numChars = ucs2decode((ucs2 *)(out->data), out->size, utf8Array->data);
227
228 if ((numChars > 0) && (numChars > countedChars * 2)) {
229 printf("UArray_asUCS2 error: numChars (%i) > countedChars (2*%i)\n",
230 (int)numChars, (int)countedChars);
231 printf("Exiting because we may have overwritten the usc2 decode output "
232 "buffer.");
233 exit(-1);
234 }
235
236 UArray_setSize_(out, numChars);
237
238 if (convertToUtf8First)
239 UArray_free((UArray *)utf8Array);
240 return out;
241}
242
243UArray *UArray_asUCS4(const UArray *self) {
244 int convertToUtf8First = !UArray_isUTF8Compatible(self);

Callers 2

UArray_convertToUCS2Function · 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
ucs2decodeFunction · 0.85
UArray_freeFunction · 0.85

Tested by

no test coverage detected