xref: /aoo42x/main/sal/textenc/tenchelp.h (revision 9eab2a37)
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 #ifndef INCLUDED_RTL_TEXTENC_TENCHELP_H
25 #define INCLUDED_RTL_TEXTENC_TENCHELP_H
26 
27 #include "rtl/tencinfo.h"
28 #include "rtl/textenc.h"
29 #include "sal/types.h"
30 
31 #if defined __cplusplus
32 extern "C" {
33 #endif /* __cplusplus */
34 
35 #define RTL_TEXTCVT_BYTE_PRIVATE_START 0xF100
36 #define RTL_TEXTCVT_BYTE_PRIVATE_END 0xF1FF
37 
38 /* ----------------- */
39 /* - TextConverter - */
40 /* ----------------- */
41 
42 typedef void ImplTextConverterData;
43 
44 typedef
45 sal_Size (* ImplConvertToUnicodeProc)(ImplTextConverterData const * pData,
46                                       void * pContext,
47                                       sal_Char const * pSrcBuf,
48                                       sal_Size nSrcBytes,
49                                       sal_Unicode * pDestBuf,
50                                       sal_Size nDestChars,
51                                       sal_uInt32 nFlags,
52                                       sal_uInt32 * pInfo,
53                                       sal_Size * pSrcCvtBytes);
54 
55 typedef
56 sal_Size (* ImplConvertToTextProc)(ImplTextConverterData const * pData,
57                                    void * pContext,
58                                    sal_Unicode const * pSrcBuf,
59                                    sal_Size nSrcChars,
60                                    sal_Char * pDestBuf,
61                                    sal_Size nDestBytes,
62                                    sal_uInt32 nFlags,
63                                    sal_uInt32 * pInfo,
64                                    sal_Size * pSrcCvtChars);
65 
66 typedef void * (* ImplCreateTextContextProc)(void);
67 
68 typedef void (* ImplDestroyTextContextProc)(void * pContext);
69 
70 typedef void (* ImplResetTextContextProc)(void * pContext);
71 
72 typedef void * (* ImplCreateUnicodeContextProc)(void);
73 
74 typedef void (* ImplDestroyUnicodeContextProc)(void * pContext);
75 
76 typedef void (* ImplResetUnicodeContextProc)(void * pContext);
77 
78 typedef struct
79 {
80     ImplTextConverterData const * mpConvertData;
81     ImplConvertToUnicodeProc mpConvertTextToUnicodeProc;
82     ImplConvertToTextProc mpConvertUnicodeToTextProc;
83     ImplCreateTextContextProc mpCreateTextToUnicodeContext;
84     ImplDestroyTextContextProc mpDestroyTextToUnicodeContext;
85     ImplResetTextContextProc mpResetTextToUnicodeContext;
86     ImplCreateUnicodeContextProc mpCreateUnicodeToTextContext;
87     ImplDestroyUnicodeContextProc mpDestroyUnicodeToTextContext;
88     ImplResetUnicodeContextProc mpResetUnicodeToTextContext;
89 } ImplTextConverter;
90 
91 /* ----------------------------- */
92 /* - TextEncoding - Structures - */
93 /* ----------------------------- */
94 
95 typedef struct
96 {
97     ImplTextConverter maConverter;
98     sal_uInt8 mnMinCharSize;
99     sal_uInt8 mnMaxCharSize;
100     sal_uInt8 mnAveCharSize;
101     sal_uInt8 mnBestWindowsCharset;
102     char const * mpBestUnixCharset;
103     char const * mpBestMimeCharset;
104     sal_uInt32 mnInfoFlags;
105 } ImplTextEncodingData;
106 
107 /* ----------------------------------- */
108 /* - TextConverter - Byte-Structures - */
109 /* ----------------------------------- */
110 
111 typedef struct
112 {
113     sal_uInt16                      mnUniChar;
114     sal_uChar                       mnChar;
115     sal_uChar                       mnChar2;
116         // to cater for mappings like MS1258 with 1--2 bytes per Unicode char,
117         // 0 if unused
118 } ImplUniCharTabData;
119 
120 typedef struct
121 {
122     const sal_uInt16*               mpToUniTab1;
123     const sal_uInt16*               mpToUniTab2;
124     sal_uChar                       mnToUniStart1;
125     sal_uChar                       mnToUniEnd1;
126     sal_uChar                       mnToUniStart2;
127     sal_uChar                       mnToUniEnd2;
128     const sal_uChar*                mpToCharTab1;
129     const sal_uChar*                mpToCharTab2;
130     const ImplUniCharTabData*       mpToCharExTab;
131     sal_uInt16                      mnToCharStart1;
132     sal_uInt16                      mnToCharEnd1;
133     sal_uInt16                      mnToCharStart2;
134     sal_uInt16                      mnToCharEnd2;
135     sal_uInt16                      mnToCharExCount;
136 } ImplByteConvertData;
137 
138 /* ----------------------------------- */
139 /* - TextConverter - DBCS-Structures - */
140 /* ----------------------------------- */
141 
142 typedef struct
143 {
144     sal_uChar                       mnLeadStart;
145     sal_uChar                       mnLeadEnd;
146     sal_uChar                       mnTrail1Start;
147     sal_uChar                       mnTrail1End;
148     sal_uChar                       mnTrail2Start;
149     sal_uChar                       mnTrail2End;
150     sal_uChar                       mnTrail3Start;
151     sal_uChar                       mnTrail3End;
152     sal_uChar                       mnTrailCount;
153     sal_uInt16                      mnTrailRangeCount;
154     sal_uInt16                      mnUniStart;
155     sal_uInt16                      mnUniEnd;
156 } ImplDBCSEUDCData;
157 
158 typedef struct
159 {
160     sal_uInt16                      mnUniChar;
161     sal_uInt8                       mnTrailStart;
162     sal_uInt8                       mnTrailEnd;
163     const sal_uInt16*               mpToUniTrailTab;
164 } ImplDBCSToUniLeadTab;
165 
166 typedef struct
167 {
168     sal_uInt8                       mnLowStart;
169     sal_uInt8                       mnLowEnd;
170     const sal_uInt16*               mpToUniTrailTab;
171 } ImplUniToDBCSHighTab;
172 
173 typedef struct
174 {
175     const ImplDBCSToUniLeadTab*     mpToUniLeadTab;
176     const ImplUniToDBCSHighTab*     mpToDBCSHighTab;
177     sal_uChar                       mnLeadStart;
178     sal_uChar                       mnLeadEnd;
179     sal_uChar                       mnTrailStart;
180     sal_uChar                       mnTrailEnd;
181     const ImplDBCSEUDCData*         mpEUDCTab;
182     sal_uInt16                      mnEUDCCount;
183 } ImplDBCSConvertData;
184 
185 /* ---------------------------------- */
186 /* - TextConverter - EUC-Structures - */
187 /* ---------------------------------- */
188 
189 typedef struct
190 {
191     const ImplDBCSToUniLeadTab*     mpJIS0208ToUniLeadTab;
192     const ImplDBCSToUniLeadTab*     mpJIS0212ToUniLeadTab;
193     const ImplUniToDBCSHighTab*     mpUniToJIS0208HighTab;
194     const ImplUniToDBCSHighTab*     mpUniToJIS0212HighTab;
195 } ImplEUCJPConvertData;
196 
197 /* --------------------------------- */
198 /* - TextConverter - HelpFunctions - */
199 /* --------------------------------- */
200 
201 sal_Unicode ImplGetUndefinedUnicodeChar(sal_uChar cChar, sal_uInt32 nFlags);
202 
203 sal_Bool
204 ImplHandleUndefinedUnicodeToTextChar(ImplTextConverterData const * pData,
205                                      sal_Unicode const ** ppSrcBuf,
206                                      sal_Unicode const * pEndSrcBuf,
207                                      sal_Char ** ppDestBuf,
208                                      sal_Char const * pEndDestBuf,
209                                      sal_uInt32 nFlags,
210                                      sal_uInt32 * pInfo);
211     /* sal_True means 'continue,' sal_False means 'break' */
212 
213 /* ----------------------------- */
214 /* - TextConverter - Functions - */
215 /* ----------------------------- */
216 
217 sal_Size ImplSymbolToUnicode( const ImplTextConverterData* pData, void* pContext,
218                               const sal_Char* pSrcBuf, sal_Size nSrcBytes,
219                               sal_Unicode* pDestBuf, sal_Size nDestChars,
220                               sal_uInt32 nFlags, sal_uInt32* pInfo, sal_Size* pSrcCvtBytes );
221 sal_Size ImplUnicodeToSymbol( const ImplTextConverterData* pData, void* pContext,
222                               const sal_Unicode* pSrcBuf, sal_Size nSrcChars,
223                               sal_Char* pDestBuf, sal_Size nDestBytes,
224                               sal_uInt32 nFlags, sal_uInt32* pInfo, sal_Size* pSrcCvtChars );
225 sal_Size ImplCharToUnicode( const ImplTextConverterData* pData, void* pContext,
226                             const sal_Char* pSrcBuf, sal_Size nSrcBytes,
227                             sal_Unicode* pDestBuf, sal_Size nDestChars,
228                             sal_uInt32 nFlags, sal_uInt32* pInfo, sal_Size* pSrcCvtBytes );
229 sal_Size ImplUnicodeToChar( const ImplTextConverterData* pData, void* pContext,
230                             const sal_Unicode* pSrcBuf, sal_Size nSrcChars,
231                             sal_Char* pDestBuf, sal_Size nDestBytes,
232                             sal_uInt32 nFlags, sal_uInt32* pInfo, sal_Size* pSrcCvtChars );
233 sal_Size ImplDBCSToUnicode( const ImplTextConverterData* pData, void* pContext,
234                             const sal_Char* pSrcBuf, sal_Size nSrcBytes,
235                             sal_Unicode* pDestBuf, sal_Size nDestChars,
236                             sal_uInt32 nFlags, sal_uInt32* pInfo,
237                             sal_Size* pSrcCvtBytes );
238 sal_Size ImplUnicodeToDBCS( const ImplTextConverterData* pData, void* pContext,
239                             const sal_Unicode* pSrcBuf, sal_Size nSrcChars,
240                             sal_Char* pDestBuf, sal_Size nDestBytes,
241                             sal_uInt32 nFlags, sal_uInt32* pInfo,
242                             sal_Size* pSrcCvtChars );
243 sal_Size ImplEUCJPToUnicode( const ImplTextConverterData* pData,
244                              void* pContext,
245                              const sal_Char* pSrcBuf, sal_Size nSrcBytes,
246                              sal_Unicode* pDestBuf, sal_Size nDestChars,
247                              sal_uInt32 nFlags, sal_uInt32* pInfo,
248                              sal_Size* pSrcCvtBytes );
249 sal_Size ImplUnicodeToEUCJP( const ImplTextConverterData* pData,
250                              void* pContext,
251                              const sal_Unicode* pSrcBuf, sal_Size nSrcChars,
252                              sal_Char* pDestBuf, sal_Size nDestBytes,
253                              sal_uInt32 nFlags, sal_uInt32* pInfo,
254                              sal_Size* pSrcCvtChars );
255 void* ImplUTF7CreateUTF7TextToUnicodeContext( void );
256 void ImplUTF7DestroyTextToUnicodeContext( void* pContext );
257 void ImplUTF7ResetTextToUnicodeContext( void* pContext );
258 sal_Size ImplUTF7ToUnicode( const ImplTextConverterData* pData, void* pContext,
259                             const sal_Char* pSrcBuf, sal_Size nSrcBytes,
260                             sal_Unicode* pDestBuf, sal_Size nDestChars,
261                             sal_uInt32 nFlags, sal_uInt32* pInfo,
262                             sal_Size* pSrcCvtBytes );
263 void* ImplUTF7CreateUnicodeToTextContext( void );
264 void ImplUTF7DestroyUnicodeToTextContext( void* pContext );
265 void ImplUTF7ResetUnicodeToTextContext( void* pContext );
266 sal_Size ImplUnicodeToUTF7( const ImplTextConverterData* pData, void* pContext,
267                             const sal_Unicode* pSrcBuf, sal_Size nSrcChars,
268                             sal_Char* pDestBuf, sal_Size nDestBytes,
269                             sal_uInt32 nFlags, sal_uInt32* pInfo,
270                             sal_Size* pSrcCvtChars );
271 
272 void * ImplCreateUtf8ToUnicodeContext(void) SAL_THROW_EXTERN_C();
273 void ImplResetUtf8ToUnicodeContext(void * pContext) SAL_THROW_EXTERN_C();
274 sal_Size ImplConvertUtf8ToUnicode(ImplTextConverterData const * pData,
275                                   void * pContext, sal_Char const * pSrcBuf,
276                                   sal_Size nSrcBytes, sal_Unicode * pDestBuf,
277                                   sal_Size nDestChars, sal_uInt32 nFlags,
278                                   sal_uInt32 * pInfo, sal_Size * pSrcCvtBytes)
279     SAL_THROW_EXTERN_C();
280 void * ImplCreateUnicodeToUtf8Context(void) SAL_THROW_EXTERN_C();
281 void ImplResetUnicodeToUtf8Context(void * pContext) SAL_THROW_EXTERN_C();
282 sal_Size ImplConvertUnicodeToUtf8(ImplTextConverterData const * pData,
283                                   void * pContext, sal_Unicode const * pSrcBuf,
284                                   sal_Size nSrcChars, sal_Char * pDestBuf,
285                                   sal_Size nDestBytes, sal_uInt32 nFlags,
286                                   sal_uInt32 * pInfo, sal_Size* pSrcCvtChars)
287     SAL_THROW_EXTERN_C();
288 
289 #if defined __cplusplus
290 }
291 #endif /* __cplusplus */
292 
293 #endif /* INCLUDED_RTL_TEXTENC_TENCHELP_H */
294