Kaydet (Commit) 2ebda60b authored tarafından Luboš Luňák's avatar Luboš Luňák

more SFINAE to distinguish between const char* and const char[]

üst 86ebc847
...@@ -799,18 +799,8 @@ public: ...@@ -799,18 +799,8 @@ public:
friend sal_Bool operator == ( const OString& rStr1, const OString& rStr2 ) SAL_THROW(()) friend sal_Bool operator == ( const OString& rStr1, const OString& rStr2 ) SAL_THROW(())
{ return rStr1.getLength() == rStr2.getLength() && rStr1.compareTo( rStr2 ) == 0; } { 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(()) friend sal_Bool operator != ( const OString& rStr1, const OString& rStr2 ) SAL_THROW(())
{ return !(operator == ( rStr1, rStr2 )); } { 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(()) friend sal_Bool operator < ( const OString& rStr1, const OString& rStr2 ) SAL_THROW(())
{ return rStr1.compareTo( rStr2 ) < 0; } { return rStr1.compareTo( rStr2 ) < 0; }
friend sal_Bool operator > ( const OString& rStr1, const OString& rStr2 ) SAL_THROW(()) friend sal_Bool operator > ( const OString& rStr1, const OString& rStr2 ) SAL_THROW(())
...@@ -820,6 +810,18 @@ public: ...@@ -820,6 +810,18 @@ public:
friend sal_Bool operator >= ( const OString& rStr1, const OString& rStr2 ) SAL_THROW(()) friend sal_Bool operator >= ( const OString& rStr1, const OString& rStr2 ) SAL_THROW(())
{ return rStr1.compareTo( rStr2 ) >= 0; } { 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 @overload
This function accepts an ASCII string literal as its argument. This function accepts an ASCII string literal as its argument.
...@@ -829,8 +831,8 @@ public: ...@@ -829,8 +831,8 @@ public:
friend bool operator == ( const OString& rStr, const char (&literal)[ N ] ) SAL_THROW(()) friend bool operator == ( const OString& rStr, const char (&literal)[ N ] ) SAL_THROW(())
{ {
RTL_STRING_CONST_FUNCTION RTL_STRING_CONST_FUNCTION
return rStr.getLength() == N - 1 && rtl_str_compare_WithLength( rStr.pData->buffer, rStr.pData->length, return rStr.getLength() == N - 1
literal, N - 1 ); && rtl_str_compare_WithLength( rStr.pData->buffer, rStr.pData->length, literal, N - 1 ) == 0;
} }
/** /**
...@@ -856,8 +858,8 @@ public: ...@@ -856,8 +858,8 @@ public:
friend bool operator == ( const char (&literal)[ N ], const OString& rStr ) SAL_THROW(()) friend bool operator == ( const char (&literal)[ N ], const OString& rStr ) SAL_THROW(())
{ {
RTL_STRING_CONST_FUNCTION RTL_STRING_CONST_FUNCTION
return rStr.getLength() == N - 1 && rtl_str_compare_WithLength( rStr.pData->buffer, rStr.pData->length, return rStr.getLength() == N - 1
literal, N - 1 ); && rtl_str_compare_WithLength( rStr.pData->buffer, rStr.pData->length, literal, N - 1 ) == 0;
} }
/** /**
...@@ -874,6 +876,18 @@ public: ...@@ -874,6 +876,18 @@ public:
return rStr.compareTo( value ) == 0; 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 @overload
This function accepts an ASCII string literal as its argument. This function accepts an ASCII string literal as its argument.
......
...@@ -149,20 +149,48 @@ void test::ostring::StringLiterals::checkUsage() ...@@ -149,20 +149,48 @@ void test::ostring::StringLiterals::checkUsage()
rtl_string_unittest_const_literal = false; // start checking for OString conversions 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_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_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( 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( 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( 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( 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( 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( 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( 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( foo == "foo" );
CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function == true );
rtl_string_unittest_const_literal_function = false;
CPPUNIT_ASSERT( "foo" == foo ); 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( foo != "bar" );
CPPUNIT_ASSERT( rtl_string_unittest_const_literal_function == true );
rtl_string_unittest_const_literal_function = false;
CPPUNIT_ASSERT( "foo" != bar ); 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( 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( 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 // if this is not true, some of the calls above converted to OString
CPPUNIT_ASSERT( rtl_string_unittest_const_literal == false ); CPPUNIT_ASSERT( rtl_string_unittest_const_literal == false );
// if this is not true, some of the calls above used non-const variants // if this is not true, some of the calls above used non-const variants
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment