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 GsmAlphabet()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 toString()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 charToGsm(char c)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 charToGsm(char c, boolean throwException)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 charToGsmExtended(char c)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 gsmToChar(int gsmChar)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 gsmExtendedToChar(int gsmChar)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 */ stringToGsm7BitPackedWithHeader(String data, byte[] header)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 */ stringToGsm7BitPackedWithHeader(String data, byte[] header, int languageTable, int languageShiftTable)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 */ stringToGsm7BitPacked(String data)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 */ stringToGsm7BitPacked(String data, int languageTable, int languageShiftTable)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 */ stringToGsm7BitPacked(String data, int startingSeptetOffset, boolean throwException, int languageTable, int languageShiftTable)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 packSmsChar(byte[] packedChars, int bitOffset, int value)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 */ gsm7BitPackedToString(byte[] pdu, int offset, int lengthSeptets)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 */ gsm7BitPackedToString(byte[] pdu, int offset, int lengthSeptets, int numPaddingBits, int languageTable, int shiftTable)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 gsm8BitUnpackedToString(byte[] data, int offset, int length)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 gsm8BitUnpackedToString(byte[] data, int offset, int length, String characterset)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 = 613 c < shiftTableToChar.length() ? shiftTableToChar.charAt(c) : ' '; 614 if (shiftChar == ' ') { 615 // display character from main table if not present in shift table 616 if (c < languageTableToChar.length()) { 617 ret.append(languageTableToChar.charAt(c)); 618 } else { 619 ret.append(' '); 620 } 621 } else { 622 ret.append(shiftChar); 623 } 624 } else { 625 if (!isMbcs || c < 0x80 || i + 1 >= offset + length) { 626 if (c < languageTableToChar.length()) { 627 ret.append(languageTableToChar.charAt(c)); 628 } else { 629 ret.append(' '); 630 } 631 } else { 632 // isMbcs must be true. So both mbcsBuffer and charset are initialized. 633 mbcsBuffer.clear(); 634 mbcsBuffer.put(data, i++, 2); 635 mbcsBuffer.flip(); 636 ret.append(charset.decode(mbcsBuffer).toString()); 637 } 638 } 639 prevWasEscape = false; 640 } 641 } 642 643 return ret.toString(); 644 } 645 646 /** 647 * Convert a string into an 8-bit unpacked GSM alphabet byte array. 648 * Always uses GSM default 7-bit alphabet and extension table. 649 * @param s the string to encode 650 * @return the 8-bit GSM encoded byte array for the string 651 */ 652 public static byte[] 653 stringToGsm8BitPacked(String s) { 654 byte[] ret; 655 656 int septets = countGsmSeptetsUsingTables(s, true, 0, 0); 657 658 // Enough for all the septets and the length byte prefix 659 ret = new byte[septets]; 660 661 stringToGsm8BitUnpackedField(s, ret, 0, ret.length); 662 663 return ret; 664 } 665 666 667 /** 668 * Write a String into a GSM 8-bit unpacked field of 669 * Field is padded with 0xff's, string is truncated if necessary 670 * 671 * @param s the string to encode 672 * @param dest the destination byte array 673 * @param offset the starting offset for the encoded string 674 * @param length the maximum number of bytes to write 675 */ 676 public static void 677 stringToGsm8BitUnpackedField(String s, byte dest[], int offset, int length) { 678 int outByteIndex = offset; 679 SparseIntArray charToLanguageTable = sCharsToGsmTables[0]; 680 SparseIntArray charToShiftTable = sCharsToShiftTables[0]; 681 682 // Septets are stored in byte-aligned octets 683 for (int i = 0, sz = s.length() 684 ; i < sz && (outByteIndex - offset) < length 685 ; i++ 686 ) { 687 char c = s.charAt(i); 688 689 int v = charToLanguageTable.get(c, -1); 690 691 if (v == -1) { 692 v = charToShiftTable.get(c, -1); 693 if (v == -1) { 694 v = charToLanguageTable.get(' ', ' '); // fall back to ASCII space 695 } else { 696 // make sure we can fit an escaped char 697 if (! (outByteIndex + 1 - offset < length)) { 698 break; 699 } 700 701 dest[outByteIndex++] = GSM_EXTENDED_ESCAPE; 702 } 703 } 704 705 dest[outByteIndex++] = (byte)v; 706 } 707 708 // pad with 0xff's 709 while((outByteIndex - offset) < length) { 710 dest[outByteIndex++] = (byte)0xff; 711 } 712 } 713 714 /** 715 * Returns the count of 7-bit GSM alphabet characters 716 * needed to represent this character. Counts unencodable char as 1 septet. 717 * @param c the character to examine 718 * @return the number of septets for this character 719 */ 720 public static int 721 countGsmSeptets(char c) { 722 try { 723 return countGsmSeptets(c, false); 724 } catch (EncodeException ex) { 725 // This should never happen. 726 return 0; 727 } 728 } 729 730 /** 731 * Returns the count of 7-bit GSM alphabet characters 732 * needed to represent this character using the default 7 bit GSM alphabet. 733 * @param c the character to examine 734 * @param throwsException If true, throws EncodeException if unencodable 735 * char. Otherwise, counts invalid char as 1 septet. 736 * @return the number of septets for this character 737 * @throws EncodeException the character can't be encoded and throwsException is true 738 */ 739 public static int 740 countGsmSeptets(char c, boolean throwsException) throws EncodeException { 741 if (sCharsToGsmTables[0].get(c, -1) != -1) { 742 return 1; 743 } 744 745 if (sCharsToShiftTables[0].get(c, -1) != -1) { 746 return 2; 747 } 748 749 if (throwsException) { 750 throw new EncodeException(c); 751 } else { 752 // count as a space char 753 return 1; 754 } 755 } 756 757 public static boolean isGsmSeptets(char c) { 758 if (sCharsToGsmTables[0].get(c, -1) != -1) { 759 return true; 760 } 761 762 if (sCharsToShiftTables[0].get(c, -1) != -1) { 763 return true; 764 } 765 766 return false; 767 } 768 769 /** 770 * Returns the count of 7-bit GSM alphabet characters needed 771 * to represent this string, using the specified 7-bit language table 772 * and extension table (0 for GSM default tables). 773 * @param s the Unicode string that will be encoded 774 * @param use7bitOnly allow using space in place of unencodable character if true, 775 * otherwise, return -1 if any characters are unencodable 776 * @param languageTable the 7 bit language table, or 0 for the default GSM alphabet 777 * @param languageShiftTable the 7 bit single shift language table, or 0 for the default 778 * GSM extension table 779 * @return the septet count for s using the specified language tables, or -1 if any 780 * characters are unencodable and use7bitOnly is false 781 */ 782 public static int countGsmSeptetsUsingTables(CharSequence s, boolean use7bitOnly, 783 int languageTable, int languageShiftTable) { 784 int count = 0; 785 int sz = s.length(); 786 SparseIntArray charToLanguageTable = sCharsToGsmTables[languageTable]; 787 SparseIntArray charToShiftTable = sCharsToShiftTables[languageShiftTable]; 788 for (int i = 0; i < sz; i++) { 789 char c = s.charAt(i); 790 if (c == GSM_EXTENDED_ESCAPE) { 791 Rlog.w(TAG, "countGsmSeptets() string contains Escape character, skipping."); 792 continue; 793 } 794 if (charToLanguageTable.get(c, -1) != -1) { 795 count++; 796 } else if (charToShiftTable.get(c, -1) != -1) { 797 count += 2; // escape + shift table index 798 } else if (use7bitOnly) { 799 count++; // encode as space 800 } else { 801 return -1; // caller must check for this case 802 } 803 } 804 return count; 805 } 806 807 /** 808 * Returns the count of 7-bit GSM alphabet characters 809 * needed to represent this string, and the language table and 810 * language shift table used to achieve this result. 811 * For multi-part text messages, each message part may use its 812 * own language table encoding as specified in the message header 813 * for that message. However, this method will only return the 814 * optimal encoding for the message as a whole. When the individual 815 * pieces are encoded, a more optimal encoding may be chosen for each 816 * piece of the message, but the message will be split into pieces 817 * based on the encoding chosen for the message as a whole. 818 * @param s the Unicode string that will be encoded 819 * @param use7bitOnly allow using space in place of unencodable character if true, 820 * using the language table pair with the fewest unencodable characters 821 * @return a TextEncodingDetails object containing the message and 822 * character counts for the most efficient 7-bit encoding, 823 * or null if there are no suitable language tables to encode the string. 824 */ 825 public static TextEncodingDetails 826 countGsmSeptets(CharSequence s, boolean use7bitOnly) { 827 // Load enabled language tables from config.xml, including any MCC overlays 828 if (!sDisableCountryEncodingCheck) { 829 enableCountrySpecificEncodings(); 830 } 831 // fast path for common case where no national language shift tables are enabled 832 if (sEnabledSingleShiftTables.length + sEnabledLockingShiftTables.length == 0) { 833 TextEncodingDetails ted = new TextEncodingDetails(); 834 int septets = GsmAlphabet.countGsmSeptetsUsingTables(s, use7bitOnly, 0, 0); 835 if (septets == -1) { 836 return null; 837 } 838 ted.codeUnitSize = SmsConstants.ENCODING_7BIT; 839 ted.codeUnitCount = septets; 840 if (septets > SmsConstants.MAX_USER_DATA_SEPTETS) { 841 ted.msgCount = (septets + (SmsConstants.MAX_USER_DATA_SEPTETS_WITH_HEADER - 1)) / 842 SmsConstants.MAX_USER_DATA_SEPTETS_WITH_HEADER; 843 ted.codeUnitsRemaining = (ted.msgCount * 844 SmsConstants.MAX_USER_DATA_SEPTETS_WITH_HEADER) - septets; 845 } else { 846 ted.msgCount = 1; 847 ted.codeUnitsRemaining = SmsConstants.MAX_USER_DATA_SEPTETS - septets; 848 } 849 ted.codeUnitSize = SmsConstants.ENCODING_7BIT; 850 return ted; 851 } 852 853 int maxSingleShiftCode = sHighestEnabledSingleShiftCode; 854 List<LanguagePairCount> lpcList = new ArrayList<LanguagePairCount>( 855 sEnabledLockingShiftTables.length + 1); 856 857 // Always add default GSM 7-bit alphabet table 858 lpcList.add(new LanguagePairCount(0)); 859 for (int i : sEnabledLockingShiftTables) { 860 // Avoid adding default table twice in case 0 is in the list of allowed tables 861 if (i != 0 && !sLanguageTables[i].isEmpty()) { 862 lpcList.add(new LanguagePairCount(i)); 863 } 864 } 865 866 int sz = s.length(); 867 // calculate septet count for each valid table / shift table pair 868 for (int i = 0; i < sz && !lpcList.isEmpty(); i++) { 869 char c = s.charAt(i); 870 if (c == GSM_EXTENDED_ESCAPE) { 871 Rlog.w(TAG, "countGsmSeptets() string contains Escape character, ignoring!"); 872 continue; 873 } 874 // iterate through enabled locking shift tables 875 for (LanguagePairCount lpc : lpcList) { 876 int tableIndex = sCharsToGsmTables[lpc.languageCode].get(c, -1); 877 if (tableIndex == -1) { 878 // iterate through single shift tables for this locking table 879 for (int table = 0; table <= maxSingleShiftCode; table++) { 880 if (lpc.septetCounts[table] != -1) { 881 int shiftTableIndex = sCharsToShiftTables[table].get(c, -1); 882 if (shiftTableIndex == -1) { 883 if (use7bitOnly) { 884 // can't encode char, use space instead 885 lpc.septetCounts[table]++; 886 lpc.unencodableCounts[table]++; 887 } else { 888 // can't encode char, remove language pair from list 889 lpc.septetCounts[table] = -1; 890 } 891 } else { 892 // encode as Escape + index into shift table 893 lpc.septetCounts[table] += 2; 894 } 895 } 896 } 897 } else { 898 // encode as index into locking shift table for all pairs 899 for (int table = 0; table <= maxSingleShiftCode; table++) { 900 if (lpc.septetCounts[table] != -1) { 901 lpc.septetCounts[table]++; 902 } 903 } 904 } 905 } 906 } 907 908 // find the least cost encoding (lowest message count and most code units remaining) 909 TextEncodingDetails ted = new TextEncodingDetails(); 910 ted.msgCount = Integer.MAX_VALUE; 911 ted.codeUnitSize = SmsConstants.ENCODING_7BIT; 912 int minUnencodableCount = Integer.MAX_VALUE; 913 for (LanguagePairCount lpc : lpcList) { 914 for (int shiftTable = 0; shiftTable <= maxSingleShiftCode; shiftTable++) { 915 int septets = lpc.septetCounts[shiftTable]; 916 if (septets == -1) { 917 continue; 918 } 919 int udhLength; 920 if (lpc.languageCode != 0 && shiftTable != 0) { 921 udhLength = UDH_SEPTET_COST_LENGTH + UDH_SEPTET_COST_TWO_SHIFT_TABLES; 922 } else if (lpc.languageCode != 0 || shiftTable != 0) { 923 udhLength = UDH_SEPTET_COST_LENGTH + UDH_SEPTET_COST_ONE_SHIFT_TABLE; 924 } else { 925 udhLength = 0; 926 } 927 int msgCount; 928 int septetsRemaining; 929 if (septets + udhLength > SmsConstants.MAX_USER_DATA_SEPTETS) { 930 if (udhLength == 0) { 931 udhLength = UDH_SEPTET_COST_LENGTH; 932 } 933 udhLength += UDH_SEPTET_COST_CONCATENATED_MESSAGE; 934 int septetsPerMessage = SmsConstants.MAX_USER_DATA_SEPTETS - udhLength; 935 msgCount = (septets + septetsPerMessage - 1) / septetsPerMessage; 936 septetsRemaining = (msgCount * septetsPerMessage) - septets; 937 } else { 938 msgCount = 1; 939 septetsRemaining = SmsConstants.MAX_USER_DATA_SEPTETS - udhLength - septets; 940 } 941 // for 7-bit only mode, use language pair with the least unencodable chars 942 int unencodableCount = lpc.unencodableCounts[shiftTable]; 943 if (use7bitOnly && unencodableCount > minUnencodableCount) { 944 continue; 945 } 946 if ((use7bitOnly && unencodableCount < minUnencodableCount) 947 || msgCount < ted.msgCount || (msgCount == ted.msgCount 948 && septetsRemaining > ted.codeUnitsRemaining)) { 949 minUnencodableCount = unencodableCount; 950 ted.msgCount = msgCount; 951 ted.codeUnitCount = septets; 952 ted.codeUnitsRemaining = septetsRemaining; 953 ted.languageTable = lpc.languageCode; 954 ted.languageShiftTable = shiftTable; 955 } 956 } 957 } 958 959 if (ted.msgCount == Integer.MAX_VALUE) { 960 return null; 961 } 962 963 return ted; 964 } 965 966 /** 967 * Returns the index into <code>s</code> of the first character 968 * after <code>limit</code> septets have been reached, starting at 969 * index <code>start</code>. This is used when dividing messages 970 * into units within the SMS message size limit. 971 * 972 * @param s source string 973 * @param start index of where to start counting septets 974 * @param limit maximum septets to include, 975 * e.g. <code>MAX_USER_DATA_SEPTETS</code> 976 * @param langTable the 7 bit character table to use (0 for default GSM 7-bit alphabet) 977 * @param langShiftTable the 7 bit shift table to use (0 for default GSM extension table) 978 * @return index of first character that won't fit, or the length 979 * of the entire string if everything fits 980 */ 981 public static int 982 findGsmSeptetLimitIndex(String s, int start, int limit, int langTable, int langShiftTable) { 983 int accumulator = 0; 984 int size = s.length(); 985 986 SparseIntArray charToLangTable = sCharsToGsmTables[langTable]; 987 SparseIntArray charToLangShiftTable = sCharsToShiftTables[langShiftTable]; 988 for (int i = start; i < size; i++) { 989 int encodedSeptet = charToLangTable.get(s.charAt(i), -1); 990 if (encodedSeptet == -1) { 991 encodedSeptet = charToLangShiftTable.get(s.charAt(i), -1); 992 if (encodedSeptet == -1) { 993 // char not found, assume we're replacing with space 994 accumulator++; 995 } else { 996 accumulator += 2; // escape character + shift table index 997 } 998 } else { 999 accumulator++; 1000 } 1001 if (accumulator > limit) { 1002 return i; 1003 } 1004 } 1005 return size; 1006 } 1007 1008 /** 1009 * Modify the array of enabled national language single shift tables for SMS 1010 * encoding. This is used for unit testing, but could also be used to 1011 * modify the enabled encodings based on the active MCC/MNC, for example. 1012 * 1013 * @param tables the new list of enabled single shift tables 1014 */ 1015 public static synchronized void setEnabledSingleShiftTables(int[] tables) { 1016 sEnabledSingleShiftTables = tables; 1017 sDisableCountryEncodingCheck = true; 1018 1019 if (tables.length > 0) { 1020 sHighestEnabledSingleShiftCode = tables[tables.length - 1]; 1021 } else { 1022 sHighestEnabledSingleShiftCode = 0; 1023 } 1024 } 1025 1026 /** 1027 * Modify the array of enabled national language locking shift tables for SMS 1028 * encoding. This is used for unit testing, but could also be used to 1029 * modify the enabled encodings based on the active MCC/MNC, for example. 1030 * 1031 * @param tables the new list of enabled locking shift tables 1032 */ 1033 public static synchronized void setEnabledLockingShiftTables(int[] tables) { 1034 sEnabledLockingShiftTables = tables; 1035 sDisableCountryEncodingCheck = true; 1036 } 1037 1038 /** 1039 * Return the array of enabled national language single shift tables for SMS 1040 * encoding. This is used for unit testing. The returned array is not a copy, so 1041 * the caller should be careful not to modify it. 1042 * 1043 * @return the list of enabled single shift tables 1044 */ 1045 public static synchronized int[] getEnabledSingleShiftTables() { 1046 return sEnabledSingleShiftTables; 1047 } 1048 1049 /** 1050 * Return the array of enabled national language locking shift tables for SMS 1051 * encoding. This is used for unit testing. The returned array is not a copy, so 1052 * the caller should be careful not to modify it. 1053 * 1054 * @return the list of enabled locking shift tables 1055 */ 1056 public static synchronized int[] getEnabledLockingShiftTables() { 1057 return sEnabledLockingShiftTables; 1058 } 1059 1060 /** 1061 * Enable country-specific language tables from MCC-specific overlays. 1062 * @context the context to use to get the TelephonyManager 1063 */ 1064 private static void enableCountrySpecificEncodings() { 1065 Resources r = Resources.getSystem(); 1066 // See comments in frameworks/base/core/res/res/values/config.xml for allowed values 1067 sEnabledSingleShiftTables = r.getIntArray(R.array.config_sms_enabled_single_shift_tables); 1068 sEnabledLockingShiftTables = r.getIntArray(R.array.config_sms_enabled_locking_shift_tables); 1069 1070 if (sEnabledSingleShiftTables.length > 0) { 1071 sHighestEnabledSingleShiftCode = 1072 sEnabledSingleShiftTables[sEnabledSingleShiftTables.length-1]; 1073 } else { 1074 sHighestEnabledSingleShiftCode = 0; 1075 } 1076 } 1077 1078 /** Reverse mapping from Unicode characters to indexes into language tables. */ 1079 private static final SparseIntArray[] sCharsToGsmTables; 1080 1081 /** Reverse mapping from Unicode characters to indexes into language shift tables. */ 1082 private static final SparseIntArray[] sCharsToShiftTables; 1083 1084 /** OEM configured list of enabled national language single shift tables for encoding. */ 1085 private static int[] sEnabledSingleShiftTables; 1086 1087 /** OEM configured list of enabled national language locking shift tables for encoding. */ 1088 private static int[] sEnabledLockingShiftTables; 1089 1090 /** Highest language code to include in array of single shift counters. */ 1091 private static int sHighestEnabledSingleShiftCode; 1092 1093 /** Flag to bypass check for country-specific overlays (for test cases only). */ 1094 private static boolean sDisableCountryEncodingCheck = false; 1095 1096 /** 1097 * Septet counter for a specific locking shift table and all of 1098 * the single shift tables that it can be paired with. 1099 */ 1100 private static class LanguagePairCount { 1101 final int languageCode; 1102 final int[] septetCounts; 1103 final int[] unencodableCounts; 1104 LanguagePairCount(int code) { 1105 this.languageCode = code; 1106 int maxSingleShiftCode = sHighestEnabledSingleShiftCode; 1107 septetCounts = new int[maxSingleShiftCode + 1]; 1108 unencodableCounts = new int[maxSingleShiftCode + 1]; 1109 // set counters for disabled single shift tables to -1 1110 // (GSM default extension table index 0 is always enabled) 1111 for (int i = 1, tableOffset = 0; i <= maxSingleShiftCode; i++) { 1112 if (sEnabledSingleShiftTables[tableOffset] == i) { 1113 tableOffset++; 1114 } else { 1115 septetCounts[i] = -1; // disabled 1116 } 1117 } 1118 // exclude Turkish locking + Turkish single shift table and 1119 // Portuguese locking + Spanish single shift table (these 1120 // combinations will never be optimal for any input). 1121 if (code == 1 && maxSingleShiftCode >= 1) { 1122 septetCounts[1] = -1; // Turkish + Turkish 1123 } else if (code == 3 && maxSingleShiftCode >= 2) { 1124 septetCounts[2] = -1; // Portuguese + Spanish 1125 } 1126 } 1127 } 1128 1129 /** 1130 * GSM default 7 bit alphabet plus national language locking shift character tables. 1131 * Comment lines above strings indicate the lower four bits of the table position. 1132 */ 1133 private static final String[] sLanguageTables = { 1134 /* 3GPP TS 23.038 V9.1.1 section 6.2.1 - GSM 7 bit Default Alphabet 1135 01.....23.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.E.....F.....0.....1 */ 1136 "@\u00a3$\u00a5\u00e8\u00e9\u00f9\u00ec\u00f2\u00c7\n\u00d8\u00f8\r\u00c5\u00e5\u0394_" 1137 // 2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E..... 1138 + "\u03a6\u0393\u039b\u03a9\u03a0\u03a8\u03a3\u0398\u039e\uffff\u00c6\u00e6\u00df" 1139 // F.....012.34.....56789ABCDEF0123456789ABCDEF0.....123456789ABCDEF0123456789A 1140 + "\u00c9 !\"#\u00a4%&'()*+,-./0123456789:;<=>?\u00a1ABCDEFGHIJKLMNOPQRSTUVWXYZ" 1141 // B.....C.....D.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D..... 1142 + "\u00c4\u00d6\u00d1\u00dc\u00a7\u00bfabcdefghijklmnopqrstuvwxyz\u00e4\u00f6\u00f1" 1143 // E.....F..... 1144 + "\u00fc\u00e0", 1145 1146 /* A.3.1 Turkish National Language Locking Shift Table 1147 01.....23.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.E.....F.....0.....1 */ 1148 "@\u00a3$\u00a5\u20ac\u00e9\u00f9\u0131\u00f2\u00c7\n\u011e\u011f\r\u00c5\u00e5\u0394_" 1149 // 2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E..... 1150 + "\u03a6\u0393\u039b\u03a9\u03a0\u03a8\u03a3\u0398\u039e\uffff\u015e\u015f\u00df" 1151 // F.....012.34.....56789ABCDEF0123456789ABCDEF0.....123456789ABCDEF0123456789A 1152 + "\u00c9 !\"#\u00a4%&'()*+,-./0123456789:;<=>?\u0130ABCDEFGHIJKLMNOPQRSTUVWXYZ" 1153 // B.....C.....D.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D..... 1154 + "\u00c4\u00d6\u00d1\u00dc\u00a7\u00e7abcdefghijklmnopqrstuvwxyz\u00e4\u00f6\u00f1" 1155 // E.....F..... 1156 + "\u00fc\u00e0", 1157 1158 /* A.3.2 Void (no locking shift table for Spanish) */ 1159 "", 1160 1161 /* A.3.3 Portuguese National Language Locking Shift Table 1162 01.....23.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.E.....F.....0.....1 */ 1163 "@\u00a3$\u00a5\u00ea\u00e9\u00fa\u00ed\u00f3\u00e7\n\u00d4\u00f4\r\u00c1\u00e1\u0394_" 1164 // 2.....3.....4.....5.....67.8.....9.....AB.....C.....D.....E.....F.....012.34..... 1165 + "\u00aa\u00c7\u00c0\u221e^\\\u20ac\u00d3|\uffff\u00c2\u00e2\u00ca\u00c9 !\"#\u00ba" 1166 // 56789ABCDEF0123456789ABCDEF0.....123456789ABCDEF0123456789AB.....C.....D.....E..... 1167 + "%&'()*+,-./0123456789:;<=>?\u00cdABCDEFGHIJKLMNOPQRSTUVWXYZ\u00c3\u00d5\u00da\u00dc" 1168 // F.....0123456789ABCDEF0123456789AB.....C.....DE.....F..... 1169 + "\u00a7~abcdefghijklmnopqrstuvwxyz\u00e3\u00f5`\u00fc\u00e0", 1170 1171 /* A.3.4 Bengali National Language Locking Shift Table 1172 0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....CD.EF.....0..... */ 1173 "\u0981\u0982\u0983\u0985\u0986\u0987\u0988\u0989\u098a\u098b\n\u098c \r \u098f\u0990" 1174 // 123.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....F..... 1175 + " \u0993\u0994\u0995\u0996\u0997\u0998\u0999\u099a\uffff\u099b\u099c\u099d\u099e" 1176 // 012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789ABC 1177 + " !\u099f\u09a0\u09a1\u09a2\u09a3\u09a4)(\u09a5\u09a6,\u09a7.\u09a80123456789:; " 1178 // D.....E.....F0.....1.....2.....3.....4.....56.....789A.....B.....C.....D..... 1179 + "\u09aa\u09ab?\u09ac\u09ad\u09ae\u09af\u09b0 \u09b2 \u09b6\u09b7\u09b8\u09b9" 1180 // E.....F.....0.....1.....2.....3.....4.....5.....6.....789.....A.....BCD.....E..... 1181 + "\u09bc\u09bd\u09be\u09bf\u09c0\u09c1\u09c2\u09c3\u09c4 \u09c7\u09c8 \u09cb\u09cc" 1182 // F.....0.....123456789ABCDEF0123456789AB.....C.....D.....E.....F..... 1183 + "\u09cd\u09ceabcdefghijklmnopqrstuvwxyz\u09d7\u09dc\u09dd\u09f0\u09f1", 1184 1185 /* A.3.5 Gujarati National Language Locking Shift Table 1186 0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.EF.....0.....*/ 1187 "\u0a81\u0a82\u0a83\u0a85\u0a86\u0a87\u0a88\u0a89\u0a8a\u0a8b\n\u0a8c\u0a8d\r \u0a8f\u0a90" 1188 // 1.....23.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E..... 1189 + "\u0a91 \u0a93\u0a94\u0a95\u0a96\u0a97\u0a98\u0a99\u0a9a\uffff\u0a9b\u0a9c\u0a9d" 1190 // F.....012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789AB 1191 + "\u0a9e !\u0a9f\u0aa0\u0aa1\u0aa2\u0aa3\u0aa4)(\u0aa5\u0aa6,\u0aa7.\u0aa80123456789:;" 1192 // CD.....E.....F0.....1.....2.....3.....4.....56.....7.....89.....A.....B.....C..... 1193 + " \u0aaa\u0aab?\u0aac\u0aad\u0aae\u0aaf\u0ab0 \u0ab2\u0ab3 \u0ab5\u0ab6\u0ab7\u0ab8" 1194 // D.....E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89.....A..... 1195 + "\u0ab9\u0abc\u0abd\u0abe\u0abf\u0ac0\u0ac1\u0ac2\u0ac3\u0ac4\u0ac5 \u0ac7\u0ac8" 1196 // B.....CD.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D.....E..... 1197 + "\u0ac9 \u0acb\u0acc\u0acd\u0ad0abcdefghijklmnopqrstuvwxyz\u0ae0\u0ae1\u0ae2\u0ae3" 1198 // F..... 1199 + "\u0af1", 1200 1201 /* A.3.6 Hindi National Language Locking Shift Table 1202 0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.E.....F.....*/ 1203 "\u0901\u0902\u0903\u0905\u0906\u0907\u0908\u0909\u090a\u090b\n\u090c\u090d\r\u090e\u090f" 1204 // 0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D..... 1205 + "\u0910\u0911\u0912\u0913\u0914\u0915\u0916\u0917\u0918\u0919\u091a\uffff\u091b\u091c" 1206 // E.....F.....012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....012345 1207 + "\u091d\u091e !\u091f\u0920\u0921\u0922\u0923\u0924)(\u0925\u0926,\u0927.\u0928012345" 1208 // 6789ABC.....D.....E.....F0.....1.....2.....3.....4.....5.....6.....7.....8..... 1209 + "6789:;\u0929\u092a\u092b?\u092c\u092d\u092e\u092f\u0930\u0931\u0932\u0933\u0934" 1210 // 9.....A.....B.....C.....D.....E.....F.....0.....1.....2.....3.....4.....5.....6..... 1211 + "\u0935\u0936\u0937\u0938\u0939\u093c\u093d\u093e\u093f\u0940\u0941\u0942\u0943\u0944" 1212 // 7.....8.....9.....A.....B.....C.....D.....E.....F.....0.....123456789ABCDEF012345678 1213 + "\u0945\u0946\u0947\u0948\u0949\u094a\u094b\u094c\u094d\u0950abcdefghijklmnopqrstuvwx" 1214 // 9AB.....C.....D.....E.....F..... 1215 + "yz\u0972\u097b\u097c\u097e\u097f", 1216 1217 /* A.3.7 Kannada National Language Locking Shift Table 1218 NOTE: TS 23.038 V9.1.1 shows code 0x24 as \u0caa, corrected to \u0ca1 (typo) 1219 01.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....CD.E.....F.....0.....1 */ 1220 " \u0c82\u0c83\u0c85\u0c86\u0c87\u0c88\u0c89\u0c8a\u0c8b\n\u0c8c \r\u0c8e\u0c8f\u0c90 " 1221 // 2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....F..... 1222 + "\u0c92\u0c93\u0c94\u0c95\u0c96\u0c97\u0c98\u0c99\u0c9a\uffff\u0c9b\u0c9c\u0c9d\u0c9e" 1223 // 012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789ABC 1224 + " !\u0c9f\u0ca0\u0ca1\u0ca2\u0ca3\u0ca4)(\u0ca5\u0ca6,\u0ca7.\u0ca80123456789:; " 1225 // D.....E.....F0.....1.....2.....3.....4.....5.....6.....7.....89.....A.....B..... 1226 + "\u0caa\u0cab?\u0cac\u0cad\u0cae\u0caf\u0cb0\u0cb1\u0cb2\u0cb3 \u0cb5\u0cb6\u0cb7" 1227 // C.....D.....E.....F.....0.....1.....2.....3.....4.....5.....6.....78.....9..... 1228 + "\u0cb8\u0cb9\u0cbc\u0cbd\u0cbe\u0cbf\u0cc0\u0cc1\u0cc2\u0cc3\u0cc4 \u0cc6\u0cc7" 1229 // A.....BC.....D.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D..... 1230 + "\u0cc8 \u0cca\u0ccb\u0ccc\u0ccd\u0cd5abcdefghijklmnopqrstuvwxyz\u0cd6\u0ce0\u0ce1" 1231 // E.....F..... 1232 + "\u0ce2\u0ce3", 1233 1234 /* A.3.8 Malayalam National Language Locking Shift Table 1235 01.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....CD.E.....F.....0.....1 */ 1236 " \u0d02\u0d03\u0d05\u0d06\u0d07\u0d08\u0d09\u0d0a\u0d0b\n\u0d0c \r\u0d0e\u0d0f\u0d10 " 1237 // 2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....F..... 1238 + "\u0d12\u0d13\u0d14\u0d15\u0d16\u0d17\u0d18\u0d19\u0d1a\uffff\u0d1b\u0d1c\u0d1d\u0d1e" 1239 // 012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789ABC 1240 + " !\u0d1f\u0d20\u0d21\u0d22\u0d23\u0d24)(\u0d25\u0d26,\u0d27.\u0d280123456789:; " 1241 // D.....E.....F0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A..... 1242 + "\u0d2a\u0d2b?\u0d2c\u0d2d\u0d2e\u0d2f\u0d30\u0d31\u0d32\u0d33\u0d34\u0d35\u0d36" 1243 // B.....C.....D.....EF.....0.....1.....2.....3.....4.....5.....6.....78.....9..... 1244 + "\u0d37\u0d38\u0d39 \u0d3d\u0d3e\u0d3f\u0d40\u0d41\u0d42\u0d43\u0d44 \u0d46\u0d47" 1245 // A.....BC.....D.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D..... 1246 + "\u0d48 \u0d4a\u0d4b\u0d4c\u0d4d\u0d57abcdefghijklmnopqrstuvwxyz\u0d60\u0d61\u0d62" 1247 // E.....F..... 1248 + "\u0d63\u0d79", 1249 1250 /* A.3.9 Oriya National Language Locking Shift Table 1251 0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....CD.EF.....0.....12 */ 1252 "\u0b01\u0b02\u0b03\u0b05\u0b06\u0b07\u0b08\u0b09\u0b0a\u0b0b\n\u0b0c \r \u0b0f\u0b10 " 1253 // 3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....F.....01 1254 + "\u0b13\u0b14\u0b15\u0b16\u0b17\u0b18\u0b19\u0b1a\uffff\u0b1b\u0b1c\u0b1d\u0b1e !" 1255 // 2.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789ABCD..... 1256 + "\u0b1f\u0b20\u0b21\u0b22\u0b23\u0b24)(\u0b25\u0b26,\u0b27.\u0b280123456789:; \u0b2a" 1257 // E.....F0.....1.....2.....3.....4.....56.....7.....89.....A.....B.....C.....D..... 1258 + "\u0b2b?\u0b2c\u0b2d\u0b2e\u0b2f\u0b30 \u0b32\u0b33 \u0b35\u0b36\u0b37\u0b38\u0b39" 1259 // E.....F.....0.....1.....2.....3.....4.....5.....6.....789.....A.....BCD.....E..... 1260 + "\u0b3c\u0b3d\u0b3e\u0b3f\u0b40\u0b41\u0b42\u0b43\u0b44 \u0b47\u0b48 \u0b4b\u0b4c" 1261 // F.....0.....123456789ABCDEF0123456789AB.....C.....D.....E.....F..... 1262 + "\u0b4d\u0b56abcdefghijklmnopqrstuvwxyz\u0b57\u0b60\u0b61\u0b62\u0b63", 1263 1264 /* A.3.10 Punjabi National Language Locking Shift Table 1265 0.....1.....2.....3.....4.....5.....6.....7.....8.....9A.BCD.EF.....0.....123.....4.....*/ 1266 "\u0a01\u0a02\u0a03\u0a05\u0a06\u0a07\u0a08\u0a09\u0a0a \n \r \u0a0f\u0a10 \u0a13\u0a14" 1267 // 5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....F.....012.....3..... 1268 + "\u0a15\u0a16\u0a17\u0a18\u0a19\u0a1a\uffff\u0a1b\u0a1c\u0a1d\u0a1e !\u0a1f\u0a20" 1269 // 4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789ABCD.....E.....F0..... 1270 + "\u0a21\u0a22\u0a23\u0a24)(\u0a25\u0a26,\u0a27.\u0a280123456789:; \u0a2a\u0a2b?\u0a2c" 1271 // 1.....2.....3.....4.....56.....7.....89.....A.....BC.....D.....E.....F0.....1..... 1272 + "\u0a2d\u0a2e\u0a2f\u0a30 \u0a32\u0a33 \u0a35\u0a36 \u0a38\u0a39\u0a3c \u0a3e\u0a3f" 1273 // 2.....3.....4.....56789.....A.....BCD.....E.....F.....0.....123456789ABCDEF012345678 1274 + "\u0a40\u0a41\u0a42 \u0a47\u0a48 \u0a4b\u0a4c\u0a4d\u0a51abcdefghijklmnopqrstuvwx" 1275 // 9AB.....C.....D.....E.....F..... 1276 + "yz\u0a70\u0a71\u0a72\u0a73\u0a74", 1277 1278 /* A.3.11 Tamil National Language Locking Shift Table 1279 01.....2.....3.....4.....5.....6.....7.....8.....9A.BCD.E.....F.....0.....12.....3..... */ 1280 " \u0b82\u0b83\u0b85\u0b86\u0b87\u0b88\u0b89\u0b8a \n \r\u0b8e\u0b8f\u0b90 \u0b92\u0b93" 1281 // 4.....5.....6789.....A.....B.....CD.....EF.....012.....3456.....7.....89ABCDEF..... 1282 + "\u0b94\u0b95 \u0b99\u0b9a\uffff \u0b9c \u0b9e !\u0b9f \u0ba3\u0ba4)( , .\u0ba8" 1283 // 0123456789ABC.....D.....EF012.....3.....4.....5.....6.....7.....8.....9.....A..... 1284 + "0123456789:;\u0ba9\u0baa ? \u0bae\u0baf\u0bb0\u0bb1\u0bb2\u0bb3\u0bb4\u0bb5\u0bb6" 1285 // B.....C.....D.....EF0.....1.....2.....3.....4.....5678.....9.....A.....BC.....D..... 1286 + "\u0bb7\u0bb8\u0bb9 \u0bbe\u0bbf\u0bc0\u0bc1\u0bc2 \u0bc6\u0bc7\u0bc8 \u0bca\u0bcb" 1287 // E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D.....E.....F..... 1288 + "\u0bcc\u0bcd\u0bd0abcdefghijklmnopqrstuvwxyz\u0bd7\u0bf0\u0bf1\u0bf2\u0bf9", 1289 1290 /* A.3.12 Telugu National Language Locking Shift Table 1291 0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....CD.E.....F.....0.....*/ 1292 "\u0c01\u0c02\u0c03\u0c05\u0c06\u0c07\u0c08\u0c09\u0c0a\u0c0b\n\u0c0c \r\u0c0e\u0c0f\u0c10" 1293 // 12.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E..... 1294 + " \u0c12\u0c13\u0c14\u0c15\u0c16\u0c17\u0c18\u0c19\u0c1a\uffff\u0c1b\u0c1c\u0c1d" 1295 // F.....012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789AB 1296 + "\u0c1e !\u0c1f\u0c20\u0c21\u0c22\u0c23\u0c24)(\u0c25\u0c26,\u0c27.\u0c280123456789:;" 1297 // CD.....E.....F0.....1.....2.....3.....4.....5.....6.....7.....89.....A.....B..... 1298 + " \u0c2a\u0c2b?\u0c2c\u0c2d\u0c2e\u0c2f\u0c30\u0c31\u0c32\u0c33 \u0c35\u0c36\u0c37" 1299 // C.....D.....EF.....0.....1.....2.....3.....4.....5.....6.....78.....9.....A.....B 1300 + "\u0c38\u0c39 \u0c3d\u0c3e\u0c3f\u0c40\u0c41\u0c42\u0c43\u0c44 \u0c46\u0c47\u0c48 " 1301 // C.....D.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D.....E..... 1302 + "\u0c4a\u0c4b\u0c4c\u0c4d\u0c55abcdefghijklmnopqrstuvwxyz\u0c56\u0c60\u0c61\u0c62" 1303 // F..... 1304 + "\u0c63", 1305 1306 /* A.3.13 Urdu National Language Locking Shift Table 1307 0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.E.....F.....*/ 1308 "\u0627\u0622\u0628\u067b\u0680\u067e\u06a6\u062a\u06c2\u067f\n\u0679\u067d\r\u067a\u067c" 1309 // 0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D..... 1310 + "\u062b\u062c\u0681\u0684\u0683\u0685\u0686\u0687\u062d\u062e\u062f\uffff\u068c\u0688" 1311 // E.....F.....012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....012345 1312 + "\u0689\u068a !\u068f\u068d\u0630\u0631\u0691\u0693)(\u0699\u0632,\u0696.\u0698012345" 1313 // 6789ABC.....D.....E.....F0.....1.....2.....3.....4.....5.....6.....7.....8..... 1314 + "6789:;\u069a\u0633\u0634?\u0635\u0636\u0637\u0638\u0639\u0641\u0642\u06a9\u06aa" 1315 // 9.....A.....B.....C.....D.....E.....F.....0.....1.....2.....3.....4.....5.....6..... 1316 + "\u06ab\u06af\u06b3\u06b1\u0644\u0645\u0646\u06ba\u06bb\u06bc\u0648\u06c4\u06d5\u06c1" 1317 // 7.....8.....9.....A.....B.....C.....D.....E.....F.....0.....123456789ABCDEF012345678 1318 + "\u06be\u0621\u06cc\u06d0\u06d2\u064d\u0650\u064f\u0657\u0654abcdefghijklmnopqrstuvwx" 1319 // 9AB.....C.....D.....E.....F..... 1320 + "yz\u0655\u0651\u0653\u0656\u0670" 1321 }; 1322 1323 /** 1324 * GSM default extension table plus national language single shift character tables. 1325 */ 1326 private static final String[] sLanguageShiftTables = new String[]{ 1327 /* 6.2.1.1 GSM 7 bit Default Alphabet Extension Table 1328 0123456789A.....BCDEF0123456789ABCDEF0123456789ABCDEF.0123456789ABCDEF0123456789ABCDEF */ 1329 " \u000c ^ {} \\ [~] | " 1330 // 0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF 1331 + " \u20ac ", 1332 1333 /* A.2.1 Turkish National Language Single Shift Table 1334 0123456789A.....BCDEF0123456789ABCDEF0123456789ABCDEF.0123456789ABCDEF01234567.....8 */ 1335 " \u000c ^ {} \\ [~] | \u011e " 1336 // 9.....ABCDEF0123.....456789ABCDEF0123.....45.....67.....89.....ABCDEF0123..... 1337 + "\u0130 \u015e \u00e7 \u20ac \u011f \u0131 \u015f" 1338 // 456789ABCDEF 1339 + " ", 1340 1341 /* A.2.2 Spanish National Language Single Shift Table 1342 0123456789.....A.....BCDEF0123456789ABCDEF0123456789ABCDEF.0123456789ABCDEF01.....23 */ 1343 " \u00e7\u000c ^ {} \\ [~] |\u00c1 " 1344 // 456789.....ABCDEF.....012345.....6789ABCDEF01.....2345.....6789.....ABCDEF.....012 1345 + " \u00cd \u00d3 \u00da \u00e1 \u20ac \u00ed \u00f3 " 1346 // 345.....6789ABCDEF 1347 + " \u00fa ", 1348 1349 /* A.2.3 Portuguese National Language Single Shift Table 1350 012345.....6789.....A.....B.....C.....DE.....F.....012.....3.....45.....6.....7.....8....*/ 1351 " \u00ea \u00e7\u000c\u00d4\u00f4 \u00c1\u00e1 \u03a6\u0393^\u03a9\u03a0\u03a8\u03a3" 1352 // 9.....ABCDEF.....0123456789ABCDEF.0123456789ABCDEF01.....23456789.....ABCDE 1353 + "\u0398 \u00ca {} \\ [~] |\u00c0 \u00cd " 1354 // F.....012345.....6789AB.....C.....DEF01.....2345.....6789.....ABCDEF.....01234 1355 + "\u00d3 \u00da \u00c3\u00d5 \u00c2 \u20ac \u00ed \u00f3 " 1356 // 5.....6789AB.....C.....DEF..... 1357 + "\u00fa \u00e3\u00f5 \u00e2", 1358 1359 /* A.2.4 Bengali National Language Single Shift Table 1360 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */ 1361 "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u09e6\u09e7 \u09e8\u09e9" 1362 // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C..... 1363 + "\u09ea\u09eb\u09ec\u09ed\u09ee\u09ef\u09df\u09e0\u09e1\u09e2{}\u09e3\u09f2\u09f3" 1364 // D.....E.....F.0.....1.....2.....3.....4.....56789ABCDEF0123456789ABCDEF 1365 + "\u09f4\u09f5\\\u09f6\u09f7\u09f8\u09f9\u09fa [~] |ABCDEFGHIJKLMNO" 1366 // 0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF 1367 + "PQRSTUVWXYZ \u20ac ", 1368 1369 /* A.2.5 Gujarati National Language Single Shift Table 1370 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */ 1371 "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0ae6\u0ae7" 1372 // E.....F.....0.....1.....2.....3.....4.....5.....6789ABCDEF.0123456789ABCDEF 1373 + "\u0ae8\u0ae9\u0aea\u0aeb\u0aec\u0aed\u0aee\u0aef {} \\ [~] " 1374 // 0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF 1375 + "|ABCDEFGHIJKLMNOPQRSTUVWXYZ \u20ac ", 1376 1377 /* A.2.6 Hindi National Language Single Shift Table 1378 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */ 1379 "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0966\u0967" 1380 // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C..... 1381 + "\u0968\u0969\u096a\u096b\u096c\u096d\u096e\u096f\u0951\u0952{}\u0953\u0954\u0958" 1382 // D.....E.....F.0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A..... 1383 + "\u0959\u095a\\\u095b\u095c\u095d\u095e\u095f\u0960\u0961\u0962\u0963\u0970\u0971" 1384 // BCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF 1385 + " [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ \u20ac ", 1386 1387 /* A.2.7 Kannada National Language Single Shift Table 1388 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */ 1389 "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0ce6\u0ce7" 1390 // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....BCDEF.01234567 1391 + "\u0ce8\u0ce9\u0cea\u0ceb\u0cec\u0ced\u0cee\u0cef\u0cde\u0cf1{}\u0cf2 \\ " 1392 // 89ABCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF 1393 + " [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ \u20ac ", 1394 1395 /* A.2.8 Malayalam National Language Single Shift Table 1396 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */ 1397 "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0d66\u0d67" 1398 // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C..... 1399 + "\u0d68\u0d69\u0d6a\u0d6b\u0d6c\u0d6d\u0d6e\u0d6f\u0d70\u0d71{}\u0d72\u0d73\u0d74" 1400 // D.....E.....F.0.....1.....2.....3.....4.....56789ABCDEF0123456789ABCDEF0123456789A 1401 + "\u0d75\u0d7a\\\u0d7b\u0d7c\u0d7d\u0d7e\u0d7f [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ" 1402 // BCDEF012345.....6789ABCDEF0123456789ABCDEF 1403 + " \u20ac ", 1404 1405 /* A.2.9 Oriya National Language Single Shift Table 1406 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */ 1407 "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0b66\u0b67" 1408 // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C.....DE 1409 + "\u0b68\u0b69\u0b6a\u0b6b\u0b6c\u0b6d\u0b6e\u0b6f\u0b5c\u0b5d{}\u0b5f\u0b70\u0b71 " 1410 // F.0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF0123456789A 1411 + "\\ [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ \u20ac " 1412 // BCDEF 1413 + " ", 1414 1415 /* A.2.10 Punjabi National Language Single Shift Table 1416 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */ 1417 "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0a66\u0a67" 1418 // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C..... 1419 + "\u0a68\u0a69\u0a6a\u0a6b\u0a6c\u0a6d\u0a6e\u0a6f\u0a59\u0a5a{}\u0a5b\u0a5c\u0a5e" 1420 // D.....EF.0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF01 1421 + "\u0a75 \\ [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ \u20ac " 1422 // 23456789ABCDEF 1423 + " ", 1424 1425 /* A.2.11 Tamil National Language Single Shift Table 1426 NOTE: TS 23.038 V9.1.1 shows code 0x24 as \u0bef, corrected to \u0bee (typo) 1427 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */ 1428 "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0be6\u0be7" 1429 // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C..... 1430 + "\u0be8\u0be9\u0bea\u0beb\u0bec\u0bed\u0bee\u0bef\u0bf3\u0bf4{}\u0bf5\u0bf6\u0bf7" 1431 // D.....E.....F.0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABC 1432 + "\u0bf8\u0bfa\\ [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ \u20ac " 1433 // DEF0123456789ABCDEF 1434 + " ", 1435 1436 /* A.2.12 Telugu National Language Single Shift Table 1437 NOTE: TS 23.038 V9.1.1 shows code 0x22-0x23 as \u06cc\u06cd, corrected to \u0c6c\u0c6d 1438 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789ABC.....D.....E.....F..... */ 1439 "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#* \u0c66\u0c67\u0c68\u0c69" 1440 // 0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C.....D.....E.....F. 1441 + "\u0c6a\u0c6b\u0c6c\u0c6d\u0c6e\u0c6f\u0c58\u0c59{}\u0c78\u0c79\u0c7a\u0c7b\u0c7c\\" 1442 // 0.....1.....2.....3456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABCD 1443 + "\u0c7d\u0c7e\u0c7f [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ \u20ac " 1444 // EF0123456789ABCDEF 1445 + " ", 1446 1447 /* A.2.13 Urdu National Language Single Shift Table 1448 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */ 1449 "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0600\u0601 \u06f0\u06f1" 1450 // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C..... 1451 + "\u06f2\u06f3\u06f4\u06f5\u06f6\u06f7\u06f8\u06f9\u060c\u060d{}\u060e\u060f\u0610" 1452 // D.....E.....F.0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A..... 1453 + "\u0611\u0612\\\u0613\u0614\u061b\u061f\u0640\u0652\u0658\u066b\u066c\u0672\u0673" 1454 // B.....CDEF.....0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF 1455 + "\u06cd[~]\u06d4|ABCDEFGHIJKLMNOPQRSTUVWXYZ \u20ac " 1456 }; 1457 1458 static { 1459 enableCountrySpecificEncodings(); 1460 int numTables = sLanguageTables.length; 1461 int numShiftTables = sLanguageShiftTables.length; 1462 if (numTables != numShiftTables) { 1463 Rlog.e(TAG, "Error: language tables array length " + numTables + 1464 " != shift tables array length " + numShiftTables); 1465 } 1466 1467 sCharsToGsmTables = new SparseIntArray[numTables]; 1468 for (int i = 0; i < numTables; i++) { 1469 String table = sLanguageTables[i]; 1470 1471 int tableLen = table.length(); 1472 if (tableLen != 0 && tableLen != 128) { 1473 Rlog.e(TAG, "Error: language tables index " + i + 1474 " length " + tableLen + " (expected 128 or 0)"); 1475 } 1476 1477 SparseIntArray charToGsmTable = new SparseIntArray(tableLen); 1478 sCharsToGsmTables[i] = charToGsmTable; 1479 for (int j = 0; j < tableLen; j++) { 1480 char c = table.charAt(j); 1481 charToGsmTable.put(c, j); 1482 } 1483 } 1484 1485 sCharsToShiftTables = new SparseIntArray[numTables]; 1486 for (int i = 0; i < numShiftTables; i++) { 1487 String shiftTable = sLanguageShiftTables[i]; 1488 1489 int shiftTableLen = shiftTable.length(); 1490 if (shiftTableLen != 0 && shiftTableLen != 128) { 1491 Rlog.e(TAG, "Error: language shift tables index " + i + 1492 " length " + shiftTableLen + " (expected 128 or 0)"); 1493 } 1494 1495 SparseIntArray charToShiftTable = new SparseIntArray(shiftTableLen); 1496 sCharsToShiftTables[i] = charToShiftTable; 1497 for (int j = 0; j < shiftTableLen; j++) { 1498 char c = shiftTable.charAt(j); 1499 if (c != ' ') { 1500 charToShiftTable.put(c, j); 1501 } 1502 } 1503 } 1504 } 1505 } 1506