B2G/gecko/dom/mobilemessage/src/ril/MmsPduHelper.jsm
/**
   * @param data
   *        A wrapped object containing raw PDU data.
   *
   * @return Decoded string.
   *
   * @throws CodeError if the raw octets cannot be converted.
   * @throws NotWellKnownEncodingError if decoded well-known charset number is
   *         not registered or supported.
   */
@param data
A wrapped object containing raw PDU data.

@return Decoded string.

@throws CodeError if the raw octets cannot be converted.
@throws NotWellKnownEncodingError if decoded well-known charset number is
not registered or supported.
@param data A wrapped object containing raw PDU data . @return Decoded string . @throws CodeError if the raw octets cannot be converted . @throws NotWellKnownEncodingError if decoded well - known charset number is not registered or supported .
function decodeCharsetEncodedString(data) {
    let length = WSP.ValueLength.decode(data);
    let end = data.offset + length;
    let charset = WSP.IntegerValue.decode(data);
    let entry = WSP.WSP_WELL_KNOWN_CHARSETS[charset];
    if (!entry) {
      throw new WSP.NotWellKnownEncodingError(
        "Charset-encoded-string: not well known charset " + charset);
    }
    let str;
    if (entry.converter) {
      let begin = data.offset;
      if (WSP.Octet.decode(data) != 127) {
        data.offset = begin;
      }
      let raw = WSP.Octet.decodeMultiple(data, end - 1);
      WSP.Octet.decodeEqualTo(data, 0);
      if (!raw) {
        str = "";
      } else {
        let conv = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
                   .createInstance(Ci.nsIScriptableUnicodeConverter);
        conv.charset = entry.converter;
        try {
          str = conv.convertFromByteArray(raw, raw.length);
        } catch (e) {
          throw new WSP.CodeError("Charset-encoded-string: " + e.message);
        }
      }
    } else {
      str = WSP.TextString.decode(data);
    }
    if (data.offset != end) {
      data.offset = end;
    }
    return str;
  }
function decodeCharsetEncodedString ( data ) { let length = WSP . ValueLength . decode ( data ) ; let end = data . offset + length ; let charset = WSP . IntegerValue . decode ( data ) ; let entry = WSP . WSP_WELL_KNOWN_CHARSETS [ charset ] ; if ( ! entry ) { throw new WSP . NotWellKnownEncodingError ( "Charset-encoded-string: not well known charset " + charset ) ; } let str ; if ( entry . converter ) { let begin = data . offset ; if ( WSP . Octet . decode ( data ) != 127 ) { data . offset = begin ; } let raw = WSP . Octet . decodeMultiple ( data , end - 1 ) ; WSP . Octet . decodeEqualTo ( data , 0 ) ; if ( ! raw ) { str = "" ; } else { let conv = Cc [ "@mozilla.org/intl/scriptableunicodeconverter" ] . createInstance ( Ci . nsIScriptableUnicodeConverter ) ; conv . charset = entry . converter ; try { str = conv . convertFromByteArray ( raw , raw . length ) ; } catch ( e ) { throw new WSP . CodeError ( "Charset-encoded-string: " + e . message ) ; } } } else { str = WSP . TextString . decode ( data ) ; } if ( data . offset != end ) { data . offset = end ; } return str ; }
@param data
        A wrapped object containing raw PDU data.
@param data A wrapped object containing raw PDU data .
// Read a possible string quote(<Octet 127>). // Read NUL character.