summaryrefslogtreecommitdiffstats
path: root/sw/inc/ToxWhitespaceStripper.hxx
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
commited5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch)
tree7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /sw/inc/ToxWhitespaceStripper.hxx
parentInitial commit. (diff)
downloadlibreoffice-upstream.tar.xz
libreoffice-upstream.zip
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--sw/inc/ToxWhitespaceStripper.hxx47
1 files changed, 47 insertions, 0 deletions
diff --git a/sw/inc/ToxWhitespaceStripper.hxx b/sw/inc/ToxWhitespaceStripper.hxx
new file mode 100644
index 000000000..9decbc020
--- /dev/null
+++ b/sw/inc/ToxWhitespaceStripper.hxx
@@ -0,0 +1,47 @@
+/* -*- 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 TOXWHITESPACESTRIPPER_HXX_
+#define TOXWHITESPACESTRIPPER_HXX_
+
+#include <rtl/ustring.hxx>
+#include <vector>
+
+namespace sw
+{
+/** This class helps to remove unwanted whitespaces from a string to use in a Tox.
+ *
+ * The new string will have
+ * - Newlines changed to spaces
+ * - Consecutive spaces merged
+ * - Trailing spaces removed
+ *
+ * It also allows to find the corresponding new positions of the input string in the stripped string.
+ * This is important for attributes which might have to be imported, e.g., it helps to answer the question:
+ * The 3rd character of the input string is subscript, which character in the output string is that?
+ *
+ * @note One leading whitespace is preserved.
+ */
+class ToxWhitespaceStripper
+{
+public:
+ ToxWhitespaceStripper(const OUString&);
+
+ sal_Int32 GetPositionInStrippedString(sal_Int32 pos) const;
+
+ const OUString& GetStrippedString() const { return mStripped; }
+
+private:
+ OUString mStripped;
+ std::vector<sal_Int32> mNewPositions;
+};
+
+} // end namespace sw
+
+#endif /* TOXWHITESPACESTRIPPER_HXX_ */