LCOV - code coverage report
Current view: top level - sc/source/filter/oox - biffhelper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 46 2.2 %
Date: 2014-11-03 Functions: 2 9 22.2 %
Legend: Lines: hit not hit

          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 "biffhelper.hxx"
      21             : 
      22             : #include <rtl/math.hxx>
      23             : #include <rtl/tencinfo.h>
      24             : #include "biffinputstream.hxx"
      25             : #include "worksheethelper.hxx"
      26             : #include <oox/helper/binaryoutputstream.hxx>
      27             : 
      28             : namespace oox {
      29             : namespace xls {
      30             : 
      31             : namespace {
      32             : 
      33             : const sal_Int32 BIFF_RK_100FLAG             = 0x00000001;
      34             : const sal_Int32 BIFF_RK_INTFLAG             = 0x00000002;
      35             : const sal_Int32 BIFF_RK_VALUEMASK           = 0xFFFFFFFC;
      36             : 
      37             : union DecodedDouble
      38             : {
      39             :     double              mfValue;
      40             :     sal_math_Double     maStruct;
      41             : 
      42           0 :     inline explicit     DecodedDouble() {}
      43           0 :     inline explicit     DecodedDouble( double fValue ) : mfValue( fValue ) {}
      44             : };
      45             : 
      46             : } // namespace
      47             : 
      48             : // conversion -----------------------------------------------------------------
      49             : 
      50           0 : /*static*/ double BiffHelper::calcDoubleFromRk( sal_Int32 nRkValue )
      51             : {
      52           0 :     DecodedDouble aDecDbl( 0.0 );
      53           0 :     if( getFlag( nRkValue, BIFF_RK_INTFLAG ) )
      54             :     {
      55           0 :         sal_Int32 nTemp = nRkValue >> 2;
      56           0 :         setFlag< sal_Int32 >( nTemp, 0xE0000000, nRkValue < 0 );
      57           0 :         aDecDbl.mfValue = nTemp;
      58             :     }
      59             :     else
      60             :     {
      61           0 :         aDecDbl.maStruct.w32_parts.msw = static_cast< sal_uInt32 >( nRkValue & BIFF_RK_VALUEMASK );
      62             :     }
      63             : 
      64           0 :     if( getFlag( nRkValue, BIFF_RK_100FLAG ) )
      65           0 :         aDecDbl.mfValue /= 100.0;
      66             : 
      67           0 :     return aDecDbl.mfValue;
      68             : }
      69             : 
      70           0 : /*static*/ double BiffHelper::calcDoubleFromError( sal_uInt8 nErrorCode )
      71             : {
      72           0 :     sal_uInt16 nApiError = 0x7FFF;
      73           0 :     switch( nErrorCode )
      74             :     {
      75           0 :         case BIFF_ERR_NULL:     nApiError = 521;    break;
      76           0 :         case BIFF_ERR_DIV0:     nApiError = 532;    break;
      77           0 :         case BIFF_ERR_VALUE:    nApiError = 519;    break;
      78           0 :         case BIFF_ERR_REF:      nApiError = 524;    break;
      79           0 :         case BIFF_ERR_NAME:     nApiError = 525;    break;
      80           0 :         case BIFF_ERR_NUM:      nApiError = 503;    break;
      81           0 :         case BIFF_ERR_NA:       nApiError = 0x7FFF; break;
      82             :         default:    OSL_FAIL( "BiffHelper::calcDoubleFromError - unknown error code" );
      83             :     }
      84           0 :     DecodedDouble aDecDbl;
      85           0 :     ::rtl::math::setNan( &aDecDbl.mfValue );
      86           0 :     aDecDbl.maStruct.nan_parts.fraction_lo = nApiError;
      87           0 :     return aDecDbl.mfValue;
      88             : }
      89             : 
      90             : // BIFF12 import --------------------------------------------------------------
      91             : 
      92           0 : /*static*/ OUString BiffHelper::readString( SequenceInputStream& rStrm, bool b32BitLen, bool bAllowNulChars )
      93             : {
      94           0 :     OUString aString;
      95           0 :     if( !rStrm.isEof() )
      96             :     {
      97           0 :         sal_Int32 nCharCount = b32BitLen ? rStrm.readValue< sal_Int32 >() : rStrm.readValue< sal_Int16 >();
      98             :         // string length -1 is often used to indicate a missing string
      99             :         OSL_ENSURE( !rStrm.isEof() && (nCharCount >= -1), "BiffHelper::readString - invalid string length" );
     100           0 :         if( !rStrm.isEof() && (nCharCount > 0) )
     101             :         {
     102             :             // SequenceInputStream always supports getRemaining()
     103           0 :             nCharCount = ::std::min( nCharCount, static_cast< sal_Int32 >( rStrm.getRemaining() / 2 ) );
     104           0 :             aString = rStrm.readUnicodeArray( nCharCount, bAllowNulChars );
     105             :         }
     106             :     }
     107           0 :     return aString;
     108             : }
     109             : 
     110             : // BIFF2-BIFF8 import ---------------------------------------------------------
     111             : 
     112           0 : /*static*/ bool BiffHelper::isBofRecord( BiffInputStream& rStrm )
     113             : {
     114             :     return
     115           0 :         (rStrm.getRecId() == BIFF2_ID_BOF) ||
     116           0 :         (rStrm.getRecId() == BIFF3_ID_BOF) ||
     117           0 :         (rStrm.getRecId() == BIFF4_ID_BOF) ||
     118           0 :         (rStrm.getRecId() == BIFF5_ID_BOF);
     119             : }
     120             : 
     121           0 : /*static*/ bool BiffHelper::skipRecordBlock( BiffInputStream& rStrm, sal_uInt16 nEndRecId )
     122             : {
     123           0 :     sal_uInt16 nStartRecId = rStrm.getRecId();
     124           0 :     while( rStrm.startNextRecord() && (rStrm.getRecId() != nEndRecId) )
     125           0 :         if( rStrm.getRecId() == nStartRecId )
     126           0 :             skipRecordBlock( rStrm, nEndRecId );
     127           0 :     return !rStrm.isEof() && (rStrm.getRecId() == nEndRecId);
     128             : }
     129             : 
     130             : } // namespace xls
     131          48 : } // namespace oox
     132             : 
     133             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10