Home | History | Annotate | Download | only in telephony
      1 /*
      2  * Copyright (C) 2006 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.internal.telephony;
     18 
     19 import android.content.res.Resources;
     20 import android.text.TextUtils;
     21 import android.util.SparseIntArray;
     22 
     23 import android.telephony.Rlog;
     24 
     25 import java.nio.ByteBuffer;
     26 import java.nio.charset.Charset;
     27 import com.android.internal.telephony.SmsConstants;
     28 import com.android.internal.R;
     29 
     30 import java.util.ArrayList;
     31 import java.util.List;
     32 
     33 /**
     34  * This class implements the character set mapping between
     35  * the GSM SMS 7-bit alphabet specified in TS 23.038 6.2.1
     36  * and UTF-16
     37  *
     38  * {@hide}
     39  */
     40 public class GsmAlphabet {
     41     private static final String TAG = "GSM";
     42 
     43     private GsmAlphabet() { }
     44 
     45     /**
     46      * This escapes extended characters, and when present indicates that the
     47      * following character should be looked up in the "extended" table.
     48      *
     49      * gsmToChar(GSM_EXTENDED_ESCAPE) returns 0xffff
     50      */
     51     public static final byte GSM_EXTENDED_ESCAPE = 0x1B;
     52 
     53     /**
     54      * User data header requires one octet for length. Count as one septet, because
     55      * all combinations of header elements below will have at least one free bit
     56      * when padding to the nearest septet boundary.
     57      */
     58     public static final int UDH_SEPTET_COST_LENGTH = 1;
     59 
     60     /**
     61      * Using a non-default language locking shift table OR single shift table
     62      * requires a user data header of 3 octets, or 4 septets, plus UDH length.
     63      */
     64     public static final int UDH_SEPTET_COST_ONE_SHIFT_TABLE = 4;
     65 
     66     /**
     67      * Using a non-default language locking shift table AND single shift table
     68      * requires a user data header of 6 octets, or 7 septets, plus UDH length.
     69      */
     70     public static final int UDH_SEPTET_COST_TWO_SHIFT_TABLES = 7;
     71 
     72     /**
     73      * Multi-part messages require a user data header of 5 octets, or 6 septets,
     74      * plus UDH length.
     75      */
     76     public static final int UDH_SEPTET_COST_CONCATENATED_MESSAGE = 6;
     77 
     78     /**
     79      * For a specific text string, this object describes protocol
     80      * properties of encoding it for transmission as message user
     81      * data.
     82      */
     83     public static class TextEncodingDetails {
     84         /**
     85          *The number of SMS's required to encode the text.
     86          */
     87         public int msgCount;
     88 
     89         /**
     90          * The number of code units consumed so far, where code units
     91          * are basically characters in the encoding -- for example,
     92          * septets for the standard ASCII and GSM encodings, and 16
     93          * bits for Unicode.
     94          */
     95         public int codeUnitCount;
     96 
     97         /**
     98          * How many code units are still available without spilling
     99          * into an additional message.
    100          */
    101         public int codeUnitsRemaining;
    102 
    103         /**
    104          * The encoding code unit size (specified using
    105          * android.telephony.SmsMessage ENCODING_*).
    106          */
    107         public int codeUnitSize;
    108 
    109         /**
    110          * The GSM national language table to use, or 0 for the default 7-bit alphabet.
    111          */
    112         public int languageTable;
    113 
    114         /**
    115          * The GSM national language shift table to use, or 0 for the default 7-bit extension table.
    116          */
    117         public int languageShiftTable;
    118 
    119         @Override
    120         public String toString() {
    121             return "TextEncodingDetails " +
    122                     "{ msgCount=" + msgCount +
    123                     ", codeUnitCount=" + codeUnitCount +
    124                     ", codeUnitsRemaining=" + codeUnitsRemaining +
    125                     ", codeUnitSize=" + codeUnitSize +
    126                     ", languageTable=" + languageTable +
    127                     ", languageShiftTable=" + languageShiftTable +
    128                     " }";
    129         }
    130     }
    131 
    132     /**
    133      * Converts a char to a GSM 7 bit table index.
    134      * Returns ' ' in GSM alphabet if there's no possible match. Returns
    135      * GSM_EXTENDED_ESCAPE if this character is in the extended table.
    136      * In this case, you must call charToGsmExtended() for the value
    137      * that should follow GSM_EXTENDED_ESCAPE in the GSM alphabet string.
    138      * @param c the character to convert
    139      * @return the GSM 7 bit table index for the specified character
    140      */
    141     public static int
    142     charToGsm(char c) {
    143         try {
    144             return charToGsm(c, false);
    145         } catch (EncodeException ex) {
    146             // this should never happen
    147             return sCharsToGsmTables[0].get(' ', ' ');
    148         }
    149     }
    150 
    151     /**
    152      * Converts a char to a GSM 7 bit table index.
    153      * Returns GSM_EXTENDED_ESCAPE if this character is in the extended table.
    154      * In this case, you must call charToGsmExtended() for the value that
    155      * should follow GSM_EXTENDED_ESCAPE in the GSM alphabet string.
    156      *
    157      * @param c the character to convert
    158      * @param throwException If true, throws EncodeException on invalid char.
    159      *   If false, returns GSM alphabet ' ' char.
    160      * @throws EncodeException encode error when throwException is true
    161      * @return the GSM 7 bit table index for the specified character
    162      */
    163     public static int
    164     charToGsm(char c, boolean throwException) throws EncodeException {
    165         int ret;
    166 
    167         ret = sCharsToGsmTables[0].get(c, -1);
    168 
    169         if (ret == -1) {
    170             ret = sCharsToShiftTables[0].get(c, -1);
    171 
    172             if (ret == -1) {
    173                 if (throwException) {
    174                     throw new EncodeException(c);
    175                 } else {
    176                     return sCharsToGsmTables[0].get(' ', ' ');
    177                 }
    178             } else {
    179                 return GSM_EXTENDED_ESCAPE;
    180             }
    181         }
    182 
    183         return ret;
    184     }
    185 
    186     /**
    187      * Converts a char to an extended GSM 7 bit table index.
    188      * Extended chars should be escaped with GSM_EXTENDED_ESCAPE.
    189      * Returns ' ' in GSM alphabet if there's no possible match.
    190      * @param c the character to convert
    191      * @return the GSM 7 bit extended table index for the specified character
    192      */
    193     public static int
    194     charToGsmExtended(char c) {
    195         int ret;
    196 
    197         ret = sCharsToShiftTables[0].get(c, -1);
    198 
    199         if (ret == -1) {
    200             return sCharsToGsmTables[0].get(' ', ' ');
    201         }
    202 
    203         return ret;
    204     }
    205 
    206     /**
    207      * Converts a character in the GSM alphabet into a char.
    208      *
    209      * If GSM_EXTENDED_ESCAPE is passed, 0xffff is returned. In this case,
    210      * the following character in the stream should be decoded with
    211      * gsmExtendedToChar().
    212      *
    213      * If an unmappable value is passed (one greater than 127), ' ' is returned.
    214      *
    215      * @param gsmChar the GSM 7 bit table index to convert
    216      * @return the decoded character
    217      */
    218     public static char
    219     gsmToChar(int gsmChar) {
    220         if (gsmChar >= 0 && gsmChar < 128) {
    221             return sLanguageTables[0].charAt(gsmChar);
    222         } else {
    223             return ' ';
    224         }
    225     }
    226 
    227     /**
    228      * Converts a character in the extended GSM alphabet into a char
    229      *
    230      * if GSM_EXTENDED_ESCAPE is passed, ' ' is returned since no second
    231      * extension page has yet been defined (see Note 1 in table 6.2.1.1 of
    232      * TS 23.038 v7.00)
    233      *
    234      * If an unmappable value is passed, the character from the GSM 7 bit
    235      * default table will be used (table 6.2.1.1 of TS 23.038).
    236      *
    237      * @param gsmChar the GSM 7 bit extended table index to convert
    238      * @return the decoded character
    239      */
    240     public static char
    241     gsmExtendedToChar(int gsmChar) {
    242         if (gsmChar == GSM_EXTENDED_ESCAPE) {
    243             return ' ';
    244         } else if (gsmChar >= 0 && gsmChar < 128) {
    245             char c = sLanguageShiftTables[0].charAt(gsmChar);
    246             if (c == ' ') {
    247                 return sLanguageTables[0].charAt(gsmChar);
    248             } else {
    249                 return c;
    250             }
    251         } else {
    252             return ' ';     // out of range
    253         }
    254     }
    255 
    256     /**
    257      * Converts a String into a byte array containing the 7-bit packed
    258      * GSM Alphabet representation of the string. If a header is provided,
    259      * this is included in the returned byte array and padded to a septet
    260      * boundary. This method is used by OEM code.
    261      *
    262      * @param data The text string to encode.
    263      * @param header Optional header (including length byte) that precedes
    264      * the encoded data, padded to septet boundary.
    265      * @return Byte array containing header and encoded data.
    266      * @throws EncodeException if String is too large to encode
    267      * @see #stringToGsm7BitPackedWithHeader(String, byte[], int, int)
    268      */
    269     public static byte[] stringToGsm7BitPackedWithHeader(String data, byte[] header)
    270             throws EncodeException {
    271         return stringToGsm7BitPackedWithHeader(data, header, 0, 0);
    272     }
    273 
    274     /**
    275      * Converts a String into a byte array containing the 7-bit packed
    276      * GSM Alphabet representation of the string. If a header is provided,
    277      * this is included in the returned byte array and padded to a septet
    278      * boundary.
    279      *
    280      * Unencodable chars are encoded as spaces
    281      *
    282      * Byte 0 in the returned byte array is the count of septets used,
    283      * including the header and header padding. The returned byte array is
    284      * the minimum size required to store the packed septets. The returned
    285      * array cannot contain more than 255 septets.
    286      *
    287      * @param data The text string to encode.
    288      * @param header Optional header (including length byte) that precedes
    289      * the encoded data, padded to septet boundary.
    290      * @param languageTable the 7 bit language table, or 0 for the default GSM alphabet
    291      * @param languageShiftTable the 7 bit single shift language table, or 0 for the default
    292      *     GSM extension table
    293      * @return Byte array containing header and encoded data.
    294      * @throws EncodeException if String is too large to encode
    295      */
    296     public static byte[] stringToGsm7BitPackedWithHeader(String data, byte[] header,
    297             int languageTable, int languageShiftTable)
    298             throws EncodeException {
    299         if (header == null || header.length == 0) {
    300             return stringToGsm7BitPacked(data, languageTable, languageShiftTable);
    301         }
    302 
    303         int headerBits = (header.length + 1) * 8;
    304         int headerSeptets = (headerBits + 6) / 7;
    305 
    306         byte[] ret = stringToGsm7BitPacked(data, headerSeptets, true, languageTable,
    307                 languageShiftTable);
    308 
    309         // Paste in the header
    310         ret[1] = (byte)header.length;
    311         System.arraycopy(header, 0, ret, 2, header.length);
    312         return ret;
    313     }
    314 
    315     /**
    316      * Converts a String into a byte array containing
    317      * the 7-bit packed GSM Alphabet representation of the string.
    318      *
    319      * Unencodable chars are encoded as spaces
    320      *
    321      * Byte 0 in the returned byte array is the count of septets used
    322      * The returned byte array is the minimum size required to store
    323      * the packed septets. The returned array cannot contain more than 255
    324      * septets.
    325      *
    326      * @param data the data string to encode
    327      * @return the encoded string
    328      * @throws EncodeException if String is too large to encode
    329      */
    330     public static byte[] stringToGsm7BitPacked(String data)
    331             throws EncodeException {
    332         return stringToGsm7BitPacked(data, 0, true, 0, 0);
    333     }
    334 
    335     /**
    336      * Converts a String into a byte array containing
    337      * the 7-bit packed GSM Alphabet representation of the string.
    338      *
    339      * Unencodable chars are encoded as spaces
    340      *
    341      * Byte 0 in the returned byte array is the count of septets used
    342      * The returned byte array is the minimum size required to store
    343      * the packed septets. The returned array cannot contain more than 255
    344      * septets.
    345      *
    346      * @param data the data string to encode
    347      * @param languageTable the 7 bit language table, or 0 for the default GSM alphabet
    348      * @param languageShiftTable the 7 bit single shift language table, or 0 for the default
    349      *     GSM extension table
    350      * @return the encoded string
    351      * @throws EncodeException if String is too large to encode
    352      */
    353     public static byte[] stringToGsm7BitPacked(String data, int languageTable,
    354             int languageShiftTable)
    355             throws EncodeException {
    356         return stringToGsm7BitPacked(data, 0, true, languageTable, languageShiftTable);
    357     }
    358 
    359     /**
    360      * Converts a String into a byte array containing
    361      * the 7-bit packed GSM Alphabet representation of the string.
    362      *
    363      * Byte 0 in the returned byte array is the count of septets used
    364      * The returned byte array is the minimum size required to store
    365      * the packed septets. The returned array cannot contain more than 255
    366      * septets.
    367      *
    368      * @param data the text to convert to septets
    369      * @param startingSeptetOffset the number of padding septets to put before
    370      *  the character data at the beginning of the array
    371      * @param throwException If true, throws EncodeException on invalid char.
    372      *   If false, replaces unencodable char with GSM alphabet space char.
    373      * @param languageTable the 7 bit language table, or 0 for the default GSM alphabet
    374      * @param languageShiftTable the 7 bit single shift language table, or 0 for the default
    375      *     GSM extension table
    376      * @return the encoded message
    377      *
    378      * @throws EncodeException if String is too large to encode
    379      */
    380     public static byte[] stringToGsm7BitPacked(String data, int startingSeptetOffset,
    381             boolean throwException, int languageTable, int languageShiftTable)
    382             throws EncodeException {
    383         int dataLen = data.length();
    384         int septetCount = countGsmSeptetsUsingTables(data, !throwException,
    385                 languageTable, languageShiftTable);
    386         if (septetCount == -1) {
    387             throw new EncodeException("countGsmSeptetsUsingTables(): unencodable char");
    388         }
    389         septetCount += startingSeptetOffset;
    390         if (septetCount > 255) {
    391             throw new EncodeException("Payload cannot exceed 255 septets");
    392         }
    393         int byteCount = ((septetCount * 7) + 7) / 8;
    394         byte[] ret = new byte[byteCount + 1];  // Include space for one byte length prefix.
    395         SparseIntArray charToLanguageTable = sCharsToGsmTables[languageTable];
    396         SparseIntArray charToShiftTable = sCharsToShiftTables[languageShiftTable];
    397         for (int i = 0, septets = startingSeptetOffset, bitOffset = startingSeptetOffset * 7;
    398                  i < dataLen && septets < septetCount;
    399                  i++, bitOffset += 7) {
    400             char c = data.charAt(i);
    401             int v = charToLanguageTable.get(c, -1);
    402             if (v == -1) {
    403                 v = charToShiftTable.get(c, -1);  // Lookup the extended char.
    404                 if (v == -1) {
    405                     if (throwException) {
    406                         throw new EncodeException("stringToGsm7BitPacked(): unencodable char");
    407                     } else {
    408                         v = charToLanguageTable.get(' ', ' ');   // should return ASCII space
    409                     }
    410                 } else {
    411                     packSmsChar(ret, bitOffset, GSM_EXTENDED_ESCAPE);
    412                     bitOffset += 7;
    413                     septets++;
    414                 }
    415             }
    416             packSmsChar(ret, bitOffset, v);
    417             septets++;
    418         }
    419         ret[0] = (byte) (septetCount);  // Validated by check above.
    420         return ret;
    421     }
    422 
    423     /**
    424      * Pack a 7-bit char into its appropriate place in a byte array
    425      *
    426      * @param packedChars the destination byte array
    427      * @param bitOffset the bit offset that the septet should be packed at
    428      *                  (septet index * 7)
    429      * @param value the 7-bit character to store
    430      */
    431     private static void
    432     packSmsChar(byte[] packedChars, int bitOffset, int value) {
    433         int byteOffset = bitOffset / 8;
    434         int shift = bitOffset % 8;
    435 
    436         packedChars[++byteOffset] |= value << shift;
    437 
    438         if (shift > 1) {
    439             packedChars[++byteOffset] = (byte)(value >> (8 - shift));
    440         }
    441     }
    442 
    443     /**
    444      * Convert a GSM alphabet 7 bit packed string (SMS string) into a
    445      * {@link java.lang.String}.
    446      *
    447      * See TS 23.038 6.1.2.1 for SMS Character Packing
    448      *
    449      * @param pdu the raw data from the pdu
    450      * @param offset the byte offset of
    451      * @param lengthSeptets string length in septets, not bytes
    452      * @return String representation or null on decoding exception
    453      */
    454     public static String gsm7BitPackedToString(byte[] pdu, int offset,
    455             int lengthSeptets) {
    456         return gsm7BitPackedToString(pdu, offset, lengthSeptets, 0, 0, 0);
    457     }
    458 
    459     /**
    460      * Convert a GSM alphabet 7 bit packed string (SMS string) into a
    461      * {@link java.lang.String}.
    462      *
    463      * See TS 23.038 6.1.2.1 for SMS Character Packing
    464      *
    465      * @param pdu the raw data from the pdu
    466      * @param offset the byte offset of
    467      * @param lengthSeptets string length in septets, not bytes
    468      * @param numPaddingBits the number of padding bits before the start of the
    469      *  string in the first byte
    470      * @param languageTable the 7 bit language table, or 0 for the default GSM alphabet
    471      * @param shiftTable the 7 bit single shift language table, or 0 for the default
    472      *     GSM extension table
    473      * @return String representation or null on decoding exception
    474      */
    475     public static String gsm7BitPackedToString(byte[] pdu, int offset,
    476             int lengthSeptets, int numPaddingBits, int languageTable, int shiftTable) {
    477         StringBuilder ret = new StringBuilder(lengthSeptets);
    478 
    479         if (languageTable < 0 || languageTable > sLanguageTables.length) {
    480             Rlog.w(TAG, "unknown language table " + languageTable + ", using default");
    481             languageTable = 0;
    482         }
    483         if (shiftTable < 0 || shiftTable > sLanguageShiftTables.length) {
    484             Rlog.w(TAG, "unknown single shift table " + shiftTable + ", using default");
    485             shiftTable = 0;
    486         }
    487 
    488         try {
    489             boolean prevCharWasEscape = false;
    490             String languageTableToChar = sLanguageTables[languageTable];
    491             String shiftTableToChar = sLanguageShiftTables[shiftTable];
    492 
    493             if (languageTableToChar.isEmpty()) {
    494                 Rlog.w(TAG, "no language table for code " + languageTable + ", using default");
    495                 languageTableToChar = sLanguageTables[0];
    496             }
    497             if (shiftTableToChar.isEmpty()) {
    498                 Rlog.w(TAG, "no single shift table for code " + shiftTable + ", using default");
    499                 shiftTableToChar = sLanguageShiftTables[0];
    500             }
    501 
    502             for (int i = 0 ; i < lengthSeptets ; i++) {
    503                 int bitOffset = (7 * i) + numPaddingBits;
    504 
    505                 int byteOffset = bitOffset / 8;
    506                 int shift = bitOffset % 8;
    507                 int gsmVal;
    508 
    509                 gsmVal = (0x7f & (pdu[offset + byteOffset] >> shift));
    510 
    511                 // if it crosses a byte boundary
    512                 if (shift > 1) {
    513                     // set msb bits to 0
    514                     gsmVal &= 0x7f >> (shift - 1);
    515 
    516                     gsmVal |= 0x7f & (pdu[offset + byteOffset + 1] << (8 - shift));
    517                 }
    518 
    519                 if (prevCharWasEscape) {
    520                     if (gsmVal == GSM_EXTENDED_ESCAPE) {
    521                         ret.append(' ');    // display ' ' for reserved double escape sequence
    522                     } else {
    523                         char c = shiftTableToChar.charAt(gsmVal);
    524                         if (c == ' ') {
    525                             ret.append(languageTableToChar.charAt(gsmVal));
    526                         } else {
    527                             ret.append(c);
    528                         }
    529                     }
    530                     prevCharWasEscape = false;
    531                 } else if (gsmVal == GSM_EXTENDED_ESCAPE) {
    532                     prevCharWasEscape = true;
    533                 } else {
    534                     ret.append(languageTableToChar.charAt(gsmVal));
    535                 }
    536             }
    537         } catch (RuntimeException ex) {
    538             Rlog.e(TAG, "Error GSM 7 bit packed: ", ex);
    539             return null;
    540         }
    541 
    542         return ret.toString();
    543     }
    544 
    545 
    546     /**
    547      * Convert a GSM alphabet string that's stored in 8-bit unpacked
    548      * format (as it often appears in SIM records) into a String
    549      *
    550      * Field may be padded with trailing 0xff's. The decode stops
    551      * at the first 0xff encountered.
    552      *
    553      * @param data the byte array to decode
    554      * @param offset array offset for the first character to decode
    555      * @param length the number of bytes to decode
    556      * @return the decoded string
    557      */
    558     public static String
    559     gsm8BitUnpackedToString(byte[] data, int offset, int length) {
    560         return gsm8BitUnpackedToString(data, offset, length, "");
    561     }
    562 
    563     /**
    564      * Convert a GSM alphabet string that's stored in 8-bit unpacked
    565      * format (as it often appears in SIM records) into a String
    566      *
    567      * Field may be padded with trailing 0xff's. The decode stops
    568      * at the first 0xff encountered.
    569      *
    570      * Additionally, in some country(ex. Korea), there are non-ASCII or MBCS characters.
    571      * If a character set is given, characters in data are treat as MBCS.
    572      */
    573     public static String
    574     gsm8BitUnpackedToString(byte[] data, int offset, int length, String characterset) {
    575         boolean isMbcs = false;
    576         Charset charset = null;
    577         ByteBuffer mbcsBuffer = null;
    578 
    579         if (!TextUtils.isEmpty(characterset)
    580                 && !characterset.equalsIgnoreCase("us-ascii")
    581                 && Charset.isSupported(characterset)) {
    582             isMbcs = true;
    583             charset = Charset.forName(characterset);
    584             mbcsBuffer = ByteBuffer.allocate(2);
    585         }
    586 
    587         // Always use GSM 7 bit default alphabet table for this method
    588         String languageTableToChar = sLanguageTables[0];
    589         String shiftTableToChar = sLanguageShiftTables[0];
    590 
    591         StringBuilder ret = new StringBuilder(length);
    592         boolean prevWasEscape = false;
    593         for (int i = offset ; i < offset + length ; i++) {
    594             // Never underestimate the pain that can be caused
    595             // by signed bytes
    596             int c = data[i] & 0xff;
    597 
    598             if (c == 0xff) {
    599                 break;
    600             } else if (c == GSM_EXTENDED_ESCAPE) {
    601                 if (prevWasEscape) {
    602                     // Two escape chars in a row
    603                     // We treat this as a space
    604                     // See Note 1 in table 6.2.1.1 of TS 23.038 v7.00
    605                     ret.append(' ');
    606                     prevWasEscape = false;
    607                 } else {
    608                     prevWasEscape = true;
    609                 }
    610             } else {
    611                 if (prevWasEscape) {
    612                     char shiftChar = shiftTableToChar.charAt(c);
    613                     if (shiftChar == ' ') {
    614                         // display character from main table if not present in shift table
    615                         ret.append(languageTableToChar.charAt(c));
    616                     } else {
    617                         ret.append(shiftChar);
    618                     }
    619                 } else {
    620                     if (!isMbcs || c < 0x80 || i + 1 >= offset + length) {
    621                         ret.append(languageTableToChar.charAt(c));
    622                     } else {
    623                         // isMbcs must be true. So both mbcsBuffer and charset are initialized.
    624                         mbcsBuffer.clear();
    625                         mbcsBuffer.put(data, i++, 2);
    626                         mbcsBuffer.flip();
    627                         ret.append(charset.decode(mbcsBuffer).toString());
    628                     }
    629                 }
    630                 prevWasEscape = false;
    631             }
    632         }
    633 
    634         return ret.toString();
    635     }
    636 
    637     /**
    638      * Convert a string into an 8-bit unpacked GSM alphabet byte array.
    639      * Always uses GSM default 7-bit alphabet and extension table.
    640      * @param s the string to encode
    641      * @return the 8-bit GSM encoded byte array for the string
    642      */
    643     public static byte[]
    644     stringToGsm8BitPacked(String s) {
    645         byte[] ret;
    646 
    647         int septets = countGsmSeptetsUsingTables(s, true, 0, 0);
    648 
    649         // Enough for all the septets and the length byte prefix
    650         ret = new byte[septets];
    651 
    652         stringToGsm8BitUnpackedField(s, ret, 0, ret.length);
    653 
    654         return ret;
    655     }
    656 
    657 
    658     /**
    659      * Write a String into a GSM 8-bit unpacked field of
    660      * Field is padded with 0xff's, string is truncated if necessary
    661      *
    662      * @param s the string to encode
    663      * @param dest the destination byte array
    664      * @param offset the starting offset for the encoded string
    665      * @param length the maximum number of bytes to write
    666      */
    667     public static void
    668     stringToGsm8BitUnpackedField(String s, byte dest[], int offset, int length) {
    669         int outByteIndex = offset;
    670         SparseIntArray charToLanguageTable = sCharsToGsmTables[0];
    671         SparseIntArray charToShiftTable = sCharsToShiftTables[0];
    672 
    673         // Septets are stored in byte-aligned octets
    674         for (int i = 0, sz = s.length()
    675                 ; i < sz && (outByteIndex - offset) < length
    676                 ; i++
    677         ) {
    678             char c = s.charAt(i);
    679 
    680             int v = charToLanguageTable.get(c, -1);
    681 
    682             if (v == -1) {
    683                 v = charToShiftTable.get(c, -1);
    684                 if (v == -1) {
    685                     v = charToLanguageTable.get(' ', ' ');  // fall back to ASCII space
    686                 } else {
    687                     // make sure we can fit an escaped char
    688                     if (! (outByteIndex + 1 - offset < length)) {
    689                         break;
    690                     }
    691 
    692                     dest[outByteIndex++] = GSM_EXTENDED_ESCAPE;
    693                 }
    694             }
    695 
    696             dest[outByteIndex++] = (byte)v;
    697         }
    698 
    699         // pad with 0xff's
    700         while((outByteIndex - offset) < length) {
    701             dest[outByteIndex++] = (byte)0xff;
    702         }
    703     }
    704 
    705     /**
    706      * Returns the count of 7-bit GSM alphabet characters
    707      * needed to represent this character. Counts unencodable char as 1 septet.
    708      * @param c the character to examine
    709      * @return the number of septets for this character
    710      */
    711     public static int
    712     countGsmSeptets(char c) {
    713         try {
    714             return countGsmSeptets(c, false);
    715         } catch (EncodeException ex) {
    716             // This should never happen.
    717             return 0;
    718         }
    719     }
    720 
    721     /**
    722      * Returns the count of 7-bit GSM alphabet characters
    723      * needed to represent this character using the default 7 bit GSM alphabet.
    724      * @param c the character to examine
    725      * @param throwsException If true, throws EncodeException if unencodable
    726      * char. Otherwise, counts invalid char as 1 septet.
    727      * @return the number of septets for this character
    728      * @throws EncodeException the character can't be encoded and throwsException is true
    729      */
    730     public static int
    731     countGsmSeptets(char c, boolean throwsException) throws EncodeException {
    732         if (sCharsToGsmTables[0].get(c, -1) != -1) {
    733             return 1;
    734         }
    735 
    736         if (sCharsToShiftTables[0].get(c, -1) != -1) {
    737             return 2;
    738         }
    739 
    740         if (throwsException) {
    741             throw new EncodeException(c);
    742         } else {
    743             // count as a space char
    744             return 1;
    745         }
    746     }
    747 
    748     /**
    749      * Returns the count of 7-bit GSM alphabet characters needed
    750      * to represent this string, using the specified 7-bit language table
    751      * and extension table (0 for GSM default tables).
    752      * @param s the Unicode string that will be encoded
    753      * @param use7bitOnly allow using space in place of unencodable character if true,
    754      *     otherwise, return -1 if any characters are unencodable
    755      * @param languageTable the 7 bit language table, or 0 for the default GSM alphabet
    756      * @param languageShiftTable the 7 bit single shift language table, or 0 for the default
    757      *     GSM extension table
    758      * @return the septet count for s using the specified language tables, or -1 if any
    759      *     characters are unencodable and use7bitOnly is false
    760      */
    761     public static int countGsmSeptetsUsingTables(CharSequence s, boolean use7bitOnly,
    762             int languageTable, int languageShiftTable) {
    763         int count = 0;
    764         int sz = s.length();
    765         SparseIntArray charToLanguageTable = sCharsToGsmTables[languageTable];
    766         SparseIntArray charToShiftTable = sCharsToShiftTables[languageShiftTable];
    767         for (int i = 0; i < sz; i++) {
    768             char c = s.charAt(i);
    769             if (c == GSM_EXTENDED_ESCAPE) {
    770                 Rlog.w(TAG, "countGsmSeptets() string contains Escape character, skipping.");
    771                 continue;
    772             }
    773             if (charToLanguageTable.get(c, -1) != -1) {
    774                 count++;
    775             } else if (charToShiftTable.get(c, -1) != -1) {
    776                 count += 2; // escape + shift table index
    777             } else if (use7bitOnly) {
    778                 count++;    // encode as space
    779             } else {
    780                 return -1;  // caller must check for this case
    781             }
    782         }
    783         return count;
    784     }
    785 
    786     /**
    787      * Returns the count of 7-bit GSM alphabet characters
    788      * needed to represent this string, and the language table and
    789      * language shift table used to achieve this result.
    790      * For multi-part text messages, each message part may use its
    791      * own language table encoding as specified in the message header
    792      * for that message. However, this method will only return the
    793      * optimal encoding for the message as a whole. When the individual
    794      * pieces are encoded, a more optimal encoding may be chosen for each
    795      * piece of the message, but the message will be split into pieces
    796      * based on the encoding chosen for the message as a whole.
    797      * @param s the Unicode string that will be encoded
    798      * @param use7bitOnly allow using space in place of unencodable character if true,
    799      *     using the language table pair with the fewest unencodable characters
    800      * @return a TextEncodingDetails object containing the message and
    801      *     character counts for the most efficient 7-bit encoding,
    802      *     or null if there are no suitable language tables to encode the string.
    803      */
    804     public static TextEncodingDetails
    805     countGsmSeptets(CharSequence s, boolean use7bitOnly) {
    806         // Load enabled language tables from config.xml, including any MCC overlays
    807         if (!sDisableCountryEncodingCheck) {
    808             enableCountrySpecificEncodings();
    809         }
    810         // fast path for common case where no national language shift tables are enabled
    811         if (sEnabledSingleShiftTables.length + sEnabledLockingShiftTables.length == 0) {
    812             TextEncodingDetails ted = new TextEncodingDetails();
    813             int septets = GsmAlphabet.countGsmSeptetsUsingTables(s, use7bitOnly, 0, 0);
    814             if (septets == -1) {
    815                 return null;
    816             }
    817             ted.codeUnitSize = SmsConstants.ENCODING_7BIT;
    818             ted.codeUnitCount = septets;
    819             if (septets > SmsConstants.MAX_USER_DATA_SEPTETS) {
    820                 ted.msgCount = (septets + (SmsConstants.MAX_USER_DATA_SEPTETS_WITH_HEADER - 1)) /
    821                         SmsConstants.MAX_USER_DATA_SEPTETS_WITH_HEADER;
    822                 ted.codeUnitsRemaining = (ted.msgCount *
    823                         SmsConstants.MAX_USER_DATA_SEPTETS_WITH_HEADER) - septets;
    824             } else {
    825                 ted.msgCount = 1;
    826                 ted.codeUnitsRemaining = SmsConstants.MAX_USER_DATA_SEPTETS - septets;
    827             }
    828             ted.codeUnitSize = SmsConstants.ENCODING_7BIT;
    829             return ted;
    830         }
    831 
    832         int maxSingleShiftCode = sHighestEnabledSingleShiftCode;
    833         List<LanguagePairCount> lpcList = new ArrayList<LanguagePairCount>(
    834                 sEnabledLockingShiftTables.length + 1);
    835 
    836         // Always add default GSM 7-bit alphabet table
    837         lpcList.add(new LanguagePairCount(0));
    838         for (int i : sEnabledLockingShiftTables) {
    839             // Avoid adding default table twice in case 0 is in the list of allowed tables
    840             if (i != 0 && !sLanguageTables[i].isEmpty()) {
    841                 lpcList.add(new LanguagePairCount(i));
    842             }
    843         }
    844 
    845         int sz = s.length();
    846         // calculate septet count for each valid table / shift table pair
    847         for (int i = 0; i < sz && !lpcList.isEmpty(); i++) {
    848             char c = s.charAt(i);
    849             if (c == GSM_EXTENDED_ESCAPE) {
    850                 Rlog.w(TAG, "countGsmSeptets() string contains Escape character, ignoring!");
    851                 continue;
    852             }
    853             // iterate through enabled locking shift tables
    854             for (LanguagePairCount lpc : lpcList) {
    855                 int tableIndex = sCharsToGsmTables[lpc.languageCode].get(c, -1);
    856                 if (tableIndex == -1) {
    857                     // iterate through single shift tables for this locking table
    858                     for (int table = 0; table <= maxSingleShiftCode; table++) {
    859                         if (lpc.septetCounts[table] != -1) {
    860                             int shiftTableIndex = sCharsToShiftTables[table].get(c, -1);
    861                             if (shiftTableIndex == -1) {
    862                                 if (use7bitOnly) {
    863                                     // can't encode char, use space instead
    864                                     lpc.septetCounts[table]++;
    865                                     lpc.unencodableCounts[table]++;
    866                                 } else {
    867                                     // can't encode char, remove language pair from list
    868                                     lpc.septetCounts[table] = -1;
    869                                 }
    870                             } else {
    871                                 // encode as Escape + index into shift table
    872                                 lpc.septetCounts[table] += 2;
    873                             }
    874                         }
    875                     }
    876                 } else {
    877                     // encode as index into locking shift table for all pairs
    878                     for (int table = 0; table <= maxSingleShiftCode; table++) {
    879                         if (lpc.septetCounts[table] != -1) {
    880                             lpc.septetCounts[table]++;
    881                         }
    882                     }
    883                 }
    884             }
    885         }
    886 
    887         // find the least cost encoding (lowest message count and most code units remaining)
    888         TextEncodingDetails ted = new TextEncodingDetails();
    889         ted.msgCount = Integer.MAX_VALUE;
    890         ted.codeUnitSize = SmsConstants.ENCODING_7BIT;
    891         int minUnencodableCount = Integer.MAX_VALUE;
    892         for (LanguagePairCount lpc : lpcList) {
    893             for (int shiftTable = 0; shiftTable <= maxSingleShiftCode; shiftTable++) {
    894                 int septets = lpc.septetCounts[shiftTable];
    895                 if (septets == -1) {
    896                     continue;
    897                 }
    898                 int udhLength;
    899                 if (lpc.languageCode != 0 && shiftTable != 0) {
    900                     udhLength = UDH_SEPTET_COST_LENGTH + UDH_SEPTET_COST_TWO_SHIFT_TABLES;
    901                 } else if (lpc.languageCode != 0 || shiftTable != 0) {
    902                     udhLength = UDH_SEPTET_COST_LENGTH + UDH_SEPTET_COST_ONE_SHIFT_TABLE;
    903                 } else {
    904                     udhLength = 0;
    905                 }
    906                 int msgCount;
    907                 int septetsRemaining;
    908                 if (septets + udhLength > SmsConstants.MAX_USER_DATA_SEPTETS) {
    909                     if (udhLength == 0) {
    910                         udhLength = UDH_SEPTET_COST_LENGTH;
    911                     }
    912                     udhLength += UDH_SEPTET_COST_CONCATENATED_MESSAGE;
    913                     int septetsPerMessage = SmsConstants.MAX_USER_DATA_SEPTETS - udhLength;
    914                     msgCount = (septets + septetsPerMessage - 1) / septetsPerMessage;
    915                     septetsRemaining = (msgCount * septetsPerMessage) - septets;
    916                 } else {
    917                     msgCount = 1;
    918                     septetsRemaining = SmsConstants.MAX_USER_DATA_SEPTETS - udhLength - septets;
    919                 }
    920                 // for 7-bit only mode, use language pair with the least unencodable chars
    921                 int unencodableCount = lpc.unencodableCounts[shiftTable];
    922                 if (use7bitOnly && unencodableCount > minUnencodableCount) {
    923                     continue;
    924                 }
    925                 if ((use7bitOnly && unencodableCount < minUnencodableCount)
    926                         || msgCount < ted.msgCount || (msgCount == ted.msgCount
    927                         && septetsRemaining > ted.codeUnitsRemaining)) {
    928                     minUnencodableCount = unencodableCount;
    929                     ted.msgCount = msgCount;
    930                     ted.codeUnitCount = septets;
    931                     ted.codeUnitsRemaining = septetsRemaining;
    932                     ted.languageTable = lpc.languageCode;
    933                     ted.languageShiftTable = shiftTable;
    934                 }
    935             }
    936         }
    937 
    938         if (ted.msgCount == Integer.MAX_VALUE) {
    939             return null;
    940         }
    941 
    942         return ted;
    943     }
    944 
    945     /**
    946      * Returns the index into <code>s</code> of the first character
    947      * after <code>limit</code> septets have been reached, starting at
    948      * index <code>start</code>.  This is used when dividing messages
    949      * into units within the SMS message size limit.
    950      *
    951      * @param s source string
    952      * @param start index of where to start counting septets
    953      * @param limit maximum septets to include,
    954      *   e.g. <code>MAX_USER_DATA_SEPTETS</code>
    955      * @param langTable the 7 bit character table to use (0 for default GSM 7-bit alphabet)
    956      * @param langShiftTable the 7 bit shift table to use (0 for default GSM extension table)
    957      * @return index of first character that won't fit, or the length
    958      *   of the entire string if everything fits
    959      */
    960     public static int
    961     findGsmSeptetLimitIndex(String s, int start, int limit, int langTable, int langShiftTable) {
    962         int accumulator = 0;
    963         int size = s.length();
    964 
    965         SparseIntArray charToLangTable = sCharsToGsmTables[langTable];
    966         SparseIntArray charToLangShiftTable = sCharsToShiftTables[langShiftTable];
    967         for (int i = start; i < size; i++) {
    968             int encodedSeptet = charToLangTable.get(s.charAt(i), -1);
    969             if (encodedSeptet == -1) {
    970                 encodedSeptet = charToLangShiftTable.get(s.charAt(i), -1);
    971                 if (encodedSeptet == -1) {
    972                     // char not found, assume we're replacing with space
    973                     accumulator++;
    974                 } else {
    975                     accumulator += 2;  // escape character + shift table index
    976                 }
    977             } else {
    978                 accumulator++;
    979             }
    980             if (accumulator > limit) {
    981                 return i;
    982             }
    983         }
    984         return size;
    985     }
    986 
    987     /**
    988      * Modify the array of enabled national language single shift tables for SMS
    989      * encoding. This is used for unit testing, but could also be used to
    990      * modify the enabled encodings based on the active MCC/MNC, for example.
    991      *
    992      * @param tables the new list of enabled single shift tables
    993      */
    994     static synchronized void setEnabledSingleShiftTables(int[] tables) {
    995         sEnabledSingleShiftTables = tables;
    996         sDisableCountryEncodingCheck = true;
    997 
    998         if (tables.length > 0) {
    999             sHighestEnabledSingleShiftCode = tables[tables.length - 1];
   1000         } else {
   1001             sHighestEnabledSingleShiftCode = 0;
   1002         }
   1003     }
   1004 
   1005     /**
   1006      * Modify the array of enabled national language locking shift tables for SMS
   1007      * encoding. This is used for unit testing, but could also be used to
   1008      * modify the enabled encodings based on the active MCC/MNC, for example.
   1009      *
   1010      * @param tables the new list of enabled locking shift tables
   1011      */
   1012     static synchronized void setEnabledLockingShiftTables(int[] tables) {
   1013         sEnabledLockingShiftTables = tables;
   1014         sDisableCountryEncodingCheck = true;
   1015     }
   1016 
   1017     /**
   1018      * Return the array of enabled national language single shift tables for SMS
   1019      * encoding. This is used for unit testing. The returned array is not a copy, so
   1020      * the caller should be careful not to modify it.
   1021      *
   1022      * @return the list of enabled single shift tables
   1023      */
   1024     static synchronized int[] getEnabledSingleShiftTables() {
   1025         return sEnabledSingleShiftTables;
   1026     }
   1027 
   1028     /**
   1029      * Return the array of enabled national language locking shift tables for SMS
   1030      * encoding. This is used for unit testing. The returned array is not a copy, so
   1031      * the caller should be careful not to modify it.
   1032      *
   1033      * @return the list of enabled locking shift tables
   1034      */
   1035     static synchronized int[] getEnabledLockingShiftTables() {
   1036         return sEnabledLockingShiftTables;
   1037     }
   1038 
   1039     /**
   1040      * Enable country-specific language tables from MCC-specific overlays.
   1041      * @context the context to use to get the TelephonyManager
   1042      */
   1043     private static void enableCountrySpecificEncodings() {
   1044         Resources r = Resources.getSystem();
   1045         // See comments in frameworks/base/core/res/res/values/config.xml for allowed values
   1046         sEnabledSingleShiftTables = r.getIntArray(R.array.config_sms_enabled_single_shift_tables);
   1047         sEnabledLockingShiftTables = r.getIntArray(R.array.config_sms_enabled_locking_shift_tables);
   1048 
   1049         if (sEnabledSingleShiftTables.length > 0) {
   1050             sHighestEnabledSingleShiftCode =
   1051                     sEnabledSingleShiftTables[sEnabledSingleShiftTables.length-1];
   1052         } else {
   1053             sHighestEnabledSingleShiftCode = 0;
   1054         }
   1055     }
   1056 
   1057     /** Reverse mapping from Unicode characters to indexes into language tables. */
   1058     private static final SparseIntArray[] sCharsToGsmTables;
   1059 
   1060     /** Reverse mapping from Unicode characters to indexes into language shift tables. */
   1061     private static final SparseIntArray[] sCharsToShiftTables;
   1062 
   1063     /** OEM configured list of enabled national language single shift tables for encoding. */
   1064     private static int[] sEnabledSingleShiftTables;
   1065 
   1066     /** OEM configured list of enabled national language locking shift tables for encoding. */
   1067     private static int[] sEnabledLockingShiftTables;
   1068 
   1069     /** Highest language code to include in array of single shift counters. */
   1070     private static int sHighestEnabledSingleShiftCode;
   1071 
   1072     /** Flag to bypass check for country-specific overlays (for test cases only). */
   1073     private static boolean sDisableCountryEncodingCheck = false;
   1074 
   1075     /**
   1076      * Septet counter for a specific locking shift table and all of
   1077      * the single shift tables that it can be paired with.
   1078      */
   1079     private static class LanguagePairCount {
   1080         final int languageCode;
   1081         final int[] septetCounts;
   1082         final int[] unencodableCounts;
   1083         LanguagePairCount(int code) {
   1084             this.languageCode = code;
   1085             int maxSingleShiftCode = sHighestEnabledSingleShiftCode;
   1086             septetCounts = new int[maxSingleShiftCode + 1];
   1087             unencodableCounts = new int[maxSingleShiftCode + 1];
   1088             // set counters for disabled single shift tables to -1
   1089             // (GSM default extension table index 0 is always enabled)
   1090             for (int i = 1, tableOffset = 0; i <= maxSingleShiftCode; i++) {
   1091                 if (sEnabledSingleShiftTables[tableOffset] == i) {
   1092                     tableOffset++;
   1093                 } else {
   1094                     septetCounts[i] = -1;   // disabled
   1095                 }
   1096             }
   1097             // exclude Turkish locking + Turkish single shift table and
   1098             // Portuguese locking + Spanish single shift table (these
   1099             // combinations will never be optimal for any input).
   1100             if (code == 1 && maxSingleShiftCode >= 1) {
   1101                 septetCounts[1] = -1;   // Turkish + Turkish
   1102             } else if (code == 3 && maxSingleShiftCode >= 2) {
   1103                 septetCounts[2] = -1;   // Portuguese + Spanish
   1104             }
   1105         }
   1106     }
   1107 
   1108     /**
   1109      * GSM default 7 bit alphabet plus national language locking shift character tables.
   1110      * Comment lines above strings indicate the lower four bits of the table position.
   1111      */
   1112     private static final String[] sLanguageTables = {
   1113         /* 3GPP TS 23.038 V9.1.1 section 6.2.1 - GSM 7 bit Default Alphabet
   1114          01.....23.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.E.....F.....0.....1 */
   1115         "@\u00a3$\u00a5\u00e8\u00e9\u00f9\u00ec\u00f2\u00c7\n\u00d8\u00f8\r\u00c5\u00e5\u0394_"
   1116             // 2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....
   1117             + "\u03a6\u0393\u039b\u03a9\u03a0\u03a8\u03a3\u0398\u039e\uffff\u00c6\u00e6\u00df"
   1118             // F.....012.34.....56789ABCDEF0123456789ABCDEF0.....123456789ABCDEF0123456789A
   1119             + "\u00c9 !\"#\u00a4%&'()*+,-./0123456789:;<=>?\u00a1ABCDEFGHIJKLMNOPQRSTUVWXYZ"
   1120             // B.....C.....D.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D.....
   1121             + "\u00c4\u00d6\u00d1\u00dc\u00a7\u00bfabcdefghijklmnopqrstuvwxyz\u00e4\u00f6\u00f1"
   1122             // E.....F.....
   1123             + "\u00fc\u00e0",
   1124 
   1125         /* A.3.1 Turkish National Language Locking Shift Table
   1126          01.....23.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.E.....F.....0.....1 */
   1127         "@\u00a3$\u00a5\u20ac\u00e9\u00f9\u0131\u00f2\u00c7\n\u011e\u011f\r\u00c5\u00e5\u0394_"
   1128             // 2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....
   1129             + "\u03a6\u0393\u039b\u03a9\u03a0\u03a8\u03a3\u0398\u039e\uffff\u015e\u015f\u00df"
   1130             // F.....012.34.....56789ABCDEF0123456789ABCDEF0.....123456789ABCDEF0123456789A
   1131             + "\u00c9 !\"#\u00a4%&'()*+,-./0123456789:;<=>?\u0130ABCDEFGHIJKLMNOPQRSTUVWXYZ"
   1132             // B.....C.....D.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D.....
   1133             + "\u00c4\u00d6\u00d1\u00dc\u00a7\u00e7abcdefghijklmnopqrstuvwxyz\u00e4\u00f6\u00f1"
   1134             // E.....F.....
   1135             + "\u00fc\u00e0",
   1136 
   1137         /* A.3.2 Void (no locking shift table for Spanish) */
   1138         "",
   1139 
   1140         /* A.3.3 Portuguese National Language Locking Shift Table
   1141          01.....23.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.E.....F.....0.....1 */
   1142         "@\u00a3$\u00a5\u00ea\u00e9\u00fa\u00ed\u00f3\u00e7\n\u00d4\u00f4\r\u00c1\u00e1\u0394_"
   1143             // 2.....3.....4.....5.....67.8.....9.....AB.....C.....D.....E.....F.....012.34.....
   1144             + "\u00aa\u00c7\u00c0\u221e^\\\u20ac\u00d3|\uffff\u00c2\u00e2\u00ca\u00c9 !\"#\u00ba"
   1145             // 56789ABCDEF0123456789ABCDEF0.....123456789ABCDEF0123456789AB.....C.....D.....E.....
   1146             + "%&'()*+,-./0123456789:;<=>?\u00cdABCDEFGHIJKLMNOPQRSTUVWXYZ\u00c3\u00d5\u00da\u00dc"
   1147             // F.....0123456789ABCDEF0123456789AB.....C.....DE.....F.....
   1148             + "\u00a7~abcdefghijklmnopqrstuvwxyz\u00e3\u00f5`\u00fc\u00e0",
   1149 
   1150         /* A.3.4 Bengali National Language Locking Shift Table
   1151          0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....CD.EF.....0..... */
   1152         "\u0981\u0982\u0983\u0985\u0986\u0987\u0988\u0989\u098a\u098b\n\u098c \r \u098f\u0990"
   1153             // 123.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....F.....
   1154             + "  \u0993\u0994\u0995\u0996\u0997\u0998\u0999\u099a\uffff\u099b\u099c\u099d\u099e"
   1155             // 012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789ABC
   1156             + " !\u099f\u09a0\u09a1\u09a2\u09a3\u09a4)(\u09a5\u09a6,\u09a7.\u09a80123456789:; "
   1157             // D.....E.....F0.....1.....2.....3.....4.....56.....789A.....B.....C.....D.....
   1158             + "\u09aa\u09ab?\u09ac\u09ad\u09ae\u09af\u09b0 \u09b2   \u09b6\u09b7\u09b8\u09b9"
   1159             // E.....F.....0.....1.....2.....3.....4.....5.....6.....789.....A.....BCD.....E.....
   1160             + "\u09bc\u09bd\u09be\u09bf\u09c0\u09c1\u09c2\u09c3\u09c4  \u09c7\u09c8  \u09cb\u09cc"
   1161             // F.....0.....123456789ABCDEF0123456789AB.....C.....D.....E.....F.....
   1162             + "\u09cd\u09ceabcdefghijklmnopqrstuvwxyz\u09d7\u09dc\u09dd\u09f0\u09f1",
   1163 
   1164         /* A.3.5 Gujarati National Language Locking Shift Table
   1165          0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.EF.....0.....*/
   1166         "\u0a81\u0a82\u0a83\u0a85\u0a86\u0a87\u0a88\u0a89\u0a8a\u0a8b\n\u0a8c\u0a8d\r \u0a8f\u0a90"
   1167             // 1.....23.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....
   1168             + "\u0a91 \u0a93\u0a94\u0a95\u0a96\u0a97\u0a98\u0a99\u0a9a\uffff\u0a9b\u0a9c\u0a9d"
   1169             // F.....012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789AB
   1170             + "\u0a9e !\u0a9f\u0aa0\u0aa1\u0aa2\u0aa3\u0aa4)(\u0aa5\u0aa6,\u0aa7.\u0aa80123456789:;"
   1171             // CD.....E.....F0.....1.....2.....3.....4.....56.....7.....89.....A.....B.....C.....
   1172             + " \u0aaa\u0aab?\u0aac\u0aad\u0aae\u0aaf\u0ab0 \u0ab2\u0ab3 \u0ab5\u0ab6\u0ab7\u0ab8"
   1173             // D.....E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89.....A.....
   1174             + "\u0ab9\u0abc\u0abd\u0abe\u0abf\u0ac0\u0ac1\u0ac2\u0ac3\u0ac4\u0ac5 \u0ac7\u0ac8"
   1175             // B.....CD.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D.....E.....
   1176             + "\u0ac9 \u0acb\u0acc\u0acd\u0ad0abcdefghijklmnopqrstuvwxyz\u0ae0\u0ae1\u0ae2\u0ae3"
   1177             // F.....
   1178             + "\u0af1",
   1179 
   1180         /* A.3.6 Hindi National Language Locking Shift Table
   1181          0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.E.....F.....*/
   1182         "\u0901\u0902\u0903\u0905\u0906\u0907\u0908\u0909\u090a\u090b\n\u090c\u090d\r\u090e\u090f"
   1183             // 0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....
   1184             + "\u0910\u0911\u0912\u0913\u0914\u0915\u0916\u0917\u0918\u0919\u091a\uffff\u091b\u091c"
   1185             // E.....F.....012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....012345
   1186             + "\u091d\u091e !\u091f\u0920\u0921\u0922\u0923\u0924)(\u0925\u0926,\u0927.\u0928012345"
   1187             // 6789ABC.....D.....E.....F0.....1.....2.....3.....4.....5.....6.....7.....8.....
   1188             + "6789:;\u0929\u092a\u092b?\u092c\u092d\u092e\u092f\u0930\u0931\u0932\u0933\u0934"
   1189             // 9.....A.....B.....C.....D.....E.....F.....0.....1.....2.....3.....4.....5.....6.....
   1190             + "\u0935\u0936\u0937\u0938\u0939\u093c\u093d\u093e\u093f\u0940\u0941\u0942\u0943\u0944"
   1191             // 7.....8.....9.....A.....B.....C.....D.....E.....F.....0.....123456789ABCDEF012345678
   1192             + "\u0945\u0946\u0947\u0948\u0949\u094a\u094b\u094c\u094d\u0950abcdefghijklmnopqrstuvwx"
   1193             // 9AB.....C.....D.....E.....F.....
   1194             + "yz\u0972\u097b\u097c\u097e\u097f",
   1195 
   1196         /* A.3.7 Kannada National Language Locking Shift Table
   1197            NOTE: TS 23.038 V9.1.1 shows code 0x24 as \u0caa, corrected to \u0ca1 (typo)
   1198          01.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....CD.E.....F.....0.....1 */
   1199         " \u0c82\u0c83\u0c85\u0c86\u0c87\u0c88\u0c89\u0c8a\u0c8b\n\u0c8c \r\u0c8e\u0c8f\u0c90 "
   1200             // 2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....F.....
   1201             + "\u0c92\u0c93\u0c94\u0c95\u0c96\u0c97\u0c98\u0c99\u0c9a\uffff\u0c9b\u0c9c\u0c9d\u0c9e"
   1202             // 012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789ABC
   1203             + " !\u0c9f\u0ca0\u0ca1\u0ca2\u0ca3\u0ca4)(\u0ca5\u0ca6,\u0ca7.\u0ca80123456789:; "
   1204             // D.....E.....F0.....1.....2.....3.....4.....5.....6.....7.....89.....A.....B.....
   1205             + "\u0caa\u0cab?\u0cac\u0cad\u0cae\u0caf\u0cb0\u0cb1\u0cb2\u0cb3 \u0cb5\u0cb6\u0cb7"
   1206             // C.....D.....E.....F.....0.....1.....2.....3.....4.....5.....6.....78.....9.....
   1207             + "\u0cb8\u0cb9\u0cbc\u0cbd\u0cbe\u0cbf\u0cc0\u0cc1\u0cc2\u0cc3\u0cc4 \u0cc6\u0cc7"
   1208             // A.....BC.....D.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D.....
   1209             + "\u0cc8 \u0cca\u0ccb\u0ccc\u0ccd\u0cd5abcdefghijklmnopqrstuvwxyz\u0cd6\u0ce0\u0ce1"
   1210             // E.....F.....
   1211             + "\u0ce2\u0ce3",
   1212 
   1213         /* A.3.8 Malayalam National Language Locking Shift Table
   1214          01.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....CD.E.....F.....0.....1 */
   1215         " \u0d02\u0d03\u0d05\u0d06\u0d07\u0d08\u0d09\u0d0a\u0d0b\n\u0d0c \r\u0d0e\u0d0f\u0d10 "
   1216             // 2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....F.....
   1217             + "\u0d12\u0d13\u0d14\u0d15\u0d16\u0d17\u0d18\u0d19\u0d1a\uffff\u0d1b\u0d1c\u0d1d\u0d1e"
   1218             // 012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789ABC
   1219             + " !\u0d1f\u0d20\u0d21\u0d22\u0d23\u0d24)(\u0d25\u0d26,\u0d27.\u0d280123456789:; "
   1220             // D.....E.....F0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.....
   1221             + "\u0d2a\u0d2b?\u0d2c\u0d2d\u0d2e\u0d2f\u0d30\u0d31\u0d32\u0d33\u0d34\u0d35\u0d36"
   1222             // B.....C.....D.....EF.....0.....1.....2.....3.....4.....5.....6.....78.....9.....
   1223             + "\u0d37\u0d38\u0d39 \u0d3d\u0d3e\u0d3f\u0d40\u0d41\u0d42\u0d43\u0d44 \u0d46\u0d47"
   1224             // A.....BC.....D.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D.....
   1225             + "\u0d48 \u0d4a\u0d4b\u0d4c\u0d4d\u0d57abcdefghijklmnopqrstuvwxyz\u0d60\u0d61\u0d62"
   1226             // E.....F.....
   1227             + "\u0d63\u0d79",
   1228 
   1229         /* A.3.9 Oriya National Language Locking Shift Table
   1230          0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....CD.EF.....0.....12 */
   1231         "\u0b01\u0b02\u0b03\u0b05\u0b06\u0b07\u0b08\u0b09\u0b0a\u0b0b\n\u0b0c \r \u0b0f\u0b10  "
   1232             // 3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....F.....01
   1233             + "\u0b13\u0b14\u0b15\u0b16\u0b17\u0b18\u0b19\u0b1a\uffff\u0b1b\u0b1c\u0b1d\u0b1e !"
   1234             // 2.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789ABCD.....
   1235             + "\u0b1f\u0b20\u0b21\u0b22\u0b23\u0b24)(\u0b25\u0b26,\u0b27.\u0b280123456789:; \u0b2a"
   1236             // E.....F0.....1.....2.....3.....4.....56.....7.....89.....A.....B.....C.....D.....
   1237             + "\u0b2b?\u0b2c\u0b2d\u0b2e\u0b2f\u0b30 \u0b32\u0b33 \u0b35\u0b36\u0b37\u0b38\u0b39"
   1238             // E.....F.....0.....1.....2.....3.....4.....5.....6.....789.....A.....BCD.....E.....
   1239             + "\u0b3c\u0b3d\u0b3e\u0b3f\u0b40\u0b41\u0b42\u0b43\u0b44  \u0b47\u0b48  \u0b4b\u0b4c"
   1240             // F.....0.....123456789ABCDEF0123456789AB.....C.....D.....E.....F.....
   1241             + "\u0b4d\u0b56abcdefghijklmnopqrstuvwxyz\u0b57\u0b60\u0b61\u0b62\u0b63",
   1242 
   1243         /* A.3.10 Punjabi National Language Locking Shift Table
   1244          0.....1.....2.....3.....4.....5.....6.....7.....8.....9A.BCD.EF.....0.....123.....4.....*/
   1245         "\u0a01\u0a02\u0a03\u0a05\u0a06\u0a07\u0a08\u0a09\u0a0a \n  \r \u0a0f\u0a10  \u0a13\u0a14"
   1246             // 5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....F.....012.....3.....
   1247             + "\u0a15\u0a16\u0a17\u0a18\u0a19\u0a1a\uffff\u0a1b\u0a1c\u0a1d\u0a1e !\u0a1f\u0a20"
   1248             // 4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789ABCD.....E.....F0.....
   1249             + "\u0a21\u0a22\u0a23\u0a24)(\u0a25\u0a26,\u0a27.\u0a280123456789:; \u0a2a\u0a2b?\u0a2c"
   1250             // 1.....2.....3.....4.....56.....7.....89.....A.....BC.....D.....E.....F0.....1.....
   1251             + "\u0a2d\u0a2e\u0a2f\u0a30 \u0a32\u0a33 \u0a35\u0a36 \u0a38\u0a39\u0a3c \u0a3e\u0a3f"
   1252             // 2.....3.....4.....56789.....A.....BCD.....E.....F.....0.....123456789ABCDEF012345678
   1253             + "\u0a40\u0a41\u0a42    \u0a47\u0a48  \u0a4b\u0a4c\u0a4d\u0a51abcdefghijklmnopqrstuvwx"
   1254             // 9AB.....C.....D.....E.....F.....
   1255             + "yz\u0a70\u0a71\u0a72\u0a73\u0a74",
   1256 
   1257         /* A.3.11 Tamil National Language Locking Shift Table
   1258          01.....2.....3.....4.....5.....6.....7.....8.....9A.BCD.E.....F.....0.....12.....3..... */
   1259         " \u0b82\u0b83\u0b85\u0b86\u0b87\u0b88\u0b89\u0b8a \n  \r\u0b8e\u0b8f\u0b90 \u0b92\u0b93"
   1260             // 4.....5.....6789.....A.....B.....CD.....EF.....012.....3456.....7.....89ABCDEF.....
   1261             + "\u0b94\u0b95   \u0b99\u0b9a\uffff \u0b9c \u0b9e !\u0b9f   \u0ba3\u0ba4)(  , .\u0ba8"
   1262             // 0123456789ABC.....D.....EF012.....3.....4.....5.....6.....7.....8.....9.....A.....
   1263             + "0123456789:;\u0ba9\u0baa ?  \u0bae\u0baf\u0bb0\u0bb1\u0bb2\u0bb3\u0bb4\u0bb5\u0bb6"
   1264             // B.....C.....D.....EF0.....1.....2.....3.....4.....5678.....9.....A.....BC.....D.....
   1265             + "\u0bb7\u0bb8\u0bb9  \u0bbe\u0bbf\u0bc0\u0bc1\u0bc2   \u0bc6\u0bc7\u0bc8 \u0bca\u0bcb"
   1266             // E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D.....E.....F.....
   1267             + "\u0bcc\u0bcd\u0bd0abcdefghijklmnopqrstuvwxyz\u0bd7\u0bf0\u0bf1\u0bf2\u0bf9",
   1268 
   1269         /* A.3.12 Telugu National Language Locking Shift Table
   1270          0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....CD.E.....F.....0.....*/
   1271         "\u0c01\u0c02\u0c03\u0c05\u0c06\u0c07\u0c08\u0c09\u0c0a\u0c0b\n\u0c0c \r\u0c0e\u0c0f\u0c10"
   1272             // 12.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....
   1273             + " \u0c12\u0c13\u0c14\u0c15\u0c16\u0c17\u0c18\u0c19\u0c1a\uffff\u0c1b\u0c1c\u0c1d"
   1274             // F.....012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789AB
   1275             + "\u0c1e !\u0c1f\u0c20\u0c21\u0c22\u0c23\u0c24)(\u0c25\u0c26,\u0c27.\u0c280123456789:;"
   1276             // CD.....E.....F0.....1.....2.....3.....4.....5.....6.....7.....89.....A.....B.....
   1277             + " \u0c2a\u0c2b?\u0c2c\u0c2d\u0c2e\u0c2f\u0c30\u0c31\u0c32\u0c33 \u0c35\u0c36\u0c37"
   1278             // C.....D.....EF.....0.....1.....2.....3.....4.....5.....6.....78.....9.....A.....B
   1279             + "\u0c38\u0c39 \u0c3d\u0c3e\u0c3f\u0c40\u0c41\u0c42\u0c43\u0c44 \u0c46\u0c47\u0c48 "
   1280             // C.....D.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D.....E.....
   1281             + "\u0c4a\u0c4b\u0c4c\u0c4d\u0c55abcdefghijklmnopqrstuvwxyz\u0c56\u0c60\u0c61\u0c62"
   1282             // F.....
   1283             + "\u0c63",
   1284 
   1285         /* A.3.13 Urdu National Language Locking Shift Table
   1286          0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.E.....F.....*/
   1287         "\u0627\u0622\u0628\u067b\u0680\u067e\u06a6\u062a\u06c2\u067f\n\u0679\u067d\r\u067a\u067c"
   1288             // 0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....
   1289             + "\u062b\u062c\u0681\u0684\u0683\u0685\u0686\u0687\u062d\u062e\u062f\uffff\u068c\u0688"
   1290             // E.....F.....012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....012345
   1291             + "\u0689\u068a !\u068f\u068d\u0630\u0631\u0691\u0693)(\u0699\u0632,\u0696.\u0698012345"
   1292             // 6789ABC.....D.....E.....F0.....1.....2.....3.....4.....5.....6.....7.....8.....
   1293             + "6789:;\u069a\u0633\u0634?\u0635\u0636\u0637\u0638\u0639\u0641\u0642\u06a9\u06aa"
   1294             // 9.....A.....B.....C.....D.....E.....F.....0.....1.....2.....3.....4.....5.....6.....
   1295             + "\u06ab\u06af\u06b3\u06b1\u0644\u0645\u0646\u06ba\u06bb\u06bc\u0648\u06c4\u06d5\u06c1"
   1296             // 7.....8.....9.....A.....B.....C.....D.....E.....F.....0.....123456789ABCDEF012345678
   1297             + "\u06be\u0621\u06cc\u06d0\u06d2\u064d\u0650\u064f\u0657\u0654abcdefghijklmnopqrstuvwx"
   1298             // 9AB.....C.....D.....E.....F.....
   1299             + "yz\u0655\u0651\u0653\u0656\u0670"
   1300     };
   1301 
   1302     /**
   1303      * GSM default extension table plus national language single shift character tables.
   1304      */
   1305     private static final String[] sLanguageShiftTables = new String[]{
   1306         /* 6.2.1.1 GSM 7 bit Default Alphabet Extension Table
   1307          0123456789A.....BCDEF0123456789ABCDEF0123456789ABCDEF.0123456789ABCDEF0123456789ABCDEF */
   1308         "          \u000c         ^                   {}     \\            [~] |               "
   1309             // 0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF
   1310             + "                     \u20ac                          ",
   1311 
   1312         /* A.2.1 Turkish National Language Single Shift Table
   1313          0123456789A.....BCDEF0123456789ABCDEF0123456789ABCDEF.0123456789ABCDEF01234567.....8 */
   1314         "          \u000c         ^                   {}     \\            [~] |      \u011e "
   1315             // 9.....ABCDEF0123.....456789ABCDEF0123.....45.....67.....89.....ABCDEF0123.....
   1316             + "\u0130         \u015e               \u00e7 \u20ac \u011f \u0131         \u015f"
   1317             // 456789ABCDEF
   1318             + "            ",
   1319 
   1320         /* A.2.2 Spanish National Language Single Shift Table
   1321          0123456789.....A.....BCDEF0123456789ABCDEF0123456789ABCDEF.0123456789ABCDEF01.....23 */
   1322         "         \u00e7\u000c         ^                   {}     \\            [~] |\u00c1  "
   1323             // 456789.....ABCDEF.....012345.....6789ABCDEF01.....2345.....6789.....ABCDEF.....012
   1324             + "     \u00cd     \u00d3     \u00da           \u00e1   \u20ac   \u00ed     \u00f3   "
   1325             // 345.....6789ABCDEF
   1326             + "  \u00fa          ",
   1327 
   1328         /* A.2.3 Portuguese National Language Single Shift Table
   1329          012345.....6789.....A.....B.....C.....DE.....F.....012.....3.....45.....6.....7.....8....*/
   1330         "     \u00ea   \u00e7\u000c\u00d4\u00f4 \u00c1\u00e1  \u03a6\u0393^\u03a9\u03a0\u03a8\u03a3"
   1331             // 9.....ABCDEF.....0123456789ABCDEF.0123456789ABCDEF01.....23456789.....ABCDE
   1332             + "\u0398     \u00ca        {}     \\            [~] |\u00c0       \u00cd     "
   1333             // F.....012345.....6789AB.....C.....DEF01.....2345.....6789.....ABCDEF.....01234
   1334             + "\u00d3     \u00da     \u00c3\u00d5    \u00c2   \u20ac   \u00ed     \u00f3     "
   1335             // 5.....6789AB.....C.....DEF.....
   1336             + "\u00fa     \u00e3\u00f5  \u00e2",
   1337 
   1338         /* A.2.4 Bengali National Language Single Shift Table
   1339          01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */
   1340         "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u09e6\u09e7 \u09e8\u09e9"
   1341             // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C.....
   1342             + "\u09ea\u09eb\u09ec\u09ed\u09ee\u09ef\u09df\u09e0\u09e1\u09e2{}\u09e3\u09f2\u09f3"
   1343             // D.....E.....F.0.....1.....2.....3.....4.....56789ABCDEF0123456789ABCDEF
   1344             + "\u09f4\u09f5\\\u09f6\u09f7\u09f8\u09f9\u09fa       [~] |ABCDEFGHIJKLMNO"
   1345             // 0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF
   1346             + "PQRSTUVWXYZ          \u20ac                          ",
   1347 
   1348         /* A.2.5 Gujarati National Language Single Shift Table
   1349          01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */
   1350         "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0ae6\u0ae7"
   1351             // E.....F.....0.....1.....2.....3.....4.....5.....6789ABCDEF.0123456789ABCDEF
   1352             + "\u0ae8\u0ae9\u0aea\u0aeb\u0aec\u0aed\u0aee\u0aef  {}     \\            [~] "
   1353             // 0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF
   1354             + "|ABCDEFGHIJKLMNOPQRSTUVWXYZ          \u20ac                          ",
   1355 
   1356         /* A.2.6 Hindi National Language Single Shift Table
   1357          01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */
   1358         "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0966\u0967"
   1359             // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C.....
   1360             + "\u0968\u0969\u096a\u096b\u096c\u096d\u096e\u096f\u0951\u0952{}\u0953\u0954\u0958"
   1361             // D.....E.....F.0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.....
   1362             + "\u0959\u095a\\\u095b\u095c\u095d\u095e\u095f\u0960\u0961\u0962\u0963\u0970\u0971"
   1363             // BCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF
   1364             + " [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ          \u20ac                          ",
   1365 
   1366         /* A.2.7 Kannada National Language Single Shift Table
   1367          01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */
   1368         "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0ce6\u0ce7"
   1369             // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....BCDEF.01234567
   1370             + "\u0ce8\u0ce9\u0cea\u0ceb\u0cec\u0ced\u0cee\u0cef\u0cde\u0cf1{}\u0cf2    \\        "
   1371             // 89ABCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF
   1372             + "    [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ          \u20ac                          ",
   1373 
   1374         /* A.2.8 Malayalam National Language Single Shift Table
   1375          01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */
   1376         "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0d66\u0d67"
   1377             // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C.....
   1378             + "\u0d68\u0d69\u0d6a\u0d6b\u0d6c\u0d6d\u0d6e\u0d6f\u0d70\u0d71{}\u0d72\u0d73\u0d74"
   1379             // D.....E.....F.0.....1.....2.....3.....4.....56789ABCDEF0123456789ABCDEF0123456789A
   1380             + "\u0d75\u0d7a\\\u0d7b\u0d7c\u0d7d\u0d7e\u0d7f       [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ"
   1381             // BCDEF012345.....6789ABCDEF0123456789ABCDEF
   1382             + "          \u20ac                          ",
   1383 
   1384         /* A.2.9 Oriya National Language Single Shift Table
   1385          01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */
   1386         "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0b66\u0b67"
   1387             // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C.....DE
   1388             + "\u0b68\u0b69\u0b6a\u0b6b\u0b6c\u0b6d\u0b6e\u0b6f\u0b5c\u0b5d{}\u0b5f\u0b70\u0b71  "
   1389             // F.0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF0123456789A
   1390             + "\\            [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ          \u20ac                     "
   1391             // BCDEF
   1392             + "     ",
   1393 
   1394         /* A.2.10 Punjabi National Language Single Shift Table
   1395          01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */
   1396         "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0a66\u0a67"
   1397             // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C.....
   1398             + "\u0a68\u0a69\u0a6a\u0a6b\u0a6c\u0a6d\u0a6e\u0a6f\u0a59\u0a5a{}\u0a5b\u0a5c\u0a5e"
   1399             // D.....EF.0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF01
   1400             + "\u0a75 \\            [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ          \u20ac            "
   1401             // 23456789ABCDEF
   1402             + "              ",
   1403 
   1404         /* A.2.11 Tamil National Language Single Shift Table
   1405            NOTE: TS 23.038 V9.1.1 shows code 0x24 as \u0bef, corrected to \u0bee (typo)
   1406          01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */
   1407         "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0be6\u0be7"
   1408             // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C.....
   1409             + "\u0be8\u0be9\u0bea\u0beb\u0bec\u0bed\u0bee\u0bef\u0bf3\u0bf4{}\u0bf5\u0bf6\u0bf7"
   1410             // D.....E.....F.0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABC
   1411             + "\u0bf8\u0bfa\\            [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ          \u20ac       "
   1412             // DEF0123456789ABCDEF
   1413             + "                   ",
   1414 
   1415         /* A.2.12 Telugu National Language Single Shift Table
   1416            NOTE: TS 23.038 V9.1.1 shows code 0x22-0x23 as \u06cc\u06cd, corrected to \u0c6c\u0c6d
   1417          01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789ABC.....D.....E.....F..... */
   1418         "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*   \u0c66\u0c67\u0c68\u0c69"
   1419             // 0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C.....D.....E.....F.
   1420             + "\u0c6a\u0c6b\u0c6c\u0c6d\u0c6e\u0c6f\u0c58\u0c59{}\u0c78\u0c79\u0c7a\u0c7b\u0c7c\\"
   1421             // 0.....1.....2.....3456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABCD
   1422             + "\u0c7d\u0c7e\u0c7f         [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ          \u20ac        "
   1423             // EF0123456789ABCDEF
   1424             + "                  ",
   1425 
   1426         /* A.2.13 Urdu National Language Single Shift Table
   1427          01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */
   1428         "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0600\u0601 \u06f0\u06f1"
   1429             // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C.....
   1430             + "\u06f2\u06f3\u06f4\u06f5\u06f6\u06f7\u06f8\u06f9\u060c\u060d{}\u060e\u060f\u0610"
   1431             // D.....E.....F.0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.....
   1432             + "\u0611\u0612\\\u0613\u0614\u061b\u061f\u0640\u0652\u0658\u066b\u066c\u0672\u0673"
   1433             // B.....CDEF.....0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF
   1434             + "\u06cd[~]\u06d4|ABCDEFGHIJKLMNOPQRSTUVWXYZ          \u20ac                          "
   1435     };
   1436 
   1437     static {
   1438         enableCountrySpecificEncodings();
   1439         int numTables = sLanguageTables.length;
   1440         int numShiftTables = sLanguageShiftTables.length;
   1441         if (numTables != numShiftTables) {
   1442             Rlog.e(TAG, "Error: language tables array length " + numTables +
   1443                     " != shift tables array length " + numShiftTables);
   1444         }
   1445 
   1446         sCharsToGsmTables = new SparseIntArray[numTables];
   1447         for (int i = 0; i < numTables; i++) {
   1448             String table = sLanguageTables[i];
   1449 
   1450             int tableLen = table.length();
   1451             if (tableLen != 0 && tableLen != 128) {
   1452                 Rlog.e(TAG, "Error: language tables index " + i +
   1453                         " length " + tableLen + " (expected 128 or 0)");
   1454             }
   1455 
   1456             SparseIntArray charToGsmTable = new SparseIntArray(tableLen);
   1457             sCharsToGsmTables[i] = charToGsmTable;
   1458             for (int j = 0; j < tableLen; j++) {
   1459                 char c = table.charAt(j);
   1460                 charToGsmTable.put(c, j);
   1461             }
   1462         }
   1463 
   1464         sCharsToShiftTables = new SparseIntArray[numTables];
   1465         for (int i = 0; i < numShiftTables; i++) {
   1466             String shiftTable = sLanguageShiftTables[i];
   1467 
   1468             int shiftTableLen = shiftTable.length();
   1469             if (shiftTableLen != 0 && shiftTableLen != 128) {
   1470                 Rlog.e(TAG, "Error: language shift tables index " + i +
   1471                         " length " + shiftTableLen + " (expected 128 or 0)");
   1472             }
   1473 
   1474             SparseIntArray charToShiftTable = new SparseIntArray(shiftTableLen);
   1475             sCharsToShiftTables[i] = charToShiftTable;
   1476             for (int j = 0; j < shiftTableLen; j++) {
   1477                 char c = shiftTable.charAt(j);
   1478                 if (c != ' ') {
   1479                     charToShiftTable.put(c, j);
   1480                 }
   1481             }
   1482         }
   1483     }
   1484 }
   1485