src/bcrypt/util/utf8.js
/** Calculates the byte length of a string encoded as UTF8. */
Calculates the byte length of a string encoded as UTF8.
Calculates the byte length of a string encoded as UTF8 .
function utf8Length(string) {
  var len = 0,
      c = 0;
  for (var i = 0; i < string.length; ++i) {
      c = string.charCodeAt(i);
      if (c < 128)
          len += 1;
      else if (c < 2048)
          len += 2;
      else if (
        (c                        & 0xFC00) === 0xD800 &&
        (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00
      ) {
          ++i;
          len += 4;
      } else
          len += 3;
  }
  return len;
}
function utf8Length ( string ) { var len = 0 , c = 0 ; for ( var i = 0 ; i < string . length ; ++ i ) { c = string . charCodeAt ( i ) ; if ( c < 128 ) len += 1 ; else if ( c < 2048 ) len += 2 ; else if ( ( c & 0xFC00 ) === 0xD800 && ( string . charCodeAt ( i + 1 ) & 0xFC00 ) === 0xDC00 ) { ++ i ; len += 4 ; } else len += 3 ; } return len ; }
Calculates the byte length of a string encoded as UTF8.
Calculates the byte length of a string encoded as UTF8 .