summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2012-06-06 14:35:49 +0100
committerCaolán McNamara <caolanm@redhat.com>2012-06-06 14:38:42 +0100
commite2cd6a77ea0e8a1abd8f4d3570ba4f5fdefff3e1 (patch)
treea345e3aae24a7f41209b40e370aa89787686979e /comphelper
parent5662854bc29acb45c1c449c05d1e92f96a4b335a (diff)
drop String::Reverse
Change-Id: Ie06635dc1f242241d48f9d6de4f592898e605bf2
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/inc/comphelper/string.hxx15
-rw-r--r--comphelper/qa/string/test_string.cxx11
-rw-r--r--comphelper/source/misc/string.cxx26
3 files changed, 51 insertions, 1 deletions
diff --git a/comphelper/inc/comphelper/string.hxx b/comphelper/inc/comphelper/string.hxx
index dc3620d67307..499e8504dd09 100644
--- a/comphelper/inc/comphelper/string.hxx
+++ b/comphelper/inc/comphelper/string.hxx
@@ -226,6 +226,21 @@ COMPHELPER_DLLPUBLIC sal_Int32 getTokenCount(const rtl::OString &rIn, sal_Char c
*/
COMPHELPER_DLLPUBLIC sal_Int32 getTokenCount(const rtl::OUString &rIn, sal_Unicode cTok);
+/** Reverse an OUString
+
+ @param rIn the input OUString
+ @return the reversed input
+*/
+COMPHELPER_DLLPUBLIC rtl::OUString reverseString(const rtl::OUString &rStr);
+
+/** Reverse an OString
+
+ @param rIn the input OString
+ @return the reversed input
+*/
+COMPHELPER_DLLPUBLIC rtl::OString reverseString(const rtl::OString &rStr);
+
+
namespace detail
{
template<typename B> B& truncateToLength(B& rBuffer, sal_Int32 nLen)
diff --git a/comphelper/qa/string/test_string.cxx b/comphelper/qa/string/test_string.cxx
index b775e01804da..96706ace353d 100644
--- a/comphelper/qa/string/test_string.cxx
+++ b/comphelper/qa/string/test_string.cxx
@@ -53,7 +53,7 @@ public:
void testTokenCount();
void testDecimalStringToNumber();
void testIsdigitAsciiString();
- void testIndexOfL();
+ void testReverseString();
CPPUNIT_TEST_SUITE(TestString);
CPPUNIT_TEST(testNatural);
@@ -65,6 +65,7 @@ public:
CPPUNIT_TEST(testTokenCount);
CPPUNIT_TEST(testDecimalStringToNumber);
CPPUNIT_TEST(testIsdigitAsciiString);
+ CPPUNIT_TEST(testReverseString);
CPPUNIT_TEST_SUITE_END();
};
@@ -396,6 +397,14 @@ void TestString::testTokenCount()
CPPUNIT_ASSERT(nOut == 0);
}
+void TestString::testReverseString()
+{
+ ::rtl::OString aIn("ABC");
+ ::rtl::OString aOut = ::comphelper::string::reverseString(aIn);
+
+ CPPUNIT_ASSERT(aOut == "CBA");
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(TestString);
}
diff --git a/comphelper/source/misc/string.cxx b/comphelper/source/misc/string.cxx
index 6eb744fc3bdf..08aa392dcd82 100644
--- a/comphelper/source/misc/string.cxx
+++ b/comphelper/source/misc/string.cxx
@@ -438,6 +438,32 @@ rtl_String * SAL_CALL rtl_string_alloc(sal_Int32 nLen)
return string_alloc<rtl_String, sal_Char>(nLen);
}
+namespace
+{
+ template <typename T, typename O> T tmpl_reverseString(const T &rIn)
+ {
+ if (rIn.isEmpty())
+ return rIn;
+
+ sal_Int32 i = rIn.getLength();
+ O sBuf(i);
+ while (i)
+ sBuf.append(rIn[--i]);
+ return sBuf.makeStringAndClear();
+ }
+}
+
+rtl::OUString reverseString(const rtl::OUString &rStr)
+{
+ return tmpl_reverseString<rtl::OUString, rtl::OUStringBuffer>(rStr);
+}
+
+rtl::OString reverseString(const rtl::OString &rStr)
+{
+ return tmpl_reverseString<rtl::OString, rtl::OStringBuffer>(rStr);
+}
+
+
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */