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

Function __hxcpp_utf8_string_to_char_bytes

src/String.cpp:602–644  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

600
601
602String __hxcpp_utf8_string_to_char_bytes(String &inUTF8)
603{
604 #ifdef HX_SMART_STRINGS
605 // This does not really make much sense
606 return inUTF8;
607 #else
608 const unsigned char *src = (unsigned char *)inUTF8.__s;
609 const unsigned char *end = src + inUTF8.length;
610 int char_count = 0;
611 while(src<end)
612 {
613 int c = DecodeAdvanceUTF8(src,end);
614 char_count++;
615 if( c == 8364 ) // euro symbol
616 c = 164;
617 else if ( c == 0xFEFF ) // BOM
618 {
619 char_count--;
620 }
621 else if( c > 255 )
622 hx::Throw(HX_CSTRING("Utf8::decode invalid character"));
623 }
624
625 if (src!=end)
626 hx::Throw(HX_CSTRING("Invalid UTF8"));
627
628 char *result = hx::NewString(char_count);
629
630 src = (unsigned char *)inUTF8.__s;
631 char_count = 0;
632 while(src<end)
633 {
634 int c = DecodeAdvanceUTF8(src);
635 if( c == 8364 ) // euro symbol
636 c = 164;
637 if ( c != 0xFEFF ) // BOM
638 result[char_count++] = c;
639 }
640
641 result[char_count] = '\0';
642 return String(result,char_count);
643 #endif
644}
645
646
647void _hx_utf8_iter(String inString, Dynamic inIter)

Callers

nothing calls this directly

Calls 4

DecodeAdvanceUTF8Function · 0.85
ThrowFunction · 0.85
NewStringFunction · 0.85
StringClass · 0.50

Tested by

no test coverage detected