@@ -515,8 +515,11 @@ function stringToAscii(str, outPtr) {
515
515
// Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the given array that contains uint8 values, returns
516
516
// a copy of that string as a Javascript String object.
517
517
518
+ #if TEXTDECODER
518
519
var UTF8Decoder = typeof TextDecoder !== 'undefined' ? new TextDecoder ( 'utf8' ) : undefined ;
520
+ #endif
519
521
function UTF8ArrayToString ( u8Array , idx ) {
522
+ #if TEXTDECODER
520
523
var endPtr = idx ;
521
524
// TextDecoder needs to know the byte length in advance, it doesn't stop on null terminator by itself.
522
525
// Also, use the length info to avoid running tiny strings through TextDecoder, since .subarray() allocates garbage.
@@ -525,6 +528,7 @@ function UTF8ArrayToString(u8Array, idx) {
525
528
if ( endPtr - idx > 16 && u8Array . subarray && UTF8Decoder ) {
526
529
return UTF8Decoder . decode ( u8Array . subarray ( idx , endPtr ) ) ;
527
530
} else {
531
+ #endif
528
532
var u0 , u1 , u2 , u3 , u4 , u5 ;
529
533
530
534
var str = '' ;
@@ -559,7 +563,9 @@ function UTF8ArrayToString(u8Array, idx) {
559
563
str += String . fromCharCode ( 0xD800 | ( ch >> 10 ) , 0xDC00 | ( ch & 0x3FF ) ) ;
560
564
}
561
565
}
566
+ #if TEXTDECODER
562
567
}
568
+ #endif
563
569
}
564
570
{ { { maybeExport ( 'UTF8ArrayToString' ) } } }
565
571
@@ -684,6 +690,7 @@ function UTF16ToString(ptr) {
684
690
#if ASSERTIONS
685
691
assert ( ptr % 2 == 0 , 'Pointer passed to UTF16ToString must be aligned to two bytes!' ) ;
686
692
#endif
693
+ #if TEXTDECODER
687
694
var endPtr = ptr ;
688
695
// TextDecoder needs to know the byte length in advance, it doesn't stop on null terminator by itself.
689
696
// Also, use the length info to avoid running tiny strings through TextDecoder, since .subarray() allocates garbage.
@@ -694,6 +701,7 @@ function UTF16ToString(ptr) {
694
701
if ( endPtr - ptr > 32 && UTF16Decoder ) {
695
702
return UTF16Decoder . decode ( HEAPU8 . subarray ( ptr , endPtr ) ) ;
696
703
} else {
704
+ #endif
697
705
var i = 0 ;
698
706
699
707
var str = '' ;
@@ -704,7 +712,9 @@ function UTF16ToString(ptr) {
704
712
// fromCharCode constructs a character from a UTF-16 code unit, so we can pass the UTF16 string right through.
705
713
str += String . fromCharCode ( codeUnit ) ;
706
714
}
715
+ #if TEXTDECODER
707
716
}
717
+ #endif
708
718
}
709
719
{ { { maybeExport ( 'UTF16ToString' ) } } }
710
720
0 commit comments