src/bcrypt/util/utf8.js
/** Converts a string to an array of UTF8 bytes. */
Converts a string to an array of UTF8 bytes.
Converts a string to an array of UTF8 bytes .
function utf8Array(string) {
  var offset = 0,
      c1, c2;
  var buffer = new Array(utf8Length(string));
  for (var i = 0, k = string.length; i < k; ++i) {
      c1 = string.charCodeAt(i);
      if (c1 < 128) {
          buffer[offset++] = c1;
      } else if (c1 < 2048) {
          buffer[offset++] = c1 >> 6       | 192;
          buffer[offset++] = c1       & 63 | 128;
      } else if (
        ( c1                             & 0xFC00) === 0xD800 &&
        ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00
      ) {
          c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
          ++i;
          buffer[offset++] = c1 >> 18      | 240;
          buffer[offset++] = c1 >> 12 & 63 | 128;
          buffer[offset++] = c1 >> 6  & 63 | 128;
          buffer[offset++] = c1       & 63 | 128;
      } else {
          buffer[offset++] = c1 >> 12      | 224;
          buffer[offset++] = c1 >> 6  & 63 | 128;
          buffer[offset++] = c1       & 63 | 128;
      }
  }
  return buffer;
}
function utf8Array ( string ) { var offset = 0 , c1 , c2 ; var buffer = new Array ( utf8Length ( string ) ) ; for ( var i = 0 , k = string . length ; i < k ; ++ i ) { c1 = string . charCodeAt ( i ) ; if ( c1 < 128 ) { buffer [ offset ++ ] = c1 ; } else if ( c1 < 2048 ) { buffer [ offset ++ ] = c1 >> 6 | 192 ; buffer [ offset ++ ] = c1 & 63 | 128 ; } else if ( ( c1 & 0xFC00 ) === 0xD800 && ( ( c2 = string . charCodeAt ( i + 1 ) ) & 0xFC00 ) === 0xDC00 ) { c1 = 0x10000 + ( ( c1 & 0x03FF ) << 10 ) + ( c2 & 0x03FF ) ; ++ i ; buffer [ offset ++ ] = c1 >> 18 | 240 ; buffer [ offset ++ ] = c1 >> 12 & 63 | 128 ; buffer [ offset ++ ] = c1 >> 6 & 63 | 128 ; buffer [ offset ++ ] = c1 & 63 | 128 ; } else { buffer [ offset ++ ] = c1 >> 12 | 224 ; buffer [ offset ++ ] = c1 >> 6 & 63 | 128 ; buffer [ offset ++ ] = c1 & 63 | 128 ; } } return buffer ; }
Converts a string to an array of UTF8 bytes.
Converts a string to an array of UTF8 bytes .