1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "sal/config.h"
31 #include "rtl/textcvt.h"
33 #include "handleundefinedunicodetotextchar.hxx"
34 #include "tcvtbyte.hxx"
35 #include "tenchelp.hxx"
37 sal_Size
ImplSymbolToUnicode( SAL_UNUSED_PARAMETER
const void*,
38 SAL_UNUSED_PARAMETER
void*,
39 const char* pSrcBuf
, sal_Size nSrcBytes
,
40 sal_Unicode
* pDestBuf
, sal_Size nDestChars
,
41 SAL_UNUSED_PARAMETER sal_uInt32
,
42 sal_uInt32
* pInfo
, sal_Size
* pSrcCvtBytes
)
45 sal_Unicode
* pEndDestBuf
;
46 const char* pEndSrcBuf
;
49 pEndDestBuf
= pDestBuf
+nDestChars
;
50 pEndSrcBuf
= pSrcBuf
+nSrcBytes
;
51 while ( pSrcBuf
< pEndSrcBuf
)
53 if ( pDestBuf
== pEndDestBuf
)
55 *pInfo
|= RTL_TEXTTOUNICODE_INFO_ERROR
| RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL
;
59 /* 0-31 (all Control-Character get the same Unicode value) */
60 c
= (sal_uChar
)*pSrcBuf
;
62 *pDestBuf
= (sal_Unicode
)c
;
64 *pDestBuf
= ((sal_Unicode
)c
)+0xF000;
69 *pSrcCvtBytes
= nSrcBytes
- (pEndSrcBuf
-pSrcBuf
);
70 return (nDestChars
- (pEndDestBuf
-pDestBuf
));
73 sal_Size
ImplUnicodeToSymbol( SAL_UNUSED_PARAMETER
const void*,
74 SAL_UNUSED_PARAMETER
void*,
75 const sal_Unicode
* pSrcBuf
, sal_Size nSrcChars
,
76 char* pDestBuf
, sal_Size nDestBytes
,
77 sal_uInt32 nFlags
, sal_uInt32
* pInfo
,
78 sal_Size
* pSrcCvtChars
)
82 const sal_Unicode
* pEndSrcBuf
;
85 pEndDestBuf
= pDestBuf
+nDestBytes
;
86 pEndSrcBuf
= pSrcBuf
+nSrcChars
;
87 while ( pSrcBuf
< pEndSrcBuf
)
89 if ( pDestBuf
== pEndDestBuf
)
91 *pInfo
|= RTL_UNICODETOTEXT_INFO_ERROR
| RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL
;
96 if ( (c
>= 0xF000) && (c
<= 0xF0FF) )
98 *pDestBuf
= static_cast< char >(static_cast< unsigned char >(c
-0xF000));
102 // Normally 0x001F, but in many cases also symbol characters
103 // are stored in the first 256 bytes, so that we don't change
105 else if ( c
<= 0x00FF )
107 *pDestBuf
= static_cast< char >(static_cast< unsigned char >(c
));
113 if ( nFlags
& RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACE
)
116 /* Only ascii characters < 0x1F */
119 /* Handle undefined and surrogates characters */
120 /* (all surrogates characters are undefined) */
121 if (!sal::detail::textenc::handleUndefinedUnicodeToTextChar(
122 &pSrcBuf
, pEndSrcBuf
, &pDestBuf
, pEndDestBuf
, nFlags
,
128 *pSrcCvtChars
= nSrcChars
- (pEndSrcBuf
-pSrcBuf
);
129 return (nDestBytes
- (pEndDestBuf
-pDestBuf
));
132 sal_Size
ImplUpperCharToUnicode( const void* pData
,
133 SAL_UNUSED_PARAMETER
void*,
134 const char* pSrcBuf
, sal_Size nSrcBytes
,
135 sal_Unicode
* pDestBuf
, sal_Size nDestChars
,
136 SAL_UNUSED_PARAMETER sal_uInt32
, sal_uInt32
* pInfo
,
137 sal_Size
* pSrcCvtBytes
)
141 const ImplByteConvertData
* pConvertData
= (const ImplByteConvertData
*)pData
;
142 sal_Unicode
* pEndDestBuf
;
143 const char* pEndSrcBuf
;
146 pEndDestBuf
= pDestBuf
+nDestChars
;
147 pEndSrcBuf
= pSrcBuf
+nSrcBytes
;
148 if ( pDestBuf
== pEndDestBuf
)
150 *pInfo
|= RTL_TEXTTOUNICODE_INFO_ERROR
| RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL
;
154 while ( pSrcBuf
< pEndSrcBuf
)
156 c
= (sal_uChar
)*pSrcBuf
;
160 // c <= 0xFF is implied.
161 cConv
= pConvertData
->mpToUniTab1
[c
- 0x80];
168 *pSrcCvtBytes
= nSrcBytes
- (pEndSrcBuf
-pSrcBuf
);
169 return (nDestChars
- (pEndDestBuf
-pDestBuf
));
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */