Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "sal/config.h"
21 :
22 : #include "rtl/textcvt.h"
23 :
24 : #include "handleundefinedunicodetotextchar.hxx"
25 : #include "tcvtbyte.hxx"
26 : #include "tenchelp.hxx"
27 :
28 24 : 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 )
34 : {
35 : sal_uChar c;
36 : sal_Unicode* pEndDestBuf;
37 : const char* pEndSrcBuf;
38 :
39 24 : *pInfo = 0;
40 24 : pEndDestBuf = pDestBuf+nDestChars;
41 24 : pEndSrcBuf = pSrcBuf+nSrcBytes;
42 72 : while ( pSrcBuf < pEndSrcBuf )
43 : {
44 24 : if ( pDestBuf == pEndDestBuf )
45 : {
46 0 : *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL;
47 0 : break;
48 : }
49 :
50 : /* 0-31 (all Control-Character get the same Unicode value) */
51 24 : c = (sal_uChar)*pSrcBuf;
52 24 : if ( c <= 0x1F )
53 0 : *pDestBuf = (sal_Unicode)c;
54 : else
55 24 : *pDestBuf = ((sal_Unicode)c)+0xF000;
56 24 : pDestBuf++;
57 24 : pSrcBuf++;
58 : }
59 :
60 24 : *pSrcCvtBytes = nSrcBytes - (pEndSrcBuf-pSrcBuf);
61 24 : return (nDestChars - (pEndDestBuf-pDestBuf));
62 : }
63 :
64 43 : 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 )
70 : {
71 : sal_Unicode c;
72 : char* pEndDestBuf;
73 : const sal_Unicode* pEndSrcBuf;
74 :
75 43 : *pInfo = 0;
76 43 : pEndDestBuf = pDestBuf+nDestBytes;
77 43 : pEndSrcBuf = pSrcBuf+nSrcChars;
78 129 : while ( pSrcBuf < pEndSrcBuf )
79 : {
80 43 : if ( pDestBuf == pEndDestBuf )
81 : {
82 0 : *pInfo |= RTL_UNICODETOTEXT_INFO_ERROR | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
83 0 : break;
84 : }
85 :
86 43 : c = *pSrcBuf;
87 43 : if ( (c >= 0xF000) && (c <= 0xF0FF) )
88 : {
89 43 : *pDestBuf = static_cast< char >(static_cast< unsigned char >(c-0xF000));
90 43 : pDestBuf++;
91 43 : pSrcBuf++;
92 : }
93 : // Normally 0x001F, but in many cases also symbol characters
94 : // are stored in the first 256 bytes, so that we don't change
95 : // these values
96 0 : else if ( c <= 0x00FF )
97 : {
98 0 : *pDestBuf = static_cast< char >(static_cast< unsigned char >(c));
99 0 : pDestBuf++;
100 0 : pSrcBuf++;
101 : }
102 : else
103 : {
104 0 : if ( nFlags & RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACE )
105 : {
106 : /* !!! */
107 : /* Only ascii characters < 0x1F */
108 : }
109 :
110 : /* Handle undefined and surrogates characters */
111 : /* (all surrogates characters are undefined) */
112 0 : if (!sal::detail::textenc::handleUndefinedUnicodeToTextChar(
113 : &pSrcBuf, pEndSrcBuf, &pDestBuf, pEndDestBuf, nFlags,
114 0 : pInfo))
115 0 : break;
116 : }
117 : }
118 :
119 43 : *pSrcCvtChars = nSrcChars - (pEndSrcBuf-pSrcBuf);
120 43 : return (nDestBytes - (pEndDestBuf-pDestBuf));
121 : }
122 :
123 5 : 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 )
129 : {
130 : sal_uChar c;
131 : sal_Unicode cConv;
132 5 : const ImplByteConvertData* pConvertData = (const ImplByteConvertData*)pData;
133 : sal_Unicode* pEndDestBuf;
134 : const char* pEndSrcBuf;
135 :
136 5 : *pInfo = 0;
137 5 : pEndDestBuf = pDestBuf+nDestChars;
138 5 : pEndSrcBuf = pSrcBuf+nSrcBytes;
139 5 : if ( pDestBuf == pEndDestBuf )
140 : {
141 0 : *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL;
142 0 : *pSrcCvtBytes = 0;
143 0 : return 0;
144 : }
145 541 : while ( pSrcBuf < pEndSrcBuf )
146 : {
147 531 : c = (sal_uChar)*pSrcBuf;
148 531 : if (c < 0x80)
149 275 : cConv = c;
150 : else
151 : // c <= 0xFF is implied.
152 256 : cConv = pConvertData->mpToUniTab1[c - 0x80];
153 :
154 531 : *pDestBuf = cConv;
155 531 : pDestBuf++;
156 531 : pSrcBuf++;
157 : }
158 :
159 5 : *pSrcCvtBytes = nSrcBytes - (pEndSrcBuf-pSrcBuf);
160 5 : return (nDestChars - (pEndDestBuf-pDestBuf));
161 : }
162 :
163 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|