[Libreoffice-commits] .: 3 commits - sal/inc sal/qa

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Nov 28 06:02:35 PST 2012


 sal/inc/rtl/string.hxx                       |   16 +++++++-------
 sal/inc/rtl/ustrbuf.hxx                      |   13 +++--------
 sal/inc/rtl/ustring.hxx                      |   30 ++++++++++++---------------
 sal/qa/rtl/strings/test_oustring_compare.cxx |   15 +++++++++++++
 4 files changed, 41 insertions(+), 33 deletions(-)

New commits:
commit 20481510003524af3e4b50c073a4f9bae87acb1f
Author: Norbert Thiebaud <nthiebaud at gmail.com>
Date:   Wed Nov 28 04:01:17 2012 -0600

    add SAL_WARN_UNUSED_RESULT in OString and OUString where appropriate
    
    String used to do some operation by modifying itself
    whereas OUString never does that and when a modificaiton is needed
    it create a new copy.
    
    so it is very easy when one convert String code to OUString code to
    miss stuff like
    
    sString.ToUpperCase()
    
    which need to be converted into
    
    sString = sString.toAsciiUpperCase()
    
    and not
    sString.toAsciiUpperCase()
    
    This patch make the compiler generate a warning in that later _wrong_ case
    
    Change-Id: I4a9c0b4c7d0b75ad8850ac23b86e8508a334f5fe
    Signed-off-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/sal/inc/rtl/string.hxx b/sal/inc/rtl/string.hxx
index 51d21cb..4e55020 100644
--- a/sal/inc/rtl/string.hxx
+++ b/sal/inc/rtl/string.hxx
@@ -1056,7 +1056,7 @@ public:
       @return   a string that represents the concatenation of this string
                 followed by the string argument.
     */
