LCOV - code coverage report
Current view: top level - sc/source/filter/excel - xestring.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 280 0.4 %
Date: 2012-08-25 Functions: 2 58 3.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 358 0.6 %

           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                 :            : 
      30                 :            : #include <algorithm>
      31                 :            : #include <stdio.h>
      32                 :            : #include "xlstyle.hxx"
      33                 :            : #include "xestyle.hxx"
      34                 :            : #include "xestream.hxx"
      35                 :            : #include "xestring.hxx"
      36                 :            : 
      37                 :            : using namespace ::oox;
      38                 :            : 
      39                 :            : using ::rtl::OString;
      40                 :            : using ::rtl::OUString;
      41                 :            : 
      42                 :            : // ============================================================================
      43                 :            : 
      44                 :            : namespace {
      45                 :            : 
      46                 :            : // compare vectors
      47                 :            : 
      48                 :            : /** Compares two vectors.
      49                 :            :     @return  A negative value, if rLeft<rRight; or a positive value, if rLeft>rRight;
      50                 :            :     or 0, if rLeft==rRight. */
      51                 :            : template< typename Type >
      52                 :          0 : int lclCompareVectors( const ::std::vector< Type >& rLeft, const ::std::vector< Type >& rRight )
      53                 :            : {
      54                 :          0 :     int nResult = 0;
      55                 :            : 
      56                 :            :     // 1st: compare all elements of the vectors
      57                 :            :     typedef typename ::std::vector< Type >::const_iterator CIT;
      58                 :          0 :     CIT aEndL = rLeft.end(), aEndR = rRight.end();
      59 [ #  # ][ #  # ]:          0 :     for( CIT aItL = rLeft.begin(), aItR = rRight.begin(); !nResult && (aItL != aEndL) && (aItR != aEndR); ++aItL, ++aItR )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      60 [ #  # ][ #  # ]:          0 :         nResult = static_cast< int >( *aItL ) - static_cast< int >( *aItR );
         [ #  # ][ #  # ]
      61                 :            : 
      62                 :            :     // 2nd: no differences found so far -> compare the vector sizes. Shorter vector is less
      63 [ #  # ][ #  # ]:          0 :     if( !nResult )
      64                 :          0 :         nResult = static_cast< int >( rLeft.size() ) - static_cast< int >( rRight.size() );
      65                 :            : 
      66                 :          0 :     return nResult;
      67                 :            : }
      68                 :            : 
      69                 :            : // hashing helpers
      70                 :            : 
      71                 :            : /** Base class for value hashers.
      72                 :            :     @descr  These function objects are used to hash any value to a sal_uInt32 value. */
      73                 :            : template< typename Type >
      74                 :            : struct XclHasher : public ::std::unary_function< Type, sal_uInt32 > {};
      75                 :            : 
      76                 :            : template< typename Type >
      77                 :            : struct XclDirectHasher : public XclHasher< Type >
      78                 :            : {
      79                 :          0 :     inline sal_uInt32   operator()( Type nVal ) const { return nVal; }
      80                 :            : };
      81                 :            : 
      82                 :            : struct XclFormatRunHasher : public XclHasher< const XclFormatRun& >
      83                 :            : {
      84                 :          0 :     inline sal_uInt32   operator()( const XclFormatRun& rRun ) const
      85                 :          0 :                             { return (rRun.mnChar << 8) ^ rRun.mnFontIdx; }
      86                 :            : };
      87                 :            : 
      88                 :            : /** Calculates a hash value from a vector.
      89                 :            :     @descr Uses the passed hasher function object to calculate hash values from
      90                 :            :     all vector elements. */
      91                 :            : template< typename Type, typename ValueHasher >
      92                 :          0 : sal_uInt16 lclHashVector( const ::std::vector< Type >& rVec, const ValueHasher& rHasher )
      93                 :            : {
      94                 :          0 :     sal_uInt32 nHash = rVec.size();
      95                 :            :     typedef typename ::std::vector< Type >::const_iterator CIT;
      96         [ #  # ]:          0 :     for( CIT aIt = rVec.begin(), aEnd = rVec.end(); aIt != aEnd; ++aIt )
           [ #  #  #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      97 [ #  # ][ #  # ]:          0 :         (nHash *= 31) += rHasher( *aIt );
      98                 :          0 :     return static_cast< sal_uInt16 >( nHash ^ (nHash >> 16) );
      99                 :            : }
     100                 :            : 
     101                 :            : /** Calculates a hash value from a vector. Uses XclDirectHasher to hash the vector elements. */
     102                 :            : template< typename Type >
     103                 :          0 : inline sal_uInt16 lclHashVector( const ::std::vector< Type >& rVec )
     104                 :            : {
     105 [ #  # ][ #  # ]:          0 :     return lclHashVector( rVec, XclDirectHasher< Type >() );
     106                 :            : }
     107                 :            : 
     108                 :            : } // namespace
     109                 :            : 
     110                 :            : // constructors ---------------------------------------------------------------
     111                 :            : 
     112 [ #  # ][ #  # ]:          0 : XclExpString::XclExpString( XclStrFlags nFlags, sal_uInt16 nMaxLen )
     113                 :            : {
     114         [ #  # ]:          0 :     Init( 0, nFlags, nMaxLen, true );
     115                 :          0 : }
     116                 :            : 
     117 [ #  # ][ #  # ]:          0 : XclExpString::XclExpString( const String& rString, XclStrFlags nFlags, sal_uInt16 nMaxLen )
     118                 :            : {
     119         [ #  # ]:          0 :     Assign( rString, nFlags, nMaxLen );
     120                 :          0 : }
     121                 :            : 
     122 [ #  # ][ #  # ]:          0 : XclExpString::XclExpString( const OUString& rString, XclStrFlags nFlags, sal_uInt16 nMaxLen )
     123                 :            : {
     124         [ #  # ]:          0 :     Assign( rString, nFlags, nMaxLen );
     125                 :          0 : }
     126                 :            : 
     127                 :            : // assign ---------------------------------------------------------------------
     128                 :            : 
     129                 :          0 : void XclExpString::Assign( const String& rString, XclStrFlags nFlags, sal_uInt16 nMaxLen )
     130                 :            : {
     131                 :          0 :     Build( rString.GetBuffer(), rString.Len(), nFlags, nMaxLen );
     132                 :          0 : }
     133                 :            : 
     134                 :          0 : void XclExpString::Assign( const OUString& rString, XclStrFlags nFlags, sal_uInt16 nMaxLen )
     135                 :            : {
     136                 :          0 :     Build( rString.getStr(), rString.getLength(), nFlags, nMaxLen );
     137                 :          0 : }
     138                 :            : 
     139                 :          0 : void XclExpString::Assign( sal_Unicode cChar, XclStrFlags nFlags, sal_uInt16 nMaxLen )
     140                 :            : {
     141                 :          0 :     Build( &cChar, 1, nFlags, nMaxLen );
     142                 :          0 : }
     143                 :            : 
     144                 :          0 : void XclExpString::AssignByte(
     145                 :            :         const String& rString, rtl_TextEncoding eTextEnc, XclStrFlags nFlags, sal_uInt16 nMaxLen )
     146                 :            : {
     147                 :            :     // length may differ from length of rString
     148 [ #  # ][ #  # ]:          0 :     rtl::OString aByteStr(rtl::OUStringToOString(rString, eTextEnc));
     149         [ #  # ]:          0 :     Build(aByteStr.getStr(), aByteStr.getLength(), nFlags, nMaxLen);
     150                 :          0 : }
     151                 :            : 
     152                 :            : // append ---------------------------------------------------------------------
     153                 :            : 
     154                 :          0 : void XclExpString::Append( const String& rString )
     155                 :            : {
     156                 :          0 :     BuildAppend( rString.GetBuffer(), rString.Len() );
     157                 :          0 : }
     158                 :            : 
     159                 :          0 : void XclExpString::AppendByte( const String& rString, rtl_TextEncoding eTextEnc )
     160                 :            : {
     161         [ #  # ]:          0 :     if( rString.Len() > 0 )
     162                 :            :     {
     163                 :            :         // length may differ from length of rString
     164 [ #  # ][ #  # ]:          0 :         rtl::OString aByteStr(rtl::OUStringToOString(rString, eTextEnc));
     165         [ #  # ]:          0 :         BuildAppend(aByteStr.getStr(), aByteStr.getLength());
     166                 :            :     }
     167                 :          0 : }
     168                 :            : 
     169                 :          0 : void XclExpString::AppendByte( sal_Unicode cChar, rtl_TextEncoding eTextEnc )
     170                 :            : {
     171         [ #  # ]:          0 :     if( !cChar )
     172                 :            :     {
     173                 :          0 :         sal_Char cByteChar = 0;
     174         [ #  # ]:          0 :         BuildAppend( &cByteChar, 1 );
     175                 :            :     }
     176                 :            :     else
     177                 :            :     {
     178         [ #  # ]:          0 :         rtl::OString aByteStr( &cChar, 1, eTextEnc );     // length may be >1
     179         [ #  # ]:          0 :         BuildAppend( aByteStr.getStr(), aByteStr.getLength() );
     180                 :            :     }
     181                 :          0 : }
     182                 :            : 
     183                 :            : // formatting runs ------------------------------------------------------------
     184                 :            : 
     185                 :          0 : void XclExpString::AppendFormat( sal_uInt16 nChar, sal_uInt16 nFontIdx, bool bDropDuplicate )
     186                 :            : {
     187                 :            :     OSL_ENSURE( maFormats.empty() || (maFormats.back().mnChar < nChar), "XclExpString::AppendFormat - invalid char index" );
     188         [ #  # ]:          0 :     size_t nMaxSize = static_cast< size_t >( mbIsBiff8 ? EXC_STR_MAXLEN : EXC_STR_MAXLEN_8BIT );
     189 [ #  # ][ #  # ]:          0 :     if( maFormats.empty() || ((maFormats.size() < nMaxSize) && (!bDropDuplicate || (maFormats.back().mnFontIdx != nFontIdx))) )
         [ #  # ][ #  # ]
                 [ #  # ]
     190         [ #  # ]:          0 :         maFormats.push_back( XclFormatRun( nChar, nFontIdx ) );
     191                 :          0 : }
     192                 :            : 
     193                 :          0 : void XclExpString::AppendTrailingFormat( sal_uInt16 nFontIdx )
     194                 :            : {
     195                 :          0 :     AppendFormat( mnLen, nFontIdx, false );
     196                 :          0 : }
     197                 :            : 
     198                 :          0 : void XclExpString::LimitFormatCount( sal_uInt16 nMaxCount )
     199                 :            : {
     200         [ #  # ]:          0 :     if( maFormats.size() > nMaxCount )
     201 [ #  # ][ #  # ]:          0 :         maFormats.erase( maFormats.begin() + nMaxCount, maFormats.end() );
     202                 :          0 : }
     203                 :            : 
     204                 :          0 : sal_uInt16 XclExpString::RemoveLeadingFont()
     205                 :            : {
     206                 :          0 :     sal_uInt16 nFontIdx = EXC_FONT_NOTFOUND;
     207 [ #  # ][ #  # ]:          0 :     if( !maFormats.empty() && (maFormats.front().mnChar == 0) )
                 [ #  # ]
     208                 :            :     {
     209                 :          0 :         nFontIdx = maFormats.front().mnFontIdx;
     210                 :          0 :         maFormats.erase( maFormats.begin() );
     211                 :            :     }
     212                 :          0 :     return nFontIdx;
     213                 :            : }
     214                 :            : 
     215                 :          0 : bool XclExpString::IsEqual( const XclExpString& rCmp ) const
     216                 :            : {
     217                 :            :     return
     218                 :            :         (mnLen          == rCmp.mnLen)          &&
     219                 :            :         (mbIsBiff8      == rCmp.mbIsBiff8)      &&
     220                 :            :         (mbIsUnicode    == rCmp.mbIsUnicode)    &&
     221                 :            :         (mbWrapped      == rCmp.mbWrapped)      &&
     222                 :            :         (
     223                 :          0 :             ( mbIsBiff8 && (maUniBuffer  == rCmp.maUniBuffer)) ||
     224                 :          0 :             (!mbIsBiff8 && (maCharBuffer == rCmp.maCharBuffer))
     225                 :            :         ) &&
     226 [ #  # ][ #  # ]:          0 :         (maFormats      == rCmp.maFormats);
         [ #  # ][ #  # ]
           [ #  #  #  # ]
           [ #  #  #  # ]
                 [ #  # ]
     227                 :            : }
     228                 :            : 
     229                 :          0 : bool XclExpString::IsLessThan( const XclExpString& rCmp ) const
     230                 :            : {
     231                 :            :     int nResult = mbIsBiff8 ?
     232                 :          0 :         lclCompareVectors( maUniBuffer, rCmp.maUniBuffer ) :
     233         [ #  # ]:          0 :         lclCompareVectors( maCharBuffer, rCmp.maCharBuffer );
     234         [ #  # ]:          0 :     return (nResult != 0) ? (nResult < 0) : (maFormats < rCmp.maFormats);
     235                 :            : }
     236                 :            : 
     237                 :            : // get data -------------------------------------------------------------------
     238                 :            : 
     239                 :          0 : sal_uInt16 XclExpString::GetFormatsCount() const
     240                 :            : {
     241                 :          0 :     return static_cast< sal_uInt16 >( maFormats.size() );
     242                 :            : }
     243                 :            : 
     244                 :          0 : sal_uInt8 XclExpString::GetFlagField() const
     245                 :            : {
     246 [ #  # ][ #  # ]:          0 :     return (mbIsUnicode ? EXC_STRF_16BIT : 0) | (IsWriteFormats() ? EXC_STRF_RICH : 0);
     247                 :            : }
     248                 :            : 
     249                 :          0 : sal_uInt16 XclExpString::GetHeaderSize() const
     250                 :            : {
     251                 :            :     return
     252                 :            :         (mb8BitLen ? 1 : 2) +           // length field
     253                 :          0 :         (IsWriteFlags() ? 1 : 0) +      // flag field
     254 [ #  # ][ #  # ]:          0 :         (IsWriteFormats() ? 2 : 0);     // richtext formattting count
                 [ #  # ]
     255                 :            : }
     256                 :            : 
     257                 :          0 : sal_Size XclExpString::GetBufferSize() const
     258                 :            : {
     259         [ #  # ]:          0 :     return mnLen * (mbIsUnicode ? 2 : 1);
     260                 :            : }
     261                 :            : 
     262                 :          0 : sal_Size XclExpString::GetSize() const
     263                 :            : {
     264                 :            :     return
     265                 :          0 :         GetHeaderSize() +                                   // header
     266                 :          0 :         GetBufferSize() +                                   // character buffer
     267         [ #  # ]:          0 :         (IsWriteFormats() ? (4 * GetFormatsCount()) : 0);   // richtext formattting
     268                 :            : }
     269                 :            : 
     270                 :          0 : sal_uInt16 XclExpString::GetChar( sal_uInt16 nCharIdx ) const
     271                 :            : {
     272                 :            :     OSL_ENSURE( nCharIdx < Len(), "XclExpString::GetChar - invalid character index" );
     273         [ #  # ]:          0 :     return static_cast< sal_uInt16 >( mbIsBiff8 ? maUniBuffer[ nCharIdx ] : maCharBuffer[ nCharIdx ] );
     274                 :            : }
     275                 :            : 
     276                 :          0 : sal_uInt16 XclExpString::GetHash() const
     277                 :            : {
     278                 :            :     return
     279                 :          0 :         (mbIsBiff8 ? lclHashVector( maUniBuffer ) : lclHashVector( maCharBuffer )) ^
     280 [ #  # ][ #  # ]:          0 :         lclHashVector( maFormats, XclFormatRunHasher() );
     281                 :            : }
     282                 :            : 
     283                 :            : // streaming ------------------------------------------------------------------
     284                 :            : 
     285                 :          0 : void XclExpString::WriteLenField( XclExpStream& rStrm ) const
     286                 :            : {
     287         [ #  # ]:          0 :     if( mb8BitLen )
     288                 :          0 :         rStrm << static_cast< sal_uInt8 >( mnLen );
     289                 :            :     else
     290                 :          0 :         rStrm << mnLen;
     291                 :          0 : }
     292                 :            : 
     293                 :          0 : void XclExpString::WriteFlagField( XclExpStream& rStrm ) const
     294                 :            : {
     295         [ #  # ]:          0 :     if( mbIsBiff8 )
     296                 :            :     {
     297                 :          0 :         PrepareWrite( rStrm, 1 );
     298                 :          0 :         rStrm << GetFlagField();
     299                 :          0 :         rStrm.SetSliceSize( 0 );
     300                 :            :     }
     301                 :          0 : }
     302                 :            : 
     303                 :          0 : void XclExpString::WriteHeader( XclExpStream& rStrm ) const
     304                 :            : {
     305                 :            :     OSL_ENSURE( !mb8BitLen || (mnLen < 256), "XclExpString::WriteHeader - string too long" );
     306                 :          0 :     PrepareWrite( rStrm, GetHeaderSize() );
     307                 :            :     // length
     308                 :          0 :     WriteLenField( rStrm );
     309                 :            :     // flag field
     310         [ #  # ]:          0 :     if( IsWriteFlags() )
     311                 :          0 :         rStrm << GetFlagField();
     312                 :            :     // format run count
     313         [ #  # ]:          0 :     if( IsWriteFormats() )
     314                 :          0 :         rStrm << GetFormatsCount();
     315                 :          0 :     rStrm.SetSliceSize( 0 );
     316                 :          0 : }
     317                 :            : 
     318                 :          0 : void XclExpString::WriteBuffer( XclExpStream& rStrm ) const
     319                 :            : {
     320         [ #  # ]:          0 :     if( mbIsBiff8 )
     321                 :          0 :         rStrm.WriteUnicodeBuffer( maUniBuffer, GetFlagField() );
     322                 :            :     else
     323                 :          0 :         rStrm.WriteCharBuffer( maCharBuffer );
     324                 :          0 : }
     325                 :            : 
     326                 :          0 : void XclExpString::WriteFormats( XclExpStream& rStrm, bool bWriteSize ) const
     327                 :            : {
     328         [ #  # ]:          0 :     if( IsRich() )
     329                 :            :     {
     330                 :          0 :         XclFormatRunVec::const_iterator aIt = maFormats.begin(), aEnd = maFormats.end();
     331         [ #  # ]:          0 :         if( mbIsBiff8 )
     332                 :            :         {
     333         [ #  # ]:          0 :             if( bWriteSize )
     334         [ #  # ]:          0 :                 rStrm << GetFormatsCount();
     335         [ #  # ]:          0 :             rStrm.SetSliceSize( 4 );
     336 [ #  # ][ #  # ]:          0 :             for( ; aIt != aEnd; ++aIt )
     337 [ #  # ][ #  # ]:          0 :                 rStrm << aIt->mnChar << aIt->mnFontIdx;
     338                 :            :         }
     339                 :            :         else
     340                 :            :         {
     341         [ #  # ]:          0 :             if( bWriteSize )
     342         [ #  # ]:          0 :                 rStrm << static_cast< sal_uInt8 >( GetFormatsCount() );
     343         [ #  # ]:          0 :             rStrm.SetSliceSize( 2 );
     344 [ #  # ][ #  # ]:          0 :             for( ; aIt != aEnd; ++aIt )
     345 [ #  # ][ #  # ]:          0 :                 rStrm << static_cast< sal_uInt8 >( aIt->mnChar ) << static_cast< sal_uInt8 >( aIt->mnFontIdx );
     346                 :            :         }
     347         [ #  # ]:          0 :         rStrm.SetSliceSize( 0 );
     348                 :            :     }
     349                 :          0 : }
     350                 :            : 
     351                 :          0 : void XclExpString::Write( XclExpStream& rStrm ) const
     352                 :            : {
     353         [ #  # ]:          0 :     if (!mbSkipHeader)
     354                 :          0 :         WriteHeader( rStrm );
     355                 :          0 :     WriteBuffer( rStrm );
     356         [ #  # ]:          0 :     if( IsWriteFormats() )      // only in BIFF8 included in string
     357                 :          0 :         WriteFormats( rStrm );
     358                 :          0 : }
     359                 :            : 
     360                 :          0 : void XclExpString::WriteHeaderToMem( sal_uInt8* pnMem ) const
     361                 :            : {
     362                 :            :     OSL_ENSURE( pnMem, "XclExpString::WriteHeaderToMem - no memory to write to" );
     363                 :            :     OSL_ENSURE( !mb8BitLen || (mnLen < 256), "XclExpString::WriteHeaderToMem - string too long" );
     364                 :            :     OSL_ENSURE( !IsWriteFormats(), "XclExpString::WriteHeaderToMem - formatted strings not supported" );
     365                 :            :     // length
     366         [ #  # ]:          0 :     if( mb8BitLen )
     367                 :            :     {
     368                 :          0 :         *pnMem = static_cast< sal_uInt8 >( mnLen );
     369                 :          0 :         ++pnMem;
     370                 :            :     }
     371                 :            :     else
     372                 :            :     {
     373                 :          0 :         ShortToSVBT16( mnLen, pnMem );
     374                 :          0 :         pnMem += 2;
     375                 :            :     }
     376                 :            :     // flag field
     377         [ #  # ]:          0 :     if( IsWriteFlags() )
     378                 :          0 :         *pnMem = GetFlagField();
     379                 :          0 : }
     380                 :            : 
     381                 :          0 : void XclExpString::WriteBufferToMem( sal_uInt8* pnMem ) const
     382                 :            : {
     383                 :            :     OSL_ENSURE( pnMem, "XclExpString::WriteBufferToMem - no memory to write to" );
     384         [ #  # ]:          0 :     if( !IsEmpty() )
     385                 :            :     {
     386         [ #  # ]:          0 :         if( mbIsBiff8 )
     387                 :            :         {
     388 [ #  # ][ #  # ]:          0 :             for( ScfUInt16Vec::const_iterator aIt = maUniBuffer.begin(), aEnd = maUniBuffer.end(); aIt != aEnd; ++aIt )
                 [ #  # ]
     389                 :            :             {
     390         [ #  # ]:          0 :                 sal_uInt16 nChar = *aIt;
     391                 :          0 :                 *pnMem = static_cast< sal_uInt8 >( nChar );
     392                 :          0 :                 ++pnMem;
     393         [ #  # ]:          0 :                 if( mbIsUnicode )
     394                 :            :                 {
     395                 :          0 :                     *pnMem = static_cast< sal_uInt8 >( nChar >> 8 );
     396                 :          0 :                     ++pnMem;
     397                 :            :                 }
     398                 :            :             }
     399                 :            :         }
     400                 :            :         else
     401                 :          0 :             memcpy( pnMem, &maCharBuffer[ 0 ], mnLen );
     402                 :            :     }
     403                 :          0 : }
     404                 :            : 
     405                 :          0 : void XclExpString::WriteToMem( sal_uInt8* pnMem ) const
     406                 :            : {
     407                 :          0 :     WriteHeaderToMem( pnMem );
     408                 :          0 :     WriteBufferToMem( pnMem + GetHeaderSize() );
     409                 :          0 : }
     410                 :            : 
     411                 :          0 : static sal_uInt16 lcl_WriteRun( XclExpXmlStream& rStrm, const ScfUInt16Vec& rBuffer, sal_uInt16 nStart, sal_Int32 nLength, const XclExpFont* pFont )
     412                 :            : {
     413         [ #  # ]:          0 :     if( nLength == 0 )
     414                 :          0 :         return nStart;
     415                 :            : 
     416                 :          0 :     sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
     417                 :            : 
     418                 :          0 :     rWorksheet->startElement( XML_r, FSEND );
     419         [ #  # ]:          0 :     if( pFont )
     420                 :            :     {
     421                 :          0 :         const XclFontData& rFontData = pFont->GetFontData();
     422                 :          0 :         rWorksheet->startElement( XML_rPr, FSEND );
     423 [ #  # ][ #  # ]:          0 :         XclXmlUtils::WriteFontData( rWorksheet, rFontData, XML_rFont );
     424                 :          0 :         rWorksheet->endElement( XML_rPr );
     425                 :            :     }
     426                 :            :     rWorksheet->startElement( XML_t,
     427                 :            :             FSNS( XML_xml, XML_space ), "preserve",
     428                 :          0 :             FSEND );
     429         [ #  # ]:          0 :     rWorksheet->writeEscaped( XclXmlUtils::ToOUString( rBuffer, nStart, nLength ) );
     430                 :          0 :     rWorksheet->endElement( XML_t );
     431                 :          0 :     rWorksheet->endElement( XML_r );
     432                 :          0 :     return nStart + nLength;
     433                 :            : }
     434                 :            : 
     435                 :          0 : void XclExpString::WriteXml( XclExpXmlStream& rStrm ) const
     436                 :            : {
     437 [ #  # ][ #  # ]:          0 :     sax_fastparser::FSHelperPtr rWorksheet = rStrm.GetCurrentStream();
     438                 :            : 
     439         [ #  # ]:          0 :     if( !IsWriteFormats() )
     440                 :            :     {
     441         [ #  # ]:          0 :         rWorksheet->startElement( XML_t, FSEND );
     442 [ #  # ][ #  # ]:          0 :         rWorksheet->writeEscaped( XclXmlUtils::ToOUString( *this ) );
     443         [ #  # ]:          0 :         rWorksheet->endElement( XML_t );
     444                 :            :     }
     445                 :            :     else
     446                 :            :     {
     447         [ #  # ]:          0 :         XclExpFontBuffer& rFonts = rStrm.GetRoot().GetFontBuffer();
     448                 :          0 :         XclFormatRunVec::const_iterator aIt = maFormats.begin(), aEnd = maFormats.end();
     449                 :            : 
     450                 :          0 :         sal_uInt16  nStart = 0;
     451                 :          0 :         const XclExpFont* pFont = NULL;
     452 [ #  # ][ #  # ]:          0 :         for ( ; aIt != aEnd; ++aIt )
     453                 :            :         {
     454                 :          0 :             nStart = lcl_WriteRun( rStrm, GetUnicodeBuffer(),
     455         [ #  # ]:          0 :                     nStart, aIt->mnChar-nStart, pFont );
     456         [ #  # ]:          0 :             pFont = rFonts.GetFont( aIt->mnFontIdx );
     457                 :            :         }
     458                 :          0 :         lcl_WriteRun( rStrm, GetUnicodeBuffer(),
     459         [ #  # ]:          0 :                 nStart, GetUnicodeBuffer().size() - nStart, pFont );
     460         [ #  # ]:          0 :     }
     461                 :          0 : }
     462                 :            : 
     463                 :            : // ----------------------------------------------------------------------------
     464                 :            : 
     465                 :          0 : bool XclExpString::IsWriteFlags() const
     466                 :            : {
     467 [ #  # ][ #  # ]:          0 :     return mbIsBiff8 && (!IsEmpty() || !mbSmartFlags);
                 [ #  # ]
     468                 :            : }
     469                 :            : 
     470                 :          0 : bool XclExpString::IsWriteFormats() const
     471                 :            : {
     472 [ #  # ][ #  # ]:          0 :     return mbIsBiff8 && !mbSkipFormats && IsRich();
                 [ #  # ]
     473                 :            : }
     474                 :            : 
     475                 :          0 : void XclExpString::SetStrLen( sal_Int32 nNewLen )
     476                 :            : {
     477 [ #  # ][ #  # ]:          0 :     sal_uInt16 nAllowedLen = (mb8BitLen && (mnMaxLen > 255)) ? 255 : mnMaxLen;
     478                 :          0 :     mnLen = limit_cast< sal_uInt16 >( nNewLen, 0, nAllowedLen );
     479                 :          0 : }
     480                 :            : 
     481                 :          0 : void XclExpString::CharsToBuffer( const sal_Unicode* pcSource, sal_Int32 nBegin, sal_Int32 nLen )
     482                 :            : {
     483                 :            :     OSL_ENSURE( maUniBuffer.size() >= static_cast< size_t >( nBegin + nLen ),
     484                 :            :         "XclExpString::CharsToBuffer - char buffer invalid" );
     485         [ #  # ]:          0 :     ScfUInt16Vec::iterator aBeg = maUniBuffer.begin() + nBegin;
     486         [ #  # ]:          0 :     ScfUInt16Vec::iterator aEnd = aBeg + nLen;
     487                 :          0 :     const sal_Unicode* pcSrcChar = pcSource;
     488 [ #  # ][ #  # ]:          0 :     for( ScfUInt16Vec::iterator aIt = aBeg; aIt != aEnd; ++aIt, ++pcSrcChar )
                 [ #  # ]
     489                 :            :     {
     490         [ #  # ]:          0 :         *aIt = static_cast< sal_uInt16 >( *pcSrcChar );
     491 [ #  # ][ #  # ]:          0 :         if( *aIt & 0xFF00 )
     492                 :          0 :             mbIsUnicode = true;
     493                 :            :     }
     494         [ #  # ]:          0 :     if( !mbWrapped )
     495 [ #  # ][ #  # ]:          0 :         mbWrapped = ::std::find( aBeg, aEnd, EXC_LF ) != aEnd;
     496                 :          0 : }
     497                 :            : 
     498                 :          0 : void XclExpString::CharsToBuffer( const sal_Char* pcSource, sal_Int32 nBegin, sal_Int32 nLen )
     499                 :            : {
     500                 :            :     OSL_ENSURE( maCharBuffer.size() >= static_cast< size_t >( nBegin + nLen ),
     501                 :            :         "XclExpString::CharsToBuffer - char buffer invalid" );
     502         [ #  # ]:          0 :     ScfUInt8Vec::iterator aBeg = maCharBuffer.begin() + nBegin;
     503         [ #  # ]:          0 :     ScfUInt8Vec::iterator aEnd = aBeg + nLen;
     504                 :          0 :     const sal_Char* pcSrcChar = pcSource;
     505 [ #  # ][ #  # ]:          0 :     for( ScfUInt8Vec::iterator aIt = aBeg; aIt != aEnd; ++aIt, ++pcSrcChar )
                 [ #  # ]
     506         [ #  # ]:          0 :         *aIt = static_cast< sal_uInt8 >( *pcSrcChar );
     507                 :          0 :     mbIsUnicode = false;
     508         [ #  # ]:          0 :     if( !mbWrapped )
     509 [ #  # ][ #  # ]:          0 :         mbWrapped = ::std::find( aBeg, aEnd, EXC_LF_C ) != aEnd;
     510                 :          0 : }
     511                 :            : 
     512                 :          0 : void XclExpString::Init( sal_Int32 nCurrLen, XclStrFlags nFlags, sal_uInt16 nMaxLen, bool bBiff8 )
     513                 :            : {
     514                 :          0 :     mbIsBiff8 = bBiff8;
     515 [ #  # ][ #  # ]:          0 :     mbIsUnicode = bBiff8 && ::get_flag( nFlags, EXC_STR_FORCEUNICODE );
     516                 :          0 :     mb8BitLen = ::get_flag( nFlags, EXC_STR_8BITLENGTH );
     517 [ #  # ][ #  # ]:          0 :     mbSmartFlags = bBiff8 && ::get_flag( nFlags, EXC_STR_SMARTFLAGS );
     518                 :          0 :     mbSkipFormats = ::get_flag( nFlags, EXC_STR_SEPARATEFORMATS );
     519                 :          0 :     mbWrapped = false;
     520                 :          0 :     mbSkipHeader = ::get_flag( nFlags, EXC_STR_NOHEADER );
     521                 :          0 :     mnMaxLen = nMaxLen;
     522                 :          0 :     SetStrLen( nCurrLen );
     523                 :            : 
     524                 :          0 :     maFormats.clear();
     525         [ #  # ]:          0 :     if( mbIsBiff8 )
     526                 :            :     {
     527                 :          0 :         maCharBuffer.clear();
     528                 :          0 :         maUniBuffer.resize( mnLen );
     529                 :            :     }
     530                 :            :     else
     531                 :            :     {
     532                 :          0 :         maUniBuffer.clear();
     533                 :          0 :         maCharBuffer.resize( mnLen );
     534                 :            :     }
     535                 :          0 : }
     536                 :            : 
     537                 :          0 : void XclExpString::Build( const sal_Unicode* pcSource, sal_Int32 nCurrLen, XclStrFlags nFlags, sal_uInt16 nMaxLen )
     538                 :            : {
     539                 :          0 :     Init( nCurrLen, nFlags, nMaxLen, true );
     540                 :          0 :     CharsToBuffer( pcSource, 0, mnLen );
     541                 :          0 : }
     542                 :            : 
     543                 :          0 : void XclExpString::Build( const sal_Char* pcSource, sal_Int32 nCurrLen, XclStrFlags nFlags, sal_uInt16 nMaxLen )
     544                 :            : {
     545                 :          0 :     Init( nCurrLen, nFlags, nMaxLen, false );
     546                 :          0 :     CharsToBuffer( pcSource, 0, mnLen );
     547                 :          0 : }
     548                 :            : 
     549                 :          0 : void XclExpString::InitAppend( sal_Int32 nAddLen )
     550                 :            : {
     551                 :          0 :     SetStrLen( static_cast< sal_Int32 >( mnLen ) + nAddLen );
     552         [ #  # ]:          0 :     if( mbIsBiff8 )
     553                 :          0 :         maUniBuffer.resize( mnLen );
     554                 :            :     else
     555                 :          0 :         maCharBuffer.resize( mnLen );
     556                 :          0 : }
     557                 :            : 
     558                 :          0 : void XclExpString::BuildAppend( const sal_Unicode* pcSource, sal_Int32 nAddLen )
     559                 :            : {
     560                 :            :     OSL_ENSURE( mbIsBiff8, "XclExpString::BuildAppend - must not be called at byte strings" );
     561         [ #  # ]:          0 :     if( mbIsBiff8 )
     562                 :            :     {
     563                 :          0 :         sal_uInt16 nOldLen = mnLen;
     564                 :          0 :         InitAppend( nAddLen );
     565                 :          0 :         CharsToBuffer( pcSource, nOldLen, mnLen - nOldLen );
     566                 :            :     }
     567                 :          0 : }
     568                 :            : 
     569                 :          0 : void XclExpString::BuildAppend( const sal_Char* pcSource, sal_Int32 nAddLen )
     570                 :            : {
     571                 :            :     OSL_ENSURE( !mbIsBiff8, "XclExpString::BuildAppend - must not be called at unicode strings" );
     572         [ #  # ]:          0 :     if( !mbIsBiff8 )
     573                 :            :     {
     574                 :          0 :         sal_uInt16 nOldLen = mnLen;
     575                 :          0 :         InitAppend( nAddLen );
     576                 :          0 :         CharsToBuffer( pcSource, nOldLen, mnLen - nOldLen );
     577                 :            :     }
     578                 :          0 : }
     579                 :            : 
     580                 :          0 : void XclExpString::PrepareWrite( XclExpStream& rStrm, sal_uInt16 nBytes ) const
     581                 :            : {
     582         [ #  # ]:          0 :     rStrm.SetSliceSize( nBytes + (mbIsUnicode ? 2 : 1) );
     583 [ +  - ][ +  - ]:         24 : }
     584                 :            : 
     585                 :            : // ============================================================================
     586                 :            : 
     587                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10