summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@suse.cz>2012-03-28 08:56:05 +0200
committerLuboš Luňák <l.lunak@suse.cz>2012-03-28 09:07:17 +0200
commit2ebda60bfe7897ac371dd7ee97c4309e72f20e4b (patch)
treef6f42a14ccd351201aae4a9f316617f8cec50b3d
parent86ebc8471d5e056a1240e5f9d487c5b1c9b3d423 (diff)
more SFINAE to distinguish between const char* and const char[]
-rw-r--r--sal/inc/rtl/string.hxx42
-rw-r--r--sal/qa/rtl/strings/test_ostring_stringliterals.cxx28
2 files changed, 56 insertions, 14 deletions
diff --git a/sal/inc/rtl/string.hxx b/sal/inc/rtl/string.hxx
index e7db97b6ed4e..0593ddf25eec 100644
--- a/sal/inc/rtl/string.hxx
+++ b/sal/inc/rtl/string.hxx
@@ -799,18 +799,8 @@ public:
friend sal_Bool operator == ( const OString& rStr1, const OString& rStr2 ) SAL_THROW(())
{ return rStr1.getLength() == rStr2.getLength() && rStr1.compareTo( rStr2 ) == 0; }
- friend sal_Bool operator == ( const OString& rStr1, const sal_Char * pStr2 ) SAL_THROW(())
- { return rStr1.compareTo( pStr2 ) == 0; }
- friend sal_Bool operator == ( const sal_Char * pStr1, const OString& rStr2 ) SAL_THROW(())
- { return OString( pStr1 ).compareTo( rStr2 ) == 0; }
-
friend sal_Bool operator != ( const OString& rStr1, const OString& rStr2 ) SAL_THROW(())
{ return !(operator == ( rStr1, rStr2 )); }
- friend sal_Bool operator != ( const OString& rStr1, const sal_Char * pStr2 ) SAL_THROW(())
- { return !(operator == ( rStr1, pStr2 )); }
- friend sal_Bool operator != ( const sal_Char * pStr1, const OString& rStr2 ) SAL_THROW(())
- { return !(operator == ( pStr1, rStr2 )); }
-
friend sal_Bool operator < ( const OString& rStr1, const OString& rStr2 ) SAL_THROW(())
{ return rStr1.compareTo( rStr2 ) < 0; }
friend sal_Bool operator > ( const OString& rStr1, const OString& rStr2 ) SAL_THROW(())
@@ -820,6 +810,18 @@ public:
friend sal_Bool operator >= ( const OString& rStr1, const OString& rStr2 ) SAL_THROW(())
{ return rStr1.compareTo( rStr2 ) >= 0; }
+ template< typename T >
+ friend typename internal::CharPtrDetector< T, bool >::Type operator==( const OString& rStr1, const T& value ) SAL_THROW(())
+ {
+ return rStr1.compareTo( value ) == 0;
+ }
+
+ template< typename T >
+ friend typename internal::CharPtrDetector< T, bool >::Type operator==( const T& value, const OString& rStr2 ) SAL_THROW(())
+ {
+ return rStr2.compareTo( value ) == 0;
+ }
+
/**
@overload
This function accepts an ASCII string literal as its argument.
@@ -829,8 +831,8 @@ public:
friend bool operator == ( const OString& rStr, const char (&literal)[ N ] ) SAL_THROW(())
{
RTL_STRING_CONST_FUNCTION
- return rStr.getLength() == N - 1 && rtl_str_compare_WithLength( rStr.pData->buffer, rStr.pData->length,
- literal, N - 1 );
+ return rStr.getLength() == N - 1
+ && rtl_str_compare_WithLength( rStr.pData->buffer, rStr.pData->length, literal, N - 1 ) == 0;
}
/**
@@ -856,8 +858,8 @@ public:
friend bool operator == ( const char (&literal)[ N ], const OString& rStr ) SAL_THROW(())
{
RTL_STRING_CONST_FUNCTION
- return rStr.getLength() == N - 1 && rtl_str_compare_WithLength( rStr.pData->buffer, rStr.pData->length,
- literal, N - 1 );
+ return rStr.getLength() == N - 1
+ && rtl_str_compare_WithLength( rStr.pData->buffer, rStr.pData->length, literal, N - 1 ) == 0;
}
/**
@@ -874,6 +876,18 @@ public:
return rStr.compareTo( value ) == 0;
}
+ template< typename T >
+ friend typename internal::CharPtrDetector< T, bool >::Type operator!=( const OString& rStr1, const T& value ) SAL_THROW(())
+ {
+ return !(operator == ( rStr1, value ));
+ }
+
+ template< typename T >
+ friend typename internal::CharPtrDetector< T, bool >::Type operator!=( const T& value, const OString& rStr2 ) SAL_THROW(())
+ {
+ return !(operator == ( value, rStr2 ));
+ }
+
/**
@overload
This function accepts an ASCII string literal as its argument.
diff --git a/sal/qa/rtl/strings/test_ostring_stringliterals.cxx b/sal/qa/rtl/strings/test_ostring_stringliterals.cxx
index 0ada7097221b..4af152c4f7c7 100644
--- a/sal/qa/rtl/strings/test_ostring_stringliterals.cxx
+++ b/sal/qa/rtl/strings/test_ostring_stringliterals.cxx
@@ -149,20 +149,48 @@ void test::ostring::StringLiterals::checkUsage()
rtl_string_unittest_const_literal = false; // start checking for OString conversions
rtl_string_unittest_non_const_literal_function = false; // and check for non-const variants
+ rtl_string_unittest_const_literal_function = false;
CPPUNIT_ASSERT_EQUAL( foo, rtl::OString() = "foo" );
+ CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function == true );
+ rtl_string_unittest_const_literal_function = false;
CPPUNIT_ASSERT( FoO.equalsIgnoreAsciiCase( "fOo" ));
+ CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function == true );
+ rtl_string_unittest_const_literal_function = false;
CPPUNIT_ASSERT( foobarfoo.match( "bar", 3 ));
+ CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function == true );
+ rtl_string_unittest_const_literal_function = false;
CPPUNIT_ASSERT( foobar.match( "foo" ));
+ CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function == true );
+ rtl_string_unittest_const_literal_function = false;
CPPUNIT_ASSERT( FooBaRfoo.matchIgnoreAsciiCase( "bAr", 3 ));
+ CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function == true );
+ rtl_string_unittest_const_literal_function = false;
CPPUNIT_ASSERT( FooBaR.matchIgnoreAsciiCase( "fOo" ));
+ CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function == true );
+ rtl_string_unittest_const_literal_function = false;
CPPUNIT_ASSERT( foobar.endsWith( "bar" ));
+ CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function == true );
+// rtl_string_unittest_const_literal_function = false;
// CPPUNIT_ASSERT( FooBaR.endsWithIgnoreAsciiCase( "bar" ));
+// CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function == true );
+ rtl_string_unittest_const_literal_function = false;
CPPUNIT_ASSERT( foo == "foo" );
+ CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function == true );
+ rtl_string_unittest_const_literal_function = false;
CPPUNIT_ASSERT( "foo" == foo );
+ CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function == true );
+ rtl_string_unittest_const_literal_function = false;
CPPUNIT_ASSERT( foo != "bar" );
+ CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function == true );
+ rtl_string_unittest_const_literal_function = false;
CPPUNIT_ASSERT( "foo" != bar );
+ CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function == true );
+ rtl_string_unittest_const_literal_function = false;
CPPUNIT_ASSERT( foobarfoo.indexOf( "foo", 1 ) == 6 );
+ CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function == true );
+// rtl_string_unittest_const_literal_function = false;
// CPPUNIT_ASSERT( foobarfoo.lastIndexOf( "foo" ) == 6 );
+// CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function == true );
// if this is not true, some of the calls above converted to OString
CPPUNIT_ASSERT( rtl_string_unittest_const_literal == false );
// if this is not true, some of the calls above used non-const variants