summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2017-03-29 16:43:23 +0200
committerMichael Stahl <mstahl@redhat.com>2017-03-29 17:31:49 +0200
commitab4f53eaad0c064d9b2ff1c2cb20560f81ade1f7 (patch)
treed034d50a5ea1972977cffc32007f534b408be647 /comphelper
parent30102ded91b9ecfea172ffc6443154230ee37cbd (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
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 1180805542fa..7135c81cb0cf 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();
};
@@ -382,6 +384,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 828728f113e7..2728e0bca12b 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)
{