Fix of accessibility warnings for the additions dialog
[LibreOffice.git] / sal / textenc / textcvt.cxx
blob2d5add0a89e4e7288c03a66a68270c41298587e6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <cassert>
24 #include <rtl/textcvt.h>
25 #include <sal/log.hxx>
27 #include "gettextencodingdata.hxx"
28 #include "tenchelp.hxx"
30 /* ======================================================================= */
32 static sal_Size ImplDummyToUnicode( const char* pSrcBuf, sal_Size nSrcBytes,
33 sal_Unicode* pDestBuf, sal_Size nDestChars,
34 sal_uInt32 nFlags, sal_uInt32* pInfo,
35 sal_Size* pSrcCvtBytes )
37 sal_Unicode* pEndDestBuf;
38 const char* pEndSrcBuf;
40 if ( ((nFlags & RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MASK) == RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR) ||
41 ((nFlags & RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_MASK) == RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR) )
43 *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR |
44 RTL_TEXTTOUNICODE_INFO_UNDEFINED |
45 RTL_TEXTTOUNICODE_INFO_MBUNDEFINED;
46 return 0;
49 *pInfo = 0;
50 pEndDestBuf = pDestBuf+nDestChars;
51 pEndSrcBuf = pSrcBuf+nSrcBytes;
52 while ( pSrcBuf < pEndSrcBuf )
54 if ( pDestBuf == pEndDestBuf )
56 *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOOSMALL;
57 break;
60 *pDestBuf = static_cast<sal_Unicode>(static_cast<unsigned char>(*pSrcBuf));
61 pDestBuf++;
62 pSrcBuf++;
65 *pSrcCvtBytes = nSrcBytes - (pEndSrcBuf-pSrcBuf);
66 return (nDestChars - (pEndDestBuf-pDestBuf));
69 /* ----------------------------------------------------------------------- */
71 static sal_Size ImplUnicodeToDummy( const sal_Unicode* pSrcBuf, sal_Size nSrcChars,
72 char* pDestBuf, sal_Size nDestBytes,
73 sal_uInt32 nFlags, sal_uInt32* pInfo,
74 sal_Size* pSrcCvtChars )
76 char* pEndDestBuf;
77 const sal_Unicode* pEndSrcBuf;
79 if ( (nFlags & RTL_UNICODETOTEXT_FLAGS_UNDEFINED_MASK) == RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR )
81 *pInfo |= RTL_UNICODETOTEXT_INFO_ERROR |
82 RTL_UNICODETOTEXT_INFO_UNDEFINED;
83 return 0;
86 *pInfo = 0;
87 pEndDestBuf = pDestBuf+nDestBytes;
88 pEndSrcBuf = pSrcBuf+nSrcChars;
89 while ( pSrcBuf < pEndSrcBuf )
91 if ( pDestBuf == pEndDestBuf )
93 *pInfo |= RTL_UNICODETOTEXT_INFO_ERROR | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
94 break;
97 *pDestBuf = static_cast<char>(static_cast<unsigned char>(*pSrcBuf & 0x00FF));
98 pDestBuf++;
99 pSrcBuf++;
102 *pSrcCvtChars = nSrcChars - (pEndSrcBuf-pSrcBuf);
103 return (nDestBytes - (pEndDestBuf-pDestBuf));
106 /* ======================================================================= */
108 rtl_TextToUnicodeConverter SAL_CALL rtl_createTextToUnicodeConverter( rtl_TextEncoding eTextEncoding )
110 const ImplTextEncodingData* pData = Impl_getTextEncodingData( eTextEncoding );
111 if ( pData )
112 return static_cast<rtl_TextToUnicodeConverter>(const_cast<ImplTextConverter *>(&pData->maConverter));
113 return nullptr;
116 /* ----------------------------------------------------------------------- */
118 void SAL_CALL rtl_destroyTextToUnicodeConverter(
119 SAL_UNUSED_PARAMETER rtl_TextToUnicodeConverter )
122 /* ----------------------------------------------------------------------- */
124 rtl_TextToUnicodeContext SAL_CALL rtl_createTextToUnicodeContext( rtl_TextToUnicodeConverter hConverter )
126 const ImplTextConverter* pConverter = static_cast<const ImplTextConverter*>(hConverter);
127 if ( !pConverter )
128 return nullptr;
129 if ( pConverter->mpCreateTextToUnicodeContext )
130 return pConverter->mpCreateTextToUnicodeContext();
131 return reinterpret_cast<rtl_TextToUnicodeContext>(1);
134 /* ----------------------------------------------------------------------- */
136 void SAL_CALL rtl_destroyTextToUnicodeContext( rtl_TextToUnicodeConverter hConverter,
137 rtl_TextToUnicodeContext hContext )
139 const ImplTextConverter* pConverter = static_cast<const ImplTextConverter*>(hConverter);
140 if ( pConverter && hContext && pConverter->mpDestroyTextToUnicodeContext )
141 pConverter->mpDestroyTextToUnicodeContext( hContext );
144 /* ----------------------------------------------------------------------- */
146 void SAL_CALL rtl_resetTextToUnicodeContext( rtl_TextToUnicodeConverter hConverter,
147 rtl_TextToUnicodeContext hContext )
149 const ImplTextConverter* pConverter = static_cast<const ImplTextConverter*>(hConverter);
150 if ( pConverter && hContext && pConverter->mpResetTextToUnicodeContext )
151 pConverter->mpResetTextToUnicodeContext( hContext );
154 /* ----------------------------------------------------------------------- */
156 sal_Size SAL_CALL rtl_convertTextToUnicode( rtl_TextToUnicodeConverter hConverter,
157 rtl_TextToUnicodeContext hContext,
158 const char* pSrcBuf, sal_Size nSrcBytes,
159 sal_Unicode* pDestBuf, sal_Size nDestChars,
160 sal_uInt32 nFlags, sal_uInt32* pInfo,
161 sal_Size* pSrcCvtBytes )
163 assert(
164 (nFlags & RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MASK)
165 <= RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_DEFAULT);
166 assert(
167 (nFlags & RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_MASK)
168 <= RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_DEFAULT);
169 assert(
170 (nFlags & RTL_TEXTTOUNICODE_FLAGS_INVALID_MASK)
171 <= RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT);
172 assert(
173 (nFlags
174 & ~(RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MASK
175 | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_MASK
176 | RTL_TEXTTOUNICODE_FLAGS_INVALID_MASK
177 | RTL_TEXTTOUNICODE_FLAGS_FLUSH
178 | RTL_TEXTTOUNICODE_FLAGS_GLOBAL_SIGNATURE))
179 == 0);
181 const ImplTextConverter* pConverter = static_cast<const ImplTextConverter*>(hConverter);
183 /* Only temporary, because we don't want die, if we don't have a
184 converter, because not all converters are implemented yet */
185 if ( !pConverter )
187 SAL_WARN("sal.textenc", "Missing rtl_TextToUnicodeConverter");
188 return ImplDummyToUnicode( pSrcBuf, nSrcBytes,
189 pDestBuf, nDestChars,
190 nFlags, pInfo, pSrcCvtBytes );
193 return pConverter->mpConvertTextToUnicodeProc( pConverter->mpConvertData,
194 hContext,
195 pSrcBuf, nSrcBytes,
196 pDestBuf, nDestChars,
197 nFlags, pInfo,
198 pSrcCvtBytes );
201 /* ======================================================================= */
203 rtl_UnicodeToTextConverter SAL_CALL rtl_createUnicodeToTextConverter( rtl_TextEncoding eTextEncoding )
205 const ImplTextEncodingData* pData = Impl_getTextEncodingData( eTextEncoding );
206 if ( pData )
207 return static_cast<rtl_TextToUnicodeConverter>(const_cast<ImplTextConverter *>(&pData->maConverter));
208 return nullptr;
211 /* ----------------------------------------------------------------------- */
213 void SAL_CALL rtl_destroyUnicodeToTextConverter(
214 SAL_UNUSED_PARAMETER rtl_UnicodeToTextConverter )
217 /* ----------------------------------------------------------------------- */
219 rtl_UnicodeToTextContext SAL_CALL rtl_createUnicodeToTextContext( rtl_UnicodeToTextConverter hConverter )
221 const ImplTextConverter* pConverter = static_cast<const ImplTextConverter*>(hConverter);
222 if ( !pConverter )
223 return nullptr;
224 if ( pConverter->mpCreateUnicodeToTextContext )
225 return pConverter->mpCreateUnicodeToTextContext();
226 return reinterpret_cast<rtl_UnicodeToTextContext>(1);
229 /* ----------------------------------------------------------------------- */
231 void SAL_CALL rtl_destroyUnicodeToTextContext( rtl_UnicodeToTextConverter hConverter,
232 rtl_UnicodeToTextContext hContext )
234 const ImplTextConverter* pConverter = static_cast<const ImplTextConverter*>(hConverter);
235 if ( pConverter && hContext && pConverter->mpDestroyUnicodeToTextContext )
236 pConverter->mpDestroyUnicodeToTextContext( hContext );
239 /* ----------------------------------------------------------------------- */
241 void SAL_CALL rtl_resetUnicodeToTextContext( rtl_UnicodeToTextConverter hConverter,
242 rtl_UnicodeToTextContext hContext )
244 const ImplTextConverter* pConverter = static_cast<const ImplTextConverter*>(hConverter);
245 if ( pConverter && hContext && pConverter->mpResetUnicodeToTextContext )
246 pConverter->mpResetUnicodeToTextContext( hContext );
249 /* ----------------------------------------------------------------------- */
251 sal_Size SAL_CALL rtl_convertUnicodeToText( rtl_UnicodeToTextConverter hConverter,
252 rtl_UnicodeToTextContext hContext,
253 const sal_Unicode* pSrcBuf, sal_Size nSrcChars,
254 char* pDestBuf, sal_Size nDestBytes,
255 sal_uInt32 nFlags, sal_uInt32* pInfo,
256 sal_Size* pSrcCvtChars )
258 assert(
259 (nFlags & RTL_UNICODETOTEXT_FLAGS_UNDEFINED_MASK)
260 <= RTL_UNICODETOTEXT_FLAGS_UNDEFINED_DEFAULT);
261 assert(
262 (nFlags & RTL_UNICODETOTEXT_FLAGS_INVALID_MASK)
263 <= RTL_UNICODETOTEXT_FLAGS_INVALID_DEFAULT);
264 assert(
265 (nFlags
266 & ~(RTL_UNICODETOTEXT_FLAGS_UNDEFINED_MASK
267 | RTL_UNICODETOTEXT_FLAGS_INVALID_MASK
268 | RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACE
269 | RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACESTR
270 | RTL_UNICODETOTEXT_FLAGS_PRIVATE_MAPTO0
271 | RTL_UNICODETOTEXT_FLAGS_NONSPACING_IGNORE
272 | RTL_UNICODETOTEXT_FLAGS_CONTROL_IGNORE
273 | RTL_UNICODETOTEXT_FLAGS_PRIVATE_IGNORE
274 | RTL_UNICODETOTEXT_FLAGS_NOCOMPOSITE
275 | RTL_UNICODETOTEXT_FLAGS_FLUSH
276 | RTL_UNICODETOTEXT_FLAGS_GLOBAL_SIGNATURE))
277 == 0);
279 const ImplTextConverter* pConverter = static_cast<const ImplTextConverter*>(hConverter);
281 /* Only temporary, because we don't want die, if we don't have a
282 converter, because not all converters are implemented yet */
283 if ( !pConverter )
285 SAL_WARN("sal.textenc", "Missing rtl_UnicodeToTextConverter");
286 return ImplUnicodeToDummy( pSrcBuf, nSrcChars,
287 pDestBuf, nDestBytes,
288 nFlags, pInfo, pSrcCvtChars );
291 return pConverter->mpConvertUnicodeToTextProc( pConverter->mpConvertData,
292 hContext,
293 pSrcBuf, nSrcChars,
294 pDestBuf, nDestBytes,
295 nFlags, pInfo,
296 pSrcCvtChars );
299 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */