From bcb44dd5d813ba2eab353ea7c5e5d2f13a1776e5 Mon Sep 17 00:00:00 2001 From: "scc%mozilla.org" Date: Sun, 11 Jun 2000 01:00:08 +0000 Subject: [PATCH] provide real definitions for |NS_LITERAL_STRING| (one of which exploits |wchar_t|); add a range-check assertion to |CharAt|; add another constructor to |nsPromiseConcatenation| to allow per-class |operator+()| (which some compilers need to resolve ambiguity) to work; fiddled with inlining to reduce bloat ... more experiments needed git-svn-id: svn://10.0.0.236/trunk@71978 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/string/public/nsAReadableString.h | 24 ++++++++++++++++--- mozilla/xpcom/ds/nsAReadableString.h | 24 ++++++++++++++++--- .../xpcom/string/public/nsAReadableString.h | 24 ++++++++++++++++--- 3 files changed, 63 insertions(+), 9 deletions(-) diff --git a/mozilla/string/public/nsAReadableString.h b/mozilla/string/public/nsAReadableString.h index 7eaa0e4b463..2c4013f6d2a 100644 --- a/mozilla/string/public/nsAReadableString.h +++ b/mozilla/string/public/nsAReadableString.h @@ -133,11 +133,15 @@ class nsReadingIterator return *get(); } +//#if 0 + // An iterator really deserves this, but some compilers (notably IBM VisualAge for OS/2) + // don't like this when |CharT| is a type without members. pointer operator->() const { return get(); } +//#endif nsReadingIterator& operator++() @@ -534,11 +538,11 @@ basic_nsAReadableString::Implementation() const */ template -inline CharT basic_nsAReadableString::CharAt( PRUint32 aIndex ) const { - // ??? Is |CharAt()| supposed to be the 'safe' version? + NS_ASSERTION(aIndex fragment; return *GetReadableFragment(fragment, kFragmentAt, aIndex); } @@ -604,6 +608,7 @@ basic_nsAReadableString::Mid( basic_nsAWritableString& aResult, PR } template +inline PRUint32 basic_nsAReadableString::Left( basic_nsAWritableString& aResult, PRUint32 aLengthToCopy ) const { @@ -877,6 +882,13 @@ class nsPromiseConcatenation mStrings[kRightString] = &aRightString; } + nsPromiseConcatenation( const nsPromiseConcatenation& aLeftString, const basic_nsAReadableString& aRightString ) + : mFragmentIdentifierMask(aLeftString.mFragmentIdentifierMask<<1) + { + mStrings[kLeftString] = &aLeftString; + mStrings[kRightString] = &aRightString; + } + virtual PRUint32 Length() const; virtual PRBool Promises( const basic_nsAReadableString& ) const; // virtual PRBool PromisesExactly( const basic_nsAReadableString& ) const; @@ -1239,7 +1251,13 @@ typedef basic_nsAReadableString nsAReadableCString; typedef basic_nsLiteralString nsLiteralString; typedef basic_nsLiteralString nsLiteralCString; -#define NS_LITERAL_STRING(s) nsLiteralString(s, (sizeof(s)/sizeof(wchar_t))-1) + +#ifdef HAVE_CPP_2BYTE_WCHAR_T + #define NS_LITERAL_STRING(s) nsLiteralString(L##s, (sizeof(L##s)/sizeof(wchar_t))-1) +#else + #define NS_LITERAL_STRING(s) NS_ConvertASCIItoUCS2(s, sizeof(s)-1) +#endif + #define NS_LITERAL_CSTRING(s) nsLiteralCString(s, sizeof(s)-1) typedef basic_nsLiteralChar nsLiteralChar; diff --git a/mozilla/xpcom/ds/nsAReadableString.h b/mozilla/xpcom/ds/nsAReadableString.h index 7eaa0e4b463..2c4013f6d2a 100644 --- a/mozilla/xpcom/ds/nsAReadableString.h +++ b/mozilla/xpcom/ds/nsAReadableString.h @@ -133,11 +133,15 @@ class nsReadingIterator return *get(); } +//#if 0 + // An iterator really deserves this, but some compilers (notably IBM VisualAge for OS/2) + // don't like this when |CharT| is a type without members. pointer operator->() const { return get(); } +//#endif nsReadingIterator& operator++() @@ -534,11 +538,11 @@ basic_nsAReadableString::Implementation() const */ template -inline CharT basic_nsAReadableString::CharAt( PRUint32 aIndex ) const { - // ??? Is |CharAt()| supposed to be the 'safe' version? + NS_ASSERTION(aIndex fragment; return *GetReadableFragment(fragment, kFragmentAt, aIndex); } @@ -604,6 +608,7 @@ basic_nsAReadableString::Mid( basic_nsAWritableString& aResult, PR } template +inline PRUint32 basic_nsAReadableString::Left( basic_nsAWritableString& aResult, PRUint32 aLengthToCopy ) const { @@ -877,6 +882,13 @@ class nsPromiseConcatenation mStrings[kRightString] = &aRightString; } + nsPromiseConcatenation( const nsPromiseConcatenation& aLeftString, const basic_nsAReadableString& aRightString ) + : mFragmentIdentifierMask(aLeftString.mFragmentIdentifierMask<<1) + { + mStrings[kLeftString] = &aLeftString; + mStrings[kRightString] = &aRightString; + } + virtual PRUint32 Length() const; virtual PRBool Promises( const basic_nsAReadableString& ) const; // virtual PRBool PromisesExactly( const basic_nsAReadableString& ) const; @@ -1239,7 +1251,13 @@ typedef basic_nsAReadableString nsAReadableCString; typedef basic_nsLiteralString nsLiteralString; typedef basic_nsLiteralString nsLiteralCString; -#define NS_LITERAL_STRING(s) nsLiteralString(s, (sizeof(s)/sizeof(wchar_t))-1) + +#ifdef HAVE_CPP_2BYTE_WCHAR_T + #define NS_LITERAL_STRING(s) nsLiteralString(L##s, (sizeof(L##s)/sizeof(wchar_t))-1) +#else + #define NS_LITERAL_STRING(s) NS_ConvertASCIItoUCS2(s, sizeof(s)-1) +#endif + #define NS_LITERAL_CSTRING(s) nsLiteralCString(s, sizeof(s)-1) typedef basic_nsLiteralChar nsLiteralChar; diff --git a/mozilla/xpcom/string/public/nsAReadableString.h b/mozilla/xpcom/string/public/nsAReadableString.h index 7eaa0e4b463..2c4013f6d2a 100644 --- a/mozilla/xpcom/string/public/nsAReadableString.h +++ b/mozilla/xpcom/string/public/nsAReadableString.h @@ -133,11 +133,15 @@ class nsReadingIterator return *get(); } +//#if 0 + // An iterator really deserves this, but some compilers (notably IBM VisualAge for OS/2) + // don't like this when |CharT| is a type without members. pointer operator->() const { return get(); } +//#endif nsReadingIterator& operator++() @@ -534,11 +538,11 @@ basic_nsAReadableString::Implementation() const */ template -inline CharT basic_nsAReadableString::CharAt( PRUint32 aIndex ) const { - // ??? Is |CharAt()| supposed to be the 'safe' version? + NS_ASSERTION(aIndex fragment; return *GetReadableFragment(fragment, kFragmentAt, aIndex); } @@ -604,6 +608,7 @@ basic_nsAReadableString::Mid( basic_nsAWritableString& aResult, PR } template +inline PRUint32 basic_nsAReadableString::Left( basic_nsAWritableString& aResult, PRUint32 aLengthToCopy ) const { @@ -877,6 +882,13 @@ class nsPromiseConcatenation mStrings[kRightString] = &aRightString; } + nsPromiseConcatenation( const nsPromiseConcatenation& aLeftString, const basic_nsAReadableString& aRightString ) + : mFragmentIdentifierMask(aLeftString.mFragmentIdentifierMask<<1) + { + mStrings[kLeftString] = &aLeftString; + mStrings[kRightString] = &aRightString; + } + virtual PRUint32 Length() const; virtual PRBool Promises( const basic_nsAReadableString& ) const; // virtual PRBool PromisesExactly( const basic_nsAReadableString& ) const; @@ -1239,7 +1251,13 @@ typedef basic_nsAReadableString nsAReadableCString; typedef basic_nsLiteralString nsLiteralString; typedef basic_nsLiteralString nsLiteralCString; -#define NS_LITERAL_STRING(s) nsLiteralString(s, (sizeof(s)/sizeof(wchar_t))-1) + +#ifdef HAVE_CPP_2BYTE_WCHAR_T + #define NS_LITERAL_STRING(s) nsLiteralString(L##s, (sizeof(L##s)/sizeof(wchar_t))-1) +#else + #define NS_LITERAL_STRING(s) NS_ConvertASCIItoUCS2(s, sizeof(s)-1) +#endif + #define NS_LITERAL_CSTRING(s) nsLiteralCString(s, sizeof(s)-1) typedef basic_nsLiteralChar nsLiteralChar;