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/textcvt.h"
13 #include "sal/types.h"
15 #include "handleundefinedunicodetotextchar.hxx"
16 #include "tenchelp.hxx"
20 bool ImplIsUnicodeIgnoreChar(sal_Unicode c
, sal_uInt32 nFlags
)
23 ((nFlags
& RTL_UNICODETOTEXT_FLAGS_NONSPACING_IGNORE
) != 0
24 && ImplIsZeroWidth(c
))
25 || ((nFlags
& RTL_UNICODETOTEXT_FLAGS_CONTROL_IGNORE
) != 0
26 && ImplIsControlOrFormat(c
))
27 || ((nFlags
& RTL_UNICODETOTEXT_FLAGS_PRIVATE_IGNORE
) != 0
28 && ImplIsPrivateUse(c
));
31 bool ImplGetUndefinedAsciiMultiByte(sal_uInt32 nFlags
,
37 switch (nFlags
& RTL_UNICODETOTEXT_FLAGS_UNDEFINED_MASK
)
39 case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_0
:
43 case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_QUESTIONMARK
:
44 default: /* RTL_UNICODETOTEXT_FLAGS_UNDEFINED_DEFAULT */
48 case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_UNDERLINE
:
55 bool ImplGetInvalidAsciiMultiByte(sal_uInt32 nFlags
,
61 switch (nFlags
& RTL_UNICODETOTEXT_FLAGS_INVALID_MASK
)
63 case RTL_UNICODETOTEXT_FLAGS_INVALID_0
:
67 case RTL_UNICODETOTEXT_FLAGS_INVALID_QUESTIONMARK
:
68 default: /* RTL_UNICODETOTEXT_FLAGS_INVALID_DEFAULT */
72 case RTL_UNICODETOTEXT_FLAGS_INVALID_UNDERLINE
:
81 bool sal::detail::textenc::handleUndefinedUnicodeToTextChar(
82 sal_Unicode
const ** ppSrcBuf
, sal_Unicode
const * pEndSrcBuf
,
83 char ** ppDestBuf
, char const * pEndDestBuf
, sal_uInt32 nFlags
,
86 sal_Unicode c
= **ppSrcBuf
;
88 /* Should the private character map to one byte */
89 if ( (c
>= RTL_TEXTCVT_BYTE_PRIVATE_START
) && (c
<= RTL_TEXTCVT_BYTE_PRIVATE_END
) )
91 if ( nFlags
& RTL_UNICODETOTEXT_FLAGS_PRIVATE_MAPTO0
)
93 **ppDestBuf
= (char)(unsigned char)(c
-RTL_TEXTCVT_BYTE_PRIVATE_START
);
100 /* Should this character ignored (Private, Non Spacing, Control) */
101 if ( ImplIsUnicodeIgnoreChar( c
, nFlags
) )
107 /* Surrogates Characters should result in */
108 /* one replacement character */
109 if (ImplIsHighSurrogate(c
))
111 if ( ((*ppSrcBuf
) + 1) == pEndSrcBuf
)
113 *pInfo
|= RTL_UNICODETOTEXT_INFO_ERROR
| RTL_UNICODETOTEXT_INFO_SRCBUFFERTOSMALL
;
117 c
= *((*ppSrcBuf
)+1);
118 if (ImplIsLowSurrogate(c
))
122 *pInfo
|= RTL_UNICODETOTEXT_INFO_INVALID
;
123 if ( (nFlags
& RTL_UNICODETOTEXT_FLAGS_INVALID_MASK
) == RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
)
125 *pInfo
|= RTL_UNICODETOTEXT_INFO_ERROR
;
128 else if ( (nFlags
& RTL_UNICODETOTEXT_FLAGS_INVALID_MASK
) == RTL_UNICODETOTEXT_FLAGS_INVALID_IGNORE
)
133 else if (ImplGetInvalidAsciiMultiByte(nFlags
,
135 pEndDestBuf
- *ppDestBuf
))
143 *pInfo
|= RTL_UNICODETOTEXT_INFO_ERROR
144 | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL
;
150 *pInfo
|= RTL_UNICODETOTEXT_INFO_UNDEFINED
;
151 if ( (nFlags
& RTL_UNICODETOTEXT_FLAGS_UNDEFINED_MASK
) == RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
)
153 *pInfo
|= RTL_UNICODETOTEXT_INFO_ERROR
;
156 else if ( (nFlags
& RTL_UNICODETOTEXT_FLAGS_UNDEFINED_MASK
) == RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE
)
158 else if (ImplGetUndefinedAsciiMultiByte(nFlags
,
160 pEndDestBuf
- *ppDestBuf
))
167 *pInfo
|= RTL_UNICODETOTEXT_INFO_ERROR
168 | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL
;
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */