LCOV - code coverage report
Current view: top level - libreoffice/basic/source/sbx - sbxchar.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 122 0.0 %
Date: 2012-12-27 Functions: 0 2 0.0 %
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 <tools/errcode.hxx>
      21             : #include <basic/sbx.hxx>
      22             : #include "sbxconv.hxx"
      23             : 
      24           0 : sal_Unicode ImpGetChar( const SbxValues* p )
      25             : {
      26           0 :     SbxValues aTmp;
      27           0 :     sal_Unicode nRes = 0;
      28             : start:
      29           0 :     switch( +p->eType )
      30             :     {
      31             :         case SbxNULL:
      32           0 :             SbxBase::SetError( SbxERR_CONVERSION );
      33             :         case SbxEMPTY:
      34           0 :             nRes = 0; break;
      35             :         case SbxCHAR:
      36           0 :             nRes = p->nChar; break;
      37             :         case SbxBYTE:
      38           0 :             nRes = (sal_Unicode) p->nByte;
      39           0 :             break;
      40             :         case SbxINTEGER:
      41             :         case SbxBOOL:
      42           0 :             if( p->nInteger < SbxMINCHAR )
      43             :             {
      44           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMINCHAR;
      45             :             }
      46             :             else
      47           0 :                 nRes = (sal_Unicode) p->nInteger;
      48           0 :             break;
      49             :         case SbxERROR:
      50             :         case SbxUSHORT:
      51           0 :             nRes = (sal_Unicode) p->nUShort;
      52           0 :             break;
      53             :         case SbxLONG:
      54           0 :             if( p->nLong > SbxMAXCHAR )
      55             :             {
      56           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXCHAR;
      57             :             }
      58           0 :             else if( p->nLong < SbxMINCHAR )
      59             :             {
      60           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMINCHAR;
      61             :             }
      62             :             else
      63           0 :                 nRes = (sal_Unicode) p->nLong;
      64           0 :             break;
      65             :         case SbxULONG:
      66           0 :             if( p->nULong > SbxMAXCHAR )
      67             :             {
      68           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXCHAR;
      69             :             }
      70             :             else
      71           0 :                 nRes = (sal_Unicode) p->nULong;
      72           0 :             break;
      73             :         case SbxCURRENCY:
      74             :         case SbxSALINT64:
      75             :         {
      76           0 :             sal_Int64 val = p->nInt64;
      77             : 
      78           0 :             if ( p->eType == SbxCURRENCY )
      79           0 :                 val = val / CURRENCY_FACTOR;
      80             : 
      81           0 :             if( val > SbxMAXCHAR )
      82             :             {
      83           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXCHAR;
      84             :             }
      85           0 :             else if( p->nInt64 < SbxMINCHAR )
      86             :             {
      87           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMINCHAR;
      88             :             }
      89             :             else
      90           0 :                 nRes = (sal_Unicode) val;
      91           0 :             break;
      92             :         }
      93             :         case SbxSALUINT64:
      94           0 :             if( p->uInt64 > SbxMAXCHAR )
      95             :             {
      96           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXCHAR;
      97             :             }
      98             :             else
      99           0 :                 nRes = (sal_Unicode) p->uInt64;
     100           0 :             break;
     101             :         case SbxSINGLE:
     102           0 :             if( p->nSingle > SbxMAXCHAR )
     103             :             {
     104           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXCHAR;
     105             :             }
     106           0 :             else if( p->nSingle < SbxMINCHAR )
     107             :             {
     108           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMINCHAR;
     109             :             }
     110             :             else
     111           0 :                 nRes = (sal_Unicode) ImpRound( p->nSingle );
     112           0 :             break;
     113             :         case SbxDATE:
     114             :         case SbxDOUBLE:
     115             :         case SbxDECIMAL:
     116             :         case SbxBYREF | SbxDECIMAL:
     117             :             {
     118             :             double dVal;
     119           0 :             if( p->eType == SbxDECIMAL )
     120             :             {
     121           0 :                 dVal = 0.0;
     122           0 :                 if( p->pDecimal )
     123           0 :                     p->pDecimal->getDouble( dVal );
     124             :             }
     125             :             else
     126           0 :                 dVal = p->nDouble;
     127             : 
     128           0 :             if( dVal > SbxMAXCHAR )
     129             :             {
     130           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXCHAR;
     131             :             }
     132           0 :             else if( dVal < SbxMINCHAR )
     133             :             {
     134           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMINCHAR;
     135             :             }
     136             :             else
     137           0 :                 nRes = (sal_uInt8) ImpRound( dVal );
     138             :             break;
     139             :             }
     140             :         case SbxBYREF | SbxSTRING:
     141             :         case SbxSTRING:
     142             :         case SbxLPSTR:
     143           0 :             if ( p->pOUString )
     144             :             {
     145             :                 double d;
     146             :                 SbxDataType t;
     147           0 :                 if( ImpScan( *p->pOUString, d, t, NULL ) != SbxERR_OK )
     148           0 :                     nRes = 0;
     149           0 :                 else if( d > SbxMAXCHAR )
     150             :                 {
     151           0 :                     SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXCHAR;
     152             :                 }
     153           0 :                 else if( d < SbxMINCHAR )
     154             :                 {
     155           0 :                     SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMINCHAR;
     156             :                 }
     157             :                 else
     158           0 :                     nRes = (sal_Unicode) ImpRound( d );
     159             :             }
     160           0 :             break;
     161             :         case SbxOBJECT:
     162             :         {
     163           0 :             SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
     164           0 :             if( pVal )
     165           0 :                 nRes = pVal->GetChar();
     166             :             else
     167             :             {
     168           0 :                 SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = 0;
     169             :             }
     170           0 :             break;
     171             :         }
     172             : 
     173             :         case SbxBYREF | SbxCHAR:
     174           0 :             nRes = *p->pChar; break;
     175             :         // from here on will be tested
     176             :         case SbxBYREF | SbxBYTE:
     177           0 :             aTmp.nByte = *p->pByte; goto ref;
     178             :         case SbxBYREF | SbxINTEGER:
     179             :         case SbxBYREF | SbxBOOL:
     180           0 :             aTmp.nInteger = *p->pInteger; goto ref;
     181             :         case SbxBYREF | SbxLONG:
     182           0 :             aTmp.nLong = *p->pLong; goto ref;
     183             :         case SbxBYREF | SbxULONG:
     184           0 :             aTmp.nULong = *p->pULong; goto ref;
     185             :         case SbxBYREF | SbxERROR:
     186             :         case SbxBYREF | SbxUSHORT:
     187           0 :             aTmp.nUShort = *p->pUShort; goto ref;
     188             :         case SbxBYREF | SbxSINGLE:
     189           0 :             aTmp.nSingle = *p->pSingle; goto ref;
     190             :         case SbxBYREF | SbxDATE:
     191             :         case SbxBYREF | SbxDOUBLE:
     192           0 :             aTmp.nDouble = *p->pDouble; goto ref;
     193             :         case SbxBYREF | SbxCURRENCY:
     194             :         case SbxBYREF | SbxSALINT64:
     195           0 :             aTmp.nInt64 = *p->pnInt64; goto ref;
     196             :         case SbxBYREF | SbxSALUINT64:
     197           0 :             aTmp.uInt64 = *p->puInt64; goto ref;
     198             :         ref:
     199           0 :             aTmp.eType = SbxDataType( p->eType & 0x0FFF );
     200           0 :             p = &aTmp; goto start;
     201             : 
     202             :         default:
     203           0 :             SbxBase::SetError( SbxERR_CONVERSION ); nRes = 0;
     204             :     }
     205           0 :     return nRes;
     206             : }
     207             : 
     208           0 : void ImpPutChar( SbxValues* p, sal_Unicode n )
     209             : {
     210           0 :     SbxValues aTmp;
     211             : start:
     212           0 :     switch( +p->eType )
     213             :     {
     214             :         case SbxCHAR:
     215           0 :             p->nChar = n; break;
     216             :         case SbxINTEGER:
     217             :         case SbxBOOL:
     218           0 :             p->nInteger = n; break;
     219             :         case SbxLONG:
     220           0 :             p->nLong = n; break;
     221             :         case SbxSINGLE:
     222           0 :             p->nSingle = n; break;
     223             :         case SbxDATE:
     224             :         case SbxDOUBLE:
     225           0 :             p->nDouble = n; break;
     226             :         case SbxCURRENCY:
     227           0 :             p->nInt64 = n * CURRENCY_FACTOR; break;
     228             :         case SbxSALINT64:
     229           0 :             p->nInt64 = n; break;
     230             :         case SbxSALUINT64:
     231           0 :             p->uInt64 = n; break;
     232             :         case SbxBYREF | SbxDECIMAL:
     233           0 :             ImpCreateDecimal( p )->setChar( n );
     234           0 :             break;
     235             : 
     236             :         // from here on will be tested
     237             :         case SbxBYTE:
     238           0 :             aTmp.pByte = &p->nByte; goto direct;
     239             :         case SbxULONG:
     240           0 :             aTmp.pULong = &p->nULong; goto direct;
     241             :         case SbxERROR:
     242             :         case SbxUSHORT:
     243           0 :             aTmp.pUShort = &p->nUShort; goto direct;
     244             :         direct:
     245           0 :             aTmp.eType = SbxDataType( p->eType | SbxBYREF );
     246           0 :             p = &aTmp; goto start;
     247             : 
     248             :         case SbxBYREF | SbxSTRING:
     249             :         case SbxSTRING:
     250             :         case SbxLPSTR:
     251           0 :             if ( !p->pOUString )
     252           0 :                 p->pOUString = new ::rtl::OUString( n );
     253             :             else
     254           0 :                 *p->pOUString = ::rtl::OUString( n );
     255           0 :             break;
     256             :         case SbxOBJECT:
     257             :         {
     258           0 :             SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
     259           0 :             if( pVal )
     260           0 :                 pVal->PutChar( n );
     261             :             else
     262           0 :                 SbxBase::SetError( SbxERR_NO_OBJECT );
     263           0 :             break;
     264             :         }
     265             :         case SbxBYREF | SbxCHAR:
     266           0 :             *p->pChar = n; break;
     267             :         case SbxBYREF | SbxBYTE:
     268           0 :             *p->pByte = (sal_uInt8) n; break;
     269             :         case SbxBYREF | SbxINTEGER:
     270             :         case SbxBYREF | SbxBOOL:
     271           0 :             *p->pInteger = n; break;
     272             :         case SbxBYREF | SbxERROR:
     273             :         case SbxBYREF | SbxUSHORT:
     274           0 :             *p->pUShort = (sal_uInt16) n; break;
     275             :         case SbxBYREF | SbxLONG:
     276           0 :             *p->pLong = (sal_Int32) n; break;
     277             :         case SbxBYREF | SbxULONG:
     278           0 :             *p->pULong = (sal_uInt32) n; break;
     279             :         case SbxBYREF | SbxSINGLE:
     280           0 :             *p->pSingle = (float) n; break;
     281             :         case SbxBYREF | SbxDATE:
     282             :         case SbxBYREF | SbxDOUBLE:
     283           0 :             *p->pDouble = (double) n; break;
     284             :         case SbxBYREF | SbxCURRENCY:
     285           0 :             p->nInt64 = n * CURRENCY_FACTOR; break;
     286             :         case SbxBYREF | SbxSALINT64:
     287           0 :             *p->pnInt64 = n; break;
     288             :         case SbxBYREF | SbxSALUINT64:
     289           0 :             *p->puInt64 = n; break;
     290             : 
     291             :         default:
     292           0 :             SbxBase::SetError( SbxERR_CONVERSION );
     293             :     }
     294           0 : }
     295             : 
     296             : 
     297             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10