summaryrefslogtreecommitdiff
path: root/sw/inc/ToxLinkProcessor.hxx
diff options
context:
space:
mode:
authorTobias Lippert <drtl@fastmail.fm>2014-06-01 14:18:39 +0200
committerCaolán McNamara <caolanm@redhat.com>2014-06-05 16:26:39 +0000
commit94b296d5416dd71d721ad16216b50bce79e3dc04 (patch)
treea53b0a660ce6646c5767865fe85af03bfaba3b3e /sw/inc/ToxLinkProcessor.hxx
parente5345f62bf525b6258736f1ce11a61b5e638e0ff (diff)
Unittest link generation for table of contents.
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 <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sw/inc/ToxLinkProcessor.hxx')
-rw-r--r--sw/inc/ToxLinkProcessor.hxx86
1 files changed, 86 insertions, 0 deletions
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 <vector>
+
+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<ClosedLink> mClosedLinks;
+
+ std::vector<StartedLink> mStartedLinks;
+
+ friend class ::ToxLinkProcessorTest;
+};
+
+}
+
+#endif /* SW_TOXLINKPROCESSOR_HXX_ */