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 
10 #ifndef INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFTOKENIZER_HXX
11 #define INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFTOKENIZER_HXX
12 
13 #include "rtflistener.hxx"
14 
15 #include <vector>
16 #include <unordered_map>
17 
18 #include <com/sun/star/uno/Reference.h>
19 
20 #include <rtl/ustring.hxx>
21 #include <tools/ref.hxx>
22 
23 namespace com
24 {
25 namespace sun
26 {
27 namespace star
28 {
29 namespace task
30 {
31 class XStatusIndicator;
32 }
33 }
34 }
35 }
36 class SvStream;
37 
38 namespace writerfilter
39 {
40 namespace rtftok
41 {
42 /// RTF tokenizer that separates control words from text.
43 class RTFTokenizer final : public virtual SvRefBase
44 {
45 public:
46     RTFTokenizer(RTFListener& rImport, SvStream* pInStream,
47                  css::uno::Reference<css::task::XStatusIndicator> const& xStatusIndicator);
48     ~RTFTokenizer() override;
49 
50     RTFError resolveParse();
51     /// Number of states on the stack.
getGroup() const52     int getGroup() const { return m_nGroup; }
53     /// To be invoked by the pushState() callback to signal when the importer enters a group.
54     void pushGroup();
55     /// To be invoked by the popState() callback to signal when the importer leaves a group.
56     void popGroup();
57     OUString getPosition();
getGroupStart() const58     std::size_t getGroupStart() const { return m_nGroupStart; }
59     /// To look up additional properties of a math symbol.
60     static bool lookupMathKeyword(RTFMathSymbol& rSymbol);
61 
62 private:
Strm()63     SvStream& Strm() { return *m_pInStream; }
64     RTFError resolveKeyword();
65     RTFError dispatchKeyword(OString const& rKeyword, bool bParam, int nParam);
66 
67     RTFListener& m_rImport;
68     SvStream* m_pInStream;
69     css::uno::Reference<css::task::XStatusIndicator> const& m_xStatusIndicator;
70     // This is the same as aRTFControlWords, but mapped by token name for fast lookup
71     static std::unordered_map<OString, RTFSymbol> s_aRTFControlWords;
72     static bool s_bControlWordsInitialised;
73     // This is the same as aRTFMathControlWords, but sorted
74     static std::vector<RTFMathSymbol> s_aRTFMathControlWords;
75     static bool s_bMathControlWordsSorted;
76     /// Same as the size of the importer's states, except that this can be negative for invalid input.
77     int m_nGroup;
78     sal_Int32 m_nLineNumber;
79     std::size_t m_nLineStartPos;
80     std::size_t m_nGroupStart;
81 };
82 } // namespace rtftok
83 } // namespace writerfilter
84 
85 #endif // INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFTOKENIZER_HXX
86 
87 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
88