MCPcopy Create free account
hub / github.com/sql-js/sql.js / UTF16ToString

Function UTF16ToString

js/sql-debug.js:899–921  ·  view source on GitHub ↗
(ptr)

Source from the content-addressed store, hash-verified

897
898var UTF16Decoder = typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-16le') : undefined;
899function UTF16ToString(ptr) {
900 var endPtr = ptr;
901 // TextDecoder needs to know the byte length in advance, it doesn't stop on null terminator by itself.
902 // Also, use the length info to avoid running tiny strings through TextDecoder, since .subarray() allocates garbage.
903 var idx = endPtr >> 1;
904 while (HEAP16[idx]) ++idx;
905 endPtr = idx << 1;
906
907 if (endPtr - ptr > 32 && UTF16Decoder) {
908 return UTF16Decoder.decode(HEAPU8.subarray(ptr, endPtr));
909 } else {
910 var i = 0;
911
912 var str = '';
913 while (1) {
914 var codeUnit = HEAP16[(((ptr)+(i*2))>>1)];
915 if (codeUnit == 0) return str;
916 ++i;
917 // fromCharCode constructs a character from a UTF-16 code unit, so we can pass the UTF16 string right through.
918 str += String.fromCharCode(codeUnit);
919 }
920 }
921}
922
923
924// Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…