LCOV - code coverage report
Current view: top level - solver/unxlngi6.pro/inc/svtools - svparser.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 31 40 77.5 %
Date: 2012-08-25 Functions: 28 34 82.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 12 31 38.7 %

           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 _SVPARSER_HXX
      30                 :            : #define _SVPARSER_HXX
      31                 :            : 
      32                 :            : #include "svtools/svtdllapi.h"
      33                 :            : #include <tools/link.hxx>
      34                 :            : #include <tools/string.hxx>
      35                 :            : #include <tools/ref.hxx>
      36                 :            : #include <rtl/textenc.h>
      37                 :            : #include <boost/ptr_container/ptr_vector.hpp>
      38                 :            : #include <boost/utility.hpp>
      39                 :            : #include <vector>
      40                 :            : 
      41                 :            : struct SvParser_Impl;
      42                 :            : class SvStream;
      43                 :            : 
      44                 :            : enum SvParserState
      45                 :            : {
      46                 :            :     SVPAR_ACCEPTED = 0,
      47                 :            :     SVPAR_NOTSTARTED,
      48                 :            :     SVPAR_WORKING,
      49                 :            :     SVPAR_PENDING,
      50                 :            :     SVPAR_WAITFORDATA,
      51                 :            :     SVPAR_ERROR
      52                 :            : };
      53                 :            : 
      54                 :            : class SVT_DLLPUBLIC SvParser : public SvRefBase
      55                 :            : {
      56                 :            :     DECL_STATIC_LINK( SvParser, NewDataRead, void* );
      57                 :            : 
      58                 :            : protected:
      59                 :            :     SvStream&       rInput;
      60                 :            :     String          aToken;             // gescanntes Token
      61                 :            :     sal_uLong           nlLineNr;           // akt. Zeilen Nummer
      62                 :            :     sal_uLong           nlLinePos;          // akt. Spalten Nummer
      63                 :            : 
      64                 :            :     SvParser_Impl   *pImplData;         // interne Daten
      65                 :            :     long            nTokenValue;        // zusaetzlicher Wert (RTF)
      66                 :            :     sal_Bool            bTokenHasValue;     // indicates whether nTokenValue is valid
      67                 :            :     SvParserState   eState;             // Status auch in abgl. Klassen
      68                 :            : 
      69                 :            :     rtl_TextEncoding    eSrcEnc;        // Source encoding
      70                 :            : 
      71                 :            :     sal_uLong nNextChPos;
      72                 :            :     sal_Unicode nNextCh;                // Akt. Zeichen fuer die "lex"
      73                 :            : 
      74                 :            : 
      75                 :            :     sal_Bool            bDownloadingFile : 1;// sal_True: Es wird gerade ein externes
      76                 :            :                                         //       File geladen. d.h. alle
      77                 :            :                                         //       DataAvailable Links muessen
      78                 :            :                                         //       ignoriert werden.
      79                 :            :                                         // Wenn keibes der folgenden
      80                 :            :                                         // Flags gesetzt ist, wird der
      81                 :            :                                         // Stream als ANSI gelesen,
      82                 :            :                                         // aber als CharSet DONTKNOW
      83                 :            :                                         // zurueckgegeben.
      84                 :            :     sal_Bool            bUCS2BSrcEnc : 1;   // oder als big-endian UCS2
      85                 :            :     sal_Bool            bSwitchToUCS2 : 1;  // Umschalten des ist erlaubt
      86                 :            : 
      87                 :            :     sal_Bool            bRTF_InTextRead : 1;  // only for RTF-Parser!!!
      88                 :            : 
      89                 :            :     struct TokenStackType
      90                 :            :     {
      91                 :            :         String  sToken;
      92                 :            :         long    nTokenValue;
      93                 :            :         sal_Bool    bTokenHasValue;
      94                 :            :         int     nTokenId;
      95                 :            : 
      96                 :         21 :         inline TokenStackType() { nTokenId = 0; }
      97                 :         21 :         inline ~TokenStackType() { }
      98                 :            :     };
      99                 :            : 
     100                 :            :     // Methoden fuer Token-Stack
     101                 :            :     int SkipToken( short nCnt = -1 );       // n Tokens zurueck "skippen"
     102                 :            :     TokenStackType* GetStackPtr( short nCnt );
     103                 :            :     inline sal_uInt8 GetStackPos() const;
     104                 :            : 
     105                 :            :     // scanne das naechste Token:
     106                 :            :     //  Tokenstack abarbeiten und ggfs. _GetNextToken() rufen. Diese
     107                 :            :     //  ist fuers erkennen von neuen Token verantwortlich
     108                 :            :     int GetNextToken();
     109                 :            :     virtual int _GetNextToken() = 0;
     110                 :            : 
     111                 :            :     // wird fuer jedes Token gerufen, das in CallParser erkannt wird
     112                 :            :     virtual void NextToken( int nToken );
     113                 :            : 
     114                 :            :     // zu Zeiten der SvRefBase-Ableitung darf nicht jeder loeschen
     115                 :            :     virtual ~SvParser();
     116                 :            : 
     117                 :            :     void ClearTxtConvContext();
     118                 :            : 
     119                 :            : private:
     120                 :            :     TokenStackType* pTokenStack;
     121                 :            :     TokenStackType *pTokenStackPos;
     122                 :            :     sal_uInt8 nTokenStackSize, nTokenStackPos;
     123                 :            : 
     124                 :            : public:
     125                 :            :     // Konstruktor
     126                 :            :     SvParser( SvStream& rIn, sal_uInt8 nStackSize = 3 );
     127                 :            : 
     128                 :            :     virtual  SvParserState CallParser() = 0;    // Aufruf des Parsers
     129                 :            : 
     130                 :          4 :     inline SvParserState GetStatus() const  { return eState; }  // StatusInfo
     131                 :            : 
     132                 :        100 :     inline sal_uLong    GetLineNr() const       { return nlLineNr; }
     133                 :        100 :     inline sal_uLong    GetLinePos() const      { return nlLinePos; }
     134                 :         66 :     inline sal_uLong    IncLineNr()             { return ++nlLineNr; }
     135                 :       1831 :     inline sal_uLong    IncLinePos()            { return ++nlLinePos; }
     136                 :            :     inline sal_uLong    SetLineNr( sal_uLong nlNum );           // inline unten
     137                 :            :     inline sal_uLong    SetLinePos( sal_uLong nlPos );          // inline unten
     138                 :            : 
     139                 :            :     sal_Unicode GetNextChar();
     140                 :            :     void RereadLookahead();
     141                 :            : 
     142                 :       2029 :     inline int  IsParserWorking() const { return SVPAR_WORKING == eState; }
     143                 :            : 
     144                 :          0 :     Link GetAsynchCallLink() const
     145                 :          0 :         { return STATIC_LINK( this, SvParser, NewDataRead ); }
     146                 :            : 
     147                 :            :     long CallAsyncCallLink() { return NewDataRead( this, 0 ); }
     148                 :            : 
     149                 :            :     // fuers asynchrone lesen aus dem SvStream
     150                 :            :     /*virtual*/ void SaveState( int nToken );
     151                 :            :     /*virtual*/ void RestoreState();
     152                 :            :     virtual void Continue( int nToken );
     153                 :            : 
     154                 :            :     inline void SetDownloadingFile( sal_Bool bSet ) { bDownloadingFile = bSet; }
     155                 :          0 :     inline sal_Bool IsDownloadingFile() const { return bDownloadingFile; }
     156                 :            : 
     157                 :            :     // Set/get source encoding. The UCS2BEncoding flag is valid if source
     158                 :            :     // encoding is UCS2. It specifies a big endian encoding.
     159                 :            :     void SetSrcEncoding( rtl_TextEncoding eSrcEnc );
     160                 :          2 :     rtl_TextEncoding GetSrcEncoding() const { return eSrcEnc; }
     161                 :            : 
     162                 :            :     void SetSrcUCS2BEncoding( sal_Bool bSet ) { bUCS2BSrcEnc = bSet; }
     163                 :            :     sal_Bool IsSrcUCS2BEncoding() const { return bUCS2BSrcEnc; }
     164                 :            : 
     165                 :            :     // Darf der Zeichensatz auf UCS/2 umgeschaltet werden, wenn
     166                 :            :     // in den ersten beiden Zeichen im Stream eine BOM steht?
     167                 :          5 :     void SetSwitchToUCS2( sal_Bool bSet ) { bSwitchToUCS2 = bSet; }
     168                 :            :     sal_Bool IsSwitchToUCS2() const { return bSwitchToUCS2; }
     169                 :            : 
     170                 :            :     // Aus wie vielen Bytes betseht ein Zeichen
     171                 :            :     inline sal_uInt16 GetCharSize() const;
     172                 :            : 
     173                 :            :     int GetSaveToken() const;
     174                 :            : 
     175                 :            :     // Aufbau einer Which-Map 'rWhichMap' aus einem Array von
     176                 :            :     // 'pWhichIds' von Which-Ids. Es hat die Lange 'nWhichIds'.
     177                 :            :     // Die Which-Map wird nicht geloescht.
     178                 :            :     static void BuildWhichTbl( std::vector<sal_uInt16> &rWhichMap,
     179                 :            :                                sal_uInt16 *pWhichIds,
     180                 :            :                                sal_uInt16 nWhichIds );
     181                 :            : };
     182                 :            : 
     183                 :            : 
     184                 :            : #ifndef GOODIES_DECL_SVPARSER_DEFINED
     185                 :            : #define GOODIES_DECL_SVPARSER_DEFINED
     186                 :          2 : SV_DECL_REF(SvParser)
     187                 :            : #endif
     188 [ +  - ][ +  - ]:          4 : SV_IMPL_REF(SvParser)
     189                 :            : 
     190                 :            : 
     191                 :            : 
     192                 :          0 : inline sal_uLong SvParser::SetLineNr( sal_uLong nlNum )
     193                 :          0 : {   sal_uLong nlOld = nlLineNr; nlLineNr = nlNum; return nlOld; }
     194                 :            : 
     195                 :         50 : inline sal_uLong SvParser::SetLinePos( sal_uLong nlPos )
     196                 :         50 : {   sal_uLong nlOld = nlLinePos; nlLinePos = nlPos; return nlOld; }
     197                 :            : 
     198                 :          0 : inline sal_uInt8 SvParser::GetStackPos() const
     199                 :          0 : {   return nTokenStackPos; }
     200                 :            : 
     201                 :          0 : inline sal_uInt16 SvParser::GetCharSize() const
     202                 :            : {
     203         [ #  # ]:          0 :     return (RTL_TEXTENCODING_UCS2 == eSrcEnc) ? 2 : 1;
     204                 :            : }
     205                 :            : 
     206                 :            : 
     207                 :            : /*========================================================================
     208                 :            :  *
     209                 :            :  * SvKeyValue.
     210                 :            :  *
     211                 :            :  *======================================================================*/
     212                 :            : 
     213                 :       9756 : SV_DECL_REF(SvKeyValueIterator)
     214                 :            : 
     215         [ +  - ]:       2575 : class SvKeyValue
     216                 :            : {
     217                 :            :     /** Representation.
     218                 :            :     */
     219                 :            :     String m_aKey;
     220                 :            :     String m_aValue;
     221                 :            : 
     222                 :            : public:
     223                 :            :     /** Construction.
     224                 :            :     */
     225                 :        896 :     SvKeyValue (void)
     226         [ +  - ]:        896 :     {}
     227                 :            : 
     228                 :        891 :     SvKeyValue (const String &rKey, const String &rValue)
     229         [ +  - ]:        891 :         : m_aKey (rKey), m_aValue (rValue)
     230                 :        891 :     {}
     231                 :            : 
     232                 :       1369 :     SvKeyValue (const SvKeyValue &rOther)
     233         [ +  - ]:       1369 :         : m_aKey (rOther.m_aKey), m_aValue (rOther.m_aValue)
     234                 :       1369 :     {}
     235                 :            : 
     236                 :            :     /** Assignment.
     237                 :            :     */
     238                 :       1380 :     SvKeyValue& operator= (SvKeyValue &rOther)
     239                 :            :     {
     240                 :       1380 :         m_aKey   = rOther.m_aKey;
     241                 :       1380 :         m_aValue = rOther.m_aValue;
     242                 :       1380 :         return *this;
     243                 :            :     }
     244                 :            : 
     245                 :            :     /** Operation.
     246                 :            :     */
     247                 :       1791 :     const String& GetKey   (void) const { return m_aKey; }
     248                 :        896 :     const String& GetValue (void) const { return m_aValue; }
     249                 :            : 
     250                 :            :     void SetKey   (const String &rKey  ) { m_aKey = rKey; }
     251                 :            :     void SetValue (const String &rValue) { m_aValue = rValue; }
     252                 :            : };
     253                 :            : 
     254                 :            : /*========================================================================
     255                 :            :  *
     256                 :            :  * SvKeyValueIterator.
     257                 :            :  *
     258                 :            :  *======================================================================*/
     259                 :            : 
     260                 :            : typedef boost::ptr_vector<SvKeyValue> SvKeyValueList_Impl;
     261                 :            : 
     262                 :            : class SVT_DLLPUBLIC SvKeyValueIterator : public SvRefBase,
     263                 :            :     private boost::noncopyable
     264                 :            : {
     265                 :            :     /** Representation.
     266                 :            :     */
     267                 :            :     SvKeyValueList_Impl* m_pList;
     268                 :            :     sal_uInt16               m_nPos;
     269                 :            : 
     270                 :            : public:
     271                 :            :     /** Construction/Destruction.
     272                 :            :     */
     273                 :            :     SvKeyValueIterator (void);
     274                 :            :     virtual ~SvKeyValueIterator (void);
     275                 :            : 
     276                 :            :     /** Operation.
     277                 :            :     */
     278                 :            :     virtual sal_Bool GetFirst (SvKeyValue &rKeyVal);
     279                 :            :     virtual sal_Bool GetNext  (SvKeyValue &rKeyVal);
     280                 :            :     virtual void Append   (const SvKeyValue &rKeyVal);
     281                 :            : };
     282                 :            : 
     283      [ +  -  # ]:       9445 : SV_IMPL_REF(SvKeyValueIterator);
         [ -  + ][ #  # ]
           [ +  +  #  # ]
         [ +  - ][ -  + ]
                 [ #  # ]
     284                 :            : 
     285                 :            : #endif //_SVPARSER_HXX
     286                 :            : 
     287                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10