1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <sal/config.h>
12 #include <rtl/character.hxx>
13 #include <rtl/textcvt.h>
14 #include <sal/types.h>
16 #include "handleundefinedunicodetotextchar.hxx"
17 #include "tenchelp.hxx"
21 bool ImplIsUnicodeIgnoreChar(sal_Unicode c
, sal_uInt32 nFlags
)
24 ((nFlags
& RTL_UNICODETOTEXT_FLAGS_NONSPACING_IGNORE
) != 0
25 && ImplIsZeroWidth(c
))
26 || ((nFlags
& RTL_UNICODETOTEXT_FLAGS_CONTROL_IGNORE
) != 0
27 && ImplIsControlOrFormat(c
))
28 || ((nFlags
& RTL_UNICODETOTEXT_FLAGS_PRIVATE_IGNORE
) != 0
29 && ImplIsPrivateUse(c
));
32 bool ImplGetUndefinedAsciiMultiByte(sal_uInt32 nFlags
,
38 switch (nFlags
& RTL_UNICODETOTEXT_FLAGS_UNDEFINED_MASK
)
40 case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_0
:
44 case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_QUESTIONMARK
:
45 default: /* RTL_UNICODETOTEXT_FLAGS_UNDEFINED_DEFAULT */
49 case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_UNDERLINE
:
56 bool ImplGetInvalidAsciiMultiByte(sal_uInt32 nFlags
,
62 switch (nFlags
& RTL_UNICODETOTEXT_FLAGS_INVALID_MASK
)
64 case RTL_UNICODETOTEXT_FLAGS_INVALID_0
:
68 case RTL_UNICODETOTEXT_FLAGS_INVALID_QUESTIONMARK
:
69 default: /* RTL_UNICODETOTEXT_FLAGS_INVALID_DEFAULT */
73 case RTL_UNICODETOTEXT_FLAGS_INVALID_UNDERLINE
:
82 bool sal::detail::textenc::handleUndefinedUnicodeToTextChar(
83 sal_Unicode
const ** ppSrcBuf
, sal_Unicode
const * pEndSrcBuf
,
84 char ** ppDestBuf
, char const * pEndDestBuf
, sal_uInt32 nFlags
,
87 sal_Unicode c
= **ppSrcBuf
;
89 /* Should the private character map to one byte */
90 if ( (c
>= RTL_TEXTCVT_BYTE_PRIVATE_START
) && (c
<= RTL_TEXTCVT_BYTE_PRIVATE_END
) )
92 if ( nFlags
& RTL_UNICODETOTEXT_FLAGS_PRIVATE_MAPTO0
)
94 **ppDestBuf
= static_cast<char>(static_cast<unsigned char>(c
-RTL_TEXTCVT_BYTE_PRIVATE_START
));
101 /* Should this character ignored (Private, Non Spacing, Control) */
102 if ( ImplIsUnicodeIgnoreChar( c
, nFlags
) )
108 /* Surrogates Characters should result in */
109 /* one replacement character */
110 if (rtl::isHighSurrogate(c
))
112 if ( ((*ppSrcBuf
) + 1) == pEndSrcBuf
)
114 *pInfo
|= RTL_UNICODETOTEXT_INFO_ERROR
| RTL_UNICODETOTEXT_INFO_SRCBUFFERTOSMALL
;
118 c
= *((*ppSrcBuf
)+1);
119 if (rtl::isLowSurrogate(c
))
123 *pInfo
|= RTL_UNICODETOTEXT_INFO_INVALID
;
124 if ( (nFlags
& RTL_UNICODETOTEXT_FLAGS_INVALID_MASK
) == RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
)
126 *pInfo
|= RTL_UNICODETOTEXT_INFO_ERROR
;
129 if ( (nFlags
& RTL_UNICODETOTEXT_FLAGS_INVALID_MASK
) == RTL_UNICODETOTEXT_FLAGS_INVALID_IGNORE
)
134 if (ImplGetInvalidAsciiMultiByte(nFlags
,
136 pEndDestBuf
- *ppDestBuf
))
142 *pInfo
|= RTL_UNICODETOTEXT_INFO_ERROR
| RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL
;
147 *pInfo
|= RTL_UNICODETOTEXT_INFO_UNDEFINED
;
148 if ( (nFlags
& RTL_UNICODETOTEXT_FLAGS_UNDEFINED_MASK
) == RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
)
150 *pInfo
|= RTL_UNICODETOTEXT_INFO_ERROR
;
153 if ( (nFlags
& RTL_UNICODETOTEXT_FLAGS_UNDEFINED_MASK
) == RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE
)
155 else if (ImplGetUndefinedAsciiMultiByte(nFlags
,
157 pEndDestBuf
- *ppDestBuf
))
164 *pInfo
|= RTL_UNICODETOTEXT_INFO_ERROR
165 | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL
;
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */