MCPcopy Index your code
hub / github.com/dcodeIO/bcrypt.js / utf8Array

Function utf8Array

index.js:361–390  ·  view source on GitHub ↗

Converts a string to an array of UTF8 bytes.

(string)

Source from the content-addressed store, hash-verified

359
360/** Converts a string to an array of UTF8 bytes. */
361function 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

Callers 1

_hashFunction · 0.85

Calls 1

utf8LengthFunction · 0.85

Tested by

no test coverage detected