diff --git a/mozilla/string/public/nsAReadableString.h b/mozilla/string/public/nsAReadableString.h index 61f46691411..a322e7ab442 100644 --- a/mozilla/string/public/nsAReadableString.h +++ b/mozilla/string/public/nsAReadableString.h @@ -119,15 +119,14 @@ class basic_nsAReadableString CharT operator*() { - normalize_forward(); return *mPosition; } ConstIterator& operator++() { - normalize_forward(); ++mPosition; + normalize_forward(); return *this; } @@ -135,8 +134,8 @@ class basic_nsAReadableString operator++( int ) { ConstIterator result(*this); - normalize_forward(); ++mPosition; + normalize_forward(); return result; } @@ -144,7 +143,7 @@ class basic_nsAReadableString operator--() { normalize_backward(); - ++mPosition; + --mPosition; return *this; } @@ -153,17 +152,17 @@ class basic_nsAReadableString { ConstIterator result(*this); normalize_backward(); - ++mPosition; + --mPosition; return result; } - bool + PRBool operator==( const ConstIterator& rhs ) { return mPosition == rhs.mPosition; } - bool + PRBool operator!=( const ConstIterator& rhs ) { return mPosition != rhs.mPosition; @@ -185,7 +184,7 @@ class basic_nsAReadableString End( PRUint32 aOffset = 0 ) const { ConstFragment fragment(this); - const CharT* startPos = GetFragment(fragment, kFragmentAt, min(0U, Length()-aOffset)); + const CharT* startPos = GetFragment(fragment, kFragmentAt, max(0U, Length()-aOffset)); return ConstIterator(fragment, startPos); } @@ -202,8 +201,8 @@ class basic_nsAReadableString PRBool IsUnicode() const { return PR_FALSE; } // ...but note specialization for |PRUnichar|, below - const CharT* GetBuffer() const { return 0; } - const CharT* GetUnicode() const { return 0; } + const char* GetBuffer() const { return 0; } + const PRUnichar* GetUnicode() const { return 0; } // ...but note specializations for |char| and |PRUnichar|, below // CharT operator[]( PRUint32 ) const; @@ -362,35 +361,98 @@ basic_nsAReadableString::Right( basic_nsAWritableString& aResult, return aLengthToCopy; } +template +int +Compare( const basic_nsAReadableString& lhs, const basic_nsAReadableString& rhs ) + { + PRUint32 lLength = lhs.Length(); + PRUint32 rLength = rhs.Length(); + int result = 0; + if ( lLength < rLength ) + result = -1; + else if ( lLength > rLength ) + result = 1; + + PRUint32 lengthToCompare = min(lLength, rLength); + + typedef typename basic_nsAReadableString::ConstIterator ConstIterator; + ConstIterator lPos = lhs.Begin(); + ConstIterator lEnd = lhs.Begin(lengthToCompare); + ConstIterator rPos = rhs.Begin(); + + while ( lPos != lEnd ) + { + if ( *lPos < *rPos ) + return -1; + if ( *rPos < *lPos ) + return 1; + + ++lPos; + ++rPos; + } + + return result; + } + template inline int basic_nsAReadableString::Compare( const basic_nsAReadableString& rhs ) const { - // ... + return ::Compare(*this, rhs); } -// readable != readable +template +PRBool +operator!=( const basic_nsAReadableString& lhs, const basic_nsAReadableString& rhs ) + { + return lhs.Compare(rhs) != 0; + } // readable != CharT* // CharT* != readable -// readable < readable +template +PRBool +operator<( const basic_nsAReadableString& lhs, const basic_nsAReadableString& rhs ) + { + return lhs.Compare(rhs) < 0; + } // readable < CharT* // CharT* < readable -// readable <= readable +template +PRBool +operator<=( const basic_nsAReadableString& lhs, const basic_nsAReadableString& rhs ) + { + return lhs.Compare(rhs) <= 0; + } // readable <= CharT* // CharT* <= readable -// readable == readable +template +PRBool +operator==( const basic_nsAReadableString& lhs, const basic_nsAReadableString& rhs ) + { + return lhs.Compare(rhs) == 0; + } // readable == CharT* // CharT* == readable -// readable >= readable +template +PRBool +operator>=( const basic_nsAReadableString& lhs, const basic_nsAReadableString& rhs ) + { + return lhs.Compare(rhs) >= 0; + } // readable >= CharT* // CharT* >= readable -// readable > readable +template +PRBool +operator>( const basic_nsAReadableString& lhs, const basic_nsAReadableString& rhs ) + { + return lhs.Compare(rhs) > 0; + } // readable > CharT* // CharT* > readable @@ -419,7 +481,7 @@ template class nsConcatString : public basic_nsAReadableString /* - ...not unlike RickG's original |nsSubsumeString| in intent. + ...not unlike RickG's original |nsSubsumeString| in _intent_. */ { public: @@ -427,9 +489,26 @@ class nsConcatString // ... }; -// readable + readable --> concat -// readable + CharT* --> concat -// CharT* + readable --> concat +template +nsConcatString +operator+( const basic_nsAReadableString&, const basic_nsAReadableString& ) + { + // ... + } + +template +nsConcatString +operator+( const basic_nsAReadableString&, const CharT* ) + { + // ... + } + +template +nsConcatString +operator+( const CharT*, const basic_nsAReadableString& ) + { + // ... + } template basic_ostream& diff --git a/mozilla/string/public/nsAWritableString.h b/mozilla/string/public/nsAWritableString.h index 2ccc8ec8023..750e5c46c99 100644 --- a/mozilla/string/public/nsAWritableString.h +++ b/mozilla/string/public/nsAWritableString.h @@ -108,15 +108,14 @@ class basic_nsAWritableString CharT& operator*() { - normalize_forward(); return *mPosition; } Iterator& operator++() { - normalize_forward(); ++mPosition; + normalize_forward(); return *this; } @@ -124,8 +123,8 @@ class basic_nsAWritableString operator++( int ) { Iterator result(*this); - normalize_forward(); ++mPosition; + normalize_forward(); return result; } @@ -133,7 +132,7 @@ class basic_nsAWritableString operator--() { normalize_backward(); - ++mPosition; + --mPosition; return *this; } @@ -142,14 +141,20 @@ class basic_nsAWritableString { Iterator result(*this); normalize_backward(); - ++mPosition; + --mPosition; return result; } - const CharT* - get() const + PRBool + operator==( const ConstIterator& rhs ) { - return mPosition; + return mPosition == rhs.mPosition; + } + + PRBool + operator!=( const ConstIterator& rhs ) + { + return mPosition != rhs.mPosition; } }; @@ -170,7 +175,7 @@ class basic_nsAWritableString End( PRUint32 aOffset = 0 ) { Fragment fragment(this); - CharT* startPos = GetFragment(fragment, kFragmentAt, min(0U, Length()-aOffset)); + CharT* startPos = GetFragment(fragment, kFragmentAt, max(0U, Length()-aOffset)); return Iterator(fragment, startPos); } diff --git a/mozilla/xpcom/ds/nsAReadableString.h b/mozilla/xpcom/ds/nsAReadableString.h index 61f46691411..a322e7ab442 100644 --- a/mozilla/xpcom/ds/nsAReadableString.h +++ b/mozilla/xpcom/ds/nsAReadableString.h @@ -119,15 +119,14 @@ class basic_nsAReadableString CharT operator*() { - normalize_forward(); return *mPosition; } ConstIterator& operator++() { - normalize_forward(); ++mPosition; + normalize_forward(); return *this; } @@ -135,8 +134,8 @@ class basic_nsAReadableString operator++( int ) { ConstIterator result(*this); - normalize_forward(); ++mPosition; + normalize_forward(); return result; } @@ -144,7 +143,7 @@ class basic_nsAReadableString operator--() { normalize_backward(); - ++mPosition; + --mPosition; return *this; } @@ -153,17 +152,17 @@ class basic_nsAReadableString { ConstIterator result(*this); normalize_backward(); - ++mPosition; + --mPosition; return result; } - bool + PRBool operator==( const ConstIterator& rhs ) { return mPosition == rhs.mPosition; } - bool + PRBool operator!=( const ConstIterator& rhs ) { return mPosition != rhs.mPosition; @@ -185,7 +184,7 @@ class basic_nsAReadableString End( PRUint32 aOffset = 0 ) const { ConstFragment fragment(this); - const CharT* startPos = GetFragment(fragment, kFragmentAt, min(0U, Length()-aOffset)); + const CharT* startPos = GetFragment(fragment, kFragmentAt, max(0U, Length()-aOffset)); return ConstIterator(fragment, startPos); } @@ -202,8 +201,8 @@ class basic_nsAReadableString PRBool IsUnicode() const { return PR_FALSE; } // ...but note specialization for |PRUnichar|, below - const CharT* GetBuffer() const { return 0; } - const CharT* GetUnicode() const { return 0; } + const char* GetBuffer() const { return 0; } + const PRUnichar* GetUnicode() const { return 0; } // ...but note specializations for |char| and |PRUnichar|, below // CharT operator[]( PRUint32 ) const; @@ -362,35 +361,98 @@ basic_nsAReadableString::Right( basic_nsAWritableString& aResult, return aLengthToCopy; } +template +int +Compare( const basic_nsAReadableString& lhs, const basic_nsAReadableString& rhs ) + { + PRUint32 lLength = lhs.Length(); + PRUint32 rLength = rhs.Length(); + int result = 0; + if ( lLength < rLength ) + result = -1; + else if ( lLength > rLength ) + result = 1; + + PRUint32 lengthToCompare = min(lLength, rLength); + + typedef typename basic_nsAReadableString::ConstIterator ConstIterator; + ConstIterator lPos = lhs.Begin(); + ConstIterator lEnd = lhs.Begin(lengthToCompare); + ConstIterator rPos = rhs.Begin(); + + while ( lPos != lEnd ) + { + if ( *lPos < *rPos ) + return -1; + if ( *rPos < *lPos ) + return 1; + + ++lPos; + ++rPos; + } + + return result; + } + template inline int basic_nsAReadableString::Compare( const basic_nsAReadableString& rhs ) const { - // ... + return ::Compare(*this, rhs); } -// readable != readable +template +PRBool +operator!=( const basic_nsAReadableString& lhs, const basic_nsAReadableString& rhs ) + { + return lhs.Compare(rhs) != 0; + } // readable != CharT* // CharT* != readable -// readable < readable +template +PRBool +operator<( const basic_nsAReadableString& lhs, const basic_nsAReadableString& rhs ) + { + return lhs.Compare(rhs) < 0; + } // readable < CharT* // CharT* < readable -// readable <= readable +template +PRBool +operator<=( const basic_nsAReadableString& lhs, const basic_nsAReadableString& rhs ) + { + return lhs.Compare(rhs) <= 0; + } // readable <= CharT* // CharT* <= readable -// readable == readable +template +PRBool +operator==( const basic_nsAReadableString& lhs, const basic_nsAReadableString& rhs ) + { + return lhs.Compare(rhs) == 0; + } // readable == CharT* // CharT* == readable -// readable >= readable +template +PRBool +operator>=( const basic_nsAReadableString& lhs, const basic_nsAReadableString& rhs ) + { + return lhs.Compare(rhs) >= 0; + } // readable >= CharT* // CharT* >= readable -// readable > readable +template +PRBool +operator>( const basic_nsAReadableString& lhs, const basic_nsAReadableString& rhs ) + { + return lhs.Compare(rhs) > 0; + } // readable > CharT* // CharT* > readable @@ -419,7 +481,7 @@ template class nsConcatString : public basic_nsAReadableString /* - ...not unlike RickG's original |nsSubsumeString| in intent. + ...not unlike RickG's original |nsSubsumeString| in _intent_. */ { public: @@ -427,9 +489,26 @@ class nsConcatString // ... }; -// readable + readable --> concat -// readable + CharT* --> concat -// CharT* + readable --> concat +template +nsConcatString +operator+( const basic_nsAReadableString&, const basic_nsAReadableString& ) + { + // ... + } + +template +nsConcatString +operator+( const basic_nsAReadableString&, const CharT* ) + { + // ... + } + +template +nsConcatString +operator+( const CharT*, const basic_nsAReadableString& ) + { + // ... + } template basic_ostream& diff --git a/mozilla/xpcom/ds/nsAWritableString.h b/mozilla/xpcom/ds/nsAWritableString.h index 2ccc8ec8023..750e5c46c99 100644 --- a/mozilla/xpcom/ds/nsAWritableString.h +++ b/mozilla/xpcom/ds/nsAWritableString.h @@ -108,15 +108,14 @@ class basic_nsAWritableString CharT& operator*() { - normalize_forward(); return *mPosition; } Iterator& operator++() { - normalize_forward(); ++mPosition; + normalize_forward(); return *this; } @@ -124,8 +123,8 @@ class basic_nsAWritableString operator++( int ) { Iterator result(*this); - normalize_forward(); ++mPosition; + normalize_forward(); return result; } @@ -133,7 +132,7 @@ class basic_nsAWritableString operator--() { normalize_backward(); - ++mPosition; + --mPosition; return *this; } @@ -142,14 +141,20 @@ class basic_nsAWritableString { Iterator result(*this); normalize_backward(); - ++mPosition; + --mPosition; return result; } - const CharT* - get() const + PRBool + operator==( const ConstIterator& rhs ) { - return mPosition; + return mPosition == rhs.mPosition; + } + + PRBool + operator!=( const ConstIterator& rhs ) + { + return mPosition != rhs.mPosition; } }; @@ -170,7 +175,7 @@ class basic_nsAWritableString End( PRUint32 aOffset = 0 ) { Fragment fragment(this); - CharT* startPos = GetFragment(fragment, kFragmentAt, min(0U, Length()-aOffset)); + CharT* startPos = GetFragment(fragment, kFragmentAt, max(0U, Length()-aOffset)); return Iterator(fragment, startPos); } diff --git a/mozilla/xpcom/string/public/nsAReadableString.h b/mozilla/xpcom/string/public/nsAReadableString.h index 61f46691411..a322e7ab442 100644 --- a/mozilla/xpcom/string/public/nsAReadableString.h +++ b/mozilla/xpcom/string/public/nsAReadableString.h @@ -119,15 +119,14 @@ class basic_nsAReadableString CharT operator*() { - normalize_forward(); return *mPosition; } ConstIterator& operator++() { - normalize_forward(); ++mPosition; + normalize_forward(); return *this; } @@ -135,8 +134,8 @@ class basic_nsAReadableString operator++( int ) { ConstIterator result(*this); - normalize_forward(); ++mPosition; + normalize_forward(); return result; } @@ -144,7 +143,7 @@ class basic_nsAReadableString operator--() { normalize_backward(); - ++mPosition; + --mPosition; return *this; } @@ -153,17 +152,17 @@ class basic_nsAReadableString { ConstIterator result(*this); normalize_backward(); - ++mPosition; + --mPosition; return result; } - bool + PRBool operator==( const ConstIterator& rhs ) { return mPosition == rhs.mPosition; } - bool + PRBool operator!=( const ConstIterator& rhs ) { return mPosition != rhs.mPosition; @@ -185,7 +184,7 @@ class basic_nsAReadableString End( PRUint32 aOffset = 0 ) const { ConstFragment fragment(this); - const CharT* startPos = GetFragment(fragment, kFragmentAt, min(0U, Length()-aOffset)); + const CharT* startPos = GetFragment(fragment, kFragmentAt, max(0U, Length()-aOffset)); return ConstIterator(fragment, startPos); } @@ -202,8 +201,8 @@ class basic_nsAReadableString PRBool IsUnicode() const { return PR_FALSE; } // ...but note specialization for |PRUnichar|, below - const CharT* GetBuffer() const { return 0; } - const CharT* GetUnicode() const { return 0; } + const char* GetBuffer() const { return 0; } + const PRUnichar* GetUnicode() const { return 0; } // ...but note specializations for |char| and |PRUnichar|, below // CharT operator[]( PRUint32 ) const; @@ -362,35 +361,98 @@ basic_nsAReadableString::Right( basic_nsAWritableString& aResult, return aLengthToCopy; } +template +int +Compare( const basic_nsAReadableString& lhs, const basic_nsAReadableString& rhs ) + { + PRUint32 lLength = lhs.Length(); + PRUint32 rLength = rhs.Length(); + int result = 0; + if ( lLength < rLength ) + result = -1; + else if ( lLength > rLength ) + result = 1; + + PRUint32 lengthToCompare = min(lLength, rLength); + + typedef typename basic_nsAReadableString::ConstIterator ConstIterator; + ConstIterator lPos = lhs.Begin(); + ConstIterator lEnd = lhs.Begin(lengthToCompare); + ConstIterator rPos = rhs.Begin(); + + while ( lPos != lEnd ) + { + if ( *lPos < *rPos ) + return -1; + if ( *rPos < *lPos ) + return 1; + + ++lPos; + ++rPos; + } + + return result; + } + template inline int basic_nsAReadableString::Compare( const basic_nsAReadableString& rhs ) const { - // ... + return ::Compare(*this, rhs); } -// readable != readable +template +PRBool +operator!=( const basic_nsAReadableString& lhs, const basic_nsAReadableString& rhs ) + { + return lhs.Compare(rhs) != 0; + } // readable != CharT* // CharT* != readable -// readable < readable +template +PRBool +operator<( const basic_nsAReadableString& lhs, const basic_nsAReadableString& rhs ) + { + return lhs.Compare(rhs) < 0; + } // readable < CharT* // CharT* < readable -// readable <= readable +template +PRBool +operator<=( const basic_nsAReadableString& lhs, const basic_nsAReadableString& rhs ) + { + return lhs.Compare(rhs) <= 0; + } // readable <= CharT* // CharT* <= readable -// readable == readable +template +PRBool +operator==( const basic_nsAReadableString& lhs, const basic_nsAReadableString& rhs ) + { + return lhs.Compare(rhs) == 0; + } // readable == CharT* // CharT* == readable -// readable >= readable +template +PRBool +operator>=( const basic_nsAReadableString& lhs, const basic_nsAReadableString& rhs ) + { + return lhs.Compare(rhs) >= 0; + } // readable >= CharT* // CharT* >= readable -// readable > readable +template +PRBool +operator>( const basic_nsAReadableString& lhs, const basic_nsAReadableString& rhs ) + { + return lhs.Compare(rhs) > 0; + } // readable > CharT* // CharT* > readable @@ -419,7 +481,7 @@ template class nsConcatString : public basic_nsAReadableString /* - ...not unlike RickG's original |nsSubsumeString| in intent. + ...not unlike RickG's original |nsSubsumeString| in _intent_. */ { public: @@ -427,9 +489,26 @@ class nsConcatString // ... }; -// readable + readable --> concat -// readable + CharT* --> concat -// CharT* + readable --> concat +template +nsConcatString +operator+( const basic_nsAReadableString&, const basic_nsAReadableString& ) + { + // ... + } + +template +nsConcatString +operator+( const basic_nsAReadableString&, const CharT* ) + { + // ... + } + +template +nsConcatString +operator+( const CharT*, const basic_nsAReadableString& ) + { + // ... + } template basic_ostream& diff --git a/mozilla/xpcom/string/public/nsAWritableString.h b/mozilla/xpcom/string/public/nsAWritableString.h index 2ccc8ec8023..750e5c46c99 100644 --- a/mozilla/xpcom/string/public/nsAWritableString.h +++ b/mozilla/xpcom/string/public/nsAWritableString.h @@ -108,15 +108,14 @@ class basic_nsAWritableString CharT& operator*() { - normalize_forward(); return *mPosition; } Iterator& operator++() { - normalize_forward(); ++mPosition; + normalize_forward(); return *this; } @@ -124,8 +123,8 @@ class basic_nsAWritableString operator++( int ) { Iterator result(*this); - normalize_forward(); ++mPosition; + normalize_forward(); return result; } @@ -133,7 +132,7 @@ class basic_nsAWritableString operator--() { normalize_backward(); - ++mPosition; + --mPosition; return *this; } @@ -142,14 +141,20 @@ class basic_nsAWritableString { Iterator result(*this); normalize_backward(); - ++mPosition; + --mPosition; return result; } - const CharT* - get() const + PRBool + operator==( const ConstIterator& rhs ) { - return mPosition; + return mPosition == rhs.mPosition; + } + + PRBool + operator!=( const ConstIterator& rhs ) + { + return mPosition != rhs.mPosition; } }; @@ -170,7 +175,7 @@ class basic_nsAWritableString End( PRUint32 aOffset = 0 ) { Fragment fragment(this); - CharT* startPos = GetFragment(fragment, kFragmentAt, min(0U, Length()-aOffset)); + CharT* startPos = GetFragment(fragment, kFragmentAt, max(0U, Length()-aOffset)); return Iterator(fragment, startPos); }