summaryrefslogtreecommitdiff
path: root/writerfilter/source/rtftok/rtftokenizer.hxx
blob: 319c39d04679035e5667c79a30397785674af22d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#ifndef INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFTOKENIZER_HXX
#define INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFTOKENIZER_HXX

#include "rtflistener.hxx"

#include <vector>
#include <unordered_map>

#include <com/sun/star/uno/Reference.h>

#include <rtl/ustring.hxx>
#include <tools/ref.hxx>

namespace com::sun::star::task
{
class XStatusIndicator;
}
class SvStream;

namespace writerfilter::rtftok
{
/// RTF tokenizer that separates control words from text.
class RTFTokenizer final : public virtual SvRefBase
{
public:
    RTFTokenizer(RTFListener& rImport, SvStream* pInStream,
                 css::uno::Reference<css::task::XStatusIndicator> const& xStatusIndicator);
    ~RTFTokenizer() override;

    RTFError resolveParse();
    /// Number of states on the stack.
    int getGroup() const { return m_nGroup; }
    /// To be invoked by the pushState() callback to signal when the importer enters a group.
    void pushGroup();
    /// To be invoked by the popState() callback to signal when the importer leaves a group.
    void popGroup();
    OUString getPosition();
    std::size_t getGroupStart() const { return m_nGroupStart; }
    /// To look up additional properties of a math symbol.
    static bool lookupMathKeyword(RTFMathSymbol& rSymbol);

private:
    SvStream& Strm() { return *m_pInStream; }
    RTFError resolveKeyword();
    RTFError dispatchKeyword(OString const& rKeyword, bool bParam, int nParam);

    RTFListener& m_rImport;
    SvStream* m_pInStream;
    css::uno::Reference<css::task::XStatusIndicator> const& m_xStatusIndicator;
    // This is the same as aRTFControlWords, but mapped by token name for fast lookup
    static std::unordered_map<OString, RTFSymbol> s_aRTFControlWords;
    static bool s_bControlWordsInitialised;
    // This is the same as aRTFMathControlWords, but sorted
    static std::vector<RTFMathSymbol> s_aRTFMathControlWords;
    static bool s_bMathControlWordsSorted;
    /// Same as the size of the importer's states, except that this can be negative for invalid input.
    int m_nGroup;
    sal_Int32 m_nLineNumber;
    std::size_t m_nLineStartPos;
    std::size_t m_nGroupStart;
};
} // namespace writerfilter::rtftok

#endif // INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFTOKENIZER_HXX

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */