Avoid potential negative array index access to cached text.
[LibreOffice.git] / writerfilter / source / rtftok / rtflookahead.cxx
blob033feacce69d7ee08c47f74fec76775842870b32
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include "rtflookahead.hxx"
11 #include <com/sun/star/uno/Reference.hxx>
12 #include <tools/stream.hxx>
13 #include "rtftokenizer.hxx"
15 namespace com::sun::star::task
17 class XStatusIndicator;
20 using namespace com::sun::star;
22 namespace writerfilter::rtftok
24 RTFLookahead::RTFLookahead(SvStream& rStream, sal_uInt64 nGroupStart)
25 : m_rStream(rStream)
26 , m_bHasTable(false)
27 , m_bHasColumns(false)
29 sal_uInt64 const nPos = m_rStream.Tell();
30 m_rStream.Seek(nGroupStart);
31 uno::Reference<task::XStatusIndicator> xStatusIndicator;
32 m_pTokenizer = new RTFTokenizer(*this, &m_rStream, xStatusIndicator);
33 m_pTokenizer->resolveParse();
34 m_rStream.Seek(nPos);
37 RTFLookahead::~RTFLookahead() = default;
39 RTFError RTFLookahead::dispatchDestination(RTFKeyword /*nKeyword*/) { return RTFError::OK; }
41 RTFError RTFLookahead::dispatchFlag(RTFKeyword nKeyword)
43 if (nKeyword == RTFKeyword::INTBL)
44 m_bHasTable = true;
45 return RTFError::OK;
48 RTFError RTFLookahead::dispatchSymbol(RTFKeyword /*nKeyword*/) { return RTFError::OK; }
50 RTFError RTFLookahead::dispatchToggle(RTFKeyword /*nKeyword*/, bool /*bParam*/, int /*nParam*/)
52 return RTFError::OK;
55 RTFError RTFLookahead::dispatchValue(RTFKeyword nKeyword, int nParam)
57 if (nKeyword == RTFKeyword::COLS && nParam >= 2)
58 m_bHasColumns = true;
59 return RTFError::OK;
62 RTFError RTFLookahead::resolveChars(char ch)
64 while (!m_rStream.eof() && (ch != '{' && ch != '}' && ch != '\\'))
65 m_rStream.ReadChar(ch);
66 if (!m_rStream.eof())
67 m_rStream.SeekRel(-1);
68 return RTFError::OK;
71 RTFError RTFLookahead::pushState()
73 m_pTokenizer->pushGroup();
74 return RTFError::OK;
77 RTFError RTFLookahead::popState()
79 m_pTokenizer->popGroup();
80 return RTFError::OK;
83 Destination RTFLookahead::getDestination() { return Destination::NORMAL; }
85 void RTFLookahead::setDestination(Destination /*eDestination*/) {}
87 RTFInternalState RTFLookahead::getInternalState() { return RTFInternalState::NORMAL; }
89 void RTFLookahead::setInternalState(RTFInternalState /*nInternalState*/) {}
91 bool RTFLookahead::getSkipUnknown() { return false; }
93 void RTFLookahead::setSkipUnknown(bool /*bSkipUnknown*/) {}
95 void RTFLookahead::finishSubstream() {}
97 bool RTFLookahead::isSubstream() const { return false; }
99 } // namespace writerfilter::rtftok
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */