1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SVTOOLS_SVPARSER_HXX
21 #define INCLUDED_SVTOOLS_SVPARSER_HXX
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>
32 template<typename T
> struct SvParser_Impl
;
35 enum class SvParserState
45 class SVT_DLLPUBLIC SvParser
: public SvRefBase
47 DECL_LINK( NewDataRead
, LinkParamNone
*, void );
51 OUString aToken
; // scanned token
52 sal_uLong nlLineNr
; // current line number
53 sal_uLong nlLinePos
; // current column number
55 std::unique_ptr
<SvParser_Impl
<T
>> pImplData
; // internal data
56 long m_nTokenIndex
; // current token index to detect loops for seeking backwards
57 long nTokenValue
; // additional value (RTF)
58 bool bTokenHasValue
; // indicates whether nTokenValue is valid
59 SvParserState eState
; // status also in derived classes
61 rtl_TextEncoding eSrcEnc
; // Source encoding
63 sal_uInt64 nNextChPos
;
64 sal_uInt32 nNextCh
; // current character codepoint in UTF32 for the "lex"
66 bool bUCS2BSrcEnc
: 1; // or as big-endian UCS2
67 bool bSwitchToUCS2
: 1; // switching is allowed
68 bool bRTF_InTextRead
: 1; // only for RTF-Parser!!!
80 // methods for Token stack
81 T
SkipToken( short nCnt
= -1 ); // "skip" n Tokens back
82 TokenStackType
* GetStackPtr( short nCnt
);
84 // scan the next token:
85 // work off Token stack and call GetNextToken_() if necessary.
86 // That one is responsible for the recognition of new Tokens.
88 virtual T
GetNextToken_() = 0;
90 // is called for each Token that is recognized in CallParser
91 virtual void NextToken( T nToken
) = 0;
93 // at times of SvRefBase derivation, not everybody may delete
94 virtual ~SvParser() override
;
96 void ClearTxtConvContext();
99 std::unique_ptr
<TokenStackType
[]> pTokenStack
;
100 TokenStackType
*pTokenStackPos
;
101 sal_uInt8 nTokenStackSize
, nTokenStackPos
;
104 SvParser( SvStream
& rIn
, sal_uInt8 nStackSize
= 3 );
106 virtual SvParserState
CallParser() = 0; // calling of the parser
108 SvParserState
GetStatus() const; // StatusInfo
110 sal_uLong
GetLineNr() const;
111 sal_uLong
GetLinePos() const;
113 sal_uLong
IncLinePos();
114 void SetLineNr( sal_uLong nlNum
);
115 void SetLinePos( sal_uLong nlPos
);
117 sal_uInt32
GetNextChar(); // Return next Unicode codepoint in UTF32.
118 void RereadLookahead();
120 bool IsParserWorking() const;
122 Link
<LinkParamNone
*,void> GetAsynchCallLink() const;
124 // for asynchronous reading from the SvStream
125 void SaveState( T nToken
);
127 virtual void Continue( T nToken
);
129 // Set/get source encoding. The UCS2BEncoding flag is valid if source
130 // encoding is UCS2. It specifies a big endian encoding.
131 void SetSrcEncoding( rtl_TextEncoding eSrcEnc
);
132 rtl_TextEncoding
GetSrcEncoding() const;
134 // May the character set be switched to UCS/2, if a BOM
135 // is in the first two characters of the stream?
136 void SetSwitchToUCS2( bool bSet
);
137 bool IsSwitchToUCS2() const;
139 // how many bytes a character consists of
140 sal_uInt16
GetCharSize() const;
142 T
GetSaveToken() const;
145 // build a Which-Map 'rWhichMap' from an array of WhichIds
146 // 'pWhichIds'. It has the length 'nWhichIds'.
147 // The WhichMap is not deleted.
148 SVT_DLLPUBLIC
void BuildWhichTable( std::vector
<sal_uInt16
> &rWhichMap
,
149 sal_uInt16
const *pWhichIds
,
150 sal_uInt16 nWhichIds
);
152 /*========================================================================
156 *======================================================================*/
171 SvKeyValue (const OUString
&rKey
, const OUString
&rValue
)
172 : m_aKey (rKey
), m_aValue (rValue
)
175 SvKeyValue (const SvKeyValue
&rOther
)
176 : m_aKey (rOther
.m_aKey
), m_aValue (rOther
.m_aValue
)
181 SvKeyValue
& operator= (SvKeyValue
const &rOther
)
183 m_aKey
= rOther
.m_aKey
;
184 m_aValue
= rOther
.m_aValue
;
190 const OUString
& GetKey() const { return m_aKey
; }
191 const OUString
& GetValue() const { return m_aValue
; }
194 /*========================================================================
196 * SvKeyValueIterator.
198 *======================================================================*/
200 class SVT_DLLPUBLIC SvKeyValueIterator
: public SvRefBase
203 std::unique_ptr
<Impl
> mpImpl
;
206 /** Construction/Destruction.
208 SvKeyValueIterator();
209 virtual ~SvKeyValueIterator() override
;
210 SvKeyValueIterator(const SvKeyValueIterator
&) = delete;
211 SvKeyValueIterator
& operator=( const SvKeyValueIterator
& ) = delete;
215 virtual bool GetFirst (SvKeyValue
&rKeyVal
);
216 virtual bool GetNext (SvKeyValue
&rKeyVal
);
217 virtual void Append (const SvKeyValue
&rKeyVal
);
220 typedef tools::SvRef
<SvKeyValueIterator
> SvKeyValueIteratorRef
;
222 #endif // INCLUDED_SVTOOLS_SVPARSER_HXX
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */