xref: /aoo4110/main/sal/textenc/tcvtbyte.c (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "tenchelp.h"
25 #include "rtl/textcvt.h"
26 
27 /* ======================================================================= */
28 
29 #define IMPL_MAX_REPLACECHAR 5
30 
31 sal_uInt16 ImplGetReplaceChar(sal_Unicode c);
32 
33 sal_uInt16 const * ImplGetReplaceString(sal_Unicode c);
34 
35 /* ----------------------------------------------------------------------- */
36 
37 typedef struct
38 {
39     sal_uInt16      mnUniChar;
40     sal_uInt16      mnReplaceChar;
41 } ImplReplaceCharData;
42 
43 static ImplReplaceCharData const aImplRepCharTab[] =
44 {
45   { 0x00A0, 0x0020 },   /* NO-BREAK-SPACE */
46   { 0x00A1, 0x0021 },   /* INVERTED EXCLAMATION MARK */
47   { 0x00B7, 0x0045 },   /* MIDDLE DOT */
48   { 0x00BF, 0x003F },   /* INVERTED QUESTION MARK */
49   { 0x00D7, 0x002A },   /* MULTIPLIKATION SIGN */
50   { 0x00F7, 0x002F },   /* DIVISION SIGN */
51   { 0x2000, 0x0020 },   /* EN QUAD */
52   { 0x2001, 0x0020 },   /* EM QUAD */
53   { 0x2002, 0x0020 },   /* EN SPACE */
54   { 0x2003, 0x0020 },   /* EM SPACE */
55   { 0x2004, 0x0020 },   /* THREE-PER-EM SPACE */
56   { 0x2005, 0x0020 },   /* FOUR-PER-EM SPACE */
57   { 0x2006, 0x0020 },   /* SIX-PER-EM SPACE */
58   { 0x2007, 0x0020 },   /* FIGURE SPACE */
59   { 0x2008, 0x0020 },   /* PUNCTATION SPACE */
60   { 0x2009, 0x0020 },   /* THIN SPACE */
61   { 0x200A, 0x0020 },   /* HAIR SPACE */
62   { 0x2010, 0x002D },   /* HYPHEN */
63   { 0x2011, 0x002D },   /* NON-BREAKING HYPHEN */
64   { 0x2012, 0x002D },   /* FIGURE DASH */
65   { 0x2013, 0x002D },   /* EN DASH */
66   { 0x2014, 0x002D },   /* EM DASH */
67   { 0x2015, 0x002D },   /* HORIZONTAL BAR */
68   { 0x2018, 0x0027 },   /* LEFT SINGLE QUOTATION MARK */
69   { 0x2019, 0x0027 },   /* RIGHT SINGLE QUOTATION MARK */
70   { 0x201A, 0x002C },   /* SINGLE LOW-9 QUOTATION MARK */
71   { 0x201B, 0x0027 },   /* SINGLE HIGH-RESERVED-9 QUOTATION MARK */
72   { 0x201C, 0x0022 },   /* LEFT DOUBLE QUOTATION MARK */
73   { 0x201D, 0x0022 },   /* RIGHT DOUBLE QUOTATION MARK */
74   { 0x201E, 0x0022 },   /* DOUBLE LOW-9 QUOTATION MARK */
75   { 0x201F, 0x0022 },   /* DOUBLE HIGH-RESERVED-9 QUOTATION MARK */
76   { 0x2022, 0x002D },   /* BULLET */
77   { 0x2023, 0x002D },   /* TRIANGULAR BULLET */
78   { 0x2024, 0x002D },   /* ONE DOT LEADER */
79   { 0x2027, 0x002D },   /* HYPHENATION POINT */
80   { 0x2028, 0x000A },   /* LINE SEPARATOR */
81   { 0x2029, 0x000D },   /* PARAGRAPH SEPARATOR */
82   { 0x2032, 0x0027 },   /* PRIME */
83   { 0x2033, 0x0022 },   /* DOUBLE PRIME */
84   { 0x2035, 0x0027 },   /* RESERVED PRIME */
85   { 0x2036, 0x0022 },   /* RESERVED DOUBLE PRIME */
86   { 0x2039, 0x003C },   /* SINGLE LEFT-POINTING ANGLE QUOTATION MARK */
87   { 0x203A, 0x003E },   /* SINGLE RIGHT-POINTING ANGLE QUOTATION MARK */
88   { 0x2043, 0x002D },   /* HYPHEN BULLET */
89   { 0x2044, 0x002F },   /* FRACTION SLASH */
90   { 0x2160, 0x0049 },   /* ROMAN NUMERAL ONE */
91   { 0x2164, 0x0056 },   /* ROMAN NUMERAL FIVE */
92   { 0x2169, 0x0058 },   /* ROMAN NUMERAL TEN */
93   { 0x216C, 0x004C },   /* ROMAN NUMERAL FIFTY */
94   { 0x216D, 0x0043 },   /* ROMAN NUMERAL ONE HUNDRED */
95   { 0x216E, 0x0044 },   /* ROMAN NUMERAL FIVE HUNDRED */
96   { 0x216F, 0x004D },   /* ROMAN NUMERAL ONE THOUSAND */
97   { 0x2170, 0x0069 },   /* SMALL ROMAN NUMERAL ONE */
98   { 0x2174, 0x0076 },   /* SMALL ROMAN NUMERAL FIVE */
99   { 0x2179, 0x0078 },   /* SMALL ROMAN NUMERAL TEN */
100   { 0x217C, 0x006C },   /* SMALL ROMAN NUMERAL FIFTY */
101   { 0x217D, 0x0063 },   /* SMALL ROMAN NUMERAL ONE HUNDRED */
102   { 0x217E, 0x0064 },   /* SMALL ROMAN NUMERAL FIVE HUNDRED */
103   { 0x217F, 0x006D },   /* SMALL ROMAN NUMERAL ONE THOUSAND */
104   { 0x2215, 0x002F },   /* DIVISION SLASH */
105   { 0x2217, 0x002A },   /* ASTERIX OPERATOR */
106   { 0xFF00, 0x0020 },   /* FULLWIDTH ASCII FORMS */
107   { 0xFF01, 0x0021 },   /* FULLWIDTH ASCII FORMS */
108   { 0xFF02, 0x0022 },   /* FULLWIDTH ASCII FORMS*/
109   { 0xFF03, 0x0023 },   /* FULLWIDTH ASCII FORMS */
110   { 0xFF04, 0x0024 },   /* FULLWIDTH ASCII FORMS*/
111   { 0xFF05, 0x0025 },   /* FULLWIDTH ASCII FORMS */
112   { 0xFF06, 0x0026 },   /* FULLWIDTH ASCII FORMS*/
113   { 0xFF07, 0x0027 },   /* FULLWIDTH ASCII FORMS */
114   { 0xFF08, 0x0028 },   /* FULLWIDTH ASCII FORMS*/
115   { 0xFF09, 0x0029 },   /* FULLWIDTH ASCII FORMS */
116   { 0xFF0A, 0x002A },   /* FULLWIDTH ASCII FORMS*/
117   { 0xFF0B, 0x002B },   /* FULLWIDTH ASCII FORMS */
118   { 0xFF0C, 0x002C },   /* FULLWIDTH ASCII FORMS*/
119   { 0xFF0D, 0x002D },   /* FULLWIDTH ASCII FORMS */
120   { 0xFF0E, 0x002E },   /* FULLWIDTH ASCII FORMS*/
121   { 0xFF0F, 0x002F },   /* FULLWIDTH ASCII FORMS */
122   { 0xFF10, 0x0030 },   /* FULLWIDTH ASCII FORMS */
123   { 0xFF11, 0x0031 },   /* FULLWIDTH ASCII FORMS */
124   { 0xFF12, 0x0032 },   /* FULLWIDTH ASCII FORMS*/
125   { 0xFF13, 0x0033 },   /* FULLWIDTH ASCII FORMS */
126   { 0xFF14, 0x0034 },   /* FULLWIDTH ASCII FORMS*/
127   { 0xFF15, 0x0035 },   /* FULLWIDTH ASCII FORMS */
128   { 0xFF16, 0x0036 },   /* FULLWIDTH ASCII FORMS*/
129   { 0xFF17, 0x0037 },   /* FULLWIDTH ASCII FORMS */
130   { 0xFF18, 0x0038 },   /* FULLWIDTH ASCII FORMS*/
131   { 0xFF19, 0x0039 },   /* FULLWIDTH ASCII FORMS */
132   { 0xFF1A, 0x003A },   /* FULLWIDTH ASCII FORMS*/
133   { 0xFF1B, 0x003B },   /* FULLWIDTH ASCII FORMS */
134   { 0xFF1C, 0x003C },   /* FULLWIDTH ASCII FORMS*/
135   { 0xFF1D, 0x003D },   /* FULLWIDTH ASCII FORMS */
136   { 0xFF1E, 0x003E },   /* FULLWIDTH ASCII FORMS*/
137   { 0xFF1F, 0x003F },   /* FULLWIDTH ASCII FORMS */
138   { 0xFF20, 0x0040 },   /* FULLWIDTH ASCII FORMS */
139   { 0xFF21, 0x0041 },   /* FULLWIDTH ASCII FORMS */
140   { 0xFF22, 0x0042 },   /* FULLWIDTH ASCII FORMS*/
141   { 0xFF23, 0x0043 },   /* FULLWIDTH ASCII FORMS */
142   { 0xFF24, 0x0044 },   /* FULLWIDTH ASCII FORMS*/
143   { 0xFF25, 0x0045 },   /* FULLWIDTH ASCII FORMS */
144   { 0xFF26, 0x0046 },   /* FULLWIDTH ASCII FORMS*/
145   { 0xFF27, 0x0047 },   /* FULLWIDTH ASCII FORMS */
146   { 0xFF28, 0x0048 },   /* FULLWIDTH ASCII FORMS*/
147   { 0xFF29, 0x0049 },   /* FULLWIDTH ASCII FORMS */
148   { 0xFF2A, 0x004A },   /* FULLWIDTH ASCII FORMS*/
149   { 0xFF2B, 0x004B },   /* FULLWIDTH ASCII FORMS */
150   { 0xFF2C, 0x004C },   /* FULLWIDTH ASCII FORMS*/
151   { 0xFF2D, 0x004D },   /* FULLWIDTH ASCII FORMS */
152   { 0xFF2E, 0x004E },   /* FULLWIDTH ASCII FORMS*/
153   { 0xFF2F, 0x004F },   /* FULLWIDTH ASCII FORMS */
154   { 0xFF30, 0x0050 },   /* FULLWIDTH ASCII FORMS */
155   { 0xFF31, 0x0051 },   /* FULLWIDTH ASCII FORMS */
156   { 0xFF32, 0x0052 },   /* FULLWIDTH ASCII FORMS*/
157   { 0xFF33, 0x0053 },   /* FULLWIDTH ASCII FORMS */
158   { 0xFF34, 0x0054 },   /* FULLWIDTH ASCII FORMS*/
159   { 0xFF35, 0x0055 },   /* FULLWIDTH ASCII FORMS */
160   { 0xFF36, 0x0056 },   /* FULLWIDTH ASCII FORMS*/
161   { 0xFF37, 0x0057 },   /* FULLWIDTH ASCII FORMS */
162   { 0xFF38, 0x0058 },   /* FULLWIDTH ASCII FORMS*/
163   { 0xFF39, 0x0059 },   /* FULLWIDTH ASCII FORMS */
164   { 0xFF3A, 0x005A },   /* FULLWIDTH ASCII FORMS*/
165   { 0xFF3B, 0x005B },   /* FULLWIDTH ASCII FORMS */
166   { 0xFF3C, 0x005C },   /* FULLWIDTH ASCII FORMS*/
167   { 0xFF3D, 0x005D },   /* FULLWIDTH ASCII FORMS */
168   { 0xFF3E, 0x005E },   /* FULLWIDTH ASCII FORMS*/
169   { 0xFF3F, 0x005F },   /* FULLWIDTH ASCII FORMS */
170   { 0xFF40, 0x0060 },   /* FULLWIDTH ASCII FORMS */
171   { 0xFF41, 0x0061 },   /* FULLWIDTH ASCII FORMS */
172   { 0xFF42, 0x0062 },   /* FULLWIDTH ASCII FORMS*/
173   { 0xFF43, 0x0063 },   /* FULLWIDTH ASCII FORMS */
174   { 0xFF44, 0x0064 },   /* FULLWIDTH ASCII FORMS*/
175   { 0xFF45, 0x0065 },   /* FULLWIDTH ASCII FORMS */
176   { 0xFF46, 0x0066 },   /* FULLWIDTH ASCII FORMS*/
177   { 0xFF47, 0x0067 },   /* FULLWIDTH ASCII FORMS */
178   { 0xFF48, 0x0068 },   /* FULLWIDTH ASCII FORMS*/
179   { 0xFF49, 0x0069 },   /* FULLWIDTH ASCII FORMS */
180   { 0xFF4A, 0x006A },   /* FULLWIDTH ASCII FORMS*/
181   { 0xFF4B, 0x006B },   /* FULLWIDTH ASCII FORMS */
182   { 0xFF4C, 0x006C },   /* FULLWIDTH ASCII FORMS*/
183   { 0xFF4D, 0x006D },   /* FULLWIDTH ASCII FORMS */
184   { 0xFF4E, 0x006E },   /* FULLWIDTH ASCII FORMS*/
185   { 0xFF4F, 0x006F },   /* FULLWIDTH ASCII FORMS */
186   { 0xFF50, 0x0070 },   /* FULLWIDTH ASCII FORMS */
187   { 0xFF51, 0x0071 },   /* FULLWIDTH ASCII FORMS */
188   { 0xFF52, 0x0072 },   /* FULLWIDTH ASCII FORMS*/
189   { 0xFF53, 0x0073 },   /* FULLWIDTH ASCII FORMS */
190   { 0xFF54, 0x0074 },   /* FULLWIDTH ASCII FORMS*/
191   { 0xFF55, 0x0075 },   /* FULLWIDTH ASCII FORMS */
192   { 0xFF56, 0x0076 },   /* FULLWIDTH ASCII FORMS*/
193   { 0xFF57, 0x0077 },   /* FULLWIDTH ASCII FORMS */
194   { 0xFF58, 0x0078 },   /* FULLWIDTH ASCII FORMS*/
195   { 0xFF59, 0x0079 },   /* FULLWIDTH ASCII FORMS */
196   { 0xFF5A, 0x007A },   /* FULLWIDTH ASCII FORMS*/
197   { 0xFF5B, 0x007B },   /* FULLWIDTH ASCII FORMS */
198   { 0xFF5C, 0x007C },   /* FULLWIDTH ASCII FORMS*/
199   { 0xFF5D, 0x007D },   /* FULLWIDTH ASCII FORMS */
200   { 0xFF5E, 0x007E },   /* FULLWIDTH ASCII FORMS*/
201   { 0xFF5F, 0x007F },   /* FULLWIDTH ASCII FORMS */
202   { 0xFF61, 0x3002 },   /* HALFWIDTH KATAKANA FORMS */
203   { 0xFF62, 0x300C },   /* HALFWIDTH KATAKANA FORMS */
204   { 0xFF63, 0x300D },   /* HALFWIDTH KATAKANA FORMS */
205   { 0xFF64, 0x3001 },   /* HALFWIDTH KATAKANA FORMS */
206   { 0xFF65, 0x30FB },   /* HALFWIDTH KATAKANA FORMS */
207   { 0xFF66, 0x30F2 },   /* HALFWIDTH KATAKANA FORMS */
208   { 0xFF67, 0x30A1 },   /* HALFWIDTH KATAKANA FORMS */
209   { 0xFF68, 0x30A3 },   /* HALFWIDTH KATAKANA FORMS */
210   { 0xFF69, 0x30A5 },   /* HALFWIDTH KATAKANA FORMS */
211   { 0xFF6A, 0x30A7 },   /* HALFWIDTH KATAKANA FORMS */
212   { 0xFF6B, 0x30A9 },   /* HALFWIDTH KATAKANA FORMS */
213   { 0xFF6C, 0x30E3 },   /* HALFWIDTH KATAKANA FORMS */
214   { 0xFF6D, 0x30E5 },   /* HALFWIDTH KATAKANA FORMS */
215   { 0xFF6E, 0x30E7 },   /* HALFWIDTH KATAKANA FORMS */
216   { 0xFF6F, 0x30C3 },   /* HALFWIDTH KATAKANA FORMS */
217   { 0xFF70, 0x30FC },   /* HALFWIDTH KATAKANA FORMS */
218   { 0xFF71, 0x30A2 },   /* HALFWIDTH KATAKANA FORMS */
219   { 0xFF72, 0x30A4 },   /* HALFWIDTH KATAKANA FORMS */
220   { 0xFF73, 0x30A6 },   /* HALFWIDTH KATAKANA FORMS */
221   { 0xFF74, 0x30A8 },   /* HALFWIDTH KATAKANA FORMS */
222   { 0xFF75, 0x30AA },   /* HALFWIDTH KATAKANA FORMS */
223   { 0xFF76, 0x30AB },   /* HALFWIDTH KATAKANA FORMS */
224   { 0xFF77, 0x30AD },   /* HALFWIDTH KATAKANA FORMS */
225   { 0xFF78, 0x30AF },   /* HALFWIDTH KATAKANA FORMS */
226   { 0xFF79, 0x30B1 },   /* HALFWIDTH KATAKANA FORMS */
227   { 0xFF7A, 0x30B3 },   /* HALFWIDTH KATAKANA FORMS */
228   { 0xFF7B, 0x30B5 },   /* HALFWIDTH KATAKANA FORMS */
229   { 0xFF7C, 0x30B7 },   /* HALFWIDTH KATAKANA FORMS */
230   { 0xFF7D, 0x30B9 },   /* HALFWIDTH KATAKANA FORMS */
231   { 0xFF7E, 0x30BB },   /* HALFWIDTH KATAKANA FORMS */
232   { 0xFF7F, 0x30BD },   /* HALFWIDTH KATAKANA FORMS */
233   { 0xFF80, 0x30BF },   /* HALFWIDTH KATAKANA FORMS */
234   { 0xFF81, 0x30C1 },   /* HALFWIDTH KATAKANA FORMS */
235   { 0xFF82, 0x30C4 },   /* HALFWIDTH KATAKANA FORMS */
236   { 0xFF83, 0x30C6 },   /* HALFWIDTH KATAKANA FORMS */
237   { 0xFF84, 0x30C8 },   /* HALFWIDTH KATAKANA FORMS */
238   { 0xFF85, 0x30CA },   /* HALFWIDTH KATAKANA FORMS */
239   { 0xFF86, 0x30CB },   /* HALFWIDTH KATAKANA FORMS */
240   { 0xFF87, 0x30CC },   /* HALFWIDTH KATAKANA FORMS */
241   { 0xFF88, 0x30CD },   /* HALFWIDTH KATAKANA FORMS */
242   { 0xFF89, 0x30CE },   /* HALFWIDTH KATAKANA FORMS */
243   { 0xFF8A, 0x30CF },   /* HALFWIDTH KATAKANA FORMS */
244   { 0xFF8B, 0x30D2 },   /* HALFWIDTH KATAKANA FORMS */
245   { 0xFF8C, 0x30D5 },   /* HALFWIDTH KATAKANA FORMS */
246   { 0xFF8D, 0x30D8 },   /* HALFWIDTH KATAKANA FORMS */
247   { 0xFF8E, 0x30DB },   /* HALFWIDTH KATAKANA FORMS */
248   { 0xFF8F, 0x30DE },   /* HALFWIDTH KATAKANA FORMS */
249   { 0xFF90, 0x30DF },   /* HALFWIDTH KATAKANA FORMS */
250   { 0xFF91, 0x30E0 },   /* HALFWIDTH KATAKANA FORMS */
251   { 0xFF92, 0x30E1 },   /* HALFWIDTH KATAKANA FORMS */
252   { 0xFF93, 0x30E2 },   /* HALFWIDTH KATAKANA FORMS */
253   { 0xFF94, 0x30E4 },   /* HALFWIDTH KATAKANA FORMS */
254   { 0xFF95, 0x30E6 },   /* HALFWIDTH KATAKANA FORMS */
255   { 0xFF96, 0x30E8 },   /* HALFWIDTH KATAKANA FORMS */
256   { 0xFF97, 0x30E9 },   /* HALFWIDTH KATAKANA FORMS */
257   { 0xFF98, 0x30EA },   /* HALFWIDTH KATAKANA FORMS */
258   { 0xFF99, 0x30EB },   /* HALFWIDTH KATAKANA FORMS */
259   { 0xFF9A, 0x30EC },   /* HALFWIDTH KATAKANA FORMS */
260   { 0xFF9B, 0x30ED },   /* HALFWIDTH KATAKANA FORMS */
261   { 0xFF9C, 0x30EF },   /* HALFWIDTH KATAKANA FORMS */
262   { 0xFF9D, 0x30F3 },   /* HALFWIDTH KATAKANA FORMS */
263   { 0xFF9E, 0x309B },   /* HALFWIDTH KATAKANA FORMS */
264   { 0xFF9F, 0x309C },   /* HALFWIDTH KATAKANA FORMS */
265   { 0xFFA0, 0x3164 },   /* HALFWIDTH HANGUL FORMS */
266   { 0xFFA1, 0x3131 },   /* HALFWIDTH HANGUL FORMS */
267   { 0xFFA2, 0x3132 },   /* HALFWIDTH HANGUL FORMS */
268   { 0xFFA3, 0x3133 },   /* HALFWIDTH HANGUL FORMS */
269   { 0xFFA4, 0x3134 },   /* HALFWIDTH HANGUL FORMS */
270   { 0xFFA5, 0x3135 },   /* HALFWIDTH HANGUL FORMS */
271   { 0xFFA6, 0x3136 },   /* HALFWIDTH HANGUL FORMS */
272   { 0xFFA7, 0x3137 },   /* HALFWIDTH HANGUL FORMS */
273   { 0xFFA8, 0x3138 },   /* HALFWIDTH HANGUL FORMS */
274   { 0xFFA9, 0x3139 },   /* HALFWIDTH HANGUL FORMS */
275   { 0xFFAA, 0x313A },   /* HALFWIDTH HANGUL FORMS */
276   { 0xFFAB, 0x313B },   /* HALFWIDTH HANGUL FORMS */
277   { 0xFFAC, 0x313C },   /* HALFWIDTH HANGUL FORMS */
278   { 0xFFAD, 0x313D },   /* HALFWIDTH HANGUL FORMS */
279   { 0xFFAE, 0x313E },   /* HALFWIDTH HANGUL FORMS */
280   { 0xFFAF, 0x313F },   /* HALFWIDTH HANGUL FORMS */
281   { 0xFFB0, 0x3140 },   /* HALFWIDTH HANGUL FORMS */
282   { 0xFFB1, 0x3141 },   /* HALFWIDTH HANGUL FORMS */
283   { 0xFFB2, 0x3142 },   /* HALFWIDTH HANGUL FORMS */
284   { 0xFFB3, 0x3143 },   /* HALFWIDTH HANGUL FORMS */
285   { 0xFFB4, 0x3144 },   /* HALFWIDTH HANGUL FORMS */
286   { 0xFFB5, 0x3145 },   /* HALFWIDTH HANGUL FORMS */
287   { 0xFFB6, 0x3146 },   /* HALFWIDTH HANGUL FORMS */
288   { 0xFFB7, 0x3147 },   /* HALFWIDTH HANGUL FORMS */
289   { 0xFFB8, 0x3148 },   /* HALFWIDTH HANGUL FORMS */
290   { 0xFFB9, 0x3149 },   /* HALFWIDTH HANGUL FORMS */
291   { 0xFFBA, 0x314A },   /* HALFWIDTH HANGUL FORMS */
292   { 0xFFBB, 0x314B },   /* HALFWIDTH HANGUL FORMS */
293   { 0xFFBC, 0x314C },   /* HALFWIDTH HANGUL FORMS */
294   { 0xFFBD, 0x314D },   /* HALFWIDTH HANGUL FORMS */
295   { 0xFFBE, 0x314E },   /* HALFWIDTH HANGUL FORMS */
296   { 0xFFC2, 0x314F },   /* HALFWIDTH HANGUL FORMS */
297   { 0xFFC3, 0x3150 },   /* HALFWIDTH HANGUL FORMS */
298   { 0xFFC4, 0x3151 },   /* HALFWIDTH HANGUL FORMS */
299   { 0xFFC5, 0x3152 },   /* HALFWIDTH HANGUL FORMS */
300   { 0xFFC6, 0x3153 },   /* HALFWIDTH HANGUL FORMS */
301   { 0xFFC7, 0x3154 },   /* HALFWIDTH HANGUL FORMS */
302   { 0xFFCA, 0x3155 },   /* HALFWIDTH HANGUL FORMS */
303   { 0xFFCB, 0x3156 },   /* HALFWIDTH HANGUL FORMS */
304   { 0xFFCC, 0x3157 },   /* HALFWIDTH HANGUL FORMS */
305   { 0xFFCD, 0x3158 },   /* HALFWIDTH HANGUL FORMS */
306   { 0xFFCE, 0x3159 },   /* HALFWIDTH HANGUL FORMS */
307   { 0xFFCF, 0x315A },   /* HALFWIDTH HANGUL FORMS */
308   { 0xFFD2, 0x315B },   /* HALFWIDTH HANGUL FORMS */
309   { 0xFFD3, 0x315C },   /* HALFWIDTH HANGUL FORMS */
310   { 0xFFD4, 0x315D },   /* HALFWIDTH HANGUL FORMS */
311   { 0xFFD5, 0x315E },   /* HALFWIDTH HANGUL FORMS */
312   { 0xFFD6, 0x315F },   /* HALFWIDTH HANGUL FORMS */
313   { 0xFFD7, 0x3160 },   /* HALFWIDTH HANGUL FORMS */
314   { 0xFFDA, 0x3161 },   /* HALFWIDTH HANGUL FORMS */
315   { 0xFFDB, 0x3162 },   /* HALFWIDTH HANGUL FORMS */
316   { 0xFFDC, 0x3163 },   /* HALFWIDTH HANGUL FORMS */
317   { 0xFFE0, 0x00A2 },   /* FULLWIDTH CENT SIGN */
318   { 0xFFE1, 0x00A3 },   /* FULLWIDTH POUND SIGN */
319   { 0xFFE2, 0x00AC },   /* FULLWIDTH NOT SIGN */
320   { 0xFFE3, 0x00AF },   /* FULLWIDTH MACRON */
321   { 0xFFE4, 0x00A6 },   /* FULLWIDTH BROKEN BAR */
322   { 0xFFE5, 0x00A5 },   /* FULLWIDTH YEN SIGN */
323   { 0xFFE6, 0x20A9 },   /* FULLWIDTH WON SIGN */
324   { 0xFFE8, 0x2502 },   /* HALFWIDTH FORMS LIGHT VERTICAL */
325   { 0xFFE9, 0x2190 },   /* HALFWIDTH LEFTWARDS ARROW */
326   { 0xFFEA, 0x2191 },   /* HALFWIDTH UPWARDS ARROW */
327   { 0xFFEB, 0x2192 },   /* HALFWIDTH RIGHTWARDS ARROW */
328   { 0xFFEC, 0x2193 },   /* HALFWIDTH DOWNWARDS ARROW */
329   { 0xFFED, 0x25A0 },   /* HALFWIDTH BLACK SQUARE */
330   { 0xFFEE, 0x25CB },   /* HALFWIDTH WHITE CIRCLE */
331   { 0xFFFD, 0x003F }    /* REPLACEMENT CHARACTER */
332 };
333 
ImplGetReplaceChar(sal_Unicode c)334 sal_uInt16 ImplGetReplaceChar( sal_Unicode c )
335 {
336     sal_uInt16                  nLow;
337     sal_uInt16                  nHigh;
338     sal_uInt16                  nMid;
339     sal_uInt16                  nCompareChar;
340     const ImplReplaceCharData*  pCharData;
341 
342     nLow = 0;
343     nHigh = (sizeof( aImplRepCharTab )/sizeof( ImplReplaceCharData ))-1;
344     do
345     {
346         nMid = (nLow+nHigh)/2;
347         pCharData = aImplRepCharTab+nMid;
348         nCompareChar = pCharData->mnUniChar;
349         if ( c < nCompareChar )
350         {
351             if ( !nMid )
352                 break;
353             nHigh = nMid-1;
354         }
355         else
356         {
357             if ( c > nCompareChar )
358                 nLow = nMid+1;
359             else
360                 return pCharData->mnReplaceChar;
361         }
362     }
363     while ( nLow <= nHigh );
364 
365     return 0;
366 }
367 
368 /* ----------------------------------------------------------------------- */
369 
370 typedef struct
371 {
372     sal_uInt16      mnUniChar;
373     sal_uInt16      maReplaceChars[IMPL_MAX_REPLACECHAR];
374 } ImplReplaceCharStrData;
375 
376 static ImplReplaceCharStrData const aImplRepCharStrTab[] =
377 {
378   { 0x00A9, { 0x0028, 0x0063, 0x0029, 0x0000, 0x0000  } },  /* COPYRIGHT SIGN */
379   { 0x00AB, { 0x003C, 0x003C, 0x0000, 0x0000, 0x0000  } },  /* LEFT-POINTING-DOUBLE ANGLE QUOTATION MARK */
380   { 0x0AE0, { 0x0028, 0x0072, 0x0029, 0x0000, 0x0000  } },  /* REGISTERED SIGN */
381   { 0x00BB, { 0x003E, 0x003E, 0x0000, 0x0000, 0x0000  } },  /* RIGHT-POINTING-DOUBLE ANGLE QUOTATION MARK */
382   { 0x00BC, { 0x0031, 0x002F, 0x0034, 0x0000, 0x0000  } },  /* VULGAR FRACTION ONE QUARTER */
383   { 0x00BD, { 0x0031, 0x002F, 0x0032, 0x0000, 0x0000  } },  /* VULGAR FRACTION ONE HALF */
384   { 0x00BE, { 0x0033, 0x002F, 0x0034, 0x0000, 0x0000  } },  /* VULGAR FRACTION THREE QUARTERS */
385   { 0x00C6, { 0x0041, 0x0045, 0x0000, 0x0000, 0x0000  } },  /* LATIN CAPITAL LETTER AE */
386   { 0x00E6, { 0x0061, 0x0065, 0x0000, 0x0000, 0x0000  } },  /* LATIN SMALL LETTER AE */
387   { 0x0152, { 0x004F, 0x0045, 0x0000, 0x0000, 0x0000  } },  /* LATIN CAPITAL LIGATURE OE */
388   { 0x0153, { 0x006F, 0x0065, 0x0000, 0x0000, 0x0000  } },  /* LATIN SMALL LIGATURE OE */
389   { 0x2025, { 0x002E, 0x002E, 0x0000, 0x0000, 0x0000  } },  /* TWO DOT LEADER */
390   { 0x2026, { 0x002E, 0x002E, 0x002E, 0x0000, 0x0000  } },  /* HORIZONTAL ELLIPSES */
391   { 0x2034, { 0x0027, 0x0027, 0x0027, 0x0000, 0x0000  } },  /* TRIPPLE PRIME */
392   { 0x2037, { 0x0027, 0x0027, 0x0027, 0x0000, 0x0000  } },  /* RESERVED TRIPPLE PRIME */
393   { 0x20AC, { 0x0045, 0x0055, 0x0052, 0x0000, 0x0000  } },  /* EURO SIGN */
394   { 0x2122, { 0x0028, 0x0074, 0x006D, 0x0029, 0x0000  } },  /* TRADE MARK SIGN */
395   { 0x2153, { 0x0031, 0x002F, 0x0033, 0x0000, 0x0000  } },  /* VULGAR FRACTION ONE THIRD */
396   { 0x2154, { 0x0032, 0x002F, 0x0033, 0x0000, 0x0000  } },  /* VULGAR FRACTION TWO THIRD */
397   { 0x2155, { 0x0031, 0x002F, 0x0035, 0x0000, 0x0000  } },  /* VULGAR FRACTION ONE FIFTH */
398   { 0x2156, { 0x0032, 0x002F, 0x0035, 0x0000, 0x0000  } },  /* VULGAR FRACTION TWO FIFTH */
399   { 0x2157, { 0x0033, 0x002F, 0x0035, 0x0000, 0x0000  } },  /* VULGAR FRACTION THREE FIFTH */
400   { 0x2158, { 0x0034, 0x002F, 0x0035, 0x0000, 0x0000  } },  /* VULGAR FRACTION FOUR FIFTH */
401   { 0x2159, { 0x0031, 0x002F, 0x0036, 0x0000, 0x0000  } },  /* VULGAR FRACTION ONE SIXTH */
402   { 0x215A, { 0x0035, 0x002F, 0x0036, 0x0000, 0x0000  } },  /* VULGAR FRACTION FIVE SIXTH */
403   { 0x215B, { 0x0031, 0x002F, 0x0038, 0x0000, 0x0000  } },  /* VULGAR FRACTION ONE EIGHTH */
404   { 0x215C, { 0x0033, 0x002F, 0x0038, 0x0000, 0x0000  } },  /* VULGAR FRACTION THREE EIGHTH */
405   { 0x215D, { 0x0035, 0x002F, 0x0038, 0x0000, 0x0000  } },  /* VULGAR FRACTION FIVE EIGHTH */
406   { 0x215E, { 0x0037, 0x002F, 0x0038, 0x0000, 0x0000  } },  /* VULGAR FRACTION SEVEN EIGHTH */
407   { 0x215F, { 0x0031, 0x002F, 0x0000, 0x0000, 0x0000  } },  /* FRACTION NUMERATOR ONE */
408   { 0x2161, { 0x0049, 0x0049, 0x0000, 0x0000, 0x0000  } },  /* ROMAN NUMERAL TWO */
409   { 0x2162, { 0x0049, 0x0049, 0x0049, 0x0000, 0x0000  } },  /* ROMAN NUMERAL THREE */
410   { 0x2163, { 0x0049, 0x0056, 0x0000, 0x0000, 0x0000  } },  /* ROMAN NUMERAL FOUR */
411   { 0x2165, { 0x0056, 0x0049, 0x0000, 0x0000, 0x0000  } },  /* ROMAN NUMERAL SIX */
412   { 0x2166, { 0x0056, 0x0049, 0x0049, 0x0000, 0x0000  } },  /* ROMAN NUMERAL SEVEN */
413   { 0x2168, { 0x0056, 0x0049, 0x0049, 0x0049, 0x0000  } },  /* ROMAN NUMERAL EIGHT */
414   { 0x2169, { 0x0049, 0x0058, 0x0000, 0x0000, 0x0000  } },  /* ROMAN NUMERAL NINE */
415   { 0x216A, { 0x0058, 0x0049, 0x0000, 0x0000, 0x0000  } },  /* ROMAN NUMERAL ELEVEN */
416   { 0x216B, { 0x0058, 0x0049, 0x0049, 0x0000, 0x0000  } },  /* ROMAN NUMERAL TWELVE */
417   { 0x2171, { 0x0069, 0x0069, 0x0000, 0x0000, 0x0000  } },  /* SMALL ROMAN NUMERAL TWO */
418   { 0x2172, { 0x0069, 0x0069, 0x0069, 0x0000, 0x0000  } },  /* SMALL ROMAN NUMERAL THREE */
419   { 0x2173, { 0x0069, 0x0076, 0x0000, 0x0000, 0x0000  } },  /* SMALL ROMAN NUMERAL FOUR */
420   { 0x2175, { 0x0076, 0x0069, 0x0000, 0x0000, 0x0000  } },  /* SMALL ROMAN NUMERAL SIX */
421   { 0x2176, { 0x0076, 0x0069, 0x0069, 0x0000, 0x0000  } },  /* SMALL ROMAN NUMERAL SEVEN */
422   { 0x2178, { 0x0076, 0x0069, 0x0069, 0x0069, 0x0000  } },  /* SMALL ROMAN NUMERAL EIGHT */
423   { 0x2179, { 0x0069, 0x0078, 0x0000, 0x0000, 0x0000  } },  /* SMALL ROMAN NUMERAL NINE */
424   { 0x217A, { 0x0078, 0x0069, 0x0000, 0x0000, 0x0000  } },  /* SMALL ROMAN NUMERAL ELEVEN */
425   { 0x217B, { 0x0058, 0x0069, 0x0069, 0x0000, 0x0000  } }   /* SMALL ROMAN NUMERAL TWELVE */
426 };
427 
ImplGetReplaceString(sal_Unicode c)428 const sal_uInt16* ImplGetReplaceString( sal_Unicode c )
429 {
430     sal_uInt16                      nLow;
431     sal_uInt16                      nHigh;
432     sal_uInt16                      nMid;
433     sal_uInt16                      nCompareChar;
434     const ImplReplaceCharStrData*   pCharData;
435 
436     nLow = 0;
437     nHigh = (sizeof( aImplRepCharStrTab )/sizeof( ImplReplaceCharStrData ))-1;
438     do
439     {
440         nMid = (nLow+nHigh)/2;
441         pCharData = aImplRepCharStrTab+nMid;
442         nCompareChar = pCharData->mnUniChar;
443         if ( c < nCompareChar )
444         {
445             if ( !nMid )
446                 break;
447             nHigh = nMid-1;
448         }
449         else
450         {
451             if ( c > nCompareChar )
452                 nLow = nMid+1;
453             else
454                 return pCharData->maReplaceChars;
455         }
456     }
457     while ( nLow <= nHigh );
458 
459     return 0;
460 }
461 
462 /* ======================================================================= */
463 
ImplSymbolToUnicode(const ImplTextConverterData * pData,void * pContext,const sal_Char * pSrcBuf,sal_Size nSrcBytes,sal_Unicode * pDestBuf,sal_Size nDestChars,sal_uInt32 nFlags,sal_uInt32 * pInfo,sal_Size * pSrcCvtBytes)464 sal_Size ImplSymbolToUnicode( const ImplTextConverterData* pData,
465                               void* pContext,
466                               const sal_Char* pSrcBuf, sal_Size nSrcBytes,
467                               sal_Unicode* pDestBuf, sal_Size nDestChars,
468                               sal_uInt32 nFlags, sal_uInt32* pInfo,
469                               sal_Size* pSrcCvtBytes )
470 {
471     sal_uChar               c;
472     sal_Unicode*            pEndDestBuf;
473     const sal_Char*         pEndSrcBuf;
474 
475     (void) pData; /* unused */
476     (void) pContext; /* unused */
477     (void) nFlags; /* unused */
478 
479     *pInfo = 0;
480     pEndDestBuf = pDestBuf+nDestChars;
481     pEndSrcBuf  = pSrcBuf+nSrcBytes;
482     while ( pSrcBuf < pEndSrcBuf )
483     {
484         if ( pDestBuf == pEndDestBuf )
485         {
486             *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL;
487             break;
488         }
489 
490         /* 0-31 (all Control-Character get the same Unicode value) */
491         c = (sal_uChar)*pSrcBuf;
492         if ( c <= 0x1F )
493             *pDestBuf = (sal_Unicode)c;
494         else
495             *pDestBuf = ((sal_Unicode)c)+0xF000;
496         pDestBuf++;
497         pSrcBuf++;
498     }
499 
500     *pSrcCvtBytes = nSrcBytes - (pEndSrcBuf-pSrcBuf);
501     return (nDestChars - (pEndDestBuf-pDestBuf));
502 }
503 
504 /* ----------------------------------------------------------------------- */
505 
ImplUnicodeToSymbol(const ImplTextConverterData * pData,void * pContext,const sal_Unicode * pSrcBuf,sal_Size nSrcChars,sal_Char * pDestBuf,sal_Size nDestBytes,sal_uInt32 nFlags,sal_uInt32 * pInfo,sal_Size * pSrcCvtChars)506 sal_Size ImplUnicodeToSymbol( const ImplTextConverterData* pData,
507                               void* pContext,
508                               const sal_Unicode* pSrcBuf, sal_Size nSrcChars,
509                               sal_Char* pDestBuf, sal_Size nDestBytes,
510                               sal_uInt32 nFlags, sal_uInt32* pInfo,
511                               sal_Size* pSrcCvtChars )
512 {
513     sal_Unicode             c;
514     sal_Char*               pEndDestBuf;
515     const sal_Unicode*      pEndSrcBuf;
516 
517     (void) pContext; /* unused */
518 
519     *pInfo = 0;
520     pEndDestBuf = pDestBuf+nDestBytes;
521     pEndSrcBuf  = pSrcBuf+nSrcChars;
522     while ( pSrcBuf < pEndSrcBuf )
523     {
524         if ( pDestBuf == pEndDestBuf )
525         {
526             *pInfo |= RTL_UNICODETOTEXT_INFO_ERROR | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
527             break;
528         }
529 
530         c = *pSrcBuf;
531         if ( (c >= 0xF000) && (c <= 0xF0FF) )
532         {
533             *pDestBuf = (sal_Char)(sal_uChar)(c-0xF000);
534             pDestBuf++;
535             pSrcBuf++;
536         }
537         // Normally 0x001F, but in many cases also symbol characters
538         // are stored in the first 256 bytes, so that we don't change
539         // these values
540         else if ( c <= 0x00FF )
541         {
542             *pDestBuf = (sal_Char)(sal_uChar)c;
543             pDestBuf++;
544             pSrcBuf++;
545         }
546         else
547         {
548             if ( nFlags & RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACE )
549             {
550                 /* !!! */
551                 /* Only ascii  characters < 0x1F */
552             }
553 
554             /* Handle undefined and surrogates characters */
555             /* (all surrogates characters are undefined) */
556             if (!ImplHandleUndefinedUnicodeToTextChar(pData,
557                                                       &pSrcBuf,
558                                                       pEndSrcBuf,
559                                                       &pDestBuf,
560                                                       pEndDestBuf,
561                                                       nFlags,
562                                                       pInfo))
563                 break;
564         }
565     }
566 
567     *pSrcCvtChars = nSrcChars - (pEndSrcBuf-pSrcBuf);
568     return (nDestBytes - (pEndDestBuf-pDestBuf));
569 }
570 
571 /* ======================================================================= */
572 
ImplCharToUnicode(const ImplTextConverterData * pData,void * pContext,const sal_Char * pSrcBuf,sal_Size nSrcBytes,sal_Unicode * pDestBuf,sal_Size nDestChars,sal_uInt32 nFlags,sal_uInt32 * pInfo,sal_Size * pSrcCvtBytes)573 sal_Size ImplCharToUnicode( const ImplTextConverterData* pData,
574                             void* pContext,
575                             const sal_Char* pSrcBuf, sal_Size nSrcBytes,
576                             sal_Unicode* pDestBuf, sal_Size nDestChars,
577                             sal_uInt32 nFlags, sal_uInt32* pInfo,
578                             sal_Size* pSrcCvtBytes )
579 {
580     sal_uChar                   c;
581     sal_Unicode                 cConv;
582     const ImplByteConvertData*  pConvertData = (const ImplByteConvertData*)pData;
583     sal_Unicode*                pEndDestBuf;
584     const sal_Char*             pEndSrcBuf;
585 
586     (void) pContext; /* unused */
587 
588     *pInfo = 0;
589     pEndDestBuf = pDestBuf+nDestChars;
590     pEndSrcBuf  = pSrcBuf+nSrcBytes;
591     while ( pSrcBuf < pEndSrcBuf )
592     {
593         c = (sal_uChar)*pSrcBuf;
594         if ( c < 0x80 )
595             cConv = c;
596         else
597         {
598             if ( (c >= pConvertData->mnToUniStart1) && (c <= pConvertData->mnToUniEnd1) )
599                 cConv = pConvertData->mpToUniTab1[c-pConvertData->mnToUniStart1];
600             else if ( (c >= pConvertData->mnToUniStart2) && (c <= pConvertData->mnToUniEnd2) )
601                 cConv = pConvertData->mpToUniTab2[c-pConvertData->mnToUniStart2];
602             else
603                 cConv = 0;
604             if ( !cConv )
605             {
606                 *pInfo |= RTL_TEXTTOUNICODE_INFO_UNDEFINED;
607                 if ( (nFlags & RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MASK) == RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR )
608                 {
609                     *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR;
610                     break;
611                 }
612                 else if ( (nFlags & RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MASK) == RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_IGNORE )
613                 {
614                     pSrcBuf++;
615                     continue;
616                 }
617                 else
618                     cConv = ImplGetUndefinedUnicodeChar(c, nFlags);
619             }
620         }
621 
622         if ( pDestBuf == pEndDestBuf )
623         {
624             *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL;
625             break;
626         }
627 
628         *pDestBuf = cConv;
629         pDestBuf++;
630         pSrcBuf++;
631     }
632 
633     *pSrcCvtBytes = nSrcBytes - (pEndSrcBuf-pSrcBuf);
634     return (nDestChars - (pEndDestBuf-pDestBuf));
635 }
636 
637 /* ----------------------------------------------------------------------- */
638 
639 // Writes 0--2 characters to dest:
ImplConvertUnicodeCharToChar(const ImplByteConvertData * pConvertData,sal_Unicode c,sal_Char * dest)640 static int ImplConvertUnicodeCharToChar(
641     const ImplByteConvertData* pConvertData, sal_Unicode c, sal_Char * dest )
642 {
643     const ImplUniCharTabData*   pToCharExTab;
644 
645     if ( c < 0x80 )
646     {
647         dest[0] = (sal_Char)c;
648         return 1;
649     }
650     if ( (c >= pConvertData->mnToCharStart1) && (c <= pConvertData->mnToCharEnd1) )
651     {
652         dest[0] = (sal_Char)pConvertData->mpToCharTab1[c-pConvertData->mnToCharStart1];
653         if ( dest[0] != 0 )
654             return 1;
655     }
656     else if ( (c >= pConvertData->mnToCharStart2) && (c <= pConvertData->mnToCharEnd2) )
657     {
658         dest[0] = (sal_Char)pConvertData->mpToCharTab2[c-pConvertData->mnToCharStart2];
659         if ( dest[0] != 0 )
660             return 1;
661     }
662     pToCharExTab = pConvertData->mpToCharExTab;
663     if ( pToCharExTab )
664     {
665         sal_uInt16                  nLow;
666         sal_uInt16                  nHigh;
667         sal_uInt16                  nMid;
668         sal_uInt16                  nCompareChar;
669         const ImplUniCharTabData*   pCharExData;
670 
671         nLow = 0;
672         nHigh = pConvertData->mnToCharExCount-1;
673         do
674         {
675             nMid = (nLow+nHigh)/2;
676             pCharExData = pToCharExTab+nMid;
677             nCompareChar = pCharExData->mnUniChar;
678             if ( c < nCompareChar )
679             {
680                 if ( !nMid )
681                     break;
682                 nHigh = nMid-1;
683             }
684             else
685             {
686                 if ( c > nCompareChar )
687                     nLow = nMid+1;
688                 else
689                 {
690                     dest[0] = (sal_Char)pCharExData->mnChar;
691                     if ( pCharExData->mnChar2 == 0 )
692                         return 1;
693                     else
694                     {
695                         dest[1] = (sal_Char)pCharExData->mnChar2;
696                         return 2;
697                     }
698                 }
699             }
700         }
701         while ( nLow <= nHigh );
702     }
703     return 0;
704 }
705 
706 /* ----------------------------------------------------------------------- */
707 
ImplUnicodeToChar(const ImplTextConverterData * pData,void * pContext,const sal_Unicode * pSrcBuf,sal_Size nSrcChars,sal_Char * pDestBuf,sal_Size nDestBytes,sal_uInt32 nFlags,sal_uInt32 * pInfo,sal_Size * pSrcCvtChars)708 sal_Size ImplUnicodeToChar( const ImplTextConverterData* pData,
709                             void* pContext,
710                             const sal_Unicode* pSrcBuf, sal_Size nSrcChars,
711                             sal_Char* pDestBuf, sal_Size nDestBytes,
712                             sal_uInt32 nFlags, sal_uInt32* pInfo,
713                             sal_Size* pSrcCvtChars )
714 {
715     sal_Unicode                 c;
716     const ImplByteConvertData*  pConvertData = (const ImplByteConvertData*)pData;
717     sal_Char*                   pEndDestBuf;
718     const sal_Unicode*          pEndSrcBuf;
719     int                         i;
720     int                         n;
721     sal_uInt16                  cTemp;
722     sal_Char                    aTempBuf[IMPL_MAX_REPLACECHAR+2];
723     const sal_uInt16*           pReplace;
724 
725     (void) pContext; /* unused */
726 
727     *pInfo = 0;
728     pEndDestBuf = pDestBuf+nDestBytes;
729     pEndSrcBuf  = pSrcBuf+nSrcChars;
730     while ( pSrcBuf < pEndSrcBuf )
731     {
732         c = *pSrcBuf;
733         if ( c < 0x80 )
734         {
735             aTempBuf[0] = (sal_Char)c;
736             n = 1;
737         }
738         else
739         {
740             n = ImplConvertUnicodeCharToChar( pConvertData, c, aTempBuf );
741 
742             if ( n == 0 )
743             {
744                 if ( nFlags & RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACE )
745                 {
746                     cTemp = ImplGetReplaceChar( c );
747                     if ( cTemp )
748                         n = ImplConvertUnicodeCharToChar(
749                             pConvertData, cTemp, aTempBuf );
750                 }
751 
752                 if ( n == 0 )
753                 {
754                     if ( nFlags & RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACESTR )
755                     {
756                         pReplace = ImplGetReplaceString( c );
757                         if ( pReplace )
758                         {
759                             while ( *pReplace && (n < IMPL_MAX_REPLACECHAR) )
760                             {
761                                 i = ImplConvertUnicodeCharToChar(
762                                     pConvertData, *pReplace, aTempBuf + n );
763                                 if ( i == 0 )
764                                 {
765                                     n = 0;
766                                     break;
767                                 }
768                                 pReplace++;
769                                 n += i;
770                             }
771                         }
772                     }
773 
774                     /* Handle undefined and surrogates characters */
775                     /* (all surrogates characters are undefined) */
776                     if ( n == 0 )
777                     {
778                         if (ImplHandleUndefinedUnicodeToTextChar(pData,
779                                                                  &pSrcBuf,
780                                                                  pEndSrcBuf,
781                                                                  &pDestBuf,
782                                                                  pEndDestBuf,
783                                                                  nFlags,
784                                                                  pInfo))
785                             continue;
786                         else
787                             break;
788                     }
789                 }
790             }
791         }
792 
793         if ( pEndDestBuf - pDestBuf < n )
794         {
795             *pInfo |= RTL_UNICODETOTEXT_INFO_ERROR | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
796             break;
797         }
798 
799         for ( i = 0; i < n; ++i )
800             *pDestBuf++ = aTempBuf[i];
801         pSrcBuf++;
802     }
803 
804     *pSrcCvtChars = nSrcChars - (pEndSrcBuf-pSrcBuf);
805     return (nDestBytes - (pEndDestBuf-pDestBuf));
806 }
807