From 94b296d5416dd71d721ad16216b50bce79e3dc04 Mon Sep 17 00:00:00 2001 From: Tobias Lippert Date: Sun, 1 Jun 2014 14:18:39 +0200 Subject: Unittest link generation for table of contents. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The logic was moved to a separate class and unittested. Conflicts: sw/inc/ToxTextGenerator.hxx Change-Id: I0e4475f5e2950cdfdfb07b89128c4ce1d6af3f22 Reviewed-on: https://gerrit.libreoffice.org/9609 Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- sw/inc/ToxLinkProcessor.hxx | 86 +++++++++++++++++++++++++++++++++++++++++++++ sw/inc/ToxTextGenerator.hxx | 12 ++++--- 2 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 sw/inc/ToxLinkProcessor.hxx (limited to 'sw/inc') diff --git a/sw/inc/ToxLinkProcessor.hxx b/sw/inc/ToxLinkProcessor.hxx new file mode 100644 index 000000000000..5a4546562ec6 --- /dev/null +++ b/sw/inc/ToxLinkProcessor.hxx @@ -0,0 +1,86 @@ +/* -*- 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 "rtl/ustring.hxx" + +#include + +class SwTxtNode; + +class ToxLinkProcessorTest; + +namespace sw { + +/** A helper class for ToxTextGenerator. + * It collects information about encountered link tokens and allows access in a processed form. + */ +class SW_DLLPUBLIC ToxLinkProcessor { +public: + ToxLinkProcessor() {;} + virtual ~ToxLinkProcessor() {;} + + void + StartNewLink(sal_Int32 startPosition, const OUString& characterStyle); + + /** Close a link which has been found during processing. + * + * @throw std::runtime_error If there are no open links. + */ + void + CloseLink(sal_Int32 endPosition, const OUString& url); + + /** Insert the found links as attributes to a text node */ + void + InsertLinkAttributes(SwTxtNode& 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, 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) : + mINetFmt(url, OUString()), mStartTextPos(endPosition), mEndTextPos(startPosition) { + } + SwFmtINetFmt mINetFmt; + sal_Int32 mStartTextPos; + sal_Int32 mEndTextPos; + }; + + std::vector mClosedLinks; + + std::vector mStartedLinks; + + friend class ::ToxLinkProcessorTest; +}; + +} + +#endif /* SW_TOXLINKPROCESSOR_HXX_ */ diff --git a/sw/inc/ToxTextGenerator.hxx b/sw/inc/ToxTextGenerator.hxx index e64c8b678d90..d83736b3eb31 100644 --- a/sw/inc/ToxTextGenerator.hxx +++ b/sw/inc/ToxTextGenerator.hxx @@ -22,6 +22,7 @@ #include "sal/types.h" #include "swdllapi.h" +#include #include class SwDoc; @@ -31,12 +32,15 @@ struct SwTOXSortTabBase; namespace sw { +class ToxLinkProcessor; + class SW_DLLPUBLIC ToxTextGenerator { public: - ToxTextGenerator(const SwForm& toxForm) - : mToxForm(toxForm) - {} + ToxTextGenerator(const SwForm& toxForm); + + ~ToxTextGenerator(); + /** Generate the text for an entry of a table of X (X is, e.g., content). * * This method will process the entries in @p entries, starting at @p indexOfEntryToProcess and @@ -47,9 +51,9 @@ public: sal_uInt16 indexOfEntryToProcess, sal_uInt16 numberOfEntriesToProcess, sal_uInt32 _nTOXSectNdIdx, const SwPageDesc* _pDefaultPageDesc); - private: const SwForm& mToxForm; + boost::shared_ptr mLinkProcessor; }; } -- cgit