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 .
22 #include <svtools/svtdllapi.h>
23 #include <tools/link.hxx>
24 #include <tools/ref.hxx>
25 #include <tools/long.hxx>
26 #include <rtl/textenc.h>
27 #include <rtl/ustrbuf.hxx>
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_DLLPRIVATE_LINK( NewDataRead
, LinkParamNone
*, void );
51 OUStringBuffer aToken
; // scanned token
52 sal_uInt32 nlLineNr
; // current line number
53 sal_uInt32 nlLinePos
; // current column number
54 sal_uInt32 nConversionErrors
; // count of conversion errors
56 std::unique_ptr
<SvParser_Impl
<T
>> pImplData
; // internal data
57 tools::Long m_nTokenIndex
; // current token index to detect loops for seeking backwards
58 tools::Long nTokenValue
; // additional value (RTF)
59 bool bTokenHasValue
; // indicates whether nTokenValue is valid
60 bool bFuzzing
; // indicates we are in Fuzzing mode
61 SvParserState eState
; // status also in derived classes
63 rtl_TextEncoding eSrcEnc
; // Source encoding
65 sal_uInt64 nNextChPos
;
66 sal_uInt32 nNextCh
; // current character codepoint in UTF32 for the "lex"
68 bool bSwitchToUCS2
: 1; // switching is allowed
69 bool bRTF_InTextRead
: 1; // only for RTF-Parser!!!
74 tools::Long nTokenValue
;
81 // methods for Token stack
82 T
SkipToken( short nCnt
= -1 ); // "skip" n Tokens back
83 TokenStackType
* GetStackPtr( short nCnt
);
85 // scan the next token:
86 // work off Token stack and call GetNextToken_() if necessary.
87 // That one is responsible for the recognition of new Tokens.
89 virtual T
GetNextToken_() = 0;
91 // is called for each Token that is recognized in CallParser
92 virtual void NextToken( T nToken
) = 0;
94 // at times of SvRefBase derivation, not everybody may delete
95 virtual ~SvParser() override
;
97 void ClearTxtConvContext();
100 std::unique_ptr
<TokenStackType
[]> pTokenStack
;
101 TokenStackType
*pTokenStackPos
;
102 sal_uInt8 nTokenStackSize
, nTokenStackPos
;
105 SvParser( SvStream
& rIn
, sal_uInt8 nStackSize
= 3 );
107 virtual SvParserState
CallParser() = 0; // calling of the parser
109 SvParserState
GetStatus() const; // StatusInfo
111 sal_uInt32
GetLineNr() const;
112 sal_uInt32
GetLinePos() const;
114 sal_uInt32
IncLinePos();
115 void SetLineNr( sal_uInt32 nlNum
);
116 void SetLinePos( sal_uInt32 nlPos
);
118 sal_uInt32
GetNextChar(); // Return next Unicode codepoint in UTF32.
119 void RereadLookahead();
121 bool IsParserWorking() const;
123 Link
<LinkParamNone
*,void> GetAsynchCallLink() const;
125 // for asynchronous reading from the SvStream
126 void SaveState( T nToken
);
128 virtual void Continue( T nToken
);
130 // Set/get source encoding. The UCS2BEncoding flag is valid if source
131 // encoding is UCS2. It specifies a big endian encoding.
132 void SetSrcEncoding( rtl_TextEncoding eSrcEnc
);
133 rtl_TextEncoding
GetSrcEncoding() const;
135 // May the character set be switched to UCS/2, if a BOM
136 // is in the first two characters of the stream?
137 void SetSwitchToUCS2( bool bSet
);
138 bool IsSwitchToUCS2() const;
140 // how many bytes a character consists of
141 sal_uInt16
GetCharSize() const;
143 T
GetSaveToken() const;
147 /*========================================================================
151 *======================================================================*/
166 SvKeyValue (OUString aKey
, OUString aValue
)
167 : m_aKey (std::move(aKey
)), m_aValue (std::move(aValue
))
170 SvKeyValue (const SvKeyValue
&rOther
)
171 : m_aKey (rOther
.m_aKey
), m_aValue (rOther
.m_aValue
)
176 SvKeyValue
& operator= (SvKeyValue
const &rOther
)
178 m_aKey
= rOther
.m_aKey
;
179 m_aValue
= rOther
.m_aValue
;
185 const OUString
& GetKey() const { return m_aKey
; }
186 const OUString
& GetValue() const { return m_aValue
; }
189 /*========================================================================
191 * SvKeyValueIterator.
193 *======================================================================*/
195 class SVT_DLLPUBLIC SvKeyValueIterator
: public SvRefBase
198 std::unique_ptr
<Impl
> mpImpl
;
201 /** Construction/Destruction.
203 SvKeyValueIterator();
204 virtual ~SvKeyValueIterator() override
;
205 SvKeyValueIterator(const SvKeyValueIterator
&) = delete;
206 SvKeyValueIterator
& operator=( const SvKeyValueIterator
& ) = delete;
210 virtual bool GetFirst (SvKeyValue
&rKeyVal
);
211 virtual bool GetNext (SvKeyValue
&rKeyVal
);
212 virtual void Append (const SvKeyValue
&rKeyVal
);
215 typedef tools::SvRef
<SvKeyValueIterator
> SvKeyValueIteratorRef
;
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */