From 9ff7db4425e4978f05aaa4a2fc6fbb6ec3dac9b9 Mon Sep 17 00:00:00 2001 From: "rickg%netscape.com" Date: Fri, 31 Mar 2000 09:24:08 +0000 Subject: [PATCH] wip for nsString classes; not part of build git-svn-id: svn://10.0.0.236/trunk@64738 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/ds/nsBufferManager.h | 1143 ++++++++++++++++------------ mozilla/xpcom/ds/nsString2x.cpp | 571 +++++++++++--- mozilla/xpcom/ds/nsString2x.h | 258 +++---- mozilla/xpcom/ds/nsStringValue.h | 230 ++++-- mozilla/xpcom/ds/nsStringx.cpp | 496 +++++++++--- mozilla/xpcom/ds/nsStringx.h | 229 +++--- 6 files changed, 1862 insertions(+), 1065 deletions(-) diff --git a/mozilla/xpcom/ds/nsBufferManager.h b/mozilla/xpcom/ds/nsBufferManager.h index a388e14f011..717e2f29077 100644 --- a/mozilla/xpcom/ds/nsBufferManager.h +++ b/mozilla/xpcom/ds/nsBufferManager.h @@ -12,6 +12,8 @@ * 02.29.2000: Original files (rickg) * 03.02.2000: Flesh out the interface to be compatible with old library (rickg) * 03.03.2000: Finished mapping original nsStr functionality to template form (rickg) + * 03.10.2000: Fixed off-by-1 error in StripChar() (rickg) + * 03.20.2000: Ran regressions by comparing operations against original nsString (rickg) * *************************************************************************************/ @@ -20,44 +22,93 @@ #include "nsStringValue.h" -#include -#include "nsCRT.h" - -class nsAReadableString; -class nsAReadableStringIterator; - -/*************************************************************************** - * - * The following (hack) template functions will go away, but for now they - * provide basic string copying and appending for my prototype. (rickg) - * - ***************************************************************************/ - -inline size_t stringlen(const PRUnichar* theString) { - const PRUnichar* theEnd=theString; - while(*theEnd++); //skip to end of aDest... - size_t result=theEnd-theString-1; - return result; -} - -inline size_t stringlen(const char* theString) { - return ::strlen(theString); -} -template -void strncopy(CharType1* aDest,const CharType2* aSource, size_t aLength) { - const CharType2* aLast=aSource+aLength; - while(aSource -void strcatn(CharType1* aDest,const CharType2* aSource, size_t aLength) { - while(*aDest++); //skip to end of aDest... - strncopy(aDest,aSource,aLength); -} /************************************************************************************* * @@ -66,15 +117,6 @@ void strcatn(CharType1* aDest,const CharType2* aSource, size_t aLength) { * *************************************************************************************/ -template -inline PRInt32 MinInt(T1 anInt1,T2 anInt2){ - return (anInt1<(T1)anInt2) ? anInt1 : anInt2; -} - -template -inline PRInt32 MaxInt(T1 anInt1,T2 anInt2){ - return (anInt1<(T1)anInt2) ? anInt2 : anInt1; -} template inline void SVAddNullTerminator( nsStringValueImpl& aDest) { @@ -83,17 +125,23 @@ inline void SVAddNullTerminator( nsStringValueImpl& aDest) { } } +template +inline CharType ToLower(CharType aChar) { + if((aChar>='A') && (aChar<='Z')) + aChar+=32; + return aChar; +} static const PRUnichar gCommonEmptyBuffer[1] = {0}; static nsresult gStringAcquiredMemory = NS_OK; + + template inline nsresult SVAlloc( nsStringValueImpl& aDest, PRUint32 aCount) { nsresult result=NS_OK; - static int mAllocCount=0; - mAllocCount++; //we're given the acount value in charunits; now scale up to next multiple. aDest.mCapacity=kDefaultStringSize; @@ -126,11 +174,13 @@ inline nsresult SVAlloc( nsStringValueImpl& aDest, PRUint32 aCount) { */ template inline nsresult SVFree( nsStringValueImpl& aDest){ - if(aDest.mBuffer){ - + aDest.mRefCount--; + + if((aDest.mBuffer) && (!aDest.mRefCount)){ delete [] aDest.mBuffer; // nsAllocator::Free(aDest.mBuffer); aDest.mBuffer=0; } + return NS_OK; } @@ -145,16 +195,22 @@ template inline nsresult SVRealloc(nsStringValueImpl&aDest,PRUint32 aCount){ nsStringValueImpl temp(aDest); + nsresult result=SVAlloc(temp,aCount); + if(NS_SUCCEEDED(result)) { - nsresult result=SVAlloc(temp,aCount); - if(NS_SUCCESS(result)) { - SVFree(aDest); - aDest.mBuffer=temp.mBuffer; - aDest.mCapacity=temp.mCapacity; + if(0 -inline nsresult SVCopyBuffer_( CharType1* aDest, const CharType2* aSource, PRInt32 aLength) { - - if(sizeof(CharType1)==sizeof(CharType2)) { - memcpy(aDest,aSource,aLength*sizeof(CharType1)); - } - else { - const CharType2* aLast=aSource+aLength; - while(aSource -inline nsresult SVCopyBuffer( nsStringValueImpl& aDest,const nsStringValueImpl& aSource,PRInt32 aLength,PRInt32 aSrcOffset) { - nsresult result=NS_OK; - if((0(aDest.mBuffer,aSource.mBuffer,aLength); +#ifdef DEBUG_ILLEGAL_CAST_UP + int i=0; + for(i=0;i255) { + NS_ASSERTION( (aSource[i] < 256), "data in U+0100-U+FFFF will be lost"); + if(track_illegal) { + if(track_latin1) { + if(aSource[i] & 0xFF80) + illegal = PR_TRUE; + } else { + if(aSource[i] & 0xFF00) + illegal = PR_TRUE; + } // track_latin1 + } // track_illegal + break; + } } - return result; +#endif + + while(aSource -inline nsresult SVDestroy(nsStringValueImpl &aStringValue) { - nsresult result=NS_OK; - return result; -} - -/** - * These methods are where memory allocation/reallocation occur. - * - * @update rickg 03.01.2000 - * @param aString is the stringvalue to be manipulated - * @return - */ -template -inline nsresult SVEnsureCapacity(nsStringValueImpl& aString,PRUint32 aNewLength){ - - nsresult result=NS_OK; - if(aNewLength>aString.mCapacity) { - result=SVRealloc< CharType>(aString,aNewLength); - SVAddNullTerminator(aString); - } - return result; - -} - -/** - * Attempt to grow the capacity of the given stringvalueimp by given amount - * (It's possible the length is already larger, so this can fall out.) - * - * @update rickg 03.02.2000 - * @return memory error (usually returns NS_OK) - */ -template -inline nsresult SVGrowCapacity(nsStringValueImpl& aDest,PRUint32 aNewLength){ - nsresult result=NS_OK; - if(aNewLength>aDest.mCapacity) { - - nsStringValueImpl theTempStr; - nsresult result=SVAlloc(theTempStr,aNewLength); - if(NS_SUCCESS(result)) { - - if(0(theTempStr.mBuffer,aDest.mBuffer,aDest.mLength); - theTempStr.mLength=aDest.mLength; - SVAddNullTerminator(aDest); - } - - result=SVFree(aDest); - aDest=theTempStr; - theTempStr.mBuffer=0; //make sure to null this out so that you don't lose the buffer you just stole... - } - } - return result; -} /** * This method deletes chars from the given str. @@ -289,28 +312,32 @@ inline nsresult SVGrowCapacity(nsStringValueImpl& aDest,PRUint32 aNewL * @update rickg 03.01.2000 * @param aDest is the stringvalue to be modified * @param aDestOffset tells us where in dest to start deleting - * @param aCount tells us the (max) # of chars to delete + * @param aCount tells us the (max) # of chars to delete (-1 means delete the rest of the string starting at offset) */ template -inline nsresult SVDelete( nsStringValueImpl& aDest,PRUint32 aDestOffset,PRInt32 aCount){ +inline nsresult SVDelete( nsStringValueImpl& aDest,PRUint32 anOffset,PRInt32 aCount=-1){ nsresult result=NS_OK; - if((0(aDest); - + else aDest.mLength=anOffset; + aDest.mBuffer[aDest.mLength]=0; } + return result; } @@ -320,15 +347,15 @@ inline nsresult SVDelete( nsStringValueImpl& aDest,PRUint32 aDestOffse * * @update rickg 03.01.2000 * @param aDest is the stringvalue to be modified - * @param aDestOffset tells us where in dest to truncate + * @param anOffset tells us where in dest to truncate */ template -inline void SVTruncate( nsStringValueImpl& aDest,PRUint32 aDestOffset) { - if(aDestOffset(aDest); +inline void SVTruncate( nsStringValueImpl& aDest,PRUint32 anOffset=0) { + if(anOffset& aDest,PRUint32 aDestOffset) * @param aDest is the stringvalue to be modified * @param aSource is the buffer to be copied from * @param anOffset tells us where in source to start copying - * @param aCount tells us the (max) # of chars to copy + * @param aCount tells us the (max) # of chars to append */ template -inline nsresult SVAppend( nsStringValueImpl& aDest,const nsStringValueImpl& aSource,PRInt32 aCount,PRInt32 aSrcOffset){ +inline nsresult SVAppend( nsStringValueImpl& aDest,const nsStringValueImpl& aSource,PRInt32 aCount=-1,PRUint32 aSrcOffset=0){ nsresult result=NS_OK; - if(aSrcOffset<(PRInt32)aSource.mLength){ - PRInt32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength); + if(aSrcOffset aDest.mCapacity) { - result=SVGrowCapacity(aDest,aDest.mLength+theLength); + result=SVRealloc(aDest,aDest.mLength+theLength); } - if(NS_SUCCESS(result)) { + if(NS_SUCCEEDED(result)) { //now append new chars, starting at offset - CharType1* theDest = &aDest.mBuffer[aDest.mLength]; - CharType2* theSource = &aSource.mBuffer[aSrcOffset]; - CharType2 *theLastChar = theSource+theLength; + CharType1 *to_cp = aDest.mBuffer+aDest.mLength; + const CharType2 *from_cp = aSource.mBuffer+aSrcOffset; - result=SVCopyBuffer_(theDest,theSource,theLength); + SVCopyBuffer_(to_cp,from_cp,theLength); aDest.mLength+=theLength; + aDest.mBuffer[aDest.mLength]=0; } - SVAddNullTerminator(aDest); + } } return result; @@ -382,7 +409,7 @@ inline nsresult SVAppend( nsStringValueImpl& aDest,const nsStringValu * @param aCount tells us the (max) # of chars to copy */ template -inline nsresult SVAppendReadable( nsStringValueImpl& aDest,const nsAReadableString& aSource,PRInt32 aCount,PRInt32 anSrcOffset){ +inline nsresult SVAppendReadable( nsStringValueImpl& aDest,const nsAReadableString& aSource,PRInt32 aCount,PRUint32 anSrcOffset){ nsresult result=NS_OK; /* //I expect a pattern similar to this that could work on any readable string @@ -408,7 +435,7 @@ inline nsresult SVAppendReadable( nsStringValueImpl& aDest,const nsAR */ template -inline nsresult SVAssign(nsStringValueImpl& aDest,const nsStringValueImpl& aSource,PRInt32 aCount,PRInt32 aSrcOffset) { +inline nsresult SVAssign(nsStringValueImpl& aDest,const nsStringValueImpl& aSource,PRInt32 aCount=-1,PRUint32 aSrcOffset=0) { nsresult result=NS_OK; if((void*)aDest.mBuffer!=(void*)aSource.mBuffer){ SVTruncate(aDest,0); @@ -430,7 +457,7 @@ inline nsresult SVAssign(nsStringValueImpl& aDest,const nsStringValue * @param aCount tells us the (max) # of chars to insert */ template -inline nsresult SVInsert( nsStringValueImpl& aDest,PRUint32 aDestOffset,const nsStringValueImpl& aSource,PRInt32 aCount,PRInt32 aSrcOffset) { +inline nsresult SVInsert( nsStringValueImpl& aDest,PRUint32 aDestOffset,const nsStringValueImpl& aSource,PRInt32 aCount=-1,PRUint32 aSrcOffset=0) { nsresult result=NS_OK; //there are a few cases for insert: @@ -440,28 +467,35 @@ inline nsresult SVInsert( nsStringValueImpl& aDest,PRUint32 aDestOffs if(0 aDest.mCapacity) { nsStringValueImpl theTempStr; - result=SVEnsureCapacity(theTempStr,aDest.mLength+theLength); + result=SVAlloc(theTempStr,aDest.mLength+theLength); + + if(NS_SUCCEEDED(result)) { + + CharType1 *to_cp=theTempStr.mBuffer; + + memcpy(to_cp,aDest.mBuffer,aDestOffset*sizeof(CharType1)); //copy front of existing string... + + to_cp+=aDestOffset; + SVCopyBuffer_(to_cp,from_src,theLength); //now insert the new data... - if(NS_SUCCESS(result)) { - if(aDestOffset) { - SVAppend(theTempStr,aDest,aDestOffset,0); //first copy leftmost data... - } - - SVAppend(theTempStr,aSource,aSource.mLength,0); //next copy inserted (new) data - PRUint32 theRemains=aDest.mLength-aDestOffset; if(theRemains) { - SVAppend(theTempStr,aDest,theRemains,aDestOffset); //next copy rightmost data + CharType1 *from_dst=to_cp; + to_cp+=theLength; + memcpy(to_cp,from_dst,theRemains*sizeof(CharType1)); } SVFree(aDest); @@ -472,25 +506,32 @@ inline nsresult SVInsert( nsStringValueImpl& aDest,PRUint32 aDestOffs } else { - CharType1* root=aDest.mBuffer; - CharType1* end= root+aDest.mLength; - CharType1* dst2 = root+aDestOffset; - CharType1* dst1 = root+aDestOffset+aCount; + //if you're here, it's because we have enough room to insert the new chars into the buffer + //that we already possess. - memmove(dst1,dst2,sizeof(CharType1)*(end-dst2)); - - nsStringValueImpl theString(dst2,theLength); - result=SVCopyBuffer< CharType1, CharType2 >(theString,aSource,theLength,aSrcOffset); - //finally, make sure to update the string length... + CharType1* root_cp = aDest.mBuffer; + CharType1* end_cp = root_cp+aDest.mLength; + CharType1* offset_cp= root_cp+aDestOffset; + CharType1* max_cp = offset_cp+aCount; + + memmove(max_cp,offset_cp,sizeof(CharType1)*(end_cp-offset_cp)); + + SVCopyBuffer_(offset_cp,from_src,theLength); + + //finally, make sure to update the string length... aDest.mLength+=theLength; - SVAddNullTerminator(aDest); + aDest.mBuffer[aDest.mLength]=0; } }//if //else nothing to do! } - else SVAppend(aDest,aSource,aCount,0); + else { + SVAppend(aDest,aSource,aCount,0); + } + } + else { + SVAppend(aDest,aSource,aCount,0); } - else SVAppend(aDest,aSource,aCount,0); } return result; } @@ -501,8 +542,6 @@ inline nsresult SVInsert( nsStringValueImpl& aDest,PRUint32 aDestOffs * * @update rickg 03.01.2000 * @param aLeft - * @param aLast - * @param aMax * @param anEnd * @param aTarget * @return aDestaSource=1 @@ -511,8 +550,8 @@ template inline PRInt32 SVCompareCase_(const CharType1* aLeft,const CharType1* anEnd,const CharType2* aTarget){ while(aLeftaSource=1 + */ +inline PRInt32 SVCompare_(const char* aLeft,const char* anEnd,const char* aTarget){ + size_t theCount=anEnd-aLeft; + return memcmp(aLeft,aTarget,theCount); +} + +/** + * This method compares characters strings of two types (case sensitive) + * + * @update rickg 03.01.2000 + * @param aLeft * @param anEnd * @param aTarget * @return aDestaSource=1 @@ -555,7 +606,7 @@ inline PRInt32 SVCompare_(const CharType1* aLeft,const CharType1* anEnd,const Ch * * @update rickg 03.01.2000 * @param aDest - * @param aString + * @param aSource * @param aIgnoreCase * @param aCount --- tells us how many iterations to make. * @return aDestaSource=1 @@ -565,48 +616,76 @@ inline PRInt32 SVCompare(const nsStringValueImpl& aDest,const nsStrin PRInt32 result=0; - if(aCount) { - PRUint32 minlen=(aSource.mLength(left,end,target) ; - else result =SVCompare_(left,end,target); - - if (0==result) { - if(-1==aCount) { - - //Since the caller didn't give us a length to test, and minlen characters matched, - //we have to assume that the longer string is greater. - - if (aDest.mLength != aSource.mLength) { - //we think they match, but we've only compared minlen characters. - //if the string lengths are different, then they don't really match. - result = (aDest.mLength +inline PRInt32 SVCompareChars(const nsStringValueImpl& aLHS,const nsStringValueImpl& aRHS,PRBool aIgnoreCase,PRInt32 aCount) { + + PRInt32 result=0; + + if(aLHS.mBuffer!=aRHS.mBuffer) { + if(!aIgnoreCase) { + PRInt32 aMax = (aLHS.mLength& aDest,const nsStrin * @return nothing */ template -inline PRInt32 SVFind(const nsStringValueImpl& aDest,const nsStringValueImpl& aTarget,PRBool aIgnoreCase,PRInt32 aCount,PRInt32 aSrcOffset) { +inline PRInt32 SVFindOrig(const nsStringValueImpl& aDest,const nsStringValueImpl& aTarget,PRBool aIgnoreCase,PRInt32 aCount=-1,PRUint32 aSrcOffset=0) { PRUint32 minlen=(aTarget.mLength(left,left+minlen,aTarget.mBuffer) ; - if(0==cmp) { - return left-root; + const CharType1* last_cp = offset_cp+aCount; + const CharType1* end_cp = (last_cp(left,left+minlen,aTarget.mBuffer); - if(0==cmp) { - return left-root; - } - left++; } } } @@ -666,6 +742,86 @@ inline PRInt32 SVFind(const nsStringValueImpl& aDest,const nsStringVa } + +/** + * This method removes characters from the given set from this string. + * NOTE: aSet is a char*, and it's length is computed using strlen, which assumes null termination. + * + * @update rickg 03.01.2000 + * @param aDest + * @param aTarget + * @param aIgnoreCase + * @param aCount : tells us how many iterations to make, starting at offset + * @param aOffset: tells us where to start searching within aDest + * @return nothing + */ +template +inline PRInt32 SVFind(const nsStringValueImpl& aDest,const nsStringValueImpl& aTarget,PRBool aIgnoreCase,PRInt32 aCount=-1,PRUint32 aSrcOffset=0) { + + PRUint32 minlen=(aTarget.mLength& aDest,const nsStringVa * @return nothing */ template -PRInt32 SVFindChar(const nsStringValueImpl& aDest,PRUnichar aChar,PRBool aIgnoreCase,PRInt32 aCount,PRInt32 aSrcOffset) { +PRInt32 SVFindChar(const nsStringValueImpl& aDest,PRUnichar aChar,PRBool aIgnoreCase,PRInt32 aCount=-1,PRUint32 aSrcOffset=0) { if(aSrcOffset<0) aSrcOffset=0; @@ -695,37 +851,37 @@ PRInt32 SVFindChar(const nsStringValueImpl& aDest,PRUnichar aChar,PRBo if(0& aDest,const n if((0(aSet,theChar,aIgnoreCase,aSet.mLength,0); + PRInt32 thePos=SVFindChar(aSet,theChar,aIgnoreCase,aSet.mLength,0); if(kNotFound& aDest,const nsStringV if(0(rightmost,rightmost+aTarget.mLength,aTarget.mBuffer) ; - else cmp =SVCompare_(rightmost,rightmost+aTarget.mLength,aTarget.mBuffer); + cmp = SVCompareCase_(first_cp,last_cp,aTarget.mBuffer) ; + else cmp =SVCompare_(first_cp,last_cp,aTarget.mBuffer); if(0==cmp) { - return rightmost-root; + return first_cp-root_cp; } - rightmost--; + first_cp--; + last_cp--; } } } @@ -858,26 +1016,29 @@ PRInt32 SVRFindChar(const nsStringValueImpl& aDest,PRUnichar aChar,PRB if(0& aDest,PRUnichar aChar,PRB * @param aChar is the target character we're looking for * @param aIgnorecase tells us whether to use a case sensitive search * @param aCount tells us how many characters to iterate through (which may be different than aLength); -1 means use full length. + * @param aSrcOffset * @return index of pos if found, else -1 (kNotFound) */ template @@ -914,15 +1076,15 @@ inline PRInt32 SVRFindCharInSet(const nsStringValueImpl& aDest,const if(0(aSet,theChar,aIgnoreCase,aSet.mLength,0); + CharType1 theChar=(aIgnoreCase) ? ToLower(*right_cp) : *right_cp; + PRInt32 thePos=SVFindChar(aSet,theChar,aIgnoreCase,aSet.mLength,0); if(kNotFound& aDest,const char* aSet,PRBool aElim nsresult result=NS_OK; if(0 theSet(const_cast(aSet)); + nsStringValueImpl theSet((char*)aSet); if(aEliminateTrailing) { - while(root<=--end) { - CharType theChar=*end; - PRInt32 thePos=SVFindChar(theSet,theChar,PR_FALSE,theSet.mLength,0); + while(root_cp(theSet,theChar,PR_FALSE,theSet.mLength,0); + PRInt32 thePos=SVFindChar(theSet,theChar,PR_FALSE,theSet.mLength,0); if(kNotFound==thePos) break; } - size_t theCount=cp-root; + size_t theCount=cp-root_cp; if(0& aDest,const char* aSet,PRBool aElim * @return nothing */ template -nsresult SVStripCharsInSet(nsStringValueImpl& aDest,const char* aSet,PRInt32 aCount,PRInt32 aSrcOffset) { +nsresult SVStripCharsInSet(nsStringValueImpl& aDest,const char* aSet,PRInt32 aCount,PRInt32 anOffset) { - if((0 theSet(const_cast(aSet)); + nsStringValueImpl theSet((char*)aSet); - while(left(theSet,theChar,PR_FALSE,theSet.mLength,0); + while(left_cp& aDest, CharType aChar,PRInt32 if(anOffset<(PRInt32)aDest.mLength){ - CharType *theCP=&aDest.mBuffer[anOffset]; + CharType *root_cp=aDest.mBuffer; + CharType *theCP=root_cp+anOffset; + CharType *end_cp=root_cp+aDest.mLength; CharType *theWriteCP=theCP; - CharType *theEndCP=theCP+aDest.mLength; - while(theCP& aDest, CharType aChar,PRInt32 * @update rickg 03.01.2000 * @param aDest is the stringvalue to be modified * @param anOffset tells us where in source to start copying - * @param aCount tells us the (max) # of chars to copy + * @param aRepCount tells us the (max) # of iterations */ template nsresult SVReplace( nsStringValueImpl &aDest, const nsStringValueImpl &aTarget, const nsStringValueImpl &aNewValue, - PRInt32 aCount, - PRInt32 anOffset) { + PRInt32 aRepCount, + PRUint32 anOffset) { nsresult result=NS_OK; @@ -1099,36 +1263,6 @@ nsresult SVReplace( nsStringValueImpl &aDest, } -/** - * This method removes a given char the underlying stringvalue - * - * @update rickg 03.01.2000 - * @param aDest is the stringvalue to be modified - * @param anOffset tells us where in source to start copying - * @param aCount tells us the (max) # of chars to copy - */ -template -nsresult SVReplaceChar( nsStringValueImpl& aDest, CharType anOldChar, CharType aNewChar, PRInt32 aCount,PRInt32 anOffset) { - - nsresult result=NS_OK; - - if(anOffset<(PRInt32)aDest.mLength){ - - CharType *theCP=&aDest.mBuffer[anOffset]; - CharType *theWriteCP=theCP; - CharType *theEndCP=theCP+aDest.mLength; - - while(theCP& aDest, CharType anOldChar, * @update rickg 03.01.2000 * @param aDest * @param aSet - * @param aEliminateLeading - * @param aEliminateTrailing + * @param aNewChar + * @param aCount + * @param anoffset * @return nothing */ template -nsresult SVReplaceCharsInSet(nsStringValueImpl& aDest,const nsStringValueImpl &aSet,PRUnichar aNewChar,PRInt32 aCount,PRInt32 anOffset) { +nsresult SVReplaceCharsInSet(nsStringValueImpl& aDest,const char* aSet,PRUnichar aNewChar,PRInt32 aCount,PRUint32 anOffset) { - if((0 theSet(aSet); + CharType *root_cp=aDest.mBuffer; + CharType *offset_cp=root_cp+anOffset; //was theCP + CharType *last_cp=offset_cp+aCount; + CharType *null_cp=root_cp+theCount; + CharType *end_cp=(last_cp theSet((char*)aSet); + while(offset_cp& aDest,const nsStringVa * @return nothing */ template -nsresult SVCompressSet(nsStringValueImpl& aDest,nsStringValueImpl &aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE){ +nsresult SVCompressSet(nsStringValueImpl& aDest,const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE){ nsresult result=NS_OK; if(0(aDest, aSet, aChar, aDest.mLength,0); - SVTrim(aDest,aSet,aEliminateLeading,aEliminateTrailing); + result=SVReplaceCharsInSet(aDest, aSet, aChar, aDest.mLength,0); + SVTrim(aDest,aSet,aEliminateLeading,aEliminateTrailing); - CharType* root = aDest.mBuffer; - CharType* end = root + aDest.mLength; - CharType* to = root; + CharType *root_cp = aDest.mBuffer; + CharType *end_cp = root_cp + aDest.mLength; + CharType *to_cp = root_cp; + + nsStringValueImpl theSet((char*)aSet); //this code converts /n, /t, /r into normal space ' '; //it also compresses runs of whitespace down to a single char... PRUint32 aSetLen=strlen(aSet); - while (root < end) { - CharType theChar = *root++; - if((255(aSet,theChar,PR_FALSE,aSet.mLength,0))){ - *to++=theChar; - while (root <= end) { - theChar = *root++; - PRInt32 thePos=SVFindChar(aSet,theChar,PR_FALSE,aSet.mLength,0); - if(kNotFound==thePos){ - *to++ = theChar; - break; + if(aSetLen) { + + while (root_cp < end_cp) { + CharType theChar = *root_cp++; + + *to_cp++=theChar; //always copy this char + if((theChar<256) && (kNotFound void SVToLowerCase(nsStringValueImpl &aString) { CharType *theCP=aString.mBuffer; - CharType *theEndCP=theCP+aString.mLength; + CharType *end_cp=theCP+aString.mLength; - while(theCP= 'A') && (theChar <= 'Z')) { *theCP = 'a' + (theChar - 'A'); @@ -1238,9 +1379,9 @@ void SVToLowerCase(nsStringValueImpl &aString) { template void SVToUpperCase(nsStringValueImpl &aString) { CharType *theCP=aString.mBuffer; - CharType *theEndCP=theCP+aString.mLength; + CharType *end_cp=theCP+aString.mLength; - while(theCP= 'a') && (theChar<= 'z')) { *theCP= 'A' + (theChar - 'a'); @@ -1253,14 +1394,15 @@ void SVToUpperCase(nsStringValueImpl &aString) { template PRInt32 SVCountChar(const nsStringValueImpl &aString,PRUnichar aChar) { PRInt32 result=0; - if(aString.mLength) { - const CharType* cp=aString.mBuffer-1; - const CharType* endcp=cp+aString.mLength; + + const CharType* cp=aString.mBuffer; + const CharType* end_cp=cp+aString.mLength; - while(++cp &aString,PRUnichar aChar) //This will not work correctly for any unicode set other than ascii template void SVDebugDump(const nsStringValueImpl &aString) { - if(aString.mLength) { + - CharType* cp=aString.mBuffer; - CharType* endcp=cp+aString.mLength; + CharType* cp=aString.mBuffer; + CharType* end_cp=cp+aString.mLength; - char theBuffer[256]; - char* outp=theBuffer; - char* outendp=&theBuffer[255]; + char theBuffer[256]={0}; + char* outp=theBuffer; + char* outendp=&theBuffer[255]; + + while(cp &aString,PRInt32* anErrorC } //switch } - //if you don't have any valid chars, return 0, but set the error; - if(cp<=endcp) { + theRadix = (kAutoDetect==aRadix) ? theRadix : aRadix; + *anErrorCode = NS_OK; - *anErrorCode = NS_OK; + //now iterate the numeric chars and build our result + CharType* first=--cp; //in case we have to back up. - //now iterate the numeric chars and build our result - CharType* first=--cp; //in case we have to back up. - - while(cp<=endcp){ - theChar=*cp++; - if(('0'<=theChar) && (theChar<='9')){ - result = (theRadix * result) + (theChar-'0'); - } - else if((theChar>='A') && (theChar<='F')) { - if(10==theRadix) { - if(kAutoDetect==aRadix){ - theRadix=16; - cp=first; //backup - result=0; - } - else { - *anErrorCode=NS_ERROR_ILLEGAL_VALUE; - result=0; - break; - } + while(cp='A') && (theChar<='F')) { + if(10==theRadix) { + if(kAutoDetect==aRadix){ + theRadix=16; + cp=first; //backup + result=0; } else { - result = (theRadix * result) + ((theChar-'A')+10); + *anErrorCode=NS_ERROR_ILLEGAL_VALUE; + result=0; + break; } } - else if((theChar>='a') && (theChar<='f')) { - if(10==theRadix) { - if(kAutoDetect==aRadix){ - theRadix=16; - cp=first; //backup - result=0; - } - else { - *anErrorCode=NS_ERROR_ILLEGAL_VALUE; - result=0; - break; - } - } - else { - result = (theRadix * result) + ((theChar-'a')+10); - } - } - else if(('X'==theChar) || ('x'==theChar) || ('#'==theChar) || ('+'==theChar)) { - continue; - } else { - //we've encountered a char that's not a legal number or sign - break; + result = (theRadix * result) + ((theChar-'A')+10); } - } //while - if(negate) - result=-result; - } //if + } + else if((theChar>='a') && (theChar<='f')) { + if(10==theRadix) { + if(kAutoDetect==aRadix){ + theRadix=16; + cp=first; //backup + result=0; + } + else { + *anErrorCode=NS_ERROR_ILLEGAL_VALUE; + result=0; + break; + } + } + else { + result = (theRadix * result) + ((theChar-'a')+10); + } + } + else if(('X'==theChar) || ('x'==theChar) || ('#'==theChar) || ('+'==theChar)) { + continue; + } + else { + //we've encountered a char that's not a legal number or sign + break; + } + } //while + if(negate) + result=-result; } return result; } diff --git a/mozilla/xpcom/ds/nsString2x.cpp b/mozilla/xpcom/ds/nsString2x.cpp index 5fc2b12c0be..6ba133cedb4 100644 --- a/mozilla/xpcom/ds/nsString2x.cpp +++ b/mozilla/xpcom/ds/nsString2x.cpp @@ -1,9 +1,13 @@ -#include "nsString2x.h" -#include "nsStringx.h" +#include "nsString2.h" +#include "nsString.h" #include "nsBufferManager.h" #include -#include "nsAutoStringImpl.h" +#include +#include "nsIAllocator.h" + +static const char* kNullPointerError = "Unexpected null pointer"; +static const char* kWhitespace="\b\t\r\n "; //****************************************** // Ctor's @@ -22,6 +26,16 @@ nsString::nsString(const nsCString &aString,PRInt32 aLength) : mStringValue() { Assign(aString,aLength); } + //call this version for a single char of type char... +nsString::nsString(const nsSubsumeStr &aSubsumeString) : mStringValue(aSubsumeString.mLHS) { + SVAppend(mStringValue,aSubsumeString.mRHS,aSubsumeString.mRHS.mLength,0); +} + + //call this version for a single char of type char... +nsString::nsString(nsSubsumeStr &aSubsumeString) : mStringValue(aSubsumeString.mLHS) { + SVAppend(mStringValue,aSubsumeString.mRHS,aSubsumeString.mRHS.mLength,0); +} + //call this version for char*'s.... nsString::nsString(const PRUnichar* aString,PRInt32 aLength) : mStringValue() { Assign(aString,aLength,0); @@ -35,7 +49,7 @@ nsString::nsString(const char aChar) : mStringValue() { //call this version for PRUnichar*'s.... nsString::nsString(const char* aString,PRInt32 aLength) : mStringValue() { - nsStringValueImpl theString(const_cast(aString),aLength); + nsStringValueImpl theString(CONST_CAST(char*,aString),aLength); SVAssign(mStringValue,theString,theString.mLength,0); } @@ -45,11 +59,17 @@ nsString::nsString(const nsAReadableString &aString) : mStringValue() { } //call this version for stack-based string buffers... -nsString::nsString(const nsStackBuffer &aBuffer) : mStringValue(aBuffer) { +nsString::nsString(const nsUStackBuffer &aBuffer) : mStringValue(aBuffer) { } nsString::~nsString() { } +void nsString::Reinitialize(PRUnichar* aBuffer,PRUint32 aCapacity,PRInt32 aLength) { + mStringValue.mBuffer=aBuffer; + mStringValue.mCapacity=aCapacity; + mStringValue.mLength=aLength; + mStringValue.mRefCount=1; +} //****************************************** // Assigment operators @@ -67,16 +87,22 @@ nsString& nsString::operator=(const nsCString &aString) { return *this; } +nsString& nsString::operator=(const nsSubsumeStr &aSubsumeString) { + //XXX NOT IMPLEMENTED + return *this; +} + + nsString& nsString::operator=(const PRUnichar *aString) { if(mStringValue.mBuffer!=aString) { - nsStringValueImpl theStringValue(const_cast(aString)); + nsStringValueImpl theStringValue(CONST_CAST(PRUnichar*,aString)); Assign(aString); } return *this; } nsString& nsString::operator=(const char *aString) { - nsStringValueImpl theStringValue(const_cast(aString)); + nsStringValueImpl theStringValue(CONST_CAST(char*,aString)); SVAssign(mStringValue,theStringValue,theStringValue.mLength,0); return *this; } @@ -98,19 +124,11 @@ nsString& nsString::operator=(const PRUnichar aChar) { nsresult nsString::SetCapacity(PRUint32 aCapacity) { if(aCapacity>mStringValue.mCapacity) { - SVGrowCapacity(mStringValue,aCapacity); - SVAddNullTerminator(mStringValue); + SVRealloc(mStringValue,aCapacity); } return NS_OK; } -PRUnichar& nsString::operator[](PRUint32 aOffset) { - static PRUnichar gSharedChar=0; - return (mStringValue.mBuffer) ? mStringValue.mBuffer[aOffset] : gSharedChar; -} - -// operator const char* const() {return mStringValue.mBuffer;} - PRBool nsString::SetCharAt(PRUnichar aChar,PRUint32 anIndex) { PRBool result=PR_FALSE; @@ -121,10 +139,6 @@ PRBool nsString::SetCharAt(PRUnichar aChar,PRUint32 anIndex) { return result; } - //these aren't the real deal, but serve as a placeholder for us to implement iterators. -nsAReadableStringIterator* nsString::First() {return new nsAReadableStringIterator(); } -nsAReadableStringIterator* nsString::Last() {return new nsAReadableStringIterator(); } - //****************************************** // Here are the Assignment methods, @@ -132,7 +146,7 @@ nsAReadableStringIterator* nsString::Last() {return new nsAReadableStringIterato //****************************************** nsresult nsString::Truncate(PRUint32 anOffset) { - SVTruncate(mStringValue,anOffset); + SVTruncate(mStringValue,anOffset); return NS_OK; } @@ -182,7 +196,7 @@ nsresult nsString::Assign(const nsCString& aString,PRInt32 aLength,PRUint32 aSrc //assign from an nsAReadableString (the ABT) nsresult nsString::Assign(const nsAReadableString &aString,PRInt32 aLength,PRUint32 aSrcOffset) { Truncate(); - return SVAppendReadable(mStringValue,aString,aLength,aSrcOffset); + return SVAppendReadable(mStringValue,aString,aLength,aSrcOffset); } //assign from a char @@ -211,55 +225,73 @@ nsresult nsString::Assign(PRUnichar aChar) { * @return this */ nsresult nsString::Append(const nsString &aString,PRInt32 aLength,PRUint32 aSrcOffset) { - aLength = (aLength<0) ? aString.mStringValue.mLength : MinInt(aLength,aString.mStringValue.mLength); - return SVAppend< PRUnichar, PRUnichar > (mStringValue,aString.mStringValue,aLength,aSrcOffset); + aLength = (aLength<0) ? aString.mStringValue.mLength : (aLength<(PRInt32)aString.mStringValue.mLength) ? aLength: aString.mStringValue.mLength; + return SVAppend (mStringValue,aString.mStringValue,aLength,aSrcOffset); } //append from a type compatible string pointer nsresult nsString::Append(const char* aString,PRInt32 aLength,PRUint32 aSrcOffset) { nsresult result=NS_OK; if(aString) { - if(aLength<0) aLength=nsCRT::strlen(aString); - nsStringValueImpl theStringValue(const_cast(aString),aLength); - result=SVAppend< PRUnichar, char > (mStringValue,theStringValue,aLength,aSrcOffset); + if(aLength<0) aLength=stringlen(aString); + nsStringValueImpl theStringValue(CONST_CAST(char*,aString),aLength); + result=SVAppend(mStringValue,theStringValue,aLength,aSrcOffset); } return result; } //append from alternative type string pointer nsresult nsString::Append(const char aChar) { - char theBuffer[]={aChar,0}; - nsStringValueImpl theStringValue(theBuffer,1); - return SVAppend< PRUnichar, char > (mStringValue,theStringValue,1,0); + + if(mStringValue.mLength==mStringValue.mCapacity) { + SVRealloc(mStringValue,mStringValue.mCapacity+5); + } + + if(mStringValue.mLength theStringValue(theBuffer,1); - return SVAppend< PRUnichar,PRUnichar> (mStringValue,theStringValue,1,0); + + if(mStringValue.mLength==mStringValue.mCapacity) { + SVRealloc(mStringValue,mStringValue.mCapacity+5); + } + + if(mStringValue.mLength theStringValue(const_cast(aString),aLength); - result=SVAppend< PRUnichar,PRUnichar> (mStringValue,theStringValue,aLength,aSrcOffset); + nsStringValueImpl theStringValue(CONST_CAST(PRUnichar*,aString),aLength); + result=SVAppend (mStringValue,theStringValue,aLength,aSrcOffset); } return result; } //append from an nsCString nsresult nsString::Append(const nsCString &aString,PRInt32 aLength,PRUint32 aSrcOffset) { - aLength = (aLength<0) ? aString.mStringValue.mLength : MinInt(aLength,aString.mStringValue.mLength); - return SVAppend< PRUnichar, char > (mStringValue,aString.mStringValue,aLength,aSrcOffset); + aLength = (aLength<0) ? aString.mStringValue.mLength : (aLength<(PRInt32)aString.mStringValue.mLength) ? aLength: aString.mStringValue.mLength; + return SVAppend (mStringValue,aString.mStringValue,aLength,aSrcOffset); } //append from an nsAReadableString (the ABT) nsresult nsString::Append(const nsAReadableString &aString,PRInt32 aLength,PRUint32 aSrcOffset) { aLength = (aLength<0) ? aString.Length() : MinInt(aLength,aString.Length()); - return SVAppendReadable (mStringValue,aString,aLength,aSrcOffset); + return SVAppendReadable(mStringValue,aString,aLength,aSrcOffset); } //append an integer @@ -315,11 +347,11 @@ nsresult nsString::Append(float aFloat) { //*************************************** nsresult nsString::Cut(PRUint32 anOffset,PRInt32 aCount) { - return SVDelete(mStringValue,anOffset,aCount); + return (0(mStringValue,aTrimSet,aEliminateLeading,aEliminateTrailing); + return SVTrim(mStringValue,aTrimSet,aEliminateLeading,aEliminateTrailing); } /** @@ -333,8 +365,7 @@ nsresult nsString::Trim(const char* aTrimSet,PRBool aEliminateLeading,PRBool aEl * @return this */ nsresult nsString::CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing){ - nsStringValueImpl theSet(const_cast(aSet)); - return SVCompressSet(mStringValue,theSet,aChar,aEliminateLeading,aEliminateTrailing); + return SVCompressSet(mStringValue,aSet,aChar,aEliminateLeading,aEliminateTrailing); } /** @@ -367,7 +398,7 @@ nsresult nsString::CompressWhitespace( PRBool aEliminateLeading,PRBool aEliminat * @return this */ nsresult nsString::Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) { - return SVInsert(mStringValue,anOffset,aCopy.mStringValue,aCount,anOffset); + return SVInsert(mStringValue,anOffset,aCopy.mStringValue,aCount,anOffset); } /** @@ -385,10 +416,10 @@ nsresult nsString::Insert(const char* aString,PRUint32 anOffset,PRInt32 aLength) nsresult result=NS_OK; if(aString){ - nsStringValueImpl theStringValue(const_cast(aString),aLength); + nsStringValueImpl theStringValue(CONST_CAST(char*,aString),aLength); if(0(mStringValue,anOffset,theStringValue,theStringValue.mLength,0); + result=SVInsert(mStringValue,anOffset,theStringValue,theStringValue.mLength,0); } } return result; @@ -409,10 +440,10 @@ nsresult nsString::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32 aLe nsresult result=NS_OK; if(aString){ - nsStringValueImpl theStringValue(const_cast(aString),aLength); + nsStringValueImpl theStringValue(CONST_CAST(PRUnichar*,aString),aLength); if(0(mStringValue,anOffset,theStringValue,theStringValue.mLength,0); + result=SVInsert(mStringValue,anOffset,theStringValue,theStringValue.mLength,0); } } return result; @@ -431,7 +462,7 @@ nsresult nsString::Insert(char aChar,PRUint32 anOffset){ char theBuffer[]={aChar,0}; nsStringValueImpl theStringValue(theBuffer,1); - return SVInsert(mStringValue,anOffset,theStringValue,1,0); + return SVInsert(mStringValue,anOffset,theStringValue,1,0); } @@ -445,26 +476,34 @@ nsresult nsString::Insert(char aChar,PRUint32 anOffset){ * @return this */ nsresult nsString::ReplaceChar(char anOldChar,char aNewChar){ - return SVReplaceChar(mStringValue,anOldChar,aNewChar,mStringValue.mLength,0); + PRUnichar *root_cp=mStringValue.mBuffer; + PRUnichar *null_cp=root_cp+mStringValue.mLength; + + while(root_cp theSet(const_cast(aSet)); - return SVReplaceCharsInSet(mStringValue,theSet,aNewChar,mStringValue.mLength,0); + return SVReplaceCharsInSet(mStringValue,aSet,aNewChar,mStringValue.mLength,0); } nsresult nsString::ReplaceSubstring( const nsString& aTarget,const nsString& aNewValue){ - return SVReplace(mStringValue,aTarget.mStringValue,aNewValue.mStringValue,mStringValue.mLength,0); + return SVReplace(mStringValue,aTarget.mStringValue,aNewValue.mStringValue,mStringValue.mLength,0); } nsresult nsString::ReplaceSubstring(const char* aTarget,const char* aNewValue) { nsresult result=NS_OK; - const nsStringValueImpl theTarget(const_cast(aTarget)); - const nsStringValueImpl theNewValue(const_cast(aNewValue)); + const nsStringValueImpl theTarget(CONST_CAST(char*,aTarget)); + const nsStringValueImpl theNewValue(CONST_CAST(char*,aNewValue)); - return SVReplace(mStringValue,theTarget,theNewValue,mStringValue.mLength,0); + return SVReplace(mStringValue,theTarget,theNewValue,mStringValue.mLength,0); } //******************************************* @@ -480,8 +519,8 @@ nsresult nsString::ReplaceSubstring(const char* aTarget,const char* aNewValue) { * @param anOffset -- where in this string to start stripping chars * @return *this */ -nsresult nsString::StripChar(char aChar,PRUint32 anOffset){ - return SVStripChar(mStringValue,aChar,mStringValue.mLength,anOffset); +nsresult nsString::StripChar(PRUnichar aChar,PRUint32 anOffset){ + return SVStripChar(mStringValue,aChar,mStringValue.mLength,anOffset); } /** @@ -494,7 +533,7 @@ nsresult nsString::StripChar(char aChar,PRUint32 anOffset){ * @return *this */ nsresult nsString::StripChar(PRInt32 anInt,PRUint32 anOffset){ - return SVStripChar(mStringValue,(PRUnichar)anInt,mStringValue.mLength,anOffset); + return SVStripChar(mStringValue,(PRUnichar)anInt,mStringValue.mLength,anOffset); } /** @@ -505,9 +544,9 @@ nsresult nsString::StripChar(PRInt32 anInt,PRUint32 anOffset){ * @param aSet -- characters to be cut from this * @return *this */ -nsresult nsString::StripChars(const char* aSet){ - nsStringValueImpl theSet(const_cast(aSet)); - return SVStripCharsInSet(mStringValue,aSet,mStringValue.mLength,0); +nsresult nsString::StripChars(const char* aSet,PRInt32 aLength){ + nsStringValueImpl theSet(CONST_CAST(char*,aSet),aLength); + return SVStripCharsInSet(mStringValue,aSet,mStringValue.mLength,0); } /** @@ -526,21 +565,44 @@ nsresult nsString::StripWhitespace() { //************************************************** nsresult nsString::Left(nsString& aCopy,PRInt32 aCount) const { - aCount = (aCount<0) ? mStringValue.mLength : MinInt(aCount,mStringValue.mLength); + aCount = (aCount<0) ? mStringValue.mLength : (aCount<(PRInt32)mStringValue.mLength) ? aCount : mStringValue.mLength; return aCopy.Assign(*this,aCount,0); } nsresult nsString::Mid(nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) const { - aCount = (aCount<0) ? mStringValue.mLength : MinInt(aCount,mStringValue.mLength); + aCount = (aCount<0) ? mStringValue.mLength : (aCount<(PRInt32)mStringValue.mLength) ? aCount : mStringValue.mLength; return aCopy.Assign(*this,aCount,anOffset); } nsresult nsString::Right(nsString& aCopy,PRInt32 aCount) const { - PRInt32 offset=MaxInt(mStringValue.mLength-aCount,0); + PRUint32 theLen=mStringValue.mLength-aCount; + PRInt32 offset=(theLen<0) ? 0 : theLen; return Mid(aCopy,offset,aCount); } + //****************************************** + // Concatenation operators + //****************************************** +nsSubsumeStr nsString::operator+(const nsString &aString) { + nsSubsumeStr result(mStringValue,aString.mStringValue); + return result; +} + +nsSubsumeStr nsString::operator+(const PRUnichar* aString) { + nsSubsumeStr result; //NOT IMPLEMENTED + return result; +} + +nsSubsumeStr nsString::operator+(const char* aCString) { + nsSubsumeStr result; //NOT IMPLEMENTED + return result; +} + +nsSubsumeStr nsString::operator+(PRUnichar aChar) { + nsSubsumeStr result; //NOT IMPLEMENTED + return result; +} //******************************************* // Here come the operator+=() methods... //******************************************* @@ -578,7 +640,7 @@ nsString& nsString::operator+=(const int anInt){ } void nsString::ToLowerCase() { - SVToLowerCase(mStringValue); + SVToLowerCase(mStringValue); } void nsString::ToLowerCase(nsString &aString) const { @@ -587,7 +649,7 @@ void nsString::ToLowerCase(nsString &aString) const { } void nsString::ToUpperCase() { - SVToUpperCase(mStringValue); + SVToUpperCase(mStringValue); } void nsString::ToUpperCase(nsString &aString) const { @@ -597,52 +659,78 @@ void nsString::ToUpperCase(nsString &aString) const { PRInt32 nsString::Compare(const nsString &aString,PRBool aIgnoreCase,PRInt32 aCount) const { - return SVCompare(mStringValue,aString.mStringValue,aIgnoreCase,aCount); + return SVCompareChars(mStringValue,aString.mStringValue,aIgnoreCase,aCount); } PRInt32 nsString::Compare(const nsCString &aString,PRBool aIgnoreCase,PRInt32 aCount) const { - return SVCompare(mStringValue,aString.mStringValue,aIgnoreCase,aCount); + return SVCompare(mStringValue,aString.mStringValue,aIgnoreCase,aCount); } PRInt32 nsString::Compare(const char* aString,PRBool aIgnoreCase,PRInt32 aCount) const { - nsStringValueImpl theStringValue(const_cast(aString),aCount); - return SVCompare(mStringValue,theStringValue,aIgnoreCase,aCount); + nsStringValueImpl theStringValue(CONST_CAST(char*,aString),aCount); + return SVCompare(mStringValue,theStringValue,aIgnoreCase,aCount); } PRInt32 nsString::Compare(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 aCount) const { - nsStringValueImpl theStringValue(const_cast(aString),aCount); - return SVCompare(mStringValue,theStringValue,aIgnoreCase,aCount); + nsStringValueImpl theStringValue(CONST_CAST(PRUnichar*,aString),aCount); + return SVCompareChars(mStringValue,theStringValue,aIgnoreCase,aCount); } PRBool nsString::Equals(const nsString &aString,PRBool aIgnoreCase,PRInt32 aCount) const { - PRInt32 result=SVCompare(mStringValue,aString.mStringValue,aIgnoreCase,aCount); - return PRBool(0==result); + return PRBool(0==SVCompare(mStringValue,aString.mStringValue,aIgnoreCase,aCount)); } PRBool nsString::Equals(const nsCString &aString,PRBool aIgnoreCase,PRInt32 aCount) const { - PRInt32 result=SVCompare(mStringValue,aString.mStringValue,aIgnoreCase,aCount); - return PRBool(0==result); + return PRBool(0==SVCompare(mStringValue,aString.mStringValue,aIgnoreCase,aCount)); } PRBool nsString::Equals(const char* aString,PRBool aIgnoreCase,PRInt32 aCount) const { - nsStringValueImpl theStringValue(const_cast(aString),aCount); - PRInt32 result=SVCompare(mStringValue,theStringValue,aIgnoreCase,aCount); - return PRBool(0==result); + nsStringValueImpl theStringValue(CONST_CAST(char*,aString),aCount); + return PRBool(0==SVCompare(mStringValue,theStringValue,aIgnoreCase,aCount)); } PRBool nsString::Equals(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 aCount) const { - nsStringValueImpl theStringValue(const_cast(aString),aCount); - PRInt32 result=SVCompare(mStringValue,theStringValue,aIgnoreCase,aCount); - return PRBool(0==result); + nsStringValueImpl theStringValue(CONST_CAST(PRUnichar*,aString),aCount); + return PRBool(0==SVCompareChars(mStringValue,theStringValue,aIgnoreCase,aCount)); } -PRBool nsString::EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const { - PRBool result=PR_FALSE; +PRBool nsString::Equals(const PRUnichar* aLHS,const PRUnichar* aRHS,PRBool aIgnoreCase) const { + NS_ASSERTION(0!=aLHS,kNullPointerError); + NS_ASSERTION(0!=aRHS,kNullPointerError); + PRBool result=PR_FALSE; + if((aLHS) && (aRHS)){ + + +// PRInt32 cmp=(aIgnoreCase) ? nsCRT::strcasecmp(aLHS,aRHS) : nsCRT::strcmp(aLHS,aRHS); +// result=PRBool(0==cmp); + + + } + return result; } - // PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const; +PRBool nsString::Equals(/*FIX: const */nsIAtom* aAtom,PRBool aIgnoreCase) const{ + NS_ASSERTION(0!=aAtom,kNullPointerError); + PRBool result=PR_FALSE; + +#if 0 + + if(aAtom){ + PRInt32 cmp=0; + const PRUnichar* unicode; + if (aAtom->GetUnicode(&unicode) != NS_OK || unicode == nsnull) + return PR_FALSE; + if (aIgnoreCase) + cmp=nsCRT::strcasecmp(mUStr,unicode); + else + cmp=nsCRT::strcmp(mUStr,unicode); + result=PRBool(0==cmp); + } +#endif + return result; +} /*************************************** @@ -660,7 +748,7 @@ PRBool nsString::EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) cons * @return offset in string, or -1 (kNotFound) */ PRInt32 nsString::Find(const nsString& aTarget,PRBool aIgnoreCase,PRUint32 anOffset,PRInt32 aRepCount) const { - return SVFind(mStringValue,aTarget.mStringValue,aIgnoreCase,aRepCount,anOffset); + return SVFind(mStringValue,aTarget.mStringValue,aIgnoreCase,aRepCount,anOffset); } /** @@ -674,7 +762,7 @@ PRInt32 nsString::Find(const nsString& aTarget,PRBool aIgnoreCase,PRUint32 anOff * @return offset in string, or -1 (kNotFound) */ PRInt32 nsString::Find(const nsCString &aString,PRBool aIgnoreCase,PRUint32 anOffset,PRInt32 aRepCount) const { - return SVFind(mStringValue,aString.mStringValue,aIgnoreCase,aRepCount,anOffset); + return SVFind(mStringValue,aString.mStringValue,aIgnoreCase,aRepCount,anOffset); } /** @@ -688,8 +776,8 @@ PRInt32 nsString::Find(const nsCString &aString,PRBool aIgnoreCase,PRUint32 anOf * @return offset in string, or -1 (kNotFound) */ PRInt32 nsString::Find(const char* aString,PRBool aIgnoreCase,PRUint32 anOffset,PRInt32 aRepCount) const { - nsStringValueImpl theString(const_cast(aString)); - return SVFind(mStringValue,theString,aIgnoreCase,aRepCount,anOffset); + nsStringValueImpl theString(CONST_CAST(char*,aString)); + return SVFind(mStringValue,theString,aIgnoreCase,aRepCount,anOffset); } /** @@ -704,8 +792,8 @@ PRInt32 nsString::Find(const char* aString,PRBool aIgnoreCase,PRUint32 anOffset, */ PRInt32 nsString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRUint32 anOffset,PRInt32 aRepCount) const { - nsStringValueImpl theString(const_cast(aString)); - return SVFind(mStringValue,theString,aIgnoreCase,aRepCount,anOffset); + nsStringValueImpl theString(CONST_CAST(PRUnichar*,aString)); + return SVFind(mStringValue,theString,aIgnoreCase,aRepCount,anOffset); } /** @@ -718,7 +806,7 @@ PRInt32 nsString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRUint32 anOf * @return */ PRInt32 nsString::FindCharInSet(const nsString& aString,PRUint32 anOffset) const{ - return SVFindCharInSet(mStringValue,aString.mStringValue,PR_FALSE,mStringValue.mLength,anOffset); + return SVFindCharInSet(mStringValue,aString.mStringValue,PR_FALSE,mStringValue.mLength,anOffset); } @@ -733,8 +821,8 @@ PRInt32 nsString::FindCharInSet(const nsString& aString,PRUint32 anOffset) const */ PRInt32 nsString::FindCharInSet(const char *aString,PRUint32 anOffset) const{ - nsStringValueImpl theStringValue(const_cast(aString)); - return SVFindCharInSet(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset); + nsStringValueImpl theStringValue(CONST_CAST(char*,aString)); + return SVFindCharInSet(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset); } /** @@ -748,8 +836,8 @@ PRInt32 nsString::FindCharInSet(const char *aString,PRUint32 anOffset) const{ */ PRInt32 nsString::FindCharInSet(const PRUnichar *aString,PRUint32 anOffset) const{ - nsStringValueImpl theStringValue(const_cast(aString)); - return SVFindCharInSet(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset); + nsStringValueImpl theStringValue(CONST_CAST(PRUnichar*,aString)); + return SVFindCharInSet(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset); } /** @@ -763,7 +851,7 @@ PRInt32 nsString::FindCharInSet(const PRUnichar *aString,PRUint32 anOffset) cons * @return offset in string, or -1 (kNotFound) */ PRInt32 nsString::FindChar(char aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const { - return SVFindChar(mStringValue,aChar,aIgnoreCase,aCount,anOffset); + return SVFindChar(mStringValue,aChar,aIgnoreCase,aCount,anOffset); } /** @@ -777,7 +865,7 @@ PRInt32 nsString::FindChar(char aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt3 * @return offset in string, or -1 (kNotFound) */ PRInt32 nsString::RFindChar(char aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aRepCount) const{ - return SVRFindChar(mStringValue,aChar,aIgnoreCase,aRepCount,anOffset); + return SVRFindChar(mStringValue,aChar,aIgnoreCase,aRepCount,anOffset); } /** @@ -795,20 +883,20 @@ PRInt32 nsString::RFind(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOff PRInt32 result=kNotFound; if(0<=theMaxPos) { - result=SVRFind(mStringValue,aString.mStringValue,aIgnoreCase,aRepCount,anOffset); + result=SVRFind(mStringValue,aString.mStringValue,aIgnoreCase,aRepCount,anOffset); } return result; } PRInt32 nsString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aRepCount) const{ - nsStringValueImpl theStringValue(const_cast(aString)); - return SVRFind(mStringValue,theStringValue,aIgnoreCase,aRepCount,anOffset); + nsStringValueImpl theStringValue(CONST_CAST(char*,aString)); + return SVRFind(mStringValue,theStringValue,aIgnoreCase,aRepCount,anOffset); } PRInt32 nsString::RFind(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aRepCount) const{ - nsStringValueImpl theStringValue(const_cast(aString)); - return SVRFind(mStringValue,theStringValue,aIgnoreCase,aRepCount,anOffset); + nsStringValueImpl theStringValue(CONST_CAST(PRUnichar*,aString)); + return SVRFind(mStringValue,theStringValue,aIgnoreCase,aRepCount,anOffset); } /** * This method finds (in reverse) the offset of the first char in this string that is @@ -820,7 +908,7 @@ PRInt32 nsString::RFind(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOf * @return */ PRInt32 nsString::RFindCharInSet(const nsString& aString,PRInt32 anOffset) const { - return SVRFindCharInSet(mStringValue,aString.mStringValue,PR_FALSE,mStringValue.mLength,anOffset); + return SVRFindCharInSet(mStringValue,aString.mStringValue,PR_FALSE,mStringValue.mLength,anOffset); } /** @@ -833,8 +921,8 @@ PRInt32 nsString::RFindCharInSet(const nsString& aString,PRInt32 anOffset) const * @return */ PRInt32 nsString::RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset) const{ - nsStringValueImpl theStringValue(const_cast(aString)); - return SVRFindCharInSet(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset); + nsStringValueImpl theStringValue(CONST_CAST(PRUnichar*,aString)); + return SVRFindCharInSet(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset); } /** @@ -847,8 +935,8 @@ PRInt32 nsString::RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset) cons * @return */ PRInt32 nsString::RFindCharInSet(const char* aString,PRInt32 anOffset) const{ - nsStringValueImpl theStringValue(const_cast(aString)); - return SVRFindCharInSet(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset); + nsStringValueImpl theStringValue(CONST_CAST(char*,aString)); + return SVRFindCharInSet(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset); } /*************************************** @@ -894,7 +982,7 @@ char* nsString::ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset) cons PRInt32 nsString::CountChar(PRUnichar aChar) { - return SVCountChar(mStringValue,aChar); + return SVCountChar(mStringValue,aChar); } //****************************************** @@ -904,7 +992,7 @@ PRInt32 nsString::CountChar(PRUnichar aChar) { //This will not work correctly for any unicode set other than ascii void nsString::DebugDump(void) const { - SVDebugDump(mStringValue); + SVDebugDump(mStringValue); } /** @@ -919,7 +1007,7 @@ float nsString::ToFloat(PRInt32* aErrorCode) const { return 0.0f; } char* cp = ToCString(buf, sizeof(buf)); - float f = (float) PR_strtod(cp, &cp); + float f = (float) strtod(cp, &cp); if (*cp != 0) { *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; } @@ -938,7 +1026,264 @@ PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const{ } nsresult nsString::Append(const nsStringValueImpl &aString,PRInt32 aLength,PRUint32 aSrcOffset) { - aLength = (aLength<0) ? aString.mLength : MinInt(aLength,aString.mLength); - return SVAppend< PRUnichar, char> (mStringValue,aString,aLength,aSrcOffset); + aLength = (aLength<0) ? aString.mLength : (aLength<(PRInt32)aString.mLength) ? aLength: aString.mLength; + return SVAppend(mStringValue,aString,aLength,aSrcOffset); +} + +/***************************************************************** + Now we declare the nsCSubsumeString class + *****************************************************************/ + + +nsSubsumeStr::nsSubsumeStr() { +} + + +nsSubsumeStr::nsSubsumeStr(const nsString& aString) : mLHS(aString.mStringValue), mRHS() { +} + + +nsSubsumeStr::nsSubsumeStr(const nsSubsumeStr& aSubsumeString) : + mLHS(aSubsumeString.mLHS), + mRHS(aSubsumeString.mRHS) { +} + + +nsSubsumeStr::nsSubsumeStr(const nsStringValueImpl &aLHS,const nsSubsumeStr& aSubsumeString) : + mLHS(aLHS), + mRHS(aSubsumeString.mLHS) { +} + + +nsSubsumeStr::nsSubsumeStr(const nsStringValueImpl &aLHS,const nsStringValueImpl &aRHS) : + mLHS(aLHS), + mRHS(aRHS) { +} + +nsSubsumeStr::nsSubsumeStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength) { +} + +nsSubsumeStr nsSubsumeStr::operator+(const nsSubsumeStr &aSubsumeString) { + nsSubsumeStr result(*this); + return result; +} + + +nsSubsumeStr nsSubsumeStr::operator+(const nsString &aString) { + SVAppend(mLHS,mRHS,mRHS.mLength,0); + memcpy(&mRHS,&aString.mStringValue,sizeof(mRHS)); + return *this; +} + +int nsSubsumeStr::Subsume(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength) { + //XXX NOT IMPLEMENTED + int result=0; + return result; +} + +/** + * + * @update gess 01/04/99 + * @param + * @return + */ +NS_COM int fputs(const nsString& aString, FILE* out) +{ + char buf[100]; + char* cp = buf; + PRInt32 len = aString.Length(); + if (len >= PRInt32(sizeof(buf))) { + cp = aString.ToNewCString(); + } else { + aString.ToCString(cp, len + 1); + } + if(len>0) + ::fwrite(cp, 1, len, out); + if (cp != buf) { + delete[] cp; + } + return (int) len; +} + +PRUint32 HashCode(const nsString& aDest) { + PRUint32 h = 0; + PRUint32 n = aDest.Length(); + PRUint32 m; + const PRUnichar* c=aDest.GetUnicode(); + + if (n < 16) { /* Hash every char in a short string. */ + for(; n; c++, n--) + h = (h >> 28) ^ (h << 4) ^ *c; + } + else { /* Sample a la java.lang.String.hash(). */ + for(m = n / 8; n >= m; c += m, n -= m) + h = (h >> 28) ^ (h << 4) ^ *c; + } + return h; +} + +void Recycle( PRUnichar* aBuffer) { + nsAllocator::Free(aBuffer); +} + + +/***************************************************************** + Now we declare the nsAutoString class + *****************************************************************/ + + +nsAutoString::nsAutoString() : nsString() { + memset(mInternalBuffer,0,sizeof(mInternalBuffer)); + mStringValue.mCapacity=kDefaultStringSize; + mStringValue.mBuffer=mInternalBuffer; + mStringValue.mRefCount++; //so we don't try to delete our internal buffer +} + + //call this version nsAutoString derivatives... +nsAutoString::nsAutoString(const nsAutoString& aString,PRInt32 aLength) : nsString() { + memset(mInternalBuffer,0,sizeof(mInternalBuffer)); + mStringValue.mCapacity=kDefaultStringSize; + mStringValue.mBuffer=mInternalBuffer; + mStringValue.mRefCount++; //so we don't try to delete our internal buffer + Assign(aString,aLength); +} + +//call this version for nsString and the autostrings +nsAutoString::nsAutoString(const nsString& aString,PRInt32 aLength) : nsString() { + memset(mInternalBuffer,0,sizeof(mInternalBuffer)); + mStringValue.mCapacity=kDefaultStringSize; + mStringValue.mBuffer=mInternalBuffer; + mStringValue.mRefCount++; //so we don't try to delete our internal buffer + Assign(aString,aLength); +} + + //call this version with nsCString +nsAutoString::nsAutoString(const nsCString& aString) : nsString(aString) { + mStringValue.mRefCount++; //so we don't try to delete our internal buffer +} + + //call this version for char*'s.... +nsAutoString::nsAutoString(const char* aString,PRInt32 aLength) : nsString() { + memset(mInternalBuffer,0,sizeof(mInternalBuffer)); + + nsStringValueImpl theString(CONST_CAST(char*,aString),aLength); + mStringValue.mCapacity=kDefaultStringSize; + mStringValue.mBuffer=mInternalBuffer; + mStringValue.mRefCount++; //so we don't try to delete our internal buffer + SVAssign(mStringValue,theString,aLength,0); +} + + //call this version for a single char of type char... +nsAutoString::nsAutoString(char aChar) : nsString() { + + memset(mInternalBuffer,0,sizeof(mInternalBuffer)); + mStringValue.mCapacity=kDefaultStringSize; + mStringValue.mBuffer=mInternalBuffer; + mStringValue.mRefCount++; //so we don't try to delete our internal buffer + + PRUnichar theBuffer[]={aChar,0}; + + Assign(theBuffer,1,0); +} + + //call this version for a single char of type char... +nsAutoString::nsAutoString(PRUnichar aChar) : nsString() { + + memset(mInternalBuffer,0,sizeof(mInternalBuffer)); + mStringValue.mCapacity=kDefaultStringSize; + mStringValue.mBuffer=mInternalBuffer; + mStringValue.mRefCount++; //so we don't try to delete our internal buffer + + PRUnichar theBuffer[]={aChar,0}; + + Assign(theBuffer,1,0); +} + + + //call this version for PRUnichar*'s.... +nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString() { + memset(mInternalBuffer,0,sizeof(mInternalBuffer)); + mStringValue.mCapacity=kDefaultStringSize; + mStringValue.mBuffer=mInternalBuffer; + nsStringValueImpl theString(CONST_CAST(PRUnichar*,aString),aLength); + mStringValue.mRefCount++; //so we don't try to delete our internal buffer + SVAssign(mStringValue,theString,theString.mLength,0); +} + + + //call this version for all other ABT versions of readable strings +nsAutoString::nsAutoString(const nsAReadableString &aString) : nsString() { + memset(mInternalBuffer,0,sizeof(mInternalBuffer)); + mStringValue.mCapacity=kDefaultStringSize; + mStringValue.mBuffer=mInternalBuffer; + mStringValue.mRefCount++; //so we don't try to delete our internal buffer + Assign(aString); +} + +nsAutoString::nsAutoString(const nsUStackBuffer &aBuffer) : nsString() { + + memset(mInternalBuffer,0,sizeof(mInternalBuffer)); + + mStringValue.mLength=aBuffer.mLength; + mStringValue.mCapacity=aBuffer.mCapacity; + mStringValue.mBuffer=aBuffer.mBuffer; + mStringValue.mRefCount++; //so we don't try to delete our internal buffer + +} + +nsAutoString::nsAutoString(const CBufDescriptor& aBuffer) : nsString() { + mStringValue.mBuffer=(PRUnichar*)aBuffer.mBuffer; + mStringValue.mCapacity=aBuffer.mCapacity; + mStringValue.mLength=aBuffer.mLength; + mStringValue.mRefCount=(aBuffer.mStackBased) ? 2 : 1; +} + +nsAutoString::nsAutoString(const nsSubsumeStr& aSubsumeStringX) : nsString() { +} + + +nsAutoString::~nsAutoString() { } + + +nsAutoString& nsAutoString::operator=(const nsAutoString& aCopy) { + if(aCopy.mStringValue.mBuffer!=mStringValue.mBuffer) { + Assign(aCopy); + } + return *this; +} + +nsAutoString& nsAutoString::operator=(const nsString& aString) { + Assign(aString); + return *this; +} + +nsAutoString& nsAutoString::operator=(const nsCString& aString) { + Assign(aString); + return *this; +} + +nsAutoString& nsAutoString::operator=(const PRUnichar* aString) { + if(mStringValue.mBuffer!=aString) { + nsStringValueImpl theStringValue(CONST_CAST(PRUnichar*,aString)); + Assign(aString); + } + return *this; +} + +nsAutoString& nsAutoString::operator=(const char* aString) { + nsStringValueImpl theStringValue(CONST_CAST(char*,aString)); + SVAssign(mStringValue,theStringValue,theStringValue.mLength,0); + return *this; +} + +nsAutoString& nsAutoString::operator=(const PRUnichar aChar) { + Assign(aChar); + return *this; +} + + +nsAutoString& nsAutoString::operator=(const nsSubsumeStr &aSubsumeString) { + nsString::operator=(aSubsumeString); + return *this; } diff --git a/mozilla/xpcom/ds/nsString2x.h b/mozilla/xpcom/ds/nsString2x.h index cac83808158..35de2bab1f3 100644 --- a/mozilla/xpcom/ds/nsString2x.h +++ b/mozilla/xpcom/ds/nsString2x.h @@ -21,12 +21,15 @@ #define _NS_STRING_ #include "nsStringValue.h" -#include "nsBufferManager.h" + +typedef nsStackBuffer nsUStackBuffer; -class nsCString; +class NS_COM nsCString; +class NS_COM nsSubsumeStr; -class nsString: public nsAReadableString { + +class NS_COM nsString { public: //****************************************** @@ -50,6 +53,12 @@ public: //call this version for a single char of type prunichar... nsString(const PRUnichar aChar); + //call this version for stack-based string buffers... + nsString(const nsSubsumeStr &aSubsumeString); + + //call this version for stack-based string buffers... + nsString(nsSubsumeStr &aSubsumeString); + //call this version for char's.... nsString(const char* aString,PRInt32 aLength=-1) ; @@ -57,10 +66,21 @@ public: nsString(const nsAReadableString &aString) ; //call this version for stack-based string buffers... - nsString(const nsStackBuffer &aBuffer); + nsString(const nsUStackBuffer &aBuffer); virtual ~nsString(); + void Reinitialize(PRUnichar* aBuffer,PRUint32 aCapacity,PRInt32 aLength=-1); + + //****************************************** + // Concat operators + //****************************************** + + nsSubsumeStr operator+(const nsString &aString); + nsSubsumeStr operator+(const PRUnichar* aString); + nsSubsumeStr operator+(const char* aString); + nsSubsumeStr operator+(PRUnichar aChar); + //****************************************** // Assigment operators @@ -68,36 +88,36 @@ public: nsString& operator=(const nsString& aString); - nsString& operator=(const nsCString& aString); - + nsString& operator=(const nsSubsumeStr &aSubsumeString); nsString& operator=(const PRUnichar* aString); - nsString& operator=(const char* aString); - nsString& operator=(const char aChar); - nsString& operator=(const PRUnichar aChar); //****************************************** - // Here are the accessor methods... + // Here are the simple accessor methods... //****************************************** virtual nsresult SetLength(PRUint32 aLength) { + if(aLength>mStringValue.mLength) + SetCapacity(aLength); Truncate(aLength); return NS_OK; } virtual nsresult SetCapacity(PRUint32 aCapacity); - PRUnichar* GetUnicode() { return mStringValue.mBuffer;} + PRUnichar* GetUnicode() const { return mStringValue.mBuffer;} - PRUnichar& operator[](PRUint32 aOffset); + PRUnichar operator[](PRUint32 aOffset) const {return CharAt(aOffset);} // operator const char* const() {return mStringValue.mBuffer;} PRUint32 Length() const {return mStringValue.mLength;} + + PRUint32 Capacity() const {return mStringValue.mCapacity;} size_t GetCharSize() const {return sizeof(char);} PRBool IsUnicode() const {return PRBool(sizeof(PRUnichar)==sizeof(char));} @@ -118,11 +138,11 @@ public: return CharAt(mStringValue.mLength-1); } - - //these aren't the real deal, but serve as a placeholder for us to implement iterators. - virtual nsAReadableStringIterator* First(); - virtual nsAReadableStringIterator* Last(); - + virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const { + if (aResult) { + *aResult = sizeof(*this) + Capacity(); + } + } //****************************************** // Here are the Assignment methods, @@ -157,13 +177,9 @@ public: virtual nsresult Assign(PRUnichar aChar); - /** - * Functionally equivalent to assign or operator=, and deprecated! - * - */ - nsresult SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} - nsresult SetString(const PRUnichar* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} - nsresult SetString(const nsString &aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} + nsString& SetString(const PRUnichar* aString,PRInt32 aLength=-1) {Assign(aString, aLength); return *this;} + nsString& SetString(const nsString& aString,PRInt32 aLength=-1) {Assign(aString, aLength); return *this;} + //*************************************** // Here come the append methods... @@ -283,11 +299,11 @@ public: * @param anOffset -- where in this string to start stripping chars * @return *this */ - nsresult StripChar(char aChar,PRUint32 anOffset=0); + nsresult StripChar(PRUnichar aChar,PRUint32 anOffset=0); nsresult StripChar(PRInt32 anInt,PRUint32 anOffset=0); - nsresult StripChars(const char* aSet); + nsresult StripChars(const char* aSet,PRInt32 aLength=-1); nsresult StripWhitespace(); @@ -307,16 +323,15 @@ public: //******************************************* nsString& operator+=(const nsString& aString); - nsString& operator+=(const char* aString); - nsString& operator+=(const PRUnichar* aString); - nsString& operator+=(const char aChar); - nsString& operator+=(const PRUnichar aChar); - nsString& operator+=(const int anInt); + nsString& operator+=(const nsSubsumeStr &aSubsumeString) { + //XXX NOT IMPLEMENTED + return *this; + } /*********************************** @@ -326,7 +341,9 @@ public: PRBool operator==(const nsString& aString) const {return Equals(aString);} PRBool operator==(const nsCString& aString) const {return Equals(aString);} PRBool operator==(const char* aString) const {return Equals(aString);} + PRBool operator==(char* aString) const {return Equals(aString);} PRBool operator==(const PRUnichar* aString) const {return Equals(aString);} + PRBool operator==(PRUnichar* aString) const {return Equals(aString);} PRBool operator!=(const nsString& aString) const {return PRBool(Compare(aString)!=0);} PRBool operator!=(const nsCString& aString) const {return PRBool(Compare(aString)!=0);} @@ -355,27 +372,23 @@ public: PRInt32 Compare(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; - PRInt32 Compare(const nsCString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; - PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; - PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const ; PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; - PRBool Equals(const nsCString &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* aLHS,const PRUnichar* aRHS,PRBool aIgnoreCase=PR_FALSE) const; PRBool EqualsIgnoreCase(const nsString &aString) const {return Equals(aString,PR_TRUE);} PRBool EqualsIgnoreCase(const nsCString &aString) const {return Equals(aString,PR_TRUE);} - PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const {return Equals(aString,PR_TRUE);} - PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const; - - // PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const; + PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const {return Equals(aString,PR_TRUE,aCount);} + PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const {return Equals(aString,PR_TRUE,aCount);} + PRBool EqualsIgnoreCase(const PRUnichar* aLHS, const PRUnichar* aRHS) const {return Equals(aLHS,aRHS,PR_TRUE);} + PRBool EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const {return Equals(aAtom,PR_TRUE);} /*************************************** @@ -396,7 +409,7 @@ public: PRInt32 Find(const nsCString &aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0,PRInt32 aRepCount=-1) const; PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0,PRInt32 aRepCount=-1) const; PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0,PRInt32 aRepCount=-1) const; - PRInt32 FindChar(char aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aRepCount=-1) const ; + PRInt32 FindChar(char aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aRepCount=-1) const ; PRInt32 FindCharInSet(const nsString& aString,PRUint32 anOffset=0) const; PRInt32 FindCharInSet(const char *aString,PRUint32 anOffset=0) const; @@ -430,6 +443,7 @@ public: char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const; + //****************************************** // Utility methods //****************************************** @@ -470,134 +484,104 @@ protected: nsStringValueImpl mStringValue; friend class nsCString; + friend class nsSubsumeStr; }; +/***************************************************************** + Now we declare the nsSubsumeStr class + *****************************************************************/ + +class NS_COM nsSubsumeStr { +public: + + nsSubsumeStr(); + + nsSubsumeStr(const nsString& aString); + + nsSubsumeStr(const nsSubsumeStr& aSubsumeString); + + nsSubsumeStr(const nsStringValueImpl &aLHS,const nsSubsumeStr& aSubsumeString); + + nsSubsumeStr(const nsStringValueImpl &aLHS,const nsStringValueImpl &aSubsumeString); + + nsSubsumeStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1); + + nsSubsumeStr operator+(const nsSubsumeStr &aSubsumeString); + + nsSubsumeStr operator+(const nsString &aString); + + operator const PRUnichar*() {return 0;} + + int Subsume(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1); + + nsStringValueImpl mLHS; + nsStringValueImpl mRHS; +}; + + /***************************************************************** Now we declare the nsAutoString class *****************************************************************/ -class nsAutoString : public nsString { +class NS_COM nsAutoString : public nsString { public: - nsAutoString() : nsString() { - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - } + nsAutoString(); //call this version nsAutoString derivatives... - nsAutoString(const nsAutoString& aString,PRInt32 aLength=-1) : nsString() { - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - Assign(aString,aLength); - } + nsAutoString(const nsAutoString& aString,PRInt32 aLength=-1); - //call this version for nsString,nsCString and the autostrings - nsAutoString(const nsString& aString,PRInt32 aLength=-1) : nsString() { - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - Assign(aString,aLength); - } + //call this version for nsString and the autostrings + nsAutoString(const nsString& aString,PRInt32 aLength=-1); - //call this version with nsStringValueImpls (start of COW) - nsAutoString(const nsCString& aString) : nsString(aString) { - } + //call this version with nsCString (start of COW) + nsAutoString(const nsCString& aString); //call this version for char*'s.... - nsAutoString(const char* aString,PRInt32 aLength=-1) : nsString() { - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); - - nsStringValueImpl theString(const_cast(aString),aLength); - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - SVAssign(mStringValue,theString,aLength,0); - } + nsAutoString(const char* aString,PRInt32 aLength=-1); //call this version for a single char of type char... - nsAutoString(const char aChar) : nsString() { - char theBuffer[]={aChar,0}; - - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - - nsStringValueImpl theString(theBuffer,1); - Assign(theString,1,0); - } - + nsAutoString(PRUnichar aChar); + nsAutoString(char aChar); //call this version for PRUnichar*'s.... - nsAutoString(const PRUnichar* aString,PRInt32 aLength=-1) : nsString() { - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - nsStringValueImpl theString(const_cast(aString),aLength); - SVAssign(mStringValue,theString,theString.mLength,0); - } - + nsAutoString(const PRUnichar* aString,PRInt32 aLength=-1); //call this version for all other ABT versions of readable strings - nsAutoString(const nsAReadableString &aString) : nsString() { - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - Assign(aString); - } + nsAutoString(const nsAReadableString &aString); - nsAutoString(const nsStackBuffer &aBuffer) : nsString() { + nsAutoString(const nsUStackBuffer &aBuffer) ; - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); + nsAutoString(const CBufDescriptor& aBuffer) ; - mStringValue.mRefCount=2; - mStringValue.mLength=aBuffer.mLength; - mStringValue.mCapacity=aBuffer.mCapacity; - mStringValue.mBuffer=aBuffer.mBuffer; - - } + nsAutoString(const nsSubsumeStr& aSubsumeStringX) ; + virtual ~nsAutoString(); - virtual ~nsAutoString() { } + + nsAutoString& operator=(const nsAutoString& aCopy); + nsAutoString& operator=(const nsString& aString); + nsAutoString& operator=(const nsCString& aString); + nsAutoString& operator=(const PRUnichar* aString); + nsAutoString& operator=(const char* aString) ; + nsAutoString& operator=(const PRUnichar aChar); + nsAutoString& operator=(const nsSubsumeStr &aSubsumeString); - - nsAutoString& operator=(const nsAutoString& aCopy) { - if(aCopy.mStringValue.mBuffer!=mStringValue.mBuffer) { - Assign(aCopy); - } - return *this; - } - - nsAutoString& operator=(const nsString& aString) { - Assign(aString); - return *this; - } - - nsAutoString& operator=(const PRUnichar* aString) { - if(mStringValue.mBuffer!=aString) { - nsStringValueImpl theStringValue(const_cast(aString)); - Assign(aString); - } - return *this; - } - - nsAutoString& operator=(const char* aString) { - nsStringValueImpl theStringValue(const_cast(aString)); - SVAssign(mStringValue,theStringValue,theStringValue.mLength,0); - return *this; - } - - nsAutoString& operator=(const char aChar) { - Assign(aChar); - return *this; - } protected: PRUnichar mInternalBuffer[kDefaultStringSize+1]; + }; +extern NS_COM int fputs(const nsString& aString, FILE* out); + +extern PRUint32 HashCode(const nsString& aDest); + +extern NS_COM void Recycle( PRUnichar* aBuffer); + + #endif diff --git a/mozilla/xpcom/ds/nsStringValue.h b/mozilla/xpcom/ds/nsStringValue.h index 3cbe9732bff..3dc7e3c3a86 100644 --- a/mozilla/xpcom/ds/nsStringValue.h +++ b/mozilla/xpcom/ds/nsStringValue.h @@ -20,96 +20,155 @@ #ifndef NSSTRINGVALUE_ #define NSSTRINGVALUE_ -#include +#include "nsIAtom.h" +#include "nscore.h" +#include "nsIAllocator.h" +#include +#include "nsCRT.h" + +#if 0 typedef int PRInt32; typedef unsigned int PRUint32; typedef short int PRUnichar; typedef int nsresult; typedef char PRBool; + #define NS_OK 0 #define NS_MEMORY_ERROR 1000 #define PR_TRUE 1 #define PR_FALSE 0 -#define NS_SUCCESS(x) (NS_OK==x) +#define NS_SUCCEEDED(x) (NS_OK==x) -static const char* kWhitespace="\b\t\r\n "; -static const char* kPossibleNull ="Possible null being inserted into string."; +#endif + + +typedef long int _RefCountType; static const int kRadix10=10; static const int kRadix16=16; static const int kAutoDetect=100; static const int kRadixUnknown=kAutoDetect+1; -static const int kDefaultStringSize=32; +static const int kDefaultStringSize=64; static const int kNotFound=-1; +#define IGNORE_CASE (PR_TRUE) -/*************************************************************************** - * - * The following is the basic interface nsString searching... - * - * We will merge this into nsAReadableString very soon, but I've kept it - * seperate until I can map and factor the original nsString methods. - * - ***************************************************************************/ -class nsSearchableString { +class nsAReadableString { public: - - //We need to decide how deep (and generic) this API can go... + virtual PRUint32 Length() const =0; }; -/*************************************************************************** - * - * This isn't intended as a real class, but only to illustrate that for - * nsAReadableString, we want a common access pattern to get at the underlying - * buffer. Iterators make perfect sense, but it will take a real implementation. - * - * Note: This class is intended to replace direct calls to GetBuffer() - * in cases where iteration on an nsAReadableString is taking place. - * - ***************************************************************************/ -class nsAReadableStringIterator { -public: - nsAReadableStringIterator() { } -}; +#define MODERN_CPP //make this false for aix/solaris... + +#ifdef MODERN_CPP +#define CONST_CAST(type,arg) const_cast(arg) +#else +#define CONST_CAST(type,arg) (type)arg +#endif /*************************************************************************** * - * The following is the basic interface anyone who wants to be passed - * as a string should define. + * The following (hack) template functions will go away, but for now they + * provide basic string copying and appending for my prototype. (rickg) * ***************************************************************************/ -class nsAReadableString : public nsSearchableString { + +template +inline PRInt32 MinInt(T1 anInt1,T2 anInt2){ + return (anInt1<(T1)anInt2) ? anInt1 : anInt2; +} + +template +inline PRInt32 MaxInt(T1 anInt1,T2 anInt2){ + return (anInt1<(T1)anInt2) ? anInt2 : anInt1; +} + +inline size_t stringlen(const PRUnichar* theString) { + const PRUnichar* theEnd=theString; + while(*theEnd++); //skip to end of aDest... + size_t result=theEnd-theString-1; + return result; +} + +inline size_t stringlen(const char* theString) { + return ::strlen(theString); +} + +//---------------------------------------------------------------------------------------- +//---------------------------------------------------------------------------------------- + +class NS_COM CBufDescriptor { public: - virtual PRUint32 Length() const =0; - virtual size_t GetCharSize() const =0; + CBufDescriptor(char* aString, PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength=-1) { + mBuffer=aString; + mCharSize=1; + mStackBased=aStackBased; + mIsConst=PR_FALSE; + mLength=mCapacity=0; + if(aString && aCapacity>1) { + mCapacity=aCapacity-1; + mLength=(-1==aLength) ? strlen(aString) : aLength; + if(mLength>PRInt32(mCapacity)) + mLength=mCapacity; + } + } -// virtual PRUnichar operator[](PRUint32) = 0; + CBufDescriptor(const char* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength=-1) { + mBuffer=(char*)aString; + mCharSize=1; + mStackBased=aStackBased; + mIsConst=PR_TRUE; + mLength=mCapacity=0; + if(aString && aCapacity>1) { + mCapacity=aCapacity-1; + mLength=(-1==aLength) ? stringlen(aString) : aLength; + if(mLength>PRInt32(mCapacity)) + mLength=mCapacity; + } + } - virtual nsAReadableStringIterator* First() = 0; //These are here so that nsReadable strings can offer a standard mechanism for - virtual nsAReadableStringIterator* Last() = 0; //callers to access underlying data. Feel free to replace with a better pattern. + CBufDescriptor(PRUnichar* aString, PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength=-1) { + mBuffer=(char*)aString; + mCharSize=2; + mStackBased=aStackBased; + mLength=mCapacity=0; + mIsConst=PR_FALSE; + if(aString && aCapacity>1) { + mCapacity=aCapacity-1; + mLength=(-1==aLength) ? stringlen(aString) : aLength; + if(mLength>PRInt32(mCapacity)) + mLength=mCapacity; + } + } -//by moving to iterators, we can support segmented content models... -//virtual nsStringIterator GetIterator() = 0; + CBufDescriptor(const PRUnichar* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength=-1) { + mBuffer=(char*)aString; + mCharSize=2; + mStackBased=aStackBased; + mLength=mCapacity=0; + mIsConst=PR_TRUE; + if(aString && aCapacity>1) { + mCapacity=aCapacity-1; + mLength=(-1==aLength) ? stringlen(aString) : aLength; + if(mLength>PRInt32(mCapacity)) + mLength=mCapacity; + } + } -//virtual PRBool IsEmpty(void) = 0; - - //etc. + char* mBuffer; + PRUint32 mCapacity; + PRInt32 mLength; + PRBool mStackBased; + PRBool mIsConst; + char mCharSize; }; -/*************************************************************************** - * - * This is ABT from which the basic stringvalues are derived. (rickg) - * - ***************************************************************************/ -class nsStringValue { -public: - virtual void AddRef(void) =0; - virtual void Release(void) =0; -}; +//---------------------------------------------------------------------------------------- + /*************************************************************************** * @@ -128,76 +187,91 @@ struct nsStackBuffer { PRUint32 mCapacity; }; + +#if 0 +template +struct RCBuffer { + + void* operator new(size_t aSize) { + CharType* theBuf = ::new CharType[aSize+1+sizeof(_RefCountType)]; + memset(theBuf,0xff,aSize+additionalBytes+1); + return theBuf; + } + + void operator delete(void *p, size_t aSize) { + ::delete [] p; + } + + _RefCountType mRefCount; + CharType mBuffer[1]; + +}; +#endif + + /*************************************************************************** * * This is the templatized base class from which stringvalues are derived. (rickg) * ***************************************************************************/ template -class nsStringValueImpl : nsStringValue { -public: +struct nsStringValueImpl { - nsStringValueImpl() : nsStringValue() { - mRefCount=1; + nsStringValueImpl() { mBuffer=0; mLength=mCapacity=0; + mRefCount=1; } - nsStringValueImpl(const nsStringValueImpl& aCopy) : nsStringValue() { - mRefCount=1; + nsStringValueImpl(const nsStringValueImpl& aCopy) { mBuffer=aCopy.mBuffer; mLength=aCopy.mLength; mCapacity=aCopy.mCapacity; + mRefCount=1; } - nsStringValueImpl(const nsStringValueImpl& aCopy,PRInt32 aLength) : nsStringValue() { - mRefCount=1; + nsStringValueImpl(const nsStringValueImpl& aCopy,PRInt32 aLength){ mBuffer=aCopy.mBuffer; mLength=aLength; mCapacity=aCopy.mCapacity; + mRefCount=1; } - nsStringValueImpl(CharType* theString,PRInt32 aLength=-1,PRInt32 aCapacity=-1) : nsStringValue() { - mRefCount=1; + nsStringValueImpl(CharType* theString,PRInt32 aLength=-1,PRUint32 aCapacity=0) { if(theString) { mLength = (-1==aLength) ? stringlen(theString) : aLength; - mCapacity=mLength+1; + mCapacity=(0==aCapacity) ? mLength+1 : aCapacity; mBuffer=theString; } else { mBuffer=0; mLength=mCapacity=0; } + mRefCount=1; } - nsStringValueImpl(const nsStackBuffer &aBuffer) : nsStringValue() { - mRefCount=2; + nsStringValueImpl(const nsStackBuffer &aBuffer) { mCapacity=aBuffer.mCapacity; mLength=aBuffer.mLength; mBuffer=aBuffer.mBuffer; + mRefCount=2; //set it to 2 so we don't try to free it. } - operator=(const nsStringValueImpl& aCopy) { - mRefCount=1; + void operator=(const nsStringValueImpl& aCopy) { mBuffer=aCopy.mBuffer; mLength=aCopy.mLength; mCapacity=aCopy.mCapacity; + mRefCount=aCopy.mRefCount; } - operator CharType*() {return mBuffer;} + void* GetBuffer() {return mBuffer;} + PRUint32 GetLength() {return mLength;} + size_t GetCharSize() {return sizeof(CharType);} - virtual void AddRef(void) {mRefCount++;} - virtual void Release(void){--mRefCount;} - - virtual void* GetBuffer() {return mBuffer;} - virtual PRUint32 GetLength() {return mLength;} - virtual size_t GetCharSize() {return sizeof(CharType);} - -public: CharType* mBuffer; - PRUint32 mRefCount; PRUint32 mLength; PRUint32 mCapacity; + PRUint32 mRefCount; }; diff --git a/mozilla/xpcom/ds/nsStringx.cpp b/mozilla/xpcom/ds/nsStringx.cpp index 1dae44b3d2b..f8e8a21715a 100644 --- a/mozilla/xpcom/ds/nsStringx.cpp +++ b/mozilla/xpcom/ds/nsStringx.cpp @@ -1,9 +1,13 @@ -#include "nsString2x.h" -#include "nsStringx.h" +#include "nsString2.h" +#include "nsString.h" #include "nsBufferManager.h" #include -#include "nsAutoStringImpl.h" +#include +#include "nsIAllocator.h" + +static const char* kWhitespace="\b\t\r\n "; + //****************************************** // Ctor's @@ -24,13 +28,22 @@ nsCString::nsCString(const nsString& aString,PRInt32 aLength) : mStringValue() { //call this version for char*'s.... nsCString::nsCString(const char* aString,PRInt32 aLength) : mStringValue() { - Assign(aString,aLength,0); + Assign(aString,aLength); } //call this version for PRUnichar*'s.... nsCString::nsCString(const PRUnichar* aString,PRInt32 aLength) : mStringValue() { - nsStringValueImpl theString(const_cast(aString),aLength); - SVAssign(mStringValue,theString,theString.mLength,0); + Assign(aString,aLength,0); +} + + //call this version for a single char of type char... +nsCString::nsCString(const nsSubsumeCStr &aSubsumeString) : mStringValue(aSubsumeString.mLHS) { + SVAppend(mStringValue,aSubsumeString.mRHS,aSubsumeString.mRHS.mLength,0); +} + + //call this version for a single char of type char... +nsCString::nsCString(nsSubsumeCStr &aSubsumeString) : mStringValue(aSubsumeString.mLHS) { + SVAppend(mStringValue,aSubsumeString.mRHS,aSubsumeString.mRHS.mLength,0); } //call this version for a single char of type char... @@ -44,12 +57,39 @@ nsCString::nsCString(const nsAReadableString &aString) : mStringValue() { } //call this version for stack-based string buffers... -nsCString::nsCString(const nsStackBuffer &aBuffer) : mStringValue(aBuffer) { +nsCString::nsCString(const nsCStackBuffer &aBuffer) : mStringValue(aBuffer) { } nsCString::~nsCString() { } +void nsCString::Reinitialize(char* aBuffer,PRUint32 aCapacity,PRInt32 aLength) { + mStringValue.mBuffer=aBuffer; + mStringValue.mCapacity=aCapacity; + mStringValue.mLength=aLength; + mStringValue.mRefCount=1; +} + + + //****************************************** + // Concatenation operators + //****************************************** + +nsSubsumeCStr nsCString::operator+(const nsCString &aCString) { + nsSubsumeCStr result(mStringValue,aCString.mStringValue); + return result; +} + +nsSubsumeCStr nsCString::operator+(const char* aCString) { + nsSubsumeCStr result; //NOT IMPLEMENTED + return result; +} + +nsSubsumeCStr nsCString::operator+(char aChar) { + nsSubsumeCStr result; //NOT IMPLEMENTED + return result; +} + //****************************************** // Assigment operators //****************************************** @@ -68,14 +108,14 @@ nsCString& nsCString::operator=(const nsString &aString) { nsCString& nsCString::operator=(const char *aString) { if(mStringValue.mBuffer!=aString) { - nsStringValueImpl theStringValue(const_cast(aString)); + nsStringValueImpl theStringValue(CONST_CAST(char*,aString)); SVAssign(mStringValue,theStringValue,theStringValue.mLength,0); } return *this; } nsCString& nsCString::operator=(const PRUnichar *aString) { - nsStringValueImpl theStringValue(const_cast(aString)); + nsStringValueImpl theStringValue(CONST_CAST(PRUnichar*,aString)); Assign(aString); return *this; } @@ -85,6 +125,11 @@ nsCString& nsCString::operator=(const char aChar) { return *this; } +nsCString& nsCString::operator=(const nsSubsumeCStr &aSubsumeString) { + //NOT IMPLEMENTED + return *this; +} + //****************************************** // Here are the accessor methods... @@ -93,17 +138,11 @@ nsCString& nsCString::operator=(const char aChar) { nsresult nsCString::SetCapacity(PRUint32 aCapacity) { if(aCapacity>mStringValue.mCapacity) { - SVGrowCapacity(mStringValue,aCapacity); - SVAddNullTerminator(mStringValue); + SVRealloc(mStringValue,aCapacity); } return NS_OK; } -char& nsCString::operator[](PRUint32 aOffset) { - static char gSharedChar=0; - return (mStringValue.mBuffer) ? mStringValue.mBuffer[aOffset] : gSharedChar; -} - // operator const char* const() {return mStringValue.mBuffer;} @@ -116,10 +155,6 @@ PRBool nsCString::SetCharAt(char aChar,PRUint32 anIndex) { return result; } - //these aren't the real deal, but serve as a placeholder for us to implement iterators. -nsAReadableStringIterator* nsCString::First() {return new nsAReadableStringIterator(); } -nsAReadableStringIterator* nsCString::Last() {return new nsAReadableStringIterator(); } - //****************************************** // Here are the Assignment methods, @@ -127,7 +162,7 @@ nsAReadableStringIterator* nsCString::Last() {return new nsAReadableStringIterat //****************************************** nsresult nsCString::Truncate(PRUint32 anOffset) { - SVTruncate(mStringValue,anOffset); + SVTruncate(mStringValue,anOffset); return NS_OK; } @@ -149,6 +184,20 @@ nsresult nsCString::Assign(const nsCString& aString,PRInt32 aLength,PRUint32 aSr return result; } +/* + * This method assign from nsCString + * + * @update rickg 03.01.2000 + * @param aString -- source String to be inserted into this + * @param aLength -- number of chars to be copied from aCopy + * @param aSrcOffset -- insertion position within this str + * @return this + */ +nsresult nsCString::Assign(const nsString& aString,PRInt32 aLength,PRUint32 aSrcOffset) { + nsresult result=NS_OK; + Truncate(); + return Append(aString,aLength,aSrcOffset); +} /* * This method assign from PRUnichar* @@ -159,12 +208,10 @@ nsresult nsCString::Assign(const nsCString& aString,PRInt32 aLength,PRUint32 aSr * @param aSrcOffset -- insertion position within this str * @return this */ -#if 0 nsresult nsCString::Assign(const PRUnichar* aString,PRInt32 aLength,PRUint32 aSrcOffset) { Truncate(); return Append(aString,aLength,aSrcOffset); } -#endif /* * This method assign from char* @@ -196,7 +243,7 @@ nsresult nsCString::Assign(const char* aString,PRInt32 aLength,PRUint32 aSrcOffs */ nsresult nsCString::Assign(const nsAReadableString &aString,PRInt32 aLength,PRUint32 aSrcOffset) { Truncate(); - return SVAppendReadable(mStringValue,aString,aLength,aSrcOffset); + return SVAppendReadable(mStringValue,aString,aLength,aSrcOffset); } //assign from a char @@ -226,7 +273,7 @@ nsresult Append(const nsStringValueImpl &aString,PRInt32 aLength,PRUint32 * @return this */ nsresult nsCString::Append(const nsCString &aString,PRInt32 aLength,PRUint32 aSrcOffset) { - return SVAppend< char, char > (mStringValue,aString.mStringValue,aLength,aSrcOffset); + return SVAppend (mStringValue,aString.mStringValue,aLength,aSrcOffset); } /* @@ -239,48 +286,68 @@ nsresult nsCString::Append(const nsCString &aString,PRInt32 aLength,PRUint32 aSr * @return this */ nsresult nsCString::Append(const nsString &aString,PRInt32 aLength,PRUint32 aSrcOffset) { - return SVAppend< char, PRUnichar > (mStringValue,aString.mStringValue,aString.mStringValue.mLength,aSrcOffset); + return SVAppend(mStringValue,aString.mStringValue,aString.mStringValue.mLength,aSrcOffset); } //append from a char* nsresult nsCString::Append(const char* aString,PRInt32 aLength,PRUint32 aSrcOffset) { nsresult result=NS_OK; if(aString) { - nsStringValueImpl theStringValue(const_cast(aString),aLength); - result=SVAppend< char, char > (mStringValue,theStringValue,aLength,aSrcOffset); + nsStringValueImpl theStringValue(CONST_CAST(char*,aString),aLength); + result=SVAppend(mStringValue,theStringValue,aLength,aSrcOffset); } return result; } //append from a char nsresult nsCString::Append(const char aChar) { - char theBuffer[]={aChar,0}; - nsStringValueImpl theStringValue(theBuffer,1); - return SVAppend< char, char > (mStringValue,theStringValue,1,0); + + if(mStringValue.mLength==mStringValue.mCapacity) { + SVRealloc(mStringValue,mStringValue.mCapacity+5); + } + + if(mStringValue.mLength theStringValue(theBuffer,1); - return SVAppend< char,PRUnichar> (mStringValue,theStringValue,1,0); + return SVAppend(mStringValue,theStringValue,1,0); } //append from a PRUnichar* -#if 0 nsresult nsCString::Append(const PRUnichar* aString,PRInt32 aLength,PRUint32 aSrcOffset) { nsresult result=NS_OK; if(aString) { - nsStringValueImpl theStringValue(const_cast(aString),aLength); - result=SVAppend< char,PRUnichar> (mStringValue,theStringValue,aLength,aSrcOffset); + nsStringValueImpl theStringValue(CONST_CAST(PRUnichar*,aString),aLength); + result=SVAppend(mStringValue,theStringValue,aLength,aSrcOffset); } return result; } -#endif //append from an nsAReadableString (the ABT) nsresult nsCString::Append(const nsAReadableString &aString,PRInt32 aLength,PRUint32 aSrcOffset) { - return SVAppendReadable (mStringValue,aString,aLength,aSrcOffset); + return SVAppendReadable(mStringValue,aString,aLength,aSrcOffset); } //append an integer @@ -324,8 +391,7 @@ nsresult nsCString::Append(float aFloat) { char buf[40]; sprintf(buf,"%g",aFloat); - nsStringValueImpl theStringValue(buf); - Append(theStringValue); + Append(buf); return result; } @@ -336,11 +402,11 @@ nsresult nsCString::Append(float aFloat) { //*************************************** nsresult nsCString::Cut(PRUint32 anOffset,PRInt32 aCount) { - return SVDelete(mStringValue,anOffset,aCount); + return (0(mStringValue,aTrimSet,aEliminateLeading,aEliminateTrailing); + return SVTrim(mStringValue,aTrimSet,aEliminateLeading,aEliminateTrailing); } /** @@ -354,8 +420,7 @@ nsresult nsCString::Trim(const char* aTrimSet,PRBool aEliminateLeading,PRBool aE * @return this */ nsresult nsCString::CompressSet(const char* aSet, char aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing){ - nsStringValueImpl theSet(const_cast(aSet)); - return SVCompressSet(mStringValue,theSet,aChar,aEliminateLeading,aEliminateTrailing); + return SVCompressSet(mStringValue,aSet,aChar,aEliminateLeading,aEliminateTrailing); } /** @@ -378,7 +443,7 @@ nsresult nsCString::CompressWhitespace( PRBool aEliminateLeading,PRBool aElimina //*************************************** nsresult nsCString::Insert(const nsCString& aString,PRUint32 anOffset,PRInt32 aCount) { - return SVInsert(mStringValue,anOffset,aString.mStringValue,aCount,anOffset); + return SVInsert(mStringValue,anOffset,aString.mStringValue,aCount,anOffset); } /** @@ -396,10 +461,10 @@ nsresult nsCString::Insert(const char* aString,PRUint32 anOffset,PRInt32 aLength nsresult result=NS_OK; if(aString){ - nsStringValueImpl theStringValue(const_cast(aString),aLength); + nsStringValueImpl theStringValue(CONST_CAST(char*,aString),aLength); if(0(mStringValue,anOffset,theStringValue,theStringValue.mLength,0); + result=SVInsert(mStringValue,anOffset,theStringValue,theStringValue.mLength,0); } } return result; @@ -419,7 +484,7 @@ nsresult nsCString::Insert(char aChar,PRUint32 anOffset){ char theBuffer[]={aChar,0}; nsStringValueImpl theStringValue(theBuffer,1); - return SVInsert(mStringValue,anOffset,theStringValue,1,0); + return SVInsert(mStringValue,anOffset,theStringValue,1,0); } @@ -433,26 +498,34 @@ nsresult nsCString::Insert(char aChar,PRUint32 anOffset){ * @return this */ nsresult nsCString::ReplaceChar(char anOldChar,char aNewChar){ - return SVReplaceChar(mStringValue,anOldChar,aNewChar,mStringValue.mLength,0); + char *root_cp=mStringValue.mBuffer; + char *null_cp=root_cp+mStringValue.mLength; + + while(root_cp theSet(const_cast(aSet)); - return SVReplaceCharsInSet(mStringValue,theSet,aNewChar,mStringValue.mLength,0); + return SVReplaceCharsInSet(mStringValue,aSet,aNewChar,mStringValue.mLength,0); } nsresult nsCString::ReplaceSubstring( const nsCString& aTarget,const nsCString& aNewValue){ - return SVReplace(mStringValue,aTarget.mStringValue,aNewValue.mStringValue,mStringValue.mLength,0); + return SVReplace(mStringValue,aTarget.mStringValue,aNewValue.mStringValue,mStringValue.mLength,0); } nsresult nsCString::ReplaceSubstring(const char* aTarget,const char* aNewValue) { nsresult result=NS_OK; - const nsStringValueImpl theTarget(const_cast(aTarget)); - const nsStringValueImpl theNewValue(const_cast(aNewValue)); + const nsStringValueImpl theTarget(CONST_CAST(char*,aTarget)); + const nsStringValueImpl theNewValue(CONST_CAST(char*,aNewValue)); - return SVReplace(mStringValue,theTarget,theNewValue,mStringValue.mLength,0); + return SVReplace(mStringValue,theTarget,theNewValue,mStringValue.mLength,0); } //******************************************* @@ -469,7 +542,7 @@ nsresult nsCString::ReplaceSubstring(const char* aTarget,const char* aNewValue) * @return *this */ nsresult nsCString::StripChar(char aChar,PRUint32 anOffset){ - return SVStripChar(mStringValue,aChar,mStringValue.mLength,anOffset); + return SVStripChar(mStringValue,aChar,mStringValue.mLength,anOffset); } /** @@ -482,7 +555,7 @@ nsresult nsCString::StripChar(char aChar,PRUint32 anOffset){ * @return *this */ nsresult nsCString::StripChar(PRInt32 anInt,PRUint32 anOffset){ - return SVStripChar(mStringValue,(char)anInt,mStringValue.mLength,anOffset); + return SVStripChar(mStringValue,(char)anInt,mStringValue.mLength,anOffset); } /** @@ -493,9 +566,9 @@ nsresult nsCString::StripChar(PRInt32 anInt,PRUint32 anOffset){ * @param aSet -- characters to be cut from this * @return *this */ -nsresult nsCString::StripChars(const char* aSet){ - nsStringValueImpl theSet(const_cast(aSet)); - return SVStripCharsInSet(mStringValue,aSet,mStringValue.mLength,0); +nsresult nsCString::StripChars(const char* aSet,PRInt32 aLength){ + nsStringValueImpl theSet(CONST_CAST(char*,aSet),aLength); + return SVStripCharsInSet(mStringValue,aSet,mStringValue.mLength,0); } /** @@ -514,17 +587,18 @@ nsresult nsCString::StripWhitespace() { //************************************************** nsresult nsCString::Left(nsCString& aCopy,PRInt32 aCount) const { - aCount = (aCount<0) ? mStringValue.mLength : MinInt(aCount,mStringValue.mLength); + aCount = (aCount<0) ? mStringValue.mLength : (aCount<(PRInt32)mStringValue.mLength) ? aCount : mStringValue.mLength; return aCopy.Assign(*this,aCount,0); } nsresult nsCString::Mid(nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount) const { - aCount = (aCount<0) ? mStringValue.mLength : MinInt(aCount,mStringValue.mLength); + aCount = (aCount<0) ? mStringValue.mLength : (aCount<(PRInt32)mStringValue.mLength) ? aCount : mStringValue.mLength; return aCopy.Assign(*this,aCount,anOffset); } nsresult nsCString::Right(nsCString& aCopy,PRInt32 aCount) const { - PRInt32 offset=MaxInt(mStringValue.mLength-aCount,0); + PRUint32 theLen=mStringValue.mLength-aCount; + PRInt32 offset=(theLen<0) ? 0 : theLen; return Mid(aCopy,offset,aCount); } @@ -539,12 +613,15 @@ nsCString& nsCString::operator+=(const char* aString) { return *this; } -/* nsCString& nsCString::operator+=(const PRUnichar* aString) { Append(aString); return *this; } -*/ + +nsCString& nsCString::operator+=(const nsCString& aCString) { + Append(aCString); + return *this; +} nsCString& nsCString::operator+=(const char aChar) { char theBuffer[]={aChar,0}; @@ -552,13 +629,11 @@ nsCString& nsCString::operator+=(const char aChar) { return *this; } -/* nsCString& nsCString::operator+=(const PRUnichar aChar) { PRUnichar theBuffer[]={aChar,0}; Append(theBuffer,1); return *this; } -*/ nsCString& nsCString::operator+=(const int anInt){ Append(anInt,10); @@ -566,7 +641,7 @@ nsCString& nsCString::operator+=(const int anInt){ } void nsCString::ToLowerCase() { - SVToLowerCase(mStringValue); + SVToLowerCase(mStringValue); } void nsCString::ToLowerCase(nsCString &aString) const { @@ -575,7 +650,7 @@ void nsCString::ToLowerCase(nsCString &aString) const { } void nsCString::ToUpperCase() { - SVToUpperCase(mStringValue); + SVToUpperCase(mStringValue); } void nsCString::ToUpperCase(nsCString &aString) const { @@ -585,48 +660,43 @@ void nsCString::ToUpperCase(nsCString &aString) const { PRInt32 nsCString::Compare(const nsCString &aString,PRBool aIgnoreCase,PRInt32 aCount) const { - return SVCompare(mStringValue,aString.mStringValue,aIgnoreCase,aCount); + return SVCompareChars(mStringValue,aString.mStringValue,aIgnoreCase,aCount); } PRInt32 nsCString::Compare(const char* aString,PRBool aIgnoreCase,PRInt32 aCount) const { - nsStringValueImpl theStringValue(const_cast(aString),aCount); - return SVCompare(mStringValue,theStringValue,aIgnoreCase,aCount); + nsStringValueImpl theStringValue(CONST_CAST(char*,aString),aCount); + return SVCompareChars(mStringValue,theStringValue,aIgnoreCase,aCount); } PRInt32 nsCString::Compare(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 aCount) const { - nsStringValueImpl theStringValue(const_cast(aString),aCount); - return SVCompare(mStringValue,theStringValue,aIgnoreCase,aCount); + nsStringValueImpl theStringValue(CONST_CAST(PRUnichar*,aString),aCount); + return SVCompare(mStringValue,theStringValue,aIgnoreCase,aCount); } PRBool nsCString::Equals(const nsString &aString,PRBool aIgnoreCase,PRInt32 aCount) const { - PRInt32 result=SVCompare(mStringValue,aString.mStringValue,aIgnoreCase,aCount); - return PRBool(0==result); + return PRBool(0==SVCompare(mStringValue,aString.mStringValue,aIgnoreCase,aCount)); } PRBool nsCString::Equals(const nsCString &aString,PRBool aIgnoreCase,PRInt32 aCount) const { - PRInt32 result=SVCompare(mStringValue,aString.mStringValue,aIgnoreCase,aCount); + PRInt32 result=SVCompareChars(mStringValue,aString.mStringValue,aIgnoreCase,aCount); return PRBool(0==result); } PRBool nsCString::Equals(const char* aString,PRBool aIgnoreCase,PRInt32 aCount) const { - nsStringValueImpl theStringValue(const_cast(aString),aCount); - PRInt32 result=SVCompare(mStringValue,theStringValue,aIgnoreCase,aCount); - return PRBool(0==result); + nsStringValueImpl theStringValue(CONST_CAST(char*,aString),aCount); + return PRBool(0==SVCompareChars(mStringValue,theStringValue,aIgnoreCase,aCount)); } PRBool nsCString::Equals(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 aCount) const { - nsStringValueImpl theStringValue(const_cast(aString),aCount); - PRInt32 result=SVCompare(mStringValue,theStringValue,aIgnoreCase,aCount); - return PRBool(0==result); + nsStringValueImpl theStringValue(CONST_CAST(PRUnichar*,aString),aCount); + return PRBool(0==SVCompare(mStringValue,theStringValue,aIgnoreCase,aCount)); } -PRBool nsCString::EqualsIgnoreCase(const char* s1, const char* s2) const { - PRBool result=PR_FALSE; - return result; -} - // PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const; +PRBool nsCString::Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const { + return PR_TRUE; +} /*************************************** @@ -644,7 +714,7 @@ PRBool nsCString::EqualsIgnoreCase(const char* s1, const char* s2) const { * @return offset in string, or -1 (kNotFound) */ PRInt32 nsCString::Find(const nsString& aTarget,PRBool aIgnoreCase,PRUint32 anOffset,PRInt32 aRepCount) const { - return SVFind(mStringValue,aTarget.mStringValue,aIgnoreCase,aRepCount,anOffset); + return SVFind(mStringValue,aTarget.mStringValue,aIgnoreCase,aRepCount,anOffset); } /** @@ -658,7 +728,7 @@ PRInt32 nsCString::Find(const nsString& aTarget,PRBool aIgnoreCase,PRUint32 anOf * @return offset in string, or -1 (kNotFound) */ PRInt32 nsCString::Find(const nsCString &aString,PRBool aIgnoreCase,PRUint32 anOffset,PRInt32 aRepCount) const { - return SVFind(mStringValue,aString.mStringValue,aIgnoreCase,aRepCount,anOffset); + return SVFind(mStringValue,aString.mStringValue,aIgnoreCase,aRepCount,anOffset); } /** @@ -672,8 +742,8 @@ PRInt32 nsCString::Find(const nsCString &aString,PRBool aIgnoreCase,PRUint32 anO * @return offset in string, or -1 (kNotFound) */ PRInt32 nsCString::Find(const char* aString,PRBool aIgnoreCase,PRUint32 anOffset,PRInt32 aRepCount) const { - nsStringValueImpl theString(const_cast(aString)); - return SVFind(mStringValue,theString,aIgnoreCase,aRepCount,anOffset); + nsStringValueImpl theString(CONST_CAST(char*,aString)); + return SVFind(mStringValue,theString,aIgnoreCase,aRepCount,anOffset); } /** @@ -688,8 +758,8 @@ PRInt32 nsCString::Find(const char* aString,PRBool aIgnoreCase,PRUint32 anOffset */ PRInt32 nsCString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRUint32 anOffset,PRInt32 aRepCount) const { - nsStringValueImpl theString(const_cast(aString)); - return SVFind(mStringValue,theString,aIgnoreCase,aRepCount,anOffset); + nsStringValueImpl theString(CONST_CAST(PRUnichar*,aString)); + return SVFind(mStringValue,theString,aIgnoreCase,aRepCount,anOffset); } /** @@ -701,8 +771,8 @@ PRInt32 nsCString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRUint32 anO * @param anOffset -- where in this string to start searching * @return */ -PRInt32 nsCString::FindCharInSet(const nsString& aString,PRUint32 anOffset) const{ - return SVFindCharInSet(mStringValue,aString.mStringValue,PR_FALSE,mStringValue.mLength,anOffset); +PRInt32 nsCString::FindCharInSet(const nsCString& aString,PRUint32 anOffset) const{ + return SVFindCharInSet(mStringValue,aString.mStringValue,PR_FALSE,mStringValue.mLength,anOffset); } @@ -717,8 +787,8 @@ PRInt32 nsCString::FindCharInSet(const nsString& aString,PRUint32 anOffset) cons */ PRInt32 nsCString::FindCharInSet(const char *aString,PRUint32 anOffset) const{ - nsStringValueImpl theStringValue(const_cast(aString)); - return SVFindCharInSet(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset); + nsStringValueImpl theStringValue(CONST_CAST(char*,aString)); + return SVFindCharInSet(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset); } /** @@ -732,7 +802,7 @@ PRInt32 nsCString::FindCharInSet(const char *aString,PRUint32 anOffset) const{ * @return offset in string, or -1 (kNotFound) */ PRInt32 nsCString::FindChar(char aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const { - return SVFindChar(mStringValue,aChar,aIgnoreCase,aCount,anOffset); + return SVFindChar(mStringValue,aChar,aIgnoreCase,aCount,anOffset); } /** @@ -746,13 +816,13 @@ PRInt32 nsCString::FindChar(char aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt * @return offset in string, or -1 (kNotFound) */ PRInt32 nsCString::RFindChar(char aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aRepCount) const{ - return SVRFindChar(mStringValue,aChar,aIgnoreCase,aRepCount,anOffset); + return SVRFindChar(mStringValue,aChar,aIgnoreCase,aRepCount,anOffset); } - + PRInt32 nsCString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aRepCount) const{ - nsStringValueImpl theStringValue(const_cast(aString)); - return SVRFind(mStringValue,theStringValue,aIgnoreCase,aRepCount,anOffset); + nsStringValueImpl theStringValue(CONST_CAST(char*,aString)); + return SVRFind(mStringValue,theStringValue,aIgnoreCase,aRepCount,anOffset); } @@ -766,7 +836,7 @@ PRInt32 nsCString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset * @return */ PRInt32 nsCString::RFindCharInSet(const nsCString& aString,PRInt32 anOffset) const { - return SVRFindCharInSet(mStringValue,aString.mStringValue,PR_FALSE,mStringValue.mLength,anOffset); + return SVRFindCharInSet(mStringValue,aString.mStringValue,PR_FALSE,mStringValue.mLength,anOffset); } @@ -780,8 +850,8 @@ PRInt32 nsCString::RFindCharInSet(const nsCString& aString,PRInt32 anOffset) con * @return */ PRInt32 nsCString::RFindCharInSet(const char* aString,PRInt32 anOffset) const{ - nsStringValueImpl theStringValue(const_cast(aString)); - return SVRFindCharInSet(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset); + nsStringValueImpl theStringValue(CONST_CAST(char*,aString)); + return SVRFindCharInSet(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset); } /*************************************** @@ -827,7 +897,7 @@ char* nsCString::ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset) con PRInt32 nsCString::CountChar(char aChar) { - return SVCountChar(mStringValue,aChar); + return SVCountChar(mStringValue,aChar); } //****************************************** @@ -837,7 +907,7 @@ PRInt32 nsCString::CountChar(char aChar) { //This will not work correctly for any unicode set other than ascii void nsCString::DebugDump(void) const { - SVDebugDump(mStringValue); + SVDebugDump(mStringValue); } /** @@ -852,7 +922,7 @@ float nsCString::ToFloat(PRInt32* aErrorCode) const { return 0.0f; } char* cp = ToCString(buf, sizeof(buf)); - float f = (float) PR_strtod(cp, &cp); + float f = (float) strtod(cp, &cp); if (*cp != 0) { *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; } @@ -860,6 +930,7 @@ float nsCString::ToFloat(PRInt32* aErrorCode) const { return f; } + /** * Perform string to int conversion. * @param aErrorCode will contain error if one occurs @@ -867,7 +938,214 @@ float nsCString::ToFloat(PRInt32* aErrorCode) const { * @return int rep of string value, and possible (out) error code */ PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const{ - return SVToInteger(mStringValue,anErrorCode,aRadix); + return SVToInteger(mStringValue,anErrorCode,aRadix); } + + +/***************************************************************** + Now we declare the nsSubsumeCStr class + *****************************************************************/ + + +nsSubsumeCStr::nsSubsumeCStr() { +} + +nsSubsumeCStr::nsSubsumeCStr(const nsCString& aCString) : mLHS(aCString.mStringValue), mRHS() { +} + +nsSubsumeCStr::nsSubsumeCStr(const nsSubsumeCStr& aSubsumeString) : + mLHS(aSubsumeString.mLHS), + mRHS(aSubsumeString.mRHS) { +} + +nsSubsumeCStr::nsSubsumeCStr(const nsStringValueImpl &aLHS,const nsSubsumeCStr& aSubsumeString) : + mLHS(aLHS), + mRHS(aSubsumeString.mLHS) { +} + +nsSubsumeCStr::nsSubsumeCStr(const nsStringValueImpl &aLHS,const nsStringValueImpl &aRHS) : + mLHS(aLHS), + mRHS(aRHS) { +} + +nsSubsumeCStr::nsSubsumeCStr(char* aString,PRBool assumeOwnership,PRInt32 aLength) { +} + +nsSubsumeCStr nsSubsumeCStr::operator+(const nsSubsumeCStr &aSubsumeString) { + nsSubsumeCStr result(*this); + return result; +} + +nsSubsumeCStr nsSubsumeCStr::operator+(const nsCString &aCString) { + SVAppend(mLHS,mRHS,mRHS.mLength,0); + memcpy(&mRHS,&aCString.mStringValue,sizeof(mRHS)); + return *this; +} + +/** + * + * @update gess 01/04/99 + * @param + * @return + */ +NS_COM int fputs(const nsCString& aString, FILE* out) +{ + char buf[100]; + char* cp = buf; + PRInt32 len = aString.Length(); + if (len >= PRInt32(sizeof(buf))) { + cp = aString.ToNewCString(); + } else { + aString.ToCString(cp, len + 1); + } + if(len>0) + ::fwrite(cp, 1, len, out); + if (cp != buf) { + delete[] cp; + } + return (int) len; +} + +PRUint32 HashCode(const nsCString& aDest) { + PRUint32 result=0; +// return (PRUint32)PL_HashString((const void*) aDest.GetBuffer()); + return result; +} + +void Recycle( char* aBuffer) { + nsAllocator::Free(aBuffer); +} + +/***************************************************************** + Now we declare the nsCAutoString class + *****************************************************************/ + + +nsCAutoString::nsCAutoString() : nsCString() { + memset(mInternalBuffer,0,sizeof(mInternalBuffer)); + mStringValue.mCapacity=kDefaultStringSize; + mStringValue.mBuffer=mInternalBuffer; +} + + //call this version nsAutoString derivatives... +nsCAutoString::nsCAutoString(const nsCAutoString& aString,PRInt32 aLength) : nsCString() { + memset(mInternalBuffer,0,sizeof(mInternalBuffer)); + mStringValue.mCapacity=kDefaultStringSize; + mStringValue.mBuffer=mInternalBuffer; + Assign(aString,aLength); +} + +//call this version for nsCString,nsCString and the autostrings +nsCAutoString::nsCAutoString(const nsCString& aString,PRInt32 aLength) : nsCString() { + memset(mInternalBuffer,0,sizeof(mInternalBuffer)); + mStringValue.mCapacity=kDefaultStringSize; + mStringValue.mBuffer=mInternalBuffer; + Assign(aString,aLength); +} + + //call this version for char*'s.... +nsCAutoString::nsCAutoString(const char* aString,PRInt32 aLength) : nsCString() { + memset(mInternalBuffer,0,sizeof(mInternalBuffer)); + + nsCString theString(aString); + mStringValue.mCapacity=kDefaultStringSize; + mStringValue.mBuffer=mInternalBuffer; + Assign(theString,aLength); +} + + //call this version for a single char of type char... +nsCAutoString::nsCAutoString(const char aChar) : nsCString() { + char theBuffer[]={aChar,0}; + + memset(mInternalBuffer,0,sizeof(mInternalBuffer)); + mStringValue.mCapacity=kDefaultStringSize; + mStringValue.mBuffer=mInternalBuffer; + + nsCString theString(theBuffer,1); + Assign(theString,1,0); +} + + + //call this version for PRUnichar*'s.... +nsCAutoString::nsCAutoString(const PRUnichar* aString,PRInt32 aLength) : nsCString() { + memset(mInternalBuffer,0,sizeof(mInternalBuffer)); + mStringValue.mCapacity=kDefaultStringSize; + mStringValue.mBuffer=mInternalBuffer; + nsStringValueImpl theString(CONST_CAST(PRUnichar*,aString),aLength); + SVAssign(mStringValue,theString,theString.mLength,0); +} + + + //call this version for all other ABT versions of readable strings +nsCAutoString::nsCAutoString(const nsAReadableString &aString) : nsCString() { + memset(mInternalBuffer,0,sizeof(mInternalBuffer)); + mStringValue.mCapacity=kDefaultStringSize; + mStringValue.mBuffer=mInternalBuffer; + Assign(aString); +} + +nsCAutoString::nsCAutoString(const nsCStackBuffer &aBuffer) : nsCString() { + + memset(mInternalBuffer,0,sizeof(mInternalBuffer)); + + mStringValue.mLength=aBuffer.mLength; + mStringValue.mCapacity=aBuffer.mCapacity; + mStringValue.mBuffer=aBuffer.mBuffer; + +} + +nsCAutoString::nsCAutoString(const CBufDescriptor& aBuffer) : nsCString() { + + mStringValue.mBuffer=aBuffer.mBuffer; + mStringValue.mCapacity=aBuffer.mCapacity; + mStringValue.mLength=aBuffer.mLength; + mStringValue.mRefCount=(aBuffer.mStackBased) ? 2 : 1; + +} + +nsCAutoString::nsCAutoString(const nsSubsumeCStr& aCSubsumeStringX) : nsCString() { +} + +nsCAutoString::~nsCAutoString() { +} + + +nsCAutoString& nsCAutoString::operator=(const nsCAutoString& aCopy) { + if(aCopy.mStringValue.mBuffer!=mStringValue.mBuffer) { + Assign(aCopy); + } + return *this; +} + +nsCAutoString& nsCAutoString::operator=(const nsCString& aString) { + Assign(aString); + return *this; +} + +nsCAutoString& nsCAutoString::operator=(const char* aString) { + if(mStringValue.mBuffer!=aString) { + nsCString theStringValue(CONST_CAST(char*,aString)); + Assign(aString); + } + return *this; +} + +nsCAutoString& nsCAutoString::operator=(const PRUnichar* aString) { + nsStringValueImpl theStringValue(CONST_CAST(PRUnichar*,aString)); + SVAssign(mStringValue,theStringValue,theStringValue.mLength,0); + return *this; +} + +nsCAutoString& nsCAutoString::operator=(const char aChar) { + Assign(aChar); + return *this; +} + + +nsCAutoString& nsCAutoString::operator=(const nsSubsumeCStr &aSubsumeString) { + nsCString::operator=(aSubsumeString); + return *this; +} + diff --git a/mozilla/xpcom/ds/nsStringx.h b/mozilla/xpcom/ds/nsStringx.h index ec073fd85c4..6d69c1263c8 100644 --- a/mozilla/xpcom/ds/nsStringx.h +++ b/mozilla/xpcom/ds/nsStringx.h @@ -21,11 +21,13 @@ #define _NS_CSTRING_ #include "nsStringValue.h" +#include "nsString2.h" +class NS_COM nsSubsumeCStr; -class nsString; +typedef nsStackBuffer nsCStackBuffer; -class nsCString: public nsAReadableString { +class NS_COM nsCString { public: //****************************************** @@ -49,48 +51,65 @@ public: //call this version for PRUnichar*'s.... nsCString(const PRUnichar* aString,PRInt32 aLength=-1) ; + //call this version for stack-based string buffers... + nsCString(const nsSubsumeCStr &aSubsumeString); + + //call this version for stack-based string buffers... + nsCString(nsSubsumeCStr &aSubsumeString); + //call this version for all other ABT versions of readable strings nsCString(const nsAReadableString &aString) ; //call this version for stack-based string buffers... - nsCString(const nsStackBuffer &aBuffer); + nsCString(const nsCStackBuffer &aBuffer); virtual ~nsCString(); - + void Reinitialize(char* aBuffer,PRUint32 aCapacity,PRInt32 aLength=-1); + + //****************************************** + // Concat operators + //****************************************** + + nsSubsumeCStr operator+(const nsCString &aCString); + nsSubsumeCStr operator+(const char* aCString); + nsSubsumeCStr operator+(char aChar); + + //****************************************** // Assigment operators //****************************************** nsCString& operator=(const nsCString& aString); - nsCString& operator=(const nsString& aString); - nsCString& operator=(const char* aString); - nsCString& operator=(const PRUnichar* aString); - nsCString& operator=(const char aChar); + nsCString& operator=(const nsSubsumeCStr &aSubsumeString); //****************************************** // Here are the accessor methods... //****************************************** virtual nsresult SetLength(PRUint32 aLength) { + if(aLength>mStringValue.mLength) + SetCapacity(aLength); Truncate(aLength); return NS_OK; } virtual nsresult SetCapacity(PRUint32 aCapacity); - char* GetBuffer() { return mStringValue.mBuffer;} + char* GetBuffer() const { return mStringValue.mBuffer;} - char& operator[](PRUint32 aOffset); + char operator[](PRUint32 aOffset) const {return CharAt(aOffset);} -// operator const PRUnichar* const() {return mStringValue.mBuffer;} + operator const char*() const {return (const char*)mStringValue.mBuffer;} + operator char*() const {return mStringValue.mBuffer;} PRUint32 Length() const {return mStringValue.mLength;} + PRUint32 Capacity() const {return mStringValue.mCapacity;} size_t GetCharSize() const {return sizeof(mStringValue.mBuffer[0]);} @@ -112,10 +131,11 @@ public: return CharAt(mStringValue.mLength-1); } - - //these aren't the real deal, but serve as a placeholder for us to implement iterators. - virtual nsAReadableStringIterator* First(); - virtual nsAReadableStringIterator* Last(); + virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const { + if (aResult) { + *aResult = sizeof(*this) + Capacity(); + } + } //****************************************** @@ -137,21 +157,19 @@ public: */ virtual nsresult Assign(const nsCString& aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0); + virtual nsresult Assign(const nsString& aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0); + virtual nsresult Assign(const char* aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0); -// virtual nsresult Assign(const PRUnichar* aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0); + virtual nsresult Assign(const PRUnichar* aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0); virtual nsresult Assign(const nsAReadableString &aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0); virtual nsresult Assign(char aChar); - /** - * Functionally equivalent to assign or operator=, and deprePRUnichared! - * - */ - nsresult SetString(const nsCString &aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} - nsresult SetString(const PRUnichar* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} - nsresult SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} + nsCString& SetString(const char* aString,PRInt32 aLength=-1) {Assign(aString, aLength); return *this;} + nsCString& SetString(const nsCString& aString,PRInt32 aLength=-1) {Assign(aString, aLength); return *this;} + //*************************************** // Here come the append methods... @@ -172,7 +190,7 @@ public: virtual nsresult Append(const char* aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0); -// virtual nsresult Append(const PRUnichar* aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0); + virtual nsresult Append(const PRUnichar* aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0); virtual nsresult Append(const char aChar) ; @@ -273,7 +291,7 @@ public: nsresult StripChar(PRInt32 anInt,PRUint32 anOffset=0); - nsresult StripChars(const char* aSet); + nsresult StripChars(const char* aSet,PRInt32 aLength=-1); nsresult StripWhitespace(); @@ -293,16 +311,15 @@ public: //******************************************* nsCString& operator+=(const nsCString& aString); - nsCString& operator+=(const PRUnichar* aString); - nsCString& operator+=(const char* aString); - nsCString& operator+=(const PRUnichar aChar); - nsCString& operator+=(const char aChar); - nsCString& operator+=(const int anInt); + nsCString& operator+=(const nsSubsumeCStr &aSubsumeString) { + //NOT IMPLEMENTED + return *this; + } /*********************************** @@ -312,6 +329,7 @@ public: PRBool operator==(const nsCString& aString) const {return Equals(aString);} PRBool operator==(const PRUnichar* aString) const {return Equals(aString);} PRBool operator==(const char* aString) const {return Equals(aString);} + PRBool operator==(char* aString) const {return Equals(aString);} PRBool operator!=(const nsCString& aString) const {return PRBool(Compare(aString)!=0);} PRBool operator!=(const PRUnichar* aString) const {return PRBool(Compare(aString)!=0);} @@ -335,24 +353,18 @@ public: PRInt32 Compare(const nsCString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; - PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; - PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const ; PRBool Equals(const nsCString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; - PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; - PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; - PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; + PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const; PRBool EqualsIgnoreCase(const nsCString &aString) const {return Equals(aString,PR_TRUE);} PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const {return Equals(aString,PR_TRUE);} - PRBool EqualsIgnoreCase(const char* s1, const char* s2) const; - - // PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const; + PRBool EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const; /*************************************** @@ -373,7 +385,7 @@ public: PRInt32 Find(const nsString& aTarget,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0,PRInt32 aRepCount=-1) const; PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0,PRInt32 aRepCount=-1) const; PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0,PRInt32 aRepCount=-1) const; - PRInt32 FindChar(char aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aRepCount=-1) const ; + PRInt32 FindChar(char aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aRepCount=-1) const ; PRInt32 FindCharInSet(const nsCString& aString,PRUint32 anOffset=0) const; PRInt32 FindCharInSet(const nsString& aString,PRUint32 anOffset=0) const; @@ -443,8 +455,37 @@ protected: nsStringValueImpl mStringValue; friend class nsString; + friend class nsSubsumeCStr; }; +/***************************************************************** + Now we declare the nsSubsumeCStr class + *****************************************************************/ + +class NS_COM nsSubsumeCStr { +public: + + nsSubsumeCStr(); + + nsSubsumeCStr(const nsCString& aCString); + + nsSubsumeCStr(const nsSubsumeCStr& aSubsumeString); + + nsSubsumeCStr(const nsStringValueImpl &aLHS,const nsSubsumeCStr& aSubsumeString); + + nsSubsumeCStr(const nsStringValueImpl &aLHS,const nsStringValueImpl &aSubsumeString); + + nsSubsumeCStr(char* aString,PRBool assumeOwnership,PRInt32 aLength=-1); + + nsSubsumeCStr operator+(const nsSubsumeCStr &aSubsumeString); + + nsSubsumeCStr operator+(const nsCString &aCString); + + operator const char*() {return 0;} + + nsStringValueImpl mLHS; + nsStringValueImpl mRHS; +}; /***************************************************************** @@ -452,122 +493,56 @@ protected: *****************************************************************/ -class nsCAutoString : public nsCString { +class NS_COM nsCAutoString : public nsCString { public: - nsCAutoString() : nsCString() { - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - } + nsCAutoString() ; //call this version nsAutoString derivatives... - nsCAutoString(const nsCAutoString& aString,PRInt32 aLength=-1) : nsCString() { - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - Assign(aString,aLength); - } + nsCAutoString(const nsCAutoString& aString,PRInt32 aLength=-1); //call this version for nsCString,nsCString and the autostrings - nsCAutoString(const nsCString& aString,PRInt32 aLength=-1) : nsCString() { - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - Assign(aString,aLength); - } - + nsCAutoString(const nsCString& aString,PRInt32 aLength=-1) ; //call this version for char*'s.... - nsCAutoString(const char* aString,PRInt32 aLength=-1) : nsCString() { - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); - - nsCString theString(aString); - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - Assign(theString,aLength); - } + nsCAutoString(const char* aString,PRInt32 aLength=-1); //call this version for a single char of type char... - nsCAutoString(const char aChar) : nsCString() { - char theBuffer[]={aChar,0}; - - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - - nsCString theString(theBuffer,1); - Assign(theString,1,0); - } - + nsCAutoString(const char aChar) ; //call this version for PRUnichar*'s.... - nsCAutoString(const PRUnichar* aString,PRInt32 aLength=-1) : nsCString() { - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - nsStringValueImpl theString(const_cast(aString),aLength); - SVAssign(mStringValue,theString,theString.mLength,0); - } - + nsCAutoString(const PRUnichar* aString,PRInt32 aLength=-1) ; //call this version for all other ABT versions of readable strings - nsCAutoString(const nsAReadableString &aString) : nsCString() { - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - Assign(aString); - } + nsCAutoString(const nsAReadableString &aString); - nsCAutoString(const nsStackBuffer &aBuffer) : nsCString() { + nsCAutoString(const nsCStackBuffer &aBuffer) ; - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); + nsCAutoString(const CBufDescriptor& aBuffer) ; - mStringValue.mRefCount=2; - mStringValue.mLength=aBuffer.mLength; - mStringValue.mCapacity=aBuffer.mCapacity; - mStringValue.mBuffer=aBuffer.mBuffer; - - } + nsCAutoString(const nsSubsumeCStr& aCSubsumeStringX) ; - - virtual ~nsCAutoString() { } + virtual ~nsCAutoString() ; - nsCAutoString& operator=(const nsCAutoString& aCopy) { - if(aCopy.mStringValue.mBuffer!=mStringValue.mBuffer) { - Assign(aCopy); - } - return *this; - } + nsCAutoString& operator=(const nsCAutoString& aCopy) ; - nsCAutoString& operator=(const nsCString& aString) { - Assign(aString); - return *this; - } + nsCAutoString& operator=(const nsCString& aString) ; - nsCAutoString& operator=(const char* aString) { - if(mStringValue.mBuffer!=aString) { - nsCString theStringValue(const_cast(aString)); - Assign(aString); - } - return *this; - } + nsCAutoString& operator=(const char* aString) ; - nsCAutoString& operator=(const PRUnichar* aString) { - nsStringValueImpl theStringValue(const_cast(aString)); - SVAssign(mStringValue,theStringValue,theStringValue.mLength,0); - return *this; - } + nsCAutoString& operator=(const PRUnichar* aString) ; - nsCAutoString& operator=(const char aChar) { - Assign(aChar); - return *this; - } + nsCAutoString& operator=(const char aChar) ; + + nsCAutoString& operator=(const nsSubsumeCStr &aSubsumeString); protected: char mInternalBuffer[kDefaultStringSize+1]; }; +extern PRUint32 HashCode(const nsCString& aDest); +extern NS_COM int fputs(const nsCString& aString, FILE* out); +extern NS_COM void Recycle( char* aBuffer); #endif