LibreOffice Module basic (master) 1
sbxchar.cxx
Go to the documentation of this file.
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
21#include <basic/sberrors.hxx>
22#include "sbxconv.hxx"
23#include <rtlproto.hxx>
24
25#include <rtl/math.hxx>
26
28{
29 SbxValues aTmp;
30 sal_Unicode nRes = 0;
31start:
32 switch( +p->eType )
33 {
34 case SbxNULL:
36 [[fallthrough]];
37 case SbxEMPTY:
38 nRes = 0; break;
39 case SbxCHAR:
40 nRes = p->nChar; break;
41 case SbxBYTE:
42 nRes = static_cast<sal_Unicode>(p->nByte);
43 break;
44 case SbxINTEGER:
45 case SbxBOOL:
46 if( p->nInteger < SbxMINCHAR )
47 {
49 }
50 else
51 nRes = static_cast<sal_Unicode>(p->nInteger);
52 break;
53 case SbxERROR:
54 case SbxUSHORT:
55 nRes = static_cast<sal_Unicode>(p->nUShort);
56 break;
57 case SbxLONG:
58 if( p->nLong > SbxMAXCHAR )
59 {
61 }
62 else if( p->nLong < SbxMINCHAR )
63 {
65 }
66 else
67 nRes = static_cast<sal_Unicode>(p->nLong);
68 break;
69 case SbxULONG:
70 if( p->nULong > SbxMAXCHAR )
71 {
73 }
74 else
75 nRes = static_cast<sal_Unicode>(p->nULong);
76 break;
77 case SbxCURRENCY:
78 case SbxSALINT64:
79 {
80 sal_Int64 val = p->nInt64;
81
82 if ( p->eType == SbxCURRENCY )
83 val = val / CURRENCY_FACTOR;
84
85 if( val > SbxMAXCHAR )
86 {
88 }
89 else if( p->nInt64 < SbxMINCHAR )
90 {
92 }
93 else
94 nRes = static_cast<sal_Unicode>(val);
95 break;
96 }
97 case SbxSALUINT64:
98 if( p->uInt64 > SbxMAXCHAR )
99 {
101 }
102 else
103 nRes = static_cast<sal_Unicode>(p->uInt64);
104 break;
105 case SbxSINGLE:
106 if( p->nSingle > SbxMAXCHAR )
107 {
109 }
110 else if( p->nSingle < SbxMINCHAR )
111 {
113 }
114 else
115 nRes = static_cast<sal_Unicode>(rtl::math::round( p->nSingle ));
116 break;
117 case SbxDATE:
118 case SbxDOUBLE:
119 case SbxDECIMAL:
120 case SbxBYREF | SbxDECIMAL:
121 {
122 double dVal;
123 if( p->eType == SbxDECIMAL )
124 {
125 dVal = 0.0;
126 if( p->pDecimal )
127 p->pDecimal->getDouble( dVal );
128 }
129 else
130 dVal = p->nDouble;
131
132 if( dVal > SbxMAXCHAR )
133 {
135 }
136 else if( dVal < SbxMINCHAR )
137 {
139 }
140 else
141 nRes = static_cast<sal_uInt8>(rtl::math::round( dVal ));
142 break;
143 }
144 case SbxBYREF | SbxSTRING:
145 case SbxSTRING:
146 case SbxLPSTR:
147 if ( p->pOUString )
148 {
149 double d;
151 if( ImpScan( *p->pOUString, d, t, nullptr, !LibreOffice6FloatingPointMode() ) != ERRCODE_NONE )
152 nRes = 0;
153 else if( d > SbxMAXCHAR )
154 {
156 }
157 else if( d < SbxMINCHAR )
158 {
160 }
161 else
162 nRes = static_cast<sal_Unicode>(rtl::math::round( d ));
163 }
164 break;
165 case SbxOBJECT:
166 {
167 SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
168 if( pVal )
169 nRes = pVal->GetChar();
170 else
171 {
173 }
174 break;
175 }
176
177 case SbxBYREF | SbxCHAR:
178 nRes = *p->pChar; break;
179 // from here on will be tested
180 case SbxBYREF | SbxBYTE:
181 aTmp.nByte = *p->pByte; goto ref;
182 case SbxBYREF | SbxINTEGER:
183 case SbxBYREF | SbxBOOL:
184 aTmp.nInteger = *p->pInteger; goto ref;
185 case SbxBYREF | SbxLONG:
186 aTmp.nLong = *p->pLong; goto ref;
187 case SbxBYREF | SbxULONG:
188 aTmp.nULong = *p->pULong; goto ref;
189 case SbxBYREF | SbxERROR:
190 case SbxBYREF | SbxUSHORT:
191 aTmp.nUShort = *p->pUShort; goto ref;
192 case SbxBYREF | SbxSINGLE:
193 aTmp.nSingle = *p->pSingle; goto ref;
194 case SbxBYREF | SbxDATE:
195 case SbxBYREF | SbxDOUBLE:
196 aTmp.nDouble = *p->pDouble; goto ref;
197 case SbxBYREF | SbxCURRENCY:
198 case SbxBYREF | SbxSALINT64:
199 aTmp.nInt64 = *p->pnInt64; goto ref;
200 case SbxBYREF | SbxSALUINT64:
201 aTmp.uInt64 = *p->puInt64; goto ref;
202 ref:
203 aTmp.eType = SbxDataType( p->eType & 0x0FFF );
204 p = &aTmp; goto start;
205
206 default:
208 }
209 return nRes;
210}
211
213{
214 SbxValues aTmp;
215start:
216 switch( +p->eType )
217 {
218 case SbxCHAR:
219 p->nChar = n; break;
220 case SbxINTEGER:
221 case SbxBOOL:
222 p->nInteger = n; break;
223 case SbxLONG:
224 p->nLong = n; break;
225 case SbxSINGLE:
226 p->nSingle = n; break;
227 case SbxDATE:
228 case SbxDOUBLE:
229 p->nDouble = n; break;
230 case SbxCURRENCY:
231 p->nInt64 = n * CURRENCY_FACTOR; break;
232 case SbxSALINT64:
233 p->nInt64 = n; break;
234 case SbxSALUINT64:
235 p->uInt64 = n; break;
236 case SbxBYREF | SbxDECIMAL:
238 break;
239
240 // from here on will be tested
241 case SbxBYTE:
242 aTmp.pByte = &p->nByte; goto direct;
243 case SbxULONG:
244 aTmp.pULong = &p->nULong; goto direct;
245 case SbxERROR:
246 case SbxUSHORT:
247 aTmp.pUShort = &p->nUShort; goto direct;
248 direct:
249 aTmp.eType = SbxDataType( p->eType | SbxBYREF );
250 p = &aTmp; goto start;
251
252 case SbxBYREF | SbxSTRING:
253 case SbxSTRING:
254 case SbxLPSTR:
255 if ( !p->pOUString )
256 p->pOUString = new OUString( n );
257 else
258 *p->pOUString = OUString( n );
259 break;
260 case SbxOBJECT:
261 {
262 SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
263 if( pVal )
264 pVal->PutChar( n );
265 else
267 break;
268 }
269 case SbxBYREF | SbxCHAR:
270 *p->pChar = n; break;
271 case SbxBYREF | SbxBYTE:
272 *p->pByte = static_cast<sal_uInt8>(n); break;
273 case SbxBYREF | SbxINTEGER:
274 case SbxBYREF | SbxBOOL:
275 *p->pInteger = n; break;
276 case SbxBYREF | SbxERROR:
277 case SbxBYREF | SbxUSHORT:
278 *p->pUShort = static_cast<sal_uInt16>(n); break;
279 case SbxBYREF | SbxLONG:
280 *p->pLong = static_cast<sal_Int32>(n); break;
281 case SbxBYREF | SbxULONG:
282 *p->pULong = static_cast<sal_uInt32>(n); break;
283 case SbxBYREF | SbxSINGLE:
284 *p->pSingle = static_cast<float>(n); break;
285 case SbxBYREF | SbxDATE:
286 case SbxBYREF | SbxDOUBLE:
287 *p->pDouble = static_cast<double>(n); break;
288 case SbxBYREF | SbxCURRENCY:
289 p->nInt64 = n * CURRENCY_FACTOR; break;
290 case SbxBYREF | SbxSALINT64:
291 *p->pnInt64 = n; break;
292 case SbxBYREF | SbxSALUINT64:
293 *p->puInt64 = n; break;
294
295 default:
297 }
298}
299
300
301/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
double d
static void SetError(ErrCode)
Definition: sbxbase.cxx:116
void setChar(sal_Unicode val)
Definition: sbxdec.cxx:318
sal_Unicode GetChar() const
Definition: sbxvar.hxx:140
bool PutChar(sal_Unicode)
#define ERRCODE_NONE
void * p
sal_Int64 n
bool LibreOffice6FloatingPointMode()
Definition: methods1.cxx:2946
#define ERRCODE_BASIC_NO_OBJECT
Definition: sberrors.hxx:34
#define ERRCODE_BASIC_MATH_OVERFLOW
Definition: sberrors.hxx:27
#define ERRCODE_BASIC_CONVERSION
Definition: sberrors.hxx:30
sal_Unicode ImpGetChar(const SbxValues *p)
Definition: sbxchar.cxx:27
void ImpPutChar(SbxValues *p, sal_Unicode n)
Definition: sbxchar.cxx:212
ErrCode ImpScan(const OUString &rSrc, double &nVal, SbxDataType &rType, sal_uInt16 *pLen, bool bOnlyIntntl)
Definition: sbxscan.cxx:71
SbxDecimal * ImpCreateDecimal(SbxValues *p)
Definition: sbxdec.cxx:376
SbxBOOL
Definition: sbxdef.hxx:215
constexpr auto SbxMAXCHAR
Definition: sbxdef.hxx:184
SbxDataType
Definition: sbxdef.hxx:37
@ SbxOBJECT
Definition: sbxdef.hxx:47
@ SbxSALINT64
Definition: sbxdef.hxx:75
@ SbxLONG
Definition: sbxdef.hxx:41
@ SbxSALUINT64
Definition: sbxdef.hxx:76
@ SbxNULL
Definition: sbxdef.hxx:39
@ SbxBYTE
Definition: sbxdef.hxx:55
@ SbxEMPTY
Definition: sbxdef.hxx:38
@ SbxDECIMAL
Definition: sbxdef.hxx:77
@ SbxULONG
Definition: sbxdef.hxx:57
@ SbxUSHORT
Definition: sbxdef.hxx:56
@ SbxERROR
Definition: sbxdef.hxx:48
@ SbxDATE
Definition: sbxdef.hxx:45
@ SbxCURRENCY
Definition: sbxdef.hxx:44
@ SbxLPSTR
Definition: sbxdef.hxx:68
@ SbxSINGLE
Definition: sbxdef.hxx:42
@ SbxBYREF
Definition: sbxdef.hxx:81
@ SbxCHAR
Definition: sbxdef.hxx:54
@ SbxSTRING
Definition: sbxdef.hxx:46
@ SbxINTEGER
Definition: sbxdef.hxx:40
@ SbxDOUBLE
Definition: sbxdef.hxx:43
constexpr auto SbxMINCHAR
Definition: sbxdef.hxx:185
constexpr auto CURRENCY_FACTOR
Definition: sbxdef.hxx:197
float nSingle
Definition: sbxvar.hxx:55
sal_Int32 nLong
Definition: sbxvar.hxx:49
sal_uInt8 * pByte
Definition: sbxvar.hxx:63
sal_uInt32 * pULong
Definition: sbxvar.hxx:67
sal_uInt16 * pUShort
Definition: sbxvar.hxx:64
sal_Int16 nInteger
Definition: sbxvar.hxx:47
sal_Int64 nInt64
Definition: sbxvar.hxx:53
double nDouble
Definition: sbxvar.hxx:56
sal_uInt16 nUShort
Definition: sbxvar.hxx:45
sal_uInt64 uInt64
Definition: sbxvar.hxx:52
SbxDataType eType
Definition: sbxvar.hxx:77
sal_uInt8 nByte
Definition: sbxvar.hxx:44
sal_uInt32 nULong
Definition: sbxvar.hxx:48
unsigned char sal_uInt8
sal_uInt16 sal_Unicode