You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// fromCharCode constructs a character from a UTF-16 code unit, so we can pass the UTF16 string right through.
70
73
str+=String.fromCharCode(codeUnit);
@@ -117,16 +120,18 @@ function lengthBytesUTF16(str) {
117
120
returnstr.length*2;
118
121
}
119
122
120
-
functionUTF32ToString(ptr){
123
+
functionUTF32ToString(ptr,maxBytesToRead){
121
124
#if ASSERTIONS
122
125
assert(ptr%4==0,'Pointer passed to UTF32ToString must be aligned to four bytes!');
123
126
#endif
124
127
vari=0;
125
128
126
129
varstr='';
127
-
while(1){
130
+
// If maxBytesToRead is not passed explicitly, it will be undefined, and this
131
+
// will always evaluate to true. This saves on code size.
132
+
while(!(i>=maxBytesToRead/4)){
128
133
varutf32={{{makeGetValue('ptr','i*4','i32')}}};
129
-
if(utf32==0)returnstr;
134
+
if(utf32==0)break;
130
135
++i;
131
136
// Gotcha: fromCharCode constructs a character from a UTF-16 encoded code (pair), not from a Unicode code point! So encode the code point to UTF-16 for constructing.
132
137
// See http://unicode.org/faq/utf_bom.html#utf16-3
@@ -137,6 +142,7 @@ function UTF32ToString(ptr) {
137
142
str+=String.fromCharCode(utf32);
138
143
}
139
144
}
145
+
returnstr;
140
146
}
141
147
142
148
// Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
0 commit comments