1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #ifndef SW_TOXLINKPROCESSOR_HXX_
11 #define SW_TOXLINKPROCESSOR_HXX_
13 #include "fmtinfmt.hxx"
14 #include <rtl/ustring.hxx>
23 class ToxLinkProcessorTest
;
27 /** A helper class for ToxTextGenerator.
28 * It collects information about encountered link tokens and allows access in a processed form.
30 class ToxLinkProcessor
{
33 virtual ~ToxLinkProcessor() {}
36 StartNewLink(sal_Int32 startPosition
, const OUString
& characterStyle
);
38 /** Close a link which has been found during processing.
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.
46 CloseLink(sal_Int32 endPosition
, const OUString
& url
, bool bRelative
);
48 /** Insert the found links as attributes to a text node */
50 InsertLinkAttributes(SwTextNode
& node
);
53 /** Obtain the pool id which belongs to a character style.
56 * This method is overridden in the unittests. You should not override it yourself.
59 ObtainPoolId(const OUString
& characterStyle
) const;
61 /** Information about a started link */
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.
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: */