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 48 : 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 : unsigned char c;
36 : sal_Unicode* pEndDestBuf;
37 : const char* pEndSrcBuf;
38 :
39 48 : *pInfo = 0;
40 48 : pEndDestBuf = pDestBuf+nDestChars;
41 48 : pEndSrcBuf = pSrcBuf+nSrcBytes;
42 144 : while ( pSrcBuf < pEndSrcBuf )
43 : {
44 48 : 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 48 : c = (unsigned char)*pSrcBuf;
52 48 : if ( c <= 0x1F )
53 0 : *pDestBuf = (sal_Unicode)c;
54 : else
55 48 : *pDestBuf = ((sal_Unicode)c)+0xF000;
56 48 : pDestBuf++;
57 48 : pSrcBuf++;
58 : }
59 :
60 48 : *pSrcCvtBytes = nSrcBytes - (pEndSrcBuf-pSrcBuf);
61 48 : return (nDestChars - (pEndDestBuf-pDestBuf));
62 : }
63 :
64 232 : 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 232 : *pInfo = 0;
76 232 : pEndDestBuf = pDestBuf+nDestBytes;
77 232 : pEndSrcBuf = pSrcBuf+nSrcChars;
78 1554 : while ( pSrcBuf < pEndSrcBuf )
79 : {
80 1090 : if ( pDestBuf == pEndDestBuf )
81 : {
82 0 : *pInfo |= RTL_UNICODETOTEXT_INFO_ERROR | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
83 0 : break;
84 : }
85 :
86 1090 : c = *pSrcBuf;
87 1090 : if ( (c >= 0xF000) && (c <= 0xF0FF) )
88 : {
89 74 : *pDestBuf = static_cast< char >(static_cast< unsigned char >(c-0xF000));
90 74 : pDestBuf++;
91 74 : 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 1016 : else if ( c <= 0x00FF )
97 : {
98 1016 : *pDestBuf = static_cast< char >(static_cast< unsigned char >(c));
99 1016 : pDestBuf++;
100 1016 : 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 232 : *pSrcCvtChars = nSrcChars - (pEndSrcBuf-pSrcBuf);
120 232 : return (nDestBytes - (pEndDestBuf-pDestBuf));
121 : }
122 :
123 10419 : 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 : unsigned char c;
131 : sal_Unicode cConv;
132 10419 : const ImplByteConvertData* pConvertData = (const ImplByteConvertData*)pData;
133 : sal_Unicode* pEndDestBuf;
134 : const char* pEndSrcBuf;
135 :
136 10419 : *pInfo = 0;
137 10419 : pEndDestBuf = pDestBuf+nDestChars;
138 10419 : pEndSrcBuf = pSrcBuf+nSrcBytes;
139 10419 : 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 142163 : while ( pSrcBuf < pEndSrcBuf )
146 : {
147 121325 : c = (unsigned char)*pSrcBuf;
148 121325 : if (c < 0x80)
149 120811 : cConv = c;
150 : else
151 : // c <= 0xFF is implied.
152 514 : cConv = pConvertData->mpToUniTab1[c - 0x80];
153 :
154 121325 : *pDestBuf = cConv;
155 121325 : pDestBuf++;
156 121325 : pSrcBuf++;
157 : }
158 :
159 10419 : *pSrcCvtBytes = nSrcBytes - (pEndSrcBuf-pSrcBuf);
160 10419 : return (nDestChars - (pEndDestBuf-pDestBuf));
161 : }
162 :
163 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|