MCPcopy Create free account
hub / github.com/HaxeFoundation/hxcpp / _hx_utf8_to_utf16

Function _hx_utf8_to_utf16

src/String.cpp:1529–1570  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1527
1528#ifdef HX_SMART_STRINGS
1529String _hx_utf8_to_utf16(const unsigned char *ptr, int inUtf8Len, bool addHash)
1530{
1531 unsigned int hash = 0;
1532 if (addHash)
1533 for(int i=0;i<inUtf8Len;i++)
1534 hash = hash*223 + ptr[i];
1535
1536 int char16Count = 0;
1537 const unsigned char *u = ptr;
1538 const unsigned char *end = ptr + inUtf8Len;
1539 while(u<end)
1540 {
1541 int code = DecodeAdvanceUTF8(u,end);
1542 char16Count += UTF16BytesCheck(code);
1543 }
1544
1545 int allocSize = 2*(char16Count+1);
1546 if (addHash)
1547 allocSize += sizeof(int);
1548 char16_t *str = (char16_t *)NewGCPrivate(0,allocSize);
1549
1550 u = ptr;
1551 char16_t *o = str;
1552 while(u<end)
1553 {
1554 int code = DecodeAdvanceUTF8(u,end);
1555 Char16AdvanceSet(o,code);
1556 }
1557 if (addHash)
1558 {
1559 #ifdef EMSCRIPTEN
1560 *((emscripten_align1_int *)(str+char16Count+1) ) = hash;
1561 #else
1562 *((unsigned int *)(str+char16Count+1) ) = hash;
1563 #endif
1564 ((unsigned int *)(str))[-1] |= HX_GC_STRING_HASH | HX_GC_STRING_CHAR16_T;
1565 }
1566 else
1567 ((unsigned int *)(str))[-1] |= HX_GC_STRING_CHAR16_T;
1568
1569 return String(str, char16Count);
1570}
1571#endif
1572
1573

Callers 4

createMethod · 0.85
__URLDecodeMethod · 0.85
__hxcpp_string_of_bytesFunction · 0.85
__hxcpp_resource_stringFunction · 0.85

Calls 5

DecodeAdvanceUTF8Function · 0.85
UTF16BytesCheckFunction · 0.85
NewGCPrivateFunction · 0.85
Char16AdvanceSetFunction · 0.85
StringClass · 0.50

Tested by

no test coverage detected