summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2016-05-03 12:59:05 +0300
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2016-06-18 17:02:08 +0200
commit0d4dcf380033902fe4eb70425138e419fb711271 (patch)
treed1c7ddc3d62d7bc787e8b84d942ca5e0b333de39 /comphelper
parentfbd80e546c51875ff310462312090abb84076b35 (diff)
add comphelper::string::split
Change-Id: Iccc989a786e8e7b8dca1996b635248d7bf7fc5d8
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/qa/string/test_string.cxx12
-rw-r--r--comphelper/source/misc/string.cxx29
2 files changed, 32 insertions, 9 deletions
diff --git a/comphelper/qa/string/test_string.cxx b/comphelper/qa/string/test_string.cxx
index 97814da5fe4c..70998759e04f 100644
--- a/comphelper/qa/string/test_string.cxx
+++ b/comphelper/qa/string/test_string.cxx
@@ -43,6 +43,7 @@ public:
void testDecimalStringToNumber();
void testIsdigitAsciiString();
void testReverseString();
+ void testSplit();
CPPUNIT_TEST_SUITE(TestString);
CPPUNIT_TEST(testNatural);
@@ -55,6 +56,7 @@ public:
CPPUNIT_TEST(testDecimalStringToNumber);
CPPUNIT_TEST(testIsdigitAsciiString);
CPPUNIT_TEST(testReverseString);
+ CPPUNIT_TEST(testSplit);
CPPUNIT_TEST_SUITE_END();
};
@@ -394,6 +396,16 @@ void TestString::testReverseString()
CPPUNIT_ASSERT(aOut == "CBA");
}
+void TestString::testSplit()
+{
+ OUString aIn("CTRL+ALT+F1");
+ std::vector<OUString> aRet = ::comphelper::string::split(aIn, '+');
+ CPPUNIT_ASSERT_EQUAL(size_t(3), aRet.size());
+ CPPUNIT_ASSERT_EQUAL(OUString("CTRL"), aRet[0]);
+ CPPUNIT_ASSERT_EQUAL(OUString("ALT"), aRet[1]);
+ CPPUNIT_ASSERT_EQUAL(OUString("F1"), aRet[2]);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(TestString);
}
diff --git a/comphelper/source/misc/string.cxx b/comphelper/source/misc/string.cxx
index 2dbbc0c90d11..db035eb22967 100644
--- a/comphelper/source/misc/string.cxx
+++ b/comphelper/source/misc/string.cxx
@@ -253,19 +253,30 @@ OUString convertCommaSeparated(
return buf.makeStringAndClear();
}
-uno::Sequence< OUString >
- convertCommaSeparated( OUString const& i_rString )
+std::vector<OUString>
+ split(const OUString& rStr, sal_Unicode cSeparator)
{
std::vector< OUString > vec;
sal_Int32 idx = 0;
- do {
- OUString kw =
- i_rString.getToken(0, static_cast<sal_Unicode> (','), idx);
- kw = kw.trim();
- if (!kw.isEmpty()) {
- vec.push_back(kw);
- }
+ do
+ {
+ OUString kw =
+ rStr.getToken(0, cSeparator, idx);
+ kw = kw.trim();
+ if (!kw.isEmpty())
+ {
+ vec.push_back(kw);
+ }
+
} while (idx >= 0);
+
+ return vec;
+}
+
+uno::Sequence< OUString >
+ convertCommaSeparated( OUString const& i_rString )
+{
+ std::vector< OUString > vec = split(i_rString, ',');
return comphelper::containerToSequence(vec);
}