2 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include "MsgTextConvert.h"
21 #include "MsgCppTypes.h"
24 /*==================================================================================================
25 IMPLEMENTATION OF MsgConvertText - Member Functions
26 ==================================================================================================*/
27 MsgTextConvert* MsgTextConvert::pInstance = NULL;
29 MsgTextConvert::MsgTextConvert()
32 ucs2toGSM7DefList.clear();
33 ucs2toGSM7ExtList.clear();
34 ucs2toTurkishList.clear();
35 ucs2toSpanishList.clear();
36 ucs2toPortuList.clear();
37 replaceCharList.clear();
39 extCharList[0x000C] = MSG_CHAR_GSM7EXT;
40 extCharList[0x005B] = MSG_CHAR_GSM7EXT;
41 extCharList[0x005C] = MSG_CHAR_GSM7EXT;
42 extCharList[0x005D] = MSG_CHAR_GSM7EXT;
43 extCharList[0x005E] = MSG_CHAR_GSM7EXT;
44 extCharList[0x007B] = MSG_CHAR_GSM7EXT;
45 extCharList[0x007C] = MSG_CHAR_GSM7EXT;
46 extCharList[0x007D] = MSG_CHAR_GSM7EXT;
47 extCharList[0x007E] = MSG_CHAR_GSM7EXT;
48 extCharList[0x20AC] = MSG_CHAR_GSM7EXT;
50 extCharList[0x00E7] = MSG_CHAR_TURKISH;
51 extCharList[0x011E] = MSG_CHAR_TURKISH;
52 extCharList[0x011F] = MSG_CHAR_TURKISH;
53 extCharList[0x01E6] = MSG_CHAR_TURKISH;
54 extCharList[0x01E7] = MSG_CHAR_TURKISH;
55 extCharList[0x0130] = MSG_CHAR_TURKISH;
56 extCharList[0x0131] = MSG_CHAR_TURKISH;
57 extCharList[0x015E] = MSG_CHAR_TURKISH;
58 extCharList[0x015F] = MSG_CHAR_TURKISH;
60 extCharList[0x00C1] = MSG_CHAR_SPANISH;
61 extCharList[0x00E1] = MSG_CHAR_SPANISH;
62 extCharList[0x00CD] = MSG_CHAR_SPANISH;
63 extCharList[0x00ED] = MSG_CHAR_SPANISH;
64 extCharList[0x00D3] = MSG_CHAR_SPANISH;
65 extCharList[0x00F3] = MSG_CHAR_SPANISH;
66 extCharList[0x00DA] = MSG_CHAR_SPANISH;
67 extCharList[0x00FA] = MSG_CHAR_SPANISH;
69 extCharList[0x00D4] = MSG_CHAR_PORTUGUESE;
70 extCharList[0x00F4] = MSG_CHAR_PORTUGUESE;
71 extCharList[0x00CA] = MSG_CHAR_PORTUGUESE;
72 extCharList[0x00EA] = MSG_CHAR_PORTUGUESE;
73 extCharList[0x00C0] = MSG_CHAR_PORTUGUESE;
74 extCharList[0x00E7] = MSG_CHAR_PORTUGUESE;
75 extCharList[0x00C3] = MSG_CHAR_PORTUGUESE;
76 extCharList[0x00E3] = MSG_CHAR_PORTUGUESE;
77 extCharList[0x00D5] = MSG_CHAR_PORTUGUESE;
78 extCharList[0x00F5] = MSG_CHAR_PORTUGUESE;
79 extCharList[0x00C2] = MSG_CHAR_PORTUGUESE;
80 extCharList[0x00E2] = MSG_CHAR_PORTUGUESE;
82 for (unsigned char i = 0; i < 128; i++) {
83 ucs2toGSM7DefList[g_GSM7BitToUCS2[i]] = i;
86 /* GSM 7 bit Extension */
87 ucs2toGSM7ExtList[0x005B] = 0x3C; /* [ */
88 ucs2toGSM7ExtList[0x005D] = 0x3E; /* ] */
89 ucs2toGSM7ExtList[0x007B] = 0x28; /* { */
90 ucs2toGSM7ExtList[0x007D] = 0x29; /* } */
91 ucs2toGSM7ExtList[0x000C] = 0x0A; /* Page Break */
92 ucs2toGSM7ExtList[0x005C] = 0x2F; /* \ */
93 ucs2toGSM7ExtList[0x005E] = 0x14; /* ^ */
94 ucs2toGSM7ExtList[0x007C] = 0x40; /* | */
95 ucs2toGSM7ExtList[0x007E] = 0x3D; /* ~ */
96 ucs2toGSM7ExtList[0x20AC] = 0x65; /* € */
99 ucs2toTurkishList[0x005B] = 0x3C; /* [ */
100 ucs2toTurkishList[0x005D] = 0x3E; /* ] */
101 ucs2toTurkishList[0x007B] = 0x28; /* { */
102 ucs2toTurkishList[0x007D] = 0x29; /* } */
103 ucs2toTurkishList[0x000C] = 0x0A; /* Page Break */
104 ucs2toTurkishList[0x005C] = 0x2F; /* \ */
105 ucs2toTurkishList[0x005E] = 0x14; /* ^ */
106 ucs2toTurkishList[0x007C] = 0x40; /* | */
107 ucs2toTurkishList[0x007E] = 0x3D; /* ~ */
108 ucs2toTurkishList[0x20AC] = 0x65; /* € */
109 ucs2toTurkishList[0x00E7] = 0x63; /* c LATIN SMALL LETTER S WITH CEDILLA */
110 ucs2toTurkishList[0x011E] = 0x47; /* G LATIN CAPITAL LETTER G WITH BREVE */
111 ucs2toTurkishList[0x011F] = 0x67; /* g LATIN SMALL LETTER G WITH BREVE */
112 ucs2toTurkishList[0x01E6] = 0x47; /* G LATIN CAPITAL LETTER G WITH CARON */
113 ucs2toTurkishList[0x01E7] = 0x67; /* g LATIN SMALL LETTER G WITH CARON */
114 ucs2toTurkishList[0x0130] = 0x49; /* I LATIN CAPITAL LETTER I WITH DOT ABOVE */
115 ucs2toTurkishList[0x0131] = 0x69; /* i LATIN SMALL LETTER DOTLESS */
116 ucs2toTurkishList[0x015E] = 0x53; /* S LATIN CAPITAL LETTER S WITH CEDILLA */
117 ucs2toTurkishList[0x015F] = 0x73; /* s LATIN SMALL LETTER S WITH CEDILLA */
120 ucs2toSpanishList[0x005B] = 0x3C; /* [ */
121 ucs2toSpanishList[0x005D] = 0x3E; /* ] */
122 ucs2toSpanishList[0x007B] = 0x28; /* { */
123 ucs2toSpanishList[0x007D] = 0x29; /* } */
124 ucs2toSpanishList[0x000C] = 0x0A; /* Page Break */
125 ucs2toSpanishList[0x005C] = 0x2F; /* \ */
126 ucs2toSpanishList[0x005E] = 0x14; /* ^ */
127 ucs2toSpanishList[0x007C] = 0x40; /* | */
128 ucs2toSpanishList[0x007E] = 0x3D; /* ~ */
129 ucs2toSpanishList[0x20AC] = 0x65; /* € */
130 ucs2toSpanishList[0x00C1] = 0x41; /* A LATIN CAPITAL LETTER A WITH ACUTE */
131 ucs2toSpanishList[0x00E1] = 0x61; /* a LATIN SMALL LETTER A WITH ACUTE */
132 ucs2toSpanishList[0x00CD] = 0x49; /* I LATIN CAPITAL LETTER I WITH ACUTE */
133 ucs2toSpanishList[0x00ED] = 0x69; /* i LATIN SMALL LETTER I WITH ACUTE */
134 ucs2toSpanishList[0x00D3] = 0x4F; /* O LATIN CAPITAL LETTER O WITH ACUTE */
135 ucs2toSpanishList[0x00F3] = 0x6F; /* o LATIN SMALL LETTER O WITH ACUTE */
136 ucs2toSpanishList[0x00DA] = 0x55; /* U LATIN CAPITAL LETTER U WITH ACUTE */
137 ucs2toSpanishList[0x00FA] = 0x75; /* u LATIN SMALL LETTER U WITH ACUTE */
140 ucs2toPortuList[0x005B] = 0x3C; /* [ */
141 ucs2toPortuList[0x005D] = 0x3E; /* ] */
142 ucs2toPortuList[0x007B] = 0x28; /* { */
143 ucs2toPortuList[0x007D] = 0x29; /* } */
144 ucs2toPortuList[0x000C] = 0x0A; /* Page Break */
145 ucs2toPortuList[0x005C] = 0x2F; /* \ */
146 ucs2toPortuList[0x005E] = 0x14; /* ^ */
147 ucs2toPortuList[0x007C] = 0x40; /* | */
148 ucs2toPortuList[0x007E] = 0x3D; /* ~ */
149 ucs2toPortuList[0x20AC] = 0x65; /* € */
150 ucs2toPortuList[0x00D4] = 0x0B; /* O LATIN CAPITAL LETTER O WITH CIRCUMFLEX */
151 ucs2toPortuList[0x00F4] = 0x0C; /* o LATIN SMALL LETTER O WITH CIRCUMFLEX */
152 ucs2toPortuList[0x00C1] = 0x0E; /* A LATIN CAPITAL LETTER A WITH ACUTE */
153 ucs2toPortuList[0x00E1] = 0x0F; /* a LATIN SMALL LETTER A WITH ACUTE */
154 ucs2toPortuList[0x00CA] = 0x1F; /* E LATIN CAPITAL LETTER E WITH CIRCUMFLEX */
155 ucs2toPortuList[0x00EA] = 0x05; /* e LATIN SMALL LETTER E WITH CIRCUMFLEX */
156 ucs2toPortuList[0x00C0] = 0x41; /* A LATIN CAPITAL LETTER A WITH GRAVE */
157 ucs2toPortuList[0x00E7] = 0x09; /* c LATIN SMALL LETTER C WITH CEDILLA */
158 ucs2toPortuList[0x00CD] = 0x49; /* I LATIN CAPITAL LETTER I WITH ACUTE */
159 ucs2toPortuList[0x00ED] = 0x69; /* i LATIN SMALL LETTER I WITH ACUTE */
160 ucs2toPortuList[0x00D3] = 0x4F; /* O LATIN CAPITAL LETTER O WITH ACUTE */
161 ucs2toPortuList[0x00F3] = 0x6F; /* o LATIN SMALL LETTER O WITH ACUTE */
162 ucs2toPortuList[0x00DA] = 0x55; /* U LATIN CAPITAL LETTER U WITH ACUTE */
163 ucs2toPortuList[0x00FA] = 0x75; /* u LATIN SMALL LETTER U WITH ACUTE */
164 ucs2toPortuList[0x00C3] = 0x61; /* A LATIN CAPITAL LETTER A WITH TILDE */
165 ucs2toPortuList[0x00E3] = 0x7B; /* a LATIN SMALL LETTER A WITH TILDE */
166 ucs2toPortuList[0x00D5] = 0x5C; /* O LATIN CAPITAL LETTER O WITH TILDE */
167 ucs2toPortuList[0x00F5] = 0x7C; /* o LATIN SMALL LETTER O WITH TILDE */
168 ucs2toPortuList[0x00C2] = 0x61; /* A LATIN CAPITAL LETTER A WITH CIRCUMFLEX */
169 ucs2toPortuList[0x00E2] = 0x7F; /* a LATIN SMALL LETTER A WITH CIRCUMFLEX */
170 ucs2toPortuList[0x03A6] = 0x12; /* Φ GREEK CAPITAL LETTER PHI */
171 ucs2toPortuList[0x0393] = 0x13; /* Γ GREEK CAPITAL LETTER GAMMA */
172 ucs2toPortuList[0x03A9] = 0x15; /* Ω GREEK CAPITAL LETTER OMEGA */
173 ucs2toPortuList[0x03A0] = 0x16; /* Π GREEK CAPITAL LETTER PI */
174 ucs2toPortuList[0x03A8] = 0x17; /* Ψ GREEK CAPITAL LETTER PSI */
175 ucs2toPortuList[0x03A3] = 0x18; /* Σ GREEK CAPITAL LETTER SIGMA */
176 ucs2toPortuList[0x0398] = 0x19; /* Θ GREEK CAPITAL LETTER THETA */
179 /* character replacement table */
180 replaceCharList[0x00E0] = 0x61; /* a LATIN SMALL LETTER A WITH GRAVE */
181 replaceCharList[0x00E1] = 0x61; /* a LATIN SMALL LETTER A WITH ACUTE */
182 replaceCharList[0x00E2] = 0x61; /* a LATIN SMALL LETTER A WITH CIRCUMFLEX */
183 replaceCharList[0x00E3] = 0x61; /* a LATIN SMALL LETTER A WITH TILDE */
184 replaceCharList[0x00E4] = 0x61; /* a LATIN SMALL LETTER A WITH DIAERESIS */
185 replaceCharList[0x00E5] = 0x61; /* a LATIN SMALL LETTER A WITH RING ABOVE */
186 replaceCharList[0x00E6] = 0x61; /* a LATIN SMALL LETTER AE */
187 replaceCharList[0x0101] = 0x61; /* a LATIN SMALL LETTER A WITH MACRON */
188 replaceCharList[0x0103] = 0x61; /* a LATIN SMALL LETTER A WITH BREVE */
189 replaceCharList[0x0105] = 0x61; /* a LATIN SMALL LETTER A WITH OGONEK */
190 replaceCharList[0x01CE] = 0x61; /* a LATIN SMALL LETTER A WITH CARON */
192 replaceCharList[0x00C0] = 0x41; /* A LATIN CAPITAL LETTER A WITH GRAVE */
193 replaceCharList[0x00C1] = 0x41; /* A LATIN CAPITAL LETTER A WITH ACUTE */
194 replaceCharList[0x00C2] = 0x41; /* A LATIN CAPITAL LETTER A WITH CIRCUMFLEX */
195 replaceCharList[0x00C3] = 0x41; /* A LATIN CAPITAL LETTER A WITH TILDE */
196 replaceCharList[0x00C4] = 0x41; /* A LATIN CAPITAL LETTER A WITH DIAERESIS */
197 replaceCharList[0x00C5] = 0x41; /* A LATIN CAPITAL LETTER A WITH RING ABOVE */
198 replaceCharList[0x00C6] = 0x41; /* A LATIN CAPITAL LETTER AE */
199 replaceCharList[0x0100] = 0x41; /* A LATIN CAPITAL LETTER A WITH MACRON */
200 replaceCharList[0x0102] = 0x41; /* A LATIN CAPITAL LETTER A WITH BREVE */
201 replaceCharList[0x0104] = 0x41; /* A LATIN CAPITAL LETTER A WITH OGONEK */
202 replaceCharList[0x01CD] = 0x41; /* A LATIN CAPITAL LETTER A WITH CARON */
204 replaceCharList[0x00E7] = 0x63; /* c LATIN SMALL LETTER C WITH CEDILLA */
205 replaceCharList[0x0107] = 0x63; /* c LATIN SMALL LETTER C WITH ACUTE */
206 replaceCharList[0x0109] = 0x63; /* c LATIN SMALL LETTER C WITH CIRCUMFLEX */
207 replaceCharList[0x010B] = 0x63; /* c LATIN SMALL LETTER C WITH DOT ABOVE */
208 replaceCharList[0x010D] = 0x63; /* c LATIN SMALL LETTER C WITH CARON */
210 replaceCharList[0x00C7] = 0x43; /* C LATIN CAPITAL LETTER C WITH CEDILLA */
211 replaceCharList[0x0106] = 0x43; /* C LATIN CAPITAL LETTER C WITH ACUTE */
212 replaceCharList[0x0108] = 0x43; /* C LATIN CAPITAL LETTER C WITH CIRCUMFLEX */
213 replaceCharList[0x010A] = 0x43; /* C LATIN CAPITAL LETTER C WITH DOT ABOVE */
214 replaceCharList[0x010C] = 0x43; /* C LATIN CAPITAL LETTER C WITH CARON */
216 replaceCharList[0x010F] = 0x64; /* d LATIN SMALL LETTER D WITH CARON */
217 replaceCharList[0x0111] = 0x64; /* d LATIN SMALL LETTER D WITH STROKE */
219 replaceCharList[0x010E] = 0x44; /* D LATIN CAPITAL LETTER D WITH CARON */
220 replaceCharList[0x0110] = 0x44; /* D LATIN CAPITAL LETTER D WITH STROKE */
222 replaceCharList[0x00E8] = 0x65; /* e LATIN SMALL LETTER E WITH GRAVE */
223 replaceCharList[0x00E9] = 0x65; /* e LATIN SMALL LETTER E WITH ACUTE */
224 replaceCharList[0x00EA] = 0x65; /* e LATIN SMALL LETTER E WITH CIRCUMFLEX */
225 replaceCharList[0x00EB] = 0x65; /* e LATIN SMALL LETTER E WITH DIAERESIS */
226 replaceCharList[0x0113] = 0x65; /* e LATIN SMALL LETTER E WITH MACRON */
227 replaceCharList[0x0115] = 0x65; /* e LATIN SMALL LETTER E WITH BREVE */
228 replaceCharList[0x0117] = 0x65; /* e LATIN SMALL LETTER E WITH DOT ABOVE */
229 replaceCharList[0x0119] = 0x65; /* e LATIN SMALL LETTER E WITH OGONEK */
230 replaceCharList[0x011B] = 0x65; /* e LATIN SMALL LETTER E WITH CARON */
231 replaceCharList[0x0259] = 0x65; /* e LATIN SMALL LETTER SCHWA */
233 replaceCharList[0x00C8] = 0x45; /* E LATIN CAPITAL LETTER E WITH GRAVE */
234 replaceCharList[0x00C9] = 0x45; /* E LATIN CAPITAL LETTER E WITH ACUTE */
235 replaceCharList[0x00CA] = 0x45; /* E LATIN CAPITAL LETTER E WITH CIRCUMFLEX */
236 replaceCharList[0x00CB] = 0x45; /* E LATIN CAPITAL LETTER E WITH DIAERESIS */
237 replaceCharList[0x0112] = 0x45; /* E LATIN CAPITAL LETTER E WITH MACRON */
238 replaceCharList[0x0114] = 0x45; /* E LATIN CAPITAL LETTER E WITH BREVE */
239 replaceCharList[0x0116] = 0x45; /* E LATIN CAPITAL LETTER E WITH DOT ABOVE */
240 replaceCharList[0x0118] = 0x45; /* E LATIN CAPITAL LETTER E WITH OGONEK */
241 replaceCharList[0x011A] = 0x45; /* E LATIN CAPITAL LETTER E WITH CARON */
242 replaceCharList[0x018F] = 0x45; /* E LATIN CAPITAL LETTER SCHWA */
244 replaceCharList[0x011D] = 0x67; /* g LATIN SMALL LETTER G WITH CIRCUMFLEX */
245 replaceCharList[0x011F] = 0x67; /* g LATIN SMALL LETTER G WITH BREVE */
246 replaceCharList[0x0121] = 0x67; /* g LATIN SMALL LETTER G WITH DOT ABOVE */
247 replaceCharList[0x0123] = 0x67; /* g LATIN SMALL LETTER G WITH CEDILLA */
248 replaceCharList[0x01E7] = 0x67; /* g LATIN SMALL LETTER G WITH CARON */
249 replaceCharList[0x01F5] = 0x67; /* g LATIN SMALL LETTER G WITH ACUTE */
250 replaceCharList[0x1E21] = 0x67; /* g LATIN SMALL LETTER G WITH MACRON */
252 replaceCharList[0x011C] = 0x47; /* G LATIN CAPITAL LETTER G WITH CIRCUMFLEX */
253 replaceCharList[0x011E] = 0x47; /* G LATIN CAPITAL LETTER G WITH BREVE */
254 replaceCharList[0x0120] = 0x47; /* G LATIN CAPITAL LETTER G WITH DOT ABOVE */
255 replaceCharList[0x0122] = 0x47; /* G LATIN CAPITAL LETTER G WITH CEDILLA */
256 replaceCharList[0x01E6] = 0x47; /* G LATIN CAPITAL LETTER G WITH CARON */
257 replaceCharList[0x01F4] = 0x47; /* G LATIN CAPITAL LETTER G WITH ACUTE */
258 replaceCharList[0x1E20] = 0x47; /* G LATIN CAPITAL LETTER G WITH MACRON */
260 replaceCharList[0x00EC] = 0x69; /* i LATIN SMALL LETTER I WITH GRAVE */
261 replaceCharList[0x00ED] = 0x69; /* i LATIN SMALL LETTER I WITH ACUTE */
262 replaceCharList[0x00EE] = 0x69; /* i LATIN SMALL LETTER I WITH CIRCUMFLEX */
263 replaceCharList[0x00EF] = 0x69; /* i LATIN SMALL LETTER I WITH DIAERESIS */
264 replaceCharList[0x0129] = 0x69; /* i LATIN SMALL LETTER I WITH TILDE */
265 replaceCharList[0x012B] = 0x69; /* i LATIN SMALL LETTER I WITH MACRON */
266 replaceCharList[0x012D] = 0x69; /* i LATIN SMALL LETTER I WITH BREVE */
267 replaceCharList[0x012F] = 0x69; /* i LATIN SMALL LETTER I WITH OGONEK */
268 replaceCharList[0x01D0] = 0x69; /* i LATIN SMALL LETTER I WITH CARON */
269 replaceCharList[0x0131] = 0x69; /* i LATIN SMALL LETTER DOTLESS I */
271 replaceCharList[0x00CC] = 0x49; /* I LATIN CAPITAL LETTER I WITH GRAVE */
272 replaceCharList[0x00CD] = 0x49; /* I LATIN CAPITAL LETTER I WITH ACUTE */
273 replaceCharList[0x00CE] = 0x49; /* I LATIN CAPITAL LETTER I WITH CIRCUMFLEX */
274 replaceCharList[0x00CF] = 0x49; /* I LATIN CAPITAL LETTER I WITH DIAERESIS */
275 replaceCharList[0x0128] = 0x49; /* I LATIN CAPITAL LETTER I WITH TILDE */
276 replaceCharList[0x012A] = 0x49; /* I LATIN CAPITAL LETTER I WITH MACRON */
277 replaceCharList[0x012C] = 0x49; /* I LATIN CAPITAL LETTER I WITH BREVE */
278 replaceCharList[0x012E] = 0x49; /* I LATIN CAPITAL LETTER I WITH OGONEK */
279 replaceCharList[0x0130] = 0x49; /* I LATIN CAPITAL LETTER I WITH DOT ABOVE */
281 replaceCharList[0x0137] = 0x6B; /* k LATIN SMALL LETTER K WITH CEDILLA */
283 replaceCharList[0x0136] = 0x4B; /* K LATIN CAPITAL LETTER K WITH CEDILLA */
285 replaceCharList[0x013A] = 0x6C; /* l LATIN SMALL LETTER L WITH ACUTE */
286 replaceCharList[0x013C] = 0x6C; /* l LATIN SMALL LETTER L WITH CEDILLA */
287 replaceCharList[0x013E] = 0x6C; /* l LATIN SMALL LETTER L WITH CARON */
288 replaceCharList[0x0140] = 0x6C; /* l LATIN SMALL LETTER L WITH MIDDLE DOT */
289 replaceCharList[0x0142] = 0x6C; /* l LATIN SMALL LETTER L WITH STROKE */
291 replaceCharList[0x0139] = 0x4C; /* L LATIN CAPITAL LETTER L WITH ACUTE */
292 replaceCharList[0x013B] = 0x4C; /* L LATIN CAPITAL LETTER L WITH CEDILLA */
293 replaceCharList[0x013D] = 0x4C; /* L LATIN CAPITAL LETTER L WITH CARON */
294 replaceCharList[0x013F] = 0x4C; /* L LATIN CAPITAL LETTER L WITH MIDDLE DOT */
295 replaceCharList[0x0141] = 0x4C; /* L LATIN CAPITAL LETTER L WITH STROKE */
297 replaceCharList[0x00F1] = 0x6E; /* n LATIN SMALL LETTER N WITH TILDE */
298 replaceCharList[0x0144] = 0x6E; /* n LATIN SMALL LETTER N WITH ACUTE */
299 replaceCharList[0x0146] = 0x6E; /* n LATIN SMALL LETTER N WITH CEDILLA */
300 replaceCharList[0x0148] = 0x6E; /* n LATIN SMALL LETTER N WITH CARON */
302 replaceCharList[0x00D1] = 0x4E; /* N LATIN CAPITAL LETTER N WITH TILDE */
303 replaceCharList[0x0143] = 0x4E; /* N LATIN CAPITAL LETTER N WITH ACUTE */
304 replaceCharList[0x0145] = 0x4E; /* N LATIN CAPITAL LETTER N WITH CEDILLA */
305 replaceCharList[0x0147] = 0x4E; /* N LATIN CAPITAL LETTER N WITH CARON */
307 replaceCharList[0x00F2] = 0x6F; /* o LATIN SMALL LETTER O WITH GRAVE */
308 replaceCharList[0x00F3] = 0x6F; /* o LATIN SMALL LETTER O WITH ACUTE */
309 replaceCharList[0x00F4] = 0x6F; /* o LATIN SMALL LETTER O WITH CIRCUMFLEX */
310 replaceCharList[0x00F5] = 0x6F; /* o LATIN SMALL LETTER O WITH TILDE */
311 replaceCharList[0x00F6] = 0x6F; /* o LATIN SMALL LETTER O WITH DIAERESIS */
312 replaceCharList[0x00F8] = 0x6F; /* o LATIN SMALL LETTER O WITH STROKE */
313 replaceCharList[0x014D] = 0x6F; /* o LATIN SMALL LETTER O WITH MACRON */
314 replaceCharList[0x014F] = 0x6F; /* o LATIN SMALL LETTER O WITH BREVE */
315 replaceCharList[0x01D2] = 0x6F; /* o LATIN SMALL LETTER O WITH CARON */
316 replaceCharList[0x01EB] = 0x6F; /* o LATIN SMALL LETTER O WITH OGONEK */
317 replaceCharList[0x0151] = 0x6F; /* o LATIN SMALL LETTER O WITH DOUBLE ACUTE */
318 replaceCharList[0x0153] = 0x6F; /* LATIN SMALL LIGATURE OE */
320 replaceCharList[0x00D2] = 0x4F; /* O LATIN CAPITAL LETTER O WITH GRAVE */
321 replaceCharList[0x00D3] = 0x4F; /* O LATIN CAPITAL LETTER O WITH ACUTE */
322 replaceCharList[0x00D4] = 0x4F; /* O LATIN CAPITAL LETTER O WITH CIRCUMFLEX */
323 replaceCharList[0x00D5] = 0x4F; /* O LATIN CAPITAL LETTER O WITH TILDE */
324 replaceCharList[0x00D6] = 0x4F; /* O LATIN CAPITAL LETTER O WITH DIAERESIS */
325 replaceCharList[0x00D8] = 0x4F; /* O LATIN CAPITAL LETTER O WITH STROKE */
326 replaceCharList[0x014C] = 0x4F; /* O LATIN CAPITAL LETTER O WITH MACRON */
327 replaceCharList[0x014E] = 0x4F; /* O LATIN CAPITAL LETTER O WITH BREVE */
328 replaceCharList[0x01D1] = 0x4F; /* O LATIN CAPITAL LETTER O WITH CARON */
329 replaceCharList[0x01EA] = 0x4F; /* O LATIN CAPITAL LETTER O WITH OGONEK */
330 replaceCharList[0x0150] = 0x4F; /* O LATIN CAPITAL LETTER O WITH DOUBLE ACUTE */
331 replaceCharList[0x0152] = 0x4F; /* LATIN CAPITAL LIGATURE OE */
333 replaceCharList[0x0155] = 0x72; /* r LATIN SMALL LETTER R WITH ACUTE */
334 replaceCharList[0x0157] = 0x72; /* r LATIN SMALL LETTER R WITH CEDILLA */
335 replaceCharList[0x0159] = 0x72; /* r LATIN SMALL LETTER R WITH CARON */
337 replaceCharList[0x0154] = 0x52; /* R LATIN CAPITAL LETTER R WITH ACUTE */
338 replaceCharList[0x0156] = 0x52; /* R LATIN CAPITAL LETTER R WITH CEDILLA */
339 replaceCharList[0x0158] = 0x52; /* R LATIN CAPITAL LETTER R WITH CARON */
341 replaceCharList[0x015B] = 0x73; /* s LATIN SMALL LETTER S WITH ACUTE */
342 replaceCharList[0x015D] = 0x73; /* s LATIN SMALL LETTER S WITH CIRCUMFLEX */
343 replaceCharList[0x015F] = 0x73; /* s LATIN SMALL LETTER S WITH CEDILLA */
344 replaceCharList[0x0161] = 0x73; /* s LATIN SMALL LETTER S WITH CARON */
346 replaceCharList[0x015A] = 0x53; /* S LATIN CAPITAL LETTER S WITH ACUTE */
347 replaceCharList[0x015C] = 0x53; /* S LATIN CAPITAL LETTER S WITH CIRCUMFLEX */
348 replaceCharList[0x015E] = 0x53; /* S LATIN CAPITAL LETTER S WITH CEDILLA */
349 replaceCharList[0x0160] = 0x53; /* S LATIN CAPITAL LETTER S WITH CARON */
351 replaceCharList[0x00FE] = 0x74; /* t LATIN CAPITAL LETTER THORN */
352 replaceCharList[0x0163] = 0x74; /* t LATIN SMALL LETTER T WITH CEDILLA */
353 replaceCharList[0x0165] = 0x74; /* t LATIN SMALL LETTER T WITH CARON */
354 replaceCharList[0x0167] = 0x74; /* t LATIN SMALL LETTER T WITH STROKE */
355 replaceCharList[0x021B] = 0x74; /* t LATIN SMALL LETTER T WITH COMMA BELOW */
357 replaceCharList[0x00DE] = 0x54; /* T LATIN CAPITAL LETTER THORN */
358 replaceCharList[0x0162] = 0x54; /* T LATIN CAPITAL LETTER T WITH CEDILLA */
359 replaceCharList[0x0164] = 0x54; /* T LATIN CAPITAL LETTER T WITH CARON */
360 replaceCharList[0x0166] = 0x54; /* T LATIN CAPITAL LETTER T WITH STROKE */
362 replaceCharList[0x00F9] = 0x75; /* u LATIN SMALL LETTER U WITH GRAVE */
363 replaceCharList[0x00FA] = 0x75; /* u LATIN SMALL LETTER U WITH ACUTE */
364 replaceCharList[0x00FB] = 0x75; /* u LATIN SMALL LETTER U WITH CIRCUMFLEX */
365 replaceCharList[0x00FC] = 0x75; /* u LATIN SMALL LETTER U WITH DIAERESIS */
366 replaceCharList[0x0169] = 0x75; /* u LATIN SMALL LETTER U WITH TILDE */
367 replaceCharList[0x016B] = 0x75; /* u LATIN SMALL LETTER U WITH MACRON */
368 replaceCharList[0x016D] = 0x75; /* u LATIN SMALL LETTER U WITH BREVE */
369 replaceCharList[0x016F] = 0x75; /* u LATIN SMALL LETTER U WITH RING ABOVE */
370 replaceCharList[0x0171] = 0x75; /* u LATIN SMALL LETTER U WITH DOUBLE ACUTE */
371 replaceCharList[0x0173] = 0x75; /* u LATIN SMALL LETTER U WITH OGONEK */
372 replaceCharList[0x01D4] = 0x75; /* u LATIN SMALL LETTER U WITH CARON */
374 replaceCharList[0x00D9] = 0x55; /* U LATIN CAPITAL LETTER U WITH GRAVE */
375 replaceCharList[0x00DA] = 0x55; /* U LATIN CAPITAL LETTER U WITH ACUTE */
376 replaceCharList[0x00DB] = 0x55; /* U LATIN CAPITAL LETTER U WITH CIRCUMFLEX */
377 replaceCharList[0x00DC] = 0x55; /* U LATIN CAPITAL LETTER U WITH DIAERESIS */
378 replaceCharList[0x0168] = 0x55; /* U LATIN CAPITAL LETTER U WITH TILDE */
379 replaceCharList[0x016A] = 0x55; /* U LATIN CAPITAL LETTER U WITH MACRON */
380 replaceCharList[0x016C] = 0x55; /* U LATIN CAPITAL LETTER U WITH BREVE */
381 replaceCharList[0x016E] = 0x55; /* U LATIN CAPITAL LETTER U WITH RING ABOVE */
382 replaceCharList[0x0170] = 0x55; /* U LATIN CAPITAL LETTER U WITH DOUBLE ACUTE */
383 replaceCharList[0x0172] = 0x55; /* U LATIN CAPITAL LETTER U WITH OGONEK */
384 replaceCharList[0x01D3] = 0x55; /* U LATIN CAPITAL LETTER U WITH CARON */
386 replaceCharList[0x00FD] = 0x79; /* y LATIN SMALL LETTER Y WITH ACUTE */
387 replaceCharList[0x00FF] = 0x79; /* y LATIN SMALL LETTER Y WITH DIAERESIS */
388 replaceCharList[0x0177] = 0x79; /* y LATIN SMALL LETTER Y WITH CIRCUMFLEX */
389 replaceCharList[0x0233] = 0x79; /* y LATIN SMALL LETTER Y WITH MACRON */
390 replaceCharList[0x1EF3] = 0x79; /* y LATIN SMALL LETTER Y WITH GRAVE */
391 replaceCharList[0x1EF9] = 0x79; /* y LATIN SMALL LETTER Y WITH TILDE */
393 replaceCharList[0x00DD] = 0x59; /* Y LATIN CAPITAL LETTER Y WITH ACUTE */
394 replaceCharList[0x0176] = 0x59; /* Y LATIN CAPITAL LETTER Y WITH CIRCUMFLEX */
395 replaceCharList[0x0178] = 0x59; /* Y LATIN CAPITAL LETTER Y WITH DIAERESIS */
396 replaceCharList[0x0232] = 0x59; /* Y LATIN CAPITAL LETTER Y WITH MACRON */
397 replaceCharList[0x1EF2] = 0x59; /* Y LATIN CAPITAL LETTER Y WITH GRAVE */
398 replaceCharList[0x1EF8] = 0x59; /* Y LATIN CAPITAL LETTER Y WITH TILDE */
400 replaceCharList[0x017A] = 0x7A; /* z LATIN SMALL LETTER Z WITH ACUTE */
401 replaceCharList[0x017C] = 0x7A; /* z LATIN SMALL LETTER Z WITH DOT ABOVE */
402 replaceCharList[0x017E] = 0x7A; /* z LATIN SMALL LETTER Z WITH CARON */
404 replaceCharList[0x0179] = 0x5A; /* Z LATIN CAPITAL LETTER Z WITH ACUTE */
405 replaceCharList[0x017B] = 0x5A; /* Z LATIN CAPITAL LETTER Z WITH DOT ABOVE */
406 replaceCharList[0x017D] = 0x5A; /* Z LATIN CAPITAL LETTER Z WITH CARON */
410 MsgTextConvert::~MsgTextConvert()
413 ucs2toGSM7DefList.clear();
414 ucs2toGSM7ExtList.clear();
415 ucs2toTurkishList.clear();
416 ucs2toSpanishList.clear();
417 ucs2toPortuList.clear();
418 replaceCharList.clear();
422 MsgTextConvert* MsgTextConvert::instance()
425 MSG_DEBUG("pInstance is NULL. Now creating instance.");
426 pInstance = new MsgTextConvert();
433 int MsgTextConvert::convertUTF8ToGSM7bit(OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText, IN int srcTextLen, OUT MSG_LANGUAGE_ID_T *pLangId, OUT bool *bIncludeAbnormalChar)
436 int gsm7bitLength = 0;
439 if (srcTextLen <= 0 && pSrcText) {
440 utf8Length = strlen((char*)pSrcText);
441 srcTextLen = utf8Length;
443 utf8Length = srcTextLen;
446 int maxUCS2Length = utf8Length; /* max # of UCS2 chars, NOT bytes. when all utf8 chars are only one byte, UCS2Length is maxUCS2 Length. otherwise (ex: 2 bytes of UTF8 is one char) UCS2Length must be less than utf8Length */
448 WCHAR *pUCS2Text = NULL;
449 unique_ptr<WCHAR*, void(*)(WCHAR**)> buf(&pUCS2Text, unique_ptr_deleter);
450 pUCS2Text = (WCHAR *)new char[maxUCS2Length * sizeof(WCHAR)];
451 memset(pUCS2Text, 0x00, maxUCS2Length * sizeof(WCHAR));
453 MSG_DEBUG("srcTextLen = %d", srcTextLen);
454 MSG_DEBUG("temp buffer size = %zu", maxUCS2Length * sizeof(WCHAR));
455 MSG_DEBUG("max dest Length = %d", maxLength);
457 ucs2Length = convertUTF8ToUCS2((unsigned char*)pUCS2Text, maxUCS2Length * sizeof(WCHAR), pSrcText, srcTextLen);
458 gsm7bitLength = convertUCS2ToGSM7bit(pDestText, maxLength, (unsigned char*)pUCS2Text, ucs2Length, pLangId, bIncludeAbnormalChar);
460 return gsm7bitLength;
465 if srcTextLen ispSrcText should be null terminated
467 byte length of converted UCS2 characters
468 -1 : converting error
470 int MsgTextConvert::convertUTF8ToUCS2(OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText, IN int srcTextLen)
473 unsigned char *unicodeTemp = (unsigned char*)pDestText;
474 gsize ucs2Length = 0;
475 gsize remainedBuffer = maxLength;
478 int srcLen = srcTextLen;
479 const unsigned char * pTempSrcText = pSrcText;
480 const unsigned char * pTempDestText = pDestText;
483 if(maxLength == 0 || pSrcText == NULL || pDestText == NULL) {
484 MSG_DEBUG("UTF8 to UCS2 Failed as text length is 0\n");
488 /* null terminated string */
489 if ( srcTextLen == -1 ) {
490 textLen = strlen((char*)pSrcText);
491 srcTextLen = textLen;
493 textLen = srcTextLen;
499 cd = g_iconv_open("UTF16BE", "UTF8");
502 err = g_iconv(cd, (char**)&pSrcText, (gsize*)&textLen, (char**)&unicodeTemp, (gsize*)&remainedBuffer);
506 MSG_DEBUG("Error in g_iconv.");
509 ucs2Length = maxLength - remainedBuffer;
513 MSG_DEBUG("\n########## Dump UTF8 -> UCS2\n");
514 convertDumpTextToHex((unsigned char*)pTempSrcText, srcLen);
515 convertDumpTextToHex((unsigned char*)pTempDestText, ucs2Length);
524 int MsgTextConvert::convertUTF8ToAuto(OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText, IN int srcTextLen, IN msg_encode_type_t defaultEncodingType, OUT msg_encode_type_t *pCharType)
527 int gsm7bitLength = 0;
530 bool bUnknown = false;
532 utf8Length = srcTextLen;
534 int maxUCS2Length = utf8Length; /* max # of UCS2 chars, NOT bytes. when all utf8 chars are only one byte, UCS2Length is maxUCS2 Length. otherwise (ex: 2 bytes of UTF8 is one char) UCS2Length must be less than utf8Length */
535 WCHAR pUCS2Text[maxUCS2Length];
536 memset(pUCS2Text, 0x00, maxUCS2Length * sizeof(WCHAR));
538 MSG_DEBUG("srcTextLen = %d", srcTextLen);
539 MSG_DEBUG("temp buffer size = %zu", maxUCS2Length * sizeof(WCHAR));
540 MSG_DEBUG("max dest Length = %d", maxLength);
542 ucs2Length = convertUTF8ToUCS2((unsigned char*)pUCS2Text, maxUCS2Length * sizeof(WCHAR), pSrcText, srcTextLen);
544 if (ucs2Length < 0) {
545 *pCharType = MSG_ENCODE_8BIT;
547 if (srcTextLen <= maxLength) {
548 memcpy(pDestText, pSrcText, srcTextLen);
551 memcpy(pDestText, pSrcText, maxLength);
555 if (defaultEncodingType == MSG_ENCODE_ASCII7BIT) {
556 gsm7bitLength = convertUCS2ToASCII(pDestText, maxLength, (unsigned char*)pUCS2Text, ucs2Length, &bUnknown);
557 *pCharType = MSG_ENCODE_ASCII7BIT;
559 gsm7bitLength = convertUCS2ToGSM7bitAuto(pDestText, maxLength, (unsigned char*)pUCS2Text, ucs2Length, &bUnknown);
560 *pCharType = MSG_ENCODE_GSM7BIT;
563 if (bUnknown == true) {
564 *pCharType = MSG_ENCODE_UCS2;
566 if (ucs2Length > 0) {
567 if (ucs2Length <= maxLength) {
568 memcpy(pDestText, pUCS2Text, ucs2Length);
571 memcpy(pDestText, pUCS2Text, maxLength);
577 return gsm7bitLength;
584 bytelength of UTF8 text
586 int MsgTextConvert::convertGSM7bitToUTF8(OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText, IN int srcTextLen, IN MSG_LANG_INFO_S *pLangInfo)
590 int maxUCS2Length = srcTextLen; /* max # of UCS2 chars, NOT bytes. when all gsm7 chars are only one byte(-there is no extenstion), UCS2Length is maxUCS2 Length. otherwise(ex: gsm7 char starts with 0x1b) UCS2Length must be less than gsm7 legnth */
592 WCHAR pUCS2Text[maxUCS2Length];
593 memset(pUCS2Text, 0x00, maxUCS2Length * sizeof(WCHAR));
595 MSG_DEBUG("srcTextLen = %d\n", srcTextLen);
596 MSG_DEBUG("max dest Length = %d\n", maxLength);
598 ucs2Length = convertGSM7bitToUCS2((unsigned char*)pUCS2Text, maxUCS2Length * sizeof(WCHAR), pSrcText, srcTextLen, pLangInfo);
599 utf8Length = convertUCS2ToUTF8(pDestText, maxLength, (unsigned char*)pUCS2Text, ucs2Length);
607 OUT unsigned char *pDestText
608 IN int maxLength : max byte length of destination text
609 IN const unsigned char *pSrcText
610 IN int srcTextLen : byte length of UCS2 source text
612 byte length of converted UTF8 characters
613 -1 : The alpha isn't the gsm 7bit code
615 int MsgTextConvert::convertUCS2ToUTF8(OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText, IN int srcTextLen)
618 gsize remainedBuffer = maxLength;
622 int srcLen = srcTextLen;
623 const unsigned char *pTempSrcText = pSrcText;
625 unsigned char *pTempDestText = pDestText;
627 if (srcTextLen == 0 || pSrcText == NULL || pDestText == NULL || maxLength == 0) {
628 MSG_ERR("UCS2 to UTF8 Failed as text length is 0\n");
632 if ( srcTextLen == -1 ) {
633 textLen = strlen((char*)pSrcText);
634 srcTextLen = textLen;
636 textLen = srcTextLen;
642 cd = g_iconv_open("UTF8", "UTF16BE");
645 err = g_iconv(cd, (char**)&pSrcText, (gsize*)&textLen, (char**)&pDestText, (gsize*)&remainedBuffer);
649 MSG_ERR("g_iconv() return value = %d", err);
651 utf8Length = maxLength - remainedBuffer;
652 pTempDestText[utf8Length] = 0x00;
655 MSG_DEBUG("\n########## Dump UCS2 -> UTF8\n");
656 convertDumpTextToHex((unsigned char*)pTempSrcText, srcLen);
657 convertDumpTextToHex((unsigned char*)pTempDestText, utf8Length);
666 int MsgTextConvert::convertEUCKRToUTF8(OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText, IN int srcTextLen)
669 gsize remainedBuffer = maxLength;
673 int srcLen = srcTextLen;
674 const unsigned char * pTempSrcText = pSrcText;
676 unsigned char * pTempDestText = pDestText;
678 if(srcTextLen == 0 || pSrcText == NULL || pDestText == NULL || maxLength == 0) {
679 MSG_DEBUG("EUCKR to UTF8 Failed as text length is 0\n");
683 if ( srcTextLen == -1 ) {
684 textLen = strlen((char*)pSrcText);
685 srcTextLen = textLen;
687 textLen = srcTextLen;
693 cd = g_iconv_open("UTF8", "EUCKR");
696 err = g_iconv(cd, (char**)&pSrcText, (gsize*)&textLen, (char**)&pDestText, (gsize*)&remainedBuffer);
699 MSG_DEBUG("g_iconv() return value = %d", err);
701 utf8Length = maxLength - remainedBuffer;
702 pTempDestText[utf8Length] = 0x00;
705 MSG_DEBUG("\n########## Dump EUCKR -> UTF8\n");
706 convertDumpTextToHex((unsigned char*)pTempSrcText, srcLen);
707 convertDumpTextToHex((unsigned char*)pTempDestText, utf8Length);
716 int MsgTextConvert::convertSHIFTJISToUTF8(OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText, IN int srcTextLen)
719 gsize remainedBuffer = maxLength;
723 int srcLen = srcTextLen;
724 const unsigned char * pTempSrcText = pSrcText;
726 unsigned char * pTempDestText = pDestText;
728 if(srcTextLen == 0 || pSrcText == NULL || pDestText == NULL || maxLength == 0) {
729 MSG_DEBUG("EUCKR to UTF8 Failed as text length is 0\n");
733 if ( srcTextLen == -1 ) {
734 textLen = strlen((char*)pSrcText);
735 srcTextLen = textLen;
737 textLen = srcTextLen;
743 cd = g_iconv_open("UTF8", "SHIFT-JIS");
746 err = g_iconv(cd, (char**)&pSrcText, (gsize*)&textLen, (char**)&pDestText, (gsize*)&remainedBuffer);
749 MSG_DEBUG("g_iconv() return value = %d", err);
751 utf8Length = maxLength - remainedBuffer;
752 pTempDestText[utf8Length] = 0x00;
755 MSG_DEBUG("\n########## Dump SHIFT-JIS -> UTF8\n");
756 convertDumpTextToHex((unsigned char*)pTempSrcText, srcLen);
757 convertDumpTextToHex((unsigned char*)pTempDestText, utf8Length);
769 unsigned char *pDestText
770 int maxLength : max destination buffer size
771 const unsigned char *pSrcText
772 int srcTextLen : BYTE length of src text (UCS2)
774 bytelength of gsm7bit text
775 -1 : converting error
777 int MsgTextConvert::convertUCS2ToGSM7bit(OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText, IN int srcTextLen, OUT MSG_LANGUAGE_ID_T *pLangId, OUT bool *bIncludeAbnormalChar)
781 unsigned char lowerByte, upperByte;
783 if (srcTextLen == 0 || pSrcText == NULL || pDestText == NULL || maxLength == 0) {
784 MSG_DEBUG("Invalid parameter.");
788 std::map<unsigned short, unsigned char>::iterator itChar;
789 std::map<unsigned short, unsigned char>::iterator itExt;
790 std::map<unsigned short, unsigned char>::iterator itReplace;
792 MSG_CHAR_TYPE_T currType = MSG_CHAR_DEFAULT;
793 MSG_CHAR_TYPE_T newType = MSG_CHAR_DEFAULT;
795 unsigned short inText;
797 /* Get Language Type by checking each character */
798 for (int index = 0; index < srcTextLen; index++) {
799 upperByte = pSrcText[index++];
800 lowerByte = pSrcText[index];
802 inText = (upperByte << 8) & 0xFF00;
804 inText = inText | lowerByte;
806 itExt = extCharList.find(inText);
808 if (itExt != extCharList.end()) {
809 newType = (MSG_CHAR_TYPE_T)itExt->second;
811 if (newType >= currType) {
812 if (inText == 0x00e7 && currType <= MSG_CHAR_TURKISH)
813 currType = MSG_CHAR_TURKISH;
820 MSG_DEBUG("charType : [%d]", currType);
822 for (int index = 0; index < srcTextLen; index++) {
823 upperByte = pSrcText[index++];
824 lowerByte = pSrcText[index];
826 inText = (upperByte << 8) & 0xFF00;
827 inText = inText | lowerByte;
829 /* Check Default Char */
830 itChar = ucs2toGSM7DefList.find(inText);
832 if (itChar != ucs2toGSM7DefList.end()) {
833 pDestText[outTextLen++] = (unsigned char)itChar->second;
835 if (currType == MSG_CHAR_GSM7EXT) {
836 itExt = ucs2toGSM7ExtList.find(inText);
838 if (itExt != ucs2toGSM7ExtList.end()) {
839 /* prevent buffer overflow */
840 if (maxLength <= outTextLen + 1) {
841 MSG_DEBUG("Buffer Full.");
845 pDestText[outTextLen++] = 0x1B;
846 pDestText[outTextLen++] = (unsigned char)itExt->second;
848 itReplace = replaceCharList.find(inText);
849 if (itReplace != replaceCharList.end()) {
850 pDestText[outTextLen++] = (unsigned char)itReplace->second;
852 pDestText[outTextLen++] = 0x3F;
854 *bIncludeAbnormalChar = true;
855 MSG_DEBUG("Abnormal character is included. inText : [%04x]", inText);
857 } else if (currType == MSG_CHAR_TURKISH) {
858 *pLangId = MSG_LANG_ID_TURKISH;
860 itExt = ucs2toTurkishList.find(inText);
862 if (itExt != ucs2toTurkishList.end()) {
863 /* prevent buffer overflow */
864 if (maxLength <= outTextLen + 1) {
865 MSG_DEBUG("Buffer Full.");
869 pDestText[outTextLen++] = 0x1B;
870 pDestText[outTextLen++] = (unsigned char)itExt->second;
872 itReplace = replaceCharList.find(inText);
873 if (itReplace != replaceCharList.end()) {
874 pDestText[outTextLen++] = (unsigned char)itReplace->second;
876 pDestText[outTextLen++] = 0x3F;
878 *bIncludeAbnormalChar = true;
879 MSG_DEBUG("Abnormal character is included. inText : [%04x]", inText);
881 } else if (currType == MSG_CHAR_SPANISH) {
882 *pLangId = MSG_LANG_ID_SPANISH;
884 itExt = ucs2toSpanishList.find(inText);
886 if (itExt != ucs2toSpanishList.end()) {
887 /* prevent buffer overflow */
888 if (maxLength <= outTextLen + 1) {
889 MSG_DEBUG("Buffer Full.");
893 pDestText[outTextLen++] = 0x1B;
894 pDestText[outTextLen++] = (unsigned char)itExt->second;
896 itReplace = replaceCharList.find(inText);
897 if (itReplace != replaceCharList.end()) {
898 pDestText[outTextLen++] = (unsigned char)itReplace->second;
900 pDestText[outTextLen++] = 0x3F;
902 *bIncludeAbnormalChar = true;
903 MSG_DEBUG("Abnormal character is included. inText : [%04x]", inText);
905 } else if (currType == MSG_CHAR_PORTUGUESE) {
906 *pLangId = MSG_LANG_ID_PORTUGUESE;
908 itExt = ucs2toPortuList.find(inText);
910 if (itExt != ucs2toPortuList.end()) {
911 /* prevent buffer overflow */
912 if (maxLength <= outTextLen + 1) {
913 MSG_DEBUG("Buffer Full.");
917 pDestText[outTextLen++] = 0x1B;
918 pDestText[outTextLen++] = (unsigned char)itExt->second;
920 itReplace = replaceCharList.find(inText);
921 if (itReplace != replaceCharList.end()) {
922 pDestText[outTextLen++] = (unsigned char)itReplace->second;
924 pDestText[outTextLen++] = 0x3F;
926 *bIncludeAbnormalChar = true;
927 MSG_DEBUG("Abnormal character is included. inText : [%04x]", inText);
930 itReplace = replaceCharList.find(inText);
931 if (itReplace != replaceCharList.end()) {
932 pDestText[outTextLen++] = (unsigned char)itReplace->second;
934 pDestText[outTextLen++] = 0x3F;
936 *bIncludeAbnormalChar = true;
937 MSG_DEBUG("Abnormal character is included. inText : [%04x]", inText);
941 /* prevent buffer overflow */
942 if (maxLength <= outTextLen) {
943 MSG_DEBUG("Buffer full.");
949 MSG_DEBUG("\n########## Dump UCS2 -> GSM7bit\n");
950 convertDumpTextToHex((unsigned char*)pSrcText, srcTextLen);
951 convertDumpTextToHex((unsigned char*)pDestText, outTextLen);
957 int MsgTextConvert::convertUCS2ToGSM7bitAuto(OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText, IN int srcTextLen, OUT bool *pUnknown)
961 unsigned char lowerByte, upperByte;
963 if (srcTextLen == 0 || pSrcText == NULL || pDestText == NULL || maxLength == 0) {
964 MSG_DEBUG("UCS2 to GSM7bit Failed as text length is 0\n");
968 std::map<unsigned short, unsigned char>::iterator itChar;
969 std::map<unsigned short, unsigned char>::iterator itExt;
971 unsigned short inText;
973 for (int index = 0; index < srcTextLen; index++) {
974 upperByte = pSrcText[index++];
975 lowerByte = pSrcText[index];
977 inText = (upperByte << 8) & 0xFF00;
978 inText = inText | lowerByte;
980 /* Check Default Char */
981 itChar = ucs2toGSM7DefList.find(inText);
983 if (itChar != ucs2toGSM7DefList.end()) {
984 pDestText[outTextLen++] = (unsigned char)itChar->second;
986 itExt = ucs2toGSM7ExtList.find(inText);
988 if (itExt != ucs2toGSM7ExtList.end()) {
989 /* prevent buffer overflow */
990 if (maxLength <= outTextLen + 1) {
991 MSG_DEBUG("Buffer Full.");
995 pDestText[outTextLen++] = 0x1B;
996 pDestText[outTextLen++] = (unsigned char)itExt->second;
998 MSG_DEBUG("Abnormal character is included. inText : [%04x]", inText);
1004 /* prevent buffer overflow */
1005 if (maxLength <= outTextLen) {
1006 MSG_DEBUG("Buffer full\n");
1012 MSG_DEBUG("\n########## Dump UCS2 -> GSM7bit\n");
1013 convertDumpTextToHex((unsigned char*)pSrcText, srcTextLen);
1014 convertDumpTextToHex((unsigned char*)pDestText, outTextLen);
1021 int MsgTextConvert::convertUCS2ToASCII(OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText, IN int srcTextLen, OUT bool *pUnknown)
1025 unsigned char lowerByte, upperByte;
1027 if (srcTextLen == 0 || pSrcText == NULL || pDestText == NULL || maxLength == 0) {
1028 MSG_DEBUG("UCS2 to GSM7bit Failed as text length is 0\n");
1032 std::map<unsigned short, unsigned char>::iterator itChar;
1033 std::map<unsigned short, unsigned char>::iterator itExt;
1035 unsigned short inText;
1037 for (int index = 0; index < srcTextLen; index++) {
1038 upperByte = pSrcText[index++];
1039 lowerByte = pSrcText[index];
1041 inText = (upperByte << 8) & 0xFF00;
1042 inText = inText | lowerByte;
1044 /* Check Default Char */
1045 if (inText > 0x007f) {
1046 MSG_DEBUG("Abnormal character is included. inText : [%04x]", inText);
1051 pDestText[outTextLen++] = (unsigned char)inText;
1053 /* prevent buffer overflow */
1054 if (maxLength <= outTextLen) {
1055 MSG_DEBUG("Buffer full\n");
1061 MSG_DEBUG("\n########## Dump UCS2 -> GSM7bit\n");
1062 convertDumpTextToHex((unsigned char*)pSrcText, srcTextLen);
1063 convertDumpTextToHex((unsigned char*)pDestText, outTextLen);
1072 unsigned char *pDestText : destination text (UCS2) - byte order depends on local byte order
1073 const unsigned char *pSrcText : source text (gsm7bit)
1074 int maxLength : max destination buffer size
1075 int srcTextLen : byte length of source text (gsm7bit)
1077 byte length of converted UCS2 characters
1078 -1 : The alpha isn't the gsm 7bit code
1080 int MsgTextConvert::convertGSM7bitToUCS2(OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText, IN int srcTextLen, IN MSG_LANG_INFO_S *pLangInfo)
1083 unsigned char lowerByte = 0, upperByte = 0;
1085 if (srcTextLen == 0 || pSrcText == NULL || pDestText == NULL || maxLength == 0) {
1086 MSG_ERR("UCS2 to GSM7bit Failed as text length is 0\n");
1090 for (int i = 0; i < srcTextLen; i++) {
1091 if (maxLength == 0) {
1095 if (pSrcText[i] >= 0x80) {
1097 MSG_ERR(">>>>>>>a_pTextString[i]=%x, The alpha isn't the gsm 7bit code, Never Come here!!!\n", pSrcText[i]);
1101 if (pLangInfo->bLockingShift == true) { /* National Language Locking Shift */
1102 MSG_DEBUG("Locking Shift [%d]", pLangInfo->lockingLang);
1104 if (pLangInfo->lockingLang == MSG_LANG_ID_TURKISH) {
1106 if (g_TurkishLockingToUCS2[pSrcText[i]] == 0x001B) {
1109 if (pLangInfo->bSingleShift == true) { /* National Language Single Shift */
1110 MSG_DEBUG("Single Shift [%d]", pLangInfo->singleLang);
1112 if (pLangInfo->singleLang == MSG_LANG_ID_TURKISH) {
1113 lowerByte = g_TurkishSingleToUCS2[pSrcText[i]] & 0x00FF;
1114 upperByte = (g_TurkishSingleToUCS2[pSrcText[i]] & 0xFF00) >> 8;
1115 } else if (pLangInfo->singleLang == MSG_LANG_ID_SPANISH) {
1116 lowerByte = g_SpanishSingleToUCS2[pSrcText[i]] & 0x00FF;
1117 upperByte = (g_SpanishSingleToUCS2[pSrcText[i]] & 0xFF00) >> 8;
1118 } else if (pLangInfo->singleLang == MSG_LANG_ID_PORTUGUESE) {
1119 lowerByte = g_PortuSingleToUCS2[pSrcText[i]] & 0x00FF;
1120 upperByte = (g_PortuSingleToUCS2[pSrcText[i]] & 0xFF00) >> 8;
1122 lowerByte = g_GSM7BitExtToUCS2[pSrcText[i]] & 0x00FF;
1123 upperByte = (g_GSM7BitExtToUCS2[pSrcText[i]] & 0xFF00) >> 8;
1125 } else { /* GSM 7 bit Default Alphabet Extension Table */
1126 lowerByte = g_GSM7BitExtToUCS2[pSrcText[i]] & 0x00FF;
1127 upperByte = (g_GSM7BitExtToUCS2[pSrcText[i]] & 0xFF00) >> 8;
1129 } else { /* TURKISH - National Language Locking Shift */
1130 lowerByte = g_TurkishLockingToUCS2[pSrcText[i]] & 0x00FF;
1131 upperByte = (g_TurkishLockingToUCS2[pSrcText[i]] & 0xFF00) >> 8;
1133 } else if (pLangInfo->lockingLang == MSG_LANG_ID_PORTUGUESE) {
1135 if (g_PortuLockingToUCS2[pSrcText[i]] == 0x001B) {
1138 if (pLangInfo->bSingleShift == true) { /* National Language Single Shift */
1139 MSG_DEBUG("Single Shift [%d]", pLangInfo->singleLang);
1141 if (pLangInfo->singleLang == MSG_LANG_ID_TURKISH) {
1142 lowerByte = g_TurkishSingleToUCS2[pSrcText[i]] & 0x00FF;
1143 upperByte = (g_TurkishSingleToUCS2[pSrcText[i]] & 0xFF00) >> 8;
1144 } else if (pLangInfo->singleLang == MSG_LANG_ID_SPANISH) {
1145 lowerByte = g_SpanishSingleToUCS2[pSrcText[i]] & 0x00FF;
1146 upperByte = (g_SpanishSingleToUCS2[pSrcText[i]] & 0xFF00) >> 8;
1147 } else if (pLangInfo->singleLang == MSG_LANG_ID_PORTUGUESE) {
1148 lowerByte = g_PortuSingleToUCS2[pSrcText[i]] & 0x00FF;
1149 upperByte = (g_PortuSingleToUCS2[pSrcText[i]] & 0xFF00) >> 8;
1151 lowerByte = g_GSM7BitExtToUCS2[pSrcText[i]] & 0x00FF;
1152 upperByte = (g_GSM7BitExtToUCS2[pSrcText[i]] & 0xFF00) >> 8;
1154 } else { /* GSM 7 bit Default Alphabet Extension Table */
1155 lowerByte = g_GSM7BitExtToUCS2[pSrcText[i]] & 0x00FF;
1156 upperByte = (g_GSM7BitExtToUCS2[pSrcText[i]] & 0xFF00) >> 8;
1158 } else { /* PORTUGUESE - National Language Locking Shift */
1159 lowerByte = g_PortuLockingToUCS2[pSrcText[i]] & 0x00FF;
1160 upperByte = (g_PortuLockingToUCS2[pSrcText[i]] & 0xFF00) >> 8;
1165 if (g_GSM7BitToUCS2[pSrcText[i]] == 0x001B) {
1168 if (pLangInfo->bSingleShift == true) { /* National Language Single Shift */
1169 MSG_DEBUG("Single Shift [%d]", pLangInfo->singleLang);
1171 if (pLangInfo->singleLang == MSG_LANG_ID_TURKISH) {
1172 lowerByte = g_TurkishSingleToUCS2[pSrcText[i]] & 0x00FF;
1173 upperByte = (g_TurkishSingleToUCS2[pSrcText[i]] & 0xFF00) >> 8;
1174 } else if (pLangInfo->singleLang == MSG_LANG_ID_SPANISH) {
1175 lowerByte = g_SpanishSingleToUCS2[pSrcText[i]] & 0x00FF;
1176 upperByte = (g_SpanishSingleToUCS2[pSrcText[i]] & 0xFF00) >> 8;
1177 } else if (pLangInfo->singleLang == MSG_LANG_ID_PORTUGUESE) {
1178 lowerByte = g_PortuSingleToUCS2[pSrcText[i]] & 0x00FF;
1179 upperByte = (g_PortuSingleToUCS2[pSrcText[i]] & 0xFF00) >> 8;
1181 lowerByte = g_GSM7BitExtToUCS2[pSrcText[i]] & 0x00FF;
1182 upperByte = (g_GSM7BitExtToUCS2[pSrcText[i]] & 0xFF00) >> 8;
1184 } else { /* GSM 7 bit Default Alphabet Extension Table */
1185 lowerByte = g_GSM7BitExtToUCS2[pSrcText[i]] & 0x00FF;
1186 upperByte = (g_GSM7BitExtToUCS2[pSrcText[i]] & 0xFF00) >> 8;
1189 lowerByte = g_GSM7BitToUCS2[pSrcText[i]] & 0x00FF;
1190 upperByte = (g_GSM7BitToUCS2[pSrcText[i]] & 0xFF00) >> 8;
1194 pDestText[outTextLen++] = upperByte;
1195 pDestText[outTextLen++] = lowerByte;
1200 MSG_DEBUG("\n########## Dump GSM7bit -> UCS2\n");
1201 convertDumpTextToHex((unsigned char*)pSrcText, srcTextLen);
1202 convertDumpTextToHex((unsigned char*)pDestText, outTextLen);
1209 void MsgTextConvert::convertDumpTextToHex(const unsigned char *pText, int length)
1211 MSG_DEBUG("=======================================");
1212 MSG_DEBUG(" Dump Text To Hex - Length :%d\n", length);
1213 MSG_DEBUG("=======================================");
1215 for (int i = 0; i < length; i++) {
1216 MSG_DEBUG("[%02x]", pText[i]);
1219 MSG_DEBUG("=======================================");