Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / inc / ToxLinkProcessor.hxx
blobb0c708fb65195e30431b2853d4da0c4d621a39fb
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 <memory>
17 #include <optional>
18 #include <utility>
19 #include <vector>
21 class SwTextNode;
23 class ToxLinkProcessorTest;
25 namespace sw {
27 /** A helper class for ToxTextGenerator.
28 * It collects information about encountered link tokens and allows access in a processed form.
30 class ToxLinkProcessor {
31 public:
32 ToxLinkProcessor() {}
33 virtual ~ToxLinkProcessor() {}
35 void
36 StartNewLink(sal_Int32 startPosition, const OUString& characterStyle);
38 /** Close a link which has been found during processing.
40 * @internal
41 * If you close more links than were opened, then the method will behave
42 * as if a start link was opened at position 0 with the character style
43 * STR_POOLCHR_TOXJUMP.
45 void
46 CloseLink(sal_Int32 endPosition, const OUString& url, bool bRelative);
48 /** Insert the found links as attributes to a text node */
49 void
50 InsertLinkAttributes(SwTextNode& node);
52 private:
53 /** Obtain the pool id which belongs to a character style.
55 * @internal
56 * This method is overridden in the unittests. You should not override it yourself.
58 virtual sal_uInt16
59 ObtainPoolId(const OUString& characterStyle) const;
61 /** Information about a started link */
62 struct StartedLink {
63 StartedLink(sal_Int32 startPosition, OUString characterStyle) :
64 mStartPosition(startPosition), mCharacterStyle(std::move(characterStyle)) {
66 sal_Int32 mStartPosition;
67 OUString mCharacterStyle;
70 /** A link that has been encountered while parsing a tox.
71 * A link is closed if it has both a start and an end token.
73 struct ClosedLink {
74 ClosedLink(const OUString& url, sal_Int32 startPosition, sal_Int32 endPosition)
75 : mINetFormat(url, OUString())
76 , mStartTextPos(startPosition)
77 , mEndTextPos(endPosition)
80 SwFormatINetFormat mINetFormat;
81 sal_Int32 mStartTextPos;
82 sal_Int32 mEndTextPos;
85 std::vector<std::unique_ptr<ClosedLink>> m_ClosedLinks;
87 std::optional<StartedLink> m_oStartedLink;
89 friend class ::ToxLinkProcessorTest;
94 #endif /* SW_TOXLINKPROCESSOR_HXX_ */
96 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */