[Libreoffice-commits] .: basic/source comphelper/inc comphelper/qa comphelper/source fpicker/source sc/source svx/source tools/inc tools/source

Caolán McNamara caolan at kemper.freedesktop.org
Wed Jun 6 06:41:37 PDT 2012


 basic/source/runtime/methods1.cxx    |    4 ++--
 comphelper/inc/comphelper/string.hxx |   15 +++++++++++++++
 comphelper/qa/string/test_string.cxx |   11 ++++++++++-
 comphelper/source/misc/string.cxx    |   26 ++++++++++++++++++++++++++
 fpicker/source/office/iodlg.cxx      |    7 +++----
 sc/source/core/tool/address.cxx      |    4 ++--
 svx/source/table/cell.cxx            |    5 +++--
 tools/inc/tools/string.hxx           |    1 -
 tools/source/string/tustring.cxx     |   24 ------------------------
 9 files changed, 61 insertions(+), 36 deletions(-)

New commits:
commit e2cd6a77ea0e8a1abd8f4d3570ba4f5fdefff3e1
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Wed Jun 6 14:35:49 2012 +0100

    drop String::Reverse
    
    Change-Id: Ie06635dc1f242241d48f9d6de4f592898e605bf2

diff --git a/basic/source/runtime/methods1.cxx b/basic/source/runtime/methods1.cxx
index 4e5788a..2195a17 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 dc3620d..499e850 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 b775e01..96706ac 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 6eb744f..08aa392 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 cc57c5b..006f8e8 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 30558bd..aeab79e 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 69085ec..9ffbd38 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 0d6b26b..5b3f270 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 f3879e8..130f6d4 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 )
 {


More information about the Libreoffice-commits mailing list