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

Generated by: LCOV version 1.10