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_Unicode* pEndDestBuf;
36 : const char* pEndSrcBuf;
37 :
38 24 : *pInfo = 0;
39 24 : pEndDestBuf = pDestBuf+nDestChars;
40 24 : pEndSrcBuf = pSrcBuf+nSrcBytes;
41 72 : while ( pSrcBuf < pEndSrcBuf )
42 : {
43 24 : if ( pDestBuf == pEndDestBuf )
44 : {
45 0 : *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL;
46 0 : break;
47 : }
48 :
49 : /* 0-31 (all Control-Character get the same Unicode value) */
50 24 : unsigned char c = (unsigned char)*pSrcBuf;
51 24 : if ( c <= 0x1F )
52 0 : *pDestBuf = (sal_Unicode)c;
53 : else
54 24 : *pDestBuf = ((sal_Unicode)c)+0xF000;
55 24 : pDestBuf++;
56 24 : pSrcBuf++;
57 : }
58 :
59 24 : *pSrcCvtBytes = nSrcBytes - (pEndSrcBuf-pSrcBuf);
60 24 : return (nDestChars - (pEndDestBuf-pDestBuf));
61 : }
62 :
63 143 : sal_Size ImplUnicodeToSymbol( SAL_UNUSED_PARAMETER const void*,
64 : SAL_UNUSED_PARAMETER void*,
65 : const sal_Unicode* pSrcBuf, sal_Size nSrcChars,
66 : char* pDestBuf, sal_Size nDestBytes,
67 : sal_uInt32 nFlags, sal_uInt32* pInfo,
68 : sal_Size* pSrcCvtChars )
69 : {
70 : sal_Unicode c;
71 : char* pEndDestBuf;
72 : const sal_Unicode* pEndSrcBuf;
73 :
74 143 : *pInfo = 0;
75 143 : pEndDestBuf = pDestBuf+nDestBytes;
76 143 : pEndSrcBuf = pSrcBuf+nSrcChars;
77 993 : while ( pSrcBuf < pEndSrcBuf )
78 : {
79 707 : if ( pDestBuf == pEndDestBuf )
80 : {
81 0 : *pInfo |= RTL_UNICODETOTEXT_INFO_ERROR | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
82 0 : break;
83 : }
84 :
85 707 : c = *pSrcBuf;
86 707 : if ( (c >= 0xF000) && (c <= 0xF0FF) )
87 : {
88 37 : *pDestBuf = static_cast< char >(static_cast< unsigned char >(c-0xF000));
89 37 : pDestBuf++;
90 37 : pSrcBuf++;
91 : }
92 : // Normally 0x001F, but in many cases also symbol characters
93 : // are stored in the first 256 bytes, so that we don't change
94 : // these values
95 670 : else if ( c <= 0x00FF )
96 : {
97 670 : *pDestBuf = static_cast< char >(static_cast< unsigned char >(c));
98 670 : pDestBuf++;
99 670 : pSrcBuf++;
100 : }
101 : else
102 : {
103 0 : if ( nFlags & RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACE )
104 : {
105 : /* !!! */
106 : /* Only ascii characters < 0x1F */
107 : }
108 :
109 : /* Handle undefined and surrogates characters */
110 : /* (all surrogates characters are undefined) */
111 0 : if (!sal::detail::textenc::handleUndefinedUnicodeToTextChar(
112 : &pSrcBuf, pEndSrcBuf, &pDestBuf, pEndDestBuf, nFlags,
113 0 : pInfo))
114 0 : break;
115 : }
116 : }
117 :
118 143 : *pSrcCvtChars = nSrcChars - (pEndSrcBuf-pSrcBuf);
119 143 : return (nDestBytes - (pEndDestBuf-pDestBuf));
120 : }
121 :
122 11443 : sal_Size ImplUpperCharToUnicode( const void* pData,
123 : SAL_UNUSED_PARAMETER void*,
124 : const char* pSrcBuf, sal_Size nSrcBytes,
125 : sal_Unicode* pDestBuf, sal_Size nDestChars,
126 : SAL_UNUSED_PARAMETER sal_uInt32, sal_uInt32* pInfo,
127 : sal_Size* pSrcCvtBytes )
128 : {
129 : sal_Unicode cConv;
130 11443 : const ImplByteConvertData* pConvertData = static_cast<const ImplByteConvertData*>(pData);
131 : sal_Unicode* pEndDestBuf;
132 : const char* pEndSrcBuf;
133 :
134 11443 : *pInfo = 0;
135 11443 : pEndDestBuf = pDestBuf+nDestChars;
136 11443 : pEndSrcBuf = pSrcBuf+nSrcBytes;
137 11443 : if ( pDestBuf == pEndDestBuf )
138 : {
139 0 : *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL;
140 0 : *pSrcCvtBytes = 0;
141 0 : return 0;
142 : }
143 185934 : while ( pSrcBuf < pEndSrcBuf )
144 : {
145 163048 : unsigned char c = (unsigned char)*pSrcBuf;
146 163048 : if (c < 0x80)
147 162782 : cConv = c;
148 : else
149 : // c <= 0xFF is implied.
150 266 : cConv = pConvertData->mpToUniTab1[c - 0x80];
151 :
152 163048 : *pDestBuf = cConv;
153 163048 : pDestBuf++;
154 163048 : pSrcBuf++;
155 : }
156 :
157 11443 : *pSrcCvtBytes = nSrcBytes - (pEndSrcBuf-pSrcBuf);
158 11443 : return (nDestChars - (pEndDestBuf-pDestBuf));
159 : }
160 :
161 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|