diff --git a/string/public/nsAString.h b/string/public/nsAString.h index ab48f175f11e..46d83f19b84a 100644 --- a/string/public/nsAString.h +++ b/string/public/nsAString.h @@ -41,6 +41,40 @@ #endif +class NS_COM nsStringComparator + { + public: + typedef PRUnichar char_type; + + virtual int operator()( const char_type*, const char_type*, PRUint32 aLength ) const = 0; + virtual int operator()( char_type, char_type ) const = 0; + }; + +class NS_COM nsDefaultStringComparator + : public nsStringComparator + { + public: + virtual int operator()( const char_type*, const char_type*, PRUint32 aLength ) const; + virtual int operator() ( char_type, char_type ) const; + }; + +class NS_COM nsCStringComparator + { + public: + typedef char char_type; + + virtual int operator()( const char_type*, const char_type*, PRUint32 aLength ) const = 0; + virtual int operator() ( char_type, char_type ) const = 0; + }; + +class NS_COM nsDefaultCStringComparator + : public nsCStringComparator + { + public: + virtual int operator()( const char_type*, const char_type*, PRUint32 aLength ) const; + virtual int operator()( char_type, char_type ) const; + }; + /** * |nsAC?String| is the most abstract class in the string hierarchy. * Strings implementing |nsAC?String| may be stored in multiple @@ -105,8 +139,8 @@ class NS_COM nsAString virtual size_type Length() const = 0; PRBool IsEmpty() const { return Length() == 0; } - inline PRBool Equals( const self_type& ) const; - PRBool Equals( const char_type* ) const; + inline PRBool Equals( const abstract_string_type&, const nsStringComparator& = nsDefaultStringComparator() ) const; + PRBool Equals( const char_type*, const nsStringComparator& = nsDefaultStringComparator() ) const; virtual PRBool IsVoid() const; virtual void SetIsVoid( PRBool ); @@ -380,8 +414,8 @@ class NS_COM nsACString virtual size_type Length() const = 0; PRBool IsEmpty() const { return Length() == 0; } - inline PRBool Equals( const self_type& ) const; - PRBool Equals( const char_type* ) const; + inline PRBool Equals( const abstract_string_type&, const nsCStringComparator& = nsDefaultCStringComparator() ) const; + PRBool Equals( const char_type*, const nsCStringComparator& = nsDefaultCStringComparator() ) const; virtual PRBool IsVoid() const; virtual void SetIsVoid( PRBool ); @@ -694,30 +728,13 @@ nsAString::EndWriting( iterator& aResult ) return aResult; } -class NS_COM nsStringComparator - { - public: - typedef nsAString::char_type char_type; - - virtual int operator()( const char_type*, const char_type*, PRUint32 aLength ) const = 0; - virtual int operator()( char_type, char_type ) const = 0; - }; - -class NS_COM nsDefaultStringComparator - : public nsStringComparator - { - public: - virtual int operator()( const char_type*, const char_type*, PRUint32 aLength ) const; - virtual int operator() ( char_type, char_type ) const; - }; - NS_COM int Compare( const nsAString& lhs, const nsAString& rhs, const nsStringComparator& = nsDefaultStringComparator() ); inline PRBool -nsAString::Equals( const self_type& rhs ) const +nsAString::Equals( const abstract_string_type& rhs, const nsStringComparator& aComparator ) const { - return Length()==rhs.Length() && Compare(*this, rhs)==0; + return Length()==rhs.Length() && Compare(*this, rhs, aComparator)==0; } inline @@ -820,23 +837,6 @@ nsACString::EndWriting( iterator& aResult ) } -class NS_COM nsCStringComparator - { - public: - typedef nsACString::char_type char_type; - - virtual int operator()( const char_type*, const char_type*, PRUint32 aLength ) const = 0; - virtual int operator() ( char_type, char_type ) const = 0; - }; - -class NS_COM nsDefaultCStringComparator - : public nsCStringComparator - { - public: - virtual int operator()( const char_type*, const char_type*, PRUint32 aLength ) const; - virtual int operator()( char_type, char_type ) const; - }; - class NS_COM nsCaseInsensitiveCStringComparator : public nsCStringComparator { @@ -849,9 +849,9 @@ NS_COM int Compare( const nsACString& lhs, const nsACString& rhs, const nsCStrin inline PRBool -nsACString::Equals( const self_type& rhs ) const +nsACString::Equals( const abstract_string_type& rhs, const nsCStringComparator& aComparator ) const { - return Length()==rhs.Length() && Compare(*this, rhs)==0; + return Length()==rhs.Length() && Compare(*this, rhs, aComparator)==0; } inline diff --git a/string/src/nsAString.cpp b/string/src/nsAString.cpp index 579e77790c78..133ec000cfb0 100644 --- a/string/src/nsAString.cpp +++ b/string/src/nsAString.cpp @@ -127,9 +127,9 @@ nsAString::SetIsVoid( PRBool ) } PRBool -nsAString::Equals( const char_type* rhs ) const +nsAString::Equals( const char_type* rhs, const nsStringComparator& aComparator ) const { - return Equals(nsDependentString(rhs)); + return Equals(nsDependentString(rhs), aComparator); } @@ -648,9 +648,9 @@ nsACString::SetIsVoid( PRBool ) } PRBool -nsACString::Equals( const char_type* rhs ) const +nsACString::Equals( const char_type* rhs, const nsCStringComparator& aComparator ) const { - return Equals(nsDependentCString(rhs)); + return Equals(nsDependentCString(rhs), aComparator); } nsACString::char_type diff --git a/xpcom/string/public/nsAString.h b/xpcom/string/public/nsAString.h index ab48f175f11e..46d83f19b84a 100644 --- a/xpcom/string/public/nsAString.h +++ b/xpcom/string/public/nsAString.h @@ -41,6 +41,40 @@ #endif +class NS_COM nsStringComparator + { + public: + typedef PRUnichar char_type; + + virtual int operator()( const char_type*, const char_type*, PRUint32 aLength ) const = 0; + virtual int operator()( char_type, char_type ) const = 0; + }; + +class NS_COM nsDefaultStringComparator + : public nsStringComparator + { + public: + virtual int operator()( const char_type*, const char_type*, PRUint32 aLength ) const; + virtual int operator() ( char_type, char_type ) const; + }; + +class NS_COM nsCStringComparator + { + public: + typedef char char_type; + + virtual int operator()( const char_type*, const char_type*, PRUint32 aLength ) const = 0; + virtual int operator() ( char_type, char_type ) const = 0; + }; + +class NS_COM nsDefaultCStringComparator + : public nsCStringComparator + { + public: + virtual int operator()( const char_type*, const char_type*, PRUint32 aLength ) const; + virtual int operator()( char_type, char_type ) const; + }; + /** * |nsAC?String| is the most abstract class in the string hierarchy. * Strings implementing |nsAC?String| may be stored in multiple @@ -105,8 +139,8 @@ class NS_COM nsAString virtual size_type Length() const = 0; PRBool IsEmpty() const { return Length() == 0; } - inline PRBool Equals( const self_type& ) const; - PRBool Equals( const char_type* ) const; + inline PRBool Equals( const abstract_string_type&, const nsStringComparator& = nsDefaultStringComparator() ) const; + PRBool Equals( const char_type*, const nsStringComparator& = nsDefaultStringComparator() ) const; virtual PRBool IsVoid() const; virtual void SetIsVoid( PRBool ); @@ -380,8 +414,8 @@ class NS_COM nsACString virtual size_type Length() const = 0; PRBool IsEmpty() const { return Length() == 0; } - inline PRBool Equals( const self_type& ) const; - PRBool Equals( const char_type* ) const; + inline PRBool Equals( const abstract_string_type&, const nsCStringComparator& = nsDefaultCStringComparator() ) const; + PRBool Equals( const char_type*, const nsCStringComparator& = nsDefaultCStringComparator() ) const; virtual PRBool IsVoid() const; virtual void SetIsVoid( PRBool ); @@ -694,30 +728,13 @@ nsAString::EndWriting( iterator& aResult ) return aResult; } -class NS_COM nsStringComparator - { - public: - typedef nsAString::char_type char_type; - - virtual int operator()( const char_type*, const char_type*, PRUint32 aLength ) const = 0; - virtual int operator()( char_type, char_type ) const = 0; - }; - -class NS_COM nsDefaultStringComparator - : public nsStringComparator - { - public: - virtual int operator()( const char_type*, const char_type*, PRUint32 aLength ) const; - virtual int operator() ( char_type, char_type ) const; - }; - NS_COM int Compare( const nsAString& lhs, const nsAString& rhs, const nsStringComparator& = nsDefaultStringComparator() ); inline PRBool -nsAString::Equals( const self_type& rhs ) const +nsAString::Equals( const abstract_string_type& rhs, const nsStringComparator& aComparator ) const { - return Length()==rhs.Length() && Compare(*this, rhs)==0; + return Length()==rhs.Length() && Compare(*this, rhs, aComparator)==0; } inline @@ -820,23 +837,6 @@ nsACString::EndWriting( iterator& aResult ) } -class NS_COM nsCStringComparator - { - public: - typedef nsACString::char_type char_type; - - virtual int operator()( const char_type*, const char_type*, PRUint32 aLength ) const = 0; - virtual int operator() ( char_type, char_type ) const = 0; - }; - -class NS_COM nsDefaultCStringComparator - : public nsCStringComparator - { - public: - virtual int operator()( const char_type*, const char_type*, PRUint32 aLength ) const; - virtual int operator()( char_type, char_type ) const; - }; - class NS_COM nsCaseInsensitiveCStringComparator : public nsCStringComparator { @@ -849,9 +849,9 @@ NS_COM int Compare( const nsACString& lhs, const nsACString& rhs, const nsCStrin inline PRBool -nsACString::Equals( const self_type& rhs ) const +nsACString::Equals( const abstract_string_type& rhs, const nsCStringComparator& aComparator ) const { - return Length()==rhs.Length() && Compare(*this, rhs)==0; + return Length()==rhs.Length() && Compare(*this, rhs, aComparator)==0; } inline diff --git a/xpcom/string/src/nsAString.cpp b/xpcom/string/src/nsAString.cpp index 579e77790c78..133ec000cfb0 100644 --- a/xpcom/string/src/nsAString.cpp +++ b/xpcom/string/src/nsAString.cpp @@ -127,9 +127,9 @@ nsAString::SetIsVoid( PRBool ) } PRBool -nsAString::Equals( const char_type* rhs ) const +nsAString::Equals( const char_type* rhs, const nsStringComparator& aComparator ) const { - return Equals(nsDependentString(rhs)); + return Equals(nsDependentString(rhs), aComparator); } @@ -648,9 +648,9 @@ nsACString::SetIsVoid( PRBool ) } PRBool -nsACString::Equals( const char_type* rhs ) const +nsACString::Equals( const char_type* rhs, const nsCStringComparator& aComparator ) const { - return Equals(nsDependentCString(rhs)); + return Equals(nsDependentCString(rhs), aComparator); } nsACString::char_type