LCOV - code coverage report
Current view: top level - sc/source/filter/inc - xestring.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 16 0.0 %
Date: 2012-08-25 Functions: 0 13 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 4 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef SC_XESTRING_HXX
      30                 :            : #define SC_XESTRING_HXX
      31                 :            : 
      32                 :            : #include "xlstring.hxx"
      33                 :            : 
      34                 :            : // ============================================================================
      35                 :            : 
      36                 :            : class XclExpStream;
      37                 :            : class XclExpXmlStream;
      38                 :            : 
      39                 :            : /** This class stores an unformatted or formatted string for Excel export.
      40                 :            : 
      41                 :            :     The class supports two completely different types of Excel strings:
      42                 :            :     1)  BIFF2-BIFF7 byte strings: The text is encoded as a 8-bit character
      43                 :            :         array. The strings cannot contain any character formatting.
      44                 :            :     2)  BIFF8 Unicode strings: The text may be stored as UCS-2 character array,
      45                 :            :         or compressed to an 8-bit array, if all characters are less than
      46                 :            :         U+0100. Unicode strings may contain a formatting array, that specifies
      47                 :            :         the used FONT record for different ranges of characters.
      48                 :            : 
      49                 :            :     The class provides full support for NUL characters in strings. On
      50                 :            :     construction or assignment the passed flags specify the behaviour of the
      51                 :            :     string while it is written to a stream (the 'Write' functions and
      52                 :            :     'operator<<').
      53                 :            :  */
      54 [ #  # ][ #  # ]:          0 : class XclExpString
      55                 :            : {
      56                 :            : public:
      57                 :            :     // constructors -----------------------------------------------------------
      58                 :            : 
      59                 :            :     /** Constructs an empty BIFF8 Unicode string.
      60                 :            :         @param nFlags  Modifiers for string export.
      61                 :            :         @param nMaxLen  The maximum number of characters to store in this string. */
      62                 :            :     explicit            XclExpString(
      63                 :            :                             XclStrFlags nFlags = EXC_STR_DEFAULT,
      64                 :            :                             sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
      65                 :            : 
      66                 :            :     /** Constructs an unformatted BIFF8 Unicode string.
      67                 :            :         @param nFlags  Modifiers for string export.
      68                 :            :         @param nMaxLen  The maximum number of characters to store in this string. */
      69                 :            :     explicit            XclExpString(
      70                 :            :                             const String& rString,
      71                 :            :                             XclStrFlags nFlags = EXC_STR_DEFAULT,
      72                 :            :                             sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
      73                 :            :     /** Constructs an unformatted BIFF8 Unicode string.
      74                 :            :         @param nFlags  Modifiers for string export.
      75                 :            :         @param nMaxLen  The maximum number of characters to store in this string. */
      76                 :            :     explicit            XclExpString(
      77                 :            :                             const ::rtl::OUString& rString,
      78                 :            :                             XclStrFlags nFlags = EXC_STR_DEFAULT,
      79                 :            :                             sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
      80                 :            : 
      81                 :            :     // assign -----------------------------------------------------------------
      82                 :            : 
      83                 :            :     /** Assigns an unformatted string, converts this object to a BIFF8 Unicode string.
      84                 :            :         @param nFlags  Modifiers for string export.
      85                 :            :         @param nMaxLen  The maximum number of characters to store in this string. */
      86                 :            :     void                Assign(
      87                 :            :                             const String& rString,
      88                 :            :                             XclStrFlags nFlags = EXC_STR_DEFAULT,
      89                 :            :                             sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
      90                 :            : 
      91                 :            :     /** Assigns an unformatted string, converts this object to a BIFF8 Unicode string.
      92                 :            :         @param nFlags  Modifiers for string export.
      93                 :            :         @param nMaxLen  The maximum number of characters to store in this string. */
      94                 :            :     void                Assign(
      95                 :            :                             const ::rtl::OUString& rString,
      96                 :            :                             XclStrFlags nFlags = EXC_STR_DEFAULT,
      97                 :            :                             sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
      98                 :            : 
      99                 :            :     /** Assigns a Unicode character, converts this object to a BIFF8 Unicode string.
     100                 :            :         @param nFlags  Modifiers for string export.
     101                 :            :         @param nMaxLen  The maximum number of characters to store in this string (for appending). */
     102                 :            :     void                Assign(
     103                 :            :                             sal_Unicode cChar,
     104                 :            :                             XclStrFlags nFlags = EXC_STR_DEFAULT,
     105                 :            :                             sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
     106                 :            : 
     107                 :            :     /** Assigns an unformatted string, converts this object to a BIFF2-BIFF7 byte string.
     108                 :            :         @param nFlags  Modifiers for string export.
     109                 :            :         @param nMaxLen  The maximum number of characters to store in this string. */
     110                 :            :     void                AssignByte(
     111                 :            :                             const String& rString,
     112                 :            :                             rtl_TextEncoding eTextEnc,
     113                 :            :                             XclStrFlags nFlags = EXC_STR_DEFAULT,
     114                 :            :                             sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
     115                 :            : 
     116                 :            :     // append -----------------------------------------------------------------
     117                 :            : 
     118                 :            :     /** Appends a string. Uses the string flags used in constructor or last Assign().
     119                 :            :         @descr  This object must be a BIFF8 Unicode string. */
     120                 :            :     void                Append( const String& rString );
     121                 :            : 
     122                 :            :     /** Appends a string. Uses the string flags used in constructor or last Assign().
     123                 :            :         @descr  This object must be a BIFF2-BIFF7 byte string. */
     124                 :            :     void                AppendByte( const String& rString, rtl_TextEncoding eTextEnc );
     125                 :            :     /** Appends a character. Uses the string flags used in constructor or last Assign().
     126                 :            :         @descr  This object must be a BIFF2-BIFF7 byte string. */
     127                 :            :     void                AppendByte( sal_Unicode cChar, rtl_TextEncoding eTextEnc );
     128                 :            : 
     129                 :            :     // formatting runs --------------------------------------------------------
     130                 :            : 
     131                 :            :     /** Appends a formatting run. nChar must be greater than last contained character index. */
     132                 :            :     void                AppendFormat( sal_uInt16 nChar, sal_uInt16 nFontIdx, bool bDropDuplicate = true );
     133                 :            :     /** Appends a trailing formatting run with the passed font index. */
     134                 :            :     void                AppendTrailingFormat( sal_uInt16 nFontIdx );
     135                 :            :     /** Removes formatting runs at the end, if the string contains too much. */
     136                 :            :     void                LimitFormatCount( sal_uInt16 nMaxCount );
     137                 :            :     /** Removes and returns the font index for the first char from the formatting runs, otherwise EXC_FONT_NOTFOUND. */
     138                 :            :     sal_uInt16          RemoveLeadingFont();
     139                 :            : 
     140                 :            :     // get data ---------------------------------------------------------------
     141                 :            : 
     142                 :            :     /** Returns the character count of the string. */
     143                 :          0 :     inline sal_uInt16   Len() const { return mnLen; }
     144                 :            :     /** Returns true, if the string is empty. */
     145                 :          0 :     inline bool         IsEmpty() const { return mnLen == 0; }
     146                 :            :     /** Returns true, if the string contains line breaks. */
     147                 :          0 :     inline bool         IsWrapped() const { return mbWrapped; }
     148                 :            :     /** Returns true, if this string is equal to the passed string. */
     149                 :            :     bool                IsEqual( const XclExpString& rCmp ) const;
     150                 :            :     /** Returns true, if this string is less than the passed string. */
     151                 :            :     bool                IsLessThan( const XclExpString& rCmp ) const;
     152                 :            : 
     153                 :            :     /** Returns true, if the string contains formatting information. */
     154                 :          0 :     inline bool         IsRich() const { return !maFormats.empty(); }
     155                 :            :     /** Returns the current count of formatting runs for rich strings. */
     156                 :            :     sal_uInt16          GetFormatsCount() const;
     157                 :            :     /** Returns the vector with all formatting runs. */
     158                 :          0 :     inline const XclFormatRunVec& GetFormats() const { return maFormats; }
     159                 :            : 
     160                 :            :     /** Returns the current string flags field to export. */
     161                 :            :     sal_uInt8           GetFlagField() const;
     162                 :            :     /** Returns the byte count the header will take on export. */
     163                 :            :     sal_uInt16          GetHeaderSize() const;
     164                 :            :     /** Returns the byte count the character buffer will take on export. */
     165                 :            :     sal_Size            GetBufferSize() const;
     166                 :            :     /** Returns the byte count the whole string will take on export. */
     167                 :            :     sal_Size            GetSize() const;
     168                 :            : 
     169                 :            :     /** Returns the specified character from the (already encoded) string. */
     170                 :            :     sal_uInt16          GetChar( sal_uInt16 nCharIdx ) const;
     171                 :            :     /** Returns a hash value for the string. */
     172                 :            :     sal_uInt16          GetHash() const;
     173                 :            : 
     174                 :          0 :     const ScfUInt16Vec& GetUnicodeBuffer() const { return maUniBuffer; }
     175                 :            : 
     176                 :            :     // streaming --------------------------------------------------------------
     177                 :            : 
     178                 :            :     /** Writes the string length field (1 byte or 2 bytes). */
     179                 :            :     void                WriteLenField( XclExpStream& rStrm ) const;
     180                 :            :     /** Writes the string flags field (1 byte). */
     181                 :            :     void                WriteFlagField( XclExpStream& rStrm ) const;
     182                 :            :     /** Writes 8-bit or 16-bit length field and string flags field. */
     183                 :            :     void                WriteHeader( XclExpStream& rStrm ) const;
     184                 :            :     /** Writes the raw character buffer. */
     185                 :            :     void                WriteBuffer( XclExpStream& rStrm ) const;
     186                 :            :     /** Writes the raw formatting run buffer. */
     187                 :            :     void                WriteFormats( XclExpStream& rStrm, bool bWriteSize = false ) const;
     188                 :            :     /** Writes the complete Unicode string. */
     189                 :            :     void                Write( XclExpStream& rStrm ) const;
     190                 :            : 
     191                 :            :     /** Writes the string header to memory. */
     192                 :            :     void                WriteHeaderToMem( sal_uInt8* pnMem ) const;
     193                 :            :     /** Writes the raw character buffer to memory (8-bit or 16-bit little-endian). */
     194                 :            :     void                WriteBufferToMem( sal_uInt8* pnMem ) const;
     195                 :            :     /** Writes the entire string to memory. */
     196                 :            :     void                WriteToMem( sal_uInt8* pnMem ) const;
     197                 :            : 
     198                 :            :     void                WriteXml( XclExpXmlStream& rStrm ) const;
     199                 :            : 
     200                 :            :     // ------------------------------------------------------------------------
     201                 :            : private:
     202                 :            :     /** Returns true, if the flag field should be written. */
     203                 :            :     bool                IsWriteFlags() const;
     204                 :            :     /** Returns true, if the formatting run vector should be written. */
     205                 :            :     bool                IsWriteFormats() const;
     206                 :            : 
     207                 :            :     /** Sets the string length but regards the limit given in mnMaxLen. */
     208                 :            :     void                SetStrLen( sal_Int32 nNewLen );
     209                 :            :     /** Inserts the passed character array into the internal character buffer.
     210                 :            :         @param nBegin  First index in internal buffer to fill.
     211                 :            :         @param nLen  Number of characters to insert. */
     212                 :            :     void                CharsToBuffer( const sal_Unicode* pcSource, sal_Int32 nBegin, sal_Int32 nLen );
     213                 :            :     /** Inserts the passed character array into the internal character buffer.
     214                 :            :         @param nBegin  First index in internal buffer to fill.
     215                 :            :         @param nLen  Number of characters to insert. */
     216                 :            :     void                CharsToBuffer( const sal_Char* pcSource, sal_Int32 nBegin, sal_Int32 nLen );
     217                 :            : 
     218                 :            :     /** Initializes flags, string length, and resizes character buffer.
     219                 :            :         @param nFlags  Modifiers for string export.
     220                 :            :         @param nCurrLen  The requested number of characters for the string.
     221                 :            :         @param nMaxLen  The maximum length allowed of the resulting string.
     222                 :            :         @param bBiff8  true = BIFF8 Unicode string; false = BIFF2-BIFF7 byte string. */
     223                 :            :     void                Init( sal_Int32 nCurrLen, XclStrFlags nFlags, sal_uInt16 nMaxLen, bool bBiff8 );
     224                 :            :     /** Creates the character buffer from the given Unicode array.
     225                 :            :         @param pcSource  The source character buffer. Trailing NUL character is not necessary.
     226                 :            :         @param nFlags  Modifiers for string export.
     227                 :            :         @param nCurrLen  The real count of characters contained in the passed buffer.
     228                 :            :         @param nMaxLen  The maximum length allowed of the resulting string. */
     229                 :            :     void                Build(
     230                 :            :                             const sal_Unicode* pcSource, sal_Int32 nCurrLen,
     231                 :            :                             XclStrFlags nFlags, sal_uInt16 nMaxLen );
     232                 :            :     /** Creates the character buffer from the given character array.
     233                 :            :         @param pcSource  The source character buffer. Trailing NUL character is not necessary.
     234                 :            :         @param nFlags  Modifiers for string export.
     235                 :            :         @param nCurrLen  The real count of characters contained in the passed buffer.
     236                 :            :         @param nMaxLen  The maximum length allowed of the resulting string. */
     237                 :            :     void                Build(
     238                 :            :                             const sal_Char* pcSource, sal_Int32 nCurrLen,
     239                 :            :                             XclStrFlags nFlags, sal_uInt16 nMaxLen );
     240                 :            : 
     241                 :            :     /** Initializes string length and resizes character buffers for appending operation.
     242                 :            :         @param nAddLen  The number of characters to be appended. */
     243                 :            :     void                InitAppend( sal_Int32 nAddLen );
     244                 :            :     /** Appends the given Unicode array to the character buffer.
     245                 :            :         @param pcSource  The source character buffer. Trailing NUL character is not necessary.
     246                 :            :         @param nAddLen  The real count of characters contained in the passed buffer. */
     247                 :            :     void                BuildAppend( const sal_Unicode* pcSource, sal_Int32 nAddLen );
     248                 :            :     /** Appends the given character array to the character buffer.
     249                 :            :         @param pcSource  The source character buffer. Trailing NUL character is not necessary.
     250                 :            :         @param nAddLen  The real count of characters contained in the passed buffer. */
     251                 :            :     void                BuildAppend( const sal_Char* pcSource, sal_Int32 nAddLen );
     252                 :            : 
     253                 :            :     /** Initializes write process on stream. */
     254                 :            :     void                PrepareWrite( XclExpStream& rStrm, sal_uInt16 nBytes ) const;
     255                 :            : 
     256                 :            : private:
     257                 :            :     ScfUInt16Vec        maUniBuffer;    /// The Unicode character buffer.
     258                 :            :     ScfUInt8Vec         maCharBuffer;   /// The byte character buffer.
     259                 :            :     XclFormatRunVec     maFormats;      /// All formatting runs.
     260                 :            :     sal_uInt16          mnLen;          /// Character count to export.
     261                 :            :     sal_uInt16          mnMaxLen;       /// Maximum allowed number of characters.
     262                 :            :     bool                mbIsBiff8;      /// true = BIFF8 Unicode string, false = BIFF2-7 bytestring.
     263                 :            :     bool                mbIsUnicode;    /// true, if at least one character is >0xFF.
     264                 :            :     bool                mb8BitLen;      /// true = write 8-bit string length; false = 16-bit.
     265                 :            :     bool                mbSmartFlags;   /// true = omit flags on empty string; false = always write flags.
     266                 :            :     bool                mbSkipFormats;  /// true = skip formats on export; false = write complete formatted string.
     267                 :            :     bool                mbWrapped;      /// true = text contains several paragraphs.
     268                 :            :     bool                mbSkipHeader;   /// ture = skip length and flags when writing string bytes.
     269                 :            : };
     270                 :            : 
     271                 :          0 : inline bool operator==( const XclExpString& rLeft, const XclExpString& rRight )
     272                 :            : {
     273                 :          0 :     return rLeft.IsEqual( rRight );
     274                 :            : }
     275                 :            : 
     276                 :          0 : inline bool operator!=( const XclExpString& rLeft, const XclExpString& rRight )
     277                 :            : {
     278                 :          0 :     return !(rLeft == rRight);
     279                 :            : }
     280                 :            : 
     281                 :          0 : inline bool operator<( const XclExpString& rLeft, const XclExpString& rRight )
     282                 :            : {
     283                 :          0 :     return rLeft.IsLessThan( rRight );
     284                 :            : }
     285                 :            : 
     286                 :          0 : inline XclExpStream& operator<<( XclExpStream& rStrm, const XclExpString& rString )
     287                 :            : {
     288                 :          0 :     rString.Write( rStrm );
     289                 :          0 :     return rStrm;
     290                 :            : }
     291                 :            : 
     292                 :            : // ============================================================================
     293                 :            : 
     294                 :            : #endif
     295                 :            : 
     296                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10