LCOV - code coverage report
Current view: top level - sc/source/filter/excel - xistring.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 67 81 82.7 %
Date: 2012-08-25 Functions: 11 12 91.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 47 101 46.5 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "xistring.hxx"
      30                 :            : #include "xlstyle.hxx"
      31                 :            : #include "xistream.hxx"
      32                 :            : #include "xiroot.hxx"
      33                 :            : 
      34                 :            : // Byte/Unicode strings =======================================================
      35                 :            : 
      36                 :            : /** All allowed flags for import. */
      37                 :            : const XclStrFlags nAllowedFlags = EXC_STR_8BITLENGTH | EXC_STR_SMARTFLAGS | EXC_STR_SEPARATEFORMATS;
      38                 :            : 
      39                 :            : // ----------------------------------------------------------------------------
      40                 :            : 
      41         [ +  - ]:        819 : XclImpString::XclImpString()
      42                 :            : {
      43                 :        819 : }
      44                 :            : 
      45                 :         48 : XclImpString::XclImpString( const String& rString ) :
      46         [ +  - ]:         48 :     maString( rString )
      47                 :            : {
      48                 :         48 : }
      49                 :            : 
      50                 :       1674 : XclImpString::~XclImpString()
      51                 :            : {
      52                 :       1674 : }
      53                 :            : 
      54                 :        819 : void XclImpString::Read( XclImpStream& rStrm, XclStrFlags nFlags )
      55                 :            : {
      56         [ +  + ]:        819 :     if( !::get_flag( nFlags, EXC_STR_SEPARATEFORMATS ) )
      57                 :        807 :         maFormats.clear();
      58                 :            : 
      59                 :            :     OSL_ENSURE( (nFlags & ~nAllowedFlags) == 0, "XclImpString::Read - unknown flag" );
      60                 :        819 :     bool b16BitLen = !::get_flag( nFlags, EXC_STR_8BITLENGTH );
      61                 :            : 
      62      [ -  +  - ]:        819 :     switch( rStrm.GetRoot().GetBiff() )
      63                 :            :     {
      64                 :            :         case EXC_BIFF2:
      65                 :            :         case EXC_BIFF3:
      66                 :            :         case EXC_BIFF4:
      67                 :            :         case EXC_BIFF5:
      68                 :            :             // no integrated formatting in BIFF2-BIFF7
      69         [ #  # ]:          0 :             maString = rStrm.ReadByteString( b16BitLen );
      70                 :          0 :         break;
      71                 :            : 
      72                 :            :         case EXC_BIFF8:
      73                 :            :         {
      74                 :            :             // --- string header ---
      75 [ +  + ][ +  - ]:        819 :             sal_uInt16 nChars = b16BitLen ? rStrm.ReaduInt16() : rStrm.ReaduInt8();
                 [ +  - ]
      76                 :        819 :             sal_uInt8 nFlagField = 0;
      77 [ -  + ][ #  # ]:        819 :             if( nChars || !::get_flag( nFlags, EXC_STR_SMARTFLAGS ) )
                 [ +  - ]
      78         [ +  - ]:        819 :                 rStrm >> nFlagField;
      79                 :            : 
      80                 :            :             bool b16Bit, bRich, bFarEast;
      81                 :            :             sal_uInt16 nRunCount;
      82                 :            :             sal_uInt32 nExtInf;
      83         [ +  - ]:        819 :             rStrm.ReadUniStringExtHeader( b16Bit, bRich, bFarEast, nRunCount, nExtInf, nFlagField );
      84                 :            :             // ignore the flags, they may be wrong
      85                 :            : 
      86                 :            :             // --- character array ---
      87 [ +  - ][ +  - ]:        819 :             maString = rStrm.ReadRawUniString( nChars, b16Bit );
                 [ +  - ]
      88                 :            : 
      89                 :            :             // --- formatting ---
      90         [ +  + ]:        819 :             if( nRunCount > 0 )
      91         [ +  - ]:        105 :                 ReadFormats( rStrm, nRunCount );
      92                 :            : 
      93                 :            :             // --- extended (FarEast) information ---
      94         [ +  - ]:        819 :             rStrm.Ignore( nExtInf );
      95                 :            :         }
      96                 :        819 :         break;
      97                 :            : 
      98                 :            :         default:
      99                 :            :             DBG_ERROR_BIFF();
     100                 :            :     }
     101                 :        819 : }
     102                 :            : 
     103                 :        318 : void XclImpString::AppendFormat( XclFormatRunVec& rFormats, sal_uInt16 nChar, sal_uInt16 nFontIdx )
     104                 :            : {
     105                 :            :     // #i33341# real life -- same character index may occur several times
     106                 :            :     OSL_ENSURE( rFormats.empty() || (rFormats.back().mnChar <= nChar), "XclImpString::AppendFormat - wrong char order" );
     107 [ +  + ][ +  - ]:        318 :     if( rFormats.empty() || (rFormats.back().mnChar < nChar) )
                 [ +  - ]
     108         [ +  - ]:        318 :         rFormats.push_back( XclFormatRun( nChar, nFontIdx ) );
     109                 :            :     else
     110                 :          0 :         rFormats.back().mnFontIdx = nFontIdx;
     111                 :        318 : }
     112                 :            : 
     113                 :          0 : void XclImpString::ReadFormats( XclImpStream& rStrm, XclFormatRunVec& rFormats )
     114                 :            : {
     115                 :          0 :     bool bBiff8 = rStrm.GetRoot().GetBiff() == EXC_BIFF8;
     116         [ #  # ]:          0 :     sal_uInt16 nRunCount = bBiff8 ? rStrm.ReaduInt16() : rStrm.ReaduInt8();
     117                 :          0 :     ReadFormats( rStrm, rFormats, nRunCount );
     118                 :          0 : }
     119                 :            : 
     120                 :        105 : void XclImpString::ReadFormats( XclImpStream& rStrm, XclFormatRunVec& rFormats, sal_uInt16 nRunCount )
     121                 :            : {
     122                 :        105 :     rFormats.clear();
     123                 :        105 :     rFormats.reserve( nRunCount );
     124                 :            :     /*  #i33341# real life -- same character index may occur several times
     125                 :            :         -> use AppendFormat() to validate formats */
     126         [ +  - ]:        105 :     if( rStrm.GetRoot().GetBiff() == EXC_BIFF8 )
     127                 :            :     {
     128         [ +  + ]:        327 :         for( sal_uInt16 nIdx = 0; nIdx < nRunCount; ++nIdx )
     129                 :            :         {
     130                 :            :             sal_uInt16 nChar, nFontIdx;
     131 [ +  - ][ +  - ]:        222 :             rStrm >> nChar >> nFontIdx;
     132         [ +  - ]:        222 :             AppendFormat( rFormats, nChar, nFontIdx );
     133                 :            :         }
     134                 :            :     }
     135                 :            :     else
     136                 :            :     {
     137         [ #  # ]:          0 :         for( sal_uInt16 nIdx = 0; nIdx < nRunCount; ++nIdx )
     138                 :            :         {
     139                 :            :             sal_uInt8 nChar, nFontIdx;
     140 [ #  # ][ #  # ]:          0 :             rStrm >> nChar >> nFontIdx;
     141         [ #  # ]:          0 :             AppendFormat( rFormats, nChar, nFontIdx );
     142                 :            :         }
     143                 :            :     }
     144                 :        105 : }
     145                 :            : 
     146                 :         48 : void XclImpString::ReadObjFormats( XclImpStream& rStrm, XclFormatRunVec& rFormats, sal_uInt16 nFormatSize )
     147                 :            : {
     148                 :            :     // number of formatting runs, each takes 8 bytes
     149                 :         48 :     sal_uInt16 nRunCount = nFormatSize / 8;
     150                 :         48 :     rFormats.clear();
     151                 :         48 :     rFormats.reserve( nRunCount );
     152         [ +  + ]:        144 :     for( sal_uInt16 nIdx = 0; nIdx < nRunCount; ++nIdx )
     153                 :            :     {
     154                 :            :         sal_uInt16 nChar, nFontIdx;
     155 [ +  - ][ +  - ]:         96 :         rStrm >> nChar >> nFontIdx;
     156         [ +  - ]:         96 :         rStrm.Ignore( 4 );
     157         [ +  - ]:         96 :         AppendFormat( rFormats, nChar, nFontIdx );
     158                 :            :     }
     159                 :         48 : }
     160                 :            : 
     161                 :            : // String iterator ============================================================
     162                 :            : 
     163                 :          6 : XclImpStringIterator::XclImpStringIterator( const XclImpString& rString ) :
     164                 :          6 :     mrText( rString.GetText() ),
     165                 :          6 :     mrFormats( rString.GetFormats() ),
     166                 :            :     mnPortion( 0 ),
     167                 :            :     mnTextBeg( 0 ),
     168                 :            :     mnTextEnd( 0 ),
     169                 :            :     mnFormatsBeg( 0 ),
     170                 :         12 :     mnFormatsEnd( 0 )
     171                 :            : {
     172                 :            :     // first portion is formatted, adjust vector index to next portion
     173 [ #  # ][ -  + ]:          6 :     if( !mrFormats.empty() && (mrFormats.front().mnChar == 0) )
                 [ -  + ]
     174                 :          0 :         ++mnFormatsEnd;
     175                 :            :     // find end position of the first portion
     176                 :          6 :     mnTextEnd = static_cast< xub_StrLen >( (mnFormatsEnd < mrFormats.size()) ?
     177         [ -  + ]:          6 :         mrFormats[ mnFormatsEnd ].mnChar : mrText.Len() );
     178                 :          6 : }
     179                 :            : 
     180                 :          6 : String XclImpStringIterator::GetPortionText() const
     181                 :            : {
     182                 :          6 :     return String( mrText, mnTextBeg, mnTextEnd - mnTextBeg );
     183                 :            : }
     184                 :            : 
     185                 :          6 : sal_uInt16 XclImpStringIterator::GetPortionFont() const
     186                 :            : {
     187         [ -  + ]:          6 :     return (mnFormatsBeg < mnFormatsEnd) ? mrFormats[ mnFormatsBeg ].mnFontIdx : EXC_FONT_NOTFOUND;
     188                 :            : }
     189                 :            : 
     190                 :          6 : XclImpStringIterator& XclImpStringIterator::operator++()
     191                 :            : {
     192         [ +  - ]:          6 :     if( Is() )
     193                 :            :     {
     194                 :          6 :         ++mnPortion;
     195 [ #  # ][ -  + ]:          6 :         do
                 [ -  + ]
     196                 :            :         {
     197                 :            :             // indexes into vector of formatting runs
     198         [ -  + ]:          6 :             if( mnFormatsBeg < mnFormatsEnd )
     199                 :          0 :                 ++mnFormatsBeg;
     200         [ -  + ]:          6 :             if( mnFormatsEnd < mrFormats.size() )
     201                 :          0 :                 ++mnFormatsEnd;
     202                 :            :             // character positions of next portion
     203                 :          6 :             mnTextBeg = mnTextEnd;
     204                 :          6 :             mnTextEnd = static_cast< xub_StrLen >( (mnFormatsEnd < mrFormats.size()) ?
     205         [ -  + ]:          6 :                 mrFormats[ mnFormatsEnd ].mnChar : mrText.Len() );
     206                 :            :         }
     207                 :          6 :         while( Is() && (mnTextBeg == mnTextEnd) );
     208                 :            :     }
     209                 :          6 :     return *this;
     210                 :            : }
     211                 :            : 
     212                 :            : // ============================================================================
     213                 :            : 
     214                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10