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

Generated by: LCOV version 1.10