1e5d0e473Sopenharmony_ci/* 2e5d0e473Sopenharmony_ci * Copyright (C) 2023 Huawei Device Co., Ltd. 3e5d0e473Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e5d0e473Sopenharmony_ci * you may not use this file except in compliance with the License. 5e5d0e473Sopenharmony_ci * You may obtain a copy of the License at 6e5d0e473Sopenharmony_ci * 7e5d0e473Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e5d0e473Sopenharmony_ci * 9e5d0e473Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e5d0e473Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e5d0e473Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e5d0e473Sopenharmony_ci * See the License for the specific language governing permissions and 13e5d0e473Sopenharmony_ci * limitations under the License. 14e5d0e473Sopenharmony_ci */ 15e5d0e473Sopenharmony_ci 16e5d0e473Sopenharmony_ci#include "text_coder.h" 17e5d0e473Sopenharmony_ci#include "glib.h" 18e5d0e473Sopenharmony_ci#include "mms_charset.h" 19e5d0e473Sopenharmony_ci#include "securec.h" 20e5d0e473Sopenharmony_ci#include "telephony_log_wrapper.h" 21e5d0e473Sopenharmony_ci 22e5d0e473Sopenharmony_cinamespace OHOS { 23e5d0e473Sopenharmony_cinamespace Telephony { 24e5d0e473Sopenharmony_ciusing msg_encode_type_t = uint8_t; 25e5d0e473Sopenharmony_ciusing namespace std; 26e5d0e473Sopenharmony_cistatic constexpr uint8_t GSM7_DEFLIST_LEN = 128; 27e5d0e473Sopenharmony_cistatic constexpr uint8_t UCS2_LEN_MIN = 2; 28e5d0e473Sopenharmony_cistatic constexpr uint32_t UCS2_LEN_MAX = INT_MAX / sizeof(WCHAR); 29e5d0e473Sopenharmony_ci 30e5d0e473Sopenharmony_ciconst WCHAR GSM7_BIT_TO_UC_S2[] = { 0x0040, 0x00A3, 0x0024, 0x00A5, 0x00E8, 0x00E9, 0x00F9, 0x00EC, 0x00F2, 0x00C7, 31e5d0e473Sopenharmony_ci 0x000A, 216, 0x00F8, 0x000D, 0x00C5, 0x00E5, 0x0394, 0x005F, 0x03A6, 0x0393, 0x039B, 0x03A9, 0x03A0, 0x03A8, 0x03A3, 32e5d0e473Sopenharmony_ci 0x0398, 0x039E, 0x001B, 0x00C6, 0x00E6, 0x00DF, 0x00C9, 0x0020, 0x0021, 0x0022, 0x0023, 0x00A4, 0x0025, 0x0026, 33e5d0e473Sopenharmony_ci 0x0027, 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 34e5d0e473Sopenharmony_ci 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F, 0x00A1, 0x0041, 0x0042, 35e5d0e473Sopenharmony_ci 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, 0x0050, 36e5d0e473Sopenharmony_ci 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x00C4, 0x00D6, 0x00D1, 0x00DC, 37e5d0e473Sopenharmony_ci 0x00A7, 0x00BF, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 38e5d0e473Sopenharmony_ci 0x006D, 0x006E, 0x006F, 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007A, 39e5d0e473Sopenharmony_ci 0x00E4, 0x00F6, 0x00F1, 0x00FC, 0x00E0 }; 40e5d0e473Sopenharmony_ci 41e5d0e473Sopenharmony_ciTextCoder::TextCoder() 42e5d0e473Sopenharmony_ci{ 43e5d0e473Sopenharmony_ci InitExtCharMap(); 44e5d0e473Sopenharmony_ci InitGsm7bitDefMap(); 45e5d0e473Sopenharmony_ci InitGsm7bitExtMap(); 46e5d0e473Sopenharmony_ci InitTurkishMap(); 47e5d0e473Sopenharmony_ci InitSpanishMap(); 48e5d0e473Sopenharmony_ci InitPortuMap(); 49e5d0e473Sopenharmony_ci InitReplaceCharMap(); 50e5d0e473Sopenharmony_ci} 51e5d0e473Sopenharmony_ci 52e5d0e473Sopenharmony_ciTextCoder::~TextCoder() 53e5d0e473Sopenharmony_ci{ 54e5d0e473Sopenharmony_ci extCharMap_.clear(); 55e5d0e473Sopenharmony_ci gsm7bitDefMap_.clear(); 56e5d0e473Sopenharmony_ci gsm7bitExtMap_.clear(); 57e5d0e473Sopenharmony_ci turkishMap_.clear(); 58e5d0e473Sopenharmony_ci spanishMap_.clear(); 59e5d0e473Sopenharmony_ci portuMap_.clear(); 60e5d0e473Sopenharmony_ci replaceCharMap_.clear(); 61e5d0e473Sopenharmony_ci} 62e5d0e473Sopenharmony_ci 63e5d0e473Sopenharmony_ciTextCoder &TextCoder::Instance() 64e5d0e473Sopenharmony_ci{ 65e5d0e473Sopenharmony_ci static TextCoder instance; 66e5d0e473Sopenharmony_ci return instance; 67e5d0e473Sopenharmony_ci} 68e5d0e473Sopenharmony_ci 69e5d0e473Sopenharmony_civoid TextCoder::InitExtCharMap() 70e5d0e473Sopenharmony_ci{ 71e5d0e473Sopenharmony_ci extCharMap_.clear(); 72e5d0e473Sopenharmony_ci extCharMap_ = { { 0x000C, MSG_GSM7EXT_CHAR }, { 0x005B, MSG_GSM7EXT_CHAR }, { 0x005C, MSG_GSM7EXT_CHAR }, 73e5d0e473Sopenharmony_ci { 0x005D, MSG_GSM7EXT_CHAR }, { 0x005E, MSG_GSM7EXT_CHAR }, { 0x007B, MSG_GSM7EXT_CHAR }, 74e5d0e473Sopenharmony_ci { 0x007C, MSG_GSM7EXT_CHAR }, { 0x007D, MSG_GSM7EXT_CHAR }, { 0x007E, MSG_GSM7EXT_CHAR }, 75e5d0e473Sopenharmony_ci { 0x20AC, MSG_GSM7EXT_CHAR }, { 0x00E7, MSG_TURKISH_CHAR }, { 0x011E, MSG_TURKISH_CHAR }, 76e5d0e473Sopenharmony_ci { 0x011F, MSG_TURKISH_CHAR }, { 0x01E6, MSG_TURKISH_CHAR }, { 0x01E7, MSG_TURKISH_CHAR }, 77e5d0e473Sopenharmony_ci { 0x0130, MSG_TURKISH_CHAR }, { 0x0131, MSG_TURKISH_CHAR }, { 0x015E, MSG_TURKISH_CHAR }, 78e5d0e473Sopenharmony_ci { 0x015F, MSG_TURKISH_CHAR }, { 0x00C1, MSG_SPANISH_CHAR }, { 0x00E1, MSG_SPANISH_CHAR }, 79e5d0e473Sopenharmony_ci { 0x00CD, MSG_SPANISH_CHAR }, { 0x00ED, MSG_SPANISH_CHAR }, { 0x00D3, MSG_SPANISH_CHAR }, 80e5d0e473Sopenharmony_ci { 0x00F3, MSG_SPANISH_CHAR }, { 0x00DA, MSG_SPANISH_CHAR }, { 0x00FA, MSG_SPANISH_CHAR }, 81e5d0e473Sopenharmony_ci { 0x00D4, MSG_PORTUGUESE_CHAR }, { 0x00F4, MSG_PORTUGUESE_CHAR }, { 0x00CA, MSG_PORTUGUESE_CHAR }, 82e5d0e473Sopenharmony_ci { 0x00EA, MSG_PORTUGUESE_CHAR }, { 0x00C0, MSG_PORTUGUESE_CHAR }, { 0x00E7, MSG_PORTUGUESE_CHAR }, 83e5d0e473Sopenharmony_ci { 0x00C3, MSG_PORTUGUESE_CHAR }, { 0x00E3, MSG_PORTUGUESE_CHAR }, { 0x00D5, MSG_PORTUGUESE_CHAR }, 84e5d0e473Sopenharmony_ci { 0x00F5, MSG_PORTUGUESE_CHAR }, { 0x00C2, MSG_PORTUGUESE_CHAR }, { 0x00E2, MSG_PORTUGUESE_CHAR } }; 85e5d0e473Sopenharmony_ci} 86e5d0e473Sopenharmony_ci 87e5d0e473Sopenharmony_civoid TextCoder::InitGsm7bitDefMap() 88e5d0e473Sopenharmony_ci{ 89e5d0e473Sopenharmony_ci gsm7bitDefMap_.clear(); 90e5d0e473Sopenharmony_ci for (uint8_t i = 0; i < GSM7_DEFLIST_LEN; i++) { 91e5d0e473Sopenharmony_ci gsm7bitDefMap_[GSM7_BIT_TO_UC_S2[i]] = i; 92e5d0e473Sopenharmony_ci } 93e5d0e473Sopenharmony_ci} 94e5d0e473Sopenharmony_ci 95e5d0e473Sopenharmony_civoid TextCoder::InitGsm7bitExtMap() 96e5d0e473Sopenharmony_ci{ 97e5d0e473Sopenharmony_ci gsm7bitExtMap_.clear(); 98e5d0e473Sopenharmony_ci gsm7bitExtMap_ = { { 0x005B, 0x3C }, { 0x005D, 0x3E }, { 0x007B, 0x28 }, { 0x007D, 0x29 }, { 0x000C, 0x0A }, 99e5d0e473Sopenharmony_ci { 0x005C, 0x2F }, { 0x005E, 0x14 }, { 0x007C, 0x40 }, { 0x007E, 0x3D }, { 0x20AC, 0x65 } }; 100e5d0e473Sopenharmony_ci} 101e5d0e473Sopenharmony_ci 102e5d0e473Sopenharmony_civoid TextCoder::InitTurkishMap() 103e5d0e473Sopenharmony_ci{ 104e5d0e473Sopenharmony_ci // Turkish 105e5d0e473Sopenharmony_ci turkishMap_.clear(); 106e5d0e473Sopenharmony_ci turkishMap_ = { { 0x005B, 0x3C }, { 0x005D, 0x3E }, { 0x007B, 0x28 }, { 0x007D, 0x29 }, { 0x000C, 0x0A }, 107e5d0e473Sopenharmony_ci { 0x005C, 0x2F }, { 0x005E, 0x14 }, { 0x007C, 0x40 }, { 0x007E, 0x3D }, { 0x20AC, 0x65 }, { 0x00E7, 0x63 }, 108e5d0e473Sopenharmony_ci { 0x011E, 0x47 }, { 0x011F, 0x67 }, { 0x01E6, 0x47 }, { 0x01E7, 0x67 }, { 0x0130, 0x49 }, { 0x0131, 0x69 }, 109e5d0e473Sopenharmony_ci { 0x015E, 0x53 }, { 0x015F, 0x73 } }; 110e5d0e473Sopenharmony_ci} 111e5d0e473Sopenharmony_ci 112e5d0e473Sopenharmony_civoid TextCoder::InitSpanishMap() 113e5d0e473Sopenharmony_ci{ 114e5d0e473Sopenharmony_ci // Spanish 115e5d0e473Sopenharmony_ci spanishMap_.clear(); 116e5d0e473Sopenharmony_ci spanishMap_ = { { 0x005B, 0x3C }, { 0x005D, 0x3E }, { 0x007B, 0x28 }, { 0x007D, 0x29 }, { 0x000C, 0x0A }, 117e5d0e473Sopenharmony_ci { 0x005C, 0x2F }, { 0x005E, 0x14 }, { 0x007C, 0x40 }, { 0x007E, 0x3D }, { 0x20AC, 0x65 }, { 0x00C1, 0x41 }, 118e5d0e473Sopenharmony_ci { 0x00E1, 0x61 }, { 0x00CD, 0x49 }, { 0x00ED, 0x69 }, { 0x00D3, 0x4F }, { 0x00F3, 0x6F }, { 0x00DA, 0x55 }, 119e5d0e473Sopenharmony_ci { 0x00FA, 0x75 } }; 120e5d0e473Sopenharmony_ci} 121e5d0e473Sopenharmony_ci 122e5d0e473Sopenharmony_civoid TextCoder::InitPortuMap() 123e5d0e473Sopenharmony_ci{ 124e5d0e473Sopenharmony_ci // Portuguese 125e5d0e473Sopenharmony_ci portuMap_.clear(); 126e5d0e473Sopenharmony_ci portuMap_ = { { 0x005B, 0x3C }, { 0x005D, 0x3E }, { 0x007B, 0x28 }, { 0x007D, 0x29 }, { 0x000C, 0x0A }, 127e5d0e473Sopenharmony_ci { 0x005C, 0x2F }, { 0x005E, 0x14 }, { 0x007C, 0x40 }, { 0x007E, 0x3D }, { 0x20AC, 0x65 }, { 0x00D4, 0x0B }, 128e5d0e473Sopenharmony_ci { 0x00F4, 0x0C }, { 0x00C1, 0x0E }, { 0x00E1, 0x0F }, { 0x00CA, 0x1F }, { 0x00EA, 0x05 }, { 0x00C0, 0x41 }, 129e5d0e473Sopenharmony_ci { 0x00E7, 0x09 }, { 0x00CD, 0x49 }, { 0x00ED, 0x69 }, { 0x00D3, 0x4F }, { 0x00F3, 0x6F }, { 0x00DA, 0x55 }, 130e5d0e473Sopenharmony_ci { 0x00FA, 0x75 }, { 0x00C3, 0x61 }, { 0x00E3, 0x7B }, { 0x00D5, 0x5C }, { 0x00F5, 0x7C }, { 0x00C2, 0x61 }, 131e5d0e473Sopenharmony_ci { 0x00E2, 0x7F }, { 0x03A6, 0x12 }, { 0x0393, 0x13 }, { 0x03A9, 0x15 }, { 0x03A0, 0x16 }, { 0x03A8, 0x17 }, 132e5d0e473Sopenharmony_ci { 0x03A3, 0x18 }, { 0x0398, 0x19 } }; 133e5d0e473Sopenharmony_ci} 134e5d0e473Sopenharmony_ci 135e5d0e473Sopenharmony_civoid TextCoder::InitReplaceCharMap() 136e5d0e473Sopenharmony_ci{ 137e5d0e473Sopenharmony_ci // character replacement table 138e5d0e473Sopenharmony_ci replaceCharMap_.clear(); 139e5d0e473Sopenharmony_ci replaceCharMap_ = { { 0x00E0, 0x61 }, { 0x00E1, 0x61 }, { 0x00E2, 0x61 }, { 0x00E3, 0x61 }, { 0x00E4, 0x61 }, 140e5d0e473Sopenharmony_ci { 0x00E5, 0x61 }, { 0x00E6, 0x61 }, { 0x0101, 0x61 }, { 0x0103, 0x61 }, { 0x0105, 0x61 }, { 0x01CE, 0x61 }, 141e5d0e473Sopenharmony_ci { 0x00C0, 0x41 }, { 0x00C1, 0x41 }, { 0x00C2, 0x41 }, { 0x00C3, 0x41 }, { 0x00C4, 0x41 }, { 0x00C5, 0x41 }, 142e5d0e473Sopenharmony_ci { 0x00C6, 0x41 }, { 0x0100, 0x41 }, { 0x0102, 0x41 }, { 0x0104, 0x41 }, { 0x01CD, 0x41 }, { 0x00E7, 0x63 }, 143e5d0e473Sopenharmony_ci { 0x0107, 0x63 }, { 0x0109, 0x63 }, { 0x010B, 0x63 }, { 0x010D, 0x63 }, { 0x00C7, 0x43 }, { 0x0106, 0x43 }, 144e5d0e473Sopenharmony_ci { 0x0108, 0x43 }, { 0x010A, 0x43 }, { 0x010C, 0x43 }, { 0x010F, 0x64 }, { 0x0111, 0x64 }, { 0x010E, 0x44 }, 145e5d0e473Sopenharmony_ci { 0x0110, 0x44 }, { 0x00E8, 0x65 }, { 0x00E9, 0x65 }, { 0x00EA, 0x65 }, { 0x00EB, 0x65 }, { 0x0113, 0x65 }, 146e5d0e473Sopenharmony_ci { 0x0115, 0x65 }, { 0x0117, 0x65 }, { 0x0119, 0x65 }, { 0x011B, 0x65 }, { 0x0259, 0x65 }, { 0x00C8, 0x45 }, 147e5d0e473Sopenharmony_ci { 0x00C9, 0x45 }, { 0x00CA, 0x45 }, { 0x00CB, 0x45 }, { 0x0112, 0x45 }, { 0x0114, 0x45 }, { 0x0116, 0x45 }, 148e5d0e473Sopenharmony_ci { 0x0118, 0x45 }, { 0x011A, 0x45 }, { 0x018F, 0x45 }, { 0x011D, 0x67 }, { 0x011F, 0x67 }, { 0x0121, 0x67 }, 149e5d0e473Sopenharmony_ci { 0x0123, 0x67 }, { 0x01E7, 0x67 }, { 0x01F5, 0x67 }, { 0x1E21, 0x67 }, { 0x011C, 0x47 }, { 0x011E, 0x47 }, 150e5d0e473Sopenharmony_ci { 0x0120, 0x47 }, { 0x0122, 0x47 }, { 0x01E6, 0x47 }, { 0x01F4, 0x47 }, { 0x1E20, 0x47 }, { 0x00EC, 0x69 }, 151e5d0e473Sopenharmony_ci { 0x00ED, 0x69 }, { 0x00EE, 0x69 }, { 0x00EF, 0x69 }, { 0x0129, 0x69 }, { 0x012B, 0x69 }, { 0x012D, 0x69 }, 152e5d0e473Sopenharmony_ci { 0x012F, 0x69 }, { 0x01D0, 0x69 }, { 0x0131, 0x69 }, { 0x00CC, 0x49 }, { 0x00CD, 0x49 }, { 0x00CE, 0x49 }, 153e5d0e473Sopenharmony_ci { 0x00CF, 0x49 }, { 0x0128, 0x49 }, { 0x012A, 0x49 }, { 0x012C, 0x49 }, { 0x012E, 0x49 }, { 0x0130, 0x49 }, 154e5d0e473Sopenharmony_ci { 0x0137, 0x6B }, { 0x0136, 0x4B }, { 0x013A, 0x6C }, { 0x013C, 0x6C }, { 0x013E, 0x6C }, { 0x0140, 0x6C }, 155e5d0e473Sopenharmony_ci { 0x0142, 0x6C }, { 0x0139, 0x4C }, { 0x013B, 0x4C }, { 0x013D, 0x4C }, { 0x013F, 0x4C }, { 0x0141, 0x4C }, 156e5d0e473Sopenharmony_ci { 0x00F1, 0x6E }, { 0x0144, 0x6E }, { 0x0146, 0x6E }, { 0x0148, 0x6E }, { 0x00D1, 0x4E }, { 0x0143, 0x4E }, 157e5d0e473Sopenharmony_ci { 0x0145, 0x4E }, { 0x0147, 0x4E }, { 0x00F2, 0x6F }, { 0x00F3, 0x6F }, { 0x00F4, 0x6F }, { 0x00F5, 0x6F }, 158e5d0e473Sopenharmony_ci { 0x00F6, 0x6F }, { 0x00F8, 0x6F }, { 0x014D, 0x6F }, { 0x014F, 0x6F }, { 0x01D2, 0x6F }, { 0x01EB, 0x6F }, 159e5d0e473Sopenharmony_ci { 0x0151, 0x6F }, { 0x0153, 0x6F }, { 0x00D2, 0x4F }, { 0x00D3, 0x4F }, { 0x00D4, 0x4F }, { 0x00D5, 0x4F }, 160e5d0e473Sopenharmony_ci { 0x00D6, 0x4F }, { 216, 0x4F }, { 0x014C, 0x4F }, { 0x014E, 0x4F }, { 0x01D1, 0x4F }, { 0x01EA, 0x4F }, 161e5d0e473Sopenharmony_ci { 0x0150, 0x4F }, { 0x0152, 0x4F }, { 0x0155, 0x72 }, { 0x0157, 0x72 }, { 0x0159, 0x72 }, { 0x0154, 0x52 }, 162e5d0e473Sopenharmony_ci { 0x0156, 0x52 }, { 0x0158, 0x52 }, { 0x015B, 0x73 }, { 0x015D, 0x73 }, { 0x015F, 0x73 }, { 0x0161, 0x73 }, 163e5d0e473Sopenharmony_ci { 0x015A, 0x53 }, { 0x015C, 0x53 }, { 0x015E, 0x53 }, { 0x0160, 0x53 }, { 0x00FE, 0x74 }, { 0x0163, 0x74 }, 164e5d0e473Sopenharmony_ci { 0x0165, 0x74 }, { 0x0167, 0x74 }, { 0x021B, 0x74 }, { 0x00DE, 0x54 }, { 0x0162, 0x54 }, { 0x0164, 0x54 }, 165e5d0e473Sopenharmony_ci { 0x0166, 0x54 }, { 0x00F9, 0x75 }, { 0x00FA, 0x75 }, { 0x00FB, 0x75 }, { 0x00FC, 0x75 }, { 0x0169, 0x75 }, 166e5d0e473Sopenharmony_ci { 0x016B, 0x75 }, { 0x016D, 0x75 }, { 0x016F, 0x75 }, { 0x0171, 0x75 }, { 0x0173, 0x75 }, { 0x01D4, 0x75 }, 167e5d0e473Sopenharmony_ci { 0x00D9, 0x55 }, { 0x00DA, 0x55 }, { 0x00DB, 0x55 }, { 0x00DC, 0x55 }, { 0x0168, 0x55 }, { 0x016A, 0x55 }, 168e5d0e473Sopenharmony_ci { 0x016C, 0x55 }, { 0x016E, 0x55 }, { 0x0170, 0x55 }, { 0x0172, 0x55 }, { 0x01D3, 0x55 }, { 0x00FD, 0x79 }, 169e5d0e473Sopenharmony_ci { 0x00FF, 0x79 }, { 0x0177, 0x79 }, { 0x0233, 0x79 }, { 0x1EF3, 0x79 }, { 0x1EF9, 0x79 }, { 0x00DD, 0x59 }, 170e5d0e473Sopenharmony_ci { 0x0176, 0x59 }, { 0x0178, 0x59 }, { 0x0232, 0x59 }, { 0x1EF2, 0x59 }, { 0x1EF8, 0x59 }, { 0x017A, 0x7A }, 171e5d0e473Sopenharmony_ci { 0x017C, 0x7A }, { 0x017E, 0x7A }, { 0x0179, 0x5A }, { 0x017B, 0x5A }, { 0x017D, 0x5A } }; 172e5d0e473Sopenharmony_ci} 173e5d0e473Sopenharmony_ci 174e5d0e473Sopenharmony_civoid TextCoder::Base64Encode(const std::string &src, std::string &dest) 175e5d0e473Sopenharmony_ci{ 176e5d0e473Sopenharmony_ci gchar *encode_data = g_base64_encode((guchar *)src.data(), src.length()); 177e5d0e473Sopenharmony_ci if (encode_data == nullptr) { 178e5d0e473Sopenharmony_ci return; 179e5d0e473Sopenharmony_ci } 180e5d0e473Sopenharmony_ci gsize out_len = 0; 181e5d0e473Sopenharmony_ci out_len = strlen(encode_data); 182e5d0e473Sopenharmony_ci std::string temp(encode_data, out_len); 183e5d0e473Sopenharmony_ci dest = temp; 184e5d0e473Sopenharmony_ci 185e5d0e473Sopenharmony_ci if (encode_data != nullptr) { 186e5d0e473Sopenharmony_ci g_free(encode_data); 187e5d0e473Sopenharmony_ci } 188e5d0e473Sopenharmony_ci} 189e5d0e473Sopenharmony_ci 190e5d0e473Sopenharmony_civoid TextCoder::Base64Decode(const std::string &src, std::string &dest) 191e5d0e473Sopenharmony_ci{ 192e5d0e473Sopenharmony_ci gsize out_len = 0; 193e5d0e473Sopenharmony_ci gchar *decodeData = reinterpret_cast<gchar *>(g_base64_decode(src.data(), &out_len)); 194e5d0e473Sopenharmony_ci if (decodeData == nullptr) { 195e5d0e473Sopenharmony_ci return; 196e5d0e473Sopenharmony_ci } 197e5d0e473Sopenharmony_ci std::string temp(decodeData, out_len); 198e5d0e473Sopenharmony_ci dest = temp; 199e5d0e473Sopenharmony_ci 200e5d0e473Sopenharmony_ci if (decodeData != nullptr) { 201e5d0e473Sopenharmony_ci g_free(decodeData); 202e5d0e473Sopenharmony_ci } 203e5d0e473Sopenharmony_ci} 204e5d0e473Sopenharmony_ci 205e5d0e473Sopenharmony_cibool TextCoder::GetEncodeString( 206e5d0e473Sopenharmony_ci std::string &encodeString, uint32_t charset, uint32_t valLength, const std::string &strEncodeString) 207e5d0e473Sopenharmony_ci{ 208e5d0e473Sopenharmony_ci bool ret = false; 209e5d0e473Sopenharmony_ci gchar *pDest = nullptr; 210e5d0e473Sopenharmony_ci gsize bytes_read = 0; 211e5d0e473Sopenharmony_ci gsize bytes_written = 0; 212e5d0e473Sopenharmony_ci GError *error = nullptr; 213e5d0e473Sopenharmony_ci std::string strToCodeset("UTF-8"); 214e5d0e473Sopenharmony_ci std::string strFromCodeset; 215e5d0e473Sopenharmony_ci auto charSetInstance = DelayedSingleton<MmsCharSet>::GetInstance(); 216e5d0e473Sopenharmony_ci if (charSetInstance == nullptr || (!charSetInstance->GetCharSetStrFromInt(strFromCodeset, charset))) { 217e5d0e473Sopenharmony_ci strFromCodeset = "UTF-8"; 218e5d0e473Sopenharmony_ci } 219e5d0e473Sopenharmony_ci pDest = g_convert(strEncodeString.c_str(), valLength, strToCodeset.c_str(), strFromCodeset.c_str(), &bytes_read, 220e5d0e473Sopenharmony_ci &bytes_written, &error); 221e5d0e473Sopenharmony_ci if (!error) { 222e5d0e473Sopenharmony_ci encodeString = std::string(pDest, bytes_written); 223e5d0e473Sopenharmony_ci ret = true; 224e5d0e473Sopenharmony_ci } else { 225e5d0e473Sopenharmony_ci TELEPHONY_LOGE("EncodeString charset convert fail."); 226e5d0e473Sopenharmony_ci ret = false; 227e5d0e473Sopenharmony_ci } 228e5d0e473Sopenharmony_ci if (pDest != nullptr) { 229e5d0e473Sopenharmony_ci g_free(pDest); 230e5d0e473Sopenharmony_ci } 231e5d0e473Sopenharmony_ci return ret; 232e5d0e473Sopenharmony_ci} 233e5d0e473Sopenharmony_ci 234e5d0e473Sopenharmony_ci/** 235e5d0e473Sopenharmony_ci * @brief Utf8ToGsm7bit 236e5d0e473Sopenharmony_ci * max # of Ucs2 chars, NOT bytes. when all utf8 chars are only one byte, 237e5d0e473Sopenharmony_ci * Ucs2Length is maxUcs2 Length. otherwise (ex: 2 bytes of UTF8 is one char) 238e5d0e473Sopenharmony_ci * Ucs2Length must be less than utf8Length 239e5d0e473Sopenharmony_ci */ 240e5d0e473Sopenharmony_ciint TextCoder::Utf8ToGsm7bit(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength, MSG_LANGUAGE_ID_T &langId) 241e5d0e473Sopenharmony_ci{ 242e5d0e473Sopenharmony_ci if (srcLength == -1 && src) { 243e5d0e473Sopenharmony_ci // null terminated string 244e5d0e473Sopenharmony_ci srcLength = strlen(reinterpret_cast<const gchar *>(src)); 245e5d0e473Sopenharmony_ci } 246e5d0e473Sopenharmony_ci if (srcLength <= 0 || src == nullptr || dest == nullptr || maxLength <= 0) { 247e5d0e473Sopenharmony_ci TELEPHONY_LOGE("text is null"); 248e5d0e473Sopenharmony_ci return 0; 249e5d0e473Sopenharmony_ci } 250e5d0e473Sopenharmony_ci 251e5d0e473Sopenharmony_ci int maxUcs2Length = srcLength; 252e5d0e473Sopenharmony_ci if (static_cast<uint32_t>(maxUcs2Length) >= UCS2_LEN_MAX) { 253e5d0e473Sopenharmony_ci TELEPHONY_LOGE("src over size"); 254e5d0e473Sopenharmony_ci return 0; 255e5d0e473Sopenharmony_ci } 256e5d0e473Sopenharmony_ci std::unique_ptr<WCHAR[]> ucs2Text = std::make_unique<WCHAR[]>(maxUcs2Length); 257e5d0e473Sopenharmony_ci if (ucs2Text == nullptr) { 258e5d0e473Sopenharmony_ci TELEPHONY_LOGE("make_unique error"); 259e5d0e473Sopenharmony_ci return 0; 260e5d0e473Sopenharmony_ci } 261e5d0e473Sopenharmony_ci WCHAR *pUcs2Text = ucs2Text.get(); 262e5d0e473Sopenharmony_ci if (memset_s(pUcs2Text, maxUcs2Length * sizeof(WCHAR), 0x00, maxUcs2Length * sizeof(WCHAR)) != EOK) { 263e5d0e473Sopenharmony_ci TELEPHONY_LOGE("memset_s error"); 264e5d0e473Sopenharmony_ci return 0; 265e5d0e473Sopenharmony_ci } 266e5d0e473Sopenharmony_ci 267e5d0e473Sopenharmony_ci TELEPHONY_LOGI("srcLength = %{public}d", srcLength); 268e5d0e473Sopenharmony_ci int ucs2Length = Utf8ToUcs2(reinterpret_cast<uint8_t *>(pUcs2Text), maxUcs2Length * sizeof(WCHAR), src, srcLength); 269e5d0e473Sopenharmony_ci return Ucs2ToGsm7bit(dest, maxLength, reinterpret_cast<uint8_t *>(pUcs2Text), ucs2Length, langId); 270e5d0e473Sopenharmony_ci} 271e5d0e473Sopenharmony_ci 272e5d0e473Sopenharmony_ciint TextCoder::Utf8ToUcs2(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength) 273e5d0e473Sopenharmony_ci{ 274e5d0e473Sopenharmony_ci if (srcLength == -1 && src) { 275e5d0e473Sopenharmony_ci // null terminated string 276e5d0e473Sopenharmony_ci srcLength = strlen(reinterpret_cast<gchar *>(const_cast<uint8_t *>(src))); 277e5d0e473Sopenharmony_ci } 278e5d0e473Sopenharmony_ci if (srcLength <= 0 || src == nullptr || dest == nullptr || maxLength <= 0) { 279e5d0e473Sopenharmony_ci TELEPHONY_LOGE("text is null"); 280e5d0e473Sopenharmony_ci return 0; 281e5d0e473Sopenharmony_ci } 282e5d0e473Sopenharmony_ci 283e5d0e473Sopenharmony_ci gsize textLen = static_cast<gsize>(srcLength); 284e5d0e473Sopenharmony_ci auto unicodeTemp = reinterpret_cast<uint8_t *>(dest); 285e5d0e473Sopenharmony_ci gsize remainedLength = static_cast<gsize>(maxLength); 286e5d0e473Sopenharmony_ci uint32_t err = 0; 287e5d0e473Sopenharmony_ci GIConv cd = g_iconv_open("UTF16BE", "UTF8"); 288e5d0e473Sopenharmony_ci if (cd != nullptr) { 289e5d0e473Sopenharmony_ci err = g_iconv(cd, reinterpret_cast<gchar **>(const_cast<uint8_t **>(&src)), reinterpret_cast<gsize *>(&textLen), 290e5d0e473Sopenharmony_ci reinterpret_cast<gchar **>(&unicodeTemp), reinterpret_cast<gsize *>(&remainedLength)); 291e5d0e473Sopenharmony_ci } 292e5d0e473Sopenharmony_ci g_iconv_close(cd); 293e5d0e473Sopenharmony_ci return (err != 0) ? -1 : (maxLength - static_cast<int>(remainedLength)); 294e5d0e473Sopenharmony_ci} 295e5d0e473Sopenharmony_ci 296e5d0e473Sopenharmony_ciint TextCoder::GsmUtf8ToAuto(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength, 297e5d0e473Sopenharmony_ci DataCodingScheme &scheme, SmsCodingNationalType codingNationalType, MSG_LANGUAGE_ID_T &langId) 298e5d0e473Sopenharmony_ci{ 299e5d0e473Sopenharmony_ci int maxUcs2Length = srcLength; 300e5d0e473Sopenharmony_ci if (maxUcs2Length <= 0 || static_cast<uint32_t>(maxUcs2Length) >= UCS2_LEN_MAX) { 301e5d0e473Sopenharmony_ci TELEPHONY_LOGE("src over size"); 302e5d0e473Sopenharmony_ci return 0; 303e5d0e473Sopenharmony_ci } 304e5d0e473Sopenharmony_ci std::unique_ptr<WCHAR[]> ucs2Text = std::make_unique<WCHAR[]>(maxUcs2Length); 305e5d0e473Sopenharmony_ci if (ucs2Text == nullptr) { 306e5d0e473Sopenharmony_ci TELEPHONY_LOGE("GsmUtf8ToAuto make_unique error"); 307e5d0e473Sopenharmony_ci return 0; 308e5d0e473Sopenharmony_ci } 309e5d0e473Sopenharmony_ci WCHAR *pUcs2Text = ucs2Text.get(); 310e5d0e473Sopenharmony_ci if (memset_s(pUcs2Text, maxUcs2Length * sizeof(WCHAR), 0x00, maxUcs2Length * sizeof(WCHAR)) != EOK) { 311e5d0e473Sopenharmony_ci TELEPHONY_LOGE("GsmUtf8ToAuto memset_s error"); 312e5d0e473Sopenharmony_ci return 0; 313e5d0e473Sopenharmony_ci } 314e5d0e473Sopenharmony_ci int ucs2Length = Utf8ToUcs2(reinterpret_cast<uint8_t *>(pUcs2Text), maxUcs2Length * sizeof(WCHAR), src, srcLength); 315e5d0e473Sopenharmony_ci int tempTextLen = 0; 316e5d0e473Sopenharmony_ci if (ucs2Length < 0) { 317e5d0e473Sopenharmony_ci scheme = DATA_CODING_8BIT; 318e5d0e473Sopenharmony_ci tempTextLen = (srcLength > maxLength) ? maxLength : srcLength; 319e5d0e473Sopenharmony_ci if (memcpy_s(dest, tempTextLen, src, tempTextLen) != EOK) { 320e5d0e473Sopenharmony_ci TELEPHONY_LOGE("GsmUtf8ToAuto memcpy_s error"); 321e5d0e473Sopenharmony_ci } 322e5d0e473Sopenharmony_ci return tempTextLen; 323e5d0e473Sopenharmony_ci } 324e5d0e473Sopenharmony_ci bool unknown = false; 325e5d0e473Sopenharmony_ci int length = Ucs2ToGsm7bitAuto(dest, maxLength, reinterpret_cast<uint8_t *>(pUcs2Text), ucs2Length, 326e5d0e473Sopenharmony_ci unknown, codingNationalType); 327e5d0e473Sopenharmony_ci if (unknown) { 328e5d0e473Sopenharmony_ci scheme = DATA_CODING_UCS2; 329e5d0e473Sopenharmony_ci if (ucs2Length <= 0) { 330e5d0e473Sopenharmony_ci return length; 331e5d0e473Sopenharmony_ci } 332e5d0e473Sopenharmony_ci tempTextLen = (ucs2Length > maxLength) ? maxLength : ucs2Length; 333e5d0e473Sopenharmony_ci if (memcpy_s(dest, tempTextLen, pUcs2Text, tempTextLen) != EOK) { 334e5d0e473Sopenharmony_ci TELEPHONY_LOGE("memcpy_s error"); 335e5d0e473Sopenharmony_ci } 336e5d0e473Sopenharmony_ci return tempTextLen; 337e5d0e473Sopenharmony_ci } 338e5d0e473Sopenharmony_ci langId = static_cast<MSG_LANGUAGE_ID_T>(codingNationalType); 339e5d0e473Sopenharmony_ci scheme = DATA_CODING_7BIT; 340e5d0e473Sopenharmony_ci return length; 341e5d0e473Sopenharmony_ci} 342e5d0e473Sopenharmony_ci 343e5d0e473Sopenharmony_ciint TextCoder::CdmaUtf8ToAuto(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength, DataCodingScheme &scheme) 344e5d0e473Sopenharmony_ci{ 345e5d0e473Sopenharmony_ci int maxUcs2Length = srcLength; 346e5d0e473Sopenharmony_ci if (maxUcs2Length <= 0 || static_cast<uint32_t>(maxUcs2Length) >= UCS2_LEN_MAX) { 347e5d0e473Sopenharmony_ci TELEPHONY_LOGE("CdmaUtf8ToAuto src over size"); 348e5d0e473Sopenharmony_ci return 0; 349e5d0e473Sopenharmony_ci } 350e5d0e473Sopenharmony_ci std::unique_ptr<WCHAR[]> ucs2Text = std::make_unique<WCHAR[]>(maxUcs2Length); 351e5d0e473Sopenharmony_ci if (ucs2Text == nullptr) { 352e5d0e473Sopenharmony_ci TELEPHONY_LOGE("CdmaUtf8ToAuto make_unique error"); 353e5d0e473Sopenharmony_ci return 0; 354e5d0e473Sopenharmony_ci } 355e5d0e473Sopenharmony_ci WCHAR *pUcs2Text = ucs2Text.get(); 356e5d0e473Sopenharmony_ci if (memset_s(pUcs2Text, maxUcs2Length * sizeof(WCHAR), 0x00, maxUcs2Length * sizeof(WCHAR)) != EOK) { 357e5d0e473Sopenharmony_ci TELEPHONY_LOGE("CdmaUtf8ToAuto memset_s error"); 358e5d0e473Sopenharmony_ci return 0; 359e5d0e473Sopenharmony_ci } 360e5d0e473Sopenharmony_ci int ucs2Length = Utf8ToUcs2(reinterpret_cast<uint8_t *>(pUcs2Text), maxUcs2Length * sizeof(WCHAR), src, srcLength); 361e5d0e473Sopenharmony_ci int tempTextLen = 0; 362e5d0e473Sopenharmony_ci if (ucs2Length < 0) { 363e5d0e473Sopenharmony_ci scheme = DATA_CODING_8BIT; 364e5d0e473Sopenharmony_ci tempTextLen = (srcLength > maxLength) ? maxLength : srcLength; 365e5d0e473Sopenharmony_ci if (memcpy_s(dest, tempTextLen, src, tempTextLen) != EOK) { 366e5d0e473Sopenharmony_ci TELEPHONY_LOGE("memcpy_s error"); 367e5d0e473Sopenharmony_ci } 368e5d0e473Sopenharmony_ci return tempTextLen; 369e5d0e473Sopenharmony_ci } 370e5d0e473Sopenharmony_ci bool unknown = false; 371e5d0e473Sopenharmony_ci int gsm7bitLength = Ucs2ToAscii(dest, maxLength, reinterpret_cast<uint8_t *>(pUcs2Text), ucs2Length, unknown); 372e5d0e473Sopenharmony_ci if (unknown) { 373e5d0e473Sopenharmony_ci scheme = DATA_CODING_UCS2; 374e5d0e473Sopenharmony_ci if (ucs2Length <= 0) { 375e5d0e473Sopenharmony_ci return gsm7bitLength; 376e5d0e473Sopenharmony_ci } 377e5d0e473Sopenharmony_ci tempTextLen = (ucs2Length > maxLength) ? maxLength : ucs2Length; 378e5d0e473Sopenharmony_ci if (memcpy_s(dest, tempTextLen, pUcs2Text, tempTextLen) != EOK) { 379e5d0e473Sopenharmony_ci TELEPHONY_LOGE("memcpy_s error"); 380e5d0e473Sopenharmony_ci } 381e5d0e473Sopenharmony_ci return tempTextLen; 382e5d0e473Sopenharmony_ci } 383e5d0e473Sopenharmony_ci scheme = DATA_CODING_ASCII7BIT; 384e5d0e473Sopenharmony_ci return gsm7bitLength; 385e5d0e473Sopenharmony_ci} 386e5d0e473Sopenharmony_ci 387e5d0e473Sopenharmony_ci/** 388e5d0e473Sopenharmony_ci * @brief Gsm7bitToUtf8 389e5d0e473Sopenharmony_ci * max # of Ucs2 chars, NOT bytes. when all gsm7 chars are only one byte(-there is no extension) 390e5d0e473Sopenharmony_ci * Ucs2Length is maxUcs2 Length. otherwise(ex: gsm7 char starts with 0x1b) 391e5d0e473Sopenharmony_ci * Ucs2Length must be less than gsm7 length 392e5d0e473Sopenharmony_ci */ 393e5d0e473Sopenharmony_ciint TextCoder::Gsm7bitToUtf8( 394e5d0e473Sopenharmony_ci uint8_t *dest, int maxLength, const uint8_t *src, int srcLength, const MsgLangInfo &langInfo) 395e5d0e473Sopenharmony_ci{ 396e5d0e473Sopenharmony_ci int maxUcs2Length = srcLength; 397e5d0e473Sopenharmony_ci if (maxUcs2Length <= 0 || static_cast<uint32_t>(maxUcs2Length) >= UCS2_LEN_MAX) { 398e5d0e473Sopenharmony_ci TELEPHONY_LOGE("Gsm7bitToUtf8 src over size"); 399e5d0e473Sopenharmony_ci return 0; 400e5d0e473Sopenharmony_ci } 401e5d0e473Sopenharmony_ci std::unique_ptr<WCHAR[]> ucs2Text = std::make_unique<WCHAR[]>(maxUcs2Length); 402e5d0e473Sopenharmony_ci if (ucs2Text == nullptr) { 403e5d0e473Sopenharmony_ci TELEPHONY_LOGE("Gsm7bitToUtf8 make_unique error"); 404e5d0e473Sopenharmony_ci return 0; 405e5d0e473Sopenharmony_ci } 406e5d0e473Sopenharmony_ci WCHAR *pUcs2Text = ucs2Text.get(); 407e5d0e473Sopenharmony_ci if (memset_s(pUcs2Text, maxUcs2Length * sizeof(WCHAR), 0x00, maxUcs2Length * sizeof(WCHAR)) != EOK) { 408e5d0e473Sopenharmony_ci TELEPHONY_LOGE("Gsm7bitToUtf8 memset_s error"); 409e5d0e473Sopenharmony_ci return 0; 410e5d0e473Sopenharmony_ci } 411e5d0e473Sopenharmony_ci TELEPHONY_LOGI("max dest Length = %{public}d, srcLength = %{public}d", maxLength, srcLength); 412e5d0e473Sopenharmony_ci int ucs2Length = 413e5d0e473Sopenharmony_ci Gsm7bitToUcs2(reinterpret_cast<uint8_t *>(pUcs2Text), maxUcs2Length * sizeof(WCHAR), src, srcLength, langInfo); 414e5d0e473Sopenharmony_ci if (ucs2Length > maxLength) { 415e5d0e473Sopenharmony_ci // Usually, maxLength is a large number, like 1530, 4200. But when you decode the address, maxLength is only 21. 416e5d0e473Sopenharmony_ci // (according to section 9/1/2/5 in 3gpp 23040). When the code is converted to UCS2, the length is doubled, 417e5d0e473Sopenharmony_ci // that is, the length is greater than maxUcs2Length * sizeof(WCHAR) should be considered a failure. 418e5d0e473Sopenharmony_ci // If the value of maxLength is large(1530 4200), and the first condition is met, this condition is also met, 419e5d0e473Sopenharmony_ci // and there is no impact. 420e5d0e473Sopenharmony_ci if (ucs2Length > static_cast<int>(maxUcs2Length * sizeof(WCHAR))) { 421e5d0e473Sopenharmony_ci TELEPHONY_LOGI("src over size, ucs2Length = %{public}d, maxLength = %{public}d", ucs2Length, 422e5d0e473Sopenharmony_ci static_cast<int>(maxUcs2Length * sizeof(WCHAR))); 423e5d0e473Sopenharmony_ci return 0; 424e5d0e473Sopenharmony_ci } 425e5d0e473Sopenharmony_ci } 426e5d0e473Sopenharmony_ci return Ucs2ToUtf8(dest, maxLength, reinterpret_cast<uint8_t *>(pUcs2Text), ucs2Length); 427e5d0e473Sopenharmony_ci} 428e5d0e473Sopenharmony_ci 429e5d0e473Sopenharmony_ciint TextCoder::Ucs2ToUtf8(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength) 430e5d0e473Sopenharmony_ci{ 431e5d0e473Sopenharmony_ci if (srcLength == -1 && src) { 432e5d0e473Sopenharmony_ci TELEPHONY_LOGE("stcLength == -1 && src branch"); 433e5d0e473Sopenharmony_ci // null terminated string 434e5d0e473Sopenharmony_ci srcLength = strlen(reinterpret_cast<gchar *>(const_cast<uint8_t *>(src))); 435e5d0e473Sopenharmony_ci } 436e5d0e473Sopenharmony_ci if (srcLength <= 0 || src == nullptr || dest == nullptr || maxLength <= 0) { 437e5d0e473Sopenharmony_ci TELEPHONY_LOGE("text is null"); 438e5d0e473Sopenharmony_ci return 0; 439e5d0e473Sopenharmony_ci } 440e5d0e473Sopenharmony_ci 441e5d0e473Sopenharmony_ci gsize textLen = static_cast<gsize>(srcLength); 442e5d0e473Sopenharmony_ci uint32_t err = 0; 443e5d0e473Sopenharmony_ci gsize remainedLength = static_cast<gsize>(maxLength); 444e5d0e473Sopenharmony_ci GIConv cd = g_iconv_open("UTF8", "UTF16BE"); 445e5d0e473Sopenharmony_ci if (cd != nullptr) { 446e5d0e473Sopenharmony_ci err = g_iconv(cd, reinterpret_cast<gchar **>(const_cast<uint8_t **>(&src)), reinterpret_cast<gsize *>(&textLen), 447e5d0e473Sopenharmony_ci reinterpret_cast<gchar **>(&dest), reinterpret_cast<gsize *>(&remainedLength)); 448e5d0e473Sopenharmony_ci } 449e5d0e473Sopenharmony_ci g_iconv_close(cd); 450e5d0e473Sopenharmony_ci if (err != 0) { 451e5d0e473Sopenharmony_ci TELEPHONY_LOGE("g_iconv result is %{public}u", err); 452e5d0e473Sopenharmony_ci } 453e5d0e473Sopenharmony_ci int length = maxLength - static_cast<int>(remainedLength); 454e5d0e473Sopenharmony_ci if (length < 0 || length >= maxLength) { 455e5d0e473Sopenharmony_ci return 0; 456e5d0e473Sopenharmony_ci } 457e5d0e473Sopenharmony_ci return length; 458e5d0e473Sopenharmony_ci} 459e5d0e473Sopenharmony_ci 460e5d0e473Sopenharmony_ciint TextCoder::EuckrToUtf8(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength) 461e5d0e473Sopenharmony_ci{ 462e5d0e473Sopenharmony_ci if (srcLength == -1 && src) { 463e5d0e473Sopenharmony_ci // null terminated string 464e5d0e473Sopenharmony_ci srcLength = strlen(reinterpret_cast<gchar *>(const_cast<uint8_t *>(src))); 465e5d0e473Sopenharmony_ci } 466e5d0e473Sopenharmony_ci if (srcLength <= 0 || src == nullptr || dest == nullptr || maxLength <= 0) { 467e5d0e473Sopenharmony_ci TELEPHONY_LOGE("text is null"); 468e5d0e473Sopenharmony_ci return 0; 469e5d0e473Sopenharmony_ci } 470e5d0e473Sopenharmony_ci 471e5d0e473Sopenharmony_ci gsize remainedLength = static_cast<gsize>(maxLength); 472e5d0e473Sopenharmony_ci gsize textLen = static_cast<gsize>(srcLength); 473e5d0e473Sopenharmony_ci uint32_t err = 0; 474e5d0e473Sopenharmony_ci GIConv cd = g_iconv_open("UTF8", "EUCKR"); 475e5d0e473Sopenharmony_ci if (cd != nullptr) { 476e5d0e473Sopenharmony_ci err = g_iconv(cd, reinterpret_cast<gchar **>(const_cast<uint8_t **>(&src)), reinterpret_cast<gsize *>(&textLen), 477e5d0e473Sopenharmony_ci reinterpret_cast<gchar **>(&dest), reinterpret_cast<gsize *>(&remainedLength)); 478e5d0e473Sopenharmony_ci } 479e5d0e473Sopenharmony_ci g_iconv_close(cd); 480e5d0e473Sopenharmony_ci if (err != 0) { 481e5d0e473Sopenharmony_ci TELEPHONY_LOGE("g_iconv result is %{public}u", err); 482e5d0e473Sopenharmony_ci } 483e5d0e473Sopenharmony_ci int utf8Length = maxLength - static_cast<int>(remainedLength); 484e5d0e473Sopenharmony_ci if (utf8Length < 0 || utf8Length >= maxLength) { 485e5d0e473Sopenharmony_ci return 0; 486e5d0e473Sopenharmony_ci } 487e5d0e473Sopenharmony_ci dest[utf8Length] = 0x00; 488e5d0e473Sopenharmony_ci return utf8Length; 489e5d0e473Sopenharmony_ci} 490e5d0e473Sopenharmony_ci 491e5d0e473Sopenharmony_ciint TextCoder::ShiftjisToUtf8(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength) const 492e5d0e473Sopenharmony_ci{ 493e5d0e473Sopenharmony_ci if (srcLength == -1 && src) { 494e5d0e473Sopenharmony_ci // null terminated string 495e5d0e473Sopenharmony_ci srcLength = strlen(reinterpret_cast<gchar *>(const_cast<uint8_t *>(src))); 496e5d0e473Sopenharmony_ci } 497e5d0e473Sopenharmony_ci if (srcLength <= 0 || src == nullptr || dest == nullptr || maxLength <= 0) { 498e5d0e473Sopenharmony_ci TELEPHONY_LOGE("text is null"); 499e5d0e473Sopenharmony_ci return 0; 500e5d0e473Sopenharmony_ci } 501e5d0e473Sopenharmony_ci 502e5d0e473Sopenharmony_ci gsize textLen = static_cast<gsize>(srcLength); 503e5d0e473Sopenharmony_ci gsize remainedLength = static_cast<gsize>(maxLength); 504e5d0e473Sopenharmony_ci uint32_t err = 0; 505e5d0e473Sopenharmony_ci GIConv cd = g_iconv_open("UTF8", "SHIFT-JIS"); 506e5d0e473Sopenharmony_ci if (cd != nullptr) { 507e5d0e473Sopenharmony_ci err = g_iconv(cd, reinterpret_cast<gchar **>(const_cast<uint8_t **>(&src)), reinterpret_cast<gsize *>(&textLen), 508e5d0e473Sopenharmony_ci reinterpret_cast<gchar **>(&dest), reinterpret_cast<gsize *>(&remainedLength)); 509e5d0e473Sopenharmony_ci } 510e5d0e473Sopenharmony_ci g_iconv_close(cd); 511e5d0e473Sopenharmony_ci TELEPHONY_LOGI("g_iconv result is %{public}u", err); 512e5d0e473Sopenharmony_ci int utf8Length = maxLength - static_cast<int>(remainedLength); 513e5d0e473Sopenharmony_ci if (utf8Length < 0 || utf8Length >= maxLength) { 514e5d0e473Sopenharmony_ci return 0; 515e5d0e473Sopenharmony_ci } 516e5d0e473Sopenharmony_ci dest[utf8Length] = 0x00; 517e5d0e473Sopenharmony_ci return utf8Length; 518e5d0e473Sopenharmony_ci} 519e5d0e473Sopenharmony_ci 520e5d0e473Sopenharmony_ciint TextCoder::Ucs2ToGsm7bit(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength, MSG_LANGUAGE_ID_T &langId) 521e5d0e473Sopenharmony_ci{ 522e5d0e473Sopenharmony_ci if (srcLength <= 0 || src == nullptr || dest == nullptr || maxLength <= 0) { 523e5d0e473Sopenharmony_ci TELEPHONY_LOGE("text is null"); 524e5d0e473Sopenharmony_ci return -1; 525e5d0e473Sopenharmony_ci } 526e5d0e473Sopenharmony_ci int outTextLen = 0; 527e5d0e473Sopenharmony_ci int remainLen = 0; 528e5d0e473Sopenharmony_ci uint16_t inText = 0; 529e5d0e473Sopenharmony_ci uint8_t currType = GetLangType(src, srcLength); 530e5d0e473Sopenharmony_ci std::map<uint16_t, uint8_t>::iterator itChar; 531e5d0e473Sopenharmony_ci for (int index = 0; index < (srcLength - 1); index += UCS2_LEN_MIN) { 532e5d0e473Sopenharmony_ci inText = src[index]; 533e5d0e473Sopenharmony_ci inText = ((inText << 0x08) & 0xFF00) | src[index + 1]; 534e5d0e473Sopenharmony_ci itChar = gsm7bitDefMap_.find(inText); // check gsm7bit default char 535e5d0e473Sopenharmony_ci if (itChar != gsm7bitDefMap_.end()) { 536e5d0e473Sopenharmony_ci dest[outTextLen++] = static_cast<uint8_t>(itChar->second); 537e5d0e473Sopenharmony_ci } else { 538e5d0e473Sopenharmony_ci switch (currType) { 539e5d0e473Sopenharmony_ci case MSG_GSM7EXT_CHAR: 540e5d0e473Sopenharmony_ci remainLen = maxLength - outTextLen; 541e5d0e473Sopenharmony_ci outTextLen += FindGsm7bitExt(&dest[outTextLen], remainLen, inText); 542e5d0e473Sopenharmony_ci break; 543e5d0e473Sopenharmony_ci case MSG_TURKISH_CHAR: 544e5d0e473Sopenharmony_ci langId = MSG_ID_TURKISH_LANG; 545e5d0e473Sopenharmony_ci remainLen = maxLength - outTextLen; 546e5d0e473Sopenharmony_ci outTextLen += FindTurkish(&dest[outTextLen], remainLen, inText); 547e5d0e473Sopenharmony_ci break; 548e5d0e473Sopenharmony_ci case MSG_SPANISH_CHAR: 549e5d0e473Sopenharmony_ci langId = MSG_ID_SPANISH_LANG; 550e5d0e473Sopenharmony_ci remainLen = maxLength - outTextLen; 551e5d0e473Sopenharmony_ci outTextLen += FindSpanish(&dest[outTextLen], remainLen, inText); 552e5d0e473Sopenharmony_ci break; 553e5d0e473Sopenharmony_ci case MSG_PORTUGUESE_CHAR: 554e5d0e473Sopenharmony_ci langId = MSG_ID_PORTUGUESE_LANG; 555e5d0e473Sopenharmony_ci remainLen = maxLength - outTextLen; 556e5d0e473Sopenharmony_ci outTextLen += FindPortu(&dest[outTextLen], remainLen, inText); 557e5d0e473Sopenharmony_ci break; 558e5d0e473Sopenharmony_ci default: 559e5d0e473Sopenharmony_ci dest[outTextLen] = FindReplaceChar(inText); 560e5d0e473Sopenharmony_ci break; 561e5d0e473Sopenharmony_ci } 562e5d0e473Sopenharmony_ci outTextLen++; 563e5d0e473Sopenharmony_ci } 564e5d0e473Sopenharmony_ci // prevent buffer overflow 565e5d0e473Sopenharmony_ci if (maxLength <= outTextLen) { 566e5d0e473Sopenharmony_ci TELEPHONY_LOGE("buffer overflow"); 567e5d0e473Sopenharmony_ci break; 568e5d0e473Sopenharmony_ci } 569e5d0e473Sopenharmony_ci } 570e5d0e473Sopenharmony_ci return outTextLen; 571e5d0e473Sopenharmony_ci} 572e5d0e473Sopenharmony_ci 573e5d0e473Sopenharmony_cistd::map<uint16_t, uint8_t> TextCoder::Get7BitCodingExtMap(SmsCodingNationalType codingNationalType) const 574e5d0e473Sopenharmony_ci{ 575e5d0e473Sopenharmony_ci std::map<uint16_t, uint8_t> extMap = gsm7bitExtMap_; 576e5d0e473Sopenharmony_ci switch (codingNationalType) { 577e5d0e473Sopenharmony_ci case SMS_CODING_NATIONAL_TYPE_DEFAULT: 578e5d0e473Sopenharmony_ci extMap = gsm7bitExtMap_; 579e5d0e473Sopenharmony_ci break; 580e5d0e473Sopenharmony_ci case SMS_CODING_NATIONAL_TYPE_TURKISH: 581e5d0e473Sopenharmony_ci extMap = turkishMap_; 582e5d0e473Sopenharmony_ci break; 583e5d0e473Sopenharmony_ci case SMS_CODING_NATIONAL_TYPE_SPANISH: 584e5d0e473Sopenharmony_ci extMap = spanishMap_; 585e5d0e473Sopenharmony_ci break; 586e5d0e473Sopenharmony_ci case SMS_CODING_NATIONAL_TYPE_PORTUGUESE: 587e5d0e473Sopenharmony_ci extMap = portuMap_; 588e5d0e473Sopenharmony_ci break; 589e5d0e473Sopenharmony_ci default: 590e5d0e473Sopenharmony_ci extMap = gsm7bitExtMap_; 591e5d0e473Sopenharmony_ci break; 592e5d0e473Sopenharmony_ci } 593e5d0e473Sopenharmony_ci return extMap; 594e5d0e473Sopenharmony_ci} 595e5d0e473Sopenharmony_ci 596e5d0e473Sopenharmony_ciint TextCoder::Ucs2ToGsm7bitAuto(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength, 597e5d0e473Sopenharmony_ci bool &unknown, SmsCodingNationalType codingNationalType) 598e5d0e473Sopenharmony_ci{ 599e5d0e473Sopenharmony_ci if (srcLength <= 0 || src == nullptr || dest == nullptr || maxLength <= 0) { 600e5d0e473Sopenharmony_ci TELEPHONY_LOGE("text is null"); 601e5d0e473Sopenharmony_ci return -1; 602e5d0e473Sopenharmony_ci } 603e5d0e473Sopenharmony_ci 604e5d0e473Sopenharmony_ci std::map<uint16_t, uint8_t> extMap = Get7BitCodingExtMap(codingNationalType); 605e5d0e473Sopenharmony_ci int outTextLen = 0; 606e5d0e473Sopenharmony_ci std::map<uint16_t, uint8_t>::iterator itChar; 607e5d0e473Sopenharmony_ci std::map<uint16_t, uint8_t>::iterator itExt; 608e5d0e473Sopenharmony_ci uint16_t inText; 609e5d0e473Sopenharmony_ci for (int i = 0; i < srcLength - 1; i += UCS2_LEN_MIN) { 610e5d0e473Sopenharmony_ci inText = src[i]; 611e5d0e473Sopenharmony_ci inText = ((inText << 0x08) & 0xFF00) | src[i + 1]; 612e5d0e473Sopenharmony_ci itChar = gsm7bitDefMap_.find(inText); // check gsm7bit default char 613e5d0e473Sopenharmony_ci if (itChar != gsm7bitDefMap_.end()) { 614e5d0e473Sopenharmony_ci dest[outTextLen++] = static_cast<uint8_t>(itChar->second); 615e5d0e473Sopenharmony_ci } else { 616e5d0e473Sopenharmony_ci itExt = extMap.find(inText); 617e5d0e473Sopenharmony_ci if (itExt == extMap.end()) { 618e5d0e473Sopenharmony_ci TELEPHONY_LOGI("Abnormal character is included. inText : [%{public}04x]", inText); 619e5d0e473Sopenharmony_ci unknown = true; 620e5d0e473Sopenharmony_ci return 0; 621e5d0e473Sopenharmony_ci } 622e5d0e473Sopenharmony_ci if (maxLength <= outTextLen + 1) { 623e5d0e473Sopenharmony_ci TELEPHONY_LOGE("buffer overflow."); 624e5d0e473Sopenharmony_ci break; 625e5d0e473Sopenharmony_ci } 626e5d0e473Sopenharmony_ci dest[outTextLen++] = 0x1B; 627e5d0e473Sopenharmony_ci dest[outTextLen++] = static_cast<uint8_t>(itExt->second); 628e5d0e473Sopenharmony_ci } 629e5d0e473Sopenharmony_ci // prevent buffer overflow 630e5d0e473Sopenharmony_ci if (maxLength <= outTextLen) { 631e5d0e473Sopenharmony_ci TELEPHONY_LOGE("buffer overflow"); 632e5d0e473Sopenharmony_ci break; 633e5d0e473Sopenharmony_ci } 634e5d0e473Sopenharmony_ci } 635e5d0e473Sopenharmony_ci return outTextLen; 636e5d0e473Sopenharmony_ci} 637e5d0e473Sopenharmony_ci 638e5d0e473Sopenharmony_ciint TextCoder::Ucs2ToAscii(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength, bool &unknown) 639e5d0e473Sopenharmony_ci{ 640e5d0e473Sopenharmony_ci if (srcLength <= 0 || src == nullptr || dest == nullptr || maxLength <= 0) { 641e5d0e473Sopenharmony_ci TELEPHONY_LOGE("text is null"); 642e5d0e473Sopenharmony_ci return -1; 643e5d0e473Sopenharmony_ci } 644e5d0e473Sopenharmony_ci 645e5d0e473Sopenharmony_ci int outTextLen = 0; 646e5d0e473Sopenharmony_ci std::map<uint16_t, uint8_t>::iterator itChar; 647e5d0e473Sopenharmony_ci std::map<uint16_t, uint8_t>::iterator itExt; 648e5d0e473Sopenharmony_ci uint16_t inText; 649e5d0e473Sopenharmony_ci for (int index = 0; index < srcLength - 1; index += UCS2_LEN_MIN) { 650e5d0e473Sopenharmony_ci inText = src[index]; 651e5d0e473Sopenharmony_ci inText = ((inText << 0x08) & 0xFF00) | src[index + 1]; 652e5d0e473Sopenharmony_ci // check default char 653e5d0e473Sopenharmony_ci if (inText > 0x007f) { 654e5d0e473Sopenharmony_ci TELEPHONY_LOGI("abnormal character is included [%{public}04x]", inText); 655e5d0e473Sopenharmony_ci unknown = true; 656e5d0e473Sopenharmony_ci return 0; 657e5d0e473Sopenharmony_ci } 658e5d0e473Sopenharmony_ci dest[outTextLen++] = static_cast<uint8_t>(inText); 659e5d0e473Sopenharmony_ci // prevent buffer overflow 660e5d0e473Sopenharmony_ci if (maxLength <= outTextLen) { 661e5d0e473Sopenharmony_ci TELEPHONY_LOGE("buffer overflow"); 662e5d0e473Sopenharmony_ci break; 663e5d0e473Sopenharmony_ci } 664e5d0e473Sopenharmony_ci } 665e5d0e473Sopenharmony_ci return outTextLen; 666e5d0e473Sopenharmony_ci} 667e5d0e473Sopenharmony_ci 668e5d0e473Sopenharmony_ciuint8_t TextCoder::GetLangType(const uint8_t *src, int srcLength) 669e5d0e473Sopenharmony_ci{ 670e5d0e473Sopenharmony_ci if (srcLength <= 0 || src == nullptr) { 671e5d0e473Sopenharmony_ci TELEPHONY_LOGE("text is null"); 672e5d0e473Sopenharmony_ci return MSG_DEFAULT_CHAR; 673e5d0e473Sopenharmony_ci } 674e5d0e473Sopenharmony_ci 675e5d0e473Sopenharmony_ci std::map<uint16_t, uint8_t>::iterator itExt; 676e5d0e473Sopenharmony_ci uint8_t currType = MSG_DEFAULT_CHAR; 677e5d0e473Sopenharmony_ci uint8_t newType = MSG_DEFAULT_CHAR; 678e5d0e473Sopenharmony_ci uint16_t inText; 679e5d0e473Sopenharmony_ci for (int index = 0; index < (srcLength - 1); index += UCS2_LEN_MIN) { 680e5d0e473Sopenharmony_ci inText = src[index]; 681e5d0e473Sopenharmony_ci inText = ((inText << 0x08) & 0xFF00) | src[index + 1]; 682e5d0e473Sopenharmony_ci itExt = extCharMap_.find(inText); 683e5d0e473Sopenharmony_ci if (itExt == extCharMap_.end()) { 684e5d0e473Sopenharmony_ci continue; 685e5d0e473Sopenharmony_ci } 686e5d0e473Sopenharmony_ci newType = static_cast<uint8_t>(itExt->second); 687e5d0e473Sopenharmony_ci if (newType >= currType) { 688e5d0e473Sopenharmony_ci bool isTurkisk = (inText == 0x00e7 && currType <= MSG_TURKISH_CHAR); 689e5d0e473Sopenharmony_ci currType = isTurkisk ? MSG_TURKISH_CHAR : newType; 690e5d0e473Sopenharmony_ci } 691e5d0e473Sopenharmony_ci } 692e5d0e473Sopenharmony_ci TELEPHONY_LOGI("charType : [%{public}hhu]", currType); 693e5d0e473Sopenharmony_ci return currType; 694e5d0e473Sopenharmony_ci} 695e5d0e473Sopenharmony_ci 696e5d0e473Sopenharmony_ciint TextCoder::FindGsm7bitExt(uint8_t *dest, int maxLength, const uint16_t inText) 697e5d0e473Sopenharmony_ci{ 698e5d0e473Sopenharmony_ci int outTextLen = 0; 699e5d0e473Sopenharmony_ci if (dest == nullptr || maxLength <= 0) { 700e5d0e473Sopenharmony_ci TELEPHONY_LOGE("Invalid parameter."); 701e5d0e473Sopenharmony_ci return outTextLen; 702e5d0e473Sopenharmony_ci } 703e5d0e473Sopenharmony_ci 704e5d0e473Sopenharmony_ci auto itExt = gsm7bitExtMap_.find(inText); 705e5d0e473Sopenharmony_ci if (itExt == gsm7bitExtMap_.end()) { 706e5d0e473Sopenharmony_ci dest[outTextLen++] = FindReplaceChar(inText); 707e5d0e473Sopenharmony_ci return outTextLen; 708e5d0e473Sopenharmony_ci } 709e5d0e473Sopenharmony_ci // prevent buffer overflow 710e5d0e473Sopenharmony_ci if (maxLength <= outTextLen + 1) { 711e5d0e473Sopenharmony_ci TELEPHONY_LOGE("FindGsm7bitExt buffer overflow"); 712e5d0e473Sopenharmony_ci return outTextLen; 713e5d0e473Sopenharmony_ci } 714e5d0e473Sopenharmony_ci dest[outTextLen++] = 0x1B; 715e5d0e473Sopenharmony_ci dest[outTextLen++] = static_cast<uint8_t>(itExt->second); 716e5d0e473Sopenharmony_ci return outTextLen; 717e5d0e473Sopenharmony_ci} 718e5d0e473Sopenharmony_ci 719e5d0e473Sopenharmony_ciint TextCoder::FindTurkish(uint8_t *dest, int maxLength, const uint16_t inText) 720e5d0e473Sopenharmony_ci{ 721e5d0e473Sopenharmony_ci int outTextLen = 0; 722e5d0e473Sopenharmony_ci if (dest == nullptr || maxLength <= 0) { 723e5d0e473Sopenharmony_ci TELEPHONY_LOGE("Invalid parameter."); 724e5d0e473Sopenharmony_ci return outTextLen; 725e5d0e473Sopenharmony_ci } 726e5d0e473Sopenharmony_ci 727e5d0e473Sopenharmony_ci auto itExt = turkishMap_.find(inText); 728e5d0e473Sopenharmony_ci if (itExt == turkishMap_.end()) { 729e5d0e473Sopenharmony_ci dest[outTextLen++] = FindReplaceChar(inText); 730e5d0e473Sopenharmony_ci return outTextLen; 731e5d0e473Sopenharmony_ci } 732e5d0e473Sopenharmony_ci // prevent buffer overflow 733e5d0e473Sopenharmony_ci if (maxLength <= outTextLen + 1) { 734e5d0e473Sopenharmony_ci TELEPHONY_LOGE("FindTurkish buffer overflow"); 735e5d0e473Sopenharmony_ci return outTextLen; 736e5d0e473Sopenharmony_ci } 737e5d0e473Sopenharmony_ci dest[outTextLen++] = 0x1B; 738e5d0e473Sopenharmony_ci dest[outTextLen++] = static_cast<uint8_t>(itExt->second); 739e5d0e473Sopenharmony_ci return outTextLen; 740e5d0e473Sopenharmony_ci} 741e5d0e473Sopenharmony_ci 742e5d0e473Sopenharmony_ciint TextCoder::FindSpanish(uint8_t *dest, int maxLength, const uint16_t inText) 743e5d0e473Sopenharmony_ci{ 744e5d0e473Sopenharmony_ci int outTextLen = 0; 745e5d0e473Sopenharmony_ci if (dest == nullptr || maxLength <= 0) { 746e5d0e473Sopenharmony_ci TELEPHONY_LOGE("Invalid parameter."); 747e5d0e473Sopenharmony_ci return outTextLen; 748e5d0e473Sopenharmony_ci } 749e5d0e473Sopenharmony_ci 750e5d0e473Sopenharmony_ci auto itExt = spanishMap_.find(inText); 751e5d0e473Sopenharmony_ci if (itExt == spanishMap_.end()) { 752e5d0e473Sopenharmony_ci dest[outTextLen++] = FindReplaceChar(inText); 753e5d0e473Sopenharmony_ci return outTextLen; 754e5d0e473Sopenharmony_ci } 755e5d0e473Sopenharmony_ci // prevent buffer overflow 756e5d0e473Sopenharmony_ci if (maxLength <= outTextLen + 1) { 757e5d0e473Sopenharmony_ci TELEPHONY_LOGE("FindSpanish buffer overflow"); 758e5d0e473Sopenharmony_ci return outTextLen; 759e5d0e473Sopenharmony_ci } 760e5d0e473Sopenharmony_ci dest[outTextLen++] = 0x1B; 761e5d0e473Sopenharmony_ci dest[outTextLen++] = static_cast<uint8_t>(itExt->second); 762e5d0e473Sopenharmony_ci return outTextLen; 763e5d0e473Sopenharmony_ci} 764e5d0e473Sopenharmony_ci 765e5d0e473Sopenharmony_ciint TextCoder::FindPortu(uint8_t *dest, int maxLength, const uint16_t inText) 766e5d0e473Sopenharmony_ci{ 767e5d0e473Sopenharmony_ci int outTextLen = 0; 768e5d0e473Sopenharmony_ci if (dest == nullptr || maxLength <= 0) { 769e5d0e473Sopenharmony_ci TELEPHONY_LOGE("Invalid parameter."); 770e5d0e473Sopenharmony_ci return outTextLen; 771e5d0e473Sopenharmony_ci } 772e5d0e473Sopenharmony_ci 773e5d0e473Sopenharmony_ci auto itExt = portuMap_.find(inText); 774e5d0e473Sopenharmony_ci if (itExt == portuMap_.end()) { 775e5d0e473Sopenharmony_ci dest[outTextLen++] = FindReplaceChar(inText); 776e5d0e473Sopenharmony_ci return outTextLen; 777e5d0e473Sopenharmony_ci } 778e5d0e473Sopenharmony_ci // prevent buffer overflow 779e5d0e473Sopenharmony_ci if (maxLength <= outTextLen + 1) { 780e5d0e473Sopenharmony_ci TELEPHONY_LOGE("FindPortu buffer overflow"); 781e5d0e473Sopenharmony_ci return outTextLen; 782e5d0e473Sopenharmony_ci } 783e5d0e473Sopenharmony_ci dest[outTextLen++] = 0x1B; 784e5d0e473Sopenharmony_ci dest[outTextLen++] = static_cast<uint8_t>(itExt->second); 785e5d0e473Sopenharmony_ci return outTextLen; 786e5d0e473Sopenharmony_ci} 787e5d0e473Sopenharmony_ci 788e5d0e473Sopenharmony_ciuint8_t TextCoder::FindReplaceChar(const uint16_t inText) 789e5d0e473Sopenharmony_ci{ 790e5d0e473Sopenharmony_ci uint8_t result = 0; 791e5d0e473Sopenharmony_ci auto itReplace = replaceCharMap_.find(inText); 792e5d0e473Sopenharmony_ci if (itReplace != replaceCharMap_.end()) { 793e5d0e473Sopenharmony_ci result = static_cast<uint8_t>(itReplace->second); 794e5d0e473Sopenharmony_ci } else { 795e5d0e473Sopenharmony_ci result = 0x3F; 796e5d0e473Sopenharmony_ci } 797e5d0e473Sopenharmony_ci return result; 798e5d0e473Sopenharmony_ci} 799e5d0e473Sopenharmony_ci 800e5d0e473Sopenharmony_ciint TextCoder::Gsm7bitToUcs2( 801e5d0e473Sopenharmony_ci uint8_t *dest, int maxLength, const uint8_t *src, int srcLength, const MsgLangInfo &langInfo) 802e5d0e473Sopenharmony_ci{ 803e5d0e473Sopenharmony_ci if (srcLength == 0 || src == nullptr || dest == nullptr || maxLength <= 0) { 804e5d0e473Sopenharmony_ci TELEPHONY_LOGE("text is null"); 805e5d0e473Sopenharmony_ci return -1; 806e5d0e473Sopenharmony_ci } 807e5d0e473Sopenharmony_ci 808e5d0e473Sopenharmony_ci int outTextLen = 0; 809e5d0e473Sopenharmony_ci uint8_t lowerByte = 0; 810e5d0e473Sopenharmony_ci uint8_t upperByte = 0; 811e5d0e473Sopenharmony_ci uint16_t result = 0; 812e5d0e473Sopenharmony_ci for (int i = 0; i < srcLength && maxLength > UCS2_LEN_MIN; i++) { 813e5d0e473Sopenharmony_ci if (src[i] >= 0x80) { 814e5d0e473Sopenharmony_ci TELEPHONY_LOGE("a_pTextString[%{public}d]=%{public}x, The alpha isn't the gsm 7bit code", i, src[i]); 815e5d0e473Sopenharmony_ci return -1; 816e5d0e473Sopenharmony_ci } 817e5d0e473Sopenharmony_ci if (langInfo.bLockingShift) { 818e5d0e473Sopenharmony_ci TELEPHONY_LOGI("National Language Locking Shift [%{public}d]", langInfo.lockingLang); 819e5d0e473Sopenharmony_ci if (langInfo.lockingLang == MSG_ID_TURKISH_LANG) { 820e5d0e473Sopenharmony_ci i += EscapeTurkishLockingToUcs2(&src[i], (srcLength - i), langInfo, result); 821e5d0e473Sopenharmony_ci lowerByte = static_cast<uint8_t>(result & 0x00FF); 822e5d0e473Sopenharmony_ci upperByte = static_cast<uint8_t>(result >> 0x08); 823e5d0e473Sopenharmony_ci } else if (langInfo.lockingLang == MSG_ID_PORTUGUESE_LANG) { 824e5d0e473Sopenharmony_ci i += EscapePortuLockingToUcs2(&src[i], (srcLength - i), langInfo, result); 825e5d0e473Sopenharmony_ci lowerByte = static_cast<uint8_t>(result & 0x00FF); 826e5d0e473Sopenharmony_ci upperByte = static_cast<uint8_t>(result >> 0x08); 827e5d0e473Sopenharmony_ci } 828e5d0e473Sopenharmony_ci } else { 829e5d0e473Sopenharmony_ci i += EscapeGsm7bitToUcs2(&src[i], (srcLength - i), langInfo, result); 830e5d0e473Sopenharmony_ci lowerByte = static_cast<uint8_t>(result & 0x00FF); 831e5d0e473Sopenharmony_ci upperByte = static_cast<uint8_t>(result >> 0x08); 832e5d0e473Sopenharmony_ci } 833e5d0e473Sopenharmony_ci dest[outTextLen++] = upperByte; 834e5d0e473Sopenharmony_ci dest[outTextLen++] = lowerByte; 835e5d0e473Sopenharmony_ci maxLength -= 0x02; 836e5d0e473Sopenharmony_ci } 837e5d0e473Sopenharmony_ci dest[outTextLen] = '\0'; 838e5d0e473Sopenharmony_ci 839e5d0e473Sopenharmony_ci return outTextLen; 840e5d0e473Sopenharmony_ci} 841e5d0e473Sopenharmony_ci 842e5d0e473Sopenharmony_ciint TextCoder::EscapeTurkishLockingToUcs2(const uint8_t *src, int srcLen, const MsgLangInfo &langInfo, uint16_t &result) 843e5d0e473Sopenharmony_ci{ 844e5d0e473Sopenharmony_ci int index = 0; 845e5d0e473Sopenharmony_ci if (src == nullptr || srcLen <= 0) { 846e5d0e473Sopenharmony_ci return index; 847e5d0e473Sopenharmony_ci } 848e5d0e473Sopenharmony_ci // Turkish National Language Locking Shift Table 849e5d0e473Sopenharmony_ci const WCHAR turkishLockingToUcs2[] = { 0x0040, 0x00A3, 0x0024, 0x00A5, 0x20AC, 0x00E9, 0x00F9, 0x00EC, 0x00F2, 850e5d0e473Sopenharmony_ci 0x00C7, 0x000A, 0x011E, 0x011F, 0x000D, 0x00C5, 0x00E5, 0x0394, 0x005F, 0x03A6, 0x0393, 0x039B, 0x03A9, 0x03A0, 851e5d0e473Sopenharmony_ci 0x03A8, 0x03A3, 0x0398, 0x039E, 0x001B, 0x015E, 0x015F, 0x00DF, 0x00C9, 0x0020, 0x0021, 0x0022, 0x0023, 0x00A4, 852e5d0e473Sopenharmony_ci 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F, 0x0030, 0x0031, 0x0032, 853e5d0e473Sopenharmony_ci 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F, 0x0130, 854e5d0e473Sopenharmony_ci 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 855e5d0e473Sopenharmony_ci 0x004F, 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x00C4, 0x00D6, 856e5d0e473Sopenharmony_ci 0x00D1, 0x00DC, 0x00A7, 0x00E7, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006A, 857e5d0e473Sopenharmony_ci 0x006B, 0x006C, 0x006D, 0x006E, 0x006F, 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 858e5d0e473Sopenharmony_ci 0x0079, 0x007A, 0x00E4, 0x00F6, 0x00F1, 0x00FC, 0x00E0 }; 859e5d0e473Sopenharmony_ci // Check Escape 860e5d0e473Sopenharmony_ci if (turkishLockingToUcs2[src[index]] == 0x001B) { 861e5d0e473Sopenharmony_ci index++; 862e5d0e473Sopenharmony_ci if (index >= srcLen) { 863e5d0e473Sopenharmony_ci return index; 864e5d0e473Sopenharmony_ci } 865e5d0e473Sopenharmony_ci result = EscapeToUcs2(src[index], langInfo); 866e5d0e473Sopenharmony_ci } else { 867e5d0e473Sopenharmony_ci // TURKISH 868e5d0e473Sopenharmony_ci result = turkishLockingToUcs2[src[index]]; 869e5d0e473Sopenharmony_ci } 870e5d0e473Sopenharmony_ci return index; 871e5d0e473Sopenharmony_ci} 872e5d0e473Sopenharmony_ci 873e5d0e473Sopenharmony_ciint TextCoder::EscapePortuLockingToUcs2(const uint8_t *src, int srcLen, const MsgLangInfo &langInfo, uint16_t &result) 874e5d0e473Sopenharmony_ci{ 875e5d0e473Sopenharmony_ci int index = 0; 876e5d0e473Sopenharmony_ci if (src == nullptr || srcLen <= 0) { 877e5d0e473Sopenharmony_ci return index; 878e5d0e473Sopenharmony_ci } 879e5d0e473Sopenharmony_ci // Portuguese National Language Locking Shift Table 880e5d0e473Sopenharmony_ci const WCHAR portuLockingToUcs2[] = { 0x0040, 0x00A3, 0x0024, 0x00A5, 0x00EA, 0x00E9, 0x00FA, 0x00ED, 0x00F3, 0x00E7, 881e5d0e473Sopenharmony_ci 0x000A, 0x00D4, 0x00F4, 0x000D, 0x00C1, 0x00E1, 0x0394, 0x005F, 0x0020, 0x00C7, 0x00C0, 0x0020, 0x005E, 0x005C, 882e5d0e473Sopenharmony_ci 0x20AC, 0x00D3, 0x007C, 0x001B, 0x00C2, 0x00E2, 0x00CA, 0x00C9, 0x0020, 0x0021, 0x0022, 0x0023, 0x00A4, 0x0025, 883e5d0e473Sopenharmony_ci 0x0026, 0x0027, 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F, 0x0030, 0x0031, 0x0032, 0x0033, 884e5d0e473Sopenharmony_ci 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F, 0x00CD, 0x0041, 885e5d0e473Sopenharmony_ci 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, 886e5d0e473Sopenharmony_ci 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x00C3, 0x00D5, 0x00DA, 887e5d0e473Sopenharmony_ci 0x00DC, 0x00A7, 0x00BF, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006A, 0x006B, 888e5d0e473Sopenharmony_ci 0x006C, 0x006D, 0x006E, 0x006F, 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 889e5d0e473Sopenharmony_ci 0x007A, 0x00E3, 0x00F5, 0x0020, 0x00FC, 0x00E0 }; 890e5d0e473Sopenharmony_ci if (portuLockingToUcs2[src[index]] == 0x001B) { 891e5d0e473Sopenharmony_ci index++; 892e5d0e473Sopenharmony_ci if (index >= srcLen) { 893e5d0e473Sopenharmony_ci return index; 894e5d0e473Sopenharmony_ci } 895e5d0e473Sopenharmony_ci result = EscapeToUcs2(src[index], langInfo); 896e5d0e473Sopenharmony_ci } else { 897e5d0e473Sopenharmony_ci // PORTUGUESE 898e5d0e473Sopenharmony_ci result = portuLockingToUcs2[src[index]]; 899e5d0e473Sopenharmony_ci } 900e5d0e473Sopenharmony_ci return index; 901e5d0e473Sopenharmony_ci} 902e5d0e473Sopenharmony_ci 903e5d0e473Sopenharmony_ciint TextCoder::EscapeGsm7bitToUcs2(const uint8_t *src, int srcLen, const MsgLangInfo &langInfo, uint16_t &result) 904e5d0e473Sopenharmony_ci{ 905e5d0e473Sopenharmony_ci int index = 0; 906e5d0e473Sopenharmony_ci if (src == nullptr || srcLen <= 0) { 907e5d0e473Sopenharmony_ci return index; 908e5d0e473Sopenharmony_ci } 909e5d0e473Sopenharmony_ci if (GSM7_BIT_TO_UC_S2[src[index]] == 0x001B) { 910e5d0e473Sopenharmony_ci index++; 911e5d0e473Sopenharmony_ci if (index >= srcLen) { 912e5d0e473Sopenharmony_ci return index; 913e5d0e473Sopenharmony_ci } 914e5d0e473Sopenharmony_ci result = EscapeToUcs2(src[index], langInfo); 915e5d0e473Sopenharmony_ci } else { 916e5d0e473Sopenharmony_ci result = GSM7_BIT_TO_UC_S2[src[index]]; 917e5d0e473Sopenharmony_ci } 918e5d0e473Sopenharmony_ci return index; 919e5d0e473Sopenharmony_ci} 920e5d0e473Sopenharmony_ci 921e5d0e473Sopenharmony_ciuint16_t TextCoder::EscapeToUcs2(const uint8_t srcText, const MsgLangInfo &langInfo) 922e5d0e473Sopenharmony_ci{ 923e5d0e473Sopenharmony_ci uint16_t result = 0; 924e5d0e473Sopenharmony_ci if (langInfo.bSingleShift) { 925e5d0e473Sopenharmony_ci TELEPHONY_LOGI("National Language Single Shift [%{public}d]", langInfo.singleLang); 926e5d0e473Sopenharmony_ci switch (langInfo.singleLang) { 927e5d0e473Sopenharmony_ci case MSG_ID_TURKISH_LANG: 928e5d0e473Sopenharmony_ci GetTurkishSingleToUcs2(srcText, result); 929e5d0e473Sopenharmony_ci break; 930e5d0e473Sopenharmony_ci case MSG_ID_SPANISH_LANG: 931e5d0e473Sopenharmony_ci GetSpanishSingleToUcs2(srcText, result); 932e5d0e473Sopenharmony_ci break; 933e5d0e473Sopenharmony_ci case MSG_ID_PORTUGUESE_LANG: 934e5d0e473Sopenharmony_ci GetPortuSingleToUcs2(srcText, result); 935e5d0e473Sopenharmony_ci break; 936e5d0e473Sopenharmony_ci default: 937e5d0e473Sopenharmony_ci GetGsm7BitExtToUcs2(srcText, result); 938e5d0e473Sopenharmony_ci break; 939e5d0e473Sopenharmony_ci } 940e5d0e473Sopenharmony_ci } else { 941e5d0e473Sopenharmony_ci GetGsm7BitExtToUcs2(srcText, result); 942e5d0e473Sopenharmony_ci } 943e5d0e473Sopenharmony_ci return result; 944e5d0e473Sopenharmony_ci} 945e5d0e473Sopenharmony_ci 946e5d0e473Sopenharmony_ciWCHAR TextCoder::GetUCS2Value(uint32_t charset) 947e5d0e473Sopenharmony_ci{ 948e5d0e473Sopenharmony_ci if (charset < 0 || charset >= GSM7_DEFLIST_LEN) { 949e5d0e473Sopenharmony_ci return 0; 950e5d0e473Sopenharmony_ci } 951e5d0e473Sopenharmony_ci return GSM7_BIT_TO_UC_S2[charset]; 952e5d0e473Sopenharmony_ci} 953e5d0e473Sopenharmony_ci 954e5d0e473Sopenharmony_civoid TextCoder::GetTurkishSingleToUcs2(const uint8_t &srcText, uint16_t &result) 955e5d0e473Sopenharmony_ci{ 956e5d0e473Sopenharmony_ci // Turkish National Language Single Shift Table 957e5d0e473Sopenharmony_ci const WCHAR turkishSingleToUcs2[] = { 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 958e5d0e473Sopenharmony_ci 0x0020, 0x000C, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x005E, 0x0020, 0x0020, 959e5d0e473Sopenharmony_ci 0x0020, 0x0020, 0x0020, 0x0020, 0x001B, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 960e5d0e473Sopenharmony_ci 0x0020, 0x0020, 0x0020, 0x007B, 0x007D, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x005C, 0x0020, 0x0020, 0x0020, 961e5d0e473Sopenharmony_ci 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x005B, 0x007E, 0x005D, 0x0020, 0x007C, 962e5d0e473Sopenharmony_ci 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x011E, 0x0020, 0x0130, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 963e5d0e473Sopenharmony_ci 0x0020, 0x0020, 0x0020, 0x0020, 0x015E, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 964e5d0e473Sopenharmony_ci 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x00E7, 0x0020, 0x20AC, 0x0020, 0x011F, 0x0020, 0x0131, 0x0020, 965e5d0e473Sopenharmony_ci 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x015F, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 966e5d0e473Sopenharmony_ci 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020 }; 967e5d0e473Sopenharmony_ci result = turkishSingleToUcs2[srcText]; 968e5d0e473Sopenharmony_ci} 969e5d0e473Sopenharmony_ci 970e5d0e473Sopenharmony_civoid TextCoder::GetSpanishSingleToUcs2(const uint8_t &srcText, uint16_t &result) 971e5d0e473Sopenharmony_ci{ 972e5d0e473Sopenharmony_ci // Spanish National Language Single Shift Table 973e5d0e473Sopenharmony_ci const WCHAR spanishSingleToUcs2[] = { 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 974e5d0e473Sopenharmony_ci 0x00E7, 0x000C, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x005E, 0x0020, 0x0020, 975e5d0e473Sopenharmony_ci 0x0020, 0x0020, 0x0020, 0x0020, 0x001B, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 976e5d0e473Sopenharmony_ci 0x0020, 0x0020, 0x0020, 0x007B, 0x007D, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x005C, 0x0020, 0x0020, 0x0020, 977e5d0e473Sopenharmony_ci 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x005B, 0x007E, 0x005D, 0x0020, 0x007C, 978e5d0e473Sopenharmony_ci 0x00C1, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x00CD, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 979e5d0e473Sopenharmony_ci 0x00D3, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x00DA, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 980e5d0e473Sopenharmony_ci 0x0020, 0x0020, 0x0020, 0x0020, 0x00E1, 0x0020, 0x0020, 0x0020, 0x20AC, 0x0020, 0x0020, 0x0020, 0x00ED, 0x0020, 981e5d0e473Sopenharmony_ci 0x0020, 0x0020, 0x0020, 0x0020, 0x00F3, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x00FA, 0x0020, 0x0020, 0x0020, 982e5d0e473Sopenharmony_ci 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020 }; 983e5d0e473Sopenharmony_ci result = spanishSingleToUcs2[srcText]; 984e5d0e473Sopenharmony_ci} 985e5d0e473Sopenharmony_ci 986e5d0e473Sopenharmony_civoid TextCoder::GetGsm7BitExtToUcs2(const uint8_t &srcText, uint16_t &result) 987e5d0e473Sopenharmony_ci{ 988e5d0e473Sopenharmony_ci // GSM 7 bit Default Alphabet Extension Table 989e5d0e473Sopenharmony_ci const WCHAR gsm7BitExtToUcs2[] = { 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 990e5d0e473Sopenharmony_ci 0x000C, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x005E, 0x0020, 0x0020, 0x0020, 991e5d0e473Sopenharmony_ci 0x0020, 0x0020, 0x0020, 0x001B, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 992e5d0e473Sopenharmony_ci 0x0020, 0x0020, 0x007B, 0x007D, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x005C, 0x0020, 0x0020, 0x0020, 0x0020, 993e5d0e473Sopenharmony_ci 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x005B, 0x007E, 0x005D, 0x0020, 0x007C, 0x0020, 994e5d0e473Sopenharmony_ci 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 995e5d0e473Sopenharmony_ci 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 996e5d0e473Sopenharmony_ci 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x20AC, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 997e5d0e473Sopenharmony_ci 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 998e5d0e473Sopenharmony_ci 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020 }; 999e5d0e473Sopenharmony_ci result = gsm7BitExtToUcs2[srcText]; 1000e5d0e473Sopenharmony_ci} 1001e5d0e473Sopenharmony_ci 1002e5d0e473Sopenharmony_civoid TextCoder::GetPortuSingleToUcs2(const uint8_t &srcText, uint16_t &result) 1003e5d0e473Sopenharmony_ci{ 1004e5d0e473Sopenharmony_ci // Portuguese National Language Single Shift Table 1005e5d0e473Sopenharmony_ci const WCHAR portuSingleToUcs2[] = { 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x00EA, 0x0020, 0x0020, 0x0020, 0x00E7, 1006e5d0e473Sopenharmony_ci 0x000C, 0x00D4, 0x00F4, 0x0020, 0x00C1, 0x00E1, 0x0020, 0x0020, 0x03A6, 0x0393, 0x005E, 0x03A9, 0x03A0, 0x03A8, 1007e5d0e473Sopenharmony_ci 0x03A3, 0x0398, 0x0020, 0x001B, 0x0020, 0x0020, 0x0020, 0x00CA, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 1008e5d0e473Sopenharmony_ci 0x0020, 0x0020, 0x007B, 0x007D, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x005C, 0x0020, 0x0020, 0x0020, 0x0020, 1009e5d0e473Sopenharmony_ci 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x005B, 0x007E, 0x005D, 0x0020, 0x007C, 0x00C0, 1010e5d0e473Sopenharmony_ci 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x00CD, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x00D3, 1011e5d0e473Sopenharmony_ci 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x00DA, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x00C3, 0x00D5, 0x0020, 1012e5d0e473Sopenharmony_ci 0x0020, 0x0020, 0x0020, 0x00C2, 0x0020, 0x0020, 0x0020, 0x20AC, 0x0020, 0x0020, 0x0020, 0x00ED, 0x0020, 0x0020, 1013e5d0e473Sopenharmony_ci 0x0020, 0x0020, 0x0020, 0x00F3, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x00FA, 0x0020, 0x0020, 0x0020, 0x0020, 1014e5d0e473Sopenharmony_ci 0x0020, 0x00E3, 0x00F5, 0x0020, 0x0020, 0x00E2 }; 1015e5d0e473Sopenharmony_ci result = portuSingleToUcs2[srcText]; 1016e5d0e473Sopenharmony_ci} 1017e5d0e473Sopenharmony_ci 1018e5d0e473Sopenharmony_ci} // namespace Telephony 1019e5d0e473Sopenharmony_ci} // namespace OHOS 1020