xref: /aoo4110/main/sal/textenc/textenc.cxx (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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sal.hxx"
26 
27 /* TODO! This file should not be called textenc.c, because it is not the
28    implementation of rtl/textenc.h.  Rather, it should be called
29    gettextencodingdata.c. */
30 #include "gettextencodingdata.h"
31 #include "tenchelp.h"
32 #include "rtl/textenc.h"
33 
34 #ifndef INCLUDED_STDDEF_H
35 #include <stddef.h>
36 #define INCLUDED_STDDEF_H
37 #endif
38 
39 #define NOTABUNI_START 0xFF
40 #define NOTABUNI_END 0x00
41 
42 #define NOTABCHAR_START 0xFFFF
43 #define NOTABCHAR_END 0x0000
44 
45 #define SAME8090UNI_START 0x80
46 #define SAME8090UNI_END 0x9F
47 static sal_uInt16 const aImpl8090SameToUniTab[SAME8090UNI_END
48                                                   - SAME8090UNI_START
49                                                   + 1]
50 = { 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, /* 0x80 */
51     0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
52     0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, /* 0x90 */
53     0x0098, 0x0099, 0x009A, 0x009B, 0x009C, 0x009D, 0x009E, 0x009F };
54 
55 #define SAME8090CHAR_START 0x0080
56 #define SAME8090CHAR_END 0x009F
57 static sal_uChar const aImpl8090SameToCharTab[SAME8090CHAR_END
58                                                   - SAME8090CHAR_START
59                                                   + 1]
60     = { 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, /* 0x0080 */
61         0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
62         0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, /* 0x0090 */
63         0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F };
64 
65 #define SAMEA0FFCHAR_START 0x00A0
66 #define SAMEA0FFCHAR_END 0x00FF
67 static sal_uChar const aImplA0FFSameToCharTab[SAMEA0FFCHAR_END
68                                                   - SAMEA0FFCHAR_START
69                                                   + 1]
70     = { 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, /* 0x00A0 */
71         0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
72         0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, /* 0x00B0 */
73         0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
74         0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, /* 0x00C0 */
75         0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
76         0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, /* 0x00D0 */
77         0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
78         0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, /* 0x00E0 */
79         0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
80         0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, /* 0x00F0 */
81         0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF };
82 
83 static sal_uInt16 const aImplDoubleByteIdentifierTab[1] = { 0 };
84 
85 #include "tcvtarb1.tab"
86 #include "tcvteas1.tab"
87 #include "tcvtest1.tab"
88 #include "tcvtjp1.tab"
89 #include "tcvtjp2.tab"
90 #include "tcvtjp3.tab"
91 #include "tcvtjp4.tab"
92 #include "tcvtjp5.tab"
93 #include "tcvtjp6.tab"
94 #include "tcvtkr1.tab"
95 #include "tcvtkr2.tab"
96 #include "tcvtkr4.tab"
97 #include "tcvtkr5.tab"
98 #include "tcvtkr6.tab"
99 #include "tcvtlat1.tab"
100 #include "tcvtscn1.tab"
101 #include "tcvtscn2.tab"
102 #include "tcvtscn3.tab"
103 #include "tcvtscn4.tab"
104 #include "tcvtscn5.tab"
105 #include "tcvtscn6.tab"
106 #include "tcvtsym1.tab"
107 #include "tcvttcn1.tab"
108 #include "tcvttcn2.tab"
109 #include "tcvttcn6.tab"
110 #include "tcvtuni1.tab"
111 
112 #include "convertbig5hkscs.tab"
113 #include "converteuctw.tab"
114 #include "convertgb18030.tab"
115 #include "convertiso2022cn.tab"
116 #include "convertiso2022jp.tab"
117 #include "convertiso2022kr.tab"
118 #include "convertadobe.tab"
119 
120 ImplTextEncodingData const *
Impl_getTextEncodingData(rtl_TextEncoding nEncoding)121 Impl_getTextEncodingData(rtl_TextEncoding nEncoding) SAL_THROW_EXTERN_C()
122 {
123     static ImplTextEncodingData const * const aData[]
124         = { NULL, /* DONTKNOW */
125             &aImplMS1252TextEncodingData, /* MS_1252 */
126             &aImplAPPLEROMANTextEncodingData, /* APPLE_ROMAN */
127             &aImplIBM437TextEncodingData, /* IBM_437 */
128             &aImplIBM850TextEncodingData, /* IBM_850 */
129             &aImplIBM860TextEncodingData, /* IBM_860 */
130             &aImplIBM861TextEncodingData, /* IBM_861 */
131             &aImplIBM863TextEncodingData, /* IBM_863 */
132             &aImplIBM865TextEncodingData, /* IBM_865 */
133             NULL, /* reserved (SYSTEM) */
134             &aImplSYMBOLTextEncodingData, /* SYMBOL */
135             &aImplUSASCIITextEncodingData, /* ASCII_US */
136             &aImplISO88591TextEncodingData, /* ISO_8859_1 */
137             &aImplISO88592TextEncodingData, /* ISO_8859_2 */
138             &aImplISO88593TextEncodingData, /* ISO_8859_3 */
139             &aImplISO88594TextEncodingData, /* ISO_8859_4 */
140             &aImplISO88595TextEncodingData, /* ISO_8859_5 */
141             &aImplISO88596TextEncodingData, /* ISO_8859_6 */
142             &aImplISO88597TextEncodingData, /* ISO_8859_7 */
143             &aImplISO88598TextEncodingData, /* ISO_8859_8 */
144             &aImplISO88599TextEncodingData, /* ISO_8859_9 */
145             &aImplISO885914TextEncodingData, /* ISO_8859_14 */
146             &aImplISO885915TextEncodingData, /* ISO_8859_15 */
147             &aImplIBM737TextEncodingData, /* IBM_737 */
148             &aImplIBM775TextEncodingData, /* IBM_775 */
149             &aImplIBM852TextEncodingData, /* IBM_852 */
150             &aImplIBM855TextEncodingData, /* IBM_855 */
151             &aImplIBM857TextEncodingData, /* IBM_857 */
152             &aImplIBM862TextEncodingData, /* IBM_862 */
153             &aImplIBM864TextEncodingData, /* IBM_864 */
154             &aImplIBM866TextEncodingData, /* IBM_866 */
155             &aImplIBM869TextEncodingData, /* IBM_869 */
156             &aImplMS874TextEncodingData, /* MS_874 */
157             &aImplMS1250TextEncodingData, /* MS_1250 */
158             &aImplMS1251TextEncodingData, /* MS_1251 */
159             &aImplMS1253TextEncodingData, /* MS_1253 */
160             &aImplMS1254TextEncodingData, /* MS_1254 */
161             &aImplMS1255TextEncodingData, /* MS_1255 */
162             &aImplMS1256TextEncodingData, /* MS_1256 */
163             &aImplMS1257TextEncodingData, /* MS_1257 */
164             &aImplMS1258TextEncodingData, /* MS_1258 */
165             NULL, /* TODO! APPLE_ARABIC */
166             &aImplAPPLECENTEUROTextEncodingData, /* APPLE_CENTEURO */
167             &aImplAPPLECROATIANTextEncodingData, /* APPLE_CROATIAN */
168             &aImplAPPLECYRILLICTextEncodingData, /* APPLE_CYRILLIC */
169             NULL, /* TODO! APPLE_DEVANAGARI */
170             NULL, /* TODO! APPLE_FARSI */
171             &aImplAPPLEGREEKTextEncodingData, /* APPLE_GREEK */
172             NULL, /* TODO! APPLE_GUJARATI */
173             NULL, /* TODO! APPLE_GURMUKHI */
174             NULL, /* TODO! APPLE_HEBREW */
175             &aImplAPPLEICELANDTextEncodingData, /* APPLE_ICELAND */
176             &aImplAPPLEROMANIANTextEncodingData, /* APPLE_ROMANIAN */
177             NULL, /* TODO! APPLE_THAI */
178             &aImplAPPLETURKISHTextEncodingData, /* APPLE_TURKISH */
179             &aImplAPPLEUKRAINIANTextEncodingData, /* APPLE_UKRAINIAN */
180             &aImplAPPLECHINSIMPTextEncodingData, /* APPLE_CHINSIMP */
181             &aImplAPPLECHINTRADTextEncodingData, /* APPLE_CHINTRAD */
182             &aImplAPPLEJAPANESETextEncodingData, /* APPLE_JAPANESE */
183             &aImplAPPLEKOREANTextEncodingData, /* APPLE_KOREAN */
184             &aImplMS932TextEncodingData, /* MS_932 */
185             &aImplMS936TextEncodingData, /* MS_936 */
186             &aImplMS949TextEncodingData, /* MS_949 */
187             &aImplMS950TextEncodingData, /* MS_950 */
188             &aImplSJISTextEncodingData, /* SHIFT_JIS */
189             &aImplGB2312TextEncodingData, /* GB_2312 */
190             &aImplGBT12345TextEncodingData, /* GBT_12345 */
191             &aImplGBKTextEncodingData, /* GBK */
192             &aImplBIG5TextEncodingData, /* BIG5 */
193             &aImplEUCJPTextEncodingData, /* EUC_JP */
194             &aImplEUCCNTextEncodingData, /* EUC_CN */
195             &aImplEucTwTextEncodingData, /* EUC_TW */
196             &aImplIso2022JpTextEncodingData, /* ISO_2022_JP */
197             &aImplIso2022CnTextEncodingData, /* ISO_2022_CN */
198             &aImplKOI8RTextEncodingData, /* KOI8_R */
199             &aImplUTF7TextEncodingData, /* UTF7 */
200             &aImplUTF8TextEncodingData, /* UTF8 */
201             &aImplISO885910TextEncodingData, /* ISO_8859_10 */
202             &aImplISO885913TextEncodingData, /* ISO_8859_13 */
203             &aImplEUCKRTextEncodingData, /* EUC_KR */
204             &aImplIso2022KrTextEncodingData, /* ISO_2022_KR */
205             &aImplJISX0201TextEncodingData, /* JIS_X_0201 */
206             &aImplJISX0208TextEncodingData, /* JIS_X_0208 */
207             &aImplJISX0212TextEncodingData, /* JIS_X_0212 */
208             &aImplMS1361TextEncodingData, /* MS_1361 */
209             &aImplGb18030TextEncodingData, /* GB_18030 */
210             &aImplBig5HkscsTextEncodingData, /* BIG5_HKSCS */
211             &aImplTis620TextEncodingData, /* TIS_620 */
212             &aImplKoi8UTextEncodingData, /* KOI8_U */
213             &aImplJavaUtf8TextEncodingData, /* JAVA_UTF8 */
214             &adobeStandardEncodingData, /* ADOBE_STANDARD */
215             &adobeSymbolEncodingData, /* ADOBE_SYMBOL */
216             &aImplPT154TextEncodingData, /* PT154 */
217             &adobeDingbatsEncodingData }; /* ADOBE_DINGBATS */
218     return
219         nEncoding < sizeof aData / sizeof aData[0] ? aData[nEncoding] : NULL;
220 }
221