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

Function stringToUTF16

js/sql-debug.js:935–953  ·  view source on GitHub ↗
(str, outPtr, maxBytesToWrite)

Source from the content-addressed store, hash-verified

933// Returns the number of bytes written, EXCLUDING the null terminator.
934
935function stringToUTF16(str, outPtr, maxBytesToWrite) {
936 // Backwards compatibility: if max bytes is not specified, assume unsafe unbounded write is allowed.
937 if (maxBytesToWrite === undefined) {
938 maxBytesToWrite = 0x7FFFFFFF;
939 }
940 if (maxBytesToWrite < 2) return 0;
941 maxBytesToWrite -= 2; // Null terminator.
942 var startPtr = outPtr;
943 var numCharsToWrite = (maxBytesToWrite < str.length*2) ? (maxBytesToWrite / 2) : str.length;
944 for (var i = 0; i < numCharsToWrite; ++i) {
945 // charCodeAt returns a UTF-16 encoded code unit, so it can be directly written to the HEAP.
946 var codeUnit = str.charCodeAt(i); // possibly a lead surrogate
947 HEAP16[((outPtr)>>1)]=codeUnit;
948 outPtr += 2;
949 }
950 // Null-terminate the pointer to the HEAP.
951 HEAP16[((outPtr)>>1)]=0;
952 return outPtr - startPtr;
953}
954
955
956// Returns the number of bytes the given Javascript string takes if encoded as a UTF16 byte array, EXCLUDING the null terminator byte.

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…