MCPcopy Create free account
hub / github.com/beefytech/Beef / UTF8Encode

Method UTF8Encode

BeefySysLib/Common.cpp:378–427  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

376}
377
378String Beefy::UTF8Encode(const uint16* theString, int length)
379{
380 if (length == 0)
381 return String();
382
383 String strOut;
384 int utf8Len = 0;
385 uint16 utf16hi = 0;
386 for (int i = 0; i < length; i++)
387 {
388 uint16 c = theString[i];
389 uint32 c32 = c;
390 if ((c >= 0xD800) && (c < 0xDC00))
391 {
392 utf16hi = (uint16)c;
393 continue;
394 }
395 else if ((c >= 0xDC00) && (c < 0xE000))
396 {
397 uint16 utf16lo = c;
398 c32 = 0x10000 + ((uint32)(utf16hi - 0xD800) << 10) | (uint32)(utf16lo - 0xDC00);
399 }
400
401 utf8Len += u8_seqlen(c32);
402 }
403 strOut.Append('?', utf8Len);
404 char* cPtr = (char*)&strOut[0];
405 int lenLeft = (int)strOut.length() + 1;
406 for (int i = 0; i < length; i++)
407 {
408 uint16 c = theString[i];
409 uint32 c32 = c;
410 if ((c >= 0xD800) && (c < 0xDC00))
411 {
412 utf16hi = (uint16)c;
413 continue;
414 }
415 else if ((c >= 0xDC00) && (c < 0xE000))
416 {
417 uint16 utf16lo = c;
418 c32 = 0x10000 + ((uint32)(utf16hi - 0xD800) << 10) | (uint32)(utf16lo - 0xDC00);
419 }
420
421 int len = u8_toutf8(cPtr, lenLeft, c32);
422 cPtr += len;
423 lenLeft -= len;
424 }
425
426 return strOut;
427}
428
429String Beefy::UTF8Encode(const UTF16String& theString)
430{

Callers

nothing calls this directly

Calls 4

StringClass · 0.85
AppendMethod · 0.80
lengthMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected