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/.
12 #include "rtflistener.hxx"
15 #include <unordered_map>
17 #include <com/sun/star/uno/Reference.h>
19 #include <rtl/ustring.hxx>
20 #include <tools/ref.hxx>
22 namespace com::sun::star::task
24 class XStatusIndicator
;
28 namespace writerfilter::rtftok
30 /// RTF tokenizer that separates control words from text.
31 class RTFTokenizer final
: public virtual SvRefBase
34 RTFTokenizer(RTFListener
& rImport
, SvStream
* pInStream
,
35 css::uno::Reference
<css::task::XStatusIndicator
> const& xStatusIndicator
);
36 ~RTFTokenizer() override
;
38 RTFError
resolveParse();
39 /// Number of states on the stack.
40 int getGroup() const { return m_nGroup
; }
41 /// To be invoked by the pushState() callback to signal when the importer enters a group.
43 /// To be invoked by the popState() callback to signal when the importer leaves a group.
45 OUString
getPosition();
46 std::size_t getGroupStart() const { return m_nGroupStart
; }
47 /// To look up additional properties of a math symbol.
48 static bool lookupMathKeyword(RTFMathSymbol
& rSymbol
);
51 SvStream
& Strm() { return *m_pInStream
; }
52 RTFError
resolveKeyword();
53 RTFError
dispatchKeyword(OString
const& rKeyword
, bool bParam
, int nParam
);
55 RTFListener
& m_rImport
;
56 SvStream
* m_pInStream
;
57 css::uno::Reference
<css::task::XStatusIndicator
> const& m_xStatusIndicator
;
58 // This is the same as aRTFControlWords, but mapped by token name for fast lookup
59 static std::unordered_map
<OString
, RTFSymbol
> s_aRTFControlWords
;
60 static bool s_bControlWordsInitialised
;
61 // This is the same as aRTFMathControlWords, but sorted
62 static std::vector
<RTFMathSymbol
> s_aRTFMathControlWords
;
63 static bool s_bMathControlWordsSorted
;
64 /// Same as the size of the importer's states, except that this can be negative for invalid input.
66 sal_Int32 m_nLineNumber
;
67 std::size_t m_nLineStartPos
;
68 std::size_t m_nGroupStart
;
70 } // namespace writerfilter::rtftok
72 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */