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

Function UArray_asUTF8

libs/basekit/source/UArray_utf.c:155–208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153}
154
155UArray *UArray_asUTF8(const UArray *self) {
156 UArray *out = UArray_new();
157 UArray_setItemType_(out, CTYPE_uint8_t);
158 UArray_setEncoding_(out, CENCODING_UTF8);
159 UArray_setSize_(out, self->size * 4);
160
161 {
162 // ConversionFlags options = lenientConversion;
163 void *sourceStart = self->data;
164 // void *sourceEnd = self->data + self->size * self->itemSize;
165 UTF8 *targetStart = out->data;
166 // UTF8 *targetEnd = out->data + out->size * out->itemSize;
167 size_t outSize;
168
169 switch (self->encoding) {
170 case CENCODING_ASCII:
171 UArray_copy_(out, self);
172 break;
173 case CENCODING_UTF8:
174 UArray_copy_(out, self);
175 break;
176 /*
177 case CENCODING_UTF16:
178 r = ConvertUTF16toUTF8((const UTF16 **)&sourceStart, (const UTF16
179 *)sourceEnd, &targetStart, targetEnd, options); break; case CENCODING_UTF32:
180 r = ConvertUTF32toUTF8((const UTF32 **)&sourceStart, (const UTF32
181 *)sourceEnd, &targetStart, targetEnd, options); break;
182 */
183 case CENCODING_UCS2:
184 // should the size be the num of chars or num of bytes??????????
185 outSize = ucs2encode(targetStart, sourceStart, self->size,
186 NULL); // ucs2 to utf8
187 UArray_setSize_(out, outSize - 1);
188 break;
189 case CENCODING_UCS4:
190 // should the size be the num of chars or num of bytes??????????
191 outSize = ucs4encode(targetStart, sourceStart, self->size,
192 NULL); // ucs4 to utf8
193 UArray_setSize_(out, outSize - 1);
194 break;
195 case CENCODING_NUMBER: {
196 UArray *nas = UArray_asNumberArrayString(self);
197 UArray_free(out);
198 out = UArray_asUTF8(nas);
199 UArray_free(nas);
200 break;
201 }
202 default:
203 printf("UArray_asUTF8 - unknown source encoding\n");
204 }
205 }
206
207 return out;
208}
209
210int UArray_isUTF8Compatible(const UArray *self) {
211 return (self->encoding == CENCODING_ASCII ||

Callers 7

UArray_readFromFilePath_Function · 0.85
UArray_writeToFilePath_Function · 0.85
UArray_asUCS2Function · 0.85
UArray_asUCS4Function · 0.85
UArray_convertToUTF8Function · 0.85
IoSeq_immutable.cFile · 0.85
IoSeq_asUTF8SeqFunction · 0.85

Calls 9

UArray_newFunction · 0.85
UArray_setItemType_Function · 0.85
UArray_setEncoding_Function · 0.85
UArray_setSize_Function · 0.85
UArray_copy_Function · 0.85
ucs2encodeFunction · 0.85
ucs4encodeFunction · 0.85
UArray_freeFunction · 0.85

Tested by

no test coverage detected