/src/libreoffice/sal/textenc/tcvtbyte.cxx
Line | Count | Source |
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 | | 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 | 24.7k | { |
35 | 24.7k | sal_Unicode* pEndDestBuf; |
36 | 24.7k | const char* pEndSrcBuf; |
37 | | |
38 | 24.7k | *pInfo = 0; |
39 | 24.7k | pEndDestBuf = pDestBuf+nDestChars; |
40 | 24.7k | pEndSrcBuf = pSrcBuf+nSrcBytes; |
41 | 558k | while ( pSrcBuf < pEndSrcBuf ) |
42 | 533k | { |
43 | 533k | if ( pDestBuf == pEndDestBuf ) |
44 | 0 | { |
45 | 0 | *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOOSMALL; |
46 | 0 | break; |
47 | 0 | } |
48 | | |
49 | | /* 0-31 (all Control-Character get the same Unicode value) */ |
50 | 533k | unsigned char c = static_cast<unsigned char>(*pSrcBuf); |
51 | 533k | if ( c <= 0x1F ) |
52 | 369k | *pDestBuf = static_cast<sal_Unicode>(c); |
53 | 164k | else |
54 | 164k | *pDestBuf = static_cast<sal_Unicode>(c)+0xF000; |
55 | 533k | pDestBuf++; |
56 | 533k | pSrcBuf++; |
57 | 533k | } |
58 | | |
59 | 24.7k | *pSrcCvtBytes = nSrcBytes - (pEndSrcBuf-pSrcBuf); |
60 | 24.7k | return (nDestChars - (pEndDestBuf-pDestBuf)); |
61 | 24.7k | } |
62 | | |
63 | | 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 | 0 | { |
70 | 0 | sal_Unicode c; |
71 | 0 | char* pEndDestBuf; |
72 | 0 | const sal_Unicode* pEndSrcBuf; |
73 | |
|
74 | 0 | *pInfo = 0; |
75 | 0 | pEndDestBuf = pDestBuf+nDestBytes; |
76 | 0 | pEndSrcBuf = pSrcBuf+nSrcChars; |
77 | 0 | while ( pSrcBuf < pEndSrcBuf ) |
78 | 0 | { |
79 | 0 | if ( pDestBuf == pEndDestBuf ) |
80 | 0 | { |
81 | 0 | *pInfo |= RTL_UNICODETOTEXT_INFO_ERROR | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL; |
82 | 0 | break; |
83 | 0 | } |
84 | | |
85 | 0 | c = *pSrcBuf; |
86 | 0 | if ( (c >= 0xF000) && (c <= 0xF0FF) ) |
87 | 0 | { |
88 | 0 | *pDestBuf = static_cast< char >(static_cast< unsigned char >(c-0xF000)); |
89 | 0 | pDestBuf++; |
90 | 0 | pSrcBuf++; |
91 | 0 | } |
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 | 0 | else if ( c <= 0x00FF ) |
96 | 0 | { |
97 | 0 | *pDestBuf = static_cast< char >(static_cast< unsigned char >(c)); |
98 | 0 | pDestBuf++; |
99 | 0 | pSrcBuf++; |
100 | 0 | } |
101 | 0 | else |
102 | 0 | { |
103 | 0 | if ( nFlags & RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACE ) |
104 | 0 | { |
105 | | /* !!! */ |
106 | | /* Only ascii characters < 0x1F */ |
107 | 0 | } |
108 | | |
109 | | /* Handle undefined and surrogates characters */ |
110 | | /* (all surrogates characters are undefined) */ |
111 | 0 | if (!sal::detail::textenc::handleUndefinedUnicodeToTextChar( |
112 | 0 | &pSrcBuf, pEndSrcBuf, &pDestBuf, pEndDestBuf, nFlags, |
113 | 0 | pInfo)) |
114 | 0 | break; |
115 | 0 | } |
116 | 0 | } |
117 | |
|
118 | 0 | *pSrcCvtChars = nSrcChars - (pEndSrcBuf-pSrcBuf); |
119 | 0 | return (nDestBytes - (pEndDestBuf-pDestBuf)); |
120 | 0 | } |
121 | | |
122 | | 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 | 4.37M | { |
129 | 4.37M | sal_Unicode cConv; |
130 | 4.37M | const ImplByteConvertData* pConvertData = static_cast<const ImplByteConvertData*>(pData); |
131 | 4.37M | sal_Unicode* pEndDestBuf; |
132 | 4.37M | const char* pEndSrcBuf; |
133 | | |
134 | 4.37M | *pInfo = 0; |
135 | 4.37M | pEndDestBuf = pDestBuf+nDestChars; |
136 | 4.37M | pEndSrcBuf = pSrcBuf+nSrcBytes; |
137 | 4.37M | if ( pDestBuf == pEndDestBuf ) |
138 | 0 | { |
139 | 0 | *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOOSMALL; |
140 | 0 | *pSrcCvtBytes = 0; |
141 | 0 | return 0; |
142 | 0 | } |
143 | 42.0M | while ( pSrcBuf < pEndSrcBuf ) |
144 | 37.6M | { |
145 | 37.6M | unsigned char c = static_cast<unsigned char>(*pSrcBuf); |
146 | 37.6M | if (c < 0x80) |
147 | 32.6M | cConv = c; |
148 | 5.03M | else |
149 | | // c <= 0xFF is implied. |
150 | 5.03M | cConv = pConvertData->mpToUniTab1[c - 0x80]; |
151 | | |
152 | 37.6M | *pDestBuf = cConv; |
153 | 37.6M | pDestBuf++; |
154 | 37.6M | pSrcBuf++; |
155 | 37.6M | } |
156 | | |
157 | 4.37M | *pSrcCvtBytes = nSrcBytes - (pEndSrcBuf-pSrcBuf); |
158 | 4.37M | return (nDestChars - (pEndDestBuf-pDestBuf)); |
159 | 4.37M | } |
160 | | |
161 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |