1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * Version: MPL 1.1 / GPLv3+ / LGPLv3+
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License or as specified alternatively below. You may obtain a copy of
8 * the License at http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * Major Contributor(s):
16 * [ Copyright (C) 2012 Red Hat, Inc., Stephan Bergmann <sbergman@redhat.com>
17 * (initial developer) ]
19 * All Rights Reserved.
21 * For minor contributions see the git repository.
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
25 * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
26 * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
27 * instead of those above.
30 #include "sal/config.h"
32 #include "rtl/textcvt.h"
33 #include "sal/types.h"
35 #include "handleundefinedunicodetotextchar.hxx"
36 #include "tenchelp.hxx"
40 bool ImplIsUnicodeIgnoreChar(sal_Unicode c
, sal_uInt32 nFlags
)
43 ((nFlags
& RTL_UNICODETOTEXT_FLAGS_NONSPACING_IGNORE
) != 0
44 && ImplIsZeroWidth(c
))
45 || ((nFlags
& RTL_UNICODETOTEXT_FLAGS_CONTROL_IGNORE
) != 0
46 && ImplIsControlOrFormat(c
))
47 || ((nFlags
& RTL_UNICODETOTEXT_FLAGS_PRIVATE_IGNORE
) != 0
48 && ImplIsPrivateUse(c
));
51 bool ImplGetUndefinedAsciiMultiByte(sal_uInt32 nFlags
,
57 switch (nFlags
& RTL_UNICODETOTEXT_FLAGS_UNDEFINED_MASK
)
59 case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_0
:
63 case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_QUESTIONMARK
:
64 default: /* RTL_UNICODETOTEXT_FLAGS_UNDEFINED_DEFAULT */
68 case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_UNDERLINE
:
75 bool ImplGetInvalidAsciiMultiByte(sal_uInt32 nFlags
,
81 switch (nFlags
& RTL_UNICODETOTEXT_FLAGS_UNDEFINED_MASK
)
83 case RTL_UNICODETOTEXT_FLAGS_INVALID_0
:
87 case RTL_UNICODETOTEXT_FLAGS_INVALID_QUESTIONMARK
:
88 default: /* RTL_UNICODETOTEXT_FLAGS_INVALID_DEFAULT */
92 case RTL_UNICODETOTEXT_FLAGS_INVALID_UNDERLINE
:
101 bool sal::detail::textenc::handleUndefinedUnicodeToTextChar(
102 sal_Unicode
const ** ppSrcBuf
, sal_Unicode
const * pEndSrcBuf
,
103 char ** ppDestBuf
, char const * pEndDestBuf
, sal_uInt32 nFlags
,
106 sal_Unicode c
= **ppSrcBuf
;
108 /* Should the private character map to one byte */
109 if ( (c
>= RTL_TEXTCVT_BYTE_PRIVATE_START
) && (c
<= RTL_TEXTCVT_BYTE_PRIVATE_END
) )
111 if ( nFlags
& RTL_UNICODETOTEXT_FLAGS_PRIVATE_MAPTO0
)
113 **ppDestBuf
= (char)(sal_uChar
)(c
-RTL_TEXTCVT_BYTE_PRIVATE_START
);
120 /* Should this character ignored (Private, Non Spacing, Control) */
121 if ( ImplIsUnicodeIgnoreChar( c
, nFlags
) )
127 /* Surrogates Characters should result in */
128 /* one replacement character */
129 if (ImplIsHighSurrogate(c
))
131 if ( *ppSrcBuf
== pEndSrcBuf
)
133 *pInfo
|= RTL_UNICODETOTEXT_INFO_ERROR
| RTL_UNICODETOTEXT_INFO_SRCBUFFERTOSMALL
;
137 c
= *((*ppSrcBuf
)+1);
138 if (ImplIsLowSurrogate(c
))
142 *pInfo
|= RTL_UNICODETOTEXT_INFO_INVALID
;
143 if ( (nFlags
& RTL_UNICODETOTEXT_FLAGS_INVALID_MASK
) == RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
)
145 *pInfo
|= RTL_UNICODETOTEXT_INFO_ERROR
;
148 else if ( (nFlags
& RTL_UNICODETOTEXT_FLAGS_INVALID_MASK
) == RTL_UNICODETOTEXT_FLAGS_INVALID_IGNORE
)
153 else if (ImplGetInvalidAsciiMultiByte(nFlags
,
155 pEndDestBuf
- *ppDestBuf
))
163 *pInfo
|= RTL_UNICODETOTEXT_INFO_ERROR
164 | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL
;
170 *pInfo
|= RTL_UNICODETOTEXT_INFO_UNDEFINED
;
171 if ( (nFlags
& RTL_UNICODETOTEXT_FLAGS_UNDEFINED_MASK
) == RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
)
173 *pInfo
|= RTL_UNICODETOTEXT_INFO_ERROR
;
176 else if ( (nFlags
& RTL_UNICODETOTEXT_FLAGS_UNDEFINED_MASK
) == RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE
)
178 else if (ImplGetUndefinedAsciiMultiByte(nFlags
,
180 pEndDestBuf
- *ppDestBuf
))
187 *pInfo
|= RTL_UNICODETOTEXT_INFO_ERROR
188 | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL
;