B2G/gecko/dom/system/gonk/RadioInterfaceLayer.js
/**
   * Calculate encoded length using specified locking/single shift table
   *
   * @param message
   *        message string to be encoded.
   * @param langTable
   *        locking shift table string.
   * @param langShiftTable
   *        single shift table string.
   * @param strict7BitEncoding
   *        Optional. Enable Latin characters replacement with corresponding
   *        ones in GSM SMS 7-bit default alphabet.
   *
   * @return encoded length in septets.
   *
   * @note that the algorithm used in this function must match exactly with
   * GsmPDUHelper#writeStringAsSeptets.
   */
Calculate encoded length using specified locking/single shift table
@param message
message string to be encoded.
@param langTable
locking shift table string.
@param langShiftTable
single shift table string.

@return encoded length in septets.

@note that the algorithm used in this function must match exactly with
GsmPDUHelper#writeStringAsSeptets.
Calculate encoded length using specified locking / single shift table @param message message string to be encoded . @param langTable locking shift table string . @param langShiftTable single shift table string . @return encoded length in septets . @note that the algorithm used in this function must match exactly with GsmPDUHelper#writeStringAsSeptets .
function _countGsm7BitSeptets(message, langTable, langShiftTable, strict7BitEncoding) {
    let length = 0;
    for (let msgIndex = 0; msgIndex < message.length; msgIndex++) {
      let c = message.charAt(msgIndex);
      if (strict7BitEncoding) {
        c = RIL.GSM_SMS_STRICT_7BIT_CHARMAP[c] || c;
      }
      let septet = langTable.indexOf(c);
      if (septet == RIL.PDU_NL_EXTENDED_ESCAPE) {
        continue;
      }
      if (septet >= 0) {
        length++;
        continue;
      }
      septet = langShiftTable.indexOf(c);
      if (septet < 0) {
        if (!strict7BitEncoding) {
          return -1;
        }
        c = '*';
        if (langTable.indexOf(c) >= 0) {
          length++;
        } else if (langShiftTable.indexOf(c) >= 0) {
          length += 2;
        } else {
          return -1;
        }
        continue;
      }
      if (septet == RIL.PDU_NL_RESERVED_CONTROL) {
        continue;
      }
      length += 2;
    }
    return length;
  }
function _countGsm7BitSeptets ( message , langTable , langShiftTable , strict7BitEncoding ) { let length = 0 ; for ( let msgIndex = 0 ; msgIndex < message . length ; msgIndex ++ ) { let c = message . charAt ( msgIndex ) ; if ( strict7BitEncoding ) { c = RIL . GSM_SMS_STRICT_7BIT_CHARMAP [ c ] || c ; } let septet = langTable . indexOf ( c ) ; if ( septet == RIL . PDU_NL_EXTENDED_ESCAPE ) { continue ; } if ( septet >= 0 ) { length ++ ; continue ; } septet = langShiftTable . indexOf ( c ) ; if ( septet < 0 ) { if ( ! strict7BitEncoding ) { return - 1 ; } c = '*' ; if ( langTable . indexOf ( c ) >= 0 ) { length ++ ; } else if ( langShiftTable . indexOf ( c ) >= 0 ) { length += 2 ; } else { return - 1 ; } continue ; } if ( septet == RIL . PDU_NL_RESERVED_CONTROL ) { continue ; } length += 2 ; } return length ; }
Calculate encoded length using specified locking/single shift table
 @param message
        message string to be encoded.
Calculate encoded length using specified locking / single shift table @param message message string to be encoded .
// According to 3GPP TS 23.038, section 6.1.1 General notes, "The // characters marked '1)' are not used but are displayed as a space." // Bug 816082, when strict7BitEncoding is enabled, we should replace // characters that can't be encoded with GSM 7-Bit alphabets with '*'. // We can't even encode a '*' character with current configuration. // According to 3GPP TS 23.038 B.2, "This code represents a control // character and therefore must not be used for language specific // characters." // The character is not found in locking shfit table, but could be // encoded as <escape><char> with single shift table. Note that it's // still possible for septet to has the value of PDU_NL_EXTENDED_ESCAPE, // but we can display it as a space in this case as said in previous // comment.