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: converter.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 ************************************************************************/
31 #include "converter.h"
34 #include "rtl/textcvt.h"
35 #include "sal/types.h"
37 ImplBadInputConversionAction
ImplHandleBadInputTextToUnicodeConversion(
38 sal_Bool bUndefined
, sal_Bool bMultiByte
, sal_Char cByte
, sal_uInt32 nFlags
,
39 sal_Unicode
** pDestBufPtr
, sal_Unicode
* pDestBufEnd
, sal_uInt32
* pInfo
)
43 ? RTL_TEXTTOUNICODE_INFO_MBUNDEFINED
44 : RTL_TEXTTOUNICODE_INFO_UNDEFINED
)
45 : RTL_TEXTTOUNICODE_INFO_INVALID
;
49 ? RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_MASK
50 : RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MASK
)
51 : RTL_TEXTTOUNICODE_FLAGS_INVALID_MASK
))
53 case RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
:
54 case RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
:
55 case RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR
:
56 *pInfo
|= RTL_TEXTTOUNICODE_INFO_ERROR
;
57 return IMPL_BAD_INPUT_STOP
;
59 case RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_IGNORE
:
60 case RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_IGNORE
:
61 case RTL_TEXTTOUNICODE_FLAGS_INVALID_IGNORE
:
62 return IMPL_BAD_INPUT_CONTINUE
;
64 case RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MAPTOPRIVATE
:
65 if (*pDestBufPtr
!= pDestBufEnd
)
67 *(*pDestBufPtr
)++ = RTL_TEXTCVT_BYTE_PRIVATE_START
68 | ((sal_uChar
) cByte
);
69 return IMPL_BAD_INPUT_CONTINUE
;
72 return IMPL_BAD_INPUT_NO_OUTPUT
;
74 default: /* RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_DEFAULT,
75 RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_DEFAULT,
76 RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT */
77 if (*pDestBufPtr
!= pDestBufEnd
)
79 *(*pDestBufPtr
)++ = RTL_TEXTENC_UNICODE_REPLACEMENT_CHARACTER
;
80 return IMPL_BAD_INPUT_CONTINUE
;
83 return IMPL_BAD_INPUT_NO_OUTPUT
;
87 ImplBadInputConversionAction
88 ImplHandleBadInputUnicodeToTextConversion(sal_Bool bUndefined
,
91 sal_Char
** pDestBufPtr
,
92 sal_Char
* pDestBufEnd
,
94 sal_Char
const * pPrefix
,
96 sal_Bool
* pPrefixWritten
)
98 /* TODO! RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACE
99 RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACESTR */
105 if (ImplIsControlOrFormat(nUtf32
))
107 if ((nFlags
& RTL_UNICODETOTEXT_FLAGS_CONTROL_IGNORE
) != 0)
108 nFlags
= RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE
;
110 else if (ImplIsPrivateUse(nUtf32
))
112 if ((nFlags
& RTL_UNICODETOTEXT_FLAGS_PRIVATE_IGNORE
) != 0)
113 nFlags
= RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE
;
114 else if ((nFlags
& RTL_UNICODETOTEXT_FLAGS_PRIVATE_MAPTO0
) != 0)
115 nFlags
= RTL_UNICODETOTEXT_FLAGS_UNDEFINED_0
;
117 else if (ImplIsZeroWidth(nUtf32
))
119 if ((nFlags
& RTL_UNICODETOTEXT_FLAGS_NONSPACING_IGNORE
) != 0)
120 nFlags
= RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE
;
123 *pInfo
|= bUndefined
? RTL_UNICODETOTEXT_INFO_UNDEFINED
:
124 RTL_UNICODETOTEXT_INFO_INVALID
;
125 switch (nFlags
& (bUndefined
? RTL_UNICODETOTEXT_FLAGS_UNDEFINED_MASK
:
126 RTL_UNICODETOTEXT_FLAGS_INVALID_MASK
))
128 case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
:
129 case RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
:
130 *pInfo
|= RTL_UNICODETOTEXT_INFO_ERROR
;
131 return IMPL_BAD_INPUT_STOP
;
133 case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE
:
134 case RTL_UNICODETOTEXT_FLAGS_INVALID_IGNORE
:
136 *pPrefixWritten
= sal_False
;
137 return IMPL_BAD_INPUT_CONTINUE
;
139 case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_0
:
140 case RTL_UNICODETOTEXT_FLAGS_INVALID_0
:
144 case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_QUESTIONMARK
:
145 case RTL_UNICODETOTEXT_FLAGS_INVALID_QUESTIONMARK
:
146 default: /* RTL_UNICODETOTEXT_FLAGS_UNDEFINED_DEFAULT,
147 RTL_UNICODETOTEXT_FLAGS_INVALID_DEFAULT */
151 case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_UNDERLINE
:
152 case RTL_UNICODETOTEXT_FLAGS_INVALID_UNDERLINE
:
156 if ((sal_Size
) (pDestBufEnd
- *pDestBufPtr
) > nPrefixLen
)
158 while (nPrefixLen
-- > 0)
159 *(*pDestBufPtr
)++ = *pPrefix
++;
160 *(*pDestBufPtr
)++ = cReplace
;
162 *pPrefixWritten
= sal_True
;
163 return IMPL_BAD_INPUT_CONTINUE
;
166 return IMPL_BAD_INPUT_NO_OUTPUT
;