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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "sal/config.h"
22 #include "rtl/textcvt.h"
23 #include "sal/types.h"
25 #include "converter.hxx"
26 #include "tenchelp.hxx"
27 #include "unichars.hxx"
29 sal::detail::textenc::BadInputConversionAction
30 sal::detail::textenc::handleBadInputTextToUnicodeConversion(
31 bool bUndefined
, bool bMultiByte
, char cByte
, sal_uInt32 nFlags
,
32 sal_Unicode
** pDestBufPtr
, sal_Unicode
* pDestBufEnd
, sal_uInt32
* pInfo
)
36 ? RTL_TEXTTOUNICODE_INFO_MBUNDEFINED
37 : RTL_TEXTTOUNICODE_INFO_UNDEFINED
)
38 : RTL_TEXTTOUNICODE_INFO_INVALID
;
42 ? RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_MASK
43 : RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MASK
)
44 : RTL_TEXTTOUNICODE_FLAGS_INVALID_MASK
))
46 case RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
:
47 case RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
:
48 case RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR
:
49 *pInfo
|= RTL_TEXTTOUNICODE_INFO_ERROR
;
50 return BAD_INPUT_STOP
;
52 case RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_IGNORE
:
53 case RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_IGNORE
:
54 case RTL_TEXTTOUNICODE_FLAGS_INVALID_IGNORE
:
55 return BAD_INPUT_CONTINUE
;
57 case RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MAPTOPRIVATE
:
58 if (*pDestBufPtr
!= pDestBufEnd
)
60 *(*pDestBufPtr
)++ = RTL_TEXTCVT_BYTE_PRIVATE_START
61 | ((unsigned char) cByte
);
62 return BAD_INPUT_CONTINUE
;
65 return BAD_INPUT_NO_OUTPUT
;
67 default: // RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_DEFAULT,
68 // RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_DEFAULT,
69 // RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT
70 if (*pDestBufPtr
!= pDestBufEnd
)
72 *(*pDestBufPtr
)++ = RTL_TEXTENC_UNICODE_REPLACEMENT_CHARACTER
;
73 return BAD_INPUT_CONTINUE
;
76 return BAD_INPUT_NO_OUTPUT
;
80 sal::detail::textenc::BadInputConversionAction
81 sal::detail::textenc::handleBadInputUnicodeToTextConversion(
82 bool bUndefined
, sal_uInt32 nUtf32
, sal_uInt32 nFlags
, char ** pDestBufPtr
,
83 char * pDestBufEnd
, sal_uInt32
* pInfo
, char const * pPrefix
,
84 sal_Size nPrefixLen
, bool * pPrefixWritten
)
86 // TODO! RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACE
87 // RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACESTR
93 if (ImplIsControlOrFormat(nUtf32
))
95 if ((nFlags
& RTL_UNICODETOTEXT_FLAGS_CONTROL_IGNORE
) != 0)
96 nFlags
= RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE
;
98 else if (ImplIsPrivateUse(nUtf32
))
100 if ((nFlags
& RTL_UNICODETOTEXT_FLAGS_PRIVATE_IGNORE
) != 0)
101 nFlags
= RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE
;
102 else if ((nFlags
& RTL_UNICODETOTEXT_FLAGS_PRIVATE_MAPTO0
) != 0)
103 nFlags
= RTL_UNICODETOTEXT_FLAGS_UNDEFINED_0
;
105 else if (ImplIsZeroWidth(nUtf32
))
107 if ((nFlags
& RTL_UNICODETOTEXT_FLAGS_NONSPACING_IGNORE
) != 0)
108 nFlags
= RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE
;
111 *pInfo
|= bUndefined
? RTL_UNICODETOTEXT_INFO_UNDEFINED
:
112 RTL_UNICODETOTEXT_INFO_INVALID
;
113 switch (nFlags
& (bUndefined
? RTL_UNICODETOTEXT_FLAGS_UNDEFINED_MASK
:
114 RTL_UNICODETOTEXT_FLAGS_INVALID_MASK
))
116 case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
:
117 case RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
:
118 *pInfo
|= RTL_UNICODETOTEXT_INFO_ERROR
;
119 return BAD_INPUT_STOP
;
121 case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE
:
122 case RTL_UNICODETOTEXT_FLAGS_INVALID_IGNORE
:
124 *pPrefixWritten
= false;
125 return BAD_INPUT_CONTINUE
;
127 case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_0
:
128 case RTL_UNICODETOTEXT_FLAGS_INVALID_0
:
132 case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_QUESTIONMARK
:
133 case RTL_UNICODETOTEXT_FLAGS_INVALID_QUESTIONMARK
:
134 default: // RTL_UNICODETOTEXT_FLAGS_UNDEFINED_DEFAULT,
135 // RTL_UNICODETOTEXT_FLAGS_INVALID_DEFAULT
139 case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_UNDERLINE
:
140 case RTL_UNICODETOTEXT_FLAGS_INVALID_UNDERLINE
:
144 if ((sal_Size
) (pDestBufEnd
- *pDestBufPtr
) > nPrefixLen
)
146 while (nPrefixLen
-- > 0)
147 *(*pDestBufPtr
)++ = *pPrefix
++;
148 *(*pDestBufPtr
)++ = cReplace
;
150 *pPrefixWritten
= true;
151 return BAD_INPUT_CONTINUE
;
154 return BAD_INPUT_NO_OUTPUT
;
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */