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

Generated by: LCOV version 1.10