LibreOffice Module sc (master) 1
biffhelper.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
20#include <biffhelper.hxx>
21
22#include <osl/diagnose.h>
24
25#include <limits>
26
27namespace oox::xls {
28
29namespace {
30
31const sal_Int32 BIFF_RK_100FLAG = 0x00000001;
32const sal_Int32 BIFF_RK_INTFLAG = 0x00000002;
33const sal_Int32 BIFF_RK_VALUEMASK = 0xFFFFFFFC;
34
35} // namespace
36
37// conversion -----------------------------------------------------------------
38
39/*static*/ double BiffHelper::calcDoubleFromRk( sal_Int32 nRkValue )
40{
41 sal_math_Double aMathDouble{};
42 if( getFlag( nRkValue, BIFF_RK_INTFLAG ) )
43 {
44 sal_Int32 nTemp = nRkValue >> 2;
45 setFlag< sal_Int32 >( nTemp, 0xE0000000, nRkValue < 0 );
46 aMathDouble.value = nTemp;
47 }
48 else
49 {
50 aMathDouble.w32_parts.msw = static_cast< sal_uInt32 >( nRkValue & BIFF_RK_VALUEMASK );
51 }
52 if( getFlag( nRkValue, BIFF_RK_100FLAG ) )
53 aMathDouble.value /= 100.0;
54
55 return aMathDouble.value;
56}
57/*static*/ double BiffHelper::calcDoubleFromError( sal_uInt8 nErrorCode )
58{
59 sal_uInt16 nApiError = 0x7FFF;
60 switch( nErrorCode )
61 {
62 case BIFF_ERR_NULL: nApiError = 521; break;
63 case BIFF_ERR_DIV0: nApiError = 532; break;
64 case BIFF_ERR_VALUE: nApiError = 519; break;
65 case BIFF_ERR_REF: nApiError = 524; break;
66 case BIFF_ERR_NAME: nApiError = 525; break;
67 case BIFF_ERR_NUM: nApiError = 503; break;
68 case BIFF_ERR_NA: nApiError = 0x7FFF; break;
69 default: OSL_FAIL( "BiffHelper::calcDoubleFromError - unknown error code" );
70 }
71 sal_math_Double aMathDouble;
72 aMathDouble.value = std::numeric_limits<double>::quiet_NaN();
73 aMathDouble.nan_parts.fraction_lo = nApiError;
74 return aMathDouble.value;
75}
76
77// BIFF12 import --------------------------------------------------------------
78
79/*static*/ OUString BiffHelper::readString( SequenceInputStream& rStrm, bool b32BitLen )
80{
81 OUString aString;
82 if( !rStrm.isEof() )
83 {
84 sal_Int32 nCharCount = b32BitLen ? rStrm.readValue< sal_Int32 >() : rStrm.readValue< sal_Int16 >();
85 // string length -1 is often used to indicate a missing string
86 OSL_ENSURE( !rStrm.isEof() && (nCharCount >= -1), "BiffHelper::readString - invalid string length" );
87 if( !rStrm.isEof() && (nCharCount > 0) )
88 {
89 // SequenceInputStream always supports getRemaining()
90 nCharCount = ::std::min( nCharCount, static_cast< sal_Int32 >( rStrm.getRemaining() / 2 ) );
91 aString = rStrm.readUnicodeArray( nCharCount );
92 }
93 }
94 return aString;
95}
96
97} // namespace oox::xls
98
99/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static double calcDoubleFromError(sal_uInt8 nErrorCode)
Converts the passed BIFF error to a double containing the respective Calc error code.
Definition: biffhelper.cxx:57
static OUString readString(SequenceInputStream &rStrm, bool b32BitLen=true)
Reads a BIFF12 string with leading 16-bit or 32-bit length field.
Definition: biffhelper.cxx:79
static double calcDoubleFromRk(sal_Int32 nRkValue)
Converts the passed packed number to a double.
Definition: biffhelper.cxx:39
void SvStream & rStrm
const sal_uInt8 BIFF_ERR_DIV0
Definition: biffhelper.hxx:561
const sal_uInt8 BIFF_ERR_NUM
Definition: biffhelper.hxx:565
const sal_uInt8 BIFF_ERR_NA
Definition: biffhelper.hxx:566
const sal_uInt8 BIFF_ERR_NULL
Common object settings.
Definition: biffhelper.hxx:560
const sal_uInt8 BIFF_ERR_VALUE
Definition: biffhelper.hxx:562
const sal_uInt8 BIFF_ERR_NAME
Definition: biffhelper.hxx:564
const sal_uInt8 BIFF_ERR_REF
Definition: biffhelper.hxx:563
bool getFlag(Type nBitField, Type nMask)
unsigned char sal_uInt8