From 940b4d1848e8c70ab7642901a68594e8016caffc Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 18:51:28 +0200 Subject: Adding upstream version 1:7.0.4. Signed-off-by: Daniel Baumann --- sw/inc/ToxLinkProcessor.hxx | 94 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 sw/inc/ToxLinkProcessor.hxx (limited to 'sw/inc/ToxLinkProcessor.hxx') diff --git a/sw/inc/ToxLinkProcessor.hxx b/sw/inc/ToxLinkProcessor.hxx new file mode 100644 index 000000000..e53c537b7 --- /dev/null +++ b/sw/inc/ToxLinkProcessor.hxx @@ -0,0 +1,94 @@ +/* -*- 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 SW_TOXLINKPROCESSOR_HXX_ +#define SW_TOXLINKPROCESSOR_HXX_ + +#include "fmtinfmt.hxx" +#include + +#include +#include + +class SwTextNode; + +class ToxLinkProcessorTest; + +namespace sw { + +/** A helper class for ToxTextGenerator. + * It collects information about encountered link tokens and allows access in a processed form. + */ +class ToxLinkProcessor { +public: + ToxLinkProcessor() {} + virtual ~ToxLinkProcessor() {} + + void + StartNewLink(sal_Int32 startPosition, const OUString& characterStyle); + + /** Close a link which has been found during processing. + * + * @internal + * If you close more links than were opened, then the method will behave + * as if a start link was opened at position 0 with the character style + * STR_POOLCHR_TOXJUMP. + */ + void + CloseLink(sal_Int32 endPosition, const OUString& url); + + /** Insert the found links as attributes to a text node */ + void + InsertLinkAttributes(SwTextNode& node); + +private: + /** Obtain the pool id which belongs to a character style. + * + * @internal + * This method is overridden in the unittests. You should not override it yourself. + */ + virtual sal_uInt16 + ObtainPoolId(const OUString& characterStyle) const; + + /** Information about a started link */ + struct StartedLink { + StartedLink(sal_Int32 startPosition, const OUString& characterStyle) : + mStartPosition(startPosition), mCharacterStyle(characterStyle) { + } + sal_Int32 mStartPosition; + OUString mCharacterStyle; + }; + + /** A link that has been encountered while parsing a tox. + * A link is closed if it has both a start and an end token. + */ + struct ClosedLink { + ClosedLink(const OUString& url, sal_Int32 startPosition, sal_Int32 endPosition) + : mINetFormat(url, OUString()) + , mStartTextPos(startPosition) + , mEndTextPos(endPosition) + { + } + SwFormatINetFormat mINetFormat; + sal_Int32 mStartTextPos; + sal_Int32 mEndTextPos; + }; + + std::vector> m_ClosedLinks; + + std::unique_ptr m_pStartedLink; + + friend class ::ToxLinkProcessorTest; +}; + +} + +#endif /* SW_TOXLINKPROCESSOR_HXX_ */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3