Converts a string to an array of UTF8 bytes.
(string)
| 359 | |
| 360 | /** Converts a string to an array of UTF8 bytes. */ |
| 361 | function utf8Array(string) { |
| 362 | var offset = 0, |
| 363 | c1, |
| 364 | c2; |
| 365 | var buffer = new Array(utf8Length(string)); |
| 366 | for (var i = 0, k = string.length; i < k; ++i) { |
| 367 | c1 = string.charCodeAt(i); |
| 368 | if (c1 < 128) { |
| 369 | buffer[offset++] = c1; |
| 370 | } else if (c1 < 2048) { |
| 371 | buffer[offset++] = (c1 >> 6) | 192; |
| 372 | buffer[offset++] = (c1 & 63) | 128; |
| 373 | } else if ( |
| 374 | (c1 & 0xfc00) === 0xd800 && |
| 375 | ((c2 = string.charCodeAt(i + 1)) & 0xfc00) === 0xdc00 |
| 376 | ) { |
| 377 | c1 = 0x10000 + ((c1 & 0x03ff) << 10) + (c2 & 0x03ff); |
| 378 | ++i; |
| 379 | buffer[offset++] = (c1 >> 18) | 240; |
| 380 | buffer[offset++] = ((c1 >> 12) & 63) | 128; |
| 381 | buffer[offset++] = ((c1 >> 6) & 63) | 128; |
| 382 | buffer[offset++] = (c1 & 63) | 128; |
| 383 | } else { |
| 384 | buffer[offset++] = (c1 >> 12) | 224; |
| 385 | buffer[offset++] = ((c1 >> 6) & 63) | 128; |
| 386 | buffer[offset++] = (c1 & 63) | 128; |
| 387 | } |
| 388 | } |
| 389 | return buffer; |
| 390 | } |
| 391 | |
| 392 | // A base64 implementation for the bcrypt algorithm. This is partly non-standard. |
| 393 |