-    OString concat( const OString & str ) const SAL_THROW(())
+    SAL_WARN_UNUSED_RESULT OString concat( const OString & str ) const SAL_THROW(())
     {
         rtl_String* pNew = 0;
         rtl_string_newConcat( &pNew, pData, str.pData );
@@ -1081,7 +1081,7 @@ public:
       @param  newStr  the new substring.
       @return the new string.
     */
-    OString replaceAt( sal_Int32 index, sal_Int32 count, const OString& newStr ) const SAL_THROW(())
+    SAL_WARN_UNUSED_RESULT OString replaceAt( sal_Int32 index, sal_Int32 count, const OString& newStr ) const SAL_THROW(())
     {
         rtl_String* pNew = 0;
         rtl_string_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
@@ -1101,7 +1101,7 @@ public:
       @return   a string derived from this string by replacing every
                 occurrence of oldChar with newChar.
     */
-    OString replace( sal_Char oldChar, sal_Char newChar ) const SAL_THROW(())
+    SAL_WARN_UNUSED_RESULT OString replace( sal_Char oldChar, sal_Char newChar ) const SAL_THROW(())
     {
         rtl_String* pNew = 0;
         rtl_string_newReplace( &pNew, pData, oldChar, newChar );
@@ -1126,7 +1126,7 @@ public:
 
       @since LibreOffice 3.6
     */
-    OString replaceFirst(
+    SAL_WARN_UNUSED_RESULT OString replaceFirst(
         OString const & from, OString const & to, sal_Int32 * index = 0) const
     {
         rtl_String * s = 0;
@@ -1150,7 +1150,7 @@ public:
 
       @since LibreOffice 3.6
     */
-    OString replaceAll(OString const & from, OString const & to) const {
+    SAL_WARN_UNUSED_RESULT OString replaceAll(OString const & from, OString const & to) const {
         rtl_String * s = 0;
         rtl_string_newReplaceAll(
             &s, pData, from.pData->buffer, from.pData->length,
@@ -1168,7 +1168,7 @@ public:
 
       @return   the string, converted to ASCII lowercase.
     */
-    OString toAsciiLowerCase() const SAL_THROW(())
+    SAL_WARN_UNUSED_RESULT OString toAsciiLowerCase() const SAL_THROW(())
     {
         rtl_String* pNew = 0;
         rtl_string_newToAsciiLowerCase( &pNew, pData );
@@ -1185,7 +1185,7 @@ public:
 
       @return   the string, converted to ASCII uppercase.
     */
-    OString toAsciiUpperCase() const SAL_THROW(())
+    SAL_WARN_UNUSED_RESULT OString toAsciiUpperCase() const SAL_THROW(())
     {
         rtl_String* pNew = 0;
         rtl_string_newToAsciiUpperCase( &pNew, pData );
@@ -1203,7 +1203,7 @@ public:
 
       @return   the string, with white space removed from the front and end.
     */
-    OString trim() const SAL_THROW(())
+    SAL_WARN_UNUSED_RESULT OString trim() const SAL_THROW(())
     {
         rtl_String* pNew = 0;
         rtl_string_newTrim( &pNew, pData );
diff --git a/sal/inc/rtl/ustring.hxx b/sal/inc/rtl/ustring.hxx
index 4fc1360..ebf548b 100644
--- a/sal/inc/rtl/ustring.hxx
+++ b/sal/inc/rtl/ustring.hxx
@@ -1394,7 +1394,7 @@ public:
       @return   a string that represents the concatenation of this string
                 followed by the string argument.
     */
-    OUString concat( const OUString & str ) const SAL_THROW(())
+    SAL_WARN_UNUSED_RESULT OUString concat( const OUString & str ) const SAL_THROW(())
     {
         rtl_uString* pNew = 0;
         rtl_uString_newConcat( &pNew, pData, str.pData );
@@ -1419,7 +1419,7 @@ public:
       @param  newStr  the new substring.
       @return the new string.
     */
-    OUString replaceAt( sal_Int32 index, sal_Int32 count, const OUString& newStr ) const SAL_THROW(())
+    SAL_WARN_UNUSED_RESULT OUString replaceAt( sal_Int32 index, sal_Int32 count, const OUString& newStr ) const SAL_THROW(())
     {
         rtl_uString* pNew = 0;
         rtl_uString_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
@@ -1439,7 +1439,7 @@ public:
       @return   a string derived from this string by replacing every
                 occurrence of oldChar with newChar.
     */
-    OUString replace( sal_Unicode oldChar, sal_Unicode newChar ) const SAL_THROW(())
+    SAL_WARN_UNUSED_RESULT OUString replace( sal_Unicode oldChar, sal_Unicode newChar ) const SAL_THROW(())
     {
         rtl_uString* pNew = 0;
         rtl_uString_newReplace( &pNew, pData, oldChar, newChar );
@@ -1464,7 +1464,7 @@ public:
 
       @since LibreOffice 3.6
     */
-    OUString replaceFirst(
+    SAL_WARN_UNUSED_RESULT OUString replaceFirst(
         OUString const & from, OUString const & to, sal_Int32 * index = 0) const
     {
         rtl_uString * s = 0;
@@ -1493,8 +1493,8 @@ public:
       @since LibreOffice 3.6
     */
     template< typename T >
-    typename internal::ConstCharArrayDetector< T, OUString >::Type replaceFirst( T& from, OUString const & to,
-                           sal_Int32 * index = 0) const
+    SAL_WARN_UNUSED_RESULT typename internal::ConstCharArrayDetector< T, OUString >::Type replaceFirst( T& from, OUString const & to,
+                                                                                                        sal_Int32 * index = 0) const
     {
         rtl_uString * s = 0;
         sal_Int32 i = 0;
@@ -1522,7 +1522,7 @@ public:
       @since LibreOffice 3.6
     */
     template< typename T1, typename T2 >
-    typename internal::ConstCharArrayDetector< T1, typename internal::ConstCharArrayDetector< T2, OUString >::Type >::Type
+        SAL_WARN_UNUSED_RESULT typename internal::ConstCharArrayDetector< T1, typename internal::ConstCharArrayDetector< T2, OUString >::Type >::Type
         replaceFirst( T1& from, T2& to, sal_Int32 * index = 0) const
     {
         rtl_uString * s = 0;
@@ -1609,7 +1609,7 @@ public:
 
       @return   the string, converted to ASCII lowercase.
     */
-    OUString toAsciiLowerCase() const SAL_THROW(())
+    SAL_WARN_UNUSED_RESULT OUString toAsciiLowerCase() const SAL_THROW(())
     {
         rtl_uString* pNew = 0;
         rtl_uString_newToAsciiLowerCase( &pNew, pData );
@@ -1626,7 +1626,7 @@ public:
 
       @return   the string, converted to ASCII uppercase.
     */
-    OUString toAsciiUpperCase() const SAL_THROW(())
+    SAL_WARN_UNUSED_RESULT OUString toAsciiUpperCase() const SAL_THROW(())
     {
         rtl_uString* pNew = 0;
         rtl_uString_newToAsciiUpperCase( &pNew, pData );
@@ -1644,7 +1644,7 @@ public:
 
       @return   the string, with white space removed from the front and end.
     */
-    OUString trim() const SAL_THROW(())
+    SAL_WARN_UNUSED_RESULT OUString trim() const SAL_THROW(())
     {
         rtl_uString* pNew = 0;
         rtl_uString_newTrim( &pNew, pData );
commit 04c79bcbbc3e646d7c9ae4f9388eb0134ec9a8b8
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Wed Nov 28 13:39:49 2012 +0100

    Clean up previous rtl::OUStringBuffer changes
    
    The OUString assignment operator is less transactional than it could be, but is
    also not necessasry, as OUStringBuffer has a non-explicit conversion constructor
    from OUString.
    
    Added some missing @since tags.
    
    Change-Id: I830be93fde78422c5a7eff9437b53e2d2d70933a

diff --git a/sal/inc/rtl/ustrbuf.hxx b/sal/inc/rtl/ustrbuf.hxx
index ecea715..d8db905 100644
--- a/sal/inc/rtl/ustrbuf.hxx
+++ b/sal/inc/rtl/ustrbuf.hxx
@@ -223,15 +223,6 @@ public:
         return *this;
     }
 
-    /** Assign to this a copy of value.
-     */
-    OUStringBuffer& operator = ( const OUString& value )
-    {
-        remove();
-        append(value);
-        return *this;
-    }
-
     /**
         Release the string data.
      */
@@ -415,6 +406,8 @@ public:
 
         @param   str   a string.
         @return  this string buffer.
+
+        @since LibreOffice 4.0
      */
     OUStringBuffer & append(OUStringBuffer &str)
     {
@@ -945,6 +938,8 @@ public:
 
         @param  start       The beginning index, inclusive. default to 0
         @return this string buffer.
+
+        @since LibreOffice 4.0
      */
     OUStringBuffer & remove( sal_Int32 start = 0)
     {
commit 6676c4ebbd264448e1d7871c91c1b3ba72c0dda0
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Wed Nov 28 13:32:31 2012 +0100

    Fix rtl::OUString::compareToIgnoreAsciiCase
    
    Change-Id: I40005ef4fad4d44314ec2fb2881fec82e926970e

diff --git a/sal/inc/rtl/ustring.hxx b/sal/inc/rtl/ustring.hxx
index aeb2b79..4fc1360 100644
--- a/sal/inc/rtl/ustring.hxx
+++ b/sal/inc/rtl/ustring.hxx
@@ -527,8 +527,8 @@ public:
     /**
       Perform a ASCII lowercase comparison of two strings.
 
-      Compare teh two string with uppercase ASCII
-      character values between 65 and 90 (ASCII A-Z) are interpreted as
+      Compare the two strings with uppercase ASCII
+      character values between 65 and 90 (ASCII A-Z) interpreted as
       values between 97 and 122 (ASCII a-z).
       This function can't be used for language specific comparison.
 
@@ -536,13 +536,11 @@ public:
       @return   0 - if both strings are equal
                 < 0 - if this string is less than the string argument
                 > 0 - if this string is greater than the string argument
+
+      @since LibreOffice 4.0
     */
     sal_Int32 compareToIgnoreAsciiCase( const OUString & str ) const SAL_THROW(())
     {
-        if ( pData->length != str.pData->length )
-            return sal_False;
-        if ( pData == str.pData )
-            return sal_True;
         return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
                                                            str.pData->buffer, str.pData->length );
     }
diff --git a/sal/qa/rtl/strings/test_oustring_compare.cxx b/sal/qa/rtl/strings/test_oustring_compare.cxx
index c41c223..8b506b7 100644
--- a/sal/qa/rtl/strings/test_oustring_compare.cxx
+++ b/sal/qa/rtl/strings/test_oustring_compare.cxx
@@ -32,9 +32,12 @@ private:
 
     void compareToAscii();
 
+    void compareToIgnoreAsciiCase();
+
 CPPUNIT_TEST_SUITE(Compare);
 CPPUNIT_TEST(equalsIgnoreAsciiCaseAscii);
 CPPUNIT_TEST(compareToAscii);
+CPPUNIT_TEST(compareToIgnoreAsciiCase);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -70,4 +73,16 @@ void test::oustring::Compare::compareToAscii()
         sal_Int32(0), abc.compareToAscii(RTL_CONSTASCII_STRINGPARAM("a")));
 }
 
+void test::oustring::Compare::compareToIgnoreAsciiCase()
+{
+    CPPUNIT_ASSERT_EQUAL(
+        sal_Int32(0),
+        rtl::OUString("abc").compareToIgnoreAsciiCase(rtl::OUString("ABC")));
+    CPPUNIT_ASSERT(
+        rtl::OUString("ABC").compareToIgnoreAsciiCase(rtl::OUString("abcdef"))
+        < 0);
+    CPPUNIT_ASSERT(
+        rtl::OUString("A").compareToIgnoreAsciiCase(rtl::OUString("_")) > 0);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list