summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2017-03-29 16:43:23 +0200
committerAndras Timar <andras.timar@collabora.com>2017-04-04 12:19:42 +0200
commit5b6fd648f020a9e84d1b68491ca06aa2e8fb86e2 (patch)
tree11fb55e7650d40b42da2b6ba8a3b0433cef9b672 /comphelper
parentec52c2f4b7090ced1810b23fd6cc5fb2db4215d2 (diff)
sw: plain-text ASCII export: filter out all CH_TXT_ATR_*
These control characters are Writer implementation details and should not be available via public interfaces. This filter is also used by SwXTextRange::getString(). Change-Id: If656ee3d451dbefe2f7a905e8b63a44cdb787809 (cherry picked from commit ab4f53eaad0c064d9b2ff1c2cb20560f81ade1f7) Reviewed-on: https://gerrit.libreoffice.org/35862 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com> (cherry picked from commit 5254a7d1cbf3f62c6664299752d2788bb4f2a0b4)
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/qa/string/test_string.cxx22
-rw-r--r--comphelper/source/misc/string.cxx36
2 files changed, 58 insertions, 0 deletions
diff --git a/comphelper/qa/string/test_string.cxx b/comphelper/qa/string/test_string.cxx
index 636c30587370..b36b7988489f 100644
--- a/comphelper/qa/string/test_string.cxx
+++ b/comphelper/qa/string/test_string.cxx
@@ -43,6 +43,7 @@ public:
void testIsdigitAsciiString();
void testReverseString();
void testSplit();
+ void testRemoveAny();
CPPUNIT_TEST_SUITE(TestString);
CPPUNIT_TEST(testNatural);
@@ -55,6 +56,7 @@ public:
CPPUNIT_TEST(testIsdigitAsciiString);
CPPUNIT_TEST(testReverseString);
CPPUNIT_TEST(testSplit);
+ CPPUNIT_TEST(testRemoveAny);
CPPUNIT_TEST_SUITE_END();
};
@@ -390,6 +392,26 @@ void TestString::testSplit()
CPPUNIT_ASSERT_EQUAL(OUString("F1"), aRet[2]);
}
+void TestString::testRemoveAny()
+{
+ using namespace ::comphelper::string;
+ OUString in("abcAAAbbC");
+ sal_Unicode const test1 [] = { 'a', 0 };
+ CPPUNIT_ASSERT_EQUAL(OUString("bcAAAbbC"), removeAny(in, test1));
+ sal_Unicode const test2 [] = { 0 };
+ CPPUNIT_ASSERT_EQUAL(in, removeAny(in, test2));
+ sal_Unicode const test3 [] = { 'A', 0 };
+ CPPUNIT_ASSERT_EQUAL(OUString("abcbbC"), removeAny(in, test3));
+ sal_Unicode const test4 [] = { 'A', 'a', 0 };
+ CPPUNIT_ASSERT_EQUAL(OUString("bcbbC"), removeAny(in, test4));
+ sal_Unicode const test5 [] = { 'C', 0 };
+ CPPUNIT_ASSERT_EQUAL(OUString("abcAAAbb"), removeAny(in, test5));
+ sal_Unicode const test6 [] = { 'X', 0 };
+ CPPUNIT_ASSERT_EQUAL(in, removeAny(in, test6));
+ sal_Unicode const test7 [] = { 'A', 'B', 'C', 'a', 'b', 'c', 0 };
+ CPPUNIT_ASSERT_EQUAL(OUString(""), removeAny(in, test7));
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(TestString);
}
diff --git a/comphelper/source/misc/string.cxx b/comphelper/source/misc/string.cxx
index db035eb22967..5ca35f9eb535 100644
--- a/comphelper/source/misc/string.cxx
+++ b/comphelper/source/misc/string.cxx
@@ -420,6 +420,42 @@ sal_Int32 indexOfAny(OUString const& rIn,
return -1;
}
+OUString removeAny(OUString const& rIn,
+ sal_Unicode const*const pChars)
+{
+ OUStringBuffer buf;
+ bool isFound(false);
+ for (sal_Int32 i = 0; i < rIn.getLength(); ++i)
+ {
+ sal_Unicode const c = rIn[i];
+ bool removeC(false);
+ for (sal_Unicode const* pChar = pChars; *pChar; ++pChar)
+ {
+ if (c == *pChar)
+ {
+ removeC = true;
+ break;
+ }
+ }
+ if (removeC)
+ {
+ if (!isFound)
+ {
+ if (i > 0)
+ {
+ buf.append(rIn.copy(0, i));
+ }
+ isFound = true;
+ }
+ }
+ else if (isFound)
+ {
+ buf.append(c);
+ }
+ }
+ return (isFound) ? buf.makeStringAndClear() : rIn;
+}
+
OUString setToken(const OUString& rIn, sal_Int32 nToken, sal_Unicode cTok,
const OUString& rNewToken)
{