B2G/gaia/apps/email/js/ext/mailapi/worker-bootstrap.js
/**
 * Encode a unicode string into a (Uint8Array) byte array with the given
 * encoding. Wraps TextEncoder to provide hex and base64 "encoding" (which it
 * does not provide).
 */
Encode a unicode string into a (Uint8Array) byte array with the given
encoding. Wraps TextEncoder to provide hex and base64 "encoding" (which it
does not provide).
Encode a unicode string into a ( Uint8Array ) byte array with the given encoding . Wraps TextEncoder to provide hex and base64 " encoding " ( which it does not provide ) .
function encode(string, encoding) {
  var buf, i;
  switch (encoding) {
    case 'base64':
      buf = safeBase64DecodeToArray(string);
      return buf;
    case 'binary':
      buf = new Uint8Array(string.length);
      for (i = 0; i < string.length; i++) {
        buf[i] = string.charCodeAt(i);
      }
      return buf;
    case 'hex':
      buf = new Uint8Array(string.length * 2);
      for (i = 0; i < string.length; i++) {
        var c = string.charCodeAt(i), nib;
        nib = c >> 4;
        buf[i*2] = (nib < 10) ? (nib + 48) : (nib - 10 + 97);
        nib = c & 0xf;
        buf[i*2 + 1] = (nib < 10) ? (nib + 48) : (nib - 10 + 97);
      }
      return buf;
    case 'utf8':
      encoding = 'utf-8';
    default:
      if (!encoding)
        encoding = 'utf-8';
      return TextEncoder(encoding, ENCODER_OPTIONS).encode(string);
  }
}
function encode ( string , encoding ) { var buf , i ; switch ( encoding ) { case 'base64' : buf = safeBase64DecodeToArray ( string ) ; return buf ; case 'binary' : buf = new Uint8Array ( string . length ) ; for ( i = 0 ; i < string . length ; i ++ ) { buf [ i ] = string . charCodeAt ( i ) ; } return buf ; case 'hex' : buf = new Uint8Array ( string . length * 2 ) ; for ( i = 0 ; i < string . length ; i ++ ) { var c = string . charCodeAt ( i ) , nib ; nib = c >> 4 ; buf [ i * 2 ] = ( nib < 10 ) ? ( nib + 48 ) : ( nib - 10 + 97 ) ; nib = c & 0xf ; buf [ i * 2 + 1 ] = ( nib < 10 ) ? ( nib + 48 ) : ( nib - 10 + 97 ) ; } return buf ; case 'utf8' : encoding = 'utf-8' ; default : if ( ! encoding ) encoding = 'utf-8' ; return TextEncoder ( encoding , ENCODER_OPTIONS ) . encode ( string ) ; } }
Encode a unicode string into a (Uint8Array) byte array with the given
 encoding.
Encode a unicode string into a ( Uint8Array ) byte array with the given encoding .
// need to normalize the name (for now at least)