(str, outPtr, maxBytesToWrite)
| 993 | // Returns the number of bytes written, EXCLUDING the null terminator. |
| 994 | |
| 995 | function stringToUTF32(str, outPtr, maxBytesToWrite) { |
| 996 | // Backwards compatibility: if max bytes is not specified, assume unsafe unbounded write is allowed. |
| 997 | if (maxBytesToWrite === undefined) { |
| 998 | maxBytesToWrite = 0x7FFFFFFF; |
| 999 | } |
| 1000 | if (maxBytesToWrite < 4) return 0; |
| 1001 | var startPtr = outPtr; |
| 1002 | var endPtr = startPtr + maxBytesToWrite - 4; |
| 1003 | for (var i = 0; i < str.length; ++i) { |
| 1004 | // 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. |
| 1005 | // See http://unicode.org/faq/utf_bom.html#utf16-3 |
| 1006 | var codeUnit = str.charCodeAt(i); // possibly a lead surrogate |
| 1007 | if (codeUnit >= 0xD800 && codeUnit <= 0xDFFF) { |
| 1008 | var trailSurrogate = str.charCodeAt(++i); |
| 1009 | codeUnit = 0x10000 + ((codeUnit & 0x3FF) << 10) | (trailSurrogate & 0x3FF); |
| 1010 | } |
| 1011 | HEAP32[((outPtr)>>2)]=codeUnit; |
| 1012 | outPtr += 4; |
| 1013 | if (outPtr + 4 > endPtr) break; |
| 1014 | } |
| 1015 | // Null-terminate the pointer to the HEAP. |
| 1016 | HEAP32[((outPtr)>>2)]=0; |
| 1017 | return outPtr - startPtr; |
| 1018 | } |
| 1019 | |
| 1020 | |
| 1021 | // Returns the number of bytes the given Javascript string takes if encoded as a UTF16 byte array, EXCLUDING the null terminator byte. |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…