Branch libreoffice-5-0-4
[LibreOffice.git] / sw / inc / ToxLinkProcessor.hxx
bloba8b06d0bdf954662d03282077b22a52b2629d4aa
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 #ifndef SW_TOXLINKPROCESSOR_HXX_
11 #define SW_TOXLINKPROCESSOR_HXX_
13 #include "fmtinfmt.hxx"
14 #include "rtl/ustring.hxx"
16 #include <boost/ptr_container/ptr_vector.hpp>
18 class SwTextNode;
20 class ToxLinkProcessorTest;
22 namespace sw {
24 /** A helper class for ToxTextGenerator.
25 * It collects information about encountered link tokens and allows access in a processed form.
27 class ToxLinkProcessor {
28 public:
29 ToxLinkProcessor() {}
30 virtual ~ToxLinkProcessor() {}
32 void
33 StartNewLink(sal_Int32 startPosition, const OUString& characterStyle);
35 /** Close a link which has been found during processing.
37 * @throw std::runtime_error If there are no open links.
39 void
40 CloseLink(sal_Int32 endPosition, const OUString& url);
42 /** Insert the found links as attributes to a text node */
43 void
44 InsertLinkAttributes(SwTextNode& node);
46 private:
47 /** Obtain the pool id which belongs to a character style.
49 * @internal
50 * This method is overridden in the unittests. You should not override it yourself.
52 virtual sal_uInt16
53 ObtainPoolId(const OUString& characterStyle) const;
55 /** Information about a started link */
56 struct StartedLink {
57 StartedLink(sal_Int32 startPosition, const OUString& characterStyle) :
58 mStartPosition(startPosition), mCharacterStyle(characterStyle) {
60 sal_Int32 mStartPosition;
61 OUString mCharacterStyle;
64 /** A link that has been encountered while parsing a tox.
65 * A link is closed if it has both a start and an end token.
67 struct ClosedLink {
68 ClosedLink(const OUString& url, sal_Int32 startPosition, sal_Int32 endPosition) :
69 mINetFormat(url, OUString()), mStartTextPos(endPosition), mEndTextPos(startPosition) {
71 SwFormatINetFormat mINetFormat;
72 sal_Int32 mStartTextPos;
73 sal_Int32 mEndTextPos;
76 boost::ptr_vector<ClosedLink> mClosedLinks;
78 boost::ptr_vector<StartedLink> mStartedLinks;
80 friend class ::ToxLinkProcessorTest;
85 #endif /* SW_TOXLINKPROCESSOR_HXX_ */
87 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */