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
if(!(maxBytesToWrite>0))// Parameter maxBytesToWrite is not optional. Negative values, 0, null, undefined and false each don't write out any bytes.
147
+
// Parameter maxBytesToWrite is not optional. Negative values, 0, null,
148
+
// undefined and false each don't write out any bytes.
149
+
if(!(maxBytesToWrite>0))
132
150
return0;
133
151
134
152
varstartIdx=outIdx;
135
153
varendIdx=outIdx+maxBytesToWrite-1;// -1 for string null terminator.
136
154
for(vari=0;i<str.length;++i){
137
-
// 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.
155
+
// Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code
156
+
// unit, not a Unicode code point of the character! So decode
157
+
// UTF16->UTF32->UTF8.
138
158
// See http://unicode.org/faq/utf_bom.html#utf16-3
139
-
// For UTF8 byte structure, see http://en.wikipedia.org/wiki/UTF-8#Description and https://www.ietf.org/rfc/rfc2279.txt and https://tools.ietf.org/html/rfc3629
159
+
// For UTF8 byte structure, see http://en.wikipedia.org/wiki/UTF-8#Description
160
+
// and https://www.ietf.org/rfc/rfc2279.txt
161
+
// and https://tools.ietf.org/html/rfc3629
140
162
varu=str.charCodeAt(i);// possibly a lead surrogate
141
163
if(u>=0xD800&&u<=0xDFFF){
142
164
varu1=str.charCodeAt(++i);
@@ -170,23 +192,35 @@ function stringToUTF8Array(str, heap, outIdx, maxBytesToWrite) {
170
192
returnoutIdx-startIdx;
171
193
}
172
194
173
-
// Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
174
-
// null-terminated and encoded in UTF8 form. The copy will require at most str.length*4+1 bytes of space in the HEAP.
175
-
// Use the function lengthBytesUTF8 to compute the exact number of bytes (excluding null terminator) that this function will write.
176
-
// Returns the number of bytes written, EXCLUDING the null terminator.
177
-
195
+
/**
196
+
* Copies the given Javascript String object 'str' to the emscripten HEAP at
197
+
* address 'outPtr', null-terminated and encoded in UTF8 form. The copy will
198
+
* require at most str.length*4+1 bytes of space in the HEAP.
199
+
* Use the function lengthBytesUTF8 to compute the exact number of bytes
200
+
* (excluding null terminator) that this function will write.
201
+
*
202
+
* @return {number} The number of bytes written, EXCLUDING the null terminator.
203
+
*/
178
204
functionstringToUTF8(str,outPtr,maxBytesToWrite){
179
205
#if ASSERTIONS
180
206
assert(typeofmaxBytesToWrite=='number','stringToUTF8(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!');
// Returns the number of bytes the given Javascript string takes if encoded as a UTF8 byte array, EXCLUDING the null terminator byte.
211
+
/**
212
+
* Returns the number of bytes the given Javascript string takes if encoded as a
213
+
* UTF8 byte array, EXCLUDING the null terminator byte.
214
+
*
215
+
* @param {string} str - JavaScript string to operator on
216
+
* @return {number} Length, in bytes, of the UTF8 encoded string.
217
+
*/
186
218
functionlengthBytesUTF8(str){
187
219
varlen=0;
188
220
for(vari=0;i<str.length;++i){
189
-
// 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.
221
+
// Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code
222
+
// unit, not a Unicode code point of the character! So decode
223
+
// UTF16->UTF32->UTF8.
190
224
// See http://unicode.org/faq/utf_bom.html#utf16-3
191
225
varc=str.charCodeAt(i);// possibly a lead surrogate
0 commit comments