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

Generated by: LCOV version 1.10