Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "sal/config.h"
30 : :
31 : : #include "rtl/textcvt.h"
32 : :
33 : : #include "gettextencodingdata.hxx"
34 : : #include "tenchelp.hxx"
35 : :
36 : : /* ======================================================================= */
37 : :
38 : 3085 : static sal_Size ImplDummyToUnicode( const char* pSrcBuf, sal_Size nSrcBytes,
39 : : sal_Unicode* pDestBuf, sal_Size nDestChars,
40 : : sal_uInt32 nFlags, sal_uInt32* pInfo,
41 : : sal_Size* pSrcCvtBytes )
42 : : {
43 : : sal_Unicode* pEndDestBuf;
44 : : const char* pEndSrcBuf;
45 : :
46 [ + - ][ - + ]: 3085 : if ( ((nFlags & RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MASK) == RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR) ||
47 : : ((nFlags & RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_MASK) == RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR) )
48 : : {
49 : : *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR |
50 : : RTL_TEXTTOUNICODE_INFO_UNDEFINED |
51 : 0 : RTL_TEXTTOUNICODE_INFO_MBUNDEFINED;
52 : 0 : return 0;
53 : : }
54 : :
55 : 3085 : *pInfo = 0;
56 : 3085 : pEndDestBuf = pDestBuf+nDestChars;
57 : 3085 : pEndSrcBuf = pSrcBuf+nSrcBytes;
58 [ + + ]: 37545 : while ( pSrcBuf < pEndSrcBuf )
59 : : {
60 [ - + ]: 34460 : if ( pDestBuf == pEndDestBuf )
61 : : {
62 : 0 : *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL;
63 : 0 : break;
64 : : }
65 : :
66 : 34460 : *pDestBuf = (sal_Unicode)(sal_uChar)*pSrcBuf;
67 : 34460 : pDestBuf++;
68 : 34460 : pSrcBuf++;
69 : : }
70 : :
71 : 3085 : *pSrcCvtBytes = nSrcBytes - (pEndSrcBuf-pSrcBuf);
72 : 3085 : return (nDestChars - (pEndDestBuf-pDestBuf));
73 : : }
74 : :
75 : : /* ----------------------------------------------------------------------- */
76 : :
77 : 540 : static sal_Size ImplUnicodeToDummy( const sal_Unicode* pSrcBuf, sal_Size nSrcChars,
78 : : char* pDestBuf, sal_Size nDestBytes,
79 : : sal_uInt32 nFlags, sal_uInt32* pInfo,
80 : : sal_Size* pSrcCvtChars )
81 : : {
82 : : char* pEndDestBuf;
83 : : const sal_Unicode* pEndSrcBuf;
84 : :
85 [ - + ]: 540 : if ( ((nFlags & RTL_UNICODETOTEXT_FLAGS_UNDEFINED_MASK) == RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR) )
86 : : {
87 : : *pInfo |= RTL_UNICODETOTEXT_INFO_ERROR |
88 : 0 : RTL_UNICODETOTEXT_INFO_UNDEFINED;
89 : 0 : return 0;
90 : : }
91 : :
92 : 540 : *pInfo = 0;
93 : 540 : pEndDestBuf = pDestBuf+nDestBytes;
94 : 540 : pEndSrcBuf = pSrcBuf+nSrcChars;
95 [ + + ]: 2695 : while ( pSrcBuf < pEndSrcBuf )
96 : : {
97 [ - + ]: 2155 : if ( pDestBuf == pEndDestBuf )
98 : : {
99 : 0 : *pInfo |= RTL_UNICODETOTEXT_INFO_ERROR | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
100 : 0 : break;
101 : : }
102 : :
103 : 2155 : *pDestBuf = (char)(sal_uChar)(*pSrcBuf & 0x00FF);
104 : 2155 : pDestBuf++;
105 : 2155 : pSrcBuf++;
106 : : }
107 : :
108 : 540 : *pSrcCvtChars = nSrcChars - (pEndSrcBuf-pSrcBuf);
109 : 540 : return (nDestBytes - (pEndDestBuf-pDestBuf));
110 : : }
111 : :
112 : : /* ======================================================================= */
113 : :
114 : 1338733 : rtl_TextToUnicodeConverter SAL_CALL rtl_createTextToUnicodeConverter( rtl_TextEncoding eTextEncoding )
115 : : {
116 : 1338733 : const ImplTextEncodingData* pData = Impl_getTextEncodingData( eTextEncoding );
117 [ + + ]: 1338733 : if ( pData )
118 : 1335648 : return (rtl_TextToUnicodeConverter) &pData->maConverter;
119 : : else
120 : 1338733 : return 0;
121 : : }
122 : :
123 : : /* ----------------------------------------------------------------------- */
124 : :
125 : 2499477 : void SAL_CALL rtl_destroyTextToUnicodeConverter(
126 : : SAL_UNUSED_PARAMETER rtl_TextToUnicodeConverter )
127 : 2499477 : {}
128 : :
129 : : /* ----------------------------------------------------------------------- */
130 : :
131 : 1290 : rtl_TextToUnicodeContext SAL_CALL rtl_createTextToUnicodeContext( rtl_TextToUnicodeConverter hConverter )
132 : : {
133 : 1290 : const ImplTextConverter* pConverter = (const ImplTextConverter*)hConverter;
134 [ - + ]: 1290 : if ( !pConverter )
135 : 0 : return 0;
136 [ + + ]: 1290 : else if ( pConverter->mpCreateTextToUnicodeContext )
137 : 1146 : return (rtl_TextToUnicodeContext)pConverter->mpCreateTextToUnicodeContext();
138 : : else
139 : 1290 : return (rtl_TextToUnicodeContext)1;
140 : : }
141 : :
142 : : /* ----------------------------------------------------------------------- */
143 : :
144 : 1166 : void SAL_CALL rtl_destroyTextToUnicodeContext( rtl_TextToUnicodeConverter hConverter,
145 : : rtl_TextToUnicodeContext hContext )
146 : : {
147 : 1166 : const ImplTextConverter* pConverter = (const ImplTextConverter*)hConverter;
148 [ + - ][ + - ]: 1166 : if ( pConverter && hContext && pConverter->mpDestroyTextToUnicodeContext )
[ + + ]
149 : 1146 : pConverter->mpDestroyTextToUnicodeContext( hContext );
150 : 1166 : }
151 : :
152 : : /* ----------------------------------------------------------------------- */
153 : :
154 : 0 : void SAL_CALL rtl_resetTextToUnicodeContext( rtl_TextToUnicodeConverter hConverter,
155 : : rtl_TextToUnicodeContext hContext )
156 : : {
157 : 0 : const ImplTextConverter* pConverter = (const ImplTextConverter*)hConverter;
158 [ # # ][ # # ]: 0 : if ( pConverter && hContext && pConverter->mpResetTextToUnicodeContext )
[ # # ]
159 : 0 : pConverter->mpResetTextToUnicodeContext( hContext );
160 : 0 : }
161 : :
162 : : /* ----------------------------------------------------------------------- */
163 : :
164 : 2287454 : sal_Size SAL_CALL rtl_convertTextToUnicode( rtl_TextToUnicodeConverter hConverter,
165 : : rtl_TextToUnicodeContext hContext,
166 : : const char* pSrcBuf, sal_Size nSrcBytes,
167 : : sal_Unicode* pDestBuf, sal_Size nDestChars,
168 : : sal_uInt32 nFlags, sal_uInt32* pInfo,
169 : : sal_Size* pSrcCvtBytes )
170 : : {
171 : 2287454 : const ImplTextConverter* pConverter = (const ImplTextConverter*)hConverter;
172 : :
173 : : /* Only temporaer, because we don't want die, if we don't have a
174 : : converter, because not all converters are implemented yet */
175 [ + + ]: 2287454 : if ( !pConverter )
176 : : {
177 : : return ImplDummyToUnicode( pSrcBuf, nSrcBytes,
178 : : pDestBuf, nDestChars,
179 : 3085 : nFlags, pInfo, pSrcCvtBytes );
180 : : }
181 : :
182 : : return pConverter->mpConvertTextToUnicodeProc( pConverter->mpConvertData,
183 : : hContext,
184 : : pSrcBuf, nSrcBytes,
185 : : pDestBuf, nDestChars,
186 : : nFlags, pInfo,
187 : 2287454 : pSrcCvtBytes );
188 : : }
189 : :
190 : : /* ======================================================================= */
191 : :
192 : 642378 : rtl_UnicodeToTextConverter SAL_CALL rtl_createUnicodeToTextConverter( rtl_TextEncoding eTextEncoding )
193 : : {
194 : 642378 : const ImplTextEncodingData* pData = Impl_getTextEncodingData( eTextEncoding );
195 [ + + ]: 642379 : if ( pData )
196 : 641839 : return (rtl_TextToUnicodeConverter) &pData->maConverter;
197 : : else
198 : 642379 : return 0;
199 : : }
200 : :
201 : : /* ----------------------------------------------------------------------- */
202 : :
203 : 569009 : void SAL_CALL rtl_destroyUnicodeToTextConverter(
204 : : SAL_UNUSED_PARAMETER rtl_UnicodeToTextConverter )
205 : 569009 : {}
206 : :
207 : : /* ----------------------------------------------------------------------- */
208 : :
209 : 20 : rtl_UnicodeToTextContext SAL_CALL rtl_createUnicodeToTextContext( rtl_UnicodeToTextConverter hConverter )
210 : : {
211 : 20 : const ImplTextConverter* pConverter = (const ImplTextConverter*)hConverter;
212 [ - + ]: 20 : if ( !pConverter )
213 : 0 : return 0;
214 [ + - ]: 20 : else if ( pConverter->mpCreateUnicodeToTextContext )
215 : 20 : return (rtl_UnicodeToTextContext)pConverter->mpCreateUnicodeToTextContext();
216 : : else
217 : 20 : return (rtl_UnicodeToTextContext)1;
218 : : }
219 : :
220 : : /* ----------------------------------------------------------------------- */
221 : :
222 : 144 : void SAL_CALL rtl_destroyUnicodeToTextContext( rtl_UnicodeToTextConverter hConverter,
223 : : rtl_UnicodeToTextContext hContext )
224 : : {
225 : 144 : const ImplTextConverter* pConverter = (const ImplTextConverter*)hConverter;
226 [ + - ][ + - ]: 144 : if ( pConverter && hContext && pConverter->mpDestroyUnicodeToTextContext )
[ + + ]
227 : 20 : pConverter->mpDestroyUnicodeToTextContext( hContext );
228 : 144 : }
229 : :
230 : : /* ----------------------------------------------------------------------- */
231 : :
232 : 0 : void SAL_CALL rtl_resetUnicodeToTextContext( rtl_UnicodeToTextConverter hConverter,
233 : : rtl_UnicodeToTextContext hContext )
234 : : {
235 : 0 : const ImplTextConverter* pConverter = (const ImplTextConverter*)hConverter;
236 [ # # ][ # # ]: 0 : if ( pConverter && hContext && pConverter->mpResetUnicodeToTextContext )
[ # # ]
237 : 0 : pConverter->mpResetUnicodeToTextContext( hContext );
238 : 0 : }
239 : :
240 : : /* ----------------------------------------------------------------------- */
241 : :
242 : 2331766 : sal_Size SAL_CALL rtl_convertUnicodeToText( rtl_UnicodeToTextConverter hConverter,
243 : : rtl_UnicodeToTextContext hContext,
244 : : const sal_Unicode* pSrcBuf, sal_Size nSrcChars,
245 : : char* pDestBuf, sal_Size nDestBytes,
246 : : sal_uInt32 nFlags, sal_uInt32* pInfo,
247 : : sal_Size* pSrcCvtChars )
248 : : {
249 : 2331766 : const ImplTextConverter* pConverter = (const ImplTextConverter*)hConverter;
250 : :
251 : : /* Only temporaer, because we don't want die, if we don't have a
252 : : converter, because not all converters are implemented yet */
253 [ + + ]: 2331766 : if ( !pConverter )
254 : : {
255 : : return ImplUnicodeToDummy( pSrcBuf, nSrcChars,
256 : : pDestBuf, nDestBytes,
257 : 540 : nFlags, pInfo, pSrcCvtChars );
258 : : }
259 : :
260 : : return pConverter->mpConvertUnicodeToTextProc( pConverter->mpConvertData,
261 : : hContext,
262 : : pSrcBuf, nSrcChars,
263 : : pDestBuf, nDestBytes,
264 : : nFlags, pInfo,
265 : 2331766 : pSrcCvtChars );
266 : : }
267 : :
268 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|