(str, outPtr, maxBytesToWrite)
| 933 | // Returns the number of bytes written, EXCLUDING the null terminator. |
| 934 | |
| 935 | function 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. |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…