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