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"
24 #include "handleundefinedunicodetotextchar.hxx"
25 #include "tcvtbyte.hxx"
26 #include "tenchelp.hxx"
28 sal_Size
ImplSymbolToUnicode( SAL_UNUSED_PARAMETER
const void*,
29 SAL_UNUSED_PARAMETER
void*,
30 const char* pSrcBuf
, sal_Size nSrcBytes
,
31 sal_Unicode
* pDestBuf
, sal_Size nDestChars
,
32 SAL_UNUSED_PARAMETER sal_uInt32
,
33 sal_uInt32
* pInfo
, sal_Size
* pSrcCvtBytes
)
36 sal_Unicode
* pEndDestBuf
;
37 const char* pEndSrcBuf
;
40 pEndDestBuf
= pDestBuf
+nDestChars
;
41 pEndSrcBuf
= pSrcBuf
+nSrcBytes
;
42 while ( pSrcBuf
< pEndSrcBuf
)
44 if ( pDestBuf
== pEndDestBuf
)
46 *pInfo
|= RTL_TEXTTOUNICODE_INFO_ERROR
| RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL
;
50 /* 0-31 (all Control-Character get the same Unicode value) */
51 c
= (sal_uChar
)*pSrcBuf
;
53 *pDestBuf
= (sal_Unicode
)c
;
55 *pDestBuf
= ((sal_Unicode
)c
)+0xF000;
60 *pSrcCvtBytes
= nSrcBytes
- (pEndSrcBuf
-pSrcBuf
);
61 return (nDestChars
- (pEndDestBuf
-pDestBuf
));
64 sal_Size
ImplUnicodeToSymbol( SAL_UNUSED_PARAMETER
const void*,
65 SAL_UNUSED_PARAMETER
void*,
66 const sal_Unicode
* pSrcBuf
, sal_Size nSrcChars
,
67 char* pDestBuf
, sal_Size nDestBytes
,
68 sal_uInt32 nFlags
, sal_uInt32
* pInfo
,
69 sal_Size
* pSrcCvtChars
)
73 const sal_Unicode
* pEndSrcBuf
;
76 pEndDestBuf
= pDestBuf
+nDestBytes
;
77 pEndSrcBuf
= pSrcBuf
+nSrcChars
;
78 while ( pSrcBuf
< pEndSrcBuf
)
80 if ( pDestBuf
== pEndDestBuf
)
82 *pInfo
|= RTL_UNICODETOTEXT_INFO_ERROR
| RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL
;
87 if ( (c
>= 0xF000) && (c
<= 0xF0FF) )
89 *pDestBuf
= static_cast< char >(static_cast< unsigned char >(c
-0xF000));
93 // Normally 0x001F, but in many cases also symbol characters
94 // are stored in the first 256 bytes, so that we don't change
96 else if ( c
<= 0x00FF )
98 *pDestBuf
= static_cast< char >(static_cast< unsigned char >(c
));
104 if ( nFlags
& RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACE
)
107 /* Only ascii characters < 0x1F */
110 /* Handle undefined and surrogates characters */
111 /* (all surrogates characters are undefined) */
112 if (!sal::detail::textenc::handleUndefinedUnicodeToTextChar(
113 &pSrcBuf
, pEndSrcBuf
, &pDestBuf
, pEndDestBuf
, nFlags
,
119 *pSrcCvtChars
= nSrcChars
- (pEndSrcBuf
-pSrcBuf
);
120 return (nDestBytes
- (pEndDestBuf
-pDestBuf
));
123 sal_Size
ImplUpperCharToUnicode( const void* pData
,
124 SAL_UNUSED_PARAMETER
void*,
125 const char* pSrcBuf
, sal_Size nSrcBytes
,
126 sal_Unicode
* pDestBuf
, sal_Size nDestChars
,
127 SAL_UNUSED_PARAMETER sal_uInt32
, sal_uInt32
* pInfo
,
128 sal_Size
* pSrcCvtBytes
)
132 const ImplByteConvertData
* pConvertData
= (const ImplByteConvertData
*)pData
;
133 sal_Unicode
* pEndDestBuf
;
134 const char* pEndSrcBuf
;
137 pEndDestBuf
= pDestBuf
+nDestChars
;
138 pEndSrcBuf
= pSrcBuf
+nSrcBytes
;
139 if ( pDestBuf
== pEndDestBuf
)
141 *pInfo
|= RTL_TEXTTOUNICODE_INFO_ERROR
| RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL
;
145 while ( pSrcBuf
< pEndSrcBuf
)
147 c
= (sal_uChar
)*pSrcBuf
;
151 // c <= 0xFF is implied.
152 cConv
= pConvertData
->mpToUniTab1
[c
- 0x80];
159 *pSrcCvtBytes
= nSrcBytes
- (pEndSrcBuf
-pSrcBuf
);
160 return (nDestChars
- (pEndDestBuf
-pDestBuf
));
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */