1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tenchelp.c,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 #include "rtl/textcvt.h"
34 #include "sal/types.h"
36 static sal_Bool
ImplGetUndefinedAsciiMultiByte(sal_uInt32 nFlags
,
40 static sal_Bool
ImplGetInvalidAsciiMultiByte(sal_uInt32 nFlags
,
44 static int ImplIsUnicodeIgnoreChar(sal_Unicode c
, sal_uInt32 nFlags
);
46 sal_Bool
ImplGetUndefinedAsciiMultiByte(sal_uInt32 nFlags
,
52 switch (nFlags
& RTL_UNICODETOTEXT_FLAGS_UNDEFINED_MASK
)
54 case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_0
:
58 case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_QUESTIONMARK
:
59 default: /* RTL_UNICODETOTEXT_FLAGS_UNDEFINED_DEFAULT */
63 case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_UNDERLINE
:
70 sal_Bool
ImplGetInvalidAsciiMultiByte(sal_uInt32 nFlags
,
76 switch (nFlags
& RTL_UNICODETOTEXT_FLAGS_UNDEFINED_MASK
)
78 case RTL_UNICODETOTEXT_FLAGS_INVALID_0
:
82 case RTL_UNICODETOTEXT_FLAGS_INVALID_QUESTIONMARK
:
83 default: /* RTL_UNICODETOTEXT_FLAGS_INVALID_DEFAULT */
87 case RTL_UNICODETOTEXT_FLAGS_INVALID_UNDERLINE
:
94 int ImplIsUnicodeIgnoreChar( sal_Unicode c
, sal_uInt32 nFlags
)
97 ((nFlags
& RTL_UNICODETOTEXT_FLAGS_NONSPACING_IGNORE
) != 0
98 && ImplIsZeroWidth(c
))
99 || ((nFlags
& RTL_UNICODETOTEXT_FLAGS_CONTROL_IGNORE
) != 0
100 && ImplIsControlOrFormat(c
))
101 || ((nFlags
& RTL_UNICODETOTEXT_FLAGS_PRIVATE_IGNORE
) != 0
102 && ImplIsPrivateUse(c
));
105 /* ======================================================================= */
107 sal_Unicode
ImplGetUndefinedUnicodeChar(sal_uChar cChar
, sal_uInt32 nFlags
)
109 return ((nFlags
& RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MASK
)
110 == RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MAPTOPRIVATE
) ?
111 RTL_TEXTCVT_BYTE_PRIVATE_START
+ cChar
:
112 RTL_TEXTENC_UNICODE_REPLACEMENT_CHARACTER
;
115 /* ----------------------------------------------------------------------- */
118 ImplHandleUndefinedUnicodeToTextChar(ImplTextConverterData
const * pData
,
119 sal_Unicode
const ** ppSrcBuf
,
120 sal_Unicode
const * pEndSrcBuf
,
121 sal_Char
** ppDestBuf
,
122 sal_Char
const * pEndDestBuf
,
126 sal_Unicode c
= **ppSrcBuf
;
128 (void) pData
; /* unused */
130 /* Should the private character map to one byte */
131 if ( (c
>= RTL_TEXTCVT_BYTE_PRIVATE_START
) && (c
<= RTL_TEXTCVT_BYTE_PRIVATE_END
) )
133 if ( nFlags
& RTL_UNICODETOTEXT_FLAGS_PRIVATE_MAPTO0
)
135 **ppDestBuf
= (sal_Char
)(sal_uChar
)(c
-RTL_TEXTCVT_BYTE_PRIVATE_START
);
142 /* Should this character ignored (Private, Non Spacing, Control) */
143 if ( ImplIsUnicodeIgnoreChar( c
, nFlags
) )
149 /* Surrogates Characters should result in */
150 /* one replacement character */
151 if (ImplIsHighSurrogate(c
))
153 if ( *ppSrcBuf
== pEndSrcBuf
)
155 *pInfo
|= RTL_UNICODETOTEXT_INFO_ERROR
| RTL_UNICODETOTEXT_INFO_SRCBUFFERTOSMALL
;
159 c
= *((*ppSrcBuf
)+1);
160 if (ImplIsLowSurrogate(c
))
164 *pInfo
|= RTL_UNICODETOTEXT_INFO_INVALID
;
165 if ( (nFlags
& RTL_UNICODETOTEXT_FLAGS_INVALID_MASK
) == RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
)
167 *pInfo
|= RTL_UNICODETOTEXT_INFO_ERROR
;
170 else if ( (nFlags
& RTL_UNICODETOTEXT_FLAGS_INVALID_MASK
) == RTL_UNICODETOTEXT_FLAGS_INVALID_IGNORE
)
175 else if (ImplGetInvalidAsciiMultiByte(nFlags
,
177 pEndDestBuf
- *ppDestBuf
))
185 *pInfo
|= RTL_UNICODETOTEXT_INFO_ERROR
186 | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL
;
192 *pInfo
|= RTL_UNICODETOTEXT_INFO_UNDEFINED
;
193 if ( (nFlags
& RTL_UNICODETOTEXT_FLAGS_UNDEFINED_MASK
) == RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
)
195 *pInfo
|= RTL_UNICODETOTEXT_INFO_ERROR
;
198 else if ( (nFlags
& RTL_UNICODETOTEXT_FLAGS_UNDEFINED_MASK
) == RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE
)
200 else if (ImplGetUndefinedAsciiMultiByte(nFlags
,
202 pEndDestBuf
- *ppDestBuf
))
209 *pInfo
|= RTL_UNICODETOTEXT_INFO_ERROR
210 | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL
;