summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--basic/source/runtime/methods1.cxx4
-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
-rw-r--r--fpicker/source/office/iodlg.cxx7
-rw-r--r--sc/source/core/tool/address.cxx4
-rw-r--r--svx/source/table/cell.cxx5
-rw-r--r--tools/inc/tools/string.hxx1
-rw-r--r--tools/source/string/tustring.cxx24
9 files changed, 61 insertions, 36 deletions
diff --git a/basic/source/runtime/methods1.cxx b/basic/source/runtime/methods1.cxx
index 4e5788ad45dc..2195a177c52e 100644
--- a/basic/source/runtime/methods1.cxx
+++ b/basic/source/runtime/methods1.cxx
@@ -52,6 +52,7 @@
#include <comphelper/processfactory.hxx>
+#include <comphelper/string.hxx>
#include <com/sun/star/uno/Sequence.hxx>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
@@ -3122,8 +3123,7 @@ RTLFUNC(StrReverse)
return;
}
- String aStr = pSbxVariable->GetString();
- aStr.Reverse();
+ rtl::OUString aStr = comphelper::string::reverseString(pSbxVariable->GetString());
rPar.Get(0)->PutString( aStr );
}
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: */
diff --git a/fpicker/source/office/iodlg.cxx b/fpicker/source/office/iodlg.cxx
index cc57c5bc7565..006f8e866541 100644
--- a/fpicker/source/office/iodlg.cxx
+++ b/fpicker/source/office/iodlg.cxx
@@ -2557,8 +2557,7 @@ void SvtFileDialog::implArrangeControls()
sal_Bool SvtFileDialog::IsolateFilterFromPath_Impl( String& rPath, String& rFilter )
{
String aEmpty;
- String aReversePath( rPath );
- aReversePath.Reverse();
+ String aReversePath = comphelper::string::reverseString(rPath);
sal_uInt16 nQuestionMarkPos = rPath.Search( '?' );
if ( nQuestionMarkPos != STRING_NOTFOUND )
@@ -2607,12 +2606,12 @@ sal_Bool SvtFileDialog::IsolateFilterFromPath_Impl( String& rPath, String& rFilt
// cut off filter
rFilter = aReversePath;
rFilter.Erase( nPathTokenPos );
- rFilter.Reverse();
+ rFilter = comphelper::string::reverseString(rFilter);
// determine folder
rPath = aReversePath;
rPath.Erase( 0, nPathTokenPos );
- rPath.Reverse();
+ rPath = comphelper::string::reverseString(rPath);
}
else
{
diff --git a/sc/source/core/tool/address.cxx b/sc/source/core/tool/address.cxx
index 30558bd63a2d..aeab79e00111 100644
--- a/sc/source/core/tool/address.cxx
+++ b/sc/source/core/tool/address.cxx
@@ -40,6 +40,7 @@
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/sheet/ExternalLinkInfo.hpp>
#include <com/sun/star/sheet/ExternalLinkType.hpp>
+#include <comphelper/string.hxx>
#include <sfx2/objsh.hxx>
#include <tools/urlobj.hxx>
@@ -2016,8 +2017,7 @@ void ScColToAlpha( rtl::OUStringBuffer& rBuf, SCCOL nCol )
}
aStr += static_cast<sal_Unicode>( 'A' +
static_cast<sal_uInt16>(nCol));
- aStr.Reverse();
- rBuf.append( aStr);
+ rBuf.append(comphelper::string::reverseString(aStr));
}
}
diff --git a/svx/source/table/cell.cxx b/svx/source/table/cell.cxx
index 69085ecb94ec..9ffbd38e7ac4 100644
--- a/svx/source/table/cell.cxx
+++ b/svx/source/table/cell.cxx
@@ -33,6 +33,8 @@
#include <com/sun/star/table/TableBorder.hpp>
#include <com/sun/star/table/BorderLine2.hpp>
+#include <comphelper/string.hxx>
+
#include <cppuhelper/typeprovider.hxx>
#include <svl/style.hxx>
#include <svl/itemset.hxx>
@@ -1664,8 +1666,7 @@ static OUString getCellName( sal_Int32 nCol, sal_Int32 nRow )
}
aStr += static_cast<sal_Unicode>( 'A' +
static_cast<sal_uInt16>(nCol));
- aStr.Reverse();
- aBuf.append( aStr);
+ aBuf.append(comphelper::string::reverseString(aStr));
}
aBuf.append( OUString::valueOf(nRow+1) );
return aBuf.makeStringAndClear();
diff --git a/tools/inc/tools/string.hxx b/tools/inc/tools/string.hxx
index 0d6b26b02683..5b3f2707ec7c 100644
--- a/tools/inc/tools/string.hxx
+++ b/tools/inc/tools/string.hxx
@@ -247,7 +247,6 @@ public:
UniString& EraseLeadingChars( sal_Unicode c = ' ' );
UniString& EraseTrailingChars( sal_Unicode c = ' ' );
- UniString& Reverse();
UniString& ToLowerAscii();
UniString& ToUpperAscii();
diff --git a/tools/source/string/tustring.cxx b/tools/source/string/tustring.cxx
index f3879e8d8126..130f6d48ee65 100644
--- a/tools/source/string/tustring.cxx
+++ b/tools/source/string/tustring.cxx
@@ -155,30 +155,6 @@ xub_StrLen STRING::SearchAndReplace( STRCODE c, STRCODE cRep, xub_StrLen nIndex
// -----------------------------------------------------------------------
-STRING& STRING::Reverse()
-{
- DBG_CHKTHIS( STRING, DBGCHECKSTRING );
-
- if ( !mpData->mnLen )
- return *this;
-
- // Daten kopieren, wenn noetig
- ImplCopyData();
-
- // Reverse
- sal_Int32 nCount = mpData->mnLen / 2;
- for ( sal_Int32 i = 0; i < nCount; ++i )
- {
- STRCODE cTemp = mpData->maStr[i];
- mpData->maStr[i] = mpData->maStr[mpData->mnLen-i-1];
- mpData->maStr[mpData->mnLen-i-1] = cTemp;
- }
-
- return *this;
-}
-
-// -----------------------------------------------------------------------
-
STRING& STRING::Insert( const STRING& rStr, xub_StrLen nPos, xub_StrLen nLen,
xub_StrLen nIndex )
{