From 4a9749eec3fde34927658d35287e490800bfcce0 Mon Sep 17 00:00:00 2001 From: "rickg%netscape.com" Date: Tue, 5 Oct 1999 04:47:19 +0000 Subject: [PATCH] bugs 13038 and 14920; also improved comments. r=kmcclusk git-svn-id: svn://10.0.0.236/trunk@49803 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/string/obsolete/nsStr.cpp | 129 +- mozilla/string/obsolete/nsStr.h | 93 +- mozilla/string/obsolete/nsString.cpp | 210 +-- mozilla/string/obsolete/nsString.h | 1139 ++++++++-------- mozilla/string/obsolete/nsString2.cpp | 180 ++- mozilla/string/obsolete/nsString2.h | 1288 +++++++++---------- mozilla/xpcom/ds/bufferRoutines.h | 4 - mozilla/xpcom/ds/nsStr.cpp | 129 +- mozilla/xpcom/ds/nsStr.h | 93 +- mozilla/xpcom/ds/nsString.cpp | 210 +-- mozilla/xpcom/ds/nsString.h | 1139 ++++++++-------- mozilla/xpcom/ds/nsString2.cpp | 180 ++- mozilla/xpcom/ds/nsString2.h | 1288 +++++++++---------- mozilla/xpcom/string/obsolete/nsStr.cpp | 129 +- mozilla/xpcom/string/obsolete/nsStr.h | 93 +- mozilla/xpcom/string/obsolete/nsString.cpp | 210 +-- mozilla/xpcom/string/obsolete/nsString.h | 1139 ++++++++-------- mozilla/xpcom/string/obsolete/nsString2.cpp | 180 ++- mozilla/xpcom/string/obsolete/nsString2.h | 1288 +++++++++---------- 19 files changed, 4521 insertions(+), 4600 deletions(-) diff --git a/mozilla/string/obsolete/nsStr.cpp b/mozilla/string/obsolete/nsStr.cpp index c34f2cdd7b7..5f53dbcc357 100644 --- a/mozilla/string/obsolete/nsStr.cpp +++ b/mozilla/string/obsolete/nsStr.cpp @@ -69,16 +69,6 @@ void nsStr::Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 a aDest.mOwnsBuffer=aOwnsBuffer; } -/** - * - * @update gess10/30/98 - * @param - * @return - */ -nsIMemoryAgent* GetDefaultAgent(void){ - static nsMemoryAgent gDefaultAgent; - return (nsIMemoryAgent*)&gDefaultAgent; -} /** * This member destroys the memory buffer owned by an nsStr object (if it actually owns it) @@ -86,17 +76,9 @@ nsIMemoryAgent* GetDefaultAgent(void){ * @param * @return */ -void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) { +void nsStr::Destroy(nsStr& aDest) { if((aDest.mStr) && (aDest.mStr!=(char*)gCommonEmptyBuffer)) { - if(!anAgent) - anAgent=GetDefaultAgent(); - - if(anAgent) { - anAgent->Free(aDest); - } - else{ - printf("%s\n","Leak occured in nsStr."); - } + Free(aDest); } } @@ -108,11 +90,10 @@ void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) { * @param aNewLength -- new capacity of string in charSize units * @return void */ -PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent) { +PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength) { PRBool result=PR_TRUE; if(aNewLength>aString.mCapacity) { - nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent(); - result=theAgent->Realloc(aString,aNewLength); + result=Realloc(aString,aNewLength); if(aString.mStr) AddNullTerminator(aString); } @@ -126,20 +107,18 @@ PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* * @param aNewLength -- new capacity of string in charSize units * @return void */ -PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAgent) { +PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength) { PRBool result=PR_TRUE; if(aNewLength>aDest.mCapacity) { nsStr theTempStr; nsStr::Initialize(theTempStr,aDest.mCharSize); - nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent(); - - result=EnsureCapacity(theTempStr,aNewLength,theAgent); + result=EnsureCapacity(theTempStr,aNewLength); if(result) { if(aDest.mLength) { - Append(theTempStr,aDest,0,aDest.mLength,theAgent); + Append(theTempStr,aDest,0,aDest.mLength); } - theAgent->Free(aDest); + Free(aDest); aDest.mStr = theTempStr.mStr; theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole... aDest.mLength=theTempStr.mLength; @@ -157,10 +136,10 @@ PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAg * @param aSource is where chars are copied from * @param aCount is the number of chars copied from aSource */ -void nsStr::Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){ +void nsStr::Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount){ if(&aDest!=&aSource){ - Truncate(aDest,0,anAgent); - Append(aDest,aSource,anOffset,aCount,anAgent); + Truncate(aDest,0); + Append(aDest,aSource,anOffset,aCount); } } @@ -172,7 +151,7 @@ void nsStr::Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 a * @param aSource is where char are copied from * @aCount is the number of bytes to be copied */ -void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){ +void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount){ if(anOffset aDest.mCapacity) { - isBigEnough=GrowCapacity(aDest,aDest.mLength+theLength,anAgent); + isBigEnough=GrowCapacity(aDest,aDest.mLength+theLength); } if(isBigEnough) { @@ -204,7 +183,7 @@ void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 a * @param aSrcOffset is where in aSource chars are copied from * @param aCount is the number of chars from aSource to be inserted into aDest */ -void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){ +void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount){ //there are a few cases for insert: // 1. You're inserting chars into an empty string (assign) // 2. You're inserting onto the end of a string (append) @@ -223,22 +202,21 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin nsStr theTempStr; nsStr::Initialize(theTempStr,aDest.mCharSize); - nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent(); - PRBool isBigEnough=EnsureCapacity(theTempStr,aDest.mLength+theLength,theAgent); //grow the temp buffer to the right size + PRBool isBigEnough=EnsureCapacity(theTempStr,aDest.mLength+theLength); //grow the temp buffer to the right size if(isBigEnough) { if(aDestOffset) { - Append(theTempStr,aDest,0,aDestOffset,theAgent); //first copy leftmost data... + Append(theTempStr,aDest,0,aDestOffset); //first copy leftmost data... } - Append(theTempStr,aSource,0,aSource.mLength,theAgent); //next copy inserted (new) data + Append(theTempStr,aSource,0,aSource.mLength); //next copy inserted (new) data PRUint32 theRemains=aDest.mLength-aDestOffset; if(theRemains) { - Append(theTempStr,aDest,aDestOffset,theRemains,theAgent); //next copy rightmost data + Append(theTempStr,aDest,aDestOffset,theRemains); //next copy rightmost data } - theAgent->Free(aDest); + Free(aDest); aDest.mStr = theTempStr.mStr; theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole... aDest.mCapacity=theTempStr.mCapacity; @@ -262,9 +240,9 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin }//if //else nothing to do! } - else Append(aDest,aSource,0,aCount,anAgent); + else Append(aDest,aSource,0,aCount); } - else Append(aDest,aSource,0,aCount,anAgent); + else Append(aDest,aSource,0,aCount); } } @@ -276,7 +254,7 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin * @param aDestOffset is where in aDest deletion is to occur * @param aCount is the number of chars to be deleted in aDest */ -void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAgent* anAgent){ +void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount){ if(aDestOffset //---------------------------------------------------------------------------------------- @@ -177,8 +178,6 @@ const PRInt32 kDefaultStringSize = 64; const PRInt32 kNotFound = -1; -class nsIMemoryAgent; - //---------------------------------------------------------------------------------------- class NS_COM CBufDescriptor { @@ -228,7 +227,7 @@ struct NS_COM nsStr { * @param aString is the nsStr to be manipulated * @param anAgent is the allocator to be used to the nsStr */ - static void Destroy(nsStr& aDest,nsIMemoryAgent* anAgent=0); + static void Destroy(nsStr& aDest); /** * These methods are where memory allocation/reallocation occur. @@ -238,8 +237,8 @@ struct NS_COM nsStr { * @param anAgent is the allocator to be used on the nsStr * @return */ - static PRBool EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0); - static PRBool GrowCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0); + static PRBool EnsureCapacity(nsStr& aString,PRUint32 aNewLength); + static PRBool GrowCapacity(nsStr& aString,PRUint32 aNewLength); /** * These methods are used to append content to the given nsStr @@ -251,7 +250,7 @@ struct NS_COM nsStr { * @param aCount tells us the (max) # of chars to copy * @param anAgent is the allocator to be used for alloc/free operations */ - static void Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0); + static void Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount); /** * These methods are used to assign contents of a source string to dest string @@ -263,7 +262,7 @@ struct NS_COM nsStr { * @param aCount tells us the (max) # of chars to copy * @param anAgent is the allocator to be used for alloc/free operations */ - static void Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0); + static void Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount); /** * These methods are used to insert content from source string to the dest nsStr @@ -276,7 +275,7 @@ struct NS_COM nsStr { * @param aCount tells us the (max) # of chars to insert * @param anAgent is the allocator to be used for alloc/free operations */ - static void Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0); + static void Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount); /** * This method deletes chars from the given str. @@ -288,7 +287,7 @@ struct NS_COM nsStr { * @param aCount tells us the (max) # of chars to delete * @param anAgent is the allocator to be used for alloc/free operations */ - static void Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAgent* anAgent=0); + static void Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount); /** * This method is used to truncate the given string. @@ -301,7 +300,7 @@ struct NS_COM nsStr { * @param aSrcOffset tells us where in source to start copying * @param anAgent is the allocator to be used for alloc/free operations */ - static void Truncate(nsStr& aDest,PRUint32 aDestOffset,nsIMemoryAgent* anAgent=0); + static void Truncate(nsStr& aDest,PRUint32 aDestOffset); /** * This method is used to perform a case conversion on the given string @@ -388,6 +387,12 @@ struct NS_COM nsStr { char* mStr; PRUnichar* mUStr; }; + +private: + static PRBool Alloc(nsStr& aString,PRUint32 aCount); + static PRBool Realloc(nsStr& aString,PRUint32 aCount); + static PRBool Free(nsStr& aString); + }; /************************************************************** @@ -430,74 +435,6 @@ inline PRUnichar GetCharAt(const nsStr& aDest,PRUint32 anIndex){ return 0; } -//---------------------------------------------------------------------------------------- - -class nsIMemoryAgent { -public: - virtual PRBool Alloc(nsStr& aString,PRUint32 aCount)=0; - virtual PRBool Realloc(nsStr& aString,PRUint32 aCount)=0; - virtual PRBool Free(nsStr& aString)=0; -}; - -class nsMemoryAgent : public nsIMemoryAgent { -public: - - virtual PRBool Alloc(nsStr& aDest,PRUint32 aCount) { - - static int mAllocCount=0; - mAllocCount++; - - //we're given the acount value in charunits; now scale up to next multiple. - PRUint32 theNewCapacity=kDefaultStringSize; - while(theNewCapacitymCapacity) { - GrowCapacity(*this,aLength,mAgent); + GrowCapacity(*this,aLength); } AddNullTerminator(*this); } @@ -262,7 +262,7 @@ PRBool nsCString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){ */ nsSubsumeCStr nsCString::operator+(const nsCString& aString){ nsCString temp(*this); //make a temp string the same size as this... - nsStr::Append(temp,aString,0,aString.mLength,mAgent); + nsStr::Append(temp,aString,0,aString.mLength); return nsSubsumeCStr(temp); } @@ -613,11 +613,19 @@ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) { } theDigit=(theChar-'A')+10; } + else if((theChar>='a') && (theChar<='f')) { + if(10==aRadix){ + *anErrorCode=NS_ERROR_ILLEGAL_VALUE; + result=0; + break; + } + theDigit=(theChar-'a')+10; + } else if('-'==theChar) { result=-result; break; } - else if(('+'==theChar) || (' '==theChar)) { //stop in a good state if you see this... + else if(('+'==theChar) || (' '==theChar) || ('X'==theChar) || ('x'==theChar)) { //stop in a good state if you see this... break; } else { @@ -634,6 +642,7 @@ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) { return result; } + /** * Call this method to extract the rightmost numeric value from the given * 1-byte input string, and simultaneously determine the radix. @@ -645,56 +654,56 @@ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) { * @param aRadix (an out parm) tells the caller what base we think the string is in. * @return non-zero error code if this string is non-numeric */ -PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) { +static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) { + static const char* validChars="0123456789abcdefABCDEF-+#"; - aString.ToUpperCase(); + const char* cp=aString.GetBuffer(); + PRInt32 result=NS_ERROR_ILLEGAL_VALUE; + if(cp) { - PRInt32 decPt=nsStr::FindChar(aString,'.',PR_TRUE,0); - char* cp = (kNotFound==decPt) ? aString.mStr + aString.mLength-1 : aString.mStr+decPt-1; - - aRadix=kRadixUnknown; //assume for starters... + //begin by skipping over leading chars that shouldn't be part of the number... + + char* to=(char*)cp; + const char* endcp=cp+aString.mLength; + int len=strlen(validChars); - // Skip trailing non-numeric... - while (cp >= aString.mStr) { - if((*cp>='0') && (*cp<='9')){ - if(kRadixUnknown==aRadix) - aRadix=kRadix10; - break; + while(cp='A') && (*cp<='F')) { - aRadix=16; - break; - } - cp--; + + while(cp='0') && (theChar<='9')) { + *to++=theChar; + } + else if((theChar>='A') && (theChar<='F')) { + aRadix=16; + *to++=theChar; + } + else if('X'==theChar){ + if('-'==aString.mStr[0]) + to=&aString.mStr[1]; + else to=aString.mStr; + aRadix=16; + //root=cp; + } + else if('-'==theChar) { + *to++=theChar; + } + else if(('#'==theChar) || ('+'==theChar)){ + //just skip this char... + } + else break; + cp++; + } + aString.Truncate(to-aString.mStr); + result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; } - aString.Truncate(cp-aString.mStr+1); - - //ok, now scan through chars until you find the start of this number... - //we delimit the number by the presence of: +,-,#,X - - // Skip trailing non-numeric... - cp++; - while (--cp >= aString.mStr) { - if((*cp>='0') && (*cp<='9')){ - continue; - } - else if((*cp>='A') && (*cp<='F')) { - continue; - } - else if((*cp=='-') || (*cp=='+')){ - break; - } - else { - if(('#'==(*cp)) || ('X'==(*cp))) - aRadix=kRadix16; - cp++; //move back by one - break; - } - } - if(cp>aString.mStr) - aString.Cut(0,cp-aString.mStr); - PRInt32 result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; - return result; } @@ -726,11 +735,12 @@ PRUint32 nsCString::DetermineRadix(void) { PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const { //copy chars to local buffer -- step down from 2 bytes to 1 if necessary... + PRInt32 result=0; nsCAutoString theString(*this); PRUint32 theRadix=aRadix; - PRInt32 result=0; - + *anErrorCode=GetNumericSubstring(theString,theRadix); //we actually don't use this radix; use given radix instead + if(NS_OK==*anErrorCode){ if(kAutoDetect==aRadix) aRadix=theRadix; @@ -755,13 +765,13 @@ PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const { */ nsCString& nsCString::Assign(const nsStr& aString,PRInt32 aCount) { if(this!=&aString){ - nsStr::Truncate(*this,0,0); + nsStr::Truncate(*this,0); if(aCount<0) aCount=aString.mLength; else aCount=MinInt(aCount,aString.mLength); - nsStr::Assign(*this,aString,0,aCount,mAgent); + nsStr::Assign(*this,aString,0,aCount); } return *this; } @@ -773,7 +783,7 @@ nsCString& nsCString::Assign(const nsStr& aString,PRInt32 aCount) { * @return this */ nsCString& nsCString::Assign(const char* aCString,PRInt32 aCount) { - nsStr::Truncate(*this,0,0); + nsStr::Truncate(*this,0); if(aCString){ Append(aCString,aCount); } @@ -787,7 +797,7 @@ nsCString& nsCString::Assign(const char* aCString,PRInt32 aCount) { * @return this */ nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) { - nsStr::Truncate(*this,0,0); + nsStr::Truncate(*this,0); if(aString){ nsStr temp; @@ -806,7 +816,7 @@ nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) { else aCount=temp.mLength=nsCRT::strlen(aString); if(0=1) { - PRInt32 div=theInt/mask1; - if((div) || (!isfirst)) { - buf[charpos++]="0123456789abcdef"[div]; + PRInt32 theDiv=theInt/mask1; + if((theDiv) || (!isfirst)) { + buf[charpos++]="0123456789abcdef"[theDiv]; isfirst=PR_FALSE; } - theInt-=div*mask1; + theInt-=theDiv*mask1; mask1/=aRadix; } return Append(buf); @@ -1001,7 +1028,7 @@ PRUint32 nsCString::Left(nsCString& aDest,PRInt32 aCount) const{ if(aCount<0) aCount=mLength; else aCount=MinInt(aCount,mLength); - nsStr::Assign(aDest,*this,0,aCount,mAgent); + nsStr::Assign(aDest,*this,0,aCount); return aDest.mLength; } @@ -1018,7 +1045,7 @@ PRUint32 nsCString::Mid(nsCString& aDest,PRUint32 anOffset,PRInt32 aCount) const if(aCount<0) aCount=mLength; else aCount=MinInt(aCount,mLength); - nsStr::Assign(aDest,*this,anOffset,aCount,mAgent); + nsStr::Assign(aDest,*this,anOffset,aCount); return aDest.mLength; } @@ -1048,7 +1075,7 @@ PRUint32 nsCString::Right(nsCString& aDest,PRInt32 aCount) const{ */ nsCString& nsCString::Insert(const nsCString& aString,PRUint32 anOffset,PRInt32 aCount) { - nsStr::Insert(*this,anOffset,aString,0,aCount,mAgent); + nsStr::Insert(*this,anOffset,aString,0,aCount); return *this; } @@ -1079,7 +1106,7 @@ nsCString& nsCString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCou else aCount=temp.mLength=nsCRT::strlen(aCString); if(temp.mLength && (0mAgent=&theAgent; delete aString; } return 0; @@ -1722,7 +1747,6 @@ NS_COM int fputs(const nsCString& aString, FILE* out) */ nsCAutoString::nsCAutoString() : nsCString(){ nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); - mAgent=0; AddNullTerminator(*this); } @@ -1732,7 +1756,6 @@ nsCAutoString::nsCAutoString() : nsCString(){ */ nsCAutoString::nsCAutoString(const nsCAutoString& aString) : nsCString() { nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); - mAgent=0; AddNullTerminator(*this); Append(aString); } @@ -1744,7 +1767,6 @@ nsCAutoString::nsCAutoString(const nsCAutoString& aString) : nsCString() { */ nsCAutoString::nsCAutoString(const char* aCString,PRInt32 aLength) : nsCString() { nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); - mAgent=0; AddNullTerminator(*this); Append(aCString,aLength); } @@ -1754,7 +1776,6 @@ nsCAutoString::nsCAutoString(const char* aCString,PRInt32 aLength) : nsCString() * @param aBuffer -- descibes external buffer */ nsCAutoString::nsCAutoString(const CBufDescriptor& aBuffer) : nsCString() { - mAgent=0; if(!aBuffer.mBuffer) { nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); } @@ -1770,7 +1791,6 @@ nsCAutoString::nsCAutoString(const CBufDescriptor& aBuffer) : nsCString() { * @param aString is a ptr to a unistr */ nsCAutoString::nsCAutoString(const PRUnichar* aString,PRInt32 aLength) : nsCString() { - mAgent=0; nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); AddNullTerminator(*this); Append(aString,aLength); @@ -1781,7 +1801,6 @@ nsCAutoString::nsCAutoString(const PRUnichar* aString,PRInt32 aLength) : nsCStri * @param */ nsCAutoString::nsCAutoString(const nsStr& aString) : nsCString() { - mAgent=0; nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); AddNullTerminator(*this); Append(aString); @@ -1794,7 +1813,6 @@ nsCAutoString::nsCAutoString(const nsStr& aString) : nsCString() { * @param */ nsCAutoString::nsCAutoString(PRUnichar aChar) : nsCString(){ - mAgent=0; nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); AddNullTerminator(*this); Append(aChar); @@ -1807,12 +1825,10 @@ nsCAutoString::nsCAutoString(PRUnichar aChar) : nsCString(){ */ #ifdef AIX nsCAutoString::nsCAutoString(const nsSubsumeCStr& aSubsumeStr) :nsCString() { - mAgent=0; nsSubsumeCStr temp(aSubsumeStr); // a temp is needed for the AIX compiler CSubsume(*this,temp); #else nsCAutoString::nsCAutoString( nsSubsumeCStr& aSubsumeStr) :nsCString() { - mAgent=0; CSubsume(*this,aSubsumeStr); #endif // AIX } diff --git a/mozilla/string/obsolete/nsString.h b/mozilla/string/obsolete/nsString.h index 05205d9a818..90db90305b4 100644 --- a/mozilla/string/obsolete/nsString.h +++ b/mozilla/string/obsolete/nsString.h @@ -46,632 +46,633 @@ class NS_COM nsSubsumeCStr; class NS_COM nsCString : public nsStr { - public: +public: -/** - * Default constructor. - */ -nsCString(nsIMemoryAgent* anAgent=0); - - -/** - * This constructor accepts an isolatin string - * @param aCString is a ptr to a 1-byte cstr - */ -nsCString(const char* aCString,PRInt32 aLength=-1,nsIMemoryAgent* anAgent=0); - -/** - * This constructor accepts a unichar string - * @param aCString is a ptr to a 2-byte cstr - */ -nsCString(const PRUnichar* aString,PRInt32 aLength=-1,nsIMemoryAgent* anAgent=0); - -/** - * This is a copy constructor that accepts an nsStr - * @param reference to another nsCString - */ -nsCString(const nsStr&,nsIMemoryAgent* anAgent=0); - -/** - * This is our copy constructor - * @param reference to another nsCString - */ -nsCString(const nsCString& aString); - -/** - * This constructor takes a subsumestr - * @param reference to subsumestr - */ -nsCString(nsSubsumeCStr& aSubsumeStr); - -/** - * Destructor - * - */ -virtual ~nsCString(); - -/** - * Retrieve the length of this string - * @return string length - */ -inline PRInt32 Length() const { return (PRInt32)mLength; } - -/** - * Retrieve the size of this string - * @return string length - */ -virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const; - - -/** - * Call this method if you want to force a different string capacity - * @update gess7/30/98 - * @param aLength -- contains new length for mStr - * @return - */ -void SetLength(PRUint32 aLength) { - Truncate(aLength); -} - -/** - * Sets the new length of the string. - * @param aLength is new string length. - * @return nada - */ -void SetCapacity(PRUint32 aLength); -/** - * This method truncates this string to given length. - * - * @param anIndex -- new length of string - * @return nada - */ -void Truncate(PRInt32 anIndex=0); - - -/** - * Determine whether or not the characters in this - * string are in sorted order. - * - * @return TRUE if ordered. - */ -PRBool IsOrdered(void) const; - - -/** - * Determine whether or not this string has a length of 0 - * - * @return TRUE if empty. - */ -PRBool IsEmpty(void) const { - return PRBool(0==mLength); -} - -/********************************************************************** - Accessor methods... - *********************************************************************/ - -const char* GetBuffer(void) const; - - - /** - * Get nth character. + /** + * Default constructor. */ -PRUnichar operator[](PRUint32 anIndex) const; -PRUnichar CharAt(PRUint32 anIndex) const; -PRUnichar First(void) const; -PRUnichar Last(void) const; + nsCString(); -PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex); + /** + * This constructor accepts an isolatin string + * @param aCString is a ptr to a 1-byte cstr + */ + nsCString(const char* aCString,PRInt32 aLength=-1); + + /** + * This constructor accepts a unichar string + * @param aCString is a ptr to a 2-byte cstr + */ + nsCString(const PRUnichar* aString,PRInt32 aLength=-1); + + /** + * This is a copy constructor that accepts an nsStr + * @param reference to another nsCString + */ + nsCString(const nsStr&); + + /** + * This is our copy constructor + * @param reference to another nsCString + */ + nsCString(const nsCString& aString); + + /** + * This constructor takes a subsumestr + * @param reference to subsumestr + */ + nsCString(nsSubsumeCStr& aSubsumeStr); + + /** + * Destructor + * + */ + virtual ~nsCString(); + + /** + * Retrieve the length of this string + * @return string length + */ + inline PRInt32 Length() const { return (PRInt32)mLength; } + + /** + * Retrieve the size of this string + * @return string length + */ + virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const; -/********************************************************************** - String creation methods... - *********************************************************************/ + /** + * Call this method if you want to force a different string capacity + * @update gess7/30/98 + * @param aLength -- contains new length for mStr + * @return + */ + void SetLength(PRUint32 aLength) { + Truncate(aLength); + } -/** - * Create a new string by appending given string to this - * @param aString -- 2nd string to be appended - * @return new string - */ -nsSubsumeCStr operator+(const nsCString& aString); - -/** - * create a new string by adding this to the given char*. - * @param aCString is a ptr to cstring to be added to this - * @return newly created string - */ -nsSubsumeCStr operator+(const char* aCString); + /** + * Sets the new length of the string. + * @param aLength is new string length. + * @return nada + */ + void SetCapacity(PRUint32 aLength); + /** + * This method truncates this string to given length. + * + * @param anIndex -- new length of string + * @return nada + */ + void Truncate(PRInt32 anIndex=0); -/** - * create a new string by adding this to the given char. - * @param aChar is a char to be added to this - * @return newly created string - */ -nsSubsumeCStr operator+(PRUnichar aChar); -nsSubsumeCStr operator+(char aChar); + /** + * Determine whether or not the characters in this + * string are in sorted order. + * + * @return TRUE if ordered. + */ + PRBool IsOrdered(void) const; -/********************************************************************** - Lexomorphic transforms... - *********************************************************************/ + /** + * Determine whether or not this string has a length of 0 + * + * @return TRUE if empty. + */ + PRBool IsEmpty(void) const { + return PRBool(0==mLength); + } -/** - * Converts chars in this to lowercase - * @update gess 7/27/98 - */ -void ToLowerCase(); + /********************************************************************** + Accessor methods... + *********************************************************************/ -/** - * Converts chars in this to lowercase, and - * stores them in aOut - * @update gess 7/27/98 - * @param aOut is a string to contain result - */ -void ToLowerCase(nsCString& aString) const; - -/** - * Converts chars in this to uppercase - * @update gess 7/27/98 - */ -void ToUpperCase(); - -/** - * Converts chars in this to lowercase, and - * stores them in a given output string - * @update gess 7/27/98 - * @param aOut is a string to contain result - */ -void ToUpperCase(nsCString& aString) const; + /** + * Retrieve const ptr to internal buffer; DO NOT TRY TO FREE IT! + */ + const char* GetBuffer(void) const; -/** - * This method is used to remove all occurances of the - * characters found in aSet from this string. - * - * @param aSet -- characters to be cut from this - * @return *this - */ -nsCString& StripChars(const char* aSet); -nsCString& StripChar(char aChar); + /** + * Get nth character. + */ + PRUnichar operator[](PRUint32 anIndex) const; + PRUnichar CharAt(PRUint32 anIndex) const; + PRUnichar First(void) const; + PRUnichar Last(void) const; -/** - * This method strips whitespace throughout the string - * - * @return this - */ -nsCString& StripWhitespace(); - -/** - * swaps occurence of 1 string for another - * - * @return this - */ -nsCString& ReplaceChar(PRUnichar aOldChar,PRUnichar aNewChar); -nsCString& ReplaceChar(const char* aSet,PRUnichar aNewChar); - -PRInt32 CountChar(PRUnichar aChar); - -/** - * This method trims characters found in aTrimSet from - * either end of the underlying string. - * - * @param aTrimSet -- contains chars to be trimmed from - * both ends - * @return this - */ -nsCString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); - -/** - * This method strips whitespace from string. - * You can control whether whitespace is yanked from - * start and end of string as well. - * - * @param aEliminateLeading controls stripping of leading ws - * @param aEliminateTrailing controls stripping of trailing ws - * @return this - */ -nsCString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); - -/** - * This method strips whitespace from string. - * You can control whether whitespace is yanked from - * start and end of string as well. - * - * @param aEliminateLeading controls stripping of leading ws - * @param aEliminateTrailing controls stripping of trailing ws - * @return this - */ -nsCString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); - -/********************************************************************** - string conversion methods... - *********************************************************************/ - - operator char*() {return mStr;} - operator const char*() const {return (const char*)mStr;} - -/** - * This method constructs a new nsCString that is a clone - * of this string. - * - */ -nsCString* ToNewString() const; - -/** - * Creates an ISOLatin1 clone of this string - * Note that calls to this method should be matched with calls to Recycle(). - * @return ptr to new isolatin1 string - */ -char* ToNewCString() const; - -/** - * Creates a unicode clone of this string - * Note that calls to this method should be matched with calls to Recycle(). - * @return ptr to new unicode string - */ -PRUnichar* ToNewUnicode() const; - -/** - * Copies data from internal buffer onto given char* buffer - * NOTE: This only copies as many chars as will fit in given buffer (clips) - * @param aBuf is the buffer where data is stored - * @param aBuflength is the max # of chars to move to buffer - * @return ptr to given buffer - */ -char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const; - -/** - * Perform string to float conversion. - * @param aErrorCode will contain error if one occurs - * @return float rep of string value - */ -float ToFloat(PRInt32* aErrorCode) const; - -/** - * Try to derive the radix from the value contained in this string - * @return kRadix10, kRadix16 or kAutoDetect (meaning unknown) - */ -PRUint32 DetermineRadix(void); - -/** - * Perform string to int conversion. - * @param aErrorCode will contain error if one occurs - * @return int rep of string value - */ -PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const; + PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex); -/********************************************************************** - String manipulation methods... - *********************************************************************/ + /********************************************************************** + String creation methods... + *********************************************************************/ -/** - * Functionally equivalent to assign or operator= - * - */ -nsCString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} -nsCString& SetString(const nsStr& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} + /** + * Create a new string by appending given string to this + * @param aString -- 2nd string to be appended + * @return new string + */ + nsSubsumeCStr operator+(const nsCString& aString); -/** - * assign given string to this string - * @param aStr: buffer to be assigned to this - * @param alength is the length of the given str (or -1) - if you want me to determine its length - * @return this - */ -nsCString& Assign(const nsStr& aString,PRInt32 aCount=-1); -nsCString& Assign(const char* aString,PRInt32 aCount=-1); -nsCString& Assign(const PRUnichar* aString,PRInt32 aCount=-1); -nsCString& Assign(PRUnichar aChar); -nsCString& Assign(char aChar); + /** + * create a new string by adding this to the given char*. + * @param aCString is a ptr to cstring to be added to this + * @return newly created string + */ + nsSubsumeCStr operator+(const char* aCString); -/** - * here come a bunch of assignment operators... - * @param aString: string to be added to this - * @return this - */ -nsCString& operator=(const nsCString& aString) {return Assign(aString);} -nsCString& operator=(const nsStr& aString) {return Assign(aString);} -nsCString& operator=(PRUnichar aChar) {return Assign(aChar);} -nsCString& operator=(char aChar) {return Assign(aChar);} -nsCString& operator=(const char* aCString) {return Assign(aCString);} -nsCString& operator=(const PRUnichar* aString) {return Assign(aString);} -#ifdef AIX -nsCString& operator=(const nsSubsumeCStr& aSubsumeString); // AIX requires a const here -#else -nsCString& operator=(nsSubsumeCStr& aSubsumeString); -#endif -/** - * Here's a bunch of methods that append varying types... - * @param various... - * @return this - */ -nsCString& operator+=(const nsCString& aString){return Append(aString,aString.mLength);} -nsCString& operator+=(const char* aCString) {return Append(aCString);} -nsCString& operator+=(PRUnichar aChar){return Append(aChar);} -nsCString& operator+=(char aChar){return Append(aChar);} + /** + * create a new string by adding this to the given char. + * @param aChar is a char to be added to this + * @return newly created string + */ + nsSubsumeCStr operator+(PRUnichar aChar); + nsSubsumeCStr operator+(char aChar); -/* - * Appends n characters from given string to this, - * This version computes the length of your given string - * - * @param aString is the source to be appended to this - * @return number of chars copied - */ -nsCString& Append(const nsCString& aString) {return Append(aString,aString.mLength);} + + /********************************************************************** + Lexomorphic transforms... + *********************************************************************/ + + /** + * Converts chars in this to lowercase + * @update gess 7/27/98 + */ + void ToLowerCase(); + + + /** + * Converts chars in this to lowercase, and + * stores them in aOut + * @update gess 7/27/98 + * @param aOut is a string to contain result + */ + void ToLowerCase(nsCString& aString) const; + + /** + * Converts chars in this to uppercase + * @update gess 7/27/98 + */ + void ToUpperCase(); + + /** + * Converts chars in this to lowercase, and + * stores them in a given output string + * @update gess 7/27/98 + * @param aOut is a string to contain result + */ + void ToUpperCase(nsCString& aString) const; + + + /** + * This method is used to remove all occurances of the + * characters found in aSet from this string. + * + * @param aSet -- characters to be cut from this + * @return *this + */ + nsCString& StripChars(const char* aSet); + nsCString& StripChar(char aChar); + + /** + * This method strips whitespace throughout the string + * + * @return this + */ + nsCString& StripWhitespace(); + + /** + * swaps occurence of 1 string for another + * + * @return this + */ + nsCString& ReplaceChar(PRUnichar aOldChar,PRUnichar aNewChar); + nsCString& ReplaceChar(const char* aSet,PRUnichar aNewChar); + + PRInt32 CountChar(PRUnichar aChar); + + /** + * This method trims characters found in aTrimSet from + * either end of the underlying string. + * + * @param aTrimSet -- contains chars to be trimmed from + * both ends + * @return this + */ + nsCString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + + /** + * This method strips whitespace from string. + * You can control whether whitespace is yanked from + * start and end of string as well. + * + * @param aEliminateLeading controls stripping of leading ws + * @param aEliminateTrailing controls stripping of trailing ws + * @return this + */ + nsCString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + + /** + * This method strips whitespace from string. + * You can control whether whitespace is yanked from + * start and end of string as well. + * + * @param aEliminateLeading controls stripping of leading ws + * @param aEliminateTrailing controls stripping of trailing ws + * @return this + */ + nsCString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + + /********************************************************************** + string conversion methods... + *********************************************************************/ + + operator char*() {return mStr;} + operator const char*() const {return (const char*)mStr;} + + /** + * This method constructs a new nsCString that is a clone + * of this string. + * + */ + nsCString* ToNewString() const; + + /** + * Creates an ISOLatin1 clone of this string + * Note that calls to this method should be matched with calls to Recycle(). + * @return ptr to new isolatin1 string + */ + char* ToNewCString() const; + + /** + * Creates a unicode clone of this string + * Note that calls to this method should be matched with calls to Recycle(). + * @return ptr to new unicode string + */ + PRUnichar* ToNewUnicode() const; + + /** + * Copies data from internal buffer onto given char* buffer + * NOTE: This only copies as many chars as will fit in given buffer (clips) + * @param aBuf is the buffer where data is stored + * @param aBuflength is the max # of chars to move to buffer + * @return ptr to given buffer + */ + char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const; + + /** + * Perform string to float conversion. + * @param aErrorCode will contain error if one occurs + * @return float rep of string value + */ + float ToFloat(PRInt32* aErrorCode) const; + + /** + * Try to derive the radix from the value contained in this string + * @return kRadix10, kRadix16 or kAutoDetect (meaning unknown) + */ + PRUint32 DetermineRadix(void); + + /** + * Perform string to int conversion. + * @param aErrorCode will contain error if one occurs + * @return int rep of string value + */ + PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const; + + + /********************************************************************** + String manipulation methods... + *********************************************************************/ + + /** + * Functionally equivalent to assign or operator= + * + */ + nsCString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} + nsCString& SetString(const nsStr& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} + + /** + * assign given string to this string + * @param aStr: buffer to be assigned to this + * @param alength is the length of the given str (or -1) + if you want me to determine its length + * @return this + */ + nsCString& Assign(const nsStr& aString,PRInt32 aCount=-1); + nsCString& Assign(const char* aString,PRInt32 aCount=-1); + nsCString& Assign(const PRUnichar* aString,PRInt32 aCount=-1); + nsCString& Assign(PRUnichar aChar); + nsCString& Assign(char aChar); + + /** + * here come a bunch of assignment operators... + * @param aString: string to be added to this + * @return this + */ + nsCString& operator=(const nsCString& aString) {return Assign(aString);} + nsCString& operator=(const nsStr& aString) {return Assign(aString);} + nsCString& operator=(PRUnichar aChar) {return Assign(aChar);} + nsCString& operator=(char aChar) {return Assign(aChar);} + nsCString& operator=(const char* aCString) {return Assign(aCString);} + nsCString& operator=(const PRUnichar* aString) {return Assign(aString);} + #ifdef AIX + nsCString& operator=(const nsSubsumeCStr& aSubsumeString); // AIX requires a const here + #else + nsCString& operator=(nsSubsumeCStr& aSubsumeString); + #endif + + /** + * Here's a bunch of methods that append varying types... + * @param various... + * @return this + */ + nsCString& operator+=(const nsCString& aString){return Append(aString,aString.mLength);} + nsCString& operator+=(const char* aCString) {return Append(aCString);} + nsCString& operator+=(PRUnichar aChar){return Append(aChar);} + nsCString& operator+=(char aChar){return Append(aChar);} + + /* + * Appends n characters from given string to this, + * This version computes the length of your given string + * + * @param aString is the source to be appended to this + * @return number of chars copied + */ + nsCString& Append(const nsCString& aString) {return Append(aString,aString.mLength);} -/* - * Appends n characters from given string to this, - * - * @param aString is the source to be appended to this - * @param aCount -- number of chars to copy; -1 tells us to compute the strlen for you - * @return number of chars copied - */ -nsCString& Append(const nsCString& aString,PRInt32 aCount); -nsCString& Append(const char* aString,PRInt32 aCount=-1); -nsCString& Append(PRUnichar aChar); -nsCString& Append(char aChar); -nsCString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16 -nsCString& Append(float aFloat); + /* + * Appends n characters from given string to this, + * + * @param aString is the source to be appended to this + * @param aCount -- number of chars to copy; -1 tells us to compute the strlen for you + * @return number of chars copied + */ + nsCString& Append(const nsCString& aString,PRInt32 aCount); + nsCString& Append(const nsStr& aString,PRInt32 aCount=-1); + nsCString& Append(const char* aString,PRInt32 aCount=-1); + nsCString& Append(PRUnichar aChar); + nsCString& Append(char aChar); + nsCString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16 + nsCString& Append(float aFloat); -/* - * Copies n characters from this string to given string, - * starting at the leftmost offset. - * - * - * @param aCopy -- Receiving string - * @param aCount -- number of chars to copy - * @return number of chars copied - */ -PRUint32 Left(nsCString& aCopy,PRInt32 aCount) const; + /* + * Copies n characters from this string to given string, + * starting at the leftmost offset. + * + * + * @param aCopy -- Receiving string + * @param aCount -- number of chars to copy + * @return number of chars copied + */ + PRUint32 Left(nsCString& aCopy,PRInt32 aCount) const; -/* - * Copies n characters from this string to given string, - * starting at the given offset. - * - * - * @param aCopy -- Receiving string - * @param aCount -- number of chars to copy - * @param anOffset -- position where copying begins - * @return number of chars copied - */ -PRUint32 Mid(nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount) const; + /* + * Copies n characters from this string to given string, + * starting at the given offset. + * + * + * @param aCopy -- Receiving string + * @param aCount -- number of chars to copy + * @param anOffset -- position where copying begins + * @return number of chars copied + */ + PRUint32 Mid(nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount) const; -/* - * Copies n characters from this string to given string, - * starting at rightmost char. - * - * - * @param aCopy -- Receiving string - * @param aCount -- number of chars to copy - * @return number of chars copied - */ -PRUint32 Right(nsCString& aCopy,PRInt32 aCount) const; + /* + * Copies n characters from this string to given string, + * starting at rightmost char. + * + * + * @param aCopy -- Receiving string + * @param aCount -- number of chars to copy + * @return number of chars copied + */ + PRUint32 Right(nsCString& aCopy,PRInt32 aCount) const; -/* - * This method inserts n chars from given string into this - * string at str[anOffset]. - * - * @param aCopy -- String to be inserted into this - * @param anOffset -- insertion position within this str - * @param aCount -- number of chars to be copied from aCopy - * @return number of chars inserted into this. - */ -nsCString& Insert(const nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1); + /* + * This method inserts n chars from given string into this + * string at str[anOffset]. + * + * @param aCopy -- String to be inserted into this + * @param anOffset -- insertion position within this str + * @param aCount -- number of chars to be copied from aCopy + * @return number of chars inserted into this. + */ + nsCString& Insert(const nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1); -/** - * Insert a given string into this string at - * a specified offset. - * - * @param aString* to be inserted into this string - * @param anOffset is insert pos in str - * @return the number of chars inserted into this string - */ -nsCString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1); + /** + * Insert a given string into this string at + * a specified offset. + * + * @param aString* to be inserted into this string + * @param anOffset is insert pos in str + * @return the number of chars inserted into this string + */ + nsCString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1); -/** - * Insert a single char into this string at - * a specified offset. - * - * @param character to be inserted into this string - * @param anOffset is insert pos in str - * @return the number of chars inserted into this string - */ -nsCString& Insert(PRUnichar aChar,PRUint32 anOffset); -nsCString& Insert(char aChar,PRUint32 anOffset); + /** + * Insert a single char into this string at + * a specified offset. + * + * @param character to be inserted into this string + * @param anOffset is insert pos in str + * @return the number of chars inserted into this string + */ + nsCString& Insert(PRUnichar aChar,PRUint32 anOffset); + nsCString& Insert(char aChar,PRUint32 anOffset); -/* - * This method is used to cut characters in this string - * starting at anOffset, continuing for aCount chars. - * - * @param anOffset -- start pos for cut operation - * @param aCount -- number of chars to be cut - * @return *this - */ -nsCString& Cut(PRUint32 anOffset,PRInt32 aCount); + /* + * This method is used to cut characters in this string + * starting at anOffset, continuing for aCount chars. + * + * @param anOffset -- start pos for cut operation + * @param aCount -- number of chars to be cut + * @return *this + */ + nsCString& Cut(PRUint32 anOffset,PRInt32 aCount); -/********************************************************************** - Searching methods... - *********************************************************************/ + /********************************************************************** + Searching methods... + *********************************************************************/ -/** - * Search for given character within this string. - * This method does so by using a binary search, - * so your string HAD BETTER BE ORDERED! - * - * @param aChar is the unicode char to be found - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 BinarySearch(PRUnichar aChar) const; + /** + * Search for given character within this string. + * This method does so by using a binary search, + * so your string HAD BETTER BE ORDERED! + * + * @param aChar is the unicode char to be found + * @return offset in string, or -1 (kNotFound) + */ + PRInt32 BinarySearch(PRUnichar aChar) const; -/** - * Search for given substring within this string - * - * @param aString is substring to be sought in this - * @param aIgnoreCase selects case sensitivity - * @param anOffset tells us where in this strig to start searching - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + /** + * Search for given substring within this string + * + * @param aString is substring to be sought in this + * @param aIgnoreCase selects case sensitivity + * @param anOffset tells us where in this strig to start searching + * @return offset in string, or -1 (kNotFound) + */ + PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -/** - * Search for given char within this string - * - * @param aString is substring to be sought in this - * @param anOffset tells us where in this strig to start searching - * @param aIgnoreCase selects case sensitivity - * @return find pos in string, or -1 (kNotFound) - */ -PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + /** + * Search for given char within this string + * + * @param aString is substring to be sought in this + * @param anOffset tells us where in this strig to start searching + * @param aIgnoreCase selects case sensitivity + * @return find pos in string, or -1 (kNotFound) + */ + PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -/** - * This method searches this string for the first character - * found in the given charset - * @param aString contains set of chars to be found - * @param anOffset tells us where to start searching in this - * @return -1 if not found, else the offset in this - */ -PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const; -PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; -PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; + /** + * This method searches this string for the first character + * found in the given charset + * @param aString contains set of chars to be found + * @param anOffset tells us where to start searching in this + * @return -1 if not found, else the offset in this + */ + PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const; + PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; + PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; -/** - * This methods scans the string backwards, looking for the given string - * @param aString is substring to be sought in this - * @param aIgnoreCase tells us whether or not to do caseless compare - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + /** + * This methods scans the string backwards, looking for the given string + * @param aString is substring to be sought in this + * @param aIgnoreCase tells us whether or not to do caseless compare + * @return offset in string, or -1 (kNotFound) + */ + PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -/** - * Search for given char within this string - * - * @param aString is substring to be sought in this - * @param anOffset tells us where in this strig to start searching - * @param aIgnoreCase selects case sensitivity - * @return find pos in string, or -1 (kNotFound) - */ -PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + /** + * Search for given char within this string + * + * @param aString is substring to be sought in this + * @param anOffset tells us where in this strig to start searching + * @param aIgnoreCase selects case sensitivity + * @return find pos in string, or -1 (kNotFound) + */ + PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -/** - * This method searches this string for the last character - * found in the given string - * @param aString contains set of chars to be found - * @param anOffset tells us where to start searching in this - * @return -1 if not found, else the offset in this - */ -PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const; -PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; -PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; + /** + * This method searches this string for the last character + * found in the given string + * @param aString contains set of chars to be found + * @param anOffset tells us where to start searching in this + * @return -1 if not found, else the offset in this + */ + PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const; + PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; + PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; -/********************************************************************** - Comparison methods... - *********************************************************************/ + /********************************************************************** + Comparison methods... + *********************************************************************/ -/** - * Compares a given string type to this string. - * @update gess 7/27/98 - * @param S is the string to be compared - * @param aIgnoreCase tells us how to treat case - * @param aCount tells us how many chars to compare - * @return -1,0,1 - */ -virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + /** + * Compares a given string type to this string. + * @update gess 7/27/98 + * @param S is the string to be compared + * @param aIgnoreCase tells us how to treat case + * @param aCount tells us how many chars to compare + * @return -1,0,1 + */ + virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -/** - * These methods compare a given string type to this one - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator==(const nsStr &aString) const; -PRBool operator==(const char* aString) const; -PRBool operator==(const PRUnichar* aString) const; + /** + * These methods compare a given string type to this one + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator==(const nsStr &aString) const; + PRBool operator==(const char* aString) const; + PRBool operator==(const PRUnichar* aString) const; -/** - * These methods perform a !compare of a given string type to this - * @param aString is the string to be compared to this - * @return TRUE - */ -PRBool operator!=(const nsStr &aString) const; -PRBool operator!=(const char* aString) const; -PRBool operator!=(const PRUnichar* aString) const; + /** + * These methods perform a !compare of a given string type to this + * @param aString is the string to be compared to this + * @return TRUE + */ + PRBool operator!=(const nsStr &aString) const; + PRBool operator!=(const char* aString) const; + PRBool operator!=(const PRUnichar* aString) const; -/** - * These methods test if a given string is < than this - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator<(const nsStr &aString) const; -PRBool operator<(const char* aString) const; -PRBool operator<(const PRUnichar* aString) const; + /** + * These methods test if a given string is < than this + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator<(const nsStr &aString) const; + PRBool operator<(const char* aString) const; + PRBool operator<(const PRUnichar* aString) const; -/** - * These methods test if a given string is > than this - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator>(const nsStr &S) const; -PRBool operator>(const char* aString) const; -PRBool operator>(const PRUnichar* aString) const; + /** + * These methods test if a given string is > than this + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator>(const nsStr &S) const; + PRBool operator>(const char* aString) const; + PRBool operator>(const PRUnichar* aString) const; -/** - * These methods test if a given string is <= than this - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator<=(const nsStr &S) const; -PRBool operator<=(const char* aString) const; -PRBool operator<=(const PRUnichar* aString) const; + /** + * These methods test if a given string is <= than this + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator<=(const nsStr &S) const; + PRBool operator<=(const char* aString) const; + PRBool operator<=(const PRUnichar* aString) const; -/** - * These methods test if a given string is >= than this - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator>=(const nsStr &S) const; -PRBool operator>=(const char* aString) const; -PRBool operator>=(const PRUnichar* aString) const; + /** + * These methods test if a given string is >= than this + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator>=(const nsStr &S) const; + PRBool operator>=(const char* aString) const; + PRBool operator>=(const PRUnichar* aString) const; -/** - * Compare this to given string; note that we compare full strings here. - * The optional length argument just lets us know how long the given string is. - * If you provide a length, it is compared to length of this string as an - * optimization. - * - * @param aString -- the string to compare to this - * @param aCount -- number of chars in given string you want to compare - * @return TRUE if equal - */ -PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + /** + * Compare this to given string; note that we compare full strings here. + * The optional length argument just lets us know how long the given string is. + * If you provide a length, it is compared to length of this string as an + * optimization. + * + * @param aString -- the string to compare to this + * @param aCount -- number of chars in given string you want to compare + * @return TRUE if equal + */ + PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -PRBool EqualsIgnoreCase(const nsStr& aString) const; -PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const; -PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const; + PRBool EqualsIgnoreCase(const nsStr& aString) const; + PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const; + PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const; -static void Recycle(nsCString* aString); -static nsCString* CreateString(void); - - - nsIMemoryAgent* mAgent; + static void Recycle(nsCString* aString); + static nsCString* CreateString(void); }; diff --git a/mozilla/string/obsolete/nsString2.cpp b/mozilla/string/obsolete/nsString2.cpp index 84553e38e94..edc080b2073 100644 --- a/mozilla/string/obsolete/nsString2.cpp +++ b/mozilla/string/obsolete/nsString2.cpp @@ -38,7 +38,7 @@ static const char* kWhitespace="\b\t\r\n "; static void Subsume(nsStr& aDest,nsStr& aSource){ if(aSource.mStr && aSource.mLength) { if(aSource.mOwnsBuffer){ - nsStr::Destroy(aDest,0); + nsStr::Destroy(aDest); aDest.mStr=aSource.mStr; aDest.mLength=aSource.mLength; aDest.mCharSize=aSource.mCharSize; @@ -48,17 +48,17 @@ static void Subsume(nsStr& aDest,nsStr& aSource){ aSource.mStr=0; } else{ - nsStr::Assign(aDest,aSource,0,aSource.mLength,0); + nsStr::Assign(aDest,aSource,0,aSource.mLength); } } - else nsStr::Truncate(aDest,0,0); + else nsStr::Truncate(aDest,0); } /** * Default constructor. */ -nsString::nsString(nsIMemoryAgent* anAgent) : mAgent(anAgent) { +nsString::nsString() { nsStr::Initialize(*this,eTwoByte); } @@ -68,7 +68,7 @@ nsString::nsString(nsIMemoryAgent* anAgent) : mAgent(anAgent) { * @param aCString is a ptr to a 1-byte cstr * @param aLength tells us how many chars to copy from given CString */ -nsString::nsString(const char* aCString,nsIMemoryAgent* anAgent) : mAgent(anAgent) { +nsString::nsString(const char* aCString){ nsStr::Initialize(*this,eTwoByte); Assign(aCString); } @@ -79,7 +79,7 @@ nsString::nsString(const char* aCString,nsIMemoryAgent* anAgent) : mAgent(anAgen * @param aString is a ptr to a unichar string * @param aLength tells us how many chars to copy from given aString */ -nsString::nsString(const PRUnichar* aString,nsIMemoryAgent* anAgent) : mAgent(anAgent) { +nsString::nsString(const PRUnichar* aString) { nsStr::Initialize(*this,eTwoByte); Assign(aString); } @@ -89,9 +89,9 @@ nsString::nsString(const PRUnichar* aString,nsIMemoryAgent* anAgent) : mAgent(an * @update gess 1/4/99 * @param reference to another nsCString */ -nsString::nsString(const nsStr &aString,nsIMemoryAgent* anAgent) : mAgent(anAgent) { +nsString::nsString(const nsStr &aString) { nsStr::Initialize(*this,eTwoByte); - nsStr::Assign(*this,aString,0,aString.mLength,mAgent); + nsStr::Assign(*this,aString,0,aString.mLength); } /** @@ -99,9 +99,9 @@ nsString::nsString(const nsStr &aString,nsIMemoryAgent* anAgent) : mAgent(anAgen * @update gess 1/4/99 * @param reference to another nsString */ -nsString::nsString(const nsString& aString) :mAgent(aString.mAgent) { +nsString::nsString(const nsString& aString) { nsStr::Initialize(*this,eTwoByte); - nsStr::Assign(*this,aString,0,aString.mLength,mAgent); + nsStr::Assign(*this,aString,0,aString.mLength); } /** @@ -109,7 +109,7 @@ nsString::nsString(const nsString& aString) :mAgent(aString.mAgent) { * @update gess 1/4/99 * @param reference to a subsumeString */ -nsString::nsString(nsSubsumeStr& aSubsumeStr) :mAgent(0) { +nsString::nsString(nsSubsumeStr& aSubsumeStr) { nsStr::Initialize(*this,eTwoByte); Subsume(*this,aSubsumeStr); } @@ -119,7 +119,7 @@ nsString::nsString(nsSubsumeStr& aSubsumeStr) :mAgent(0) { * Make sure we call nsStr::Destroy. */ nsString::~nsString() { - nsStr::Destroy(*this,mAgent); + nsStr::Destroy(*this); } void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const { @@ -136,7 +136,7 @@ void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const { * @return nada */ void nsString::Truncate(PRInt32 anIndex) { - nsStr::Truncate(*this,anIndex,mAgent); + nsStr::Truncate(*this,anIndex); } /** @@ -173,7 +173,7 @@ PRBool nsString::IsOrdered(void) const { */ void nsString::SetCapacity(PRUint32 aLength) { if(aLength>mCapacity) { - GrowCapacity(*this,aLength,mAgent); + GrowCapacity(*this,aLength); } AddNullTerminator(*this); } @@ -270,7 +270,7 @@ PRBool nsString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){ */ nsSubsumeStr nsString::operator+(const nsStr& aString){ nsString temp(*this); //make a temp string the same size as this... - nsStr::Append(temp,aString,0,aString.mLength,mAgent); + nsStr::Append(temp,aString,0,aString.mLength); return nsSubsumeStr(temp); } @@ -282,7 +282,7 @@ nsSubsumeStr nsString::operator+(const nsStr& aString){ */ nsSubsumeStr nsString::operator+(const nsString& aString){ nsString temp(*this); //make a temp string the same size as this... - nsStr::Append(temp,aString,0,aString.mLength,mAgent); + nsStr::Append(temp,aString,0,aString.mLength); return nsSubsumeStr(temp); } @@ -786,54 +786,55 @@ static PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadi * @return non-zero error code if this string is non-numeric */ static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) { + static const char* validChars="0123456789abcdefABCDEF-+#"; - aString.ToUpperCase(); + const char* cp=aString.GetBuffer(); + PRInt32 result=NS_ERROR_ILLEGAL_VALUE; + if(cp) { - PRInt32 decPt=nsStr::FindChar(aString,'.',PR_TRUE,0); - char* cp = (kNotFound==decPt) ? aString.mStr + aString.mLength-1 : aString.mStr+decPt-1; - - aRadix=kRadixUnknown; //assume for starters... + //begin by skipping over leading chars that shouldn't be part of the number... + + char* to=(char*)cp; + const char* endcp=cp+aString.mLength; + int len=strlen(validChars); - // Skip trailing non-numeric... - while (cp >= aString.mStr) { - if((*cp>='0') && (*cp<='9')){ - if(kRadixUnknown==aRadix) - aRadix=kRadix10; - break; + while(cp='A') && (*cp<='F')) { - aRadix=16; - break; - } - cp--; + + while(cp='0') && (theChar<='9')) { + *to++=theChar; + } + else if((theChar>='A') && (theChar<='F')) { + aRadix=16; + *to++=theChar; + } + else if('X'==theChar){ + if('-'==aString.mStr[0]) + to=&aString.mStr[1]; + else to=aString.mStr; + aRadix=16; + //root=cp; + } + else if('-'==theChar) { + *to++=theChar; + } + else if(('#'==theChar) || ('+'==theChar)){ + //just skip this char... + } + else break; + cp++; + } + aString.Truncate(to-aString.mStr); + result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; } - aString.Truncate(cp-aString.mStr+1); - - //ok, now scan through chars until you find the start of this number... - //we delimit the number by the presence of: +,-,#,X - - // Skip trailing non-numeric... - cp++; - while (--cp >= aString.mStr) { - if((*cp>='0') && (*cp<='9')){ - continue; - } - else if((*cp>='A') && (*cp<='F')) { - continue; - } - else if((*cp=='-') || (*cp=='+')){ - break; - } - else { - if(('#'==(*cp)) || ('X'==(*cp))) - aRadix=kRadix16; - cp++; //move back by one - break; - } - } - if(cp>aString.mStr) - aString.Cut(0,cp-aString.mStr); - PRInt32 result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; return result; } @@ -865,10 +866,10 @@ PRUint32 nsString::DetermineRadix(void) { PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const { //copy chars to local buffer -- step down from 2 bytes to 1 if necessary... + PRInt32 result=0; nsCAutoString theString(*this); PRUint32 theRadix=aRadix; - PRInt32 result=0; - + *anErrorCode=GetNumericSubstring(theString,theRadix); //we actually don't use this radix; use given radix instead if(NS_OK==*anErrorCode){ if(kAutoDetect==aRadix) @@ -893,13 +894,13 @@ PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const { */ nsString& nsString::Assign(const nsStr& aString,PRInt32 aCount) { if(this!=&aString){ - nsStr::Truncate(*this,0,0); + nsStr::Truncate(*this,0); if(aCount<0) aCount=aString.mLength; else aCount=MinInt(aCount,aString.mLength); - nsStr::Assign(*this,aString,0,aCount,mAgent); + nsStr::Assign(*this,aString,0,aCount); } return *this; } @@ -912,7 +913,7 @@ nsString& nsString::Assign(const nsStr& aString,PRInt32 aCount) { * @return this */ nsString& nsString::Assign(const char* aCString,PRInt32 aCount) { - nsStr::Truncate(*this,0,0); + nsStr::Truncate(*this,0); if(aCString){ Append(aCString,aCount); } @@ -926,7 +927,7 @@ nsString& nsString::Assign(const char* aCString,PRInt32 aCount) { * @return this */ nsString& nsString::Assign(const PRUnichar* aString,PRInt32 aCount) { - nsStr::Truncate(*this,0,0); + nsStr::Truncate(*this,0); if(aString){ Append(aString,aCount); } @@ -940,7 +941,7 @@ nsString& nsString::Assign(const PRUnichar* aString,PRInt32 aCount) { * @return this */ nsString& nsString::Assign(char aChar) { - nsStr::Truncate(*this,0,0); + nsStr::Truncate(*this,0); return Append(aChar); } @@ -951,7 +952,7 @@ nsString& nsString::Assign(char aChar) { * @return this */ nsString& nsString::Assign(PRUnichar aChar) { - nsStr::Truncate(*this,0,0); + nsStr::Truncate(*this,0); return Append(aChar); } @@ -988,7 +989,7 @@ nsString& nsString::Append(const nsStr& aString,PRInt32 aCount) { else aCount=MinInt(aCount,aString.mLength); if(0=1) { - PRInt32 div=theInt/mask1; - if((div) || (!isfirst)) { - buf[charpos++]="0123456789abcdef"[div]; + PRInt32 theDiv=theInt/mask1; + if((theDiv) || (!isfirst)) { + buf[charpos++]="0123456789abcdef"[theDiv]; isfirst=PR_FALSE; } - theInt-=div*mask1; + theInt-=theDiv*mask1; mask1/=aRadix; } return Append(buf); @@ -1173,7 +1174,7 @@ PRUint32 nsString::Left(nsString& aDest,PRInt32 aCount) const{ if(aCount<0) aCount=mLength; else aCount=MinInt(aCount,mLength); - nsStr::Assign(aDest,*this,0,aCount,mAgent); + nsStr::Assign(aDest,*this,0,aCount); return aDest.mLength; } @@ -1191,7 +1192,7 @@ PRUint32 nsString::Mid(nsString& aDest,PRUint32 anOffset,PRInt32 aCount) const{ if(aCount<0) aCount=mLength; else aCount=MinInt(aCount,mLength); - nsStr::Assign(aDest,*this,anOffset,aCount,mAgent); + nsStr::Assign(aDest,*this,anOffset,aCount); return aDest.mLength; } @@ -1221,7 +1222,7 @@ PRUint32 nsString::Right(nsString& aDest,PRInt32 aCount) const{ * @return this */ nsString& nsString::Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) { - nsStr::Insert(*this,anOffset,aCopy,0,aCount,mAgent); + nsStr::Insert(*this,anOffset,aCopy,0,aCount); return *this; } @@ -1252,7 +1253,7 @@ nsString& nsString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCount else aCount=temp.mLength=nsCRT::strlen(aCString); if(0mAgent=&theAgent; delete aString; } return 0; @@ -2116,7 +2115,6 @@ NS_COM int fputs(const nsString& aString, FILE* out) */ nsAutoString::nsAutoString() : nsString() { nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); - mAgent=0; AddNullTerminator(*this); } @@ -2127,7 +2125,6 @@ nsAutoString::nsAutoString() : nsString() { */ nsAutoString::nsAutoString(const char* aCString,PRInt32 aLength) : nsString() { nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); - mAgent=0; AddNullTerminator(*this); Append(aCString,aLength); } @@ -2138,7 +2135,6 @@ nsAutoString::nsAutoString(const char* aCString,PRInt32 aLength) : nsString() { * @param aLength tells us how many chars to copy from aString */ nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString() { - mAgent=0; nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); AddNullTerminator(*this); Append(aString,aLength); @@ -2149,7 +2145,6 @@ nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString( * @param aBuffer describes the external buffer */ nsAutoString::nsAutoString(const CBufDescriptor& aBuffer) : nsString() { - mAgent=0; if(!aBuffer.mBuffer) { nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); } @@ -2166,7 +2161,6 @@ nsAutoString::nsAutoString(const CBufDescriptor& aBuffer) : nsString() { * @param */ nsAutoString::nsAutoString(const nsStr& aString) : nsString() { - mAgent=0; nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); AddNullTerminator(*this); Append(aString); @@ -2176,7 +2170,6 @@ nsAutoString::nsAutoString(const nsStr& aString) : nsString() { * Default copy constructor */ nsAutoString::nsAutoString(const nsAutoString& aString) : nsString() { - mAgent=0; nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); AddNullTerminator(*this); Append(aString); @@ -2188,7 +2181,6 @@ nsAutoString::nsAutoString(const nsAutoString& aString) : nsString() { * @param */ nsAutoString::nsAutoString(PRUnichar aChar) : nsString(){ - mAgent=0; nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); AddNullTerminator(*this); Append(aChar); @@ -2201,12 +2193,10 @@ nsAutoString::nsAutoString(PRUnichar aChar) : nsString(){ */ #ifdef AIX nsAutoString::nsAutoString(const nsSubsumeStr& aSubsumeStr) :nsString() { - mAgent=0; nsSubsumeStr temp(aSubsumeStr); // a temp is needed for the AIX compiler Subsume(*this,temp); #else nsAutoString::nsAutoString( nsSubsumeStr& aSubsumeStr) :nsString() { - mAgent=0; Subsume(*this,aSubsumeStr); #endif // AIX } diff --git a/mozilla/string/obsolete/nsString2.h b/mozilla/string/obsolete/nsString2.h index 80332198c4d..a22ca6b7c04 100644 --- a/mozilla/string/obsolete/nsString2.h +++ b/mozilla/string/obsolete/nsString2.h @@ -53,716 +53,716 @@ class nsISizeOfHandler; class NS_COM nsSubsumeStr; class NS_COM nsString : public nsStr { - public: +public: -/** - * Default constructor. - */ -nsString(nsIMemoryAgent* anAgent=0); - - -/** - * This constructor accepts an isolatin string - * @param aCString is a ptr to a 1-byte cstr - */ -nsString(const char* aCString,nsIMemoryAgent* anAgent=0); - -/** - * This constructor accepts a unichar string - * @param aCString is a ptr to a 2-byte cstr - */ -nsString(const PRUnichar* aString,nsIMemoryAgent* anAgent=0); - -/** - * This is a copy constructor that accepts an nsStr - * @param reference to another nsString - */ -nsString(const nsStr&,nsIMemoryAgent* anAgent=0); - -/** - * This is our copy constructor - * @param reference to another nsString - */ -nsString(const nsString& aString); - -/** - * This constructor takes a subsumestr - * @param reference to subsumestr - */ -nsString(nsSubsumeStr& aSubsumeStr); - -/** - * Destructor - * - */ -virtual ~nsString(); - -/** - * Retrieve the length of this string - * @return string length - */ -inline PRInt32 Length() const { return (PRInt32)mLength; } - -/** - * Retrieve the size of this string - * @return string length - */ -virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const; - - -/** - * Call this method if you want to force a different string length - * @update gess7/30/98 - * @param aLength -- contains new length for mStr - * @return - */ -void SetLength(PRUint32 aLength) { - Truncate(aLength); -} - -/** - * Sets the new length of the string. - * @param aLength is new string length. - * @return nada - */ -void SetCapacity(PRUint32 aLength); - -/** - * This method truncates this string to given length. - * - * @param anIndex -- new length of string - * @return nada - */ -void Truncate(PRInt32 anIndex=0); - - -/** - * Determine whether or not the characters in this - * string are in sorted order. - * - * @return TRUE if ordered. - */ -PRBool IsOrdered(void) const; - -/** - * Determine whether or not the characters in this - * string are in store as 1 or 2 byte (unicode) strings. - * - * @return TRUE if ordered. - */ -PRBool IsUnicode(void) const { - PRBool result=PRBool(mCharSize==eTwoByte); - return result; -} - -/** - * Determine whether or not this string has a length of 0 - * - * @return TRUE if empty. - */ -PRBool IsEmpty(void) const { - return PRBool(0==mLength); -} - -/********************************************************************** - Getters/Setters... - *********************************************************************/ - -const char* GetBuffer(void) const; -const PRUnichar* GetUnicode(void) const; - - - /** - * Get nth character. + /** + * Default constructor. */ -PRUnichar operator[](PRUint32 anIndex) const; -PRUnichar CharAt(PRUint32 anIndex) const; -PRUnichar First(void) const; -PRUnichar Last(void) const; + nsString(); - /** - * Set nth character. + + /** + * This constructor accepts an isolatin string + * @param aCString is a ptr to a 1-byte cstr */ -PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex); + nsString(const char* aCString); + + /** + * This constructor accepts a unichar string + * @param aCString is a ptr to a 2-byte cstr + */ + nsString(const PRUnichar* aString); + + /** + * This is a copy constructor that accepts an nsStr + * @param reference to another nsString + */ + nsString(const nsStr&); + + /** + * This is our copy constructor + * @param reference to another nsString + */ + nsString(const nsString& aString); + + /** + * This constructor takes a subsumestr + * @param reference to subsumestr + */ + nsString(nsSubsumeStr& aSubsumeStr); + + /** + * Destructor + * + */ + virtual ~nsString(); + + /** + * Retrieve the length of this string + * @return string length + */ + inline PRInt32 Length() const { return (PRInt32)mLength; } + + /** + * Retrieve the size of this string + * @return string length + */ + virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const; -/********************************************************************** - String concatenation methods... - *********************************************************************/ + /** + * Call this method if you want to force a different string length + * @update gess7/30/98 + * @param aLength -- contains new length for mStr + * @return + */ + void SetLength(PRUint32 aLength) { + Truncate(aLength); + } -/** - * Create a new string by appending given string to this - * @param aString -- 2nd string to be appended - * @return new subsumable string - */ -nsSubsumeStr operator+(const nsStr& aString); -nsSubsumeStr operator+(const nsString& aString); + /** + * Sets the new length of the string. + * @param aLength is new string length. + * @return nada + */ + void SetCapacity(PRUint32 aLength); -/** - * create a new string by adding this to the given cstring - * @param aCString is a ptr to cstring to be added to this - * @return newly created string - */ -nsSubsumeStr operator+(const char* aCString); - -/** - * create a new string by adding this to the given prunichar*. - * @param aString is a ptr to UC-string to be added to this - * @return newly created string - */ -nsSubsumeStr operator+(const PRUnichar* aString); - -/** - * create a new string by adding this to the given char. - * @param aChar is a char to be added to this - * @return newly created string - */ -nsSubsumeStr operator+(char aChar); - -/** - * create a new string by adding this to the given char. - * @param aChar is a unichar to be added to this - * @return newly created string - */ -nsSubsumeStr operator+(PRUnichar aChar); - -/********************************************************************** - Lexomorphic transforms... - *********************************************************************/ + /** + * This method truncates this string to given length. + * + * @param anIndex -- new length of string + * @return nada + */ + void Truncate(PRInt32 anIndex=0); -/** - * Converts chars in this to lowercase - * @update gess 7/27/98 - */ -void ToLowerCase(); + /** + * Determine whether or not the characters in this + * string are in sorted order. + * + * @return TRUE if ordered. + */ + PRBool IsOrdered(void) const; + + /** + * Determine whether or not the characters in this + * string are in store as 1 or 2 byte (unicode) strings. + * + * @return TRUE if ordered. + */ + PRBool IsUnicode(void) const { + PRBool result=PRBool(mCharSize==eTwoByte); + return result; + } + + /** + * Determine whether or not this string has a length of 0 + * + * @return TRUE if empty. + */ + PRBool IsEmpty(void) const { + return PRBool(0==mLength); + } + + /********************************************************************** + Getters/Setters... + *********************************************************************/ + + /** + * Retrieve const ptr to internal buffer; DO NOT TRY TO FREE IT! + */ + const char* GetBuffer(void) const; + const PRUnichar* GetUnicode(void) const; -/** - * Converts chars in this to lowercase, and - * stores them in aOut - * @update gess 7/27/98 - * @param aOut is a string to contain result - */ -void ToLowerCase(nsString& aString) const; + /** + * Get nth character. + */ + PRUnichar operator[](PRUint32 anIndex) const; + PRUnichar CharAt(PRUint32 anIndex) const; + PRUnichar First(void) const; + PRUnichar Last(void) const; -/** - * Converts chars in this to uppercase - * @update gess 7/27/98 - */ -void ToUpperCase(); - -/** - * Converts chars in this to lowercase, and - * stores them in a given output string - * @update gess 7/27/98 - * @param aOut is a string to contain result - */ -void ToUpperCase(nsString& aString) const; + /** + * Set nth character. + */ + PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex); -/** - * This method is used to remove all occurances of the - * characters found in aSet from this string. - * - * @param aSet -- characters to be cut from this - * @return *this - */ -nsString& StripChars(const char* aSet); -nsString& StripChar(char aChar); + /********************************************************************** + String concatenation methods... + *********************************************************************/ -/** - * This method strips whitespace throughout the string - * - * @return this - */ -nsString& StripWhitespace(); + /** + * Create a new string by appending given string to this + * @param aString -- 2nd string to be appended + * @return new subsumable string + */ + nsSubsumeStr operator+(const nsStr& aString); + nsSubsumeStr operator+(const nsString& aString); -/** - * swaps occurence of 1 string for another - * - * @return this - */ -nsString& ReplaceChar(PRUnichar anOldChar,PRUnichar aNewChar); -nsString& ReplaceChar(const char* aSet,PRUnichar aNewChar); + /** + * create a new string by adding this to the given cstring + * @param aCString is a ptr to cstring to be added to this + * @return newly created string + */ + nsSubsumeStr operator+(const char* aCString); -PRInt32 CountChar(PRUnichar aChar); + /** + * create a new string by adding this to the given prunichar*. + * @param aString is a ptr to UC-string to be added to this + * @return newly created string + */ + nsSubsumeStr operator+(const PRUnichar* aString); -/** - * This method trims characters found in aTrimSet from - * either end of the underlying string. - * - * @param aTrimSet -- contains chars to be trimmed from - * both ends - * @return this - */ -nsString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + /** + * create a new string by adding this to the given char. + * @param aChar is a char to be added to this + * @return newly created string + */ + nsSubsumeStr operator+(char aChar); -/** - * This method strips whitespace from string. - * You can control whether whitespace is yanked from - * start and end of string as well. - * - * @param aEliminateLeading controls stripping of leading ws - * @param aEliminateTrailing controls stripping of trailing ws - * @return this - */ -nsString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + /** + * create a new string by adding this to the given char. + * @param aChar is a unichar to be added to this + * @return newly created string + */ + nsSubsumeStr operator+(PRUnichar aChar); -/** - * This method strips whitespace from string. - * You can control whether whitespace is yanked from - * start and end of string as well. - * - * @param aEliminateLeading controls stripping of leading ws - * @param aEliminateTrailing controls stripping of trailing ws - * @return this - */ -nsString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); - -/********************************************************************** - string conversion methods... - *********************************************************************/ - -/** - * This method constructs a new nsString is a clone of this string. - * - */ -nsString* ToNewString() const; - -/** - * Creates an ISOLatin1 clone of this string - * Note that calls to this method should be matched with calls to Recycle(). - * @return ptr to new isolatin1 string - */ -char* ToNewCString() const; - -/** - * Creates an UTF8 clone of this string - * Note that calls to this method should be matched with calls to Recycle(). - * @return ptr to new isolatin1 string - */ -char* ToNewUTF8String() const; - -/** - * Creates a unicode clone of this string - * Note that calls to this method should be matched with calls to Recycle(). - * @return ptr to new unicode string - */ -PRUnichar* ToNewUnicode() const; - -/** - * Copies data from internal buffer onto given char* buffer - * NOTE: This only copies as many chars as will fit in given buffer (clips) - * @param aBuf is the buffer where data is stored - * @param aBuflength is the max # of chars to move to buffer - * @return ptr to given buffer - */ -char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const; - -/** - * Perform string to float conversion. - * @param aErrorCode will contain error if one occurs - * @return float rep of string value - */ -float ToFloat(PRInt32* aErrorCode) const; - -/** - * Try to derive the radix from the value contained in this string - * @return kRadix10, kRadix16 or kAutoDetect (meaning unknown) - */ -PRUint32 DetermineRadix(void); - -/** - * Perform string to int conversion. - * @param aErrorCode will contain error if one occurs - * @return int rep of string value - */ -PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const; + /********************************************************************** + Lexomorphic transforms... + *********************************************************************/ -/********************************************************************** - String manipulation methods... - *********************************************************************/ + /** + * Converts chars in this to lowercase + * @update gess 7/27/98 + */ + void ToLowerCase(); -/** - * Functionally equivalent to assign or operator= - * - */ -nsString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} -nsString& SetString(const PRUnichar* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} -nsString& SetString(const nsString& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} -/** - * assign given string to this string - * @param aStr: buffer to be assigned to this - * @param alength is the length of the given str (or -1) - if you want me to determine its length - * @return this - */ -nsString& Assign(const nsStr& aString,PRInt32 aCount=-1); -nsString& Assign(const char* aString,PRInt32 aCount=-1); -nsString& Assign(const PRUnichar* aString,PRInt32 aCount=-1); -nsString& Assign(char aChar); -nsString& Assign(PRUnichar aChar); + /** + * Converts chars in this to lowercase, and + * stores them in aOut + * @update gess 7/27/98 + * @param aOut is a string to contain result + */ + void ToLowerCase(nsString& aString) const; -/** - * here come a bunch of assignment operators... - * @param aString: string to be added to this - * @return this - */ -nsString& operator=(const nsString& aString) {return Assign(aString);} -nsString& operator=(const nsStr& aString) {return Assign(aString);} -nsString& operator=(char aChar) {return Assign(aChar);} -nsString& operator=(PRUnichar aChar) {return Assign(aChar);} -nsString& operator=(const char* aCString) {return Assign(aCString);} -nsString& operator=(const PRUnichar* aString) {return Assign(aString);} -#ifdef AIX -nsString& operator=(const nsSubsumeStr& aSubsumeString); // AIX requires a const here -#else -nsString& operator=(nsSubsumeStr& aSubsumeString); -#endif + /** + * Converts chars in this to uppercase + * @update gess 7/27/98 + */ + void ToUpperCase(); -/** - * Here's a bunch of methods that append varying types... - * @param various... - * @return this - */ -nsString& operator+=(const nsStr& aString){return Append(aString,aString.mLength);} -nsString& operator+=(const nsString& aString){return Append(aString,aString.mLength);} -nsString& operator+=(const char* aCString) {return Append(aCString);} -//nsString& operator+=(char aChar){return Append(aChar);} -nsString& operator+=(const PRUnichar* aUCString) {return Append(aUCString);} -nsString& operator+=(PRUnichar aChar){return Append(aChar);} + /** + * Converts chars in this to lowercase, and + * stores them in a given output string + * @update gess 7/27/98 + * @param aOut is a string to contain result + */ + void ToUpperCase(nsString& aString) const; -/* - * Appends n characters from given string to this, - * This version computes the length of your given string - * - * @param aString is the source to be appended to this - * @return number of chars copied - */ -nsString& Append(const nsStr& aString) {return Append(aString,aString.mLength);} -nsString& Append(const nsString& aString) {return Append(aString,aString.mLength);} + + /** + * This method is used to remove all occurances of the + * characters found in aSet from this string. + * + * @param aSet -- characters to be cut from this + * @return *this + */ + nsString& StripChars(const char* aSet); + nsString& StripChar(char aChar); + + /** + * This method strips whitespace throughout the string + * + * @return this + */ + nsString& StripWhitespace(); + + /** + * swaps occurence of 1 string for another + * + * @return this + */ + nsString& ReplaceChar(PRUnichar anOldChar,PRUnichar aNewChar); + nsString& ReplaceChar(const char* aSet,PRUnichar aNewChar); + + PRInt32 CountChar(PRUnichar aChar); + + /** + * This method trims characters found in aTrimSet from + * either end of the underlying string. + * + * @param aTrimSet -- contains chars to be trimmed from + * both ends + * @return this + */ + nsString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + + /** + * This method strips whitespace from string. + * You can control whether whitespace is yanked from + * start and end of string as well. + * + * @param aEliminateLeading controls stripping of leading ws + * @param aEliminateTrailing controls stripping of trailing ws + * @return this + */ + nsString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + + /** + * This method strips whitespace from string. + * You can control whether whitespace is yanked from + * start and end of string as well. + * + * @param aEliminateLeading controls stripping of leading ws + * @param aEliminateTrailing controls stripping of trailing ws + * @return this + */ + nsString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + + /********************************************************************** + string conversion methods... + *********************************************************************/ + + /** + * This method constructs a new nsString is a clone of this string. + * + */ + nsString* ToNewString() const; + + /** + * Creates an ISOLatin1 clone of this string + * Note that calls to this method should be matched with calls to Recycle(). + * @return ptr to new isolatin1 string + */ + char* ToNewCString() const; + + /** + * Creates an UTF8 clone of this string + * Note that calls to this method should be matched with calls to Recycle(). + * @return ptr to new isolatin1 string + */ + char* ToNewUTF8String() const; + + /** + * Creates a unicode clone of this string + * Note that calls to this method should be matched with calls to Recycle(). + * @return ptr to new unicode string + */ + PRUnichar* ToNewUnicode() const; + + /** + * Copies data from internal buffer onto given char* buffer + * NOTE: This only copies as many chars as will fit in given buffer (clips) + * @param aBuf is the buffer where data is stored + * @param aBuflength is the max # of chars to move to buffer + * @return ptr to given buffer + */ + char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const; + + /** + * Perform string to float conversion. + * @param aErrorCode will contain error if one occurs + * @return float rep of string value + */ + float ToFloat(PRInt32* aErrorCode) const; + + /** + * Try to derive the radix from the value contained in this string + * @return kRadix10, kRadix16 or kAutoDetect (meaning unknown) + */ + PRUint32 DetermineRadix(void); + + /** + * Perform string to int conversion. + * @param aErrorCode will contain error if one occurs + * @return int rep of string value + */ + PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const; + + + /********************************************************************** + String manipulation methods... + *********************************************************************/ + + /** + * Functionally equivalent to assign or operator= + * + */ + nsString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} + nsString& SetString(const PRUnichar* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} + nsString& SetString(const nsString& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} + + /** + * assign given string to this string + * @param aStr: buffer to be assigned to this + * @param alength is the length of the given str (or -1) + if you want me to determine its length + * @return this + */ + nsString& Assign(const nsStr& aString,PRInt32 aCount=-1); + nsString& Assign(const char* aString,PRInt32 aCount=-1); + nsString& Assign(const PRUnichar* aString,PRInt32 aCount=-1); + nsString& Assign(char aChar); + nsString& Assign(PRUnichar aChar); + + /** + * here come a bunch of assignment operators... + * @param aString: string to be added to this + * @return this + */ + nsString& operator=(const nsString& aString) {return Assign(aString);} + nsString& operator=(const nsStr& aString) {return Assign(aString);} + nsString& operator=(char aChar) {return Assign(aChar);} + nsString& operator=(PRUnichar aChar) {return Assign(aChar);} + nsString& operator=(const char* aCString) {return Assign(aCString);} + nsString& operator=(const PRUnichar* aString) {return Assign(aString);} + #ifdef AIX + nsString& operator=(const nsSubsumeStr& aSubsumeString); // AIX requires a const here + #else + nsString& operator=(nsSubsumeStr& aSubsumeString); + #endif + + /** + * Here's a bunch of methods that append varying types... + * @param various... + * @return this + */ + nsString& operator+=(const nsStr& aString){return Append(aString,aString.mLength);} + nsString& operator+=(const nsString& aString){return Append(aString,aString.mLength);} + nsString& operator+=(const char* aCString) {return Append(aCString);} + //nsString& operator+=(char aChar){return Append(aChar);} + nsString& operator+=(const PRUnichar* aUCString) {return Append(aUCString);} + nsString& operator+=(PRUnichar aChar){return Append(aChar);} + + /* + * Appends n characters from given string to this, + * This version computes the length of your given string + * + * @param aString is the source to be appended to this + * @return number of chars copied + */ + nsString& Append(const nsStr& aString) {return Append(aString,aString.mLength);} + nsString& Append(const nsString& aString) {return Append(aString,aString.mLength);} -/* - * Appends n characters from given string to this, - * - * @param aString is the source to be appended to this - * @param aCount -- number of chars to copy; -1 tells us to compute the strlen for you - * @return number of chars copied - */ -nsString& Append(const nsStr& aString,PRInt32 aCount); -nsString& Append(const nsString& aString,PRInt32 aCount); -nsString& Append(const char* aString,PRInt32 aCount=-1); -nsString& Append(const PRUnichar* aString,PRInt32 aCount=-1); -nsString& Append(char aChar); -nsString& Append(PRUnichar aChar); -nsString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16 -nsString& Append(float aFloat); + /* + * Appends n characters from given string to this, + * + * @param aString is the source to be appended to this + * @param aCount -- number of chars to copy; -1 tells us to compute the strlen for you + * @return number of chars copied + */ + nsString& Append(const nsStr& aString,PRInt32 aCount); + nsString& Append(const nsString& aString,PRInt32 aCount); + nsString& Append(const char* aString,PRInt32 aCount=-1); + nsString& Append(const PRUnichar* aString,PRInt32 aCount=-1); + nsString& Append(char aChar); + nsString& Append(PRUnichar aChar); + nsString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16 + nsString& Append(float aFloat); -/* - * Copies n characters from this string to given string, - * starting at the leftmost offset. - * - * - * @param aCopy -- Receiving string - * @param aCount -- number of chars to copy - * @return number of chars copied - */ -PRUint32 Left(nsString& aCopy,PRInt32 aCount) const; + /* + * Copies n characters from this string to given string, + * starting at the leftmost offset. + * + * + * @param aCopy -- Receiving string + * @param aCount -- number of chars to copy + * @return number of chars copied + */ + PRUint32 Left(nsString& aCopy,PRInt32 aCount) const; -/* - * Copies n characters from this string to given string, - * starting at the given offset. - * - * - * @param aCopy -- Receiving string - * @param aCount -- number of chars to copy - * @param anOffset -- position where copying begins - * @return number of chars copied - */ -PRUint32 Mid(nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) const; + /* + * Copies n characters from this string to given string, + * starting at the given offset. + * + * + * @param aCopy -- Receiving string + * @param aCount -- number of chars to copy + * @param anOffset -- position where copying begins + * @return number of chars copied + */ + PRUint32 Mid(nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) const; -/* - * Copies n characters from this string to given string, - * starting at rightmost char. - * - * - * @param aCopy -- Receiving string - * @param aCount -- number of chars to copy - * @return number of chars copied - */ -PRUint32 Right(nsString& aCopy,PRInt32 aCount) const; + /* + * Copies n characters from this string to given string, + * starting at rightmost char. + * + * + * @param aCopy -- Receiving string + * @param aCount -- number of chars to copy + * @return number of chars copied + */ + PRUint32 Right(nsString& aCopy,PRInt32 aCount) const; -/* - * This method inserts n chars from given string into this - * string at str[anOffset]. - * - * @param aCopy -- String to be inserted into this - * @param anOffset -- insertion position within this str - * @param aCount -- number of chars to be copied from aCopy - * @return number of chars inserted into this. - */ -nsString& Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1); + /* + * This method inserts n chars from given string into this + * string at str[anOffset]. + * + * @param aCopy -- String to be inserted into this + * @param anOffset -- insertion position within this str + * @param aCount -- number of chars to be copied from aCopy + * @return number of chars inserted into this. + */ + nsString& Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1); -/** - * Insert a given string into this string at - * a specified offset. - * - * @param aString* to be inserted into this string - * @param anOffset is insert pos in str - * @return the number of chars inserted into this string - */ -nsString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1); -nsString& Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1); + /** + * Insert a given string into this string at + * a specified offset. + * + * @param aString* to be inserted into this string + * @param anOffset is insert pos in str + * @return the number of chars inserted into this string + */ + nsString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1); + nsString& Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1); -/** - * Insert a single char into this string at - * a specified offset. - * - * @param character to be inserted into this string - * @param anOffset is insert pos in str - * @return the number of chars inserted into this string - */ -//nsString& Insert(char aChar,PRUint32 anOffset); -nsString& Insert(PRUnichar aChar,PRUint32 anOffset); + /** + * Insert a single char into this string at + * a specified offset. + * + * @param character to be inserted into this string + * @param anOffset is insert pos in str + * @return the number of chars inserted into this string + */ + //nsString& Insert(char aChar,PRUint32 anOffset); + nsString& Insert(PRUnichar aChar,PRUint32 anOffset); -/* - * This method is used to cut characters in this string - * starting at anOffset, continuing for aCount chars. - * - * @param anOffset -- start pos for cut operation - * @param aCount -- number of chars to be cut - * @return *this - */ -nsString& Cut(PRUint32 anOffset,PRInt32 aCount); + /* + * This method is used to cut characters in this string + * starting at anOffset, continuing for aCount chars. + * + * @param anOffset -- start pos for cut operation + * @param aCount -- number of chars to be cut + * @return *this + */ + nsString& Cut(PRUint32 anOffset,PRInt32 aCount); -/********************************************************************** - Searching methods... - *********************************************************************/ + /********************************************************************** + Searching methods... + *********************************************************************/ -/** - * Search for given character within this string. - * This method does so by using a binary search, - * so your string HAD BETTER BE ORDERED! - * - * @param aChar is the unicode char to be found - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 BinarySearch(PRUnichar aChar) const; + /** + * Search for given character within this string. + * This method does so by using a binary search, + * so your string HAD BETTER BE ORDERED! + * + * @param aChar is the unicode char to be found + * @return offset in string, or -1 (kNotFound) + */ + PRInt32 BinarySearch(PRUnichar aChar) const; -/** - * Search for given substring within this string - * - * @param aString is substring to be sought in this - * @param aIgnoreCase selects case sensitivity - * @param anOffset tells us where in this strig to start searching - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + /** + * Search for given substring within this string + * + * @param aString is substring to be sought in this + * @param aIgnoreCase selects case sensitivity + * @param anOffset tells us where in this strig to start searching + * @return offset in string, or -1 (kNotFound) + */ + PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -/** - * Search for given char within this string - * - * @param aString is substring to be sought in this - * @param anOffset tells us where in this strig to start searching - * @param aIgnoreCase selects case sensitivity - * @return find pos in string, or -1 (kNotFound) - */ -//PRInt32 Find(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const; -PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + /** + * Search for given char within this string + * + * @param aString is substring to be sought in this + * @param anOffset tells us where in this strig to start searching + * @param aIgnoreCase selects case sensitivity + * @return find pos in string, or -1 (kNotFound) + */ + //PRInt32 Find(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const; + PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -/** - * This method searches this string for the first character - * found in the given charset - * @param aString contains set of chars to be found - * @param anOffset tells us where to start searching in this - * @return -1 if not found, else the offset in this - */ -PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const; -PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; -PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; + /** + * This method searches this string for the first character + * found in the given charset + * @param aString contains set of chars to be found + * @param anOffset tells us where to start searching in this + * @return -1 if not found, else the offset in this + */ + PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const; + PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; + PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; -/** - * This methods scans the string backwards, looking for the given string - * @param aString is substring to be sought in this - * @param aIgnoreCase tells us whether or not to do caseless compare - * @param anOffset tells us where in this strig to start searching (counting from left) - */ -PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + /** + * This methods scans the string backwards, looking for the given string + * @param aString is substring to be sought in this + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this strig to start searching (counting from left) + */ + PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -/** - * Search for given char within this string - * - * @param aString is substring to be sought in this - * @param anOffset tells us where in this strig to start searching (counting from left) - * @param aIgnoreCase selects case sensitivity - * @return find pos in string, or -1 (kNotFound) - */ -//PRInt32 RFind(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const; -PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + /** + * Search for given char within this string + * + * @param aString is substring to be sought in this + * @param anOffset tells us where in this strig to start searching (counting from left) + * @param aIgnoreCase selects case sensitivity + * @return find pos in string, or -1 (kNotFound) + */ + //PRInt32 RFind(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const; + PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -/** - * This method searches this string for the last character - * found in the given string - * @param aString contains set of chars to be found - * @param anOffset tells us where in this strig to start searching (counting from left) - * @return -1 if not found, else the offset in this - */ -PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const; -PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; -PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; + /** + * This method searches this string for the last character + * found in the given string + * @param aString contains set of chars to be found + * @param anOffset tells us where in this strig to start searching (counting from left) + * @return -1 if not found, else the offset in this + */ + PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const; + PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; + PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; -/********************************************************************** - Comparison methods... - *********************************************************************/ + /********************************************************************** + Comparison methods... + *********************************************************************/ -/** - * Compares a given string type to this string. - * @update gess 7/27/98 - * @param S is the string to be compared - * @param aIgnoreCase tells us how to treat case - * @param aCount tells us how many chars to compare - * @return -1,0,1 - */ -virtual PRInt32 Compare(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + /** + * Compares a given string type to this string. + * @update gess 7/27/98 + * @param S is the string to be compared + * @param aIgnoreCase tells us how to treat case + * @param aCount tells us how many chars to compare + * @return -1,0,1 + */ + virtual PRInt32 Compare(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -/** - * These methods compare a given string type to this one - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator==(const nsString &aString) const; -PRBool operator==(const nsStr &aString) const; -PRBool operator==(const char *aString) const; -PRBool operator==(const PRUnichar* aString) const; + /** + * These methods compare a given string type to this one + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator==(const nsString &aString) const; + PRBool operator==(const nsStr &aString) const; + PRBool operator==(const char *aString) const; + PRBool operator==(const PRUnichar* aString) const; -/** - * These methods perform a !compare of a given string type to this - * @param aString is the string to be compared to this - * @return TRUE - */ -PRBool operator!=(const nsString &aString) const; -PRBool operator!=(const nsStr &aString) const; -PRBool operator!=(const char* aString) const; -PRBool operator!=(const PRUnichar* aString) const; + /** + * These methods perform a !compare of a given string type to this + * @param aString is the string to be compared to this + * @return TRUE + */ + PRBool operator!=(const nsString &aString) const; + PRBool operator!=(const nsStr &aString) const; + PRBool operator!=(const char* aString) const; + PRBool operator!=(const PRUnichar* aString) const; -/** - * These methods test if a given string is < than this - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator<(const nsString &aString) const; -PRBool operator<(const nsStr &aString) const; -PRBool operator<(const char* aString) const; -PRBool operator<(const PRUnichar* aString) const; + /** + * These methods test if a given string is < than this + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator<(const nsString &aString) const; + PRBool operator<(const nsStr &aString) const; + PRBool operator<(const char* aString) const; + PRBool operator<(const PRUnichar* aString) const; -/** - * These methods test if a given string is > than this - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator>(const nsString &aString) const; -PRBool operator>(const nsStr &S) const; -PRBool operator>(const char* aString) const; -PRBool operator>(const PRUnichar* aString) const; + /** + * These methods test if a given string is > than this + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator>(const nsString &aString) const; + PRBool operator>(const nsStr &S) const; + PRBool operator>(const char* aString) const; + PRBool operator>(const PRUnichar* aString) const; -/** - * These methods test if a given string is <= than this - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator<=(const nsString &aString) const; -PRBool operator<=(const nsStr &S) const; -PRBool operator<=(const char* aString) const; -PRBool operator<=(const PRUnichar* aString) const; + /** + * These methods test if a given string is <= than this + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator<=(const nsString &aString) const; + PRBool operator<=(const nsStr &S) const; + PRBool operator<=(const char* aString) const; + PRBool operator<=(const PRUnichar* aString) const; -/** - * These methods test if a given string is >= than this - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator>=(const nsString &aString) const; -PRBool operator>=(const nsStr &S) const; -PRBool operator>=(const char* aString) const; -PRBool operator>=(const PRUnichar* aString) const; + /** + * These methods test if a given string is >= than this + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator>=(const nsString &aString) const; + PRBool operator>=(const nsStr &S) const; + PRBool operator>=(const char* aString) const; + PRBool operator>=(const PRUnichar* aString) const; -/** - * Compare this to given string; note that we compare full strings here. - * The optional length argument just lets us know how long the given string is. - * If you provide a length, it is compared to length of this string as an - * optimization. - * - * @param aString -- the string to compare to this - * @param aCount -- number of chars to be compared. - * @return TRUE if equal - */ -PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const; -PRBool Equals(const PRUnichar* s1, const PRUnichar* s2,PRBool aIgnoreCase=PR_FALSE) const; + /** + * Compare this to given string; note that we compare full strings here. + * The optional length argument just lets us know how long the given string is. + * If you provide a length, it is compared to length of this string as an + * optimization. + * + * @param aString -- the string to compare to this + * @param aCount -- number of chars to be compared. + * @return TRUE if equal + */ + PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const; + PRBool Equals(const PRUnichar* s1, const PRUnichar* s2,PRBool aIgnoreCase=PR_FALSE) const; -PRBool EqualsIgnoreCase(const nsString& aString) const; -PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const; -PRBool EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const; -PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const; + PRBool EqualsIgnoreCase(const nsString& aString) const; + PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const; + PRBool EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const; + PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const; -/** - * Determine if given buffer is plain ascii - * - * @param aBuffer -- if null, then we test *this, otherwise we test given buffer - * @return TRUE if is all ascii chars or if strlen==0 - */ -PRBool IsASCII(const PRUnichar* aBuffer=0); + /** + * Determine if given buffer is plain ascii + * + * @param aBuffer -- if null, then we test *this, otherwise we test given buffer + * @return TRUE if is all ascii chars or if strlen==0 + */ + PRBool IsASCII(const PRUnichar* aBuffer=0); -/** - * Determine if given char is a valid space character - * - * @param aChar is character to be tested - * @return TRUE if is valid space char - */ -static PRBool IsSpace(PRUnichar ch); + /** + * Determine if given char is a valid space character + * + * @param aChar is character to be tested + * @return TRUE if is valid space char + */ + static PRBool IsSpace(PRUnichar ch); -/** - * Determine if given char in valid alpha range - * - * @param aChar is character to be tested - * @return TRUE if in alpha range - */ -static PRBool IsAlpha(PRUnichar ch); + /** + * Determine if given char in valid alpha range + * + * @param aChar is character to be tested + * @return TRUE if in alpha range + */ + static PRBool IsAlpha(PRUnichar ch); -/** - * Determine if given char is valid digit - * - * @param aChar is character to be tested - * @return TRUE if char is a valid digit - */ -static PRBool IsDigit(PRUnichar ch); + /** + * Determine if given char is valid digit + * + * @param aChar is character to be tested + * @return TRUE if char is a valid digit + */ + static PRBool IsDigit(PRUnichar ch); -static void Recycle(nsString* aString); -static nsString* CreateString(void); - - - nsIMemoryAgent* mAgent; + static void Recycle(nsString* aString); + static nsString* CreateString(void); }; diff --git a/mozilla/xpcom/ds/bufferRoutines.h b/mozilla/xpcom/ds/bufferRoutines.h index 1b3cbde84ba..cb9c77a00d0 100644 --- a/mozilla/xpcom/ds/bufferRoutines.h +++ b/mozilla/xpcom/ds/bufferRoutines.h @@ -249,8 +249,6 @@ CopyChars gCopyChars[2][2]={ * @return index of pos if found, else -1 (kNotFound) */ inline PRInt32 FindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase) { - PRInt32 theIndex=0; - PRInt32 theLength=(PRInt32)aLength; if(aIgnoreCase) { char theChar=(char)nsCRT::ToUpper(aChar); @@ -285,8 +283,6 @@ inline PRInt32 FindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,co * @return index of pos if found, else -1 (kNotFound) */ inline PRInt32 FindChar2(const char* aDest,PRUint32 aLength,PRUint32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase) { - PRInt32 theIndex=0; - PRInt32 theLength=(PRInt32)aLength; const PRUnichar* root=(PRUnichar*)aDest; const PRUnichar* ptr=root+(anOffset-1); const PRUnichar* last=root+aLength; diff --git a/mozilla/xpcom/ds/nsStr.cpp b/mozilla/xpcom/ds/nsStr.cpp index c34f2cdd7b7..5f53dbcc357 100644 --- a/mozilla/xpcom/ds/nsStr.cpp +++ b/mozilla/xpcom/ds/nsStr.cpp @@ -69,16 +69,6 @@ void nsStr::Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 a aDest.mOwnsBuffer=aOwnsBuffer; } -/** - * - * @update gess10/30/98 - * @param - * @return - */ -nsIMemoryAgent* GetDefaultAgent(void){ - static nsMemoryAgent gDefaultAgent; - return (nsIMemoryAgent*)&gDefaultAgent; -} /** * This member destroys the memory buffer owned by an nsStr object (if it actually owns it) @@ -86,17 +76,9 @@ nsIMemoryAgent* GetDefaultAgent(void){ * @param * @return */ -void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) { +void nsStr::Destroy(nsStr& aDest) { if((aDest.mStr) && (aDest.mStr!=(char*)gCommonEmptyBuffer)) { - if(!anAgent) - anAgent=GetDefaultAgent(); - - if(anAgent) { - anAgent->Free(aDest); - } - else{ - printf("%s\n","Leak occured in nsStr."); - } + Free(aDest); } } @@ -108,11 +90,10 @@ void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) { * @param aNewLength -- new capacity of string in charSize units * @return void */ -PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent) { +PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength) { PRBool result=PR_TRUE; if(aNewLength>aString.mCapacity) { - nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent(); - result=theAgent->Realloc(aString,aNewLength); + result=Realloc(aString,aNewLength); if(aString.mStr) AddNullTerminator(aString); } @@ -126,20 +107,18 @@ PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* * @param aNewLength -- new capacity of string in charSize units * @return void */ -PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAgent) { +PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength) { PRBool result=PR_TRUE; if(aNewLength>aDest.mCapacity) { nsStr theTempStr; nsStr::Initialize(theTempStr,aDest.mCharSize); - nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent(); - - result=EnsureCapacity(theTempStr,aNewLength,theAgent); + result=EnsureCapacity(theTempStr,aNewLength); if(result) { if(aDest.mLength) { - Append(theTempStr,aDest,0,aDest.mLength,theAgent); + Append(theTempStr,aDest,0,aDest.mLength); } - theAgent->Free(aDest); + Free(aDest); aDest.mStr = theTempStr.mStr; theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole... aDest.mLength=theTempStr.mLength; @@ -157,10 +136,10 @@ PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAg * @param aSource is where chars are copied from * @param aCount is the number of chars copied from aSource */ -void nsStr::Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){ +void nsStr::Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount){ if(&aDest!=&aSource){ - Truncate(aDest,0,anAgent); - Append(aDest,aSource,anOffset,aCount,anAgent); + Truncate(aDest,0); + Append(aDest,aSource,anOffset,aCount); } } @@ -172,7 +151,7 @@ void nsStr::Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 a * @param aSource is where char are copied from * @aCount is the number of bytes to be copied */ -void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){ +void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount){ if(anOffset aDest.mCapacity) { - isBigEnough=GrowCapacity(aDest,aDest.mLength+theLength,anAgent); + isBigEnough=GrowCapacity(aDest,aDest.mLength+theLength); } if(isBigEnough) { @@ -204,7 +183,7 @@ void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 a * @param aSrcOffset is where in aSource chars are copied from * @param aCount is the number of chars from aSource to be inserted into aDest */ -void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){ +void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount){ //there are a few cases for insert: // 1. You're inserting chars into an empty string (assign) // 2. You're inserting onto the end of a string (append) @@ -223,22 +202,21 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin nsStr theTempStr; nsStr::Initialize(theTempStr,aDest.mCharSize); - nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent(); - PRBool isBigEnough=EnsureCapacity(theTempStr,aDest.mLength+theLength,theAgent); //grow the temp buffer to the right size + PRBool isBigEnough=EnsureCapacity(theTempStr,aDest.mLength+theLength); //grow the temp buffer to the right size if(isBigEnough) { if(aDestOffset) { - Append(theTempStr,aDest,0,aDestOffset,theAgent); //first copy leftmost data... + Append(theTempStr,aDest,0,aDestOffset); //first copy leftmost data... } - Append(theTempStr,aSource,0,aSource.mLength,theAgent); //next copy inserted (new) data + Append(theTempStr,aSource,0,aSource.mLength); //next copy inserted (new) data PRUint32 theRemains=aDest.mLength-aDestOffset; if(theRemains) { - Append(theTempStr,aDest,aDestOffset,theRemains,theAgent); //next copy rightmost data + Append(theTempStr,aDest,aDestOffset,theRemains); //next copy rightmost data } - theAgent->Free(aDest); + Free(aDest); aDest.mStr = theTempStr.mStr; theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole... aDest.mCapacity=theTempStr.mCapacity; @@ -262,9 +240,9 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin }//if //else nothing to do! } - else Append(aDest,aSource,0,aCount,anAgent); + else Append(aDest,aSource,0,aCount); } - else Append(aDest,aSource,0,aCount,anAgent); + else Append(aDest,aSource,0,aCount); } } @@ -276,7 +254,7 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin * @param aDestOffset is where in aDest deletion is to occur * @param aCount is the number of chars to be deleted in aDest */ -void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAgent* anAgent){ +void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount){ if(aDestOffset //---------------------------------------------------------------------------------------- @@ -177,8 +178,6 @@ const PRInt32 kDefaultStringSize = 64; const PRInt32 kNotFound = -1; -class nsIMemoryAgent; - //---------------------------------------------------------------------------------------- class NS_COM CBufDescriptor { @@ -228,7 +227,7 @@ struct NS_COM nsStr { * @param aString is the nsStr to be manipulated * @param anAgent is the allocator to be used to the nsStr */ - static void Destroy(nsStr& aDest,nsIMemoryAgent* anAgent=0); + static void Destroy(nsStr& aDest); /** * These methods are where memory allocation/reallocation occur. @@ -238,8 +237,8 @@ struct NS_COM nsStr { * @param anAgent is the allocator to be used on the nsStr * @return */ - static PRBool EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0); - static PRBool GrowCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0); + static PRBool EnsureCapacity(nsStr& aString,PRUint32 aNewLength); + static PRBool GrowCapacity(nsStr& aString,PRUint32 aNewLength); /** * These methods are used to append content to the given nsStr @@ -251,7 +250,7 @@ struct NS_COM nsStr { * @param aCount tells us the (max) # of chars to copy * @param anAgent is the allocator to be used for alloc/free operations */ - static void Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0); + static void Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount); /** * These methods are used to assign contents of a source string to dest string @@ -263,7 +262,7 @@ struct NS_COM nsStr { * @param aCount tells us the (max) # of chars to copy * @param anAgent is the allocator to be used for alloc/free operations */ - static void Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0); + static void Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount); /** * These methods are used to insert content from source string to the dest nsStr @@ -276,7 +275,7 @@ struct NS_COM nsStr { * @param aCount tells us the (max) # of chars to insert * @param anAgent is the allocator to be used for alloc/free operations */ - static void Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0); + static void Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount); /** * This method deletes chars from the given str. @@ -288,7 +287,7 @@ struct NS_COM nsStr { * @param aCount tells us the (max) # of chars to delete * @param anAgent is the allocator to be used for alloc/free operations */ - static void Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAgent* anAgent=0); + static void Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount); /** * This method is used to truncate the given string. @@ -301,7 +300,7 @@ struct NS_COM nsStr { * @param aSrcOffset tells us where in source to start copying * @param anAgent is the allocator to be used for alloc/free operations */ - static void Truncate(nsStr& aDest,PRUint32 aDestOffset,nsIMemoryAgent* anAgent=0); + static void Truncate(nsStr& aDest,PRUint32 aDestOffset); /** * This method is used to perform a case conversion on the given string @@ -388,6 +387,12 @@ struct NS_COM nsStr { char* mStr; PRUnichar* mUStr; }; + +private: + static PRBool Alloc(nsStr& aString,PRUint32 aCount); + static PRBool Realloc(nsStr& aString,PRUint32 aCount); + static PRBool Free(nsStr& aString); + }; /************************************************************** @@ -430,74 +435,6 @@ inline PRUnichar GetCharAt(const nsStr& aDest,PRUint32 anIndex){ return 0; } -//---------------------------------------------------------------------------------------- - -class nsIMemoryAgent { -public: - virtual PRBool Alloc(nsStr& aString,PRUint32 aCount)=0; - virtual PRBool Realloc(nsStr& aString,PRUint32 aCount)=0; - virtual PRBool Free(nsStr& aString)=0; -}; - -class nsMemoryAgent : public nsIMemoryAgent { -public: - - virtual PRBool Alloc(nsStr& aDest,PRUint32 aCount) { - - static int mAllocCount=0; - mAllocCount++; - - //we're given the acount value in charunits; now scale up to next multiple. - PRUint32 theNewCapacity=kDefaultStringSize; - while(theNewCapacitymCapacity) { - GrowCapacity(*this,aLength,mAgent); + GrowCapacity(*this,aLength); } AddNullTerminator(*this); } @@ -262,7 +262,7 @@ PRBool nsCString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){ */ nsSubsumeCStr nsCString::operator+(const nsCString& aString){ nsCString temp(*this); //make a temp string the same size as this... - nsStr::Append(temp,aString,0,aString.mLength,mAgent); + nsStr::Append(temp,aString,0,aString.mLength); return nsSubsumeCStr(temp); } @@ -613,11 +613,19 @@ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) { } theDigit=(theChar-'A')+10; } + else if((theChar>='a') && (theChar<='f')) { + if(10==aRadix){ + *anErrorCode=NS_ERROR_ILLEGAL_VALUE; + result=0; + break; + } + theDigit=(theChar-'a')+10; + } else if('-'==theChar) { result=-result; break; } - else if(('+'==theChar) || (' '==theChar)) { //stop in a good state if you see this... + else if(('+'==theChar) || (' '==theChar) || ('X'==theChar) || ('x'==theChar)) { //stop in a good state if you see this... break; } else { @@ -634,6 +642,7 @@ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) { return result; } + /** * Call this method to extract the rightmost numeric value from the given * 1-byte input string, and simultaneously determine the radix. @@ -645,56 +654,56 @@ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) { * @param aRadix (an out parm) tells the caller what base we think the string is in. * @return non-zero error code if this string is non-numeric */ -PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) { +static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) { + static const char* validChars="0123456789abcdefABCDEF-+#"; - aString.ToUpperCase(); + const char* cp=aString.GetBuffer(); + PRInt32 result=NS_ERROR_ILLEGAL_VALUE; + if(cp) { - PRInt32 decPt=nsStr::FindChar(aString,'.',PR_TRUE,0); - char* cp = (kNotFound==decPt) ? aString.mStr + aString.mLength-1 : aString.mStr+decPt-1; - - aRadix=kRadixUnknown; //assume for starters... + //begin by skipping over leading chars that shouldn't be part of the number... + + char* to=(char*)cp; + const char* endcp=cp+aString.mLength; + int len=strlen(validChars); - // Skip trailing non-numeric... - while (cp >= aString.mStr) { - if((*cp>='0') && (*cp<='9')){ - if(kRadixUnknown==aRadix) - aRadix=kRadix10; - break; + while(cp='A') && (*cp<='F')) { - aRadix=16; - break; - } - cp--; + + while(cp='0') && (theChar<='9')) { + *to++=theChar; + } + else if((theChar>='A') && (theChar<='F')) { + aRadix=16; + *to++=theChar; + } + else if('X'==theChar){ + if('-'==aString.mStr[0]) + to=&aString.mStr[1]; + else to=aString.mStr; + aRadix=16; + //root=cp; + } + else if('-'==theChar) { + *to++=theChar; + } + else if(('#'==theChar) || ('+'==theChar)){ + //just skip this char... + } + else break; + cp++; + } + aString.Truncate(to-aString.mStr); + result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; } - aString.Truncate(cp-aString.mStr+1); - - //ok, now scan through chars until you find the start of this number... - //we delimit the number by the presence of: +,-,#,X - - // Skip trailing non-numeric... - cp++; - while (--cp >= aString.mStr) { - if((*cp>='0') && (*cp<='9')){ - continue; - } - else if((*cp>='A') && (*cp<='F')) { - continue; - } - else if((*cp=='-') || (*cp=='+')){ - break; - } - else { - if(('#'==(*cp)) || ('X'==(*cp))) - aRadix=kRadix16; - cp++; //move back by one - break; - } - } - if(cp>aString.mStr) - aString.Cut(0,cp-aString.mStr); - PRInt32 result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; - return result; } @@ -726,11 +735,12 @@ PRUint32 nsCString::DetermineRadix(void) { PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const { //copy chars to local buffer -- step down from 2 bytes to 1 if necessary... + PRInt32 result=0; nsCAutoString theString(*this); PRUint32 theRadix=aRadix; - PRInt32 result=0; - + *anErrorCode=GetNumericSubstring(theString,theRadix); //we actually don't use this radix; use given radix instead + if(NS_OK==*anErrorCode){ if(kAutoDetect==aRadix) aRadix=theRadix; @@ -755,13 +765,13 @@ PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const { */ nsCString& nsCString::Assign(const nsStr& aString,PRInt32 aCount) { if(this!=&aString){ - nsStr::Truncate(*this,0,0); + nsStr::Truncate(*this,0); if(aCount<0) aCount=aString.mLength; else aCount=MinInt(aCount,aString.mLength); - nsStr::Assign(*this,aString,0,aCount,mAgent); + nsStr::Assign(*this,aString,0,aCount); } return *this; } @@ -773,7 +783,7 @@ nsCString& nsCString::Assign(const nsStr& aString,PRInt32 aCount) { * @return this */ nsCString& nsCString::Assign(const char* aCString,PRInt32 aCount) { - nsStr::Truncate(*this,0,0); + nsStr::Truncate(*this,0); if(aCString){ Append(aCString,aCount); } @@ -787,7 +797,7 @@ nsCString& nsCString::Assign(const char* aCString,PRInt32 aCount) { * @return this */ nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) { - nsStr::Truncate(*this,0,0); + nsStr::Truncate(*this,0); if(aString){ nsStr temp; @@ -806,7 +816,7 @@ nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) { else aCount=temp.mLength=nsCRT::strlen(aString); if(0=1) { - PRInt32 div=theInt/mask1; - if((div) || (!isfirst)) { - buf[charpos++]="0123456789abcdef"[div]; + PRInt32 theDiv=theInt/mask1; + if((theDiv) || (!isfirst)) { + buf[charpos++]="0123456789abcdef"[theDiv]; isfirst=PR_FALSE; } - theInt-=div*mask1; + theInt-=theDiv*mask1; mask1/=aRadix; } return Append(buf); @@ -1001,7 +1028,7 @@ PRUint32 nsCString::Left(nsCString& aDest,PRInt32 aCount) const{ if(aCount<0) aCount=mLength; else aCount=MinInt(aCount,mLength); - nsStr::Assign(aDest,*this,0,aCount,mAgent); + nsStr::Assign(aDest,*this,0,aCount); return aDest.mLength; } @@ -1018,7 +1045,7 @@ PRUint32 nsCString::Mid(nsCString& aDest,PRUint32 anOffset,PRInt32 aCount) const if(aCount<0) aCount=mLength; else aCount=MinInt(aCount,mLength); - nsStr::Assign(aDest,*this,anOffset,aCount,mAgent); + nsStr::Assign(aDest,*this,anOffset,aCount); return aDest.mLength; } @@ -1048,7 +1075,7 @@ PRUint32 nsCString::Right(nsCString& aDest,PRInt32 aCount) const{ */ nsCString& nsCString::Insert(const nsCString& aString,PRUint32 anOffset,PRInt32 aCount) { - nsStr::Insert(*this,anOffset,aString,0,aCount,mAgent); + nsStr::Insert(*this,anOffset,aString,0,aCount); return *this; } @@ -1079,7 +1106,7 @@ nsCString& nsCString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCou else aCount=temp.mLength=nsCRT::strlen(aCString); if(temp.mLength && (0mAgent=&theAgent; delete aString; } return 0; @@ -1722,7 +1747,6 @@ NS_COM int fputs(const nsCString& aString, FILE* out) */ nsCAutoString::nsCAutoString() : nsCString(){ nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); - mAgent=0; AddNullTerminator(*this); } @@ -1732,7 +1756,6 @@ nsCAutoString::nsCAutoString() : nsCString(){ */ nsCAutoString::nsCAutoString(const nsCAutoString& aString) : nsCString() { nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); - mAgent=0; AddNullTerminator(*this); Append(aString); } @@ -1744,7 +1767,6 @@ nsCAutoString::nsCAutoString(const nsCAutoString& aString) : nsCString() { */ nsCAutoString::nsCAutoString(const char* aCString,PRInt32 aLength) : nsCString() { nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); - mAgent=0; AddNullTerminator(*this); Append(aCString,aLength); } @@ -1754,7 +1776,6 @@ nsCAutoString::nsCAutoString(const char* aCString,PRInt32 aLength) : nsCString() * @param aBuffer -- descibes external buffer */ nsCAutoString::nsCAutoString(const CBufDescriptor& aBuffer) : nsCString() { - mAgent=0; if(!aBuffer.mBuffer) { nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); } @@ -1770,7 +1791,6 @@ nsCAutoString::nsCAutoString(const CBufDescriptor& aBuffer) : nsCString() { * @param aString is a ptr to a unistr */ nsCAutoString::nsCAutoString(const PRUnichar* aString,PRInt32 aLength) : nsCString() { - mAgent=0; nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); AddNullTerminator(*this); Append(aString,aLength); @@ -1781,7 +1801,6 @@ nsCAutoString::nsCAutoString(const PRUnichar* aString,PRInt32 aLength) : nsCStri * @param */ nsCAutoString::nsCAutoString(const nsStr& aString) : nsCString() { - mAgent=0; nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); AddNullTerminator(*this); Append(aString); @@ -1794,7 +1813,6 @@ nsCAutoString::nsCAutoString(const nsStr& aString) : nsCString() { * @param */ nsCAutoString::nsCAutoString(PRUnichar aChar) : nsCString(){ - mAgent=0; nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); AddNullTerminator(*this); Append(aChar); @@ -1807,12 +1825,10 @@ nsCAutoString::nsCAutoString(PRUnichar aChar) : nsCString(){ */ #ifdef AIX nsCAutoString::nsCAutoString(const nsSubsumeCStr& aSubsumeStr) :nsCString() { - mAgent=0; nsSubsumeCStr temp(aSubsumeStr); // a temp is needed for the AIX compiler CSubsume(*this,temp); #else nsCAutoString::nsCAutoString( nsSubsumeCStr& aSubsumeStr) :nsCString() { - mAgent=0; CSubsume(*this,aSubsumeStr); #endif // AIX } diff --git a/mozilla/xpcom/ds/nsString.h b/mozilla/xpcom/ds/nsString.h index 05205d9a818..90db90305b4 100644 --- a/mozilla/xpcom/ds/nsString.h +++ b/mozilla/xpcom/ds/nsString.h @@ -46,632 +46,633 @@ class NS_COM nsSubsumeCStr; class NS_COM nsCString : public nsStr { - public: +public: -/** - * Default constructor. - */ -nsCString(nsIMemoryAgent* anAgent=0); - - -/** - * This constructor accepts an isolatin string - * @param aCString is a ptr to a 1-byte cstr - */ -nsCString(const char* aCString,PRInt32 aLength=-1,nsIMemoryAgent* anAgent=0); - -/** - * This constructor accepts a unichar string - * @param aCString is a ptr to a 2-byte cstr - */ -nsCString(const PRUnichar* aString,PRInt32 aLength=-1,nsIMemoryAgent* anAgent=0); - -/** - * This is a copy constructor that accepts an nsStr - * @param reference to another nsCString - */ -nsCString(const nsStr&,nsIMemoryAgent* anAgent=0); - -/** - * This is our copy constructor - * @param reference to another nsCString - */ -nsCString(const nsCString& aString); - -/** - * This constructor takes a subsumestr - * @param reference to subsumestr - */ -nsCString(nsSubsumeCStr& aSubsumeStr); - -/** - * Destructor - * - */ -virtual ~nsCString(); - -/** - * Retrieve the length of this string - * @return string length - */ -inline PRInt32 Length() const { return (PRInt32)mLength; } - -/** - * Retrieve the size of this string - * @return string length - */ -virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const; - - -/** - * Call this method if you want to force a different string capacity - * @update gess7/30/98 - * @param aLength -- contains new length for mStr - * @return - */ -void SetLength(PRUint32 aLength) { - Truncate(aLength); -} - -/** - * Sets the new length of the string. - * @param aLength is new string length. - * @return nada - */ -void SetCapacity(PRUint32 aLength); -/** - * This method truncates this string to given length. - * - * @param anIndex -- new length of string - * @return nada - */ -void Truncate(PRInt32 anIndex=0); - - -/** - * Determine whether or not the characters in this - * string are in sorted order. - * - * @return TRUE if ordered. - */ -PRBool IsOrdered(void) const; - - -/** - * Determine whether or not this string has a length of 0 - * - * @return TRUE if empty. - */ -PRBool IsEmpty(void) const { - return PRBool(0==mLength); -} - -/********************************************************************** - Accessor methods... - *********************************************************************/ - -const char* GetBuffer(void) const; - - - /** - * Get nth character. + /** + * Default constructor. */ -PRUnichar operator[](PRUint32 anIndex) const; -PRUnichar CharAt(PRUint32 anIndex) const; -PRUnichar First(void) const; -PRUnichar Last(void) const; + nsCString(); -PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex); + /** + * This constructor accepts an isolatin string + * @param aCString is a ptr to a 1-byte cstr + */ + nsCString(const char* aCString,PRInt32 aLength=-1); + + /** + * This constructor accepts a unichar string + * @param aCString is a ptr to a 2-byte cstr + */ + nsCString(const PRUnichar* aString,PRInt32 aLength=-1); + + /** + * This is a copy constructor that accepts an nsStr + * @param reference to another nsCString + */ + nsCString(const nsStr&); + + /** + * This is our copy constructor + * @param reference to another nsCString + */ + nsCString(const nsCString& aString); + + /** + * This constructor takes a subsumestr + * @param reference to subsumestr + */ + nsCString(nsSubsumeCStr& aSubsumeStr); + + /** + * Destructor + * + */ + virtual ~nsCString(); + + /** + * Retrieve the length of this string + * @return string length + */ + inline PRInt32 Length() const { return (PRInt32)mLength; } + + /** + * Retrieve the size of this string + * @return string length + */ + virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const; -/********************************************************************** - String creation methods... - *********************************************************************/ + /** + * Call this method if you want to force a different string capacity + * @update gess7/30/98 + * @param aLength -- contains new length for mStr + * @return + */ + void SetLength(PRUint32 aLength) { + Truncate(aLength); + } -/** - * Create a new string by appending given string to this - * @param aString -- 2nd string to be appended - * @return new string - */ -nsSubsumeCStr operator+(const nsCString& aString); - -/** - * create a new string by adding this to the given char*. - * @param aCString is a ptr to cstring to be added to this - * @return newly created string - */ -nsSubsumeCStr operator+(const char* aCString); + /** + * Sets the new length of the string. + * @param aLength is new string length. + * @return nada + */ + void SetCapacity(PRUint32 aLength); + /** + * This method truncates this string to given length. + * + * @param anIndex -- new length of string + * @return nada + */ + void Truncate(PRInt32 anIndex=0); -/** - * create a new string by adding this to the given char. - * @param aChar is a char to be added to this - * @return newly created string - */ -nsSubsumeCStr operator+(PRUnichar aChar); -nsSubsumeCStr operator+(char aChar); + /** + * Determine whether or not the characters in this + * string are in sorted order. + * + * @return TRUE if ordered. + */ + PRBool IsOrdered(void) const; -/********************************************************************** - Lexomorphic transforms... - *********************************************************************/ + /** + * Determine whether or not this string has a length of 0 + * + * @return TRUE if empty. + */ + PRBool IsEmpty(void) const { + return PRBool(0==mLength); + } -/** - * Converts chars in this to lowercase - * @update gess 7/27/98 - */ -void ToLowerCase(); + /********************************************************************** + Accessor methods... + *********************************************************************/ -/** - * Converts chars in this to lowercase, and - * stores them in aOut - * @update gess 7/27/98 - * @param aOut is a string to contain result - */ -void ToLowerCase(nsCString& aString) const; - -/** - * Converts chars in this to uppercase - * @update gess 7/27/98 - */ -void ToUpperCase(); - -/** - * Converts chars in this to lowercase, and - * stores them in a given output string - * @update gess 7/27/98 - * @param aOut is a string to contain result - */ -void ToUpperCase(nsCString& aString) const; + /** + * Retrieve const ptr to internal buffer; DO NOT TRY TO FREE IT! + */ + const char* GetBuffer(void) const; -/** - * This method is used to remove all occurances of the - * characters found in aSet from this string. - * - * @param aSet -- characters to be cut from this - * @return *this - */ -nsCString& StripChars(const char* aSet); -nsCString& StripChar(char aChar); + /** + * Get nth character. + */ + PRUnichar operator[](PRUint32 anIndex) const; + PRUnichar CharAt(PRUint32 anIndex) const; + PRUnichar First(void) const; + PRUnichar Last(void) const; -/** - * This method strips whitespace throughout the string - * - * @return this - */ -nsCString& StripWhitespace(); - -/** - * swaps occurence of 1 string for another - * - * @return this - */ -nsCString& ReplaceChar(PRUnichar aOldChar,PRUnichar aNewChar); -nsCString& ReplaceChar(const char* aSet,PRUnichar aNewChar); - -PRInt32 CountChar(PRUnichar aChar); - -/** - * This method trims characters found in aTrimSet from - * either end of the underlying string. - * - * @param aTrimSet -- contains chars to be trimmed from - * both ends - * @return this - */ -nsCString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); - -/** - * This method strips whitespace from string. - * You can control whether whitespace is yanked from - * start and end of string as well. - * - * @param aEliminateLeading controls stripping of leading ws - * @param aEliminateTrailing controls stripping of trailing ws - * @return this - */ -nsCString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); - -/** - * This method strips whitespace from string. - * You can control whether whitespace is yanked from - * start and end of string as well. - * - * @param aEliminateLeading controls stripping of leading ws - * @param aEliminateTrailing controls stripping of trailing ws - * @return this - */ -nsCString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); - -/********************************************************************** - string conversion methods... - *********************************************************************/ - - operator char*() {return mStr;} - operator const char*() const {return (const char*)mStr;} - -/** - * This method constructs a new nsCString that is a clone - * of this string. - * - */ -nsCString* ToNewString() const; - -/** - * Creates an ISOLatin1 clone of this string - * Note that calls to this method should be matched with calls to Recycle(). - * @return ptr to new isolatin1 string - */ -char* ToNewCString() const; - -/** - * Creates a unicode clone of this string - * Note that calls to this method should be matched with calls to Recycle(). - * @return ptr to new unicode string - */ -PRUnichar* ToNewUnicode() const; - -/** - * Copies data from internal buffer onto given char* buffer - * NOTE: This only copies as many chars as will fit in given buffer (clips) - * @param aBuf is the buffer where data is stored - * @param aBuflength is the max # of chars to move to buffer - * @return ptr to given buffer - */ -char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const; - -/** - * Perform string to float conversion. - * @param aErrorCode will contain error if one occurs - * @return float rep of string value - */ -float ToFloat(PRInt32* aErrorCode) const; - -/** - * Try to derive the radix from the value contained in this string - * @return kRadix10, kRadix16 or kAutoDetect (meaning unknown) - */ -PRUint32 DetermineRadix(void); - -/** - * Perform string to int conversion. - * @param aErrorCode will contain error if one occurs - * @return int rep of string value - */ -PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const; + PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex); -/********************************************************************** - String manipulation methods... - *********************************************************************/ + /********************************************************************** + String creation methods... + *********************************************************************/ -/** - * Functionally equivalent to assign or operator= - * - */ -nsCString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} -nsCString& SetString(const nsStr& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} + /** + * Create a new string by appending given string to this + * @param aString -- 2nd string to be appended + * @return new string + */ + nsSubsumeCStr operator+(const nsCString& aString); -/** - * assign given string to this string - * @param aStr: buffer to be assigned to this - * @param alength is the length of the given str (or -1) - if you want me to determine its length - * @return this - */ -nsCString& Assign(const nsStr& aString,PRInt32 aCount=-1); -nsCString& Assign(const char* aString,PRInt32 aCount=-1); -nsCString& Assign(const PRUnichar* aString,PRInt32 aCount=-1); -nsCString& Assign(PRUnichar aChar); -nsCString& Assign(char aChar); + /** + * create a new string by adding this to the given char*. + * @param aCString is a ptr to cstring to be added to this + * @return newly created string + */ + nsSubsumeCStr operator+(const char* aCString); -/** - * here come a bunch of assignment operators... - * @param aString: string to be added to this - * @return this - */ -nsCString& operator=(const nsCString& aString) {return Assign(aString);} -nsCString& operator=(const nsStr& aString) {return Assign(aString);} -nsCString& operator=(PRUnichar aChar) {return Assign(aChar);} -nsCString& operator=(char aChar) {return Assign(aChar);} -nsCString& operator=(const char* aCString) {return Assign(aCString);} -nsCString& operator=(const PRUnichar* aString) {return Assign(aString);} -#ifdef AIX -nsCString& operator=(const nsSubsumeCStr& aSubsumeString); // AIX requires a const here -#else -nsCString& operator=(nsSubsumeCStr& aSubsumeString); -#endif -/** - * Here's a bunch of methods that append varying types... - * @param various... - * @return this - */ -nsCString& operator+=(const nsCString& aString){return Append(aString,aString.mLength);} -nsCString& operator+=(const char* aCString) {return Append(aCString);} -nsCString& operator+=(PRUnichar aChar){return Append(aChar);} -nsCString& operator+=(char aChar){return Append(aChar);} + /** + * create a new string by adding this to the given char. + * @param aChar is a char to be added to this + * @return newly created string + */ + nsSubsumeCStr operator+(PRUnichar aChar); + nsSubsumeCStr operator+(char aChar); -/* - * Appends n characters from given string to this, - * This version computes the length of your given string - * - * @param aString is the source to be appended to this - * @return number of chars copied - */ -nsCString& Append(const nsCString& aString) {return Append(aString,aString.mLength);} + + /********************************************************************** + Lexomorphic transforms... + *********************************************************************/ + + /** + * Converts chars in this to lowercase + * @update gess 7/27/98 + */ + void ToLowerCase(); + + + /** + * Converts chars in this to lowercase, and + * stores them in aOut + * @update gess 7/27/98 + * @param aOut is a string to contain result + */ + void ToLowerCase(nsCString& aString) const; + + /** + * Converts chars in this to uppercase + * @update gess 7/27/98 + */ + void ToUpperCase(); + + /** + * Converts chars in this to lowercase, and + * stores them in a given output string + * @update gess 7/27/98 + * @param aOut is a string to contain result + */ + void ToUpperCase(nsCString& aString) const; + + + /** + * This method is used to remove all occurances of the + * characters found in aSet from this string. + * + * @param aSet -- characters to be cut from this + * @return *this + */ + nsCString& StripChars(const char* aSet); + nsCString& StripChar(char aChar); + + /** + * This method strips whitespace throughout the string + * + * @return this + */ + nsCString& StripWhitespace(); + + /** + * swaps occurence of 1 string for another + * + * @return this + */ + nsCString& ReplaceChar(PRUnichar aOldChar,PRUnichar aNewChar); + nsCString& ReplaceChar(const char* aSet,PRUnichar aNewChar); + + PRInt32 CountChar(PRUnichar aChar); + + /** + * This method trims characters found in aTrimSet from + * either end of the underlying string. + * + * @param aTrimSet -- contains chars to be trimmed from + * both ends + * @return this + */ + nsCString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + + /** + * This method strips whitespace from string. + * You can control whether whitespace is yanked from + * start and end of string as well. + * + * @param aEliminateLeading controls stripping of leading ws + * @param aEliminateTrailing controls stripping of trailing ws + * @return this + */ + nsCString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + + /** + * This method strips whitespace from string. + * You can control whether whitespace is yanked from + * start and end of string as well. + * + * @param aEliminateLeading controls stripping of leading ws + * @param aEliminateTrailing controls stripping of trailing ws + * @return this + */ + nsCString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + + /********************************************************************** + string conversion methods... + *********************************************************************/ + + operator char*() {return mStr;} + operator const char*() const {return (const char*)mStr;} + + /** + * This method constructs a new nsCString that is a clone + * of this string. + * + */ + nsCString* ToNewString() const; + + /** + * Creates an ISOLatin1 clone of this string + * Note that calls to this method should be matched with calls to Recycle(). + * @return ptr to new isolatin1 string + */ + char* ToNewCString() const; + + /** + * Creates a unicode clone of this string + * Note that calls to this method should be matched with calls to Recycle(). + * @return ptr to new unicode string + */ + PRUnichar* ToNewUnicode() const; + + /** + * Copies data from internal buffer onto given char* buffer + * NOTE: This only copies as many chars as will fit in given buffer (clips) + * @param aBuf is the buffer where data is stored + * @param aBuflength is the max # of chars to move to buffer + * @return ptr to given buffer + */ + char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const; + + /** + * Perform string to float conversion. + * @param aErrorCode will contain error if one occurs + * @return float rep of string value + */ + float ToFloat(PRInt32* aErrorCode) const; + + /** + * Try to derive the radix from the value contained in this string + * @return kRadix10, kRadix16 or kAutoDetect (meaning unknown) + */ + PRUint32 DetermineRadix(void); + + /** + * Perform string to int conversion. + * @param aErrorCode will contain error if one occurs + * @return int rep of string value + */ + PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const; + + + /********************************************************************** + String manipulation methods... + *********************************************************************/ + + /** + * Functionally equivalent to assign or operator= + * + */ + nsCString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} + nsCString& SetString(const nsStr& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} + + /** + * assign given string to this string + * @param aStr: buffer to be assigned to this + * @param alength is the length of the given str (or -1) + if you want me to determine its length + * @return this + */ + nsCString& Assign(const nsStr& aString,PRInt32 aCount=-1); + nsCString& Assign(const char* aString,PRInt32 aCount=-1); + nsCString& Assign(const PRUnichar* aString,PRInt32 aCount=-1); + nsCString& Assign(PRUnichar aChar); + nsCString& Assign(char aChar); + + /** + * here come a bunch of assignment operators... + * @param aString: string to be added to this + * @return this + */ + nsCString& operator=(const nsCString& aString) {return Assign(aString);} + nsCString& operator=(const nsStr& aString) {return Assign(aString);} + nsCString& operator=(PRUnichar aChar) {return Assign(aChar);} + nsCString& operator=(char aChar) {return Assign(aChar);} + nsCString& operator=(const char* aCString) {return Assign(aCString);} + nsCString& operator=(const PRUnichar* aString) {return Assign(aString);} + #ifdef AIX + nsCString& operator=(const nsSubsumeCStr& aSubsumeString); // AIX requires a const here + #else + nsCString& operator=(nsSubsumeCStr& aSubsumeString); + #endif + + /** + * Here's a bunch of methods that append varying types... + * @param various... + * @return this + */ + nsCString& operator+=(const nsCString& aString){return Append(aString,aString.mLength);} + nsCString& operator+=(const char* aCString) {return Append(aCString);} + nsCString& operator+=(PRUnichar aChar){return Append(aChar);} + nsCString& operator+=(char aChar){return Append(aChar);} + + /* + * Appends n characters from given string to this, + * This version computes the length of your given string + * + * @param aString is the source to be appended to this + * @return number of chars copied + */ + nsCString& Append(const nsCString& aString) {return Append(aString,aString.mLength);} -/* - * Appends n characters from given string to this, - * - * @param aString is the source to be appended to this - * @param aCount -- number of chars to copy; -1 tells us to compute the strlen for you - * @return number of chars copied - */ -nsCString& Append(const nsCString& aString,PRInt32 aCount); -nsCString& Append(const char* aString,PRInt32 aCount=-1); -nsCString& Append(PRUnichar aChar); -nsCString& Append(char aChar); -nsCString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16 -nsCString& Append(float aFloat); + /* + * Appends n characters from given string to this, + * + * @param aString is the source to be appended to this + * @param aCount -- number of chars to copy; -1 tells us to compute the strlen for you + * @return number of chars copied + */ + nsCString& Append(const nsCString& aString,PRInt32 aCount); + nsCString& Append(const nsStr& aString,PRInt32 aCount=-1); + nsCString& Append(const char* aString,PRInt32 aCount=-1); + nsCString& Append(PRUnichar aChar); + nsCString& Append(char aChar); + nsCString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16 + nsCString& Append(float aFloat); -/* - * Copies n characters from this string to given string, - * starting at the leftmost offset. - * - * - * @param aCopy -- Receiving string - * @param aCount -- number of chars to copy - * @return number of chars copied - */ -PRUint32 Left(nsCString& aCopy,PRInt32 aCount) const; + /* + * Copies n characters from this string to given string, + * starting at the leftmost offset. + * + * + * @param aCopy -- Receiving string + * @param aCount -- number of chars to copy + * @return number of chars copied + */ + PRUint32 Left(nsCString& aCopy,PRInt32 aCount) const; -/* - * Copies n characters from this string to given string, - * starting at the given offset. - * - * - * @param aCopy -- Receiving string - * @param aCount -- number of chars to copy - * @param anOffset -- position where copying begins - * @return number of chars copied - */ -PRUint32 Mid(nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount) const; + /* + * Copies n characters from this string to given string, + * starting at the given offset. + * + * + * @param aCopy -- Receiving string + * @param aCount -- number of chars to copy + * @param anOffset -- position where copying begins + * @return number of chars copied + */ + PRUint32 Mid(nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount) const; -/* - * Copies n characters from this string to given string, - * starting at rightmost char. - * - * - * @param aCopy -- Receiving string - * @param aCount -- number of chars to copy - * @return number of chars copied - */ -PRUint32 Right(nsCString& aCopy,PRInt32 aCount) const; + /* + * Copies n characters from this string to given string, + * starting at rightmost char. + * + * + * @param aCopy -- Receiving string + * @param aCount -- number of chars to copy + * @return number of chars copied + */ + PRUint32 Right(nsCString& aCopy,PRInt32 aCount) const; -/* - * This method inserts n chars from given string into this - * string at str[anOffset]. - * - * @param aCopy -- String to be inserted into this - * @param anOffset -- insertion position within this str - * @param aCount -- number of chars to be copied from aCopy - * @return number of chars inserted into this. - */ -nsCString& Insert(const nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1); + /* + * This method inserts n chars from given string into this + * string at str[anOffset]. + * + * @param aCopy -- String to be inserted into this + * @param anOffset -- insertion position within this str + * @param aCount -- number of chars to be copied from aCopy + * @return number of chars inserted into this. + */ + nsCString& Insert(const nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1); -/** - * Insert a given string into this string at - * a specified offset. - * - * @param aString* to be inserted into this string - * @param anOffset is insert pos in str - * @return the number of chars inserted into this string - */ -nsCString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1); + /** + * Insert a given string into this string at + * a specified offset. + * + * @param aString* to be inserted into this string + * @param anOffset is insert pos in str + * @return the number of chars inserted into this string + */ + nsCString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1); -/** - * Insert a single char into this string at - * a specified offset. - * - * @param character to be inserted into this string - * @param anOffset is insert pos in str - * @return the number of chars inserted into this string - */ -nsCString& Insert(PRUnichar aChar,PRUint32 anOffset); -nsCString& Insert(char aChar,PRUint32 anOffset); + /** + * Insert a single char into this string at + * a specified offset. + * + * @param character to be inserted into this string + * @param anOffset is insert pos in str + * @return the number of chars inserted into this string + */ + nsCString& Insert(PRUnichar aChar,PRUint32 anOffset); + nsCString& Insert(char aChar,PRUint32 anOffset); -/* - * This method is used to cut characters in this string - * starting at anOffset, continuing for aCount chars. - * - * @param anOffset -- start pos for cut operation - * @param aCount -- number of chars to be cut - * @return *this - */ -nsCString& Cut(PRUint32 anOffset,PRInt32 aCount); + /* + * This method is used to cut characters in this string + * starting at anOffset, continuing for aCount chars. + * + * @param anOffset -- start pos for cut operation + * @param aCount -- number of chars to be cut + * @return *this + */ + nsCString& Cut(PRUint32 anOffset,PRInt32 aCount); -/********************************************************************** - Searching methods... - *********************************************************************/ + /********************************************************************** + Searching methods... + *********************************************************************/ -/** - * Search for given character within this string. - * This method does so by using a binary search, - * so your string HAD BETTER BE ORDERED! - * - * @param aChar is the unicode char to be found - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 BinarySearch(PRUnichar aChar) const; + /** + * Search for given character within this string. + * This method does so by using a binary search, + * so your string HAD BETTER BE ORDERED! + * + * @param aChar is the unicode char to be found + * @return offset in string, or -1 (kNotFound) + */ + PRInt32 BinarySearch(PRUnichar aChar) const; -/** - * Search for given substring within this string - * - * @param aString is substring to be sought in this - * @param aIgnoreCase selects case sensitivity - * @param anOffset tells us where in this strig to start searching - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + /** + * Search for given substring within this string + * + * @param aString is substring to be sought in this + * @param aIgnoreCase selects case sensitivity + * @param anOffset tells us where in this strig to start searching + * @return offset in string, or -1 (kNotFound) + */ + PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -/** - * Search for given char within this string - * - * @param aString is substring to be sought in this - * @param anOffset tells us where in this strig to start searching - * @param aIgnoreCase selects case sensitivity - * @return find pos in string, or -1 (kNotFound) - */ -PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + /** + * Search for given char within this string + * + * @param aString is substring to be sought in this + * @param anOffset tells us where in this strig to start searching + * @param aIgnoreCase selects case sensitivity + * @return find pos in string, or -1 (kNotFound) + */ + PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -/** - * This method searches this string for the first character - * found in the given charset - * @param aString contains set of chars to be found - * @param anOffset tells us where to start searching in this - * @return -1 if not found, else the offset in this - */ -PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const; -PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; -PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; + /** + * This method searches this string for the first character + * found in the given charset + * @param aString contains set of chars to be found + * @param anOffset tells us where to start searching in this + * @return -1 if not found, else the offset in this + */ + PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const; + PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; + PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; -/** - * This methods scans the string backwards, looking for the given string - * @param aString is substring to be sought in this - * @param aIgnoreCase tells us whether or not to do caseless compare - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + /** + * This methods scans the string backwards, looking for the given string + * @param aString is substring to be sought in this + * @param aIgnoreCase tells us whether or not to do caseless compare + * @return offset in string, or -1 (kNotFound) + */ + PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -/** - * Search for given char within this string - * - * @param aString is substring to be sought in this - * @param anOffset tells us where in this strig to start searching - * @param aIgnoreCase selects case sensitivity - * @return find pos in string, or -1 (kNotFound) - */ -PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + /** + * Search for given char within this string + * + * @param aString is substring to be sought in this + * @param anOffset tells us where in this strig to start searching + * @param aIgnoreCase selects case sensitivity + * @return find pos in string, or -1 (kNotFound) + */ + PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -/** - * This method searches this string for the last character - * found in the given string - * @param aString contains set of chars to be found - * @param anOffset tells us where to start searching in this - * @return -1 if not found, else the offset in this - */ -PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const; -PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; -PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; + /** + * This method searches this string for the last character + * found in the given string + * @param aString contains set of chars to be found + * @param anOffset tells us where to start searching in this + * @return -1 if not found, else the offset in this + */ + PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const; + PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; + PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; -/********************************************************************** - Comparison methods... - *********************************************************************/ + /********************************************************************** + Comparison methods... + *********************************************************************/ -/** - * Compares a given string type to this string. - * @update gess 7/27/98 - * @param S is the string to be compared - * @param aIgnoreCase tells us how to treat case - * @param aCount tells us how many chars to compare - * @return -1,0,1 - */ -virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + /** + * Compares a given string type to this string. + * @update gess 7/27/98 + * @param S is the string to be compared + * @param aIgnoreCase tells us how to treat case + * @param aCount tells us how many chars to compare + * @return -1,0,1 + */ + virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -/** - * These methods compare a given string type to this one - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator==(const nsStr &aString) const; -PRBool operator==(const char* aString) const; -PRBool operator==(const PRUnichar* aString) const; + /** + * These methods compare a given string type to this one + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator==(const nsStr &aString) const; + PRBool operator==(const char* aString) const; + PRBool operator==(const PRUnichar* aString) const; -/** - * These methods perform a !compare of a given string type to this - * @param aString is the string to be compared to this - * @return TRUE - */ -PRBool operator!=(const nsStr &aString) const; -PRBool operator!=(const char* aString) const; -PRBool operator!=(const PRUnichar* aString) const; + /** + * These methods perform a !compare of a given string type to this + * @param aString is the string to be compared to this + * @return TRUE + */ + PRBool operator!=(const nsStr &aString) const; + PRBool operator!=(const char* aString) const; + PRBool operator!=(const PRUnichar* aString) const; -/** - * These methods test if a given string is < than this - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator<(const nsStr &aString) const; -PRBool operator<(const char* aString) const; -PRBool operator<(const PRUnichar* aString) const; + /** + * These methods test if a given string is < than this + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator<(const nsStr &aString) const; + PRBool operator<(const char* aString) const; + PRBool operator<(const PRUnichar* aString) const; -/** - * These methods test if a given string is > than this - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator>(const nsStr &S) const; -PRBool operator>(const char* aString) const; -PRBool operator>(const PRUnichar* aString) const; + /** + * These methods test if a given string is > than this + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator>(const nsStr &S) const; + PRBool operator>(const char* aString) const; + PRBool operator>(const PRUnichar* aString) const; -/** - * These methods test if a given string is <= than this - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator<=(const nsStr &S) const; -PRBool operator<=(const char* aString) const; -PRBool operator<=(const PRUnichar* aString) const; + /** + * These methods test if a given string is <= than this + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator<=(const nsStr &S) const; + PRBool operator<=(const char* aString) const; + PRBool operator<=(const PRUnichar* aString) const; -/** - * These methods test if a given string is >= than this - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator>=(const nsStr &S) const; -PRBool operator>=(const char* aString) const; -PRBool operator>=(const PRUnichar* aString) const; + /** + * These methods test if a given string is >= than this + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator>=(const nsStr &S) const; + PRBool operator>=(const char* aString) const; + PRBool operator>=(const PRUnichar* aString) const; -/** - * Compare this to given string; note that we compare full strings here. - * The optional length argument just lets us know how long the given string is. - * If you provide a length, it is compared to length of this string as an - * optimization. - * - * @param aString -- the string to compare to this - * @param aCount -- number of chars in given string you want to compare - * @return TRUE if equal - */ -PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + /** + * Compare this to given string; note that we compare full strings here. + * The optional length argument just lets us know how long the given string is. + * If you provide a length, it is compared to length of this string as an + * optimization. + * + * @param aString -- the string to compare to this + * @param aCount -- number of chars in given string you want to compare + * @return TRUE if equal + */ + PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -PRBool EqualsIgnoreCase(const nsStr& aString) const; -PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const; -PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const; + PRBool EqualsIgnoreCase(const nsStr& aString) const; + PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const; + PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const; -static void Recycle(nsCString* aString); -static nsCString* CreateString(void); - - - nsIMemoryAgent* mAgent; + static void Recycle(nsCString* aString); + static nsCString* CreateString(void); }; diff --git a/mozilla/xpcom/ds/nsString2.cpp b/mozilla/xpcom/ds/nsString2.cpp index 84553e38e94..edc080b2073 100644 --- a/mozilla/xpcom/ds/nsString2.cpp +++ b/mozilla/xpcom/ds/nsString2.cpp @@ -38,7 +38,7 @@ static const char* kWhitespace="\b\t\r\n "; static void Subsume(nsStr& aDest,nsStr& aSource){ if(aSource.mStr && aSource.mLength) { if(aSource.mOwnsBuffer){ - nsStr::Destroy(aDest,0); + nsStr::Destroy(aDest); aDest.mStr=aSource.mStr; aDest.mLength=aSource.mLength; aDest.mCharSize=aSource.mCharSize; @@ -48,17 +48,17 @@ static void Subsume(nsStr& aDest,nsStr& aSource){ aSource.mStr=0; } else{ - nsStr::Assign(aDest,aSource,0,aSource.mLength,0); + nsStr::Assign(aDest,aSource,0,aSource.mLength); } } - else nsStr::Truncate(aDest,0,0); + else nsStr::Truncate(aDest,0); } /** * Default constructor. */ -nsString::nsString(nsIMemoryAgent* anAgent) : mAgent(anAgent) { +nsString::nsString() { nsStr::Initialize(*this,eTwoByte); } @@ -68,7 +68,7 @@ nsString::nsString(nsIMemoryAgent* anAgent) : mAgent(anAgent) { * @param aCString is a ptr to a 1-byte cstr * @param aLength tells us how many chars to copy from given CString */ -nsString::nsString(const char* aCString,nsIMemoryAgent* anAgent) : mAgent(anAgent) { +nsString::nsString(const char* aCString){ nsStr::Initialize(*this,eTwoByte); Assign(aCString); } @@ -79,7 +79,7 @@ nsString::nsString(const char* aCString,nsIMemoryAgent* anAgent) : mAgent(anAgen * @param aString is a ptr to a unichar string * @param aLength tells us how many chars to copy from given aString */ -nsString::nsString(const PRUnichar* aString,nsIMemoryAgent* anAgent) : mAgent(anAgent) { +nsString::nsString(const PRUnichar* aString) { nsStr::Initialize(*this,eTwoByte); Assign(aString); } @@ -89,9 +89,9 @@ nsString::nsString(const PRUnichar* aString,nsIMemoryAgent* anAgent) : mAgent(an * @update gess 1/4/99 * @param reference to another nsCString */ -nsString::nsString(const nsStr &aString,nsIMemoryAgent* anAgent) : mAgent(anAgent) { +nsString::nsString(const nsStr &aString) { nsStr::Initialize(*this,eTwoByte); - nsStr::Assign(*this,aString,0,aString.mLength,mAgent); + nsStr::Assign(*this,aString,0,aString.mLength); } /** @@ -99,9 +99,9 @@ nsString::nsString(const nsStr &aString,nsIMemoryAgent* anAgent) : mAgent(anAgen * @update gess 1/4/99 * @param reference to another nsString */ -nsString::nsString(const nsString& aString) :mAgent(aString.mAgent) { +nsString::nsString(const nsString& aString) { nsStr::Initialize(*this,eTwoByte); - nsStr::Assign(*this,aString,0,aString.mLength,mAgent); + nsStr::Assign(*this,aString,0,aString.mLength); } /** @@ -109,7 +109,7 @@ nsString::nsString(const nsString& aString) :mAgent(aString.mAgent) { * @update gess 1/4/99 * @param reference to a subsumeString */ -nsString::nsString(nsSubsumeStr& aSubsumeStr) :mAgent(0) { +nsString::nsString(nsSubsumeStr& aSubsumeStr) { nsStr::Initialize(*this,eTwoByte); Subsume(*this,aSubsumeStr); } @@ -119,7 +119,7 @@ nsString::nsString(nsSubsumeStr& aSubsumeStr) :mAgent(0) { * Make sure we call nsStr::Destroy. */ nsString::~nsString() { - nsStr::Destroy(*this,mAgent); + nsStr::Destroy(*this); } void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const { @@ -136,7 +136,7 @@ void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const { * @return nada */ void nsString::Truncate(PRInt32 anIndex) { - nsStr::Truncate(*this,anIndex,mAgent); + nsStr::Truncate(*this,anIndex); } /** @@ -173,7 +173,7 @@ PRBool nsString::IsOrdered(void) const { */ void nsString::SetCapacity(PRUint32 aLength) { if(aLength>mCapacity) { - GrowCapacity(*this,aLength,mAgent); + GrowCapacity(*this,aLength); } AddNullTerminator(*this); } @@ -270,7 +270,7 @@ PRBool nsString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){ */ nsSubsumeStr nsString::operator+(const nsStr& aString){ nsString temp(*this); //make a temp string the same size as this... - nsStr::Append(temp,aString,0,aString.mLength,mAgent); + nsStr::Append(temp,aString,0,aString.mLength); return nsSubsumeStr(temp); } @@ -282,7 +282,7 @@ nsSubsumeStr nsString::operator+(const nsStr& aString){ */ nsSubsumeStr nsString::operator+(const nsString& aString){ nsString temp(*this); //make a temp string the same size as this... - nsStr::Append(temp,aString,0,aString.mLength,mAgent); + nsStr::Append(temp,aString,0,aString.mLength); return nsSubsumeStr(temp); } @@ -786,54 +786,55 @@ static PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadi * @return non-zero error code if this string is non-numeric */ static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) { + static const char* validChars="0123456789abcdefABCDEF-+#"; - aString.ToUpperCase(); + const char* cp=aString.GetBuffer(); + PRInt32 result=NS_ERROR_ILLEGAL_VALUE; + if(cp) { - PRInt32 decPt=nsStr::FindChar(aString,'.',PR_TRUE,0); - char* cp = (kNotFound==decPt) ? aString.mStr + aString.mLength-1 : aString.mStr+decPt-1; - - aRadix=kRadixUnknown; //assume for starters... + //begin by skipping over leading chars that shouldn't be part of the number... + + char* to=(char*)cp; + const char* endcp=cp+aString.mLength; + int len=strlen(validChars); - // Skip trailing non-numeric... - while (cp >= aString.mStr) { - if((*cp>='0') && (*cp<='9')){ - if(kRadixUnknown==aRadix) - aRadix=kRadix10; - break; + while(cp='A') && (*cp<='F')) { - aRadix=16; - break; - } - cp--; + + while(cp='0') && (theChar<='9')) { + *to++=theChar; + } + else if((theChar>='A') && (theChar<='F')) { + aRadix=16; + *to++=theChar; + } + else if('X'==theChar){ + if('-'==aString.mStr[0]) + to=&aString.mStr[1]; + else to=aString.mStr; + aRadix=16; + //root=cp; + } + else if('-'==theChar) { + *to++=theChar; + } + else if(('#'==theChar) || ('+'==theChar)){ + //just skip this char... + } + else break; + cp++; + } + aString.Truncate(to-aString.mStr); + result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; } - aString.Truncate(cp-aString.mStr+1); - - //ok, now scan through chars until you find the start of this number... - //we delimit the number by the presence of: +,-,#,X - - // Skip trailing non-numeric... - cp++; - while (--cp >= aString.mStr) { - if((*cp>='0') && (*cp<='9')){ - continue; - } - else if((*cp>='A') && (*cp<='F')) { - continue; - } - else if((*cp=='-') || (*cp=='+')){ - break; - } - else { - if(('#'==(*cp)) || ('X'==(*cp))) - aRadix=kRadix16; - cp++; //move back by one - break; - } - } - if(cp>aString.mStr) - aString.Cut(0,cp-aString.mStr); - PRInt32 result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; return result; } @@ -865,10 +866,10 @@ PRUint32 nsString::DetermineRadix(void) { PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const { //copy chars to local buffer -- step down from 2 bytes to 1 if necessary... + PRInt32 result=0; nsCAutoString theString(*this); PRUint32 theRadix=aRadix; - PRInt32 result=0; - + *anErrorCode=GetNumericSubstring(theString,theRadix); //we actually don't use this radix; use given radix instead if(NS_OK==*anErrorCode){ if(kAutoDetect==aRadix) @@ -893,13 +894,13 @@ PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const { */ nsString& nsString::Assign(const nsStr& aString,PRInt32 aCount) { if(this!=&aString){ - nsStr::Truncate(*this,0,0); + nsStr::Truncate(*this,0); if(aCount<0) aCount=aString.mLength; else aCount=MinInt(aCount,aString.mLength); - nsStr::Assign(*this,aString,0,aCount,mAgent); + nsStr::Assign(*this,aString,0,aCount); } return *this; } @@ -912,7 +913,7 @@ nsString& nsString::Assign(const nsStr& aString,PRInt32 aCount) { * @return this */ nsString& nsString::Assign(const char* aCString,PRInt32 aCount) { - nsStr::Truncate(*this,0,0); + nsStr::Truncate(*this,0); if(aCString){ Append(aCString,aCount); } @@ -926,7 +927,7 @@ nsString& nsString::Assign(const char* aCString,PRInt32 aCount) { * @return this */ nsString& nsString::Assign(const PRUnichar* aString,PRInt32 aCount) { - nsStr::Truncate(*this,0,0); + nsStr::Truncate(*this,0); if(aString){ Append(aString,aCount); } @@ -940,7 +941,7 @@ nsString& nsString::Assign(const PRUnichar* aString,PRInt32 aCount) { * @return this */ nsString& nsString::Assign(char aChar) { - nsStr::Truncate(*this,0,0); + nsStr::Truncate(*this,0); return Append(aChar); } @@ -951,7 +952,7 @@ nsString& nsString::Assign(char aChar) { * @return this */ nsString& nsString::Assign(PRUnichar aChar) { - nsStr::Truncate(*this,0,0); + nsStr::Truncate(*this,0); return Append(aChar); } @@ -988,7 +989,7 @@ nsString& nsString::Append(const nsStr& aString,PRInt32 aCount) { else aCount=MinInt(aCount,aString.mLength); if(0=1) { - PRInt32 div=theInt/mask1; - if((div) || (!isfirst)) { - buf[charpos++]="0123456789abcdef"[div]; + PRInt32 theDiv=theInt/mask1; + if((theDiv) || (!isfirst)) { + buf[charpos++]="0123456789abcdef"[theDiv]; isfirst=PR_FALSE; } - theInt-=div*mask1; + theInt-=theDiv*mask1; mask1/=aRadix; } return Append(buf); @@ -1173,7 +1174,7 @@ PRUint32 nsString::Left(nsString& aDest,PRInt32 aCount) const{ if(aCount<0) aCount=mLength; else aCount=MinInt(aCount,mLength); - nsStr::Assign(aDest,*this,0,aCount,mAgent); + nsStr::Assign(aDest,*this,0,aCount); return aDest.mLength; } @@ -1191,7 +1192,7 @@ PRUint32 nsString::Mid(nsString& aDest,PRUint32 anOffset,PRInt32 aCount) const{ if(aCount<0) aCount=mLength; else aCount=MinInt(aCount,mLength); - nsStr::Assign(aDest,*this,anOffset,aCount,mAgent); + nsStr::Assign(aDest,*this,anOffset,aCount); return aDest.mLength; } @@ -1221,7 +1222,7 @@ PRUint32 nsString::Right(nsString& aDest,PRInt32 aCount) const{ * @return this */ nsString& nsString::Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) { - nsStr::Insert(*this,anOffset,aCopy,0,aCount,mAgent); + nsStr::Insert(*this,anOffset,aCopy,0,aCount); return *this; } @@ -1252,7 +1253,7 @@ nsString& nsString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCount else aCount=temp.mLength=nsCRT::strlen(aCString); if(0mAgent=&theAgent; delete aString; } return 0; @@ -2116,7 +2115,6 @@ NS_COM int fputs(const nsString& aString, FILE* out) */ nsAutoString::nsAutoString() : nsString() { nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); - mAgent=0; AddNullTerminator(*this); } @@ -2127,7 +2125,6 @@ nsAutoString::nsAutoString() : nsString() { */ nsAutoString::nsAutoString(const char* aCString,PRInt32 aLength) : nsString() { nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); - mAgent=0; AddNullTerminator(*this); Append(aCString,aLength); } @@ -2138,7 +2135,6 @@ nsAutoString::nsAutoString(const char* aCString,PRInt32 aLength) : nsString() { * @param aLength tells us how many chars to copy from aString */ nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString() { - mAgent=0; nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); AddNullTerminator(*this); Append(aString,aLength); @@ -2149,7 +2145,6 @@ nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString( * @param aBuffer describes the external buffer */ nsAutoString::nsAutoString(const CBufDescriptor& aBuffer) : nsString() { - mAgent=0; if(!aBuffer.mBuffer) { nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); } @@ -2166,7 +2161,6 @@ nsAutoString::nsAutoString(const CBufDescriptor& aBuffer) : nsString() { * @param */ nsAutoString::nsAutoString(const nsStr& aString) : nsString() { - mAgent=0; nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); AddNullTerminator(*this); Append(aString); @@ -2176,7 +2170,6 @@ nsAutoString::nsAutoString(const nsStr& aString) : nsString() { * Default copy constructor */ nsAutoString::nsAutoString(const nsAutoString& aString) : nsString() { - mAgent=0; nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); AddNullTerminator(*this); Append(aString); @@ -2188,7 +2181,6 @@ nsAutoString::nsAutoString(const nsAutoString& aString) : nsString() { * @param */ nsAutoString::nsAutoString(PRUnichar aChar) : nsString(){ - mAgent=0; nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); AddNullTerminator(*this); Append(aChar); @@ -2201,12 +2193,10 @@ nsAutoString::nsAutoString(PRUnichar aChar) : nsString(){ */ #ifdef AIX nsAutoString::nsAutoString(const nsSubsumeStr& aSubsumeStr) :nsString() { - mAgent=0; nsSubsumeStr temp(aSubsumeStr); // a temp is needed for the AIX compiler Subsume(*this,temp); #else nsAutoString::nsAutoString( nsSubsumeStr& aSubsumeStr) :nsString() { - mAgent=0; Subsume(*this,aSubsumeStr); #endif // AIX } diff --git a/mozilla/xpcom/ds/nsString2.h b/mozilla/xpcom/ds/nsString2.h index 80332198c4d..a22ca6b7c04 100644 --- a/mozilla/xpcom/ds/nsString2.h +++ b/mozilla/xpcom/ds/nsString2.h @@ -53,716 +53,716 @@ class nsISizeOfHandler; class NS_COM nsSubsumeStr; class NS_COM nsString : public nsStr { - public: +public: -/** - * Default constructor. - */ -nsString(nsIMemoryAgent* anAgent=0); - - -/** - * This constructor accepts an isolatin string - * @param aCString is a ptr to a 1-byte cstr - */ -nsString(const char* aCString,nsIMemoryAgent* anAgent=0); - -/** - * This constructor accepts a unichar string - * @param aCString is a ptr to a 2-byte cstr - */ -nsString(const PRUnichar* aString,nsIMemoryAgent* anAgent=0); - -/** - * This is a copy constructor that accepts an nsStr - * @param reference to another nsString - */ -nsString(const nsStr&,nsIMemoryAgent* anAgent=0); - -/** - * This is our copy constructor - * @param reference to another nsString - */ -nsString(const nsString& aString); - -/** - * This constructor takes a subsumestr - * @param reference to subsumestr - */ -nsString(nsSubsumeStr& aSubsumeStr); - -/** - * Destructor - * - */ -virtual ~nsString(); - -/** - * Retrieve the length of this string - * @return string length - */ -inline PRInt32 Length() const { return (PRInt32)mLength; } - -/** - * Retrieve the size of this string - * @return string length - */ -virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const; - - -/** - * Call this method if you want to force a different string length - * @update gess7/30/98 - * @param aLength -- contains new length for mStr - * @return - */ -void SetLength(PRUint32 aLength) { - Truncate(aLength); -} - -/** - * Sets the new length of the string. - * @param aLength is new string length. - * @return nada - */ -void SetCapacity(PRUint32 aLength); - -/** - * This method truncates this string to given length. - * - * @param anIndex -- new length of string - * @return nada - */ -void Truncate(PRInt32 anIndex=0); - - -/** - * Determine whether or not the characters in this - * string are in sorted order. - * - * @return TRUE if ordered. - */ -PRBool IsOrdered(void) const; - -/** - * Determine whether or not the characters in this - * string are in store as 1 or 2 byte (unicode) strings. - * - * @return TRUE if ordered. - */ -PRBool IsUnicode(void) const { - PRBool result=PRBool(mCharSize==eTwoByte); - return result; -} - -/** - * Determine whether or not this string has a length of 0 - * - * @return TRUE if empty. - */ -PRBool IsEmpty(void) const { - return PRBool(0==mLength); -} - -/********************************************************************** - Getters/Setters... - *********************************************************************/ - -const char* GetBuffer(void) const; -const PRUnichar* GetUnicode(void) const; - - - /** - * Get nth character. + /** + * Default constructor. */ -PRUnichar operator[](PRUint32 anIndex) const; -PRUnichar CharAt(PRUint32 anIndex) const; -PRUnichar First(void) const; -PRUnichar Last(void) const; + nsString(); - /** - * Set nth character. + + /** + * This constructor accepts an isolatin string + * @param aCString is a ptr to a 1-byte cstr */ -PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex); + nsString(const char* aCString); + + /** + * This constructor accepts a unichar string + * @param aCString is a ptr to a 2-byte cstr + */ + nsString(const PRUnichar* aString); + + /** + * This is a copy constructor that accepts an nsStr + * @param reference to another nsString + */ + nsString(const nsStr&); + + /** + * This is our copy constructor + * @param reference to another nsString + */ + nsString(const nsString& aString); + + /** + * This constructor takes a subsumestr + * @param reference to subsumestr + */ + nsString(nsSubsumeStr& aSubsumeStr); + + /** + * Destructor + * + */ + virtual ~nsString(); + + /** + * Retrieve the length of this string + * @return string length + */ + inline PRInt32 Length() const { return (PRInt32)mLength; } + + /** + * Retrieve the size of this string + * @return string length + */ + virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const; -/********************************************************************** - String concatenation methods... - *********************************************************************/ + /** + * Call this method if you want to force a different string length + * @update gess7/30/98 + * @param aLength -- contains new length for mStr + * @return + */ + void SetLength(PRUint32 aLength) { + Truncate(aLength); + } -/** - * Create a new string by appending given string to this - * @param aString -- 2nd string to be appended - * @return new subsumable string - */ -nsSubsumeStr operator+(const nsStr& aString); -nsSubsumeStr operator+(const nsString& aString); + /** + * Sets the new length of the string. + * @param aLength is new string length. + * @return nada + */ + void SetCapacity(PRUint32 aLength); -/** - * create a new string by adding this to the given cstring - * @param aCString is a ptr to cstring to be added to this - * @return newly created string - */ -nsSubsumeStr operator+(const char* aCString); - -/** - * create a new string by adding this to the given prunichar*. - * @param aString is a ptr to UC-string to be added to this - * @return newly created string - */ -nsSubsumeStr operator+(const PRUnichar* aString); - -/** - * create a new string by adding this to the given char. - * @param aChar is a char to be added to this - * @return newly created string - */ -nsSubsumeStr operator+(char aChar); - -/** - * create a new string by adding this to the given char. - * @param aChar is a unichar to be added to this - * @return newly created string - */ -nsSubsumeStr operator+(PRUnichar aChar); - -/********************************************************************** - Lexomorphic transforms... - *********************************************************************/ + /** + * This method truncates this string to given length. + * + * @param anIndex -- new length of string + * @return nada + */ + void Truncate(PRInt32 anIndex=0); -/** - * Converts chars in this to lowercase - * @update gess 7/27/98 - */ -void ToLowerCase(); + /** + * Determine whether or not the characters in this + * string are in sorted order. + * + * @return TRUE if ordered. + */ + PRBool IsOrdered(void) const; + + /** + * Determine whether or not the characters in this + * string are in store as 1 or 2 byte (unicode) strings. + * + * @return TRUE if ordered. + */ + PRBool IsUnicode(void) const { + PRBool result=PRBool(mCharSize==eTwoByte); + return result; + } + + /** + * Determine whether or not this string has a length of 0 + * + * @return TRUE if empty. + */ + PRBool IsEmpty(void) const { + return PRBool(0==mLength); + } + + /********************************************************************** + Getters/Setters... + *********************************************************************/ + + /** + * Retrieve const ptr to internal buffer; DO NOT TRY TO FREE IT! + */ + const char* GetBuffer(void) const; + const PRUnichar* GetUnicode(void) const; -/** - * Converts chars in this to lowercase, and - * stores them in aOut - * @update gess 7/27/98 - * @param aOut is a string to contain result - */ -void ToLowerCase(nsString& aString) const; + /** + * Get nth character. + */ + PRUnichar operator[](PRUint32 anIndex) const; + PRUnichar CharAt(PRUint32 anIndex) const; + PRUnichar First(void) const; + PRUnichar Last(void) const; -/** - * Converts chars in this to uppercase - * @update gess 7/27/98 - */ -void ToUpperCase(); - -/** - * Converts chars in this to lowercase, and - * stores them in a given output string - * @update gess 7/27/98 - * @param aOut is a string to contain result - */ -void ToUpperCase(nsString& aString) const; + /** + * Set nth character. + */ + PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex); -/** - * This method is used to remove all occurances of the - * characters found in aSet from this string. - * - * @param aSet -- characters to be cut from this - * @return *this - */ -nsString& StripChars(const char* aSet); -nsString& StripChar(char aChar); + /********************************************************************** + String concatenation methods... + *********************************************************************/ -/** - * This method strips whitespace throughout the string - * - * @return this - */ -nsString& StripWhitespace(); + /** + * Create a new string by appending given string to this + * @param aString -- 2nd string to be appended + * @return new subsumable string + */ + nsSubsumeStr operator+(const nsStr& aString); + nsSubsumeStr operator+(const nsString& aString); -/** - * swaps occurence of 1 string for another - * - * @return this - */ -nsString& ReplaceChar(PRUnichar anOldChar,PRUnichar aNewChar); -nsString& ReplaceChar(const char* aSet,PRUnichar aNewChar); + /** + * create a new string by adding this to the given cstring + * @param aCString is a ptr to cstring to be added to this + * @return newly created string + */ + nsSubsumeStr operator+(const char* aCString); -PRInt32 CountChar(PRUnichar aChar); + /** + * create a new string by adding this to the given prunichar*. + * @param aString is a ptr to UC-string to be added to this + * @return newly created string + */ + nsSubsumeStr operator+(const PRUnichar* aString); -/** - * This method trims characters found in aTrimSet from - * either end of the underlying string. - * - * @param aTrimSet -- contains chars to be trimmed from - * both ends - * @return this - */ -nsString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + /** + * create a new string by adding this to the given char. + * @param aChar is a char to be added to this + * @return newly created string + */ + nsSubsumeStr operator+(char aChar); -/** - * This method strips whitespace from string. - * You can control whether whitespace is yanked from - * start and end of string as well. - * - * @param aEliminateLeading controls stripping of leading ws - * @param aEliminateTrailing controls stripping of trailing ws - * @return this - */ -nsString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + /** + * create a new string by adding this to the given char. + * @param aChar is a unichar to be added to this + * @return newly created string + */ + nsSubsumeStr operator+(PRUnichar aChar); -/** - * This method strips whitespace from string. - * You can control whether whitespace is yanked from - * start and end of string as well. - * - * @param aEliminateLeading controls stripping of leading ws - * @param aEliminateTrailing controls stripping of trailing ws - * @return this - */ -nsString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); - -/********************************************************************** - string conversion methods... - *********************************************************************/ - -/** - * This method constructs a new nsString is a clone of this string. - * - */ -nsString* ToNewString() const; - -/** - * Creates an ISOLatin1 clone of this string - * Note that calls to this method should be matched with calls to Recycle(). - * @return ptr to new isolatin1 string - */ -char* ToNewCString() const; - -/** - * Creates an UTF8 clone of this string - * Note that calls to this method should be matched with calls to Recycle(). - * @return ptr to new isolatin1 string - */ -char* ToNewUTF8String() const; - -/** - * Creates a unicode clone of this string - * Note that calls to this method should be matched with calls to Recycle(). - * @return ptr to new unicode string - */ -PRUnichar* ToNewUnicode() const; - -/** - * Copies data from internal buffer onto given char* buffer - * NOTE: This only copies as many chars as will fit in given buffer (clips) - * @param aBuf is the buffer where data is stored - * @param aBuflength is the max # of chars to move to buffer - * @return ptr to given buffer - */ -char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const; - -/** - * Perform string to float conversion. - * @param aErrorCode will contain error if one occurs - * @return float rep of string value - */ -float ToFloat(PRInt32* aErrorCode) const; - -/** - * Try to derive the radix from the value contained in this string - * @return kRadix10, kRadix16 or kAutoDetect (meaning unknown) - */ -PRUint32 DetermineRadix(void); - -/** - * Perform string to int conversion. - * @param aErrorCode will contain error if one occurs - * @return int rep of string value - */ -PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const; + /********************************************************************** + Lexomorphic transforms... + *********************************************************************/ -/********************************************************************** - String manipulation methods... - *********************************************************************/ + /** + * Converts chars in this to lowercase + * @update gess 7/27/98 + */ + void ToLowerCase(); -/** - * Functionally equivalent to assign or operator= - * - */ -nsString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} -nsString& SetString(const PRUnichar* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} -nsString& SetString(const nsString& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} -/** - * assign given string to this string - * @param aStr: buffer to be assigned to this - * @param alength is the length of the given str (or -1) - if you want me to determine its length - * @return this - */ -nsString& Assign(const nsStr& aString,PRInt32 aCount=-1); -nsString& Assign(const char* aString,PRInt32 aCount=-1); -nsString& Assign(const PRUnichar* aString,PRInt32 aCount=-1); -nsString& Assign(char aChar); -nsString& Assign(PRUnichar aChar); + /** + * Converts chars in this to lowercase, and + * stores them in aOut + * @update gess 7/27/98 + * @param aOut is a string to contain result + */ + void ToLowerCase(nsString& aString) const; -/** - * here come a bunch of assignment operators... - * @param aString: string to be added to this - * @return this - */ -nsString& operator=(const nsString& aString) {return Assign(aString);} -nsString& operator=(const nsStr& aString) {return Assign(aString);} -nsString& operator=(char aChar) {return Assign(aChar);} -nsString& operator=(PRUnichar aChar) {return Assign(aChar);} -nsString& operator=(const char* aCString) {return Assign(aCString);} -nsString& operator=(const PRUnichar* aString) {return Assign(aString);} -#ifdef AIX -nsString& operator=(const nsSubsumeStr& aSubsumeString); // AIX requires a const here -#else -nsString& operator=(nsSubsumeStr& aSubsumeString); -#endif + /** + * Converts chars in this to uppercase + * @update gess 7/27/98 + */ + void ToUpperCase(); -/** - * Here's a bunch of methods that append varying types... - * @param various... - * @return this - */ -nsString& operator+=(const nsStr& aString){return Append(aString,aString.mLength);} -nsString& operator+=(const nsString& aString){return Append(aString,aString.mLength);} -nsString& operator+=(const char* aCString) {return Append(aCString);} -//nsString& operator+=(char aChar){return Append(aChar);} -nsString& operator+=(const PRUnichar* aUCString) {return Append(aUCString);} -nsString& operator+=(PRUnichar aChar){return Append(aChar);} + /** + * Converts chars in this to lowercase, and + * stores them in a given output string + * @update gess 7/27/98 + * @param aOut is a string to contain result + */ + void ToUpperCase(nsString& aString) const; -/* - * Appends n characters from given string to this, - * This version computes the length of your given string - * - * @param aString is the source to be appended to this - * @return number of chars copied - */ -nsString& Append(const nsStr& aString) {return Append(aString,aString.mLength);} -nsString& Append(const nsString& aString) {return Append(aString,aString.mLength);} + + /** + * This method is used to remove all occurances of the + * characters found in aSet from this string. + * + * @param aSet -- characters to be cut from this + * @return *this + */ + nsString& StripChars(const char* aSet); + nsString& StripChar(char aChar); + + /** + * This method strips whitespace throughout the string + * + * @return this + */ + nsString& StripWhitespace(); + + /** + * swaps occurence of 1 string for another + * + * @return this + */ + nsString& ReplaceChar(PRUnichar anOldChar,PRUnichar aNewChar); + nsString& ReplaceChar(const char* aSet,PRUnichar aNewChar); + + PRInt32 CountChar(PRUnichar aChar); + + /** + * This method trims characters found in aTrimSet from + * either end of the underlying string. + * + * @param aTrimSet -- contains chars to be trimmed from + * both ends + * @return this + */ + nsString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + + /** + * This method strips whitespace from string. + * You can control whether whitespace is yanked from + * start and end of string as well. + * + * @param aEliminateLeading controls stripping of leading ws + * @param aEliminateTrailing controls stripping of trailing ws + * @return this + */ + nsString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + + /** + * This method strips whitespace from string. + * You can control whether whitespace is yanked from + * start and end of string as well. + * + * @param aEliminateLeading controls stripping of leading ws + * @param aEliminateTrailing controls stripping of trailing ws + * @return this + */ + nsString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + + /********************************************************************** + string conversion methods... + *********************************************************************/ + + /** + * This method constructs a new nsString is a clone of this string. + * + */ + nsString* ToNewString() const; + + /** + * Creates an ISOLatin1 clone of this string + * Note that calls to this method should be matched with calls to Recycle(). + * @return ptr to new isolatin1 string + */ + char* ToNewCString() const; + + /** + * Creates an UTF8 clone of this string + * Note that calls to this method should be matched with calls to Recycle(). + * @return ptr to new isolatin1 string + */ + char* ToNewUTF8String() const; + + /** + * Creates a unicode clone of this string + * Note that calls to this method should be matched with calls to Recycle(). + * @return ptr to new unicode string + */ + PRUnichar* ToNewUnicode() const; + + /** + * Copies data from internal buffer onto given char* buffer + * NOTE: This only copies as many chars as will fit in given buffer (clips) + * @param aBuf is the buffer where data is stored + * @param aBuflength is the max # of chars to move to buffer + * @return ptr to given buffer + */ + char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const; + + /** + * Perform string to float conversion. + * @param aErrorCode will contain error if one occurs + * @return float rep of string value + */ + float ToFloat(PRInt32* aErrorCode) const; + + /** + * Try to derive the radix from the value contained in this string + * @return kRadix10, kRadix16 or kAutoDetect (meaning unknown) + */ + PRUint32 DetermineRadix(void); + + /** + * Perform string to int conversion. + * @param aErrorCode will contain error if one occurs + * @return int rep of string value + */ + PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const; + + + /********************************************************************** + String manipulation methods... + *********************************************************************/ + + /** + * Functionally equivalent to assign or operator= + * + */ + nsString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} + nsString& SetString(const PRUnichar* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} + nsString& SetString(const nsString& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} + + /** + * assign given string to this string + * @param aStr: buffer to be assigned to this + * @param alength is the length of the given str (or -1) + if you want me to determine its length + * @return this + */ + nsString& Assign(const nsStr& aString,PRInt32 aCount=-1); + nsString& Assign(const char* aString,PRInt32 aCount=-1); + nsString& Assign(const PRUnichar* aString,PRInt32 aCount=-1); + nsString& Assign(char aChar); + nsString& Assign(PRUnichar aChar); + + /** + * here come a bunch of assignment operators... + * @param aString: string to be added to this + * @return this + */ + nsString& operator=(const nsString& aString) {return Assign(aString);} + nsString& operator=(const nsStr& aString) {return Assign(aString);} + nsString& operator=(char aChar) {return Assign(aChar);} + nsString& operator=(PRUnichar aChar) {return Assign(aChar);} + nsString& operator=(const char* aCString) {return Assign(aCString);} + nsString& operator=(const PRUnichar* aString) {return Assign(aString);} + #ifdef AIX + nsString& operator=(const nsSubsumeStr& aSubsumeString); // AIX requires a const here + #else + nsString& operator=(nsSubsumeStr& aSubsumeString); + #endif + + /** + * Here's a bunch of methods that append varying types... + * @param various... + * @return this + */ + nsString& operator+=(const nsStr& aString){return Append(aString,aString.mLength);} + nsString& operator+=(const nsString& aString){return Append(aString,aString.mLength);} + nsString& operator+=(const char* aCString) {return Append(aCString);} + //nsString& operator+=(char aChar){return Append(aChar);} + nsString& operator+=(const PRUnichar* aUCString) {return Append(aUCString);} + nsString& operator+=(PRUnichar aChar){return Append(aChar);} + + /* + * Appends n characters from given string to this, + * This version computes the length of your given string + * + * @param aString is the source to be appended to this + * @return number of chars copied + */ + nsString& Append(const nsStr& aString) {return Append(aString,aString.mLength);} + nsString& Append(const nsString& aString) {return Append(aString,aString.mLength);} -/* - * Appends n characters from given string to this, - * - * @param aString is the source to be appended to this - * @param aCount -- number of chars to copy; -1 tells us to compute the strlen for you - * @return number of chars copied - */ -nsString& Append(const nsStr& aString,PRInt32 aCount); -nsString& Append(const nsString& aString,PRInt32 aCount); -nsString& Append(const char* aString,PRInt32 aCount=-1); -nsString& Append(const PRUnichar* aString,PRInt32 aCount=-1); -nsString& Append(char aChar); -nsString& Append(PRUnichar aChar); -nsString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16 -nsString& Append(float aFloat); + /* + * Appends n characters from given string to this, + * + * @param aString is the source to be appended to this + * @param aCount -- number of chars to copy; -1 tells us to compute the strlen for you + * @return number of chars copied + */ + nsString& Append(const nsStr& aString,PRInt32 aCount); + nsString& Append(const nsString& aString,PRInt32 aCount); + nsString& Append(const char* aString,PRInt32 aCount=-1); + nsString& Append(const PRUnichar* aString,PRInt32 aCount=-1); + nsString& Append(char aChar); + nsString& Append(PRUnichar aChar); + nsString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16 + nsString& Append(float aFloat); -/* - * Copies n characters from this string to given string, - * starting at the leftmost offset. - * - * - * @param aCopy -- Receiving string - * @param aCount -- number of chars to copy - * @return number of chars copied - */ -PRUint32 Left(nsString& aCopy,PRInt32 aCount) const; + /* + * Copies n characters from this string to given string, + * starting at the leftmost offset. + * + * + * @param aCopy -- Receiving string + * @param aCount -- number of chars to copy + * @return number of chars copied + */ + PRUint32 Left(nsString& aCopy,PRInt32 aCount) const; -/* - * Copies n characters from this string to given string, - * starting at the given offset. - * - * - * @param aCopy -- Receiving string - * @param aCount -- number of chars to copy - * @param anOffset -- position where copying begins - * @return number of chars copied - */ -PRUint32 Mid(nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) const; + /* + * Copies n characters from this string to given string, + * starting at the given offset. + * + * + * @param aCopy -- Receiving string + * @param aCount -- number of chars to copy + * @param anOffset -- position where copying begins + * @return number of chars copied + */ + PRUint32 Mid(nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) const; -/* - * Copies n characters from this string to given string, - * starting at rightmost char. - * - * - * @param aCopy -- Receiving string - * @param aCount -- number of chars to copy - * @return number of chars copied - */ -PRUint32 Right(nsString& aCopy,PRInt32 aCount) const; + /* + * Copies n characters from this string to given string, + * starting at rightmost char. + * + * + * @param aCopy -- Receiving string + * @param aCount -- number of chars to copy + * @return number of chars copied + */ + PRUint32 Right(nsString& aCopy,PRInt32 aCount) const; -/* - * This method inserts n chars from given string into this - * string at str[anOffset]. - * - * @param aCopy -- String to be inserted into this - * @param anOffset -- insertion position within this str - * @param aCount -- number of chars to be copied from aCopy - * @return number of chars inserted into this. - */ -nsString& Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1); + /* + * This method inserts n chars from given string into this + * string at str[anOffset]. + * + * @param aCopy -- String to be inserted into this + * @param anOffset -- insertion position within this str + * @param aCount -- number of chars to be copied from aCopy + * @return number of chars inserted into this. + */ + nsString& Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1); -/** - * Insert a given string into this string at - * a specified offset. - * - * @param aString* to be inserted into this string - * @param anOffset is insert pos in str - * @return the number of chars inserted into this string - */ -nsString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1); -nsString& Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1); + /** + * Insert a given string into this string at + * a specified offset. + * + * @param aString* to be inserted into this string + * @param anOffset is insert pos in str + * @return the number of chars inserted into this string + */ + nsString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1); + nsString& Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1); -/** - * Insert a single char into this string at - * a specified offset. - * - * @param character to be inserted into this string - * @param anOffset is insert pos in str - * @return the number of chars inserted into this string - */ -//nsString& Insert(char aChar,PRUint32 anOffset); -nsString& Insert(PRUnichar aChar,PRUint32 anOffset); + /** + * Insert a single char into this string at + * a specified offset. + * + * @param character to be inserted into this string + * @param anOffset is insert pos in str + * @return the number of chars inserted into this string + */ + //nsString& Insert(char aChar,PRUint32 anOffset); + nsString& Insert(PRUnichar aChar,PRUint32 anOffset); -/* - * This method is used to cut characters in this string - * starting at anOffset, continuing for aCount chars. - * - * @param anOffset -- start pos for cut operation - * @param aCount -- number of chars to be cut - * @return *this - */ -nsString& Cut(PRUint32 anOffset,PRInt32 aCount); + /* + * This method is used to cut characters in this string + * starting at anOffset, continuing for aCount chars. + * + * @param anOffset -- start pos for cut operation + * @param aCount -- number of chars to be cut + * @return *this + */ + nsString& Cut(PRUint32 anOffset,PRInt32 aCount); -/********************************************************************** - Searching methods... - *********************************************************************/ + /********************************************************************** + Searching methods... + *********************************************************************/ -/** - * Search for given character within this string. - * This method does so by using a binary search, - * so your string HAD BETTER BE ORDERED! - * - * @param aChar is the unicode char to be found - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 BinarySearch(PRUnichar aChar) const; + /** + * Search for given character within this string. + * This method does so by using a binary search, + * so your string HAD BETTER BE ORDERED! + * + * @param aChar is the unicode char to be found + * @return offset in string, or -1 (kNotFound) + */ + PRInt32 BinarySearch(PRUnichar aChar) const; -/** - * Search for given substring within this string - * - * @param aString is substring to be sought in this - * @param aIgnoreCase selects case sensitivity - * @param anOffset tells us where in this strig to start searching - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + /** + * Search for given substring within this string + * + * @param aString is substring to be sought in this + * @param aIgnoreCase selects case sensitivity + * @param anOffset tells us where in this strig to start searching + * @return offset in string, or -1 (kNotFound) + */ + PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -/** - * Search for given char within this string - * - * @param aString is substring to be sought in this - * @param anOffset tells us where in this strig to start searching - * @param aIgnoreCase selects case sensitivity - * @return find pos in string, or -1 (kNotFound) - */ -//PRInt32 Find(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const; -PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + /** + * Search for given char within this string + * + * @param aString is substring to be sought in this + * @param anOffset tells us where in this strig to start searching + * @param aIgnoreCase selects case sensitivity + * @return find pos in string, or -1 (kNotFound) + */ + //PRInt32 Find(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const; + PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -/** - * This method searches this string for the first character - * found in the given charset - * @param aString contains set of chars to be found - * @param anOffset tells us where to start searching in this - * @return -1 if not found, else the offset in this - */ -PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const; -PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; -PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; + /** + * This method searches this string for the first character + * found in the given charset + * @param aString contains set of chars to be found + * @param anOffset tells us where to start searching in this + * @return -1 if not found, else the offset in this + */ + PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const; + PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; + PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; -/** - * This methods scans the string backwards, looking for the given string - * @param aString is substring to be sought in this - * @param aIgnoreCase tells us whether or not to do caseless compare - * @param anOffset tells us where in this strig to start searching (counting from left) - */ -PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + /** + * This methods scans the string backwards, looking for the given string + * @param aString is substring to be sought in this + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this strig to start searching (counting from left) + */ + PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -/** - * Search for given char within this string - * - * @param aString is substring to be sought in this - * @param anOffset tells us where in this strig to start searching (counting from left) - * @param aIgnoreCase selects case sensitivity - * @return find pos in string, or -1 (kNotFound) - */ -//PRInt32 RFind(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const; -PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + /** + * Search for given char within this string + * + * @param aString is substring to be sought in this + * @param anOffset tells us where in this strig to start searching (counting from left) + * @param aIgnoreCase selects case sensitivity + * @return find pos in string, or -1 (kNotFound) + */ + //PRInt32 RFind(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const; + PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -/** - * This method searches this string for the last character - * found in the given string - * @param aString contains set of chars to be found - * @param anOffset tells us where in this strig to start searching (counting from left) - * @return -1 if not found, else the offset in this - */ -PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const; -PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; -PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; + /** + * This method searches this string for the last character + * found in the given string + * @param aString contains set of chars to be found + * @param anOffset tells us where in this strig to start searching (counting from left) + * @return -1 if not found, else the offset in this + */ + PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const; + PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; + PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; -/********************************************************************** - Comparison methods... - *********************************************************************/ + /********************************************************************** + Comparison methods... + *********************************************************************/ -/** - * Compares a given string type to this string. - * @update gess 7/27/98 - * @param S is the string to be compared - * @param aIgnoreCase tells us how to treat case - * @param aCount tells us how many chars to compare - * @return -1,0,1 - */ -virtual PRInt32 Compare(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + /** + * Compares a given string type to this string. + * @update gess 7/27/98 + * @param S is the string to be compared + * @param aIgnoreCase tells us how to treat case + * @param aCount tells us how many chars to compare + * @return -1,0,1 + */ + virtual PRInt32 Compare(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -/** - * These methods compare a given string type to this one - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator==(const nsString &aString) const; -PRBool operator==(const nsStr &aString) const; -PRBool operator==(const char *aString) const; -PRBool operator==(const PRUnichar* aString) const; + /** + * These methods compare a given string type to this one + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator==(const nsString &aString) const; + PRBool operator==(const nsStr &aString) const; + PRBool operator==(const char *aString) const; + PRBool operator==(const PRUnichar* aString) const; -/** - * These methods perform a !compare of a given string type to this - * @param aString is the string to be compared to this - * @return TRUE - */ -PRBool operator!=(const nsString &aString) const; -PRBool operator!=(const nsStr &aString) const; -PRBool operator!=(const char* aString) const; -PRBool operator!=(const PRUnichar* aString) const; + /** + * These methods perform a !compare of a given string type to this + * @param aString is the string to be compared to this + * @return TRUE + */ + PRBool operator!=(const nsString &aString) const; + PRBool operator!=(const nsStr &aString) const; + PRBool operator!=(const char* aString) const; + PRBool operator!=(const PRUnichar* aString) const; -/** - * These methods test if a given string is < than this - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator<(const nsString &aString) const; -PRBool operator<(const nsStr &aString) const; -PRBool operator<(const char* aString) const; -PRBool operator<(const PRUnichar* aString) const; + /** + * These methods test if a given string is < than this + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator<(const nsString &aString) const; + PRBool operator<(const nsStr &aString) const; + PRBool operator<(const char* aString) const; + PRBool operator<(const PRUnichar* aString) const; -/** - * These methods test if a given string is > than this - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator>(const nsString &aString) const; -PRBool operator>(const nsStr &S) const; -PRBool operator>(const char* aString) const; -PRBool operator>(const PRUnichar* aString) const; + /** + * These methods test if a given string is > than this + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator>(const nsString &aString) const; + PRBool operator>(const nsStr &S) const; + PRBool operator>(const char* aString) const; + PRBool operator>(const PRUnichar* aString) const; -/** - * These methods test if a given string is <= than this - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator<=(const nsString &aString) const; -PRBool operator<=(const nsStr &S) const; -PRBool operator<=(const char* aString) const; -PRBool operator<=(const PRUnichar* aString) const; + /** + * These methods test if a given string is <= than this + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator<=(const nsString &aString) const; + PRBool operator<=(const nsStr &S) const; + PRBool operator<=(const char* aString) const; + PRBool operator<=(const PRUnichar* aString) const; -/** - * These methods test if a given string is >= than this - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator>=(const nsString &aString) const; -PRBool operator>=(const nsStr &S) const; -PRBool operator>=(const char* aString) const; -PRBool operator>=(const PRUnichar* aString) const; + /** + * These methods test if a given string is >= than this + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator>=(const nsString &aString) const; + PRBool operator>=(const nsStr &S) const; + PRBool operator>=(const char* aString) const; + PRBool operator>=(const PRUnichar* aString) const; -/** - * Compare this to given string; note that we compare full strings here. - * The optional length argument just lets us know how long the given string is. - * If you provide a length, it is compared to length of this string as an - * optimization. - * - * @param aString -- the string to compare to this - * @param aCount -- number of chars to be compared. - * @return TRUE if equal - */ -PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const; -PRBool Equals(const PRUnichar* s1, const PRUnichar* s2,PRBool aIgnoreCase=PR_FALSE) const; + /** + * Compare this to given string; note that we compare full strings here. + * The optional length argument just lets us know how long the given string is. + * If you provide a length, it is compared to length of this string as an + * optimization. + * + * @param aString -- the string to compare to this + * @param aCount -- number of chars to be compared. + * @return TRUE if equal + */ + PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const; + PRBool Equals(const PRUnichar* s1, const PRUnichar* s2,PRBool aIgnoreCase=PR_FALSE) const; -PRBool EqualsIgnoreCase(const nsString& aString) const; -PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const; -PRBool EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const; -PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const; + PRBool EqualsIgnoreCase(const nsString& aString) const; + PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const; + PRBool EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const; + PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const; -/** - * Determine if given buffer is plain ascii - * - * @param aBuffer -- if null, then we test *this, otherwise we test given buffer - * @return TRUE if is all ascii chars or if strlen==0 - */ -PRBool IsASCII(const PRUnichar* aBuffer=0); + /** + * Determine if given buffer is plain ascii + * + * @param aBuffer -- if null, then we test *this, otherwise we test given buffer + * @return TRUE if is all ascii chars or if strlen==0 + */ + PRBool IsASCII(const PRUnichar* aBuffer=0); -/** - * Determine if given char is a valid space character - * - * @param aChar is character to be tested - * @return TRUE if is valid space char - */ -static PRBool IsSpace(PRUnichar ch); + /** + * Determine if given char is a valid space character + * + * @param aChar is character to be tested + * @return TRUE if is valid space char + */ + static PRBool IsSpace(PRUnichar ch); -/** - * Determine if given char in valid alpha range - * - * @param aChar is character to be tested - * @return TRUE if in alpha range - */ -static PRBool IsAlpha(PRUnichar ch); + /** + * Determine if given char in valid alpha range + * + * @param aChar is character to be tested + * @return TRUE if in alpha range + */ + static PRBool IsAlpha(PRUnichar ch); -/** - * Determine if given char is valid digit - * - * @param aChar is character to be tested - * @return TRUE if char is a valid digit - */ -static PRBool IsDigit(PRUnichar ch); + /** + * Determine if given char is valid digit + * + * @param aChar is character to be tested + * @return TRUE if char is a valid digit + */ + static PRBool IsDigit(PRUnichar ch); -static void Recycle(nsString* aString); -static nsString* CreateString(void); - - - nsIMemoryAgent* mAgent; + static void Recycle(nsString* aString); + static nsString* CreateString(void); }; diff --git a/mozilla/xpcom/string/obsolete/nsStr.cpp b/mozilla/xpcom/string/obsolete/nsStr.cpp index c34f2cdd7b7..5f53dbcc357 100644 --- a/mozilla/xpcom/string/obsolete/nsStr.cpp +++ b/mozilla/xpcom/string/obsolete/nsStr.cpp @@ -69,16 +69,6 @@ void nsStr::Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 a aDest.mOwnsBuffer=aOwnsBuffer; } -/** - * - * @update gess10/30/98 - * @param - * @return - */ -nsIMemoryAgent* GetDefaultAgent(void){ - static nsMemoryAgent gDefaultAgent; - return (nsIMemoryAgent*)&gDefaultAgent; -} /** * This member destroys the memory buffer owned by an nsStr object (if it actually owns it) @@ -86,17 +76,9 @@ nsIMemoryAgent* GetDefaultAgent(void){ * @param * @return */ -void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) { +void nsStr::Destroy(nsStr& aDest) { if((aDest.mStr) && (aDest.mStr!=(char*)gCommonEmptyBuffer)) { - if(!anAgent) - anAgent=GetDefaultAgent(); - - if(anAgent) { - anAgent->Free(aDest); - } - else{ - printf("%s\n","Leak occured in nsStr."); - } + Free(aDest); } } @@ -108,11 +90,10 @@ void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) { * @param aNewLength -- new capacity of string in charSize units * @return void */ -PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent) { +PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength) { PRBool result=PR_TRUE; if(aNewLength>aString.mCapacity) { - nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent(); - result=theAgent->Realloc(aString,aNewLength); + result=Realloc(aString,aNewLength); if(aString.mStr) AddNullTerminator(aString); } @@ -126,20 +107,18 @@ PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* * @param aNewLength -- new capacity of string in charSize units * @return void */ -PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAgent) { +PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength) { PRBool result=PR_TRUE; if(aNewLength>aDest.mCapacity) { nsStr theTempStr; nsStr::Initialize(theTempStr,aDest.mCharSize); - nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent(); - - result=EnsureCapacity(theTempStr,aNewLength,theAgent); + result=EnsureCapacity(theTempStr,aNewLength); if(result) { if(aDest.mLength) { - Append(theTempStr,aDest,0,aDest.mLength,theAgent); + Append(theTempStr,aDest,0,aDest.mLength); } - theAgent->Free(aDest); + Free(aDest); aDest.mStr = theTempStr.mStr; theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole... aDest.mLength=theTempStr.mLength; @@ -157,10 +136,10 @@ PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAg * @param aSource is where chars are copied from * @param aCount is the number of chars copied from aSource */ -void nsStr::Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){ +void nsStr::Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount){ if(&aDest!=&aSource){ - Truncate(aDest,0,anAgent); - Append(aDest,aSource,anOffset,aCount,anAgent); + Truncate(aDest,0); + Append(aDest,aSource,anOffset,aCount); } } @@ -172,7 +151,7 @@ void nsStr::Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 a * @param aSource is where char are copied from * @aCount is the number of bytes to be copied */ -void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){ +void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount){ if(anOffset aDest.mCapacity) { - isBigEnough=GrowCapacity(aDest,aDest.mLength+theLength,anAgent); + isBigEnough=GrowCapacity(aDest,aDest.mLength+theLength); } if(isBigEnough) { @@ -204,7 +183,7 @@ void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 a * @param aSrcOffset is where in aSource chars are copied from * @param aCount is the number of chars from aSource to be inserted into aDest */ -void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){ +void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount){ //there are a few cases for insert: // 1. You're inserting chars into an empty string (assign) // 2. You're inserting onto the end of a string (append) @@ -223,22 +202,21 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin nsStr theTempStr; nsStr::Initialize(theTempStr,aDest.mCharSize); - nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent(); - PRBool isBigEnough=EnsureCapacity(theTempStr,aDest.mLength+theLength,theAgent); //grow the temp buffer to the right size + PRBool isBigEnough=EnsureCapacity(theTempStr,aDest.mLength+theLength); //grow the temp buffer to the right size if(isBigEnough) { if(aDestOffset) { - Append(theTempStr,aDest,0,aDestOffset,theAgent); //first copy leftmost data... + Append(theTempStr,aDest,0,aDestOffset); //first copy leftmost data... } - Append(theTempStr,aSource,0,aSource.mLength,theAgent); //next copy inserted (new) data + Append(theTempStr,aSource,0,aSource.mLength); //next copy inserted (new) data PRUint32 theRemains=aDest.mLength-aDestOffset; if(theRemains) { - Append(theTempStr,aDest,aDestOffset,theRemains,theAgent); //next copy rightmost data + Append(theTempStr,aDest,aDestOffset,theRemains); //next copy rightmost data } - theAgent->Free(aDest); + Free(aDest); aDest.mStr = theTempStr.mStr; theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole... aDest.mCapacity=theTempStr.mCapacity; @@ -262,9 +240,9 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin }//if //else nothing to do! } - else Append(aDest,aSource,0,aCount,anAgent); + else Append(aDest,aSource,0,aCount); } - else Append(aDest,aSource,0,aCount,anAgent); + else Append(aDest,aSource,0,aCount); } } @@ -276,7 +254,7 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin * @param aDestOffset is where in aDest deletion is to occur * @param aCount is the number of chars to be deleted in aDest */ -void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAgent* anAgent){ +void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount){ if(aDestOffset //---------------------------------------------------------------------------------------- @@ -177,8 +178,6 @@ const PRInt32 kDefaultStringSize = 64; const PRInt32 kNotFound = -1; -class nsIMemoryAgent; - //---------------------------------------------------------------------------------------- class NS_COM CBufDescriptor { @@ -228,7 +227,7 @@ struct NS_COM nsStr { * @param aString is the nsStr to be manipulated * @param anAgent is the allocator to be used to the nsStr */ - static void Destroy(nsStr& aDest,nsIMemoryAgent* anAgent=0); + static void Destroy(nsStr& aDest); /** * These methods are where memory allocation/reallocation occur. @@ -238,8 +237,8 @@ struct NS_COM nsStr { * @param anAgent is the allocator to be used on the nsStr * @return */ - static PRBool EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0); - static PRBool GrowCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0); + static PRBool EnsureCapacity(nsStr& aString,PRUint32 aNewLength); + static PRBool GrowCapacity(nsStr& aString,PRUint32 aNewLength); /** * These methods are used to append content to the given nsStr @@ -251,7 +250,7 @@ struct NS_COM nsStr { * @param aCount tells us the (max) # of chars to copy * @param anAgent is the allocator to be used for alloc/free operations */ - static void Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0); + static void Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount); /** * These methods are used to assign contents of a source string to dest string @@ -263,7 +262,7 @@ struct NS_COM nsStr { * @param aCount tells us the (max) # of chars to copy * @param anAgent is the allocator to be used for alloc/free operations */ - static void Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0); + static void Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount); /** * These methods are used to insert content from source string to the dest nsStr @@ -276,7 +275,7 @@ struct NS_COM nsStr { * @param aCount tells us the (max) # of chars to insert * @param anAgent is the allocator to be used for alloc/free operations */ - static void Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0); + static void Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount); /** * This method deletes chars from the given str. @@ -288,7 +287,7 @@ struct NS_COM nsStr { * @param aCount tells us the (max) # of chars to delete * @param anAgent is the allocator to be used for alloc/free operations */ - static void Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAgent* anAgent=0); + static void Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount); /** * This method is used to truncate the given string. @@ -301,7 +300,7 @@ struct NS_COM nsStr { * @param aSrcOffset tells us where in source to start copying * @param anAgent is the allocator to be used for alloc/free operations */ - static void Truncate(nsStr& aDest,PRUint32 aDestOffset,nsIMemoryAgent* anAgent=0); + static void Truncate(nsStr& aDest,PRUint32 aDestOffset); /** * This method is used to perform a case conversion on the given string @@ -388,6 +387,12 @@ struct NS_COM nsStr { char* mStr; PRUnichar* mUStr; }; + +private: + static PRBool Alloc(nsStr& aString,PRUint32 aCount); + static PRBool Realloc(nsStr& aString,PRUint32 aCount); + static PRBool Free(nsStr& aString); + }; /************************************************************** @@ -430,74 +435,6 @@ inline PRUnichar GetCharAt(const nsStr& aDest,PRUint32 anIndex){ return 0; } -//---------------------------------------------------------------------------------------- - -class nsIMemoryAgent { -public: - virtual PRBool Alloc(nsStr& aString,PRUint32 aCount)=0; - virtual PRBool Realloc(nsStr& aString,PRUint32 aCount)=0; - virtual PRBool Free(nsStr& aString)=0; -}; - -class nsMemoryAgent : public nsIMemoryAgent { -public: - - virtual PRBool Alloc(nsStr& aDest,PRUint32 aCount) { - - static int mAllocCount=0; - mAllocCount++; - - //we're given the acount value in charunits; now scale up to next multiple. - PRUint32 theNewCapacity=kDefaultStringSize; - while(theNewCapacitymCapacity) { - GrowCapacity(*this,aLength,mAgent); + GrowCapacity(*this,aLength); } AddNullTerminator(*this); } @@ -262,7 +262,7 @@ PRBool nsCString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){ */ nsSubsumeCStr nsCString::operator+(const nsCString& aString){ nsCString temp(*this); //make a temp string the same size as this... - nsStr::Append(temp,aString,0,aString.mLength,mAgent); + nsStr::Append(temp,aString,0,aString.mLength); return nsSubsumeCStr(temp); } @@ -613,11 +613,19 @@ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) { } theDigit=(theChar-'A')+10; } + else if((theChar>='a') && (theChar<='f')) { + if(10==aRadix){ + *anErrorCode=NS_ERROR_ILLEGAL_VALUE; + result=0; + break; + } + theDigit=(theChar-'a')+10; + } else if('-'==theChar) { result=-result; break; } - else if(('+'==theChar) || (' '==theChar)) { //stop in a good state if you see this... + else if(('+'==theChar) || (' '==theChar) || ('X'==theChar) || ('x'==theChar)) { //stop in a good state if you see this... break; } else { @@ -634,6 +642,7 @@ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) { return result; } + /** * Call this method to extract the rightmost numeric value from the given * 1-byte input string, and simultaneously determine the radix. @@ -645,56 +654,56 @@ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) { * @param aRadix (an out parm) tells the caller what base we think the string is in. * @return non-zero error code if this string is non-numeric */ -PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) { +static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) { + static const char* validChars="0123456789abcdefABCDEF-+#"; - aString.ToUpperCase(); + const char* cp=aString.GetBuffer(); + PRInt32 result=NS_ERROR_ILLEGAL_VALUE; + if(cp) { - PRInt32 decPt=nsStr::FindChar(aString,'.',PR_TRUE,0); - char* cp = (kNotFound==decPt) ? aString.mStr + aString.mLength-1 : aString.mStr+decPt-1; - - aRadix=kRadixUnknown; //assume for starters... + //begin by skipping over leading chars that shouldn't be part of the number... + + char* to=(char*)cp; + const char* endcp=cp+aString.mLength; + int len=strlen(validChars); - // Skip trailing non-numeric... - while (cp >= aString.mStr) { - if((*cp>='0') && (*cp<='9')){ - if(kRadixUnknown==aRadix) - aRadix=kRadix10; - break; + while(cp='A') && (*cp<='F')) { - aRadix=16; - break; - } - cp--; + + while(cp='0') && (theChar<='9')) { + *to++=theChar; + } + else if((theChar>='A') && (theChar<='F')) { + aRadix=16; + *to++=theChar; + } + else if('X'==theChar){ + if('-'==aString.mStr[0]) + to=&aString.mStr[1]; + else to=aString.mStr; + aRadix=16; + //root=cp; + } + else if('-'==theChar) { + *to++=theChar; + } + else if(('#'==theChar) || ('+'==theChar)){ + //just skip this char... + } + else break; + cp++; + } + aString.Truncate(to-aString.mStr); + result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; } - aString.Truncate(cp-aString.mStr+1); - - //ok, now scan through chars until you find the start of this number... - //we delimit the number by the presence of: +,-,#,X - - // Skip trailing non-numeric... - cp++; - while (--cp >= aString.mStr) { - if((*cp>='0') && (*cp<='9')){ - continue; - } - else if((*cp>='A') && (*cp<='F')) { - continue; - } - else if((*cp=='-') || (*cp=='+')){ - break; - } - else { - if(('#'==(*cp)) || ('X'==(*cp))) - aRadix=kRadix16; - cp++; //move back by one - break; - } - } - if(cp>aString.mStr) - aString.Cut(0,cp-aString.mStr); - PRInt32 result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; - return result; } @@ -726,11 +735,12 @@ PRUint32 nsCString::DetermineRadix(void) { PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const { //copy chars to local buffer -- step down from 2 bytes to 1 if necessary... + PRInt32 result=0; nsCAutoString theString(*this); PRUint32 theRadix=aRadix; - PRInt32 result=0; - + *anErrorCode=GetNumericSubstring(theString,theRadix); //we actually don't use this radix; use given radix instead + if(NS_OK==*anErrorCode){ if(kAutoDetect==aRadix) aRadix=theRadix; @@ -755,13 +765,13 @@ PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const { */ nsCString& nsCString::Assign(const nsStr& aString,PRInt32 aCount) { if(this!=&aString){ - nsStr::Truncate(*this,0,0); + nsStr::Truncate(*this,0); if(aCount<0) aCount=aString.mLength; else aCount=MinInt(aCount,aString.mLength); - nsStr::Assign(*this,aString,0,aCount,mAgent); + nsStr::Assign(*this,aString,0,aCount); } return *this; } @@ -773,7 +783,7 @@ nsCString& nsCString::Assign(const nsStr& aString,PRInt32 aCount) { * @return this */ nsCString& nsCString::Assign(const char* aCString,PRInt32 aCount) { - nsStr::Truncate(*this,0,0); + nsStr::Truncate(*this,0); if(aCString){ Append(aCString,aCount); } @@ -787,7 +797,7 @@ nsCString& nsCString::Assign(const char* aCString,PRInt32 aCount) { * @return this */ nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) { - nsStr::Truncate(*this,0,0); + nsStr::Truncate(*this,0); if(aString){ nsStr temp; @@ -806,7 +816,7 @@ nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) { else aCount=temp.mLength=nsCRT::strlen(aString); if(0=1) { - PRInt32 div=theInt/mask1; - if((div) || (!isfirst)) { - buf[charpos++]="0123456789abcdef"[div]; + PRInt32 theDiv=theInt/mask1; + if((theDiv) || (!isfirst)) { + buf[charpos++]="0123456789abcdef"[theDiv]; isfirst=PR_FALSE; } - theInt-=div*mask1; + theInt-=theDiv*mask1; mask1/=aRadix; } return Append(buf); @@ -1001,7 +1028,7 @@ PRUint32 nsCString::Left(nsCString& aDest,PRInt32 aCount) const{ if(aCount<0) aCount=mLength; else aCount=MinInt(aCount,mLength); - nsStr::Assign(aDest,*this,0,aCount,mAgent); + nsStr::Assign(aDest,*this,0,aCount); return aDest.mLength; } @@ -1018,7 +1045,7 @@ PRUint32 nsCString::Mid(nsCString& aDest,PRUint32 anOffset,PRInt32 aCount) const if(aCount<0) aCount=mLength; else aCount=MinInt(aCount,mLength); - nsStr::Assign(aDest,*this,anOffset,aCount,mAgent); + nsStr::Assign(aDest,*this,anOffset,aCount); return aDest.mLength; } @@ -1048,7 +1075,7 @@ PRUint32 nsCString::Right(nsCString& aDest,PRInt32 aCount) const{ */ nsCString& nsCString::Insert(const nsCString& aString,PRUint32 anOffset,PRInt32 aCount) { - nsStr::Insert(*this,anOffset,aString,0,aCount,mAgent); + nsStr::Insert(*this,anOffset,aString,0,aCount); return *this; } @@ -1079,7 +1106,7 @@ nsCString& nsCString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCou else aCount=temp.mLength=nsCRT::strlen(aCString); if(temp.mLength && (0mAgent=&theAgent; delete aString; } return 0; @@ -1722,7 +1747,6 @@ NS_COM int fputs(const nsCString& aString, FILE* out) */ nsCAutoString::nsCAutoString() : nsCString(){ nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); - mAgent=0; AddNullTerminator(*this); } @@ -1732,7 +1756,6 @@ nsCAutoString::nsCAutoString() : nsCString(){ */ nsCAutoString::nsCAutoString(const nsCAutoString& aString) : nsCString() { nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); - mAgent=0; AddNullTerminator(*this); Append(aString); } @@ -1744,7 +1767,6 @@ nsCAutoString::nsCAutoString(const nsCAutoString& aString) : nsCString() { */ nsCAutoString::nsCAutoString(const char* aCString,PRInt32 aLength) : nsCString() { nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); - mAgent=0; AddNullTerminator(*this); Append(aCString,aLength); } @@ -1754,7 +1776,6 @@ nsCAutoString::nsCAutoString(const char* aCString,PRInt32 aLength) : nsCString() * @param aBuffer -- descibes external buffer */ nsCAutoString::nsCAutoString(const CBufDescriptor& aBuffer) : nsCString() { - mAgent=0; if(!aBuffer.mBuffer) { nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); } @@ -1770,7 +1791,6 @@ nsCAutoString::nsCAutoString(const CBufDescriptor& aBuffer) : nsCString() { * @param aString is a ptr to a unistr */ nsCAutoString::nsCAutoString(const PRUnichar* aString,PRInt32 aLength) : nsCString() { - mAgent=0; nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); AddNullTerminator(*this); Append(aString,aLength); @@ -1781,7 +1801,6 @@ nsCAutoString::nsCAutoString(const PRUnichar* aString,PRInt32 aLength) : nsCStri * @param */ nsCAutoString::nsCAutoString(const nsStr& aString) : nsCString() { - mAgent=0; nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); AddNullTerminator(*this); Append(aString); @@ -1794,7 +1813,6 @@ nsCAutoString::nsCAutoString(const nsStr& aString) : nsCString() { * @param */ nsCAutoString::nsCAutoString(PRUnichar aChar) : nsCString(){ - mAgent=0; nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); AddNullTerminator(*this); Append(aChar); @@ -1807,12 +1825,10 @@ nsCAutoString::nsCAutoString(PRUnichar aChar) : nsCString(){ */ #ifdef AIX nsCAutoString::nsCAutoString(const nsSubsumeCStr& aSubsumeStr) :nsCString() { - mAgent=0; nsSubsumeCStr temp(aSubsumeStr); // a temp is needed for the AIX compiler CSubsume(*this,temp); #else nsCAutoString::nsCAutoString( nsSubsumeCStr& aSubsumeStr) :nsCString() { - mAgent=0; CSubsume(*this,aSubsumeStr); #endif // AIX } diff --git a/mozilla/xpcom/string/obsolete/nsString.h b/mozilla/xpcom/string/obsolete/nsString.h index 05205d9a818..90db90305b4 100644 --- a/mozilla/xpcom/string/obsolete/nsString.h +++ b/mozilla/xpcom/string/obsolete/nsString.h @@ -46,632 +46,633 @@ class NS_COM nsSubsumeCStr; class NS_COM nsCString : public nsStr { - public: +public: -/** - * Default constructor. - */ -nsCString(nsIMemoryAgent* anAgent=0); - - -/** - * This constructor accepts an isolatin string - * @param aCString is a ptr to a 1-byte cstr - */ -nsCString(const char* aCString,PRInt32 aLength=-1,nsIMemoryAgent* anAgent=0); - -/** - * This constructor accepts a unichar string - * @param aCString is a ptr to a 2-byte cstr - */ -nsCString(const PRUnichar* aString,PRInt32 aLength=-1,nsIMemoryAgent* anAgent=0); - -/** - * This is a copy constructor that accepts an nsStr - * @param reference to another nsCString - */ -nsCString(const nsStr&,nsIMemoryAgent* anAgent=0); - -/** - * This is our copy constructor - * @param reference to another nsCString - */ -nsCString(const nsCString& aString); - -/** - * This constructor takes a subsumestr - * @param reference to subsumestr - */ -nsCString(nsSubsumeCStr& aSubsumeStr); - -/** - * Destructor - * - */ -virtual ~nsCString(); - -/** - * Retrieve the length of this string - * @return string length - */ -inline PRInt32 Length() const { return (PRInt32)mLength; } - -/** - * Retrieve the size of this string - * @return string length - */ -virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const; - - -/** - * Call this method if you want to force a different string capacity - * @update gess7/30/98 - * @param aLength -- contains new length for mStr - * @return - */ -void SetLength(PRUint32 aLength) { - Truncate(aLength); -} - -/** - * Sets the new length of the string. - * @param aLength is new string length. - * @return nada - */ -void SetCapacity(PRUint32 aLength); -/** - * This method truncates this string to given length. - * - * @param anIndex -- new length of string - * @return nada - */ -void Truncate(PRInt32 anIndex=0); - - -/** - * Determine whether or not the characters in this - * string are in sorted order. - * - * @return TRUE if ordered. - */ -PRBool IsOrdered(void) const; - - -/** - * Determine whether or not this string has a length of 0 - * - * @return TRUE if empty. - */ -PRBool IsEmpty(void) const { - return PRBool(0==mLength); -} - -/********************************************************************** - Accessor methods... - *********************************************************************/ - -const char* GetBuffer(void) const; - - - /** - * Get nth character. + /** + * Default constructor. */ -PRUnichar operator[](PRUint32 anIndex) const; -PRUnichar CharAt(PRUint32 anIndex) const; -PRUnichar First(void) const; -PRUnichar Last(void) const; + nsCString(); -PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex); + /** + * This constructor accepts an isolatin string + * @param aCString is a ptr to a 1-byte cstr + */ + nsCString(const char* aCString,PRInt32 aLength=-1); + + /** + * This constructor accepts a unichar string + * @param aCString is a ptr to a 2-byte cstr + */ + nsCString(const PRUnichar* aString,PRInt32 aLength=-1); + + /** + * This is a copy constructor that accepts an nsStr + * @param reference to another nsCString + */ + nsCString(const nsStr&); + + /** + * This is our copy constructor + * @param reference to another nsCString + */ + nsCString(const nsCString& aString); + + /** + * This constructor takes a subsumestr + * @param reference to subsumestr + */ + nsCString(nsSubsumeCStr& aSubsumeStr); + + /** + * Destructor + * + */ + virtual ~nsCString(); + + /** + * Retrieve the length of this string + * @return string length + */ + inline PRInt32 Length() const { return (PRInt32)mLength; } + + /** + * Retrieve the size of this string + * @return string length + */ + virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const; -/********************************************************************** - String creation methods... - *********************************************************************/ + /** + * Call this method if you want to force a different string capacity + * @update gess7/30/98 + * @param aLength -- contains new length for mStr + * @return + */ + void SetLength(PRUint32 aLength) { + Truncate(aLength); + } -/** - * Create a new string by appending given string to this - * @param aString -- 2nd string to be appended - * @return new string - */ -nsSubsumeCStr operator+(const nsCString& aString); - -/** - * create a new string by adding this to the given char*. - * @param aCString is a ptr to cstring to be added to this - * @return newly created string - */ -nsSubsumeCStr operator+(const char* aCString); + /** + * Sets the new length of the string. + * @param aLength is new string length. + * @return nada + */ + void SetCapacity(PRUint32 aLength); + /** + * This method truncates this string to given length. + * + * @param anIndex -- new length of string + * @return nada + */ + void Truncate(PRInt32 anIndex=0); -/** - * create a new string by adding this to the given char. - * @param aChar is a char to be added to this - * @return newly created string - */ -nsSubsumeCStr operator+(PRUnichar aChar); -nsSubsumeCStr operator+(char aChar); + /** + * Determine whether or not the characters in this + * string are in sorted order. + * + * @return TRUE if ordered. + */ + PRBool IsOrdered(void) const; -/********************************************************************** - Lexomorphic transforms... - *********************************************************************/ + /** + * Determine whether or not this string has a length of 0 + * + * @return TRUE if empty. + */ + PRBool IsEmpty(void) const { + return PRBool(0==mLength); + } -/** - * Converts chars in this to lowercase - * @update gess 7/27/98 - */ -void ToLowerCase(); + /********************************************************************** + Accessor methods... + *********************************************************************/ -/** - * Converts chars in this to lowercase, and - * stores them in aOut - * @update gess 7/27/98 - * @param aOut is a string to contain result - */ -void ToLowerCase(nsCString& aString) const; - -/** - * Converts chars in this to uppercase - * @update gess 7/27/98 - */ -void ToUpperCase(); - -/** - * Converts chars in this to lowercase, and - * stores them in a given output string - * @update gess 7/27/98 - * @param aOut is a string to contain result - */ -void ToUpperCase(nsCString& aString) const; + /** + * Retrieve const ptr to internal buffer; DO NOT TRY TO FREE IT! + */ + const char* GetBuffer(void) const; -/** - * This method is used to remove all occurances of the - * characters found in aSet from this string. - * - * @param aSet -- characters to be cut from this - * @return *this - */ -nsCString& StripChars(const char* aSet); -nsCString& StripChar(char aChar); + /** + * Get nth character. + */ + PRUnichar operator[](PRUint32 anIndex) const; + PRUnichar CharAt(PRUint32 anIndex) const; + PRUnichar First(void) const; + PRUnichar Last(void) const; -/** - * This method strips whitespace throughout the string - * - * @return this - */ -nsCString& StripWhitespace(); - -/** - * swaps occurence of 1 string for another - * - * @return this - */ -nsCString& ReplaceChar(PRUnichar aOldChar,PRUnichar aNewChar); -nsCString& ReplaceChar(const char* aSet,PRUnichar aNewChar); - -PRInt32 CountChar(PRUnichar aChar); - -/** - * This method trims characters found in aTrimSet from - * either end of the underlying string. - * - * @param aTrimSet -- contains chars to be trimmed from - * both ends - * @return this - */ -nsCString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); - -/** - * This method strips whitespace from string. - * You can control whether whitespace is yanked from - * start and end of string as well. - * - * @param aEliminateLeading controls stripping of leading ws - * @param aEliminateTrailing controls stripping of trailing ws - * @return this - */ -nsCString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); - -/** - * This method strips whitespace from string. - * You can control whether whitespace is yanked from - * start and end of string as well. - * - * @param aEliminateLeading controls stripping of leading ws - * @param aEliminateTrailing controls stripping of trailing ws - * @return this - */ -nsCString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); - -/********************************************************************** - string conversion methods... - *********************************************************************/ - - operator char*() {return mStr;} - operator const char*() const {return (const char*)mStr;} - -/** - * This method constructs a new nsCString that is a clone - * of this string. - * - */ -nsCString* ToNewString() const; - -/** - * Creates an ISOLatin1 clone of this string - * Note that calls to this method should be matched with calls to Recycle(). - * @return ptr to new isolatin1 string - */ -char* ToNewCString() const; - -/** - * Creates a unicode clone of this string - * Note that calls to this method should be matched with calls to Recycle(). - * @return ptr to new unicode string - */ -PRUnichar* ToNewUnicode() const; - -/** - * Copies data from internal buffer onto given char* buffer - * NOTE: This only copies as many chars as will fit in given buffer (clips) - * @param aBuf is the buffer where data is stored - * @param aBuflength is the max # of chars to move to buffer - * @return ptr to given buffer - */ -char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const; - -/** - * Perform string to float conversion. - * @param aErrorCode will contain error if one occurs - * @return float rep of string value - */ -float ToFloat(PRInt32* aErrorCode) const; - -/** - * Try to derive the radix from the value contained in this string - * @return kRadix10, kRadix16 or kAutoDetect (meaning unknown) - */ -PRUint32 DetermineRadix(void); - -/** - * Perform string to int conversion. - * @param aErrorCode will contain error if one occurs - * @return int rep of string value - */ -PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const; + PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex); -/********************************************************************** - String manipulation methods... - *********************************************************************/ + /********************************************************************** + String creation methods... + *********************************************************************/ -/** - * Functionally equivalent to assign or operator= - * - */ -nsCString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} -nsCString& SetString(const nsStr& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} + /** + * Create a new string by appending given string to this + * @param aString -- 2nd string to be appended + * @return new string + */ + nsSubsumeCStr operator+(const nsCString& aString); -/** - * assign given string to this string - * @param aStr: buffer to be assigned to this - * @param alength is the length of the given str (or -1) - if you want me to determine its length - * @return this - */ -nsCString& Assign(const nsStr& aString,PRInt32 aCount=-1); -nsCString& Assign(const char* aString,PRInt32 aCount=-1); -nsCString& Assign(const PRUnichar* aString,PRInt32 aCount=-1); -nsCString& Assign(PRUnichar aChar); -nsCString& Assign(char aChar); + /** + * create a new string by adding this to the given char*. + * @param aCString is a ptr to cstring to be added to this + * @return newly created string + */ + nsSubsumeCStr operator+(const char* aCString); -/** - * here come a bunch of assignment operators... - * @param aString: string to be added to this - * @return this - */ -nsCString& operator=(const nsCString& aString) {return Assign(aString);} -nsCString& operator=(const nsStr& aString) {return Assign(aString);} -nsCString& operator=(PRUnichar aChar) {return Assign(aChar);} -nsCString& operator=(char aChar) {return Assign(aChar);} -nsCString& operator=(const char* aCString) {return Assign(aCString);} -nsCString& operator=(const PRUnichar* aString) {return Assign(aString);} -#ifdef AIX -nsCString& operator=(const nsSubsumeCStr& aSubsumeString); // AIX requires a const here -#else -nsCString& operator=(nsSubsumeCStr& aSubsumeString); -#endif -/** - * Here's a bunch of methods that append varying types... - * @param various... - * @return this - */ -nsCString& operator+=(const nsCString& aString){return Append(aString,aString.mLength);} -nsCString& operator+=(const char* aCString) {return Append(aCString);} -nsCString& operator+=(PRUnichar aChar){return Append(aChar);} -nsCString& operator+=(char aChar){return Append(aChar);} + /** + * create a new string by adding this to the given char. + * @param aChar is a char to be added to this + * @return newly created string + */ + nsSubsumeCStr operator+(PRUnichar aChar); + nsSubsumeCStr operator+(char aChar); -/* - * Appends n characters from given string to this, - * This version computes the length of your given string - * - * @param aString is the source to be appended to this - * @return number of chars copied - */ -nsCString& Append(const nsCString& aString) {return Append(aString,aString.mLength);} + + /********************************************************************** + Lexomorphic transforms... + *********************************************************************/ + + /** + * Converts chars in this to lowercase + * @update gess 7/27/98 + */ + void ToLowerCase(); + + + /** + * Converts chars in this to lowercase, and + * stores them in aOut + * @update gess 7/27/98 + * @param aOut is a string to contain result + */ + void ToLowerCase(nsCString& aString) const; + + /** + * Converts chars in this to uppercase + * @update gess 7/27/98 + */ + void ToUpperCase(); + + /** + * Converts chars in this to lowercase, and + * stores them in a given output string + * @update gess 7/27/98 + * @param aOut is a string to contain result + */ + void ToUpperCase(nsCString& aString) const; + + + /** + * This method is used to remove all occurances of the + * characters found in aSet from this string. + * + * @param aSet -- characters to be cut from this + * @return *this + */ + nsCString& StripChars(const char* aSet); + nsCString& StripChar(char aChar); + + /** + * This method strips whitespace throughout the string + * + * @return this + */ + nsCString& StripWhitespace(); + + /** + * swaps occurence of 1 string for another + * + * @return this + */ + nsCString& ReplaceChar(PRUnichar aOldChar,PRUnichar aNewChar); + nsCString& ReplaceChar(const char* aSet,PRUnichar aNewChar); + + PRInt32 CountChar(PRUnichar aChar); + + /** + * This method trims characters found in aTrimSet from + * either end of the underlying string. + * + * @param aTrimSet -- contains chars to be trimmed from + * both ends + * @return this + */ + nsCString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + + /** + * This method strips whitespace from string. + * You can control whether whitespace is yanked from + * start and end of string as well. + * + * @param aEliminateLeading controls stripping of leading ws + * @param aEliminateTrailing controls stripping of trailing ws + * @return this + */ + nsCString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + + /** + * This method strips whitespace from string. + * You can control whether whitespace is yanked from + * start and end of string as well. + * + * @param aEliminateLeading controls stripping of leading ws + * @param aEliminateTrailing controls stripping of trailing ws + * @return this + */ + nsCString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + + /********************************************************************** + string conversion methods... + *********************************************************************/ + + operator char*() {return mStr;} + operator const char*() const {return (const char*)mStr;} + + /** + * This method constructs a new nsCString that is a clone + * of this string. + * + */ + nsCString* ToNewString() const; + + /** + * Creates an ISOLatin1 clone of this string + * Note that calls to this method should be matched with calls to Recycle(). + * @return ptr to new isolatin1 string + */ + char* ToNewCString() const; + + /** + * Creates a unicode clone of this string + * Note that calls to this method should be matched with calls to Recycle(). + * @return ptr to new unicode string + */ + PRUnichar* ToNewUnicode() const; + + /** + * Copies data from internal buffer onto given char* buffer + * NOTE: This only copies as many chars as will fit in given buffer (clips) + * @param aBuf is the buffer where data is stored + * @param aBuflength is the max # of chars to move to buffer + * @return ptr to given buffer + */ + char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const; + + /** + * Perform string to float conversion. + * @param aErrorCode will contain error if one occurs + * @return float rep of string value + */ + float ToFloat(PRInt32* aErrorCode) const; + + /** + * Try to derive the radix from the value contained in this string + * @return kRadix10, kRadix16 or kAutoDetect (meaning unknown) + */ + PRUint32 DetermineRadix(void); + + /** + * Perform string to int conversion. + * @param aErrorCode will contain error if one occurs + * @return int rep of string value + */ + PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const; + + + /********************************************************************** + String manipulation methods... + *********************************************************************/ + + /** + * Functionally equivalent to assign or operator= + * + */ + nsCString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} + nsCString& SetString(const nsStr& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} + + /** + * assign given string to this string + * @param aStr: buffer to be assigned to this + * @param alength is the length of the given str (or -1) + if you want me to determine its length + * @return this + */ + nsCString& Assign(const nsStr& aString,PRInt32 aCount=-1); + nsCString& Assign(const char* aString,PRInt32 aCount=-1); + nsCString& Assign(const PRUnichar* aString,PRInt32 aCount=-1); + nsCString& Assign(PRUnichar aChar); + nsCString& Assign(char aChar); + + /** + * here come a bunch of assignment operators... + * @param aString: string to be added to this + * @return this + */ + nsCString& operator=(const nsCString& aString) {return Assign(aString);} + nsCString& operator=(const nsStr& aString) {return Assign(aString);} + nsCString& operator=(PRUnichar aChar) {return Assign(aChar);} + nsCString& operator=(char aChar) {return Assign(aChar);} + nsCString& operator=(const char* aCString) {return Assign(aCString);} + nsCString& operator=(const PRUnichar* aString) {return Assign(aString);} + #ifdef AIX + nsCString& operator=(const nsSubsumeCStr& aSubsumeString); // AIX requires a const here + #else + nsCString& operator=(nsSubsumeCStr& aSubsumeString); + #endif + + /** + * Here's a bunch of methods that append varying types... + * @param various... + * @return this + */ + nsCString& operator+=(const nsCString& aString){return Append(aString,aString.mLength);} + nsCString& operator+=(const char* aCString) {return Append(aCString);} + nsCString& operator+=(PRUnichar aChar){return Append(aChar);} + nsCString& operator+=(char aChar){return Append(aChar);} + + /* + * Appends n characters from given string to this, + * This version computes the length of your given string + * + * @param aString is the source to be appended to this + * @return number of chars copied + */ + nsCString& Append(const nsCString& aString) {return Append(aString,aString.mLength);} -/* - * Appends n characters from given string to this, - * - * @param aString is the source to be appended to this - * @param aCount -- number of chars to copy; -1 tells us to compute the strlen for you - * @return number of chars copied - */ -nsCString& Append(const nsCString& aString,PRInt32 aCount); -nsCString& Append(const char* aString,PRInt32 aCount=-1); -nsCString& Append(PRUnichar aChar); -nsCString& Append(char aChar); -nsCString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16 -nsCString& Append(float aFloat); + /* + * Appends n characters from given string to this, + * + * @param aString is the source to be appended to this + * @param aCount -- number of chars to copy; -1 tells us to compute the strlen for you + * @return number of chars copied + */ + nsCString& Append(const nsCString& aString,PRInt32 aCount); + nsCString& Append(const nsStr& aString,PRInt32 aCount=-1); + nsCString& Append(const char* aString,PRInt32 aCount=-1); + nsCString& Append(PRUnichar aChar); + nsCString& Append(char aChar); + nsCString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16 + nsCString& Append(float aFloat); -/* - * Copies n characters from this string to given string, - * starting at the leftmost offset. - * - * - * @param aCopy -- Receiving string - * @param aCount -- number of chars to copy - * @return number of chars copied - */ -PRUint32 Left(nsCString& aCopy,PRInt32 aCount) const; + /* + * Copies n characters from this string to given string, + * starting at the leftmost offset. + * + * + * @param aCopy -- Receiving string + * @param aCount -- number of chars to copy + * @return number of chars copied + */ + PRUint32 Left(nsCString& aCopy,PRInt32 aCount) const; -/* - * Copies n characters from this string to given string, - * starting at the given offset. - * - * - * @param aCopy -- Receiving string - * @param aCount -- number of chars to copy - * @param anOffset -- position where copying begins - * @return number of chars copied - */ -PRUint32 Mid(nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount) const; + /* + * Copies n characters from this string to given string, + * starting at the given offset. + * + * + * @param aCopy -- Receiving string + * @param aCount -- number of chars to copy + * @param anOffset -- position where copying begins + * @return number of chars copied + */ + PRUint32 Mid(nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount) const; -/* - * Copies n characters from this string to given string, - * starting at rightmost char. - * - * - * @param aCopy -- Receiving string - * @param aCount -- number of chars to copy - * @return number of chars copied - */ -PRUint32 Right(nsCString& aCopy,PRInt32 aCount) const; + /* + * Copies n characters from this string to given string, + * starting at rightmost char. + * + * + * @param aCopy -- Receiving string + * @param aCount -- number of chars to copy + * @return number of chars copied + */ + PRUint32 Right(nsCString& aCopy,PRInt32 aCount) const; -/* - * This method inserts n chars from given string into this - * string at str[anOffset]. - * - * @param aCopy -- String to be inserted into this - * @param anOffset -- insertion position within this str - * @param aCount -- number of chars to be copied from aCopy - * @return number of chars inserted into this. - */ -nsCString& Insert(const nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1); + /* + * This method inserts n chars from given string into this + * string at str[anOffset]. + * + * @param aCopy -- String to be inserted into this + * @param anOffset -- insertion position within this str + * @param aCount -- number of chars to be copied from aCopy + * @return number of chars inserted into this. + */ + nsCString& Insert(const nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1); -/** - * Insert a given string into this string at - * a specified offset. - * - * @param aString* to be inserted into this string - * @param anOffset is insert pos in str - * @return the number of chars inserted into this string - */ -nsCString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1); + /** + * Insert a given string into this string at + * a specified offset. + * + * @param aString* to be inserted into this string + * @param anOffset is insert pos in str + * @return the number of chars inserted into this string + */ + nsCString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1); -/** - * Insert a single char into this string at - * a specified offset. - * - * @param character to be inserted into this string - * @param anOffset is insert pos in str - * @return the number of chars inserted into this string - */ -nsCString& Insert(PRUnichar aChar,PRUint32 anOffset); -nsCString& Insert(char aChar,PRUint32 anOffset); + /** + * Insert a single char into this string at + * a specified offset. + * + * @param character to be inserted into this string + * @param anOffset is insert pos in str + * @return the number of chars inserted into this string + */ + nsCString& Insert(PRUnichar aChar,PRUint32 anOffset); + nsCString& Insert(char aChar,PRUint32 anOffset); -/* - * This method is used to cut characters in this string - * starting at anOffset, continuing for aCount chars. - * - * @param anOffset -- start pos for cut operation - * @param aCount -- number of chars to be cut - * @return *this - */ -nsCString& Cut(PRUint32 anOffset,PRInt32 aCount); + /* + * This method is used to cut characters in this string + * starting at anOffset, continuing for aCount chars. + * + * @param anOffset -- start pos for cut operation + * @param aCount -- number of chars to be cut + * @return *this + */ + nsCString& Cut(PRUint32 anOffset,PRInt32 aCount); -/********************************************************************** - Searching methods... - *********************************************************************/ + /********************************************************************** + Searching methods... + *********************************************************************/ -/** - * Search for given character within this string. - * This method does so by using a binary search, - * so your string HAD BETTER BE ORDERED! - * - * @param aChar is the unicode char to be found - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 BinarySearch(PRUnichar aChar) const; + /** + * Search for given character within this string. + * This method does so by using a binary search, + * so your string HAD BETTER BE ORDERED! + * + * @param aChar is the unicode char to be found + * @return offset in string, or -1 (kNotFound) + */ + PRInt32 BinarySearch(PRUnichar aChar) const; -/** - * Search for given substring within this string - * - * @param aString is substring to be sought in this - * @param aIgnoreCase selects case sensitivity - * @param anOffset tells us where in this strig to start searching - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + /** + * Search for given substring within this string + * + * @param aString is substring to be sought in this + * @param aIgnoreCase selects case sensitivity + * @param anOffset tells us where in this strig to start searching + * @return offset in string, or -1 (kNotFound) + */ + PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -/** - * Search for given char within this string - * - * @param aString is substring to be sought in this - * @param anOffset tells us where in this strig to start searching - * @param aIgnoreCase selects case sensitivity - * @return find pos in string, or -1 (kNotFound) - */ -PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + /** + * Search for given char within this string + * + * @param aString is substring to be sought in this + * @param anOffset tells us where in this strig to start searching + * @param aIgnoreCase selects case sensitivity + * @return find pos in string, or -1 (kNotFound) + */ + PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -/** - * This method searches this string for the first character - * found in the given charset - * @param aString contains set of chars to be found - * @param anOffset tells us where to start searching in this - * @return -1 if not found, else the offset in this - */ -PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const; -PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; -PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; + /** + * This method searches this string for the first character + * found in the given charset + * @param aString contains set of chars to be found + * @param anOffset tells us where to start searching in this + * @return -1 if not found, else the offset in this + */ + PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const; + PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; + PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; -/** - * This methods scans the string backwards, looking for the given string - * @param aString is substring to be sought in this - * @param aIgnoreCase tells us whether or not to do caseless compare - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + /** + * This methods scans the string backwards, looking for the given string + * @param aString is substring to be sought in this + * @param aIgnoreCase tells us whether or not to do caseless compare + * @return offset in string, or -1 (kNotFound) + */ + PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -/** - * Search for given char within this string - * - * @param aString is substring to be sought in this - * @param anOffset tells us where in this strig to start searching - * @param aIgnoreCase selects case sensitivity - * @return find pos in string, or -1 (kNotFound) - */ -PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + /** + * Search for given char within this string + * + * @param aString is substring to be sought in this + * @param anOffset tells us where in this strig to start searching + * @param aIgnoreCase selects case sensitivity + * @return find pos in string, or -1 (kNotFound) + */ + PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -/** - * This method searches this string for the last character - * found in the given string - * @param aString contains set of chars to be found - * @param anOffset tells us where to start searching in this - * @return -1 if not found, else the offset in this - */ -PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const; -PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; -PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; + /** + * This method searches this string for the last character + * found in the given string + * @param aString contains set of chars to be found + * @param anOffset tells us where to start searching in this + * @return -1 if not found, else the offset in this + */ + PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const; + PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; + PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; -/********************************************************************** - Comparison methods... - *********************************************************************/ + /********************************************************************** + Comparison methods... + *********************************************************************/ -/** - * Compares a given string type to this string. - * @update gess 7/27/98 - * @param S is the string to be compared - * @param aIgnoreCase tells us how to treat case - * @param aCount tells us how many chars to compare - * @return -1,0,1 - */ -virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + /** + * Compares a given string type to this string. + * @update gess 7/27/98 + * @param S is the string to be compared + * @param aIgnoreCase tells us how to treat case + * @param aCount tells us how many chars to compare + * @return -1,0,1 + */ + virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -/** - * These methods compare a given string type to this one - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator==(const nsStr &aString) const; -PRBool operator==(const char* aString) const; -PRBool operator==(const PRUnichar* aString) const; + /** + * These methods compare a given string type to this one + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator==(const nsStr &aString) const; + PRBool operator==(const char* aString) const; + PRBool operator==(const PRUnichar* aString) const; -/** - * These methods perform a !compare of a given string type to this - * @param aString is the string to be compared to this - * @return TRUE - */ -PRBool operator!=(const nsStr &aString) const; -PRBool operator!=(const char* aString) const; -PRBool operator!=(const PRUnichar* aString) const; + /** + * These methods perform a !compare of a given string type to this + * @param aString is the string to be compared to this + * @return TRUE + */ + PRBool operator!=(const nsStr &aString) const; + PRBool operator!=(const char* aString) const; + PRBool operator!=(const PRUnichar* aString) const; -/** - * These methods test if a given string is < than this - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator<(const nsStr &aString) const; -PRBool operator<(const char* aString) const; -PRBool operator<(const PRUnichar* aString) const; + /** + * These methods test if a given string is < than this + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator<(const nsStr &aString) const; + PRBool operator<(const char* aString) const; + PRBool operator<(const PRUnichar* aString) const; -/** - * These methods test if a given string is > than this - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator>(const nsStr &S) const; -PRBool operator>(const char* aString) const; -PRBool operator>(const PRUnichar* aString) const; + /** + * These methods test if a given string is > than this + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator>(const nsStr &S) const; + PRBool operator>(const char* aString) const; + PRBool operator>(const PRUnichar* aString) const; -/** - * These methods test if a given string is <= than this - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator<=(const nsStr &S) const; -PRBool operator<=(const char* aString) const; -PRBool operator<=(const PRUnichar* aString) const; + /** + * These methods test if a given string is <= than this + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator<=(const nsStr &S) const; + PRBool operator<=(const char* aString) const; + PRBool operator<=(const PRUnichar* aString) const; -/** - * These methods test if a given string is >= than this - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator>=(const nsStr &S) const; -PRBool operator>=(const char* aString) const; -PRBool operator>=(const PRUnichar* aString) const; + /** + * These methods test if a given string is >= than this + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator>=(const nsStr &S) const; + PRBool operator>=(const char* aString) const; + PRBool operator>=(const PRUnichar* aString) const; -/** - * Compare this to given string; note that we compare full strings here. - * The optional length argument just lets us know how long the given string is. - * If you provide a length, it is compared to length of this string as an - * optimization. - * - * @param aString -- the string to compare to this - * @param aCount -- number of chars in given string you want to compare - * @return TRUE if equal - */ -PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + /** + * Compare this to given string; note that we compare full strings here. + * The optional length argument just lets us know how long the given string is. + * If you provide a length, it is compared to length of this string as an + * optimization. + * + * @param aString -- the string to compare to this + * @param aCount -- number of chars in given string you want to compare + * @return TRUE if equal + */ + PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -PRBool EqualsIgnoreCase(const nsStr& aString) const; -PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const; -PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const; + PRBool EqualsIgnoreCase(const nsStr& aString) const; + PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const; + PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const; -static void Recycle(nsCString* aString); -static nsCString* CreateString(void); - - - nsIMemoryAgent* mAgent; + static void Recycle(nsCString* aString); + static nsCString* CreateString(void); }; diff --git a/mozilla/xpcom/string/obsolete/nsString2.cpp b/mozilla/xpcom/string/obsolete/nsString2.cpp index 84553e38e94..edc080b2073 100644 --- a/mozilla/xpcom/string/obsolete/nsString2.cpp +++ b/mozilla/xpcom/string/obsolete/nsString2.cpp @@ -38,7 +38,7 @@ static const char* kWhitespace="\b\t\r\n "; static void Subsume(nsStr& aDest,nsStr& aSource){ if(aSource.mStr && aSource.mLength) { if(aSource.mOwnsBuffer){ - nsStr::Destroy(aDest,0); + nsStr::Destroy(aDest); aDest.mStr=aSource.mStr; aDest.mLength=aSource.mLength; aDest.mCharSize=aSource.mCharSize; @@ -48,17 +48,17 @@ static void Subsume(nsStr& aDest,nsStr& aSource){ aSource.mStr=0; } else{ - nsStr::Assign(aDest,aSource,0,aSource.mLength,0); + nsStr::Assign(aDest,aSource,0,aSource.mLength); } } - else nsStr::Truncate(aDest,0,0); + else nsStr::Truncate(aDest,0); } /** * Default constructor. */ -nsString::nsString(nsIMemoryAgent* anAgent) : mAgent(anAgent) { +nsString::nsString() { nsStr::Initialize(*this,eTwoByte); } @@ -68,7 +68,7 @@ nsString::nsString(nsIMemoryAgent* anAgent) : mAgent(anAgent) { * @param aCString is a ptr to a 1-byte cstr * @param aLength tells us how many chars to copy from given CString */ -nsString::nsString(const char* aCString,nsIMemoryAgent* anAgent) : mAgent(anAgent) { +nsString::nsString(const char* aCString){ nsStr::Initialize(*this,eTwoByte); Assign(aCString); } @@ -79,7 +79,7 @@ nsString::nsString(const char* aCString,nsIMemoryAgent* anAgent) : mAgent(anAgen * @param aString is a ptr to a unichar string * @param aLength tells us how many chars to copy from given aString */ -nsString::nsString(const PRUnichar* aString,nsIMemoryAgent* anAgent) : mAgent(anAgent) { +nsString::nsString(const PRUnichar* aString) { nsStr::Initialize(*this,eTwoByte); Assign(aString); } @@ -89,9 +89,9 @@ nsString::nsString(const PRUnichar* aString,nsIMemoryAgent* anAgent) : mAgent(an * @update gess 1/4/99 * @param reference to another nsCString */ -nsString::nsString(const nsStr &aString,nsIMemoryAgent* anAgent) : mAgent(anAgent) { +nsString::nsString(const nsStr &aString) { nsStr::Initialize(*this,eTwoByte); - nsStr::Assign(*this,aString,0,aString.mLength,mAgent); + nsStr::Assign(*this,aString,0,aString.mLength); } /** @@ -99,9 +99,9 @@ nsString::nsString(const nsStr &aString,nsIMemoryAgent* anAgent) : mAgent(anAgen * @update gess 1/4/99 * @param reference to another nsString */ -nsString::nsString(const nsString& aString) :mAgent(aString.mAgent) { +nsString::nsString(const nsString& aString) { nsStr::Initialize(*this,eTwoByte); - nsStr::Assign(*this,aString,0,aString.mLength,mAgent); + nsStr::Assign(*this,aString,0,aString.mLength); } /** @@ -109,7 +109,7 @@ nsString::nsString(const nsString& aString) :mAgent(aString.mAgent) { * @update gess 1/4/99 * @param reference to a subsumeString */ -nsString::nsString(nsSubsumeStr& aSubsumeStr) :mAgent(0) { +nsString::nsString(nsSubsumeStr& aSubsumeStr) { nsStr::Initialize(*this,eTwoByte); Subsume(*this,aSubsumeStr); } @@ -119,7 +119,7 @@ nsString::nsString(nsSubsumeStr& aSubsumeStr) :mAgent(0) { * Make sure we call nsStr::Destroy. */ nsString::~nsString() { - nsStr::Destroy(*this,mAgent); + nsStr::Destroy(*this); } void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const { @@ -136,7 +136,7 @@ void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const { * @return nada */ void nsString::Truncate(PRInt32 anIndex) { - nsStr::Truncate(*this,anIndex,mAgent); + nsStr::Truncate(*this,anIndex); } /** @@ -173,7 +173,7 @@ PRBool nsString::IsOrdered(void) const { */ void nsString::SetCapacity(PRUint32 aLength) { if(aLength>mCapacity) { - GrowCapacity(*this,aLength,mAgent); + GrowCapacity(*this,aLength); } AddNullTerminator(*this); } @@ -270,7 +270,7 @@ PRBool nsString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){ */ nsSubsumeStr nsString::operator+(const nsStr& aString){ nsString temp(*this); //make a temp string the same size as this... - nsStr::Append(temp,aString,0,aString.mLength,mAgent); + nsStr::Append(temp,aString,0,aString.mLength); return nsSubsumeStr(temp); } @@ -282,7 +282,7 @@ nsSubsumeStr nsString::operator+(const nsStr& aString){ */ nsSubsumeStr nsString::operator+(const nsString& aString){ nsString temp(*this); //make a temp string the same size as this... - nsStr::Append(temp,aString,0,aString.mLength,mAgent); + nsStr::Append(temp,aString,0,aString.mLength); return nsSubsumeStr(temp); } @@ -786,54 +786,55 @@ static PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadi * @return non-zero error code if this string is non-numeric */ static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) { + static const char* validChars="0123456789abcdefABCDEF-+#"; - aString.ToUpperCase(); + const char* cp=aString.GetBuffer(); + PRInt32 result=NS_ERROR_ILLEGAL_VALUE; + if(cp) { - PRInt32 decPt=nsStr::FindChar(aString,'.',PR_TRUE,0); - char* cp = (kNotFound==decPt) ? aString.mStr + aString.mLength-1 : aString.mStr+decPt-1; - - aRadix=kRadixUnknown; //assume for starters... + //begin by skipping over leading chars that shouldn't be part of the number... + + char* to=(char*)cp; + const char* endcp=cp+aString.mLength; + int len=strlen(validChars); - // Skip trailing non-numeric... - while (cp >= aString.mStr) { - if((*cp>='0') && (*cp<='9')){ - if(kRadixUnknown==aRadix) - aRadix=kRadix10; - break; + while(cp='A') && (*cp<='F')) { - aRadix=16; - break; - } - cp--; + + while(cp='0') && (theChar<='9')) { + *to++=theChar; + } + else if((theChar>='A') && (theChar<='F')) { + aRadix=16; + *to++=theChar; + } + else if('X'==theChar){ + if('-'==aString.mStr[0]) + to=&aString.mStr[1]; + else to=aString.mStr; + aRadix=16; + //root=cp; + } + else if('-'==theChar) { + *to++=theChar; + } + else if(('#'==theChar) || ('+'==theChar)){ + //just skip this char... + } + else break; + cp++; + } + aString.Truncate(to-aString.mStr); + result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; } - aString.Truncate(cp-aString.mStr+1); - - //ok, now scan through chars until you find the start of this number... - //we delimit the number by the presence of: +,-,#,X - - // Skip trailing non-numeric... - cp++; - while (--cp >= aString.mStr) { - if((*cp>='0') && (*cp<='9')){ - continue; - } - else if((*cp>='A') && (*cp<='F')) { - continue; - } - else if((*cp=='-') || (*cp=='+')){ - break; - } - else { - if(('#'==(*cp)) || ('X'==(*cp))) - aRadix=kRadix16; - cp++; //move back by one - break; - } - } - if(cp>aString.mStr) - aString.Cut(0,cp-aString.mStr); - PRInt32 result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; return result; } @@ -865,10 +866,10 @@ PRUint32 nsString::DetermineRadix(void) { PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const { //copy chars to local buffer -- step down from 2 bytes to 1 if necessary... + PRInt32 result=0; nsCAutoString theString(*this); PRUint32 theRadix=aRadix; - PRInt32 result=0; - + *anErrorCode=GetNumericSubstring(theString,theRadix); //we actually don't use this radix; use given radix instead if(NS_OK==*anErrorCode){ if(kAutoDetect==aRadix) @@ -893,13 +894,13 @@ PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const { */ nsString& nsString::Assign(const nsStr& aString,PRInt32 aCount) { if(this!=&aString){ - nsStr::Truncate(*this,0,0); + nsStr::Truncate(*this,0); if(aCount<0) aCount=aString.mLength; else aCount=MinInt(aCount,aString.mLength); - nsStr::Assign(*this,aString,0,aCount,mAgent); + nsStr::Assign(*this,aString,0,aCount); } return *this; } @@ -912,7 +913,7 @@ nsString& nsString::Assign(const nsStr& aString,PRInt32 aCount) { * @return this */ nsString& nsString::Assign(const char* aCString,PRInt32 aCount) { - nsStr::Truncate(*this,0,0); + nsStr::Truncate(*this,0); if(aCString){ Append(aCString,aCount); } @@ -926,7 +927,7 @@ nsString& nsString::Assign(const char* aCString,PRInt32 aCount) { * @return this */ nsString& nsString::Assign(const PRUnichar* aString,PRInt32 aCount) { - nsStr::Truncate(*this,0,0); + nsStr::Truncate(*this,0); if(aString){ Append(aString,aCount); } @@ -940,7 +941,7 @@ nsString& nsString::Assign(const PRUnichar* aString,PRInt32 aCount) { * @return this */ nsString& nsString::Assign(char aChar) { - nsStr::Truncate(*this,0,0); + nsStr::Truncate(*this,0); return Append(aChar); } @@ -951,7 +952,7 @@ nsString& nsString::Assign(char aChar) { * @return this */ nsString& nsString::Assign(PRUnichar aChar) { - nsStr::Truncate(*this,0,0); + nsStr::Truncate(*this,0); return Append(aChar); } @@ -988,7 +989,7 @@ nsString& nsString::Append(const nsStr& aString,PRInt32 aCount) { else aCount=MinInt(aCount,aString.mLength); if(0=1) { - PRInt32 div=theInt/mask1; - if((div) || (!isfirst)) { - buf[charpos++]="0123456789abcdef"[div]; + PRInt32 theDiv=theInt/mask1; + if((theDiv) || (!isfirst)) { + buf[charpos++]="0123456789abcdef"[theDiv]; isfirst=PR_FALSE; } - theInt-=div*mask1; + theInt-=theDiv*mask1; mask1/=aRadix; } return Append(buf); @@ -1173,7 +1174,7 @@ PRUint32 nsString::Left(nsString& aDest,PRInt32 aCount) const{ if(aCount<0) aCount=mLength; else aCount=MinInt(aCount,mLength); - nsStr::Assign(aDest,*this,0,aCount,mAgent); + nsStr::Assign(aDest,*this,0,aCount); return aDest.mLength; } @@ -1191,7 +1192,7 @@ PRUint32 nsString::Mid(nsString& aDest,PRUint32 anOffset,PRInt32 aCount) const{ if(aCount<0) aCount=mLength; else aCount=MinInt(aCount,mLength); - nsStr::Assign(aDest,*this,anOffset,aCount,mAgent); + nsStr::Assign(aDest,*this,anOffset,aCount); return aDest.mLength; } @@ -1221,7 +1222,7 @@ PRUint32 nsString::Right(nsString& aDest,PRInt32 aCount) const{ * @return this */ nsString& nsString::Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) { - nsStr::Insert(*this,anOffset,aCopy,0,aCount,mAgent); + nsStr::Insert(*this,anOffset,aCopy,0,aCount); return *this; } @@ -1252,7 +1253,7 @@ nsString& nsString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCount else aCount=temp.mLength=nsCRT::strlen(aCString); if(0mAgent=&theAgent; delete aString; } return 0; @@ -2116,7 +2115,6 @@ NS_COM int fputs(const nsString& aString, FILE* out) */ nsAutoString::nsAutoString() : nsString() { nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); - mAgent=0; AddNullTerminator(*this); } @@ -2127,7 +2125,6 @@ nsAutoString::nsAutoString() : nsString() { */ nsAutoString::nsAutoString(const char* aCString,PRInt32 aLength) : nsString() { nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); - mAgent=0; AddNullTerminator(*this); Append(aCString,aLength); } @@ -2138,7 +2135,6 @@ nsAutoString::nsAutoString(const char* aCString,PRInt32 aLength) : nsString() { * @param aLength tells us how many chars to copy from aString */ nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString() { - mAgent=0; nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); AddNullTerminator(*this); Append(aString,aLength); @@ -2149,7 +2145,6 @@ nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString( * @param aBuffer describes the external buffer */ nsAutoString::nsAutoString(const CBufDescriptor& aBuffer) : nsString() { - mAgent=0; if(!aBuffer.mBuffer) { nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); } @@ -2166,7 +2161,6 @@ nsAutoString::nsAutoString(const CBufDescriptor& aBuffer) : nsString() { * @param */ nsAutoString::nsAutoString(const nsStr& aString) : nsString() { - mAgent=0; nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); AddNullTerminator(*this); Append(aString); @@ -2176,7 +2170,6 @@ nsAutoString::nsAutoString(const nsStr& aString) : nsString() { * Default copy constructor */ nsAutoString::nsAutoString(const nsAutoString& aString) : nsString() { - mAgent=0; nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); AddNullTerminator(*this); Append(aString); @@ -2188,7 +2181,6 @@ nsAutoString::nsAutoString(const nsAutoString& aString) : nsString() { * @param */ nsAutoString::nsAutoString(PRUnichar aChar) : nsString(){ - mAgent=0; nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); AddNullTerminator(*this); Append(aChar); @@ -2201,12 +2193,10 @@ nsAutoString::nsAutoString(PRUnichar aChar) : nsString(){ */ #ifdef AIX nsAutoString::nsAutoString(const nsSubsumeStr& aSubsumeStr) :nsString() { - mAgent=0; nsSubsumeStr temp(aSubsumeStr); // a temp is needed for the AIX compiler Subsume(*this,temp); #else nsAutoString::nsAutoString( nsSubsumeStr& aSubsumeStr) :nsString() { - mAgent=0; Subsume(*this,aSubsumeStr); #endif // AIX } diff --git a/mozilla/xpcom/string/obsolete/nsString2.h b/mozilla/xpcom/string/obsolete/nsString2.h index 80332198c4d..a22ca6b7c04 100644 --- a/mozilla/xpcom/string/obsolete/nsString2.h +++ b/mozilla/xpcom/string/obsolete/nsString2.h @@ -53,716 +53,716 @@ class nsISizeOfHandler; class NS_COM nsSubsumeStr; class NS_COM nsString : public nsStr { - public: +public: -/** - * Default constructor. - */ -nsString(nsIMemoryAgent* anAgent=0); - - -/** - * This constructor accepts an isolatin string - * @param aCString is a ptr to a 1-byte cstr - */ -nsString(const char* aCString,nsIMemoryAgent* anAgent=0); - -/** - * This constructor accepts a unichar string - * @param aCString is a ptr to a 2-byte cstr - */ -nsString(const PRUnichar* aString,nsIMemoryAgent* anAgent=0); - -/** - * This is a copy constructor that accepts an nsStr - * @param reference to another nsString - */ -nsString(const nsStr&,nsIMemoryAgent* anAgent=0); - -/** - * This is our copy constructor - * @param reference to another nsString - */ -nsString(const nsString& aString); - -/** - * This constructor takes a subsumestr - * @param reference to subsumestr - */ -nsString(nsSubsumeStr& aSubsumeStr); - -/** - * Destructor - * - */ -virtual ~nsString(); - -/** - * Retrieve the length of this string - * @return string length - */ -inline PRInt32 Length() const { return (PRInt32)mLength; } - -/** - * Retrieve the size of this string - * @return string length - */ -virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const; - - -/** - * Call this method if you want to force a different string length - * @update gess7/30/98 - * @param aLength -- contains new length for mStr - * @return - */ -void SetLength(PRUint32 aLength) { - Truncate(aLength); -} - -/** - * Sets the new length of the string. - * @param aLength is new string length. - * @return nada - */ -void SetCapacity(PRUint32 aLength); - -/** - * This method truncates this string to given length. - * - * @param anIndex -- new length of string - * @return nada - */ -void Truncate(PRInt32 anIndex=0); - - -/** - * Determine whether or not the characters in this - * string are in sorted order. - * - * @return TRUE if ordered. - */ -PRBool IsOrdered(void) const; - -/** - * Determine whether or not the characters in this - * string are in store as 1 or 2 byte (unicode) strings. - * - * @return TRUE if ordered. - */ -PRBool IsUnicode(void) const { - PRBool result=PRBool(mCharSize==eTwoByte); - return result; -} - -/** - * Determine whether or not this string has a length of 0 - * - * @return TRUE if empty. - */ -PRBool IsEmpty(void) const { - return PRBool(0==mLength); -} - -/********************************************************************** - Getters/Setters... - *********************************************************************/ - -const char* GetBuffer(void) const; -const PRUnichar* GetUnicode(void) const; - - - /** - * Get nth character. + /** + * Default constructor. */ -PRUnichar operator[](PRUint32 anIndex) const; -PRUnichar CharAt(PRUint32 anIndex) const; -PRUnichar First(void) const; -PRUnichar Last(void) const; + nsString(); - /** - * Set nth character. + + /** + * This constructor accepts an isolatin string + * @param aCString is a ptr to a 1-byte cstr */ -PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex); + nsString(const char* aCString); + + /** + * This constructor accepts a unichar string + * @param aCString is a ptr to a 2-byte cstr + */ + nsString(const PRUnichar* aString); + + /** + * This is a copy constructor that accepts an nsStr + * @param reference to another nsString + */ + nsString(const nsStr&); + + /** + * This is our copy constructor + * @param reference to another nsString + */ + nsString(const nsString& aString); + + /** + * This constructor takes a subsumestr + * @param reference to subsumestr + */ + nsString(nsSubsumeStr& aSubsumeStr); + + /** + * Destructor + * + */ + virtual ~nsString(); + + /** + * Retrieve the length of this string + * @return string length + */ + inline PRInt32 Length() const { return (PRInt32)mLength; } + + /** + * Retrieve the size of this string + * @return string length + */ + virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const; -/********************************************************************** - String concatenation methods... - *********************************************************************/ + /** + * Call this method if you want to force a different string length + * @update gess7/30/98 + * @param aLength -- contains new length for mStr + * @return + */ + void SetLength(PRUint32 aLength) { + Truncate(aLength); + } -/** - * Create a new string by appending given string to this - * @param aString -- 2nd string to be appended - * @return new subsumable string - */ -nsSubsumeStr operator+(const nsStr& aString); -nsSubsumeStr operator+(const nsString& aString); + /** + * Sets the new length of the string. + * @param aLength is new string length. + * @return nada + */ + void SetCapacity(PRUint32 aLength); -/** - * create a new string by adding this to the given cstring - * @param aCString is a ptr to cstring to be added to this - * @return newly created string - */ -nsSubsumeStr operator+(const char* aCString); - -/** - * create a new string by adding this to the given prunichar*. - * @param aString is a ptr to UC-string to be added to this - * @return newly created string - */ -nsSubsumeStr operator+(const PRUnichar* aString); - -/** - * create a new string by adding this to the given char. - * @param aChar is a char to be added to this - * @return newly created string - */ -nsSubsumeStr operator+(char aChar); - -/** - * create a new string by adding this to the given char. - * @param aChar is a unichar to be added to this - * @return newly created string - */ -nsSubsumeStr operator+(PRUnichar aChar); - -/********************************************************************** - Lexomorphic transforms... - *********************************************************************/ + /** + * This method truncates this string to given length. + * + * @param anIndex -- new length of string + * @return nada + */ + void Truncate(PRInt32 anIndex=0); -/** - * Converts chars in this to lowercase - * @update gess 7/27/98 - */ -void ToLowerCase(); + /** + * Determine whether or not the characters in this + * string are in sorted order. + * + * @return TRUE if ordered. + */ + PRBool IsOrdered(void) const; + + /** + * Determine whether or not the characters in this + * string are in store as 1 or 2 byte (unicode) strings. + * + * @return TRUE if ordered. + */ + PRBool IsUnicode(void) const { + PRBool result=PRBool(mCharSize==eTwoByte); + return result; + } + + /** + * Determine whether or not this string has a length of 0 + * + * @return TRUE if empty. + */ + PRBool IsEmpty(void) const { + return PRBool(0==mLength); + } + + /********************************************************************** + Getters/Setters... + *********************************************************************/ + + /** + * Retrieve const ptr to internal buffer; DO NOT TRY TO FREE IT! + */ + const char* GetBuffer(void) const; + const PRUnichar* GetUnicode(void) const; -/** - * Converts chars in this to lowercase, and - * stores them in aOut - * @update gess 7/27/98 - * @param aOut is a string to contain result - */ -void ToLowerCase(nsString& aString) const; + /** + * Get nth character. + */ + PRUnichar operator[](PRUint32 anIndex) const; + PRUnichar CharAt(PRUint32 anIndex) const; + PRUnichar First(void) const; + PRUnichar Last(void) const; -/** - * Converts chars in this to uppercase - * @update gess 7/27/98 - */ -void ToUpperCase(); - -/** - * Converts chars in this to lowercase, and - * stores them in a given output string - * @update gess 7/27/98 - * @param aOut is a string to contain result - */ -void ToUpperCase(nsString& aString) const; + /** + * Set nth character. + */ + PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex); -/** - * This method is used to remove all occurances of the - * characters found in aSet from this string. - * - * @param aSet -- characters to be cut from this - * @return *this - */ -nsString& StripChars(const char* aSet); -nsString& StripChar(char aChar); + /********************************************************************** + String concatenation methods... + *********************************************************************/ -/** - * This method strips whitespace throughout the string - * - * @return this - */ -nsString& StripWhitespace(); + /** + * Create a new string by appending given string to this + * @param aString -- 2nd string to be appended + * @return new subsumable string + */ + nsSubsumeStr operator+(const nsStr& aString); + nsSubsumeStr operator+(const nsString& aString); -/** - * swaps occurence of 1 string for another - * - * @return this - */ -nsString& ReplaceChar(PRUnichar anOldChar,PRUnichar aNewChar); -nsString& ReplaceChar(const char* aSet,PRUnichar aNewChar); + /** + * create a new string by adding this to the given cstring + * @param aCString is a ptr to cstring to be added to this + * @return newly created string + */ + nsSubsumeStr operator+(const char* aCString); -PRInt32 CountChar(PRUnichar aChar); + /** + * create a new string by adding this to the given prunichar*. + * @param aString is a ptr to UC-string to be added to this + * @return newly created string + */ + nsSubsumeStr operator+(const PRUnichar* aString); -/** - * This method trims characters found in aTrimSet from - * either end of the underlying string. - * - * @param aTrimSet -- contains chars to be trimmed from - * both ends - * @return this - */ -nsString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + /** + * create a new string by adding this to the given char. + * @param aChar is a char to be added to this + * @return newly created string + */ + nsSubsumeStr operator+(char aChar); -/** - * This method strips whitespace from string. - * You can control whether whitespace is yanked from - * start and end of string as well. - * - * @param aEliminateLeading controls stripping of leading ws - * @param aEliminateTrailing controls stripping of trailing ws - * @return this - */ -nsString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + /** + * create a new string by adding this to the given char. + * @param aChar is a unichar to be added to this + * @return newly created string + */ + nsSubsumeStr operator+(PRUnichar aChar); -/** - * This method strips whitespace from string. - * You can control whether whitespace is yanked from - * start and end of string as well. - * - * @param aEliminateLeading controls stripping of leading ws - * @param aEliminateTrailing controls stripping of trailing ws - * @return this - */ -nsString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); - -/********************************************************************** - string conversion methods... - *********************************************************************/ - -/** - * This method constructs a new nsString is a clone of this string. - * - */ -nsString* ToNewString() const; - -/** - * Creates an ISOLatin1 clone of this string - * Note that calls to this method should be matched with calls to Recycle(). - * @return ptr to new isolatin1 string - */ -char* ToNewCString() const; - -/** - * Creates an UTF8 clone of this string - * Note that calls to this method should be matched with calls to Recycle(). - * @return ptr to new isolatin1 string - */ -char* ToNewUTF8String() const; - -/** - * Creates a unicode clone of this string - * Note that calls to this method should be matched with calls to Recycle(). - * @return ptr to new unicode string - */ -PRUnichar* ToNewUnicode() const; - -/** - * Copies data from internal buffer onto given char* buffer - * NOTE: This only copies as many chars as will fit in given buffer (clips) - * @param aBuf is the buffer where data is stored - * @param aBuflength is the max # of chars to move to buffer - * @return ptr to given buffer - */ -char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const; - -/** - * Perform string to float conversion. - * @param aErrorCode will contain error if one occurs - * @return float rep of string value - */ -float ToFloat(PRInt32* aErrorCode) const; - -/** - * Try to derive the radix from the value contained in this string - * @return kRadix10, kRadix16 or kAutoDetect (meaning unknown) - */ -PRUint32 DetermineRadix(void); - -/** - * Perform string to int conversion. - * @param aErrorCode will contain error if one occurs - * @return int rep of string value - */ -PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const; + /********************************************************************** + Lexomorphic transforms... + *********************************************************************/ -/********************************************************************** - String manipulation methods... - *********************************************************************/ + /** + * Converts chars in this to lowercase + * @update gess 7/27/98 + */ + void ToLowerCase(); -/** - * Functionally equivalent to assign or operator= - * - */ -nsString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} -nsString& SetString(const PRUnichar* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} -nsString& SetString(const nsString& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} -/** - * assign given string to this string - * @param aStr: buffer to be assigned to this - * @param alength is the length of the given str (or -1) - if you want me to determine its length - * @return this - */ -nsString& Assign(const nsStr& aString,PRInt32 aCount=-1); -nsString& Assign(const char* aString,PRInt32 aCount=-1); -nsString& Assign(const PRUnichar* aString,PRInt32 aCount=-1); -nsString& Assign(char aChar); -nsString& Assign(PRUnichar aChar); + /** + * Converts chars in this to lowercase, and + * stores them in aOut + * @update gess 7/27/98 + * @param aOut is a string to contain result + */ + void ToLowerCase(nsString& aString) const; -/** - * here come a bunch of assignment operators... - * @param aString: string to be added to this - * @return this - */ -nsString& operator=(const nsString& aString) {return Assign(aString);} -nsString& operator=(const nsStr& aString) {return Assign(aString);} -nsString& operator=(char aChar) {return Assign(aChar);} -nsString& operator=(PRUnichar aChar) {return Assign(aChar);} -nsString& operator=(const char* aCString) {return Assign(aCString);} -nsString& operator=(const PRUnichar* aString) {return Assign(aString);} -#ifdef AIX -nsString& operator=(const nsSubsumeStr& aSubsumeString); // AIX requires a const here -#else -nsString& operator=(nsSubsumeStr& aSubsumeString); -#endif + /** + * Converts chars in this to uppercase + * @update gess 7/27/98 + */ + void ToUpperCase(); -/** - * Here's a bunch of methods that append varying types... - * @param various... - * @return this - */ -nsString& operator+=(const nsStr& aString){return Append(aString,aString.mLength);} -nsString& operator+=(const nsString& aString){return Append(aString,aString.mLength);} -nsString& operator+=(const char* aCString) {return Append(aCString);} -//nsString& operator+=(char aChar){return Append(aChar);} -nsString& operator+=(const PRUnichar* aUCString) {return Append(aUCString);} -nsString& operator+=(PRUnichar aChar){return Append(aChar);} + /** + * Converts chars in this to lowercase, and + * stores them in a given output string + * @update gess 7/27/98 + * @param aOut is a string to contain result + */ + void ToUpperCase(nsString& aString) const; -/* - * Appends n characters from given string to this, - * This version computes the length of your given string - * - * @param aString is the source to be appended to this - * @return number of chars copied - */ -nsString& Append(const nsStr& aString) {return Append(aString,aString.mLength);} -nsString& Append(const nsString& aString) {return Append(aString,aString.mLength);} + + /** + * This method is used to remove all occurances of the + * characters found in aSet from this string. + * + * @param aSet -- characters to be cut from this + * @return *this + */ + nsString& StripChars(const char* aSet); + nsString& StripChar(char aChar); + + /** + * This method strips whitespace throughout the string + * + * @return this + */ + nsString& StripWhitespace(); + + /** + * swaps occurence of 1 string for another + * + * @return this + */ + nsString& ReplaceChar(PRUnichar anOldChar,PRUnichar aNewChar); + nsString& ReplaceChar(const char* aSet,PRUnichar aNewChar); + + PRInt32 CountChar(PRUnichar aChar); + + /** + * This method trims characters found in aTrimSet from + * either end of the underlying string. + * + * @param aTrimSet -- contains chars to be trimmed from + * both ends + * @return this + */ + nsString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + + /** + * This method strips whitespace from string. + * You can control whether whitespace is yanked from + * start and end of string as well. + * + * @param aEliminateLeading controls stripping of leading ws + * @param aEliminateTrailing controls stripping of trailing ws + * @return this + */ + nsString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + + /** + * This method strips whitespace from string. + * You can control whether whitespace is yanked from + * start and end of string as well. + * + * @param aEliminateLeading controls stripping of leading ws + * @param aEliminateTrailing controls stripping of trailing ws + * @return this + */ + nsString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + + /********************************************************************** + string conversion methods... + *********************************************************************/ + + /** + * This method constructs a new nsString is a clone of this string. + * + */ + nsString* ToNewString() const; + + /** + * Creates an ISOLatin1 clone of this string + * Note that calls to this method should be matched with calls to Recycle(). + * @return ptr to new isolatin1 string + */ + char* ToNewCString() const; + + /** + * Creates an UTF8 clone of this string + * Note that calls to this method should be matched with calls to Recycle(). + * @return ptr to new isolatin1 string + */ + char* ToNewUTF8String() const; + + /** + * Creates a unicode clone of this string + * Note that calls to this method should be matched with calls to Recycle(). + * @return ptr to new unicode string + */ + PRUnichar* ToNewUnicode() const; + + /** + * Copies data from internal buffer onto given char* buffer + * NOTE: This only copies as many chars as will fit in given buffer (clips) + * @param aBuf is the buffer where data is stored + * @param aBuflength is the max # of chars to move to buffer + * @return ptr to given buffer + */ + char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const; + + /** + * Perform string to float conversion. + * @param aErrorCode will contain error if one occurs + * @return float rep of string value + */ + float ToFloat(PRInt32* aErrorCode) const; + + /** + * Try to derive the radix from the value contained in this string + * @return kRadix10, kRadix16 or kAutoDetect (meaning unknown) + */ + PRUint32 DetermineRadix(void); + + /** + * Perform string to int conversion. + * @param aErrorCode will contain error if one occurs + * @return int rep of string value + */ + PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const; + + + /********************************************************************** + String manipulation methods... + *********************************************************************/ + + /** + * Functionally equivalent to assign or operator= + * + */ + nsString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} + nsString& SetString(const PRUnichar* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} + nsString& SetString(const nsString& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} + + /** + * assign given string to this string + * @param aStr: buffer to be assigned to this + * @param alength is the length of the given str (or -1) + if you want me to determine its length + * @return this + */ + nsString& Assign(const nsStr& aString,PRInt32 aCount=-1); + nsString& Assign(const char* aString,PRInt32 aCount=-1); + nsString& Assign(const PRUnichar* aString,PRInt32 aCount=-1); + nsString& Assign(char aChar); + nsString& Assign(PRUnichar aChar); + + /** + * here come a bunch of assignment operators... + * @param aString: string to be added to this + * @return this + */ + nsString& operator=(const nsString& aString) {return Assign(aString);} + nsString& operator=(const nsStr& aString) {return Assign(aString);} + nsString& operator=(char aChar) {return Assign(aChar);} + nsString& operator=(PRUnichar aChar) {return Assign(aChar);} + nsString& operator=(const char* aCString) {return Assign(aCString);} + nsString& operator=(const PRUnichar* aString) {return Assign(aString);} + #ifdef AIX + nsString& operator=(const nsSubsumeStr& aSubsumeString); // AIX requires a const here + #else + nsString& operator=(nsSubsumeStr& aSubsumeString); + #endif + + /** + * Here's a bunch of methods that append varying types... + * @param various... + * @return this + */ + nsString& operator+=(const nsStr& aString){return Append(aString,aString.mLength);} + nsString& operator+=(const nsString& aString){return Append(aString,aString.mLength);} + nsString& operator+=(const char* aCString) {return Append(aCString);} + //nsString& operator+=(char aChar){return Append(aChar);} + nsString& operator+=(const PRUnichar* aUCString) {return Append(aUCString);} + nsString& operator+=(PRUnichar aChar){return Append(aChar);} + + /* + * Appends n characters from given string to this, + * This version computes the length of your given string + * + * @param aString is the source to be appended to this + * @return number of chars copied + */ + nsString& Append(const nsStr& aString) {return Append(aString,aString.mLength);} + nsString& Append(const nsString& aString) {return Append(aString,aString.mLength);} -/* - * Appends n characters from given string to this, - * - * @param aString is the source to be appended to this - * @param aCount -- number of chars to copy; -1 tells us to compute the strlen for you - * @return number of chars copied - */ -nsString& Append(const nsStr& aString,PRInt32 aCount); -nsString& Append(const nsString& aString,PRInt32 aCount); -nsString& Append(const char* aString,PRInt32 aCount=-1); -nsString& Append(const PRUnichar* aString,PRInt32 aCount=-1); -nsString& Append(char aChar); -nsString& Append(PRUnichar aChar); -nsString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16 -nsString& Append(float aFloat); + /* + * Appends n characters from given string to this, + * + * @param aString is the source to be appended to this + * @param aCount -- number of chars to copy; -1 tells us to compute the strlen for you + * @return number of chars copied + */ + nsString& Append(const nsStr& aString,PRInt32 aCount); + nsString& Append(const nsString& aString,PRInt32 aCount); + nsString& Append(const char* aString,PRInt32 aCount=-1); + nsString& Append(const PRUnichar* aString,PRInt32 aCount=-1); + nsString& Append(char aChar); + nsString& Append(PRUnichar aChar); + nsString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16 + nsString& Append(float aFloat); -/* - * Copies n characters from this string to given string, - * starting at the leftmost offset. - * - * - * @param aCopy -- Receiving string - * @param aCount -- number of chars to copy - * @return number of chars copied - */ -PRUint32 Left(nsString& aCopy,PRInt32 aCount) const; + /* + * Copies n characters from this string to given string, + * starting at the leftmost offset. + * + * + * @param aCopy -- Receiving string + * @param aCount -- number of chars to copy + * @return number of chars copied + */ + PRUint32 Left(nsString& aCopy,PRInt32 aCount) const; -/* - * Copies n characters from this string to given string, - * starting at the given offset. - * - * - * @param aCopy -- Receiving string - * @param aCount -- number of chars to copy - * @param anOffset -- position where copying begins - * @return number of chars copied - */ -PRUint32 Mid(nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) const; + /* + * Copies n characters from this string to given string, + * starting at the given offset. + * + * + * @param aCopy -- Receiving string + * @param aCount -- number of chars to copy + * @param anOffset -- position where copying begins + * @return number of chars copied + */ + PRUint32 Mid(nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) const; -/* - * Copies n characters from this string to given string, - * starting at rightmost char. - * - * - * @param aCopy -- Receiving string - * @param aCount -- number of chars to copy - * @return number of chars copied - */ -PRUint32 Right(nsString& aCopy,PRInt32 aCount) const; + /* + * Copies n characters from this string to given string, + * starting at rightmost char. + * + * + * @param aCopy -- Receiving string + * @param aCount -- number of chars to copy + * @return number of chars copied + */ + PRUint32 Right(nsString& aCopy,PRInt32 aCount) const; -/* - * This method inserts n chars from given string into this - * string at str[anOffset]. - * - * @param aCopy -- String to be inserted into this - * @param anOffset -- insertion position within this str - * @param aCount -- number of chars to be copied from aCopy - * @return number of chars inserted into this. - */ -nsString& Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1); + /* + * This method inserts n chars from given string into this + * string at str[anOffset]. + * + * @param aCopy -- String to be inserted into this + * @param anOffset -- insertion position within this str + * @param aCount -- number of chars to be copied from aCopy + * @return number of chars inserted into this. + */ + nsString& Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1); -/** - * Insert a given string into this string at - * a specified offset. - * - * @param aString* to be inserted into this string - * @param anOffset is insert pos in str - * @return the number of chars inserted into this string - */ -nsString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1); -nsString& Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1); + /** + * Insert a given string into this string at + * a specified offset. + * + * @param aString* to be inserted into this string + * @param anOffset is insert pos in str + * @return the number of chars inserted into this string + */ + nsString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1); + nsString& Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1); -/** - * Insert a single char into this string at - * a specified offset. - * - * @param character to be inserted into this string - * @param anOffset is insert pos in str - * @return the number of chars inserted into this string - */ -//nsString& Insert(char aChar,PRUint32 anOffset); -nsString& Insert(PRUnichar aChar,PRUint32 anOffset); + /** + * Insert a single char into this string at + * a specified offset. + * + * @param character to be inserted into this string + * @param anOffset is insert pos in str + * @return the number of chars inserted into this string + */ + //nsString& Insert(char aChar,PRUint32 anOffset); + nsString& Insert(PRUnichar aChar,PRUint32 anOffset); -/* - * This method is used to cut characters in this string - * starting at anOffset, continuing for aCount chars. - * - * @param anOffset -- start pos for cut operation - * @param aCount -- number of chars to be cut - * @return *this - */ -nsString& Cut(PRUint32 anOffset,PRInt32 aCount); + /* + * This method is used to cut characters in this string + * starting at anOffset, continuing for aCount chars. + * + * @param anOffset -- start pos for cut operation + * @param aCount -- number of chars to be cut + * @return *this + */ + nsString& Cut(PRUint32 anOffset,PRInt32 aCount); -/********************************************************************** - Searching methods... - *********************************************************************/ + /********************************************************************** + Searching methods... + *********************************************************************/ -/** - * Search for given character within this string. - * This method does so by using a binary search, - * so your string HAD BETTER BE ORDERED! - * - * @param aChar is the unicode char to be found - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 BinarySearch(PRUnichar aChar) const; + /** + * Search for given character within this string. + * This method does so by using a binary search, + * so your string HAD BETTER BE ORDERED! + * + * @param aChar is the unicode char to be found + * @return offset in string, or -1 (kNotFound) + */ + PRInt32 BinarySearch(PRUnichar aChar) const; -/** - * Search for given substring within this string - * - * @param aString is substring to be sought in this - * @param aIgnoreCase selects case sensitivity - * @param anOffset tells us where in this strig to start searching - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + /** + * Search for given substring within this string + * + * @param aString is substring to be sought in this + * @param aIgnoreCase selects case sensitivity + * @param anOffset tells us where in this strig to start searching + * @return offset in string, or -1 (kNotFound) + */ + PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -/** - * Search for given char within this string - * - * @param aString is substring to be sought in this - * @param anOffset tells us where in this strig to start searching - * @param aIgnoreCase selects case sensitivity - * @return find pos in string, or -1 (kNotFound) - */ -//PRInt32 Find(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const; -PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + /** + * Search for given char within this string + * + * @param aString is substring to be sought in this + * @param anOffset tells us where in this strig to start searching + * @param aIgnoreCase selects case sensitivity + * @return find pos in string, or -1 (kNotFound) + */ + //PRInt32 Find(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const; + PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -/** - * This method searches this string for the first character - * found in the given charset - * @param aString contains set of chars to be found - * @param anOffset tells us where to start searching in this - * @return -1 if not found, else the offset in this - */ -PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const; -PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; -PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; + /** + * This method searches this string for the first character + * found in the given charset + * @param aString contains set of chars to be found + * @param anOffset tells us where to start searching in this + * @return -1 if not found, else the offset in this + */ + PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const; + PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; + PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; -/** - * This methods scans the string backwards, looking for the given string - * @param aString is substring to be sought in this - * @param aIgnoreCase tells us whether or not to do caseless compare - * @param anOffset tells us where in this strig to start searching (counting from left) - */ -PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + /** + * This methods scans the string backwards, looking for the given string + * @param aString is substring to be sought in this + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this strig to start searching (counting from left) + */ + PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -/** - * Search for given char within this string - * - * @param aString is substring to be sought in this - * @param anOffset tells us where in this strig to start searching (counting from left) - * @param aIgnoreCase selects case sensitivity - * @return find pos in string, or -1 (kNotFound) - */ -//PRInt32 RFind(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const; -PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + /** + * Search for given char within this string + * + * @param aString is substring to be sought in this + * @param anOffset tells us where in this strig to start searching (counting from left) + * @param aIgnoreCase selects case sensitivity + * @return find pos in string, or -1 (kNotFound) + */ + //PRInt32 RFind(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const; + PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; -/** - * This method searches this string for the last character - * found in the given string - * @param aString contains set of chars to be found - * @param anOffset tells us where in this strig to start searching (counting from left) - * @return -1 if not found, else the offset in this - */ -PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const; -PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; -PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; + /** + * This method searches this string for the last character + * found in the given string + * @param aString contains set of chars to be found + * @param anOffset tells us where in this strig to start searching (counting from left) + * @return -1 if not found, else the offset in this + */ + PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const; + PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; + PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const; -/********************************************************************** - Comparison methods... - *********************************************************************/ + /********************************************************************** + Comparison methods... + *********************************************************************/ -/** - * Compares a given string type to this string. - * @update gess 7/27/98 - * @param S is the string to be compared - * @param aIgnoreCase tells us how to treat case - * @param aCount tells us how many chars to compare - * @return -1,0,1 - */ -virtual PRInt32 Compare(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + /** + * Compares a given string type to this string. + * @update gess 7/27/98 + * @param S is the string to be compared + * @param aIgnoreCase tells us how to treat case + * @param aCount tells us how many chars to compare + * @return -1,0,1 + */ + virtual PRInt32 Compare(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -/** - * These methods compare a given string type to this one - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator==(const nsString &aString) const; -PRBool operator==(const nsStr &aString) const; -PRBool operator==(const char *aString) const; -PRBool operator==(const PRUnichar* aString) const; + /** + * These methods compare a given string type to this one + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator==(const nsString &aString) const; + PRBool operator==(const nsStr &aString) const; + PRBool operator==(const char *aString) const; + PRBool operator==(const PRUnichar* aString) const; -/** - * These methods perform a !compare of a given string type to this - * @param aString is the string to be compared to this - * @return TRUE - */ -PRBool operator!=(const nsString &aString) const; -PRBool operator!=(const nsStr &aString) const; -PRBool operator!=(const char* aString) const; -PRBool operator!=(const PRUnichar* aString) const; + /** + * These methods perform a !compare of a given string type to this + * @param aString is the string to be compared to this + * @return TRUE + */ + PRBool operator!=(const nsString &aString) const; + PRBool operator!=(const nsStr &aString) const; + PRBool operator!=(const char* aString) const; + PRBool operator!=(const PRUnichar* aString) const; -/** - * These methods test if a given string is < than this - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator<(const nsString &aString) const; -PRBool operator<(const nsStr &aString) const; -PRBool operator<(const char* aString) const; -PRBool operator<(const PRUnichar* aString) const; + /** + * These methods test if a given string is < than this + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator<(const nsString &aString) const; + PRBool operator<(const nsStr &aString) const; + PRBool operator<(const char* aString) const; + PRBool operator<(const PRUnichar* aString) const; -/** - * These methods test if a given string is > than this - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator>(const nsString &aString) const; -PRBool operator>(const nsStr &S) const; -PRBool operator>(const char* aString) const; -PRBool operator>(const PRUnichar* aString) const; + /** + * These methods test if a given string is > than this + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator>(const nsString &aString) const; + PRBool operator>(const nsStr &S) const; + PRBool operator>(const char* aString) const; + PRBool operator>(const PRUnichar* aString) const; -/** - * These methods test if a given string is <= than this - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator<=(const nsString &aString) const; -PRBool operator<=(const nsStr &S) const; -PRBool operator<=(const char* aString) const; -PRBool operator<=(const PRUnichar* aString) const; + /** + * These methods test if a given string is <= than this + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator<=(const nsString &aString) const; + PRBool operator<=(const nsStr &S) const; + PRBool operator<=(const char* aString) const; + PRBool operator<=(const PRUnichar* aString) const; -/** - * These methods test if a given string is >= than this - * @param aString is the string to be compared to this - * @return TRUE or FALSE - */ -PRBool operator>=(const nsString &aString) const; -PRBool operator>=(const nsStr &S) const; -PRBool operator>=(const char* aString) const; -PRBool operator>=(const PRUnichar* aString) const; + /** + * These methods test if a given string is >= than this + * @param aString is the string to be compared to this + * @return TRUE or FALSE + */ + PRBool operator>=(const nsString &aString) const; + PRBool operator>=(const nsStr &S) const; + PRBool operator>=(const char* aString) const; + PRBool operator>=(const PRUnichar* aString) const; -/** - * Compare this to given string; note that we compare full strings here. - * The optional length argument just lets us know how long the given string is. - * If you provide a length, it is compared to length of this string as an - * optimization. - * - * @param aString -- the string to compare to this - * @param aCount -- number of chars to be compared. - * @return TRUE if equal - */ -PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; -PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const; -PRBool Equals(const PRUnichar* s1, const PRUnichar* s2,PRBool aIgnoreCase=PR_FALSE) const; + /** + * Compare this to given string; note that we compare full strings here. + * The optional length argument just lets us know how long the given string is. + * If you provide a length, it is compared to length of this string as an + * optimization. + * + * @param aString -- the string to compare to this + * @param aCount -- number of chars to be compared. + * @return TRUE if equal + */ + PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const; + PRBool Equals(const PRUnichar* s1, const PRUnichar* s2,PRBool aIgnoreCase=PR_FALSE) const; -PRBool EqualsIgnoreCase(const nsString& aString) const; -PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const; -PRBool EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const; -PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const; + PRBool EqualsIgnoreCase(const nsString& aString) const; + PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const; + PRBool EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const; + PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const; -/** - * Determine if given buffer is plain ascii - * - * @param aBuffer -- if null, then we test *this, otherwise we test given buffer - * @return TRUE if is all ascii chars or if strlen==0 - */ -PRBool IsASCII(const PRUnichar* aBuffer=0); + /** + * Determine if given buffer is plain ascii + * + * @param aBuffer -- if null, then we test *this, otherwise we test given buffer + * @return TRUE if is all ascii chars or if strlen==0 + */ + PRBool IsASCII(const PRUnichar* aBuffer=0); -/** - * Determine if given char is a valid space character - * - * @param aChar is character to be tested - * @return TRUE if is valid space char - */ -static PRBool IsSpace(PRUnichar ch); + /** + * Determine if given char is a valid space character + * + * @param aChar is character to be tested + * @return TRUE if is valid space char + */ + static PRBool IsSpace(PRUnichar ch); -/** - * Determine if given char in valid alpha range - * - * @param aChar is character to be tested - * @return TRUE if in alpha range - */ -static PRBool IsAlpha(PRUnichar ch); + /** + * Determine if given char in valid alpha range + * + * @param aChar is character to be tested + * @return TRUE if in alpha range + */ + static PRBool IsAlpha(PRUnichar ch); -/** - * Determine if given char is valid digit - * - * @param aChar is character to be tested - * @return TRUE if char is a valid digit - */ -static PRBool IsDigit(PRUnichar ch); + /** + * Determine if given char is valid digit + * + * @param aChar is character to be tested + * @return TRUE if char is a valid digit + */ + static PRBool IsDigit(PRUnichar ch); -static void Recycle(nsString* aString); -static nsString* CreateString(void); - - - nsIMemoryAgent* mAgent; + static void Recycle(nsString* aString); + static nsString* CreateString(void); };