(str)
| 868 | // Returns the number of bytes the given Javascript string takes if encoded as a UTF8 byte array, EXCLUDING the null terminator byte. |
| 869 | |
| 870 | function lengthBytesUTF8(str) { |
| 871 | var len = 0; |
| 872 | for (var i = 0; i < str.length; ++i) { |
| 873 | // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! So decode UTF16->UTF32->UTF8. |
| 874 | // See http://unicode.org/faq/utf_bom.html#utf16-3 |
| 875 | var u = str.charCodeAt(i); // possibly a lead surrogate |
| 876 | if (u >= 0xD800 && u <= 0xDFFF) u = 0x10000 + ((u & 0x3FF) << 10) | (str.charCodeAt(++i) & 0x3FF); |
| 877 | if (u <= 0x7F) { |
| 878 | ++len; |
| 879 | } else if (u <= 0x7FF) { |
| 880 | len += 2; |
| 881 | } else if (u <= 0xFFFF) { |
| 882 | len += 3; |
| 883 | } else if (u <= 0x1FFFFF) { |
| 884 | len += 4; |
| 885 | } else if (u <= 0x3FFFFFF) { |
| 886 | len += 5; |
| 887 | } else { |
| 888 | len += 6; |
| 889 | } |
| 890 | } |
| 891 | return len; |
| 892 | } |
| 893 | |
| 894 | |
| 895 | // Given a pointer 'ptr' to a null-terminated UTF16LE-encoded string in the emscripten HEAP, returns |
no outgoing calls
no test coverage detected
searching dependent graphs…