LCOV - code coverage report
Current view: top level - include/svtools - svparser.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 31 36 86.1 %
Date: 2015-06-13 12:38:46 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 <tools/solar.h>
      27             : #include <rtl/textenc.h>
      28             : #include <rtl/ustring.hxx>
      29             : #include <boost/noncopyable.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_LINK( NewDataRead, void* );
      48             : 
      49             : protected:
      50             :     SvStream&           rInput;
      51             :     OUString            aToken;             // scanned token
      52             :     sal_uLong           nlLineNr;           // current line number
      53             :     sal_uLong           nlLinePos;          // current column number
      54             : 
      55             :     SvParser_Impl       *pImplData;         // internal data
      56             :     long                nTokenValue;        // additional vavlue (RTF)
      57             :     bool                bTokenHasValue;     // indicates whether nTokenValue is valid
      58             :     SvParserState       eState;             // status also in derived classes
      59             : 
      60             :     rtl_TextEncoding    eSrcEnc;        // Source encoding
      61             : 
      62             :     sal_uLong nNextChPos;
      63             :     sal_Unicode nNextCh;                // current character for the "lex"
      64             : 
      65             : 
      66             :     bool                bDownloadingFile : 1; // true: An external file is
      67             :                                         // currently being loaded, i.e.
      68             :                                         // all DataAvailable Links must
      69             :                                         // be ignored.
      70             :                                         // If none of the following
      71             :                                         // flags is set, the stream
      72             :                                         // is read as ANSI, but returned
      73             :                                         // as CharSet DONTKNOW.
      74             :     bool                bUCS2BSrcEnc : 1;   // or as big-endian UCS2
      75             :     bool                bSwitchToUCS2 : 1;  // switching is allowed
      76             : 
      77             :     bool                bRTF_InTextRead : 1;  // only for RTF-Parser!!!
      78             : 
      79             :     struct TokenStackType
      80             :     {
      81             :         OUString    sToken;
      82             :         long        nTokenValue;
      83             :         bool        bTokenHasValue;
      84             :         int         nTokenId;
      85             : 
      86          51 :         TokenStackType()
      87             :             : nTokenValue(0)
      88             :             , bTokenHasValue(false)
      89          51 :             , nTokenId(0)
      90             :         {
      91          51 :         }
      92          51 :         ~TokenStackType() { }
      93             :     };
      94             : 
      95             :     // methods for Token stack
      96             :     int SkipToken( short nCnt = -1 );       // "skip" n Tokens back
      97             :     TokenStackType* GetStackPtr( short nCnt );
      98             :     inline sal_uInt8 GetStackPos() const;
      99             : 
     100             :     // scan the next token:
     101             :     //  work off Token stack and call _GetNextToken() if necessary.
     102             :     //  That one is responsible for the recognition of new Tokens.
     103             :     int GetNextToken();
     104             :     virtual int _GetNextToken() = 0;
     105             : 
     106             :     // is called for each Token that is recognized in CallParser
     107             :     virtual void NextToken( int nToken );
     108             : 
     109             :     // at times of SvRefBase derivation, not everybody may delete
     110             :     virtual ~SvParser();
     111             : 
     112             :     void ClearTxtConvContext();
     113             : 
     114             : private:
     115             :     TokenStackType* pTokenStack;
     116             :     TokenStackType *pTokenStackPos;
     117             :     sal_uInt8 nTokenStackSize, nTokenStackPos;
     118             : 
     119             : public:
     120             :     SvParser( SvStream& rIn, sal_uInt8 nStackSize = 3 );
     121             : 
     122             :     virtual  SvParserState CallParser() = 0; // calling of the parser
     123             : 
     124         687 :     inline SvParserState GetStatus() const  { return eState; }  // StatusInfo
     125             : 
     126        1889 :     inline sal_uLong    GetLineNr() const       { return nlLineNr; }
     127        1889 :     inline sal_uLong    GetLinePos() const      { return nlLinePos; }
     128        1942 :     inline sal_uLong    IncLineNr()             { return ++nlLineNr; }
     129      107943 :     inline sal_uLong    IncLinePos()            { return ++nlLinePos; }
     130             :     inline sal_uLong    SetLineNr( sal_uLong nlNum );           // inline bottom
     131             :     inline sal_uLong    SetLinePos( sal_uLong nlPos );          // inline bottom
     132             : 
     133             :     sal_Unicode GetNextChar();
     134             :     void RereadLookahead();
     135             : 
     136      132763 :     inline bool IsParserWorking() const { return SVPAR_WORKING == eState; }
     137             : 
     138           0 :     Link<> GetAsynchCallLink() const
     139           0 :         { return LINK( const_cast<SvParser*>(this), SvParser, NewDataRead ); }
     140             : 
     141             :     long CallAsyncCallLink() { return NewDataRead( 0 ); }
     142             : 
     143             :     // for asynchronous reading from the SvStream
     144             :     void SaveState( int nToken );
     145             :     void RestoreState();
     146             :     virtual void Continue( int nToken );
     147             : 
     148             :     inline void SetDownloadingFile( bool bSet ) { bDownloadingFile = bSet; }
     149           0 :     inline bool IsDownloadingFile() const { return bDownloadingFile; }
     150             : 
     151             :     // Set/get source encoding. The UCS2BEncoding flag is valid if source
     152             :     // encoding is UCS2. It specifies a big endian encoding.
     153             :     void SetSrcEncoding( rtl_TextEncoding eSrcEnc );
     154          11 :     rtl_TextEncoding GetSrcEncoding() const { return eSrcEnc; }
     155             : 
     156             :     void SetSrcUCS2BEncoding( bool bSet ) { bUCS2BSrcEnc = bSet; }
     157             :     bool IsSrcUCS2BEncoding() const { return bUCS2BSrcEnc; }
     158             : 
     159             :     // May the character set be switched to UCS/2, if a BOM
     160             :     // is in the first two characters of the stream?
     161          17 :     void SetSwitchToUCS2( bool bSet ) { bSwitchToUCS2 = bSet; }
     162             :     bool IsSwitchToUCS2() const { return bSwitchToUCS2; }
     163             : 
     164             :     // how many bytes a character consists of
     165             :     inline sal_uInt16 GetCharSize() const;
     166             : 
     167             :     int GetSaveToken() const;
     168             : 
     169             :     // build a Which-Map 'rWhichMap' from an array of WhichIds
     170             :     // 'pWhichIds'. It has the length 'nWhichIds'.
     171             :     // The WhichMap is not deleted.
     172             :     static void BuildWhichTable( std::vector<sal_uInt16> &rWhichMap,
     173             :                                sal_uInt16 *pWhichIds,
     174             :                                sal_uInt16 nWhichIds );
     175             : };
     176             : 
     177             : 
     178             : #ifndef GOODIES_DECL_SVPARSER_DEFINED
     179             : #define GOODIES_DECL_SVPARSER_DEFINED
     180             : typedef tools::SvRef<SvParser> SvParserRef;
     181             : #endif
     182             : 
     183          12 : inline sal_uLong SvParser::SetLineNr( sal_uLong nlNum )
     184          12 : {   sal_uLong nlOld = nlLineNr; nlLineNr = nlNum; return nlOld; }
     185             : 
     186        1954 : inline sal_uLong SvParser::SetLinePos( sal_uLong nlPos )
     187        1954 : {   sal_uLong nlOld = nlLinePos; nlLinePos = nlPos; return nlOld; }
     188             : 
     189             : inline sal_uInt8 SvParser::GetStackPos() const
     190             : {   return nTokenStackPos; }
     191             : 
     192           0 : inline sal_uInt16 SvParser::GetCharSize() const
     193             : {
     194           0 :     return (RTL_TEXTENCODING_UCS2 == eSrcEnc) ? 2 : 1;
     195             : }
     196             : 
     197             : 
     198             : /*========================================================================
     199             :  *
     200             :  * SvKeyValue.
     201             :  *
     202             :  *======================================================================*/
     203             : 
     204        8900 : class SvKeyValue
     205             : {
     206             :     /** Representation.
     207             :     */
     208             :     OUString m_aKey;
     209             :     OUString m_aValue;
     210             : 
     211             : public:
     212             :     /** Construction.
     213             :     */
     214        2996 :     SvKeyValue()
     215        2996 :     {}
     216             : 
     217        2960 :     SvKeyValue (const OUString &rKey, const OUString &rValue)
     218        2960 :         : m_aKey (rKey), m_aValue (rValue)
     219        2960 :     {}
     220             : 
     221        2960 :     SvKeyValue (const SvKeyValue &rOther)
     222        2960 :         : m_aKey (rOther.m_aKey), m_aValue (rOther.m_aValue)
     223        2960 :     {}
     224             : 
     225             :     /** Assignment.
     226             :     */
     227        3003 :     SvKeyValue& operator= (SvKeyValue &rOther)
     228             :     {
     229        3003 :         m_aKey   = rOther.m_aKey;
     230        3003 :         m_aValue = rOther.m_aValue;
     231        3003 :         return *this;
     232             :     }
     233             : 
     234             :     /** Operation.
     235             :     */
     236        5963 :     const OUString& GetKey() const { return m_aKey; }
     237        2977 :     const OUString& GetValue() const { return m_aValue; }
     238             : 
     239             :     void SetKey   (const OUString &rKey  ) { m_aKey = rKey; }
     240             :     void SetValue (const OUString &rValue) { m_aValue = rValue; }
     241             : };
     242             : 
     243             : /*========================================================================
     244             :  *
     245             :  * SvKeyValueIterator.
     246             :  *
     247             :  *======================================================================*/
     248             : 
     249             : class SVT_DLLPUBLIC SvKeyValueIterator : public SvRefBase,
     250             :     private boost::noncopyable
     251             : {
     252             :     struct Impl;
     253             :     Impl* mpImpl;
     254             : 
     255             : public:
     256             :     /** Construction/Destruction.
     257             :     */
     258             :     SvKeyValueIterator();
     259             :     virtual ~SvKeyValueIterator();
     260             : 
     261             :     /** Operation.
     262             :     */
     263             :     virtual bool GetFirst (SvKeyValue &rKeyVal);
     264             :     virtual bool GetNext  (SvKeyValue &rKeyVal);
     265             :     virtual void Append   (const SvKeyValue &rKeyVal);
     266             : };
     267             : 
     268             : typedef tools::SvRef<SvKeyValueIterator> SvKeyValueIteratorRef;
     269             : 
     270             : #endif // INCLUDED_SVTOOLS_SVPARSER_HXX
     271             : 
     272             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11