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

Function lengthBytesUTF32

js/sql-debug.js:1023–1034  ·  view source on GitHub ↗
(str)

Source from the content-addressed store, hash-verified

1021// Returns the number of bytes the given Javascript string takes if encoded as a UTF16 byte array, EXCLUDING the null terminator byte.
1022
1023function lengthBytesUTF32(str) {
1024 var len = 0;
1025 for (var i = 0; i < str.length; ++i) {
1026 // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! We must decode the string to UTF-32 to the heap.
1027 // See http://unicode.org/faq/utf_bom.html#utf16-3
1028 var codeUnit = str.charCodeAt(i);
1029 if (codeUnit >= 0xD800 && codeUnit <= 0xDFFF) ++i; // possibly a lead surrogate, so skip over the tail surrogate.
1030 len += 4;
1031 }
1032
1033 return len;
1034}
1035
1036
1037function demangle(func) {

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…