bugs 13038 and 14920; also improved comments. r=kmcclusk

This commit is contained in:
rickg@netscape.com
1999-10-05 04:47:19 +00:00
parent 24cdd75dcd
commit e90dcad4bf
19 changed files with 4521 additions and 4600 deletions

View File

@@ -69,16 +69,6 @@ void nsStr::Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 a
aDest.mOwnsBuffer=aOwnsBuffer;
}
/**
*
* @update gess10/30/98
* @param
* @return
*/
nsIMemoryAgent* GetDefaultAgent(void){
static nsMemoryAgent gDefaultAgent;
return (nsIMemoryAgent*)&gDefaultAgent;
}
/**
* This member destroys the memory buffer owned by an nsStr object (if it actually owns it)
@@ -86,17 +76,9 @@ nsIMemoryAgent* GetDefaultAgent(void){
* @param
* @return
*/
void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) {
void nsStr::Destroy(nsStr& aDest) {
if((aDest.mStr) && (aDest.mStr!=(char*)gCommonEmptyBuffer)) {
if(!anAgent)
anAgent=GetDefaultAgent();
if(anAgent) {
anAgent->Free(aDest);
}
else{
printf("%s\n","Leak occured in nsStr.");
}
Free(aDest);
}
}
@@ -108,11 +90,10 @@ void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) {
* @param aNewLength -- new capacity of string in charSize units
* @return void
*/
PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent) {
PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength) {
PRBool result=PR_TRUE;
if(aNewLength>aString.mCapacity) {
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
result=theAgent->Realloc(aString,aNewLength);
result=Realloc(aString,aNewLength);
if(aString.mStr)
AddNullTerminator(aString);
}
@@ -126,20 +107,18 @@ PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent*
* @param aNewLength -- new capacity of string in charSize units
* @return void
*/
PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAgent) {
PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength) {
PRBool result=PR_TRUE;
if(aNewLength>aDest.mCapacity) {
nsStr theTempStr;
nsStr::Initialize(theTempStr,aDest.mCharSize);
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
result=EnsureCapacity(theTempStr,aNewLength,theAgent);
result=EnsureCapacity(theTempStr,aNewLength);
if(result) {
if(aDest.mLength) {
Append(theTempStr,aDest,0,aDest.mLength,theAgent);
Append(theTempStr,aDest,0,aDest.mLength);
}
theAgent->Free(aDest);
Free(aDest);
aDest.mStr = theTempStr.mStr;
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
aDest.mLength=theTempStr.mLength;
@@ -157,10 +136,10 @@ PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAg
* @param aSource is where chars are copied from
* @param aCount is the number of chars copied from aSource
*/
void nsStr::Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){
void nsStr::Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount){
if(&aDest!=&aSource){
Truncate(aDest,0,anAgent);
Append(aDest,aSource,anOffset,aCount,anAgent);
Truncate(aDest,0);
Append(aDest,aSource,anOffset,aCount);
}
}
@@ -172,7 +151,7 @@ void nsStr::Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 a
* @param aSource is where char are copied from
* @aCount is the number of bytes to be copied
*/
void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){
void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount){
if(anOffset<aSource.mLength){
PRUint32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
PRUint32 theLength=(anOffset+theRealLen<aSource.mLength) ? theRealLen : (aSource.mLength-anOffset);
@@ -180,7 +159,7 @@ void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 a
PRBool isBigEnough=PR_TRUE;
if(aDest.mLength+theLength > aDest.mCapacity) {
isBigEnough=GrowCapacity(aDest,aDest.mLength+theLength,anAgent);
isBigEnough=GrowCapacity(aDest,aDest.mLength+theLength);
}
if(isBigEnough) {
@@ -204,7 +183,7 @@ void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 a
* @param aSrcOffset is where in aSource chars are copied from
* @param aCount is the number of chars from aSource to be inserted into aDest
*/
void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){
void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount){
//there are a few cases for insert:
// 1. You're inserting chars into an empty string (assign)
// 2. You're inserting onto the end of a string (append)
@@ -223,22 +202,21 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin
nsStr theTempStr;
nsStr::Initialize(theTempStr,aDest.mCharSize);
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
PRBool isBigEnough=EnsureCapacity(theTempStr,aDest.mLength+theLength,theAgent); //grow the temp buffer to the right size
PRBool isBigEnough=EnsureCapacity(theTempStr,aDest.mLength+theLength); //grow the temp buffer to the right size
if(isBigEnough) {
if(aDestOffset) {
Append(theTempStr,aDest,0,aDestOffset,theAgent); //first copy leftmost data...
Append(theTempStr,aDest,0,aDestOffset); //first copy leftmost data...
}
Append(theTempStr,aSource,0,aSource.mLength,theAgent); //next copy inserted (new) data
Append(theTempStr,aSource,0,aSource.mLength); //next copy inserted (new) data
PRUint32 theRemains=aDest.mLength-aDestOffset;
if(theRemains) {
Append(theTempStr,aDest,aDestOffset,theRemains,theAgent); //next copy rightmost data
Append(theTempStr,aDest,aDestOffset,theRemains); //next copy rightmost data
}
theAgent->Free(aDest);
Free(aDest);
aDest.mStr = theTempStr.mStr;
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
aDest.mCapacity=theTempStr.mCapacity;
@@ -262,9 +240,9 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin
}//if
//else nothing to do!
}
else Append(aDest,aSource,0,aCount,anAgent);
else Append(aDest,aSource,0,aCount);
}
else Append(aDest,aSource,0,aCount,anAgent);
else Append(aDest,aSource,0,aCount);
}
}
@@ -276,7 +254,7 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin
* @param aDestOffset is where in aDest deletion is to occur
* @param aCount is the number of chars to be deleted in aDest
*/
void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAgent* anAgent){
void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount){
if(aDestOffset<aDest.mLength){
PRUint32 theDelta=aDest.mLength-aDestOffset;
@@ -290,7 +268,7 @@ void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAg
aDest.mLength-=theLength;
AddNullTerminator(aDest);
}
else Truncate(aDest,aDestOffset,anAgent);
else Truncate(aDest,aDestOffset);
}//if
}
@@ -300,7 +278,7 @@ void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAg
* @param aDest is the nsStr to be truncated
* @param aDestOffset is where in aDest truncation is to occur
*/
void nsStr::Truncate(nsStr& aDest,PRUint32 aDestOffset,nsIMemoryAgent* anAgent){
void nsStr::Truncate(nsStr& aDest,PRUint32 aDestOffset){
if(aDestOffset<aDest.mLength){
aDest.mLength=aDestOffset;
AddNullTerminator(aDest);
@@ -342,7 +320,7 @@ void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool a
}
if(0<theIndex) {
if(theIndex<theMax) {
Delete(aDest,0,theIndex,0);
Delete(aDest,0,theIndex);
}
else Truncate(aDest,0);
}
@@ -515,7 +493,7 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgno
nsStr theCopy;
nsStr::Initialize(theCopy,eOneByte);
nsStr::Assign(theCopy,aTarget,0,aTarget.mLength,0);
nsStr::Assign(theCopy,aTarget,0,aTarget.mLength);
if(aIgnoreCase){
nsStr::ChangeCase(theCopy,PR_FALSE); //force to lowercase
}
@@ -538,7 +516,7 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgno
}
index--;
} //while
nsStr::Destroy(theCopy,0);
nsStr::Destroy(theCopy);
}//if
}//if
return result;
@@ -625,6 +603,57 @@ PRInt32 nsStr::Compare(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PR
//----------------------------------------------------------------------------------------
PRBool nsStr::Alloc(nsStr& aDest,PRUint32 aCount) {
static int mAllocCount=0;
mAllocCount++;
//we're given the acount value in charunits; now scale up to next multiple.
PRUint32 theNewCapacity=kDefaultStringSize;
while(theNewCapacity<aCount){
theNewCapacity<<=1;
}
aDest.mCapacity=theNewCapacity++;
PRUint32 theSize=(theNewCapacity<<aDest.mCharSize);
aDest.mStr = (char*)nsAllocator::Alloc(theSize);
PRBool result=PR_FALSE;
if(aDest.mStr) {
aDest.mOwnsBuffer=1;
result=PR_TRUE;
}
return result;
}
PRBool nsStr::Free(nsStr& aDest){
if(aDest.mStr){
if(aDest.mOwnsBuffer){
nsAllocator::Free(aDest.mStr);
}
aDest.mStr=0;
aDest.mOwnsBuffer=0;
return PR_TRUE;
}
return PR_FALSE;
}
PRBool nsStr::Realloc(nsStr& aDest,PRUint32 aCount){
nsStr temp;
memcpy(&temp,&aDest,sizeof(aDest));
PRBool result=Alloc(temp,aCount);
if(result) {
Free(aDest);
aDest.mStr=temp.mStr;
aDest.mCapacity=temp.mCapacity;
}
return result;
}
//----------------------------------------------------------------------------------------
CBufDescriptor::CBufDescriptor(char* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength) {
mBuffer=aString;
mCharSize=eOneByte;
@@ -683,3 +712,5 @@ CBufDescriptor::CBufDescriptor(const PRUnichar* aString,PRBool aStackBased,PRUin
}
//----------------------------------------------------------------------------------------

View File

@@ -164,6 +164,7 @@
#include "nscore.h"
#include "nsIAllocator.h"
#include <string.h>
//----------------------------------------------------------------------------------------
@@ -177,8 +178,6 @@ const PRInt32 kDefaultStringSize = 64;
const PRInt32 kNotFound = -1;
class nsIMemoryAgent;
//----------------------------------------------------------------------------------------
class NS_COM CBufDescriptor {
@@ -228,7 +227,7 @@ struct NS_COM nsStr {
* @param aString is the nsStr to be manipulated
* @param anAgent is the allocator to be used to the nsStr
*/
static void Destroy(nsStr& aDest,nsIMemoryAgent* anAgent=0);
static void Destroy(nsStr& aDest);
/**
* These methods are where memory allocation/reallocation occur.
@@ -238,8 +237,8 @@ struct NS_COM nsStr {
* @param anAgent is the allocator to be used on the nsStr
* @return
*/
static PRBool EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0);
static PRBool GrowCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0);
static PRBool EnsureCapacity(nsStr& aString,PRUint32 aNewLength);
static PRBool GrowCapacity(nsStr& aString,PRUint32 aNewLength);
/**
* These methods are used to append content to the given nsStr
@@ -251,7 +250,7 @@ struct NS_COM nsStr {
* @param aCount tells us the (max) # of chars to copy
* @param anAgent is the allocator to be used for alloc/free operations
*/
static void Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0);
static void Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount);
/**
* These methods are used to assign contents of a source string to dest string
@@ -263,7 +262,7 @@ struct NS_COM nsStr {
* @param aCount tells us the (max) # of chars to copy
* @param anAgent is the allocator to be used for alloc/free operations
*/
static void Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0);
static void Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount);
/**
* These methods are used to insert content from source string to the dest nsStr
@@ -276,7 +275,7 @@ struct NS_COM nsStr {
* @param aCount tells us the (max) # of chars to insert
* @param anAgent is the allocator to be used for alloc/free operations
*/
static void Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0);
static void Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount);
/**
* This method deletes chars from the given str.
@@ -288,7 +287,7 @@ struct NS_COM nsStr {
* @param aCount tells us the (max) # of chars to delete
* @param anAgent is the allocator to be used for alloc/free operations
*/
static void Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAgent* anAgent=0);
static void Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount);
/**
* This method is used to truncate the given string.
@@ -301,7 +300,7 @@ struct NS_COM nsStr {
* @param aSrcOffset tells us where in source to start copying
* @param anAgent is the allocator to be used for alloc/free operations
*/
static void Truncate(nsStr& aDest,PRUint32 aDestOffset,nsIMemoryAgent* anAgent=0);
static void Truncate(nsStr& aDest,PRUint32 aDestOffset);
/**
* This method is used to perform a case conversion on the given string
@@ -388,6 +387,12 @@ struct NS_COM nsStr {
char* mStr;
PRUnichar* mUStr;
};
private:
static PRBool Alloc(nsStr& aString,PRUint32 aCount);
static PRBool Realloc(nsStr& aString,PRUint32 aCount);
static PRBool Free(nsStr& aString);
};
/**************************************************************
@@ -430,74 +435,6 @@ inline PRUnichar GetCharAt(const nsStr& aDest,PRUint32 anIndex){
return 0;
}
//----------------------------------------------------------------------------------------
class nsIMemoryAgent {
public:
virtual PRBool Alloc(nsStr& aString,PRUint32 aCount)=0;
virtual PRBool Realloc(nsStr& aString,PRUint32 aCount)=0;
virtual PRBool Free(nsStr& aString)=0;
};
class nsMemoryAgent : public nsIMemoryAgent {
public:
virtual PRBool Alloc(nsStr& aDest,PRUint32 aCount) {
static int mAllocCount=0;
mAllocCount++;
//we're given the acount value in charunits; now scale up to next multiple.
PRUint32 theNewCapacity=kDefaultStringSize;
while(theNewCapacity<aCount){
theNewCapacity<<=1;
}
aDest.mCapacity=theNewCapacity++;
PRUint32 theSize=(theNewCapacity<<aDest.mCharSize);
aDest.mStr = (char*)nsAllocator::Alloc(theSize);
PRBool result=PR_FALSE;
if(aDest.mStr) {
aDest.mOwnsBuffer=1;
result=PR_TRUE;
}
return result;
}
virtual PRBool Free(nsStr& aDest){
if(aDest.mStr){
if(aDest.mOwnsBuffer){
nsAllocator::Free(aDest.mStr);
}
aDest.mStr=0;
aDest.mOwnsBuffer=0;
return PR_TRUE;
}
return PR_FALSE;
}
virtual PRBool Realloc(nsStr& aDest,PRUint32 aCount){
Free(aDest);
return Alloc(aDest,aCount);
#if 0
nsStr temp;
memcpy(&temp,&aDest,sizeof(aDest));
PRBool result=Alloc(temp,aCount);
if(result) {
Free(aDest);
aDest.mStr=temp.mStr;
aDest.mCapacity=temp.mCapacity;
}
return result;
#endif
}
};
nsIMemoryAgent* GetDefaultAgent(void);
#endif

View File

@@ -40,7 +40,7 @@ static const char* kWhitespace="\b\t\r\n ";
static void CSubsume(nsStr& aDest,nsStr& aSource){
if(aSource.mStr && aSource.mLength) {
if(aSource.mOwnsBuffer){
nsStr::Destroy(aDest,0);
nsStr::Destroy(aDest);
aDest.mStr=aSource.mStr;
aDest.mLength=aSource.mLength;
aDest.mCharSize=aSource.mCharSize;
@@ -50,17 +50,17 @@ static void CSubsume(nsStr& aDest,nsStr& aSource){
aSource.mStr=0;
}
else{
nsStr::Assign(aDest,aSource,0,aSource.mLength,0);
nsStr::Assign(aDest,aSource,0,aSource.mLength);
}
}
else nsStr::Truncate(aDest,0,0);
else nsStr::Truncate(aDest,0);
}
/**
* Default constructor.
*/
nsCString::nsCString(nsIMemoryAgent* anAgent) : mAgent(anAgent) {
nsCString::nsCString() {
nsStr::Initialize(*this,eOneByte);
}
@@ -70,7 +70,7 @@ nsCString::nsCString(nsIMemoryAgent* anAgent) : mAgent(anAgent) {
* @param aCString is a ptr to a 1-byte cstr
* @param aLength tells us how many chars to copy from given CString
*/
nsCString::nsCString(const char* aCString,PRInt32 aLength,nsIMemoryAgent* anAgent) : mAgent(anAgent) {
nsCString::nsCString(const char* aCString,PRInt32 aLength) {
nsStr::Initialize(*this,eOneByte);
Assign(aCString,aLength);
}
@@ -81,7 +81,7 @@ nsCString::nsCString(const char* aCString,PRInt32 aLength,nsIMemoryAgent* anAgen
* @param aString is a ptr to a unichar string
* @param aLength tells us how many chars to copy from given aString
*/
nsCString::nsCString(const PRUnichar* aString,PRInt32 aLength,nsIMemoryAgent* anAgent) : mAgent(anAgent) {
nsCString::nsCString(const PRUnichar* aString,PRInt32 aLength) {
nsStr::Initialize(*this,eOneByte);
if(aString && aLength){
@@ -101,7 +101,7 @@ nsCString::nsCString(const PRUnichar* aString,PRInt32 aLength,nsIMemoryAgent* an
else aLength=temp.mLength=nsCRT::strlen(aString);
if(0<aLength)
nsStr::Append(*this,temp,0,aLength,mAgent);
nsStr::Append(*this,temp,0,aLength);
}
}
@@ -110,9 +110,9 @@ nsCString::nsCString(const PRUnichar* aString,PRInt32 aLength,nsIMemoryAgent* an
* @update gess 1/4/99
* @param reference to another nsCString
*/
nsCString::nsCString(const nsStr &aString,nsIMemoryAgent* anAgent) : mAgent(anAgent) {
nsCString::nsCString(const nsStr &aString) {
nsStr::Initialize(*this,eOneByte);
nsStr::Assign(*this,aString,0,aString.mLength,mAgent);
nsStr::Assign(*this,aString,0,aString.mLength);
}
/**
@@ -120,9 +120,9 @@ nsCString::nsCString(const nsStr &aString,nsIMemoryAgent* anAgent) : mAgent(anAg
* @update gess 1/4/99
* @param reference to another nsCString
*/
nsCString::nsCString(const nsCString& aString) :mAgent(aString.mAgent) {
nsCString::nsCString(const nsCString& aString) {
nsStr::Initialize(*this,aString.mCharSize);
nsStr::Assign(*this,aString,0,aString.mLength,mAgent);
nsStr::Assign(*this,aString,0,aString.mLength);
}
/**
@@ -130,7 +130,7 @@ nsCString::nsCString(const nsCString& aString) :mAgent(aString.mAgent) {
* @update gess 1/4/99
* @param reference to a subsumeString
*/
nsCString::nsCString(nsSubsumeCStr& aSubsumeStr) :mAgent(0) {
nsCString::nsCString(nsSubsumeCStr& aSubsumeStr) {
CSubsume(*this,aSubsumeStr);
}
@@ -138,7 +138,7 @@ nsCString::nsCString(nsSubsumeCStr& aSubsumeStr) :mAgent(0) {
* Destructor
*/
nsCString::~nsCString() {
nsStr::Destroy(*this,mAgent);
nsStr::Destroy(*this);
}
void nsCString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
@@ -155,7 +155,7 @@ void nsCString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
* @return nada
*/
void nsCString::Truncate(PRInt32 anIndex) {
nsStr::Truncate(*this,anIndex,mAgent);
nsStr::Truncate(*this,anIndex);
}
/**
@@ -187,7 +187,7 @@ PRBool nsCString::IsOrdered(void) const {
*/
void nsCString::SetCapacity(PRUint32 aLength) {
if(aLength>mCapacity) {
GrowCapacity(*this,aLength,mAgent);
GrowCapacity(*this,aLength);
}
AddNullTerminator(*this);
}
@@ -262,7 +262,7 @@ PRBool nsCString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
*/
nsSubsumeCStr nsCString::operator+(const nsCString& aString){
nsCString temp(*this); //make a temp string the same size as this...
nsStr::Append(temp,aString,0,aString.mLength,mAgent);
nsStr::Append(temp,aString,0,aString.mLength);
return nsSubsumeCStr(temp);
}
@@ -613,11 +613,19 @@ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) {
}
theDigit=(theChar-'A')+10;
}
else if((theChar>='a') && (theChar<='f')) {
if(10==aRadix){
*anErrorCode=NS_ERROR_ILLEGAL_VALUE;
result=0;
break;
}
theDigit=(theChar-'a')+10;
}
else if('-'==theChar) {
result=-result;
break;
}
else if(('+'==theChar) || (' '==theChar)) { //stop in a good state if you see this...
else if(('+'==theChar) || (' '==theChar) || ('X'==theChar) || ('x'==theChar)) { //stop in a good state if you see this...
break;
}
else {
@@ -634,6 +642,7 @@ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) {
return result;
}
/**
* Call this method to extract the rightmost numeric value from the given
* 1-byte input string, and simultaneously determine the radix.
@@ -645,56 +654,56 @@ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) {
* @param aRadix (an out parm) tells the caller what base we think the string is in.
* @return non-zero error code if this string is non-numeric
*/
PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) {
static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) {
static const char* validChars="0123456789abcdefABCDEF-+#";
aString.ToUpperCase();
const char* cp=aString.GetBuffer();
PRInt32 result=NS_ERROR_ILLEGAL_VALUE;
if(cp) {
PRInt32 decPt=nsStr::FindChar(aString,'.',PR_TRUE,0);
char* cp = (kNotFound==decPt) ? aString.mStr + aString.mLength-1 : aString.mStr+decPt-1;
aRadix=kRadixUnknown; //assume for starters...
//begin by skipping over leading chars that shouldn't be part of the number...
char* to=(char*)cp;
const char* endcp=cp+aString.mLength;
int len=strlen(validChars);
// Skip trailing non-numeric...
while (cp >= aString.mStr) {
if((*cp>='0') && (*cp<='9')){
if(kRadixUnknown==aRadix)
aRadix=kRadix10;
break;
while(cp<endcp){
const char* pos=(const char*)memchr(validChars,*cp,len);
if(!pos) {
cp++;
}
else break;
}
else if((*cp>='A') && (*cp<='F')) {
aRadix=16;
break;
}
cp--;
while(cp<endcp){
char theChar=toupper(*cp);
if((theChar>='0') && (theChar<='9')) {
*to++=theChar;
}
else if((theChar>='A') && (theChar<='F')) {
aRadix=16;
*to++=theChar;
}
else if('X'==theChar){
if('-'==aString.mStr[0])
to=&aString.mStr[1];
else to=aString.mStr;
aRadix=16;
//root=cp;
}
else if('-'==theChar) {
*to++=theChar;
}
else if(('#'==theChar) || ('+'==theChar)){
//just skip this char...
}
else break;
cp++;
}
aString.Truncate(to-aString.mStr);
result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK;
}
aString.Truncate(cp-aString.mStr+1);
//ok, now scan through chars until you find the start of this number...
//we delimit the number by the presence of: +,-,#,X
// Skip trailing non-numeric...
cp++;
while (--cp >= aString.mStr) {
if((*cp>='0') && (*cp<='9')){
continue;
}
else if((*cp>='A') && (*cp<='F')) {
continue;
}
else if((*cp=='-') || (*cp=='+')){
break;
}
else {
if(('#'==(*cp)) || ('X'==(*cp)))
aRadix=kRadix16;
cp++; //move back by one
break;
}
}
if(cp>aString.mStr)
aString.Cut(0,cp-aString.mStr);
PRInt32 result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK;
return result;
}
@@ -726,11 +735,12 @@ PRUint32 nsCString::DetermineRadix(void) {
PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
//copy chars to local buffer -- step down from 2 bytes to 1 if necessary...
PRInt32 result=0;
nsCAutoString theString(*this);
PRUint32 theRadix=aRadix;
PRInt32 result=0;
*anErrorCode=GetNumericSubstring(theString,theRadix); //we actually don't use this radix; use given radix instead
if(NS_OK==*anErrorCode){
if(kAutoDetect==aRadix)
aRadix=theRadix;
@@ -755,13 +765,13 @@ PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
*/
nsCString& nsCString::Assign(const nsStr& aString,PRInt32 aCount) {
if(this!=&aString){
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
if(aCount<0)
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
nsStr::Assign(*this,aString,0,aCount,mAgent);
nsStr::Assign(*this,aString,0,aCount);
}
return *this;
}
@@ -773,7 +783,7 @@ nsCString& nsCString::Assign(const nsStr& aString,PRInt32 aCount) {
* @return this
*/
nsCString& nsCString::Assign(const char* aCString,PRInt32 aCount) {
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
if(aCString){
Append(aCString,aCount);
}
@@ -787,7 +797,7 @@ nsCString& nsCString::Assign(const char* aCString,PRInt32 aCount) {
* @return this
*/
nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) {
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
if(aString){
nsStr temp;
@@ -806,7 +816,7 @@ nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) {
else aCount=temp.mLength=nsCRT::strlen(aString);
if(0<aCount)
nsStr::Append(*this,temp,0,aCount,mAgent);
nsStr::Append(*this,temp,0,aCount);
}
return *this;
}
@@ -818,7 +828,7 @@ nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) {
* @return this
*/
nsCString& nsCString::Assign(PRUnichar aChar) {
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
return Append(aChar);
}
@@ -829,7 +839,7 @@ nsCString& nsCString::Assign(PRUnichar aChar) {
* @return this
*/
nsCString& nsCString::Assign(char aChar) {
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
return Append(aChar);
}
@@ -864,7 +874,24 @@ nsCString& nsCString::Append(const nsCString& aString,PRInt32 aCount) {
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
if(0<aCount)
nsStr::Append(*this,aString,0,aCount,mAgent);
nsStr::Append(*this,aString,0,aCount);
return *this;
}
/**
* append given string to this string;
* @update gess 01/04/99
* @param aString : string to be appended to this
* @return this
*/
nsCString& nsCString::Append(const nsStr& aString,PRInt32 aCount) {
if(aCount<0)
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
if(0<aCount)
nsStr::Append(*this,aString,0,aCount);
return *this;
}
@@ -893,7 +920,7 @@ nsCString& nsCString::Append(const char* aCString,PRInt32 aCount) {
else aCount=temp.mLength=nsCRT::strlen(aCString);
if(0<aCount)
nsStr::Append(*this,temp,0,aCount,mAgent);
nsStr::Append(*this,temp,0,aCount);
}
return *this;
}
@@ -913,7 +940,7 @@ nsCString& nsCString::Append(PRUnichar aChar) {
Initialize(temp,eTwoByte);
temp.mUStr=buf;
temp.mLength=1;
nsStr::Append(*this,temp,0,1,mAgent);
nsStr::Append(*this,temp,0,1);
return *this;
}
@@ -931,7 +958,7 @@ nsCString& nsCString::Append(char aChar) {
Initialize(temp,eOneByte);
temp.mStr=buf;
temp.mLength=1;
nsStr::Append(*this,temp,0,1,mAgent);
nsStr::Append(*this,temp,0,1);
return *this;
}
@@ -962,12 +989,12 @@ nsCString& nsCString::Append(PRInt32 anInteger,PRInt32 aRadix) {
PRBool isfirst=PR_TRUE;
while(mask1>=1) {
PRInt32 div=theInt/mask1;
if((div) || (!isfirst)) {
buf[charpos++]="0123456789abcdef"[div];
PRInt32 theDiv=theInt/mask1;
if((theDiv) || (!isfirst)) {
buf[charpos++]="0123456789abcdef"[theDiv];
isfirst=PR_FALSE;
}
theInt-=div*mask1;
theInt-=theDiv*mask1;
mask1/=aRadix;
}
return Append(buf);
@@ -1001,7 +1028,7 @@ PRUint32 nsCString::Left(nsCString& aDest,PRInt32 aCount) const{
if(aCount<0)
aCount=mLength;
else aCount=MinInt(aCount,mLength);
nsStr::Assign(aDest,*this,0,aCount,mAgent);
nsStr::Assign(aDest,*this,0,aCount);
return aDest.mLength;
}
@@ -1018,7 +1045,7 @@ PRUint32 nsCString::Mid(nsCString& aDest,PRUint32 anOffset,PRInt32 aCount) const
if(aCount<0)
aCount=mLength;
else aCount=MinInt(aCount,mLength);
nsStr::Assign(aDest,*this,anOffset,aCount,mAgent);
nsStr::Assign(aDest,*this,anOffset,aCount);
return aDest.mLength;
}
@@ -1048,7 +1075,7 @@ PRUint32 nsCString::Right(nsCString& aDest,PRInt32 aCount) const{
*/
nsCString& nsCString::Insert(const nsCString& aString,PRUint32 anOffset,PRInt32 aCount) {
nsStr::Insert(*this,anOffset,aString,0,aCount,mAgent);
nsStr::Insert(*this,anOffset,aString,0,aCount);
return *this;
}
@@ -1079,7 +1106,7 @@ nsCString& nsCString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCou
else aCount=temp.mLength=nsCRT::strlen(aCString);
if(temp.mLength && (0<aCount)){
nsStr::Insert(*this,anOffset,temp,0,aCount,0);
nsStr::Insert(*this,anOffset,temp,0,aCount);
}
}
return *this;
@@ -1101,7 +1128,7 @@ nsCString& nsCString::Insert(PRUnichar aChar,PRUint32 anOffset){
nsStr::Initialize(temp,eTwoByte);
temp.mUStr=theBuffer;
temp.mLength=1;
nsStr::Insert(*this,anOffset,temp,0,1,0);
nsStr::Insert(*this,anOffset,temp,0,1);
return *this;
}
@@ -1121,7 +1148,7 @@ nsCString& nsCString::Insert(char aChar,PRUint32 anOffset){
nsStr::Initialize(temp,eOneByte);
temp.mStr=theBuffer;
temp.mLength=1;
nsStr::Insert(*this,anOffset,temp,0,1,0);
nsStr::Insert(*this,anOffset,temp,0,1);
return *this;
}
@@ -1136,7 +1163,7 @@ nsCString& nsCString::Insert(char aChar,PRUint32 anOffset){
*/
nsCString& nsCString::Cut(PRUint32 anOffset, PRInt32 aCount) {
if(0<aCount) {
nsStr::Delete(*this,anOffset,aCount,mAgent);
nsStr::Delete(*this,anOffset,aCount);
}
return *this;
}
@@ -1560,10 +1587,8 @@ PRBool nsCString::Equals(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 aCo
class nsCStringDeallocator: public nsDequeFunctor{
public:
virtual void* operator()(void* anObject) {
static nsMemoryAgent theAgent;
nsCString* aString= (nsCString*)anObject;
if(aString){
aString->mAgent=&theAgent;
delete aString;
}
return 0;
@@ -1722,7 +1747,6 @@ NS_COM int fputs(const nsCString& aString, FILE* out)
*/
nsCAutoString::nsCAutoString() : nsCString(){
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
mAgent=0;
AddNullTerminator(*this);
}
@@ -1732,7 +1756,6 @@ nsCAutoString::nsCAutoString() : nsCString(){
*/
nsCAutoString::nsCAutoString(const nsCAutoString& aString) : nsCString() {
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
mAgent=0;
AddNullTerminator(*this);
Append(aString);
}
@@ -1744,7 +1767,6 @@ nsCAutoString::nsCAutoString(const nsCAutoString& aString) : nsCString() {
*/
nsCAutoString::nsCAutoString(const char* aCString,PRInt32 aLength) : nsCString() {
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
mAgent=0;
AddNullTerminator(*this);
Append(aCString,aLength);
}
@@ -1754,7 +1776,6 @@ nsCAutoString::nsCAutoString(const char* aCString,PRInt32 aLength) : nsCString()
* @param aBuffer -- descibes external buffer
*/
nsCAutoString::nsCAutoString(const CBufDescriptor& aBuffer) : nsCString() {
mAgent=0;
if(!aBuffer.mBuffer) {
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
}
@@ -1770,7 +1791,6 @@ nsCAutoString::nsCAutoString(const CBufDescriptor& aBuffer) : nsCString() {
* @param aString is a ptr to a unistr
*/
nsCAutoString::nsCAutoString(const PRUnichar* aString,PRInt32 aLength) : nsCString() {
mAgent=0;
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
AddNullTerminator(*this);
Append(aString,aLength);
@@ -1781,7 +1801,6 @@ nsCAutoString::nsCAutoString(const PRUnichar* aString,PRInt32 aLength) : nsCStri
* @param
*/
nsCAutoString::nsCAutoString(const nsStr& aString) : nsCString() {
mAgent=0;
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
AddNullTerminator(*this);
Append(aString);
@@ -1794,7 +1813,6 @@ nsCAutoString::nsCAutoString(const nsStr& aString) : nsCString() {
* @param
*/
nsCAutoString::nsCAutoString(PRUnichar aChar) : nsCString(){
mAgent=0;
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
AddNullTerminator(*this);
Append(aChar);
@@ -1807,12 +1825,10 @@ nsCAutoString::nsCAutoString(PRUnichar aChar) : nsCString(){
*/
#ifdef AIX
nsCAutoString::nsCAutoString(const nsSubsumeCStr& aSubsumeStr) :nsCString() {
mAgent=0;
nsSubsumeCStr temp(aSubsumeStr); // a temp is needed for the AIX compiler
CSubsume(*this,temp);
#else
nsCAutoString::nsCAutoString( nsSubsumeCStr& aSubsumeStr) :nsCString() {
mAgent=0;
CSubsume(*this,aSubsumeStr);
#endif // AIX
}

File diff suppressed because it is too large Load Diff

View File

@@ -38,7 +38,7 @@ static const char* kWhitespace="\b\t\r\n ";
static void Subsume(nsStr& aDest,nsStr& aSource){
if(aSource.mStr && aSource.mLength) {
if(aSource.mOwnsBuffer){
nsStr::Destroy(aDest,0);
nsStr::Destroy(aDest);
aDest.mStr=aSource.mStr;
aDest.mLength=aSource.mLength;
aDest.mCharSize=aSource.mCharSize;
@@ -48,17 +48,17 @@ static void Subsume(nsStr& aDest,nsStr& aSource){
aSource.mStr=0;
}
else{
nsStr::Assign(aDest,aSource,0,aSource.mLength,0);
nsStr::Assign(aDest,aSource,0,aSource.mLength);
}
}
else nsStr::Truncate(aDest,0,0);
else nsStr::Truncate(aDest,0);
}
/**
* Default constructor.
*/
nsString::nsString(nsIMemoryAgent* anAgent) : mAgent(anAgent) {
nsString::nsString() {
nsStr::Initialize(*this,eTwoByte);
}
@@ -68,7 +68,7 @@ nsString::nsString(nsIMemoryAgent* anAgent) : mAgent(anAgent) {
* @param aCString is a ptr to a 1-byte cstr
* @param aLength tells us how many chars to copy from given CString
*/
nsString::nsString(const char* aCString,nsIMemoryAgent* anAgent) : mAgent(anAgent) {
nsString::nsString(const char* aCString){
nsStr::Initialize(*this,eTwoByte);
Assign(aCString);
}
@@ -79,7 +79,7 @@ nsString::nsString(const char* aCString,nsIMemoryAgent* anAgent) : mAgent(anAgen
* @param aString is a ptr to a unichar string
* @param aLength tells us how many chars to copy from given aString
*/
nsString::nsString(const PRUnichar* aString,nsIMemoryAgent* anAgent) : mAgent(anAgent) {
nsString::nsString(const PRUnichar* aString) {
nsStr::Initialize(*this,eTwoByte);
Assign(aString);
}
@@ -89,9 +89,9 @@ nsString::nsString(const PRUnichar* aString,nsIMemoryAgent* anAgent) : mAgent(an
* @update gess 1/4/99
* @param reference to another nsCString
*/
nsString::nsString(const nsStr &aString,nsIMemoryAgent* anAgent) : mAgent(anAgent) {
nsString::nsString(const nsStr &aString) {
nsStr::Initialize(*this,eTwoByte);
nsStr::Assign(*this,aString,0,aString.mLength,mAgent);
nsStr::Assign(*this,aString,0,aString.mLength);
}
/**
@@ -99,9 +99,9 @@ nsString::nsString(const nsStr &aString,nsIMemoryAgent* anAgent) : mAgent(anAgen
* @update gess 1/4/99
* @param reference to another nsString
*/
nsString::nsString(const nsString& aString) :mAgent(aString.mAgent) {
nsString::nsString(const nsString& aString) {
nsStr::Initialize(*this,eTwoByte);
nsStr::Assign(*this,aString,0,aString.mLength,mAgent);
nsStr::Assign(*this,aString,0,aString.mLength);
}
/**
@@ -109,7 +109,7 @@ nsString::nsString(const nsString& aString) :mAgent(aString.mAgent) {
* @update gess 1/4/99
* @param reference to a subsumeString
*/
nsString::nsString(nsSubsumeStr& aSubsumeStr) :mAgent(0) {
nsString::nsString(nsSubsumeStr& aSubsumeStr) {
nsStr::Initialize(*this,eTwoByte);
Subsume(*this,aSubsumeStr);
}
@@ -119,7 +119,7 @@ nsString::nsString(nsSubsumeStr& aSubsumeStr) :mAgent(0) {
* Make sure we call nsStr::Destroy.
*/
nsString::~nsString() {
nsStr::Destroy(*this,mAgent);
nsStr::Destroy(*this);
}
void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
@@ -136,7 +136,7 @@ void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
* @return nada
*/
void nsString::Truncate(PRInt32 anIndex) {
nsStr::Truncate(*this,anIndex,mAgent);
nsStr::Truncate(*this,anIndex);
}
/**
@@ -173,7 +173,7 @@ PRBool nsString::IsOrdered(void) const {
*/
void nsString::SetCapacity(PRUint32 aLength) {
if(aLength>mCapacity) {
GrowCapacity(*this,aLength,mAgent);
GrowCapacity(*this,aLength);
}
AddNullTerminator(*this);
}
@@ -270,7 +270,7 @@ PRBool nsString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
*/
nsSubsumeStr nsString::operator+(const nsStr& aString){
nsString temp(*this); //make a temp string the same size as this...
nsStr::Append(temp,aString,0,aString.mLength,mAgent);
nsStr::Append(temp,aString,0,aString.mLength);
return nsSubsumeStr(temp);
}
@@ -282,7 +282,7 @@ nsSubsumeStr nsString::operator+(const nsStr& aString){
*/
nsSubsumeStr nsString::operator+(const nsString& aString){
nsString temp(*this); //make a temp string the same size as this...
nsStr::Append(temp,aString,0,aString.mLength,mAgent);
nsStr::Append(temp,aString,0,aString.mLength);
return nsSubsumeStr(temp);
}
@@ -786,54 +786,55 @@ static PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadi
* @return non-zero error code if this string is non-numeric
*/
static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) {
static const char* validChars="0123456789abcdefABCDEF-+#";
aString.ToUpperCase();
const char* cp=aString.GetBuffer();
PRInt32 result=NS_ERROR_ILLEGAL_VALUE;
if(cp) {
PRInt32 decPt=nsStr::FindChar(aString,'.',PR_TRUE,0);
char* cp = (kNotFound==decPt) ? aString.mStr + aString.mLength-1 : aString.mStr+decPt-1;
aRadix=kRadixUnknown; //assume for starters...
//begin by skipping over leading chars that shouldn't be part of the number...
char* to=(char*)cp;
const char* endcp=cp+aString.mLength;
int len=strlen(validChars);
// Skip trailing non-numeric...
while (cp >= aString.mStr) {
if((*cp>='0') && (*cp<='9')){
if(kRadixUnknown==aRadix)
aRadix=kRadix10;
break;
while(cp<endcp){
const char* pos=(const char*)memchr(validChars,*cp,len);
if(!pos) {
cp++;
}
else break;
}
else if((*cp>='A') && (*cp<='F')) {
aRadix=16;
break;
}
cp--;
while(cp<endcp){
char theChar=toupper(*cp);
if((theChar>='0') && (theChar<='9')) {
*to++=theChar;
}
else if((theChar>='A') && (theChar<='F')) {
aRadix=16;
*to++=theChar;
}
else if('X'==theChar){
if('-'==aString.mStr[0])
to=&aString.mStr[1];
else to=aString.mStr;
aRadix=16;
//root=cp;
}
else if('-'==theChar) {
*to++=theChar;
}
else if(('#'==theChar) || ('+'==theChar)){
//just skip this char...
}
else break;
cp++;
}
aString.Truncate(to-aString.mStr);
result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK;
}
aString.Truncate(cp-aString.mStr+1);
//ok, now scan through chars until you find the start of this number...
//we delimit the number by the presence of: +,-,#,X
// Skip trailing non-numeric...
cp++;
while (--cp >= aString.mStr) {
if((*cp>='0') && (*cp<='9')){
continue;
}
else if((*cp>='A') && (*cp<='F')) {
continue;
}
else if((*cp=='-') || (*cp=='+')){
break;
}
else {
if(('#'==(*cp)) || ('X'==(*cp)))
aRadix=kRadix16;
cp++; //move back by one
break;
}
}
if(cp>aString.mStr)
aString.Cut(0,cp-aString.mStr);
PRInt32 result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK;
return result;
}
@@ -865,10 +866,10 @@ PRUint32 nsString::DetermineRadix(void) {
PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
//copy chars to local buffer -- step down from 2 bytes to 1 if necessary...
PRInt32 result=0;
nsCAutoString theString(*this);
PRUint32 theRadix=aRadix;
PRInt32 result=0;
*anErrorCode=GetNumericSubstring(theString,theRadix); //we actually don't use this radix; use given radix instead
if(NS_OK==*anErrorCode){
if(kAutoDetect==aRadix)
@@ -893,13 +894,13 @@ PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
*/
nsString& nsString::Assign(const nsStr& aString,PRInt32 aCount) {
if(this!=&aString){
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
if(aCount<0)
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
nsStr::Assign(*this,aString,0,aCount,mAgent);
nsStr::Assign(*this,aString,0,aCount);
}
return *this;
}
@@ -912,7 +913,7 @@ nsString& nsString::Assign(const nsStr& aString,PRInt32 aCount) {
* @return this
*/
nsString& nsString::Assign(const char* aCString,PRInt32 aCount) {
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
if(aCString){
Append(aCString,aCount);
}
@@ -926,7 +927,7 @@ nsString& nsString::Assign(const char* aCString,PRInt32 aCount) {
* @return this
*/
nsString& nsString::Assign(const PRUnichar* aString,PRInt32 aCount) {
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
if(aString){
Append(aString,aCount);
}
@@ -940,7 +941,7 @@ nsString& nsString::Assign(const PRUnichar* aString,PRInt32 aCount) {
* @return this
*/
nsString& nsString::Assign(char aChar) {
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
return Append(aChar);
}
@@ -951,7 +952,7 @@ nsString& nsString::Assign(char aChar) {
* @return this
*/
nsString& nsString::Assign(PRUnichar aChar) {
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
return Append(aChar);
}
@@ -988,7 +989,7 @@ nsString& nsString::Append(const nsStr& aString,PRInt32 aCount) {
else aCount=MinInt(aCount,aString.mLength);
if(0<aCount)
nsStr::Append(*this,aString,0,aCount,mAgent);
nsStr::Append(*this,aString,0,aCount);
return *this;
}
@@ -1005,7 +1006,7 @@ nsString& nsString::Append(const nsString& aString,PRInt32 aCount) {
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
if(0<aCount)
nsStr::Append(*this,aString,0,aCount,mAgent);
nsStr::Append(*this,aString,0,aCount);
return *this;
}
@@ -1034,7 +1035,7 @@ nsString& nsString::Append(const char* aCString,PRInt32 aCount) {
else aCount=temp.mLength=nsCRT::strlen(aCString);
if(0<aCount)
nsStr::Append(*this,temp,0,aCount,mAgent);
nsStr::Append(*this,temp,0,aCount);
}
return *this;
}
@@ -1064,7 +1065,7 @@ nsString& nsString::Append(const PRUnichar* aString,PRInt32 aCount) {
else aCount=temp.mLength=nsCRT::strlen(aString);
if(0<aCount)
nsStr::Append(*this,temp,0,aCount,mAgent);
nsStr::Append(*this,temp,0,aCount);
}
return *this;
}
@@ -1083,7 +1084,7 @@ nsString& nsString::Append(char aChar) {
Initialize(temp,eOneByte);
temp.mStr=buf;
temp.mLength=1;
nsStr::Append(*this,temp,0,1,mAgent);
nsStr::Append(*this,temp,0,1);
return *this;
}
@@ -1101,7 +1102,7 @@ nsString& nsString::Append(PRUnichar aChar) {
Initialize(temp,eTwoByte);
temp.mUStr=buf;
temp.mLength=1;
nsStr::Append(*this,temp,0,1,mAgent);
nsStr::Append(*this,temp,0,1);
return *this;
}
@@ -1132,12 +1133,12 @@ nsString& nsString::Append(PRInt32 anInteger,PRInt32 aRadix) {
PRBool isfirst=PR_TRUE;
while(mask1>=1) {
PRInt32 div=theInt/mask1;
if((div) || (!isfirst)) {
buf[charpos++]="0123456789abcdef"[div];
PRInt32 theDiv=theInt/mask1;
if((theDiv) || (!isfirst)) {
buf[charpos++]="0123456789abcdef"[theDiv];
isfirst=PR_FALSE;
}
theInt-=div*mask1;
theInt-=theDiv*mask1;
mask1/=aRadix;
}
return Append(buf);
@@ -1173,7 +1174,7 @@ PRUint32 nsString::Left(nsString& aDest,PRInt32 aCount) const{
if(aCount<0)
aCount=mLength;
else aCount=MinInt(aCount,mLength);
nsStr::Assign(aDest,*this,0,aCount,mAgent);
nsStr::Assign(aDest,*this,0,aCount);
return aDest.mLength;
}
@@ -1191,7 +1192,7 @@ PRUint32 nsString::Mid(nsString& aDest,PRUint32 anOffset,PRInt32 aCount) const{
if(aCount<0)
aCount=mLength;
else aCount=MinInt(aCount,mLength);
nsStr::Assign(aDest,*this,anOffset,aCount,mAgent);
nsStr::Assign(aDest,*this,anOffset,aCount);
return aDest.mLength;
}
@@ -1221,7 +1222,7 @@ PRUint32 nsString::Right(nsString& aDest,PRInt32 aCount) const{
* @return this
*/
nsString& nsString::Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) {
nsStr::Insert(*this,anOffset,aCopy,0,aCount,mAgent);
nsStr::Insert(*this,anOffset,aCopy,0,aCount);
return *this;
}
@@ -1252,7 +1253,7 @@ nsString& nsString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCount
else aCount=temp.mLength=nsCRT::strlen(aCString);
if(0<aCount){
nsStr::Insert(*this,anOffset,temp,0,aCount,0);
nsStr::Insert(*this,anOffset,temp,0,aCount);
}
}
return *this;
@@ -1285,7 +1286,7 @@ nsString& nsString::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32 aC
else aCount=temp.mLength=nsCRT::strlen(aString);
if(0<aCount){
nsStr::Insert(*this,anOffset,temp,0,aCount,0);
nsStr::Insert(*this,anOffset,temp,0,aCount);
}
}
return *this;
@@ -1308,7 +1309,7 @@ nsString& nsString::Insert(PRUnichar aChar,PRUint32 anOffset){
nsStr::Initialize(temp,eTwoByte);
temp.mUStr=theBuffer;
temp.mLength=1;
nsStr::Insert(*this,anOffset,temp,0,1,0);
nsStr::Insert(*this,anOffset,temp,0,1);
return *this;
}
@@ -1323,7 +1324,7 @@ nsString& nsString::Insert(PRUnichar aChar,PRUint32 anOffset){
*/
nsString& nsString::Cut(PRUint32 anOffset, PRInt32 aCount) {
if(0<aCount) {
nsStr::Delete(*this,anOffset,aCount,mAgent);
nsStr::Delete(*this,anOffset,aCount);
}
return *this;
}
@@ -1957,10 +1958,8 @@ PRBool nsString::IsDigit(PRUnichar aChar) {
class nsStringDeallocator: public nsDequeFunctor{
public:
virtual void* operator()(void* anObject) {
static nsMemoryAgent theAgent;
nsString* aString= (nsString*)anObject;
if(aString){
aString->mAgent=&theAgent;
delete aString;
}
return 0;
@@ -2116,7 +2115,6 @@ NS_COM int fputs(const nsString& aString, FILE* out)
*/
nsAutoString::nsAutoString() : nsString() {
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
mAgent=0;
AddNullTerminator(*this);
}
@@ -2127,7 +2125,6 @@ nsAutoString::nsAutoString() : nsString() {
*/
nsAutoString::nsAutoString(const char* aCString,PRInt32 aLength) : nsString() {
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
mAgent=0;
AddNullTerminator(*this);
Append(aCString,aLength);
}
@@ -2138,7 +2135,6 @@ nsAutoString::nsAutoString(const char* aCString,PRInt32 aLength) : nsString() {
* @param aLength tells us how many chars to copy from aString
*/
nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString() {
mAgent=0;
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
AddNullTerminator(*this);
Append(aString,aLength);
@@ -2149,7 +2145,6 @@ nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString(
* @param aBuffer describes the external buffer
*/
nsAutoString::nsAutoString(const CBufDescriptor& aBuffer) : nsString() {
mAgent=0;
if(!aBuffer.mBuffer) {
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
}
@@ -2166,7 +2161,6 @@ nsAutoString::nsAutoString(const CBufDescriptor& aBuffer) : nsString() {
* @param
*/
nsAutoString::nsAutoString(const nsStr& aString) : nsString() {
mAgent=0;
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
AddNullTerminator(*this);
Append(aString);
@@ -2176,7 +2170,6 @@ nsAutoString::nsAutoString(const nsStr& aString) : nsString() {
* Default copy constructor
*/
nsAutoString::nsAutoString(const nsAutoString& aString) : nsString() {
mAgent=0;
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
AddNullTerminator(*this);
Append(aString);
@@ -2188,7 +2181,6 @@ nsAutoString::nsAutoString(const nsAutoString& aString) : nsString() {
* @param
*/
nsAutoString::nsAutoString(PRUnichar aChar) : nsString(){
mAgent=0;
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
AddNullTerminator(*this);
Append(aChar);
@@ -2201,12 +2193,10 @@ nsAutoString::nsAutoString(PRUnichar aChar) : nsString(){
*/
#ifdef AIX
nsAutoString::nsAutoString(const nsSubsumeStr& aSubsumeStr) :nsString() {
mAgent=0;
nsSubsumeStr temp(aSubsumeStr); // a temp is needed for the AIX compiler
Subsume(*this,temp);
#else
nsAutoString::nsAutoString( nsSubsumeStr& aSubsumeStr) :nsString() {
mAgent=0;
Subsume(*this,aSubsumeStr);
#endif // AIX
}

File diff suppressed because it is too large Load Diff

View File

@@ -249,8 +249,6 @@ CopyChars gCopyChars[2][2]={
* @return index of pos if found, else -1 (kNotFound)
*/
inline PRInt32 FindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase) {
PRInt32 theIndex=0;
PRInt32 theLength=(PRInt32)aLength;
if(aIgnoreCase) {
char theChar=(char)nsCRT::ToUpper(aChar);
@@ -285,8 +283,6 @@ inline PRInt32 FindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,co
* @return index of pos if found, else -1 (kNotFound)
*/
inline PRInt32 FindChar2(const char* aDest,PRUint32 aLength,PRUint32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase) {
PRInt32 theIndex=0;
PRInt32 theLength=(PRInt32)aLength;
const PRUnichar* root=(PRUnichar*)aDest;
const PRUnichar* ptr=root+(anOffset-1);
const PRUnichar* last=root+aLength;

View File

@@ -69,16 +69,6 @@ void nsStr::Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 a
aDest.mOwnsBuffer=aOwnsBuffer;
}
/**
*
* @update gess10/30/98
* @param
* @return
*/
nsIMemoryAgent* GetDefaultAgent(void){
static nsMemoryAgent gDefaultAgent;
return (nsIMemoryAgent*)&gDefaultAgent;
}
/**
* This member destroys the memory buffer owned by an nsStr object (if it actually owns it)
@@ -86,17 +76,9 @@ nsIMemoryAgent* GetDefaultAgent(void){
* @param
* @return
*/
void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) {
void nsStr::Destroy(nsStr& aDest) {
if((aDest.mStr) && (aDest.mStr!=(char*)gCommonEmptyBuffer)) {
if(!anAgent)
anAgent=GetDefaultAgent();
if(anAgent) {
anAgent->Free(aDest);
}
else{
printf("%s\n","Leak occured in nsStr.");
}
Free(aDest);
}
}
@@ -108,11 +90,10 @@ void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) {
* @param aNewLength -- new capacity of string in charSize units
* @return void
*/
PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent) {
PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength) {
PRBool result=PR_TRUE;
if(aNewLength>aString.mCapacity) {
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
result=theAgent->Realloc(aString,aNewLength);
result=Realloc(aString,aNewLength);
if(aString.mStr)
AddNullTerminator(aString);
}
@@ -126,20 +107,18 @@ PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent*
* @param aNewLength -- new capacity of string in charSize units
* @return void
*/
PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAgent) {
PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength) {
PRBool result=PR_TRUE;
if(aNewLength>aDest.mCapacity) {
nsStr theTempStr;
nsStr::Initialize(theTempStr,aDest.mCharSize);
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
result=EnsureCapacity(theTempStr,aNewLength,theAgent);
result=EnsureCapacity(theTempStr,aNewLength);
if(result) {
if(aDest.mLength) {
Append(theTempStr,aDest,0,aDest.mLength,theAgent);
Append(theTempStr,aDest,0,aDest.mLength);
}
theAgent->Free(aDest);
Free(aDest);
aDest.mStr = theTempStr.mStr;
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
aDest.mLength=theTempStr.mLength;
@@ -157,10 +136,10 @@ PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAg
* @param aSource is where chars are copied from
* @param aCount is the number of chars copied from aSource
*/
void nsStr::Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){
void nsStr::Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount){
if(&aDest!=&aSource){
Truncate(aDest,0,anAgent);
Append(aDest,aSource,anOffset,aCount,anAgent);
Truncate(aDest,0);
Append(aDest,aSource,anOffset,aCount);
}
}
@@ -172,7 +151,7 @@ void nsStr::Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 a
* @param aSource is where char are copied from
* @aCount is the number of bytes to be copied
*/
void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){
void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount){
if(anOffset<aSource.mLength){
PRUint32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
PRUint32 theLength=(anOffset+theRealLen<aSource.mLength) ? theRealLen : (aSource.mLength-anOffset);
@@ -180,7 +159,7 @@ void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 a
PRBool isBigEnough=PR_TRUE;
if(aDest.mLength+theLength > aDest.mCapacity) {
isBigEnough=GrowCapacity(aDest,aDest.mLength+theLength,anAgent);
isBigEnough=GrowCapacity(aDest,aDest.mLength+theLength);
}
if(isBigEnough) {
@@ -204,7 +183,7 @@ void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 a
* @param aSrcOffset is where in aSource chars are copied from
* @param aCount is the number of chars from aSource to be inserted into aDest
*/
void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){
void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount){
//there are a few cases for insert:
// 1. You're inserting chars into an empty string (assign)
// 2. You're inserting onto the end of a string (append)
@@ -223,22 +202,21 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin
nsStr theTempStr;
nsStr::Initialize(theTempStr,aDest.mCharSize);
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
PRBool isBigEnough=EnsureCapacity(theTempStr,aDest.mLength+theLength,theAgent); //grow the temp buffer to the right size
PRBool isBigEnough=EnsureCapacity(theTempStr,aDest.mLength+theLength); //grow the temp buffer to the right size
if(isBigEnough) {
if(aDestOffset) {
Append(theTempStr,aDest,0,aDestOffset,theAgent); //first copy leftmost data...
Append(theTempStr,aDest,0,aDestOffset); //first copy leftmost data...
}
Append(theTempStr,aSource,0,aSource.mLength,theAgent); //next copy inserted (new) data
Append(theTempStr,aSource,0,aSource.mLength); //next copy inserted (new) data
PRUint32 theRemains=aDest.mLength-aDestOffset;
if(theRemains) {
Append(theTempStr,aDest,aDestOffset,theRemains,theAgent); //next copy rightmost data
Append(theTempStr,aDest,aDestOffset,theRemains); //next copy rightmost data
}
theAgent->Free(aDest);
Free(aDest);
aDest.mStr = theTempStr.mStr;
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
aDest.mCapacity=theTempStr.mCapacity;
@@ -262,9 +240,9 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin
}//if
//else nothing to do!
}
else Append(aDest,aSource,0,aCount,anAgent);
else Append(aDest,aSource,0,aCount);
}
else Append(aDest,aSource,0,aCount,anAgent);
else Append(aDest,aSource,0,aCount);
}
}
@@ -276,7 +254,7 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin
* @param aDestOffset is where in aDest deletion is to occur
* @param aCount is the number of chars to be deleted in aDest
*/
void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAgent* anAgent){
void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount){
if(aDestOffset<aDest.mLength){
PRUint32 theDelta=aDest.mLength-aDestOffset;
@@ -290,7 +268,7 @@ void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAg
aDest.mLength-=theLength;
AddNullTerminator(aDest);
}
else Truncate(aDest,aDestOffset,anAgent);
else Truncate(aDest,aDestOffset);
}//if
}
@@ -300,7 +278,7 @@ void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAg
* @param aDest is the nsStr to be truncated
* @param aDestOffset is where in aDest truncation is to occur
*/
void nsStr::Truncate(nsStr& aDest,PRUint32 aDestOffset,nsIMemoryAgent* anAgent){
void nsStr::Truncate(nsStr& aDest,PRUint32 aDestOffset){
if(aDestOffset<aDest.mLength){
aDest.mLength=aDestOffset;
AddNullTerminator(aDest);
@@ -342,7 +320,7 @@ void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool a
}
if(0<theIndex) {
if(theIndex<theMax) {
Delete(aDest,0,theIndex,0);
Delete(aDest,0,theIndex);
}
else Truncate(aDest,0);
}
@@ -515,7 +493,7 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgno
nsStr theCopy;
nsStr::Initialize(theCopy,eOneByte);
nsStr::Assign(theCopy,aTarget,0,aTarget.mLength,0);
nsStr::Assign(theCopy,aTarget,0,aTarget.mLength);
if(aIgnoreCase){
nsStr::ChangeCase(theCopy,PR_FALSE); //force to lowercase
}
@@ -538,7 +516,7 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgno
}
index--;
} //while
nsStr::Destroy(theCopy,0);
nsStr::Destroy(theCopy);
}//if
}//if
return result;
@@ -625,6 +603,57 @@ PRInt32 nsStr::Compare(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PR
//----------------------------------------------------------------------------------------
PRBool nsStr::Alloc(nsStr& aDest,PRUint32 aCount) {
static int mAllocCount=0;
mAllocCount++;
//we're given the acount value in charunits; now scale up to next multiple.
PRUint32 theNewCapacity=kDefaultStringSize;
while(theNewCapacity<aCount){
theNewCapacity<<=1;
}
aDest.mCapacity=theNewCapacity++;
PRUint32 theSize=(theNewCapacity<<aDest.mCharSize);
aDest.mStr = (char*)nsAllocator::Alloc(theSize);
PRBool result=PR_FALSE;
if(aDest.mStr) {
aDest.mOwnsBuffer=1;
result=PR_TRUE;
}
return result;
}
PRBool nsStr::Free(nsStr& aDest){
if(aDest.mStr){
if(aDest.mOwnsBuffer){
nsAllocator::Free(aDest.mStr);
}
aDest.mStr=0;
aDest.mOwnsBuffer=0;
return PR_TRUE;
}
return PR_FALSE;
}
PRBool nsStr::Realloc(nsStr& aDest,PRUint32 aCount){
nsStr temp;
memcpy(&temp,&aDest,sizeof(aDest));
PRBool result=Alloc(temp,aCount);
if(result) {
Free(aDest);
aDest.mStr=temp.mStr;
aDest.mCapacity=temp.mCapacity;
}
return result;
}
//----------------------------------------------------------------------------------------
CBufDescriptor::CBufDescriptor(char* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength) {
mBuffer=aString;
mCharSize=eOneByte;
@@ -683,3 +712,5 @@ CBufDescriptor::CBufDescriptor(const PRUnichar* aString,PRBool aStackBased,PRUin
}
//----------------------------------------------------------------------------------------

View File

@@ -164,6 +164,7 @@
#include "nscore.h"
#include "nsIAllocator.h"
#include <string.h>
//----------------------------------------------------------------------------------------
@@ -177,8 +178,6 @@ const PRInt32 kDefaultStringSize = 64;
const PRInt32 kNotFound = -1;
class nsIMemoryAgent;
//----------------------------------------------------------------------------------------
class NS_COM CBufDescriptor {
@@ -228,7 +227,7 @@ struct NS_COM nsStr {
* @param aString is the nsStr to be manipulated
* @param anAgent is the allocator to be used to the nsStr
*/
static void Destroy(nsStr& aDest,nsIMemoryAgent* anAgent=0);
static void Destroy(nsStr& aDest);
/**
* These methods are where memory allocation/reallocation occur.
@@ -238,8 +237,8 @@ struct NS_COM nsStr {
* @param anAgent is the allocator to be used on the nsStr
* @return
*/
static PRBool EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0);
static PRBool GrowCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0);
static PRBool EnsureCapacity(nsStr& aString,PRUint32 aNewLength);
static PRBool GrowCapacity(nsStr& aString,PRUint32 aNewLength);
/**
* These methods are used to append content to the given nsStr
@@ -251,7 +250,7 @@ struct NS_COM nsStr {
* @param aCount tells us the (max) # of chars to copy
* @param anAgent is the allocator to be used for alloc/free operations
*/
static void Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0);
static void Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount);
/**
* These methods are used to assign contents of a source string to dest string
@@ -263,7 +262,7 @@ struct NS_COM nsStr {
* @param aCount tells us the (max) # of chars to copy
* @param anAgent is the allocator to be used for alloc/free operations
*/
static void Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0);
static void Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount);
/**
* These methods are used to insert content from source string to the dest nsStr
@@ -276,7 +275,7 @@ struct NS_COM nsStr {
* @param aCount tells us the (max) # of chars to insert
* @param anAgent is the allocator to be used for alloc/free operations
*/
static void Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0);
static void Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount);
/**
* This method deletes chars from the given str.
@@ -288,7 +287,7 @@ struct NS_COM nsStr {
* @param aCount tells us the (max) # of chars to delete
* @param anAgent is the allocator to be used for alloc/free operations
*/
static void Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAgent* anAgent=0);
static void Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount);
/**
* This method is used to truncate the given string.
@@ -301,7 +300,7 @@ struct NS_COM nsStr {
* @param aSrcOffset tells us where in source to start copying
* @param anAgent is the allocator to be used for alloc/free operations
*/
static void Truncate(nsStr& aDest,PRUint32 aDestOffset,nsIMemoryAgent* anAgent=0);
static void Truncate(nsStr& aDest,PRUint32 aDestOffset);
/**
* This method is used to perform a case conversion on the given string
@@ -388,6 +387,12 @@ struct NS_COM nsStr {
char* mStr;
PRUnichar* mUStr;
};
private:
static PRBool Alloc(nsStr& aString,PRUint32 aCount);
static PRBool Realloc(nsStr& aString,PRUint32 aCount);
static PRBool Free(nsStr& aString);
};
/**************************************************************
@@ -430,74 +435,6 @@ inline PRUnichar GetCharAt(const nsStr& aDest,PRUint32 anIndex){
return 0;
}
//----------------------------------------------------------------------------------------
class nsIMemoryAgent {
public:
virtual PRBool Alloc(nsStr& aString,PRUint32 aCount)=0;
virtual PRBool Realloc(nsStr& aString,PRUint32 aCount)=0;
virtual PRBool Free(nsStr& aString)=0;
};
class nsMemoryAgent : public nsIMemoryAgent {
public:
virtual PRBool Alloc(nsStr& aDest,PRUint32 aCount) {
static int mAllocCount=0;
mAllocCount++;
//we're given the acount value in charunits; now scale up to next multiple.
PRUint32 theNewCapacity=kDefaultStringSize;
while(theNewCapacity<aCount){
theNewCapacity<<=1;
}
aDest.mCapacity=theNewCapacity++;
PRUint32 theSize=(theNewCapacity<<aDest.mCharSize);
aDest.mStr = (char*)nsAllocator::Alloc(theSize);
PRBool result=PR_FALSE;
if(aDest.mStr) {
aDest.mOwnsBuffer=1;
result=PR_TRUE;
}
return result;
}
virtual PRBool Free(nsStr& aDest){
if(aDest.mStr){
if(aDest.mOwnsBuffer){
nsAllocator::Free(aDest.mStr);
}
aDest.mStr=0;
aDest.mOwnsBuffer=0;
return PR_TRUE;
}
return PR_FALSE;
}
virtual PRBool Realloc(nsStr& aDest,PRUint32 aCount){
Free(aDest);
return Alloc(aDest,aCount);
#if 0
nsStr temp;
memcpy(&temp,&aDest,sizeof(aDest));
PRBool result=Alloc(temp,aCount);
if(result) {
Free(aDest);
aDest.mStr=temp.mStr;
aDest.mCapacity=temp.mCapacity;
}
return result;
#endif
}
};
nsIMemoryAgent* GetDefaultAgent(void);
#endif

View File

@@ -40,7 +40,7 @@ static const char* kWhitespace="\b\t\r\n ";
static void CSubsume(nsStr& aDest,nsStr& aSource){
if(aSource.mStr && aSource.mLength) {
if(aSource.mOwnsBuffer){
nsStr::Destroy(aDest,0);
nsStr::Destroy(aDest);
aDest.mStr=aSource.mStr;
aDest.mLength=aSource.mLength;
aDest.mCharSize=aSource.mCharSize;
@@ -50,17 +50,17 @@ static void CSubsume(nsStr& aDest,nsStr& aSource){
aSource.mStr=0;
}
else{
nsStr::Assign(aDest,aSource,0,aSource.mLength,0);
nsStr::Assign(aDest,aSource,0,aSource.mLength);
}
}
else nsStr::Truncate(aDest,0,0);
else nsStr::Truncate(aDest,0);
}
/**
* Default constructor.
*/
nsCString::nsCString(nsIMemoryAgent* anAgent) : mAgent(anAgent) {
nsCString::nsCString() {
nsStr::Initialize(*this,eOneByte);
}
@@ -70,7 +70,7 @@ nsCString::nsCString(nsIMemoryAgent* anAgent) : mAgent(anAgent) {
* @param aCString is a ptr to a 1-byte cstr
* @param aLength tells us how many chars to copy from given CString
*/
nsCString::nsCString(const char* aCString,PRInt32 aLength,nsIMemoryAgent* anAgent) : mAgent(anAgent) {
nsCString::nsCString(const char* aCString,PRInt32 aLength) {
nsStr::Initialize(*this,eOneByte);
Assign(aCString,aLength);
}
@@ -81,7 +81,7 @@ nsCString::nsCString(const char* aCString,PRInt32 aLength,nsIMemoryAgent* anAgen
* @param aString is a ptr to a unichar string
* @param aLength tells us how many chars to copy from given aString
*/
nsCString::nsCString(const PRUnichar* aString,PRInt32 aLength,nsIMemoryAgent* anAgent) : mAgent(anAgent) {
nsCString::nsCString(const PRUnichar* aString,PRInt32 aLength) {
nsStr::Initialize(*this,eOneByte);
if(aString && aLength){
@@ -101,7 +101,7 @@ nsCString::nsCString(const PRUnichar* aString,PRInt32 aLength,nsIMemoryAgent* an
else aLength=temp.mLength=nsCRT::strlen(aString);
if(0<aLength)
nsStr::Append(*this,temp,0,aLength,mAgent);
nsStr::Append(*this,temp,0,aLength);
}
}
@@ -110,9 +110,9 @@ nsCString::nsCString(const PRUnichar* aString,PRInt32 aLength,nsIMemoryAgent* an
* @update gess 1/4/99
* @param reference to another nsCString
*/
nsCString::nsCString(const nsStr &aString,nsIMemoryAgent* anAgent) : mAgent(anAgent) {
nsCString::nsCString(const nsStr &aString) {
nsStr::Initialize(*this,eOneByte);
nsStr::Assign(*this,aString,0,aString.mLength,mAgent);
nsStr::Assign(*this,aString,0,aString.mLength);
}
/**
@@ -120,9 +120,9 @@ nsCString::nsCString(const nsStr &aString,nsIMemoryAgent* anAgent) : mAgent(anAg
* @update gess 1/4/99
* @param reference to another nsCString
*/
nsCString::nsCString(const nsCString& aString) :mAgent(aString.mAgent) {
nsCString::nsCString(const nsCString& aString) {
nsStr::Initialize(*this,aString.mCharSize);
nsStr::Assign(*this,aString,0,aString.mLength,mAgent);
nsStr::Assign(*this,aString,0,aString.mLength);
}
/**
@@ -130,7 +130,7 @@ nsCString::nsCString(const nsCString& aString) :mAgent(aString.mAgent) {
* @update gess 1/4/99
* @param reference to a subsumeString
*/
nsCString::nsCString(nsSubsumeCStr& aSubsumeStr) :mAgent(0) {
nsCString::nsCString(nsSubsumeCStr& aSubsumeStr) {
CSubsume(*this,aSubsumeStr);
}
@@ -138,7 +138,7 @@ nsCString::nsCString(nsSubsumeCStr& aSubsumeStr) :mAgent(0) {
* Destructor
*/
nsCString::~nsCString() {
nsStr::Destroy(*this,mAgent);
nsStr::Destroy(*this);
}
void nsCString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
@@ -155,7 +155,7 @@ void nsCString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
* @return nada
*/
void nsCString::Truncate(PRInt32 anIndex) {
nsStr::Truncate(*this,anIndex,mAgent);
nsStr::Truncate(*this,anIndex);
}
/**
@@ -187,7 +187,7 @@ PRBool nsCString::IsOrdered(void) const {
*/
void nsCString::SetCapacity(PRUint32 aLength) {
if(aLength>mCapacity) {
GrowCapacity(*this,aLength,mAgent);
GrowCapacity(*this,aLength);
}
AddNullTerminator(*this);
}
@@ -262,7 +262,7 @@ PRBool nsCString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
*/
nsSubsumeCStr nsCString::operator+(const nsCString& aString){
nsCString temp(*this); //make a temp string the same size as this...
nsStr::Append(temp,aString,0,aString.mLength,mAgent);
nsStr::Append(temp,aString,0,aString.mLength);
return nsSubsumeCStr(temp);
}
@@ -613,11 +613,19 @@ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) {
}
theDigit=(theChar-'A')+10;
}
else if((theChar>='a') && (theChar<='f')) {
if(10==aRadix){
*anErrorCode=NS_ERROR_ILLEGAL_VALUE;
result=0;
break;
}
theDigit=(theChar-'a')+10;
}
else if('-'==theChar) {
result=-result;
break;
}
else if(('+'==theChar) || (' '==theChar)) { //stop in a good state if you see this...
else if(('+'==theChar) || (' '==theChar) || ('X'==theChar) || ('x'==theChar)) { //stop in a good state if you see this...
break;
}
else {
@@ -634,6 +642,7 @@ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) {
return result;
}
/**
* Call this method to extract the rightmost numeric value from the given
* 1-byte input string, and simultaneously determine the radix.
@@ -645,56 +654,56 @@ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) {
* @param aRadix (an out parm) tells the caller what base we think the string is in.
* @return non-zero error code if this string is non-numeric
*/
PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) {
static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) {
static const char* validChars="0123456789abcdefABCDEF-+#";
aString.ToUpperCase();
const char* cp=aString.GetBuffer();
PRInt32 result=NS_ERROR_ILLEGAL_VALUE;
if(cp) {
PRInt32 decPt=nsStr::FindChar(aString,'.',PR_TRUE,0);
char* cp = (kNotFound==decPt) ? aString.mStr + aString.mLength-1 : aString.mStr+decPt-1;
aRadix=kRadixUnknown; //assume for starters...
//begin by skipping over leading chars that shouldn't be part of the number...
char* to=(char*)cp;
const char* endcp=cp+aString.mLength;
int len=strlen(validChars);
// Skip trailing non-numeric...
while (cp >= aString.mStr) {
if((*cp>='0') && (*cp<='9')){
if(kRadixUnknown==aRadix)
aRadix=kRadix10;
break;
while(cp<endcp){
const char* pos=(const char*)memchr(validChars,*cp,len);
if(!pos) {
cp++;
}
else break;
}
else if((*cp>='A') && (*cp<='F')) {
aRadix=16;
break;
}
cp--;
while(cp<endcp){
char theChar=toupper(*cp);
if((theChar>='0') && (theChar<='9')) {
*to++=theChar;
}
else if((theChar>='A') && (theChar<='F')) {
aRadix=16;
*to++=theChar;
}
else if('X'==theChar){
if('-'==aString.mStr[0])
to=&aString.mStr[1];
else to=aString.mStr;
aRadix=16;
//root=cp;
}
else if('-'==theChar) {
*to++=theChar;
}
else if(('#'==theChar) || ('+'==theChar)){
//just skip this char...
}
else break;
cp++;
}
aString.Truncate(to-aString.mStr);
result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK;
}
aString.Truncate(cp-aString.mStr+1);
//ok, now scan through chars until you find the start of this number...
//we delimit the number by the presence of: +,-,#,X
// Skip trailing non-numeric...
cp++;
while (--cp >= aString.mStr) {
if((*cp>='0') && (*cp<='9')){
continue;
}
else if((*cp>='A') && (*cp<='F')) {
continue;
}
else if((*cp=='-') || (*cp=='+')){
break;
}
else {
if(('#'==(*cp)) || ('X'==(*cp)))
aRadix=kRadix16;
cp++; //move back by one
break;
}
}
if(cp>aString.mStr)
aString.Cut(0,cp-aString.mStr);
PRInt32 result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK;
return result;
}
@@ -726,11 +735,12 @@ PRUint32 nsCString::DetermineRadix(void) {
PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
//copy chars to local buffer -- step down from 2 bytes to 1 if necessary...
PRInt32 result=0;
nsCAutoString theString(*this);
PRUint32 theRadix=aRadix;
PRInt32 result=0;
*anErrorCode=GetNumericSubstring(theString,theRadix); //we actually don't use this radix; use given radix instead
if(NS_OK==*anErrorCode){
if(kAutoDetect==aRadix)
aRadix=theRadix;
@@ -755,13 +765,13 @@ PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
*/
nsCString& nsCString::Assign(const nsStr& aString,PRInt32 aCount) {
if(this!=&aString){
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
if(aCount<0)
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
nsStr::Assign(*this,aString,0,aCount,mAgent);
nsStr::Assign(*this,aString,0,aCount);
}
return *this;
}
@@ -773,7 +783,7 @@ nsCString& nsCString::Assign(const nsStr& aString,PRInt32 aCount) {
* @return this
*/
nsCString& nsCString::Assign(const char* aCString,PRInt32 aCount) {
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
if(aCString){
Append(aCString,aCount);
}
@@ -787,7 +797,7 @@ nsCString& nsCString::Assign(const char* aCString,PRInt32 aCount) {
* @return this
*/
nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) {
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
if(aString){
nsStr temp;
@@ -806,7 +816,7 @@ nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) {
else aCount=temp.mLength=nsCRT::strlen(aString);
if(0<aCount)
nsStr::Append(*this,temp,0,aCount,mAgent);
nsStr::Append(*this,temp,0,aCount);
}
return *this;
}
@@ -818,7 +828,7 @@ nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) {
* @return this
*/
nsCString& nsCString::Assign(PRUnichar aChar) {
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
return Append(aChar);
}
@@ -829,7 +839,7 @@ nsCString& nsCString::Assign(PRUnichar aChar) {
* @return this
*/
nsCString& nsCString::Assign(char aChar) {
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
return Append(aChar);
}
@@ -864,7 +874,24 @@ nsCString& nsCString::Append(const nsCString& aString,PRInt32 aCount) {
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
if(0<aCount)
nsStr::Append(*this,aString,0,aCount,mAgent);
nsStr::Append(*this,aString,0,aCount);
return *this;
}
/**
* append given string to this string;
* @update gess 01/04/99
* @param aString : string to be appended to this
* @return this
*/
nsCString& nsCString::Append(const nsStr& aString,PRInt32 aCount) {
if(aCount<0)
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
if(0<aCount)
nsStr::Append(*this,aString,0,aCount);
return *this;
}
@@ -893,7 +920,7 @@ nsCString& nsCString::Append(const char* aCString,PRInt32 aCount) {
else aCount=temp.mLength=nsCRT::strlen(aCString);
if(0<aCount)
nsStr::Append(*this,temp,0,aCount,mAgent);
nsStr::Append(*this,temp,0,aCount);
}
return *this;
}
@@ -913,7 +940,7 @@ nsCString& nsCString::Append(PRUnichar aChar) {
Initialize(temp,eTwoByte);
temp.mUStr=buf;
temp.mLength=1;
nsStr::Append(*this,temp,0,1,mAgent);
nsStr::Append(*this,temp,0,1);
return *this;
}
@@ -931,7 +958,7 @@ nsCString& nsCString::Append(char aChar) {
Initialize(temp,eOneByte);
temp.mStr=buf;
temp.mLength=1;
nsStr::Append(*this,temp,0,1,mAgent);
nsStr::Append(*this,temp,0,1);
return *this;
}
@@ -962,12 +989,12 @@ nsCString& nsCString::Append(PRInt32 anInteger,PRInt32 aRadix) {
PRBool isfirst=PR_TRUE;
while(mask1>=1) {
PRInt32 div=theInt/mask1;
if((div) || (!isfirst)) {
buf[charpos++]="0123456789abcdef"[div];
PRInt32 theDiv=theInt/mask1;
if((theDiv) || (!isfirst)) {
buf[charpos++]="0123456789abcdef"[theDiv];
isfirst=PR_FALSE;
}
theInt-=div*mask1;
theInt-=theDiv*mask1;
mask1/=aRadix;
}
return Append(buf);
@@ -1001,7 +1028,7 @@ PRUint32 nsCString::Left(nsCString& aDest,PRInt32 aCount) const{
if(aCount<0)
aCount=mLength;
else aCount=MinInt(aCount,mLength);
nsStr::Assign(aDest,*this,0,aCount,mAgent);
nsStr::Assign(aDest,*this,0,aCount);
return aDest.mLength;
}
@@ -1018,7 +1045,7 @@ PRUint32 nsCString::Mid(nsCString& aDest,PRUint32 anOffset,PRInt32 aCount) const
if(aCount<0)
aCount=mLength;
else aCount=MinInt(aCount,mLength);
nsStr::Assign(aDest,*this,anOffset,aCount,mAgent);
nsStr::Assign(aDest,*this,anOffset,aCount);
return aDest.mLength;
}
@@ -1048,7 +1075,7 @@ PRUint32 nsCString::Right(nsCString& aDest,PRInt32 aCount) const{
*/
nsCString& nsCString::Insert(const nsCString& aString,PRUint32 anOffset,PRInt32 aCount) {
nsStr::Insert(*this,anOffset,aString,0,aCount,mAgent);
nsStr::Insert(*this,anOffset,aString,0,aCount);
return *this;
}
@@ -1079,7 +1106,7 @@ nsCString& nsCString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCou
else aCount=temp.mLength=nsCRT::strlen(aCString);
if(temp.mLength && (0<aCount)){
nsStr::Insert(*this,anOffset,temp,0,aCount,0);
nsStr::Insert(*this,anOffset,temp,0,aCount);
}
}
return *this;
@@ -1101,7 +1128,7 @@ nsCString& nsCString::Insert(PRUnichar aChar,PRUint32 anOffset){
nsStr::Initialize(temp,eTwoByte);
temp.mUStr=theBuffer;
temp.mLength=1;
nsStr::Insert(*this,anOffset,temp,0,1,0);
nsStr::Insert(*this,anOffset,temp,0,1);
return *this;
}
@@ -1121,7 +1148,7 @@ nsCString& nsCString::Insert(char aChar,PRUint32 anOffset){
nsStr::Initialize(temp,eOneByte);
temp.mStr=theBuffer;
temp.mLength=1;
nsStr::Insert(*this,anOffset,temp,0,1,0);
nsStr::Insert(*this,anOffset,temp,0,1);
return *this;
}
@@ -1136,7 +1163,7 @@ nsCString& nsCString::Insert(char aChar,PRUint32 anOffset){
*/
nsCString& nsCString::Cut(PRUint32 anOffset, PRInt32 aCount) {
if(0<aCount) {
nsStr::Delete(*this,anOffset,aCount,mAgent);
nsStr::Delete(*this,anOffset,aCount);
}
return *this;
}
@@ -1560,10 +1587,8 @@ PRBool nsCString::Equals(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 aCo
class nsCStringDeallocator: public nsDequeFunctor{
public:
virtual void* operator()(void* anObject) {
static nsMemoryAgent theAgent;
nsCString* aString= (nsCString*)anObject;
if(aString){
aString->mAgent=&theAgent;
delete aString;
}
return 0;
@@ -1722,7 +1747,6 @@ NS_COM int fputs(const nsCString& aString, FILE* out)
*/
nsCAutoString::nsCAutoString() : nsCString(){
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
mAgent=0;
AddNullTerminator(*this);
}
@@ -1732,7 +1756,6 @@ nsCAutoString::nsCAutoString() : nsCString(){
*/
nsCAutoString::nsCAutoString(const nsCAutoString& aString) : nsCString() {
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
mAgent=0;
AddNullTerminator(*this);
Append(aString);
}
@@ -1744,7 +1767,6 @@ nsCAutoString::nsCAutoString(const nsCAutoString& aString) : nsCString() {
*/
nsCAutoString::nsCAutoString(const char* aCString,PRInt32 aLength) : nsCString() {
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
mAgent=0;
AddNullTerminator(*this);
Append(aCString,aLength);
}
@@ -1754,7 +1776,6 @@ nsCAutoString::nsCAutoString(const char* aCString,PRInt32 aLength) : nsCString()
* @param aBuffer -- descibes external buffer
*/
nsCAutoString::nsCAutoString(const CBufDescriptor& aBuffer) : nsCString() {
mAgent=0;
if(!aBuffer.mBuffer) {
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
}
@@ -1770,7 +1791,6 @@ nsCAutoString::nsCAutoString(const CBufDescriptor& aBuffer) : nsCString() {
* @param aString is a ptr to a unistr
*/
nsCAutoString::nsCAutoString(const PRUnichar* aString,PRInt32 aLength) : nsCString() {
mAgent=0;
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
AddNullTerminator(*this);
Append(aString,aLength);
@@ -1781,7 +1801,6 @@ nsCAutoString::nsCAutoString(const PRUnichar* aString,PRInt32 aLength) : nsCStri
* @param
*/
nsCAutoString::nsCAutoString(const nsStr& aString) : nsCString() {
mAgent=0;
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
AddNullTerminator(*this);
Append(aString);
@@ -1794,7 +1813,6 @@ nsCAutoString::nsCAutoString(const nsStr& aString) : nsCString() {
* @param
*/
nsCAutoString::nsCAutoString(PRUnichar aChar) : nsCString(){
mAgent=0;
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
AddNullTerminator(*this);
Append(aChar);
@@ -1807,12 +1825,10 @@ nsCAutoString::nsCAutoString(PRUnichar aChar) : nsCString(){
*/
#ifdef AIX
nsCAutoString::nsCAutoString(const nsSubsumeCStr& aSubsumeStr) :nsCString() {
mAgent=0;
nsSubsumeCStr temp(aSubsumeStr); // a temp is needed for the AIX compiler
CSubsume(*this,temp);
#else
nsCAutoString::nsCAutoString( nsSubsumeCStr& aSubsumeStr) :nsCString() {
mAgent=0;
CSubsume(*this,aSubsumeStr);
#endif // AIX
}

File diff suppressed because it is too large Load Diff

View File

@@ -38,7 +38,7 @@ static const char* kWhitespace="\b\t\r\n ";
static void Subsume(nsStr& aDest,nsStr& aSource){
if(aSource.mStr && aSource.mLength) {
if(aSource.mOwnsBuffer){
nsStr::Destroy(aDest,0);
nsStr::Destroy(aDest);
aDest.mStr=aSource.mStr;
aDest.mLength=aSource.mLength;
aDest.mCharSize=aSource.mCharSize;
@@ -48,17 +48,17 @@ static void Subsume(nsStr& aDest,nsStr& aSource){
aSource.mStr=0;
}
else{
nsStr::Assign(aDest,aSource,0,aSource.mLength,0);
nsStr::Assign(aDest,aSource,0,aSource.mLength);
}
}
else nsStr::Truncate(aDest,0,0);
else nsStr::Truncate(aDest,0);
}
/**
* Default constructor.
*/
nsString::nsString(nsIMemoryAgent* anAgent) : mAgent(anAgent) {
nsString::nsString() {
nsStr::Initialize(*this,eTwoByte);
}
@@ -68,7 +68,7 @@ nsString::nsString(nsIMemoryAgent* anAgent) : mAgent(anAgent) {
* @param aCString is a ptr to a 1-byte cstr
* @param aLength tells us how many chars to copy from given CString
*/
nsString::nsString(const char* aCString,nsIMemoryAgent* anAgent) : mAgent(anAgent) {
nsString::nsString(const char* aCString){
nsStr::Initialize(*this,eTwoByte);
Assign(aCString);
}
@@ -79,7 +79,7 @@ nsString::nsString(const char* aCString,nsIMemoryAgent* anAgent) : mAgent(anAgen
* @param aString is a ptr to a unichar string
* @param aLength tells us how many chars to copy from given aString
*/
nsString::nsString(const PRUnichar* aString,nsIMemoryAgent* anAgent) : mAgent(anAgent) {
nsString::nsString(const PRUnichar* aString) {
nsStr::Initialize(*this,eTwoByte);
Assign(aString);
}
@@ -89,9 +89,9 @@ nsString::nsString(const PRUnichar* aString,nsIMemoryAgent* anAgent) : mAgent(an
* @update gess 1/4/99
* @param reference to another nsCString
*/
nsString::nsString(const nsStr &aString,nsIMemoryAgent* anAgent) : mAgent(anAgent) {
nsString::nsString(const nsStr &aString) {
nsStr::Initialize(*this,eTwoByte);
nsStr::Assign(*this,aString,0,aString.mLength,mAgent);
nsStr::Assign(*this,aString,0,aString.mLength);
}
/**
@@ -99,9 +99,9 @@ nsString::nsString(const nsStr &aString,nsIMemoryAgent* anAgent) : mAgent(anAgen
* @update gess 1/4/99
* @param reference to another nsString
*/
nsString::nsString(const nsString& aString) :mAgent(aString.mAgent) {
nsString::nsString(const nsString& aString) {
nsStr::Initialize(*this,eTwoByte);
nsStr::Assign(*this,aString,0,aString.mLength,mAgent);
nsStr::Assign(*this,aString,0,aString.mLength);
}
/**
@@ -109,7 +109,7 @@ nsString::nsString(const nsString& aString) :mAgent(aString.mAgent) {
* @update gess 1/4/99
* @param reference to a subsumeString
*/
nsString::nsString(nsSubsumeStr& aSubsumeStr) :mAgent(0) {
nsString::nsString(nsSubsumeStr& aSubsumeStr) {
nsStr::Initialize(*this,eTwoByte);
Subsume(*this,aSubsumeStr);
}
@@ -119,7 +119,7 @@ nsString::nsString(nsSubsumeStr& aSubsumeStr) :mAgent(0) {
* Make sure we call nsStr::Destroy.
*/
nsString::~nsString() {
nsStr::Destroy(*this,mAgent);
nsStr::Destroy(*this);
}
void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
@@ -136,7 +136,7 @@ void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
* @return nada
*/
void nsString::Truncate(PRInt32 anIndex) {
nsStr::Truncate(*this,anIndex,mAgent);
nsStr::Truncate(*this,anIndex);
}
/**
@@ -173,7 +173,7 @@ PRBool nsString::IsOrdered(void) const {
*/
void nsString::SetCapacity(PRUint32 aLength) {
if(aLength>mCapacity) {
GrowCapacity(*this,aLength,mAgent);
GrowCapacity(*this,aLength);
}
AddNullTerminator(*this);
}
@@ -270,7 +270,7 @@ PRBool nsString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
*/
nsSubsumeStr nsString::operator+(const nsStr& aString){
nsString temp(*this); //make a temp string the same size as this...
nsStr::Append(temp,aString,0,aString.mLength,mAgent);
nsStr::Append(temp,aString,0,aString.mLength);
return nsSubsumeStr(temp);
}
@@ -282,7 +282,7 @@ nsSubsumeStr nsString::operator+(const nsStr& aString){
*/
nsSubsumeStr nsString::operator+(const nsString& aString){
nsString temp(*this); //make a temp string the same size as this...
nsStr::Append(temp,aString,0,aString.mLength,mAgent);
nsStr::Append(temp,aString,0,aString.mLength);
return nsSubsumeStr(temp);
}
@@ -786,54 +786,55 @@ static PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadi
* @return non-zero error code if this string is non-numeric
*/
static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) {
static const char* validChars="0123456789abcdefABCDEF-+#";
aString.ToUpperCase();
const char* cp=aString.GetBuffer();
PRInt32 result=NS_ERROR_ILLEGAL_VALUE;
if(cp) {
PRInt32 decPt=nsStr::FindChar(aString,'.',PR_TRUE,0);
char* cp = (kNotFound==decPt) ? aString.mStr + aString.mLength-1 : aString.mStr+decPt-1;
aRadix=kRadixUnknown; //assume for starters...
//begin by skipping over leading chars that shouldn't be part of the number...
char* to=(char*)cp;
const char* endcp=cp+aString.mLength;
int len=strlen(validChars);
// Skip trailing non-numeric...
while (cp >= aString.mStr) {
if((*cp>='0') && (*cp<='9')){
if(kRadixUnknown==aRadix)
aRadix=kRadix10;
break;
while(cp<endcp){
const char* pos=(const char*)memchr(validChars,*cp,len);
if(!pos) {
cp++;
}
else break;
}
else if((*cp>='A') && (*cp<='F')) {
aRadix=16;
break;
}
cp--;
while(cp<endcp){
char theChar=toupper(*cp);
if((theChar>='0') && (theChar<='9')) {
*to++=theChar;
}
else if((theChar>='A') && (theChar<='F')) {
aRadix=16;
*to++=theChar;
}
else if('X'==theChar){
if('-'==aString.mStr[0])
to=&aString.mStr[1];
else to=aString.mStr;
aRadix=16;
//root=cp;
}
else if('-'==theChar) {
*to++=theChar;
}
else if(('#'==theChar) || ('+'==theChar)){
//just skip this char...
}
else break;
cp++;
}
aString.Truncate(to-aString.mStr);
result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK;
}
aString.Truncate(cp-aString.mStr+1);
//ok, now scan through chars until you find the start of this number...
//we delimit the number by the presence of: +,-,#,X
// Skip trailing non-numeric...
cp++;
while (--cp >= aString.mStr) {
if((*cp>='0') && (*cp<='9')){
continue;
}
else if((*cp>='A') && (*cp<='F')) {
continue;
}
else if((*cp=='-') || (*cp=='+')){
break;
}
else {
if(('#'==(*cp)) || ('X'==(*cp)))
aRadix=kRadix16;
cp++; //move back by one
break;
}
}
if(cp>aString.mStr)
aString.Cut(0,cp-aString.mStr);
PRInt32 result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK;
return result;
}
@@ -865,10 +866,10 @@ PRUint32 nsString::DetermineRadix(void) {
PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
//copy chars to local buffer -- step down from 2 bytes to 1 if necessary...
PRInt32 result=0;
nsCAutoString theString(*this);
PRUint32 theRadix=aRadix;
PRInt32 result=0;
*anErrorCode=GetNumericSubstring(theString,theRadix); //we actually don't use this radix; use given radix instead
if(NS_OK==*anErrorCode){
if(kAutoDetect==aRadix)
@@ -893,13 +894,13 @@ PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
*/
nsString& nsString::Assign(const nsStr& aString,PRInt32 aCount) {
if(this!=&aString){
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
if(aCount<0)
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
nsStr::Assign(*this,aString,0,aCount,mAgent);
nsStr::Assign(*this,aString,0,aCount);
}
return *this;
}
@@ -912,7 +913,7 @@ nsString& nsString::Assign(const nsStr& aString,PRInt32 aCount) {
* @return this
*/
nsString& nsString::Assign(const char* aCString,PRInt32 aCount) {
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
if(aCString){
Append(aCString,aCount);
}
@@ -926,7 +927,7 @@ nsString& nsString::Assign(const char* aCString,PRInt32 aCount) {
* @return this
*/
nsString& nsString::Assign(const PRUnichar* aString,PRInt32 aCount) {
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
if(aString){
Append(aString,aCount);
}
@@ -940,7 +941,7 @@ nsString& nsString::Assign(const PRUnichar* aString,PRInt32 aCount) {
* @return this
*/
nsString& nsString::Assign(char aChar) {
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
return Append(aChar);
}
@@ -951,7 +952,7 @@ nsString& nsString::Assign(char aChar) {
* @return this
*/
nsString& nsString::Assign(PRUnichar aChar) {
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
return Append(aChar);
}
@@ -988,7 +989,7 @@ nsString& nsString::Append(const nsStr& aString,PRInt32 aCount) {
else aCount=MinInt(aCount,aString.mLength);
if(0<aCount)
nsStr::Append(*this,aString,0,aCount,mAgent);
nsStr::Append(*this,aString,0,aCount);
return *this;
}
@@ -1005,7 +1006,7 @@ nsString& nsString::Append(const nsString& aString,PRInt32 aCount) {
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
if(0<aCount)
nsStr::Append(*this,aString,0,aCount,mAgent);
nsStr::Append(*this,aString,0,aCount);
return *this;
}
@@ -1034,7 +1035,7 @@ nsString& nsString::Append(const char* aCString,PRInt32 aCount) {
else aCount=temp.mLength=nsCRT::strlen(aCString);
if(0<aCount)
nsStr::Append(*this,temp,0,aCount,mAgent);
nsStr::Append(*this,temp,0,aCount);
}
return *this;
}
@@ -1064,7 +1065,7 @@ nsString& nsString::Append(const PRUnichar* aString,PRInt32 aCount) {
else aCount=temp.mLength=nsCRT::strlen(aString);
if(0<aCount)
nsStr::Append(*this,temp,0,aCount,mAgent);
nsStr::Append(*this,temp,0,aCount);
}
return *this;
}
@@ -1083,7 +1084,7 @@ nsString& nsString::Append(char aChar) {
Initialize(temp,eOneByte);
temp.mStr=buf;
temp.mLength=1;
nsStr::Append(*this,temp,0,1,mAgent);
nsStr::Append(*this,temp,0,1);
return *this;
}
@@ -1101,7 +1102,7 @@ nsString& nsString::Append(PRUnichar aChar) {
Initialize(temp,eTwoByte);
temp.mUStr=buf;
temp.mLength=1;
nsStr::Append(*this,temp,0,1,mAgent);
nsStr::Append(*this,temp,0,1);
return *this;
}
@@ -1132,12 +1133,12 @@ nsString& nsString::Append(PRInt32 anInteger,PRInt32 aRadix) {
PRBool isfirst=PR_TRUE;
while(mask1>=1) {
PRInt32 div=theInt/mask1;
if((div) || (!isfirst)) {
buf[charpos++]="0123456789abcdef"[div];
PRInt32 theDiv=theInt/mask1;
if((theDiv) || (!isfirst)) {
buf[charpos++]="0123456789abcdef"[theDiv];
isfirst=PR_FALSE;
}
theInt-=div*mask1;
theInt-=theDiv*mask1;
mask1/=aRadix;
}
return Append(buf);
@@ -1173,7 +1174,7 @@ PRUint32 nsString::Left(nsString& aDest,PRInt32 aCount) const{
if(aCount<0)
aCount=mLength;
else aCount=MinInt(aCount,mLength);
nsStr::Assign(aDest,*this,0,aCount,mAgent);
nsStr::Assign(aDest,*this,0,aCount);
return aDest.mLength;
}
@@ -1191,7 +1192,7 @@ PRUint32 nsString::Mid(nsString& aDest,PRUint32 anOffset,PRInt32 aCount) const{
if(aCount<0)
aCount=mLength;
else aCount=MinInt(aCount,mLength);
nsStr::Assign(aDest,*this,anOffset,aCount,mAgent);
nsStr::Assign(aDest,*this,anOffset,aCount);
return aDest.mLength;
}
@@ -1221,7 +1222,7 @@ PRUint32 nsString::Right(nsString& aDest,PRInt32 aCount) const{
* @return this
*/
nsString& nsString::Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) {
nsStr::Insert(*this,anOffset,aCopy,0,aCount,mAgent);
nsStr::Insert(*this,anOffset,aCopy,0,aCount);
return *this;
}
@@ -1252,7 +1253,7 @@ nsString& nsString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCount
else aCount=temp.mLength=nsCRT::strlen(aCString);
if(0<aCount){
nsStr::Insert(*this,anOffset,temp,0,aCount,0);
nsStr::Insert(*this,anOffset,temp,0,aCount);
}
}
return *this;
@@ -1285,7 +1286,7 @@ nsString& nsString::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32 aC
else aCount=temp.mLength=nsCRT::strlen(aString);
if(0<aCount){
nsStr::Insert(*this,anOffset,temp,0,aCount,0);
nsStr::Insert(*this,anOffset,temp,0,aCount);
}
}
return *this;
@@ -1308,7 +1309,7 @@ nsString& nsString::Insert(PRUnichar aChar,PRUint32 anOffset){
nsStr::Initialize(temp,eTwoByte);
temp.mUStr=theBuffer;
temp.mLength=1;
nsStr::Insert(*this,anOffset,temp,0,1,0);
nsStr::Insert(*this,anOffset,temp,0,1);
return *this;
}
@@ -1323,7 +1324,7 @@ nsString& nsString::Insert(PRUnichar aChar,PRUint32 anOffset){
*/
nsString& nsString::Cut(PRUint32 anOffset, PRInt32 aCount) {
if(0<aCount) {
nsStr::Delete(*this,anOffset,aCount,mAgent);
nsStr::Delete(*this,anOffset,aCount);
}
return *this;
}
@@ -1957,10 +1958,8 @@ PRBool nsString::IsDigit(PRUnichar aChar) {
class nsStringDeallocator: public nsDequeFunctor{
public:
virtual void* operator()(void* anObject) {
static nsMemoryAgent theAgent;
nsString* aString= (nsString*)anObject;
if(aString){
aString->mAgent=&theAgent;
delete aString;
}
return 0;
@@ -2116,7 +2115,6 @@ NS_COM int fputs(const nsString& aString, FILE* out)
*/
nsAutoString::nsAutoString() : nsString() {
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
mAgent=0;
AddNullTerminator(*this);
}
@@ -2127,7 +2125,6 @@ nsAutoString::nsAutoString() : nsString() {
*/
nsAutoString::nsAutoString(const char* aCString,PRInt32 aLength) : nsString() {
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
mAgent=0;
AddNullTerminator(*this);
Append(aCString,aLength);
}
@@ -2138,7 +2135,6 @@ nsAutoString::nsAutoString(const char* aCString,PRInt32 aLength) : nsString() {
* @param aLength tells us how many chars to copy from aString
*/
nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString() {
mAgent=0;
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
AddNullTerminator(*this);
Append(aString,aLength);
@@ -2149,7 +2145,6 @@ nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString(
* @param aBuffer describes the external buffer
*/
nsAutoString::nsAutoString(const CBufDescriptor& aBuffer) : nsString() {
mAgent=0;
if(!aBuffer.mBuffer) {
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
}
@@ -2166,7 +2161,6 @@ nsAutoString::nsAutoString(const CBufDescriptor& aBuffer) : nsString() {
* @param
*/
nsAutoString::nsAutoString(const nsStr& aString) : nsString() {
mAgent=0;
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
AddNullTerminator(*this);
Append(aString);
@@ -2176,7 +2170,6 @@ nsAutoString::nsAutoString(const nsStr& aString) : nsString() {
* Default copy constructor
*/
nsAutoString::nsAutoString(const nsAutoString& aString) : nsString() {
mAgent=0;
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
AddNullTerminator(*this);
Append(aString);
@@ -2188,7 +2181,6 @@ nsAutoString::nsAutoString(const nsAutoString& aString) : nsString() {
* @param
*/
nsAutoString::nsAutoString(PRUnichar aChar) : nsString(){
mAgent=0;
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
AddNullTerminator(*this);
Append(aChar);
@@ -2201,12 +2193,10 @@ nsAutoString::nsAutoString(PRUnichar aChar) : nsString(){
*/
#ifdef AIX
nsAutoString::nsAutoString(const nsSubsumeStr& aSubsumeStr) :nsString() {
mAgent=0;
nsSubsumeStr temp(aSubsumeStr); // a temp is needed for the AIX compiler
Subsume(*this,temp);
#else
nsAutoString::nsAutoString( nsSubsumeStr& aSubsumeStr) :nsString() {
mAgent=0;
Subsume(*this,aSubsumeStr);
#endif // AIX
}

File diff suppressed because it is too large Load Diff

View File

@@ -69,16 +69,6 @@ void nsStr::Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 a
aDest.mOwnsBuffer=aOwnsBuffer;
}
/**
*
* @update gess10/30/98
* @param
* @return
*/
nsIMemoryAgent* GetDefaultAgent(void){
static nsMemoryAgent gDefaultAgent;
return (nsIMemoryAgent*)&gDefaultAgent;
}
/**
* This member destroys the memory buffer owned by an nsStr object (if it actually owns it)
@@ -86,17 +76,9 @@ nsIMemoryAgent* GetDefaultAgent(void){
* @param
* @return
*/
void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) {
void nsStr::Destroy(nsStr& aDest) {
if((aDest.mStr) && (aDest.mStr!=(char*)gCommonEmptyBuffer)) {
if(!anAgent)
anAgent=GetDefaultAgent();
if(anAgent) {
anAgent->Free(aDest);
}
else{
printf("%s\n","Leak occured in nsStr.");
}
Free(aDest);
}
}
@@ -108,11 +90,10 @@ void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) {
* @param aNewLength -- new capacity of string in charSize units
* @return void
*/
PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent) {
PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength) {
PRBool result=PR_TRUE;
if(aNewLength>aString.mCapacity) {
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
result=theAgent->Realloc(aString,aNewLength);
result=Realloc(aString,aNewLength);
if(aString.mStr)
AddNullTerminator(aString);
}
@@ -126,20 +107,18 @@ PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent*
* @param aNewLength -- new capacity of string in charSize units
* @return void
*/
PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAgent) {
PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength) {
PRBool result=PR_TRUE;
if(aNewLength>aDest.mCapacity) {
nsStr theTempStr;
nsStr::Initialize(theTempStr,aDest.mCharSize);
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
result=EnsureCapacity(theTempStr,aNewLength,theAgent);
result=EnsureCapacity(theTempStr,aNewLength);
if(result) {
if(aDest.mLength) {
Append(theTempStr,aDest,0,aDest.mLength,theAgent);
Append(theTempStr,aDest,0,aDest.mLength);
}
theAgent->Free(aDest);
Free(aDest);
aDest.mStr = theTempStr.mStr;
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
aDest.mLength=theTempStr.mLength;
@@ -157,10 +136,10 @@ PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAg
* @param aSource is where chars are copied from
* @param aCount is the number of chars copied from aSource
*/
void nsStr::Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){
void nsStr::Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount){
if(&aDest!=&aSource){
Truncate(aDest,0,anAgent);
Append(aDest,aSource,anOffset,aCount,anAgent);
Truncate(aDest,0);
Append(aDest,aSource,anOffset,aCount);
}
}
@@ -172,7 +151,7 @@ void nsStr::Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 a
* @param aSource is where char are copied from
* @aCount is the number of bytes to be copied
*/
void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){
void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount){
if(anOffset<aSource.mLength){
PRUint32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
PRUint32 theLength=(anOffset+theRealLen<aSource.mLength) ? theRealLen : (aSource.mLength-anOffset);
@@ -180,7 +159,7 @@ void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 a
PRBool isBigEnough=PR_TRUE;
if(aDest.mLength+theLength > aDest.mCapacity) {
isBigEnough=GrowCapacity(aDest,aDest.mLength+theLength,anAgent);
isBigEnough=GrowCapacity(aDest,aDest.mLength+theLength);
}
if(isBigEnough) {
@@ -204,7 +183,7 @@ void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 a
* @param aSrcOffset is where in aSource chars are copied from
* @param aCount is the number of chars from aSource to be inserted into aDest
*/
void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){
void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount){
//there are a few cases for insert:
// 1. You're inserting chars into an empty string (assign)
// 2. You're inserting onto the end of a string (append)
@@ -223,22 +202,21 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin
nsStr theTempStr;
nsStr::Initialize(theTempStr,aDest.mCharSize);
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
PRBool isBigEnough=EnsureCapacity(theTempStr,aDest.mLength+theLength,theAgent); //grow the temp buffer to the right size
PRBool isBigEnough=EnsureCapacity(theTempStr,aDest.mLength+theLength); //grow the temp buffer to the right size
if(isBigEnough) {
if(aDestOffset) {
Append(theTempStr,aDest,0,aDestOffset,theAgent); //first copy leftmost data...
Append(theTempStr,aDest,0,aDestOffset); //first copy leftmost data...
}
Append(theTempStr,aSource,0,aSource.mLength,theAgent); //next copy inserted (new) data
Append(theTempStr,aSource,0,aSource.mLength); //next copy inserted (new) data
PRUint32 theRemains=aDest.mLength-aDestOffset;
if(theRemains) {
Append(theTempStr,aDest,aDestOffset,theRemains,theAgent); //next copy rightmost data
Append(theTempStr,aDest,aDestOffset,theRemains); //next copy rightmost data
}
theAgent->Free(aDest);
Free(aDest);
aDest.mStr = theTempStr.mStr;
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
aDest.mCapacity=theTempStr.mCapacity;
@@ -262,9 +240,9 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin
}//if
//else nothing to do!
}
else Append(aDest,aSource,0,aCount,anAgent);
else Append(aDest,aSource,0,aCount);
}
else Append(aDest,aSource,0,aCount,anAgent);
else Append(aDest,aSource,0,aCount);
}
}
@@ -276,7 +254,7 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin
* @param aDestOffset is where in aDest deletion is to occur
* @param aCount is the number of chars to be deleted in aDest
*/
void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAgent* anAgent){
void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount){
if(aDestOffset<aDest.mLength){
PRUint32 theDelta=aDest.mLength-aDestOffset;
@@ -290,7 +268,7 @@ void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAg
aDest.mLength-=theLength;
AddNullTerminator(aDest);
}
else Truncate(aDest,aDestOffset,anAgent);
else Truncate(aDest,aDestOffset);
}//if
}
@@ -300,7 +278,7 @@ void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAg
* @param aDest is the nsStr to be truncated
* @param aDestOffset is where in aDest truncation is to occur
*/
void nsStr::Truncate(nsStr& aDest,PRUint32 aDestOffset,nsIMemoryAgent* anAgent){
void nsStr::Truncate(nsStr& aDest,PRUint32 aDestOffset){
if(aDestOffset<aDest.mLength){
aDest.mLength=aDestOffset;
AddNullTerminator(aDest);
@@ -342,7 +320,7 @@ void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool a
}
if(0<theIndex) {
if(theIndex<theMax) {
Delete(aDest,0,theIndex,0);
Delete(aDest,0,theIndex);
}
else Truncate(aDest,0);
}
@@ -515,7 +493,7 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgno
nsStr theCopy;
nsStr::Initialize(theCopy,eOneByte);
nsStr::Assign(theCopy,aTarget,0,aTarget.mLength,0);
nsStr::Assign(theCopy,aTarget,0,aTarget.mLength);
if(aIgnoreCase){
nsStr::ChangeCase(theCopy,PR_FALSE); //force to lowercase
}
@@ -538,7 +516,7 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgno
}
index--;
} //while
nsStr::Destroy(theCopy,0);
nsStr::Destroy(theCopy);
}//if
}//if
return result;
@@ -625,6 +603,57 @@ PRInt32 nsStr::Compare(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PR
//----------------------------------------------------------------------------------------
PRBool nsStr::Alloc(nsStr& aDest,PRUint32 aCount) {
static int mAllocCount=0;
mAllocCount++;
//we're given the acount value in charunits; now scale up to next multiple.
PRUint32 theNewCapacity=kDefaultStringSize;
while(theNewCapacity<aCount){
theNewCapacity<<=1;
}
aDest.mCapacity=theNewCapacity++;
PRUint32 theSize=(theNewCapacity<<aDest.mCharSize);
aDest.mStr = (char*)nsAllocator::Alloc(theSize);
PRBool result=PR_FALSE;
if(aDest.mStr) {
aDest.mOwnsBuffer=1;
result=PR_TRUE;
}
return result;
}
PRBool nsStr::Free(nsStr& aDest){
if(aDest.mStr){
if(aDest.mOwnsBuffer){
nsAllocator::Free(aDest.mStr);
}
aDest.mStr=0;
aDest.mOwnsBuffer=0;
return PR_TRUE;
}
return PR_FALSE;
}
PRBool nsStr::Realloc(nsStr& aDest,PRUint32 aCount){
nsStr temp;
memcpy(&temp,&aDest,sizeof(aDest));
PRBool result=Alloc(temp,aCount);
if(result) {
Free(aDest);
aDest.mStr=temp.mStr;
aDest.mCapacity=temp.mCapacity;
}
return result;
}
//----------------------------------------------------------------------------------------
CBufDescriptor::CBufDescriptor(char* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength) {
mBuffer=aString;
mCharSize=eOneByte;
@@ -683,3 +712,5 @@ CBufDescriptor::CBufDescriptor(const PRUnichar* aString,PRBool aStackBased,PRUin
}
//----------------------------------------------------------------------------------------

View File

@@ -164,6 +164,7 @@
#include "nscore.h"
#include "nsIAllocator.h"
#include <string.h>
//----------------------------------------------------------------------------------------
@@ -177,8 +178,6 @@ const PRInt32 kDefaultStringSize = 64;
const PRInt32 kNotFound = -1;
class nsIMemoryAgent;
//----------------------------------------------------------------------------------------
class NS_COM CBufDescriptor {
@@ -228,7 +227,7 @@ struct NS_COM nsStr {
* @param aString is the nsStr to be manipulated
* @param anAgent is the allocator to be used to the nsStr
*/
static void Destroy(nsStr& aDest,nsIMemoryAgent* anAgent=0);
static void Destroy(nsStr& aDest);
/**
* These methods are where memory allocation/reallocation occur.
@@ -238,8 +237,8 @@ struct NS_COM nsStr {
* @param anAgent is the allocator to be used on the nsStr
* @return
*/
static PRBool EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0);
static PRBool GrowCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0);
static PRBool EnsureCapacity(nsStr& aString,PRUint32 aNewLength);
static PRBool GrowCapacity(nsStr& aString,PRUint32 aNewLength);
/**
* These methods are used to append content to the given nsStr
@@ -251,7 +250,7 @@ struct NS_COM nsStr {
* @param aCount tells us the (max) # of chars to copy
* @param anAgent is the allocator to be used for alloc/free operations
*/
static void Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0);
static void Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount);
/**
* These methods are used to assign contents of a source string to dest string
@@ -263,7 +262,7 @@ struct NS_COM nsStr {
* @param aCount tells us the (max) # of chars to copy
* @param anAgent is the allocator to be used for alloc/free operations
*/
static void Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0);
static void Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount);
/**
* These methods are used to insert content from source string to the dest nsStr
@@ -276,7 +275,7 @@ struct NS_COM nsStr {
* @param aCount tells us the (max) # of chars to insert
* @param anAgent is the allocator to be used for alloc/free operations
*/
static void Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0);
static void Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount);
/**
* This method deletes chars from the given str.
@@ -288,7 +287,7 @@ struct NS_COM nsStr {
* @param aCount tells us the (max) # of chars to delete
* @param anAgent is the allocator to be used for alloc/free operations
*/
static void Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAgent* anAgent=0);
static void Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount);
/**
* This method is used to truncate the given string.
@@ -301,7 +300,7 @@ struct NS_COM nsStr {
* @param aSrcOffset tells us where in source to start copying
* @param anAgent is the allocator to be used for alloc/free operations
*/
static void Truncate(nsStr& aDest,PRUint32 aDestOffset,nsIMemoryAgent* anAgent=0);
static void Truncate(nsStr& aDest,PRUint32 aDestOffset);
/**
* This method is used to perform a case conversion on the given string
@@ -388,6 +387,12 @@ struct NS_COM nsStr {
char* mStr;
PRUnichar* mUStr;
};
private:
static PRBool Alloc(nsStr& aString,PRUint32 aCount);
static PRBool Realloc(nsStr& aString,PRUint32 aCount);
static PRBool Free(nsStr& aString);
};
/**************************************************************
@@ -430,74 +435,6 @@ inline PRUnichar GetCharAt(const nsStr& aDest,PRUint32 anIndex){
return 0;
}
//----------------------------------------------------------------------------------------
class nsIMemoryAgent {
public:
virtual PRBool Alloc(nsStr& aString,PRUint32 aCount)=0;
virtual PRBool Realloc(nsStr& aString,PRUint32 aCount)=0;
virtual PRBool Free(nsStr& aString)=0;
};
class nsMemoryAgent : public nsIMemoryAgent {
public:
virtual PRBool Alloc(nsStr& aDest,PRUint32 aCount) {
static int mAllocCount=0;
mAllocCount++;
//we're given the acount value in charunits; now scale up to next multiple.
PRUint32 theNewCapacity=kDefaultStringSize;
while(theNewCapacity<aCount){
theNewCapacity<<=1;
}
aDest.mCapacity=theNewCapacity++;
PRUint32 theSize=(theNewCapacity<<aDest.mCharSize);
aDest.mStr = (char*)nsAllocator::Alloc(theSize);
PRBool result=PR_FALSE;
if(aDest.mStr) {
aDest.mOwnsBuffer=1;
result=PR_TRUE;
}
return result;
}
virtual PRBool Free(nsStr& aDest){
if(aDest.mStr){
if(aDest.mOwnsBuffer){
nsAllocator::Free(aDest.mStr);
}
aDest.mStr=0;
aDest.mOwnsBuffer=0;
return PR_TRUE;
}
return PR_FALSE;
}
virtual PRBool Realloc(nsStr& aDest,PRUint32 aCount){
Free(aDest);
return Alloc(aDest,aCount);
#if 0
nsStr temp;
memcpy(&temp,&aDest,sizeof(aDest));
PRBool result=Alloc(temp,aCount);
if(result) {
Free(aDest);
aDest.mStr=temp.mStr;
aDest.mCapacity=temp.mCapacity;
}
return result;
#endif
}
};
nsIMemoryAgent* GetDefaultAgent(void);
#endif

View File

@@ -40,7 +40,7 @@ static const char* kWhitespace="\b\t\r\n ";
static void CSubsume(nsStr& aDest,nsStr& aSource){
if(aSource.mStr && aSource.mLength) {
if(aSource.mOwnsBuffer){
nsStr::Destroy(aDest,0);
nsStr::Destroy(aDest);
aDest.mStr=aSource.mStr;
aDest.mLength=aSource.mLength;
aDest.mCharSize=aSource.mCharSize;
@@ -50,17 +50,17 @@ static void CSubsume(nsStr& aDest,nsStr& aSource){
aSource.mStr=0;
}
else{
nsStr::Assign(aDest,aSource,0,aSource.mLength,0);
nsStr::Assign(aDest,aSource,0,aSource.mLength);
}
}
else nsStr::Truncate(aDest,0,0);
else nsStr::Truncate(aDest,0);
}
/**
* Default constructor.
*/
nsCString::nsCString(nsIMemoryAgent* anAgent) : mAgent(anAgent) {
nsCString::nsCString() {
nsStr::Initialize(*this,eOneByte);
}
@@ -70,7 +70,7 @@ nsCString::nsCString(nsIMemoryAgent* anAgent) : mAgent(anAgent) {
* @param aCString is a ptr to a 1-byte cstr
* @param aLength tells us how many chars to copy from given CString
*/
nsCString::nsCString(const char* aCString,PRInt32 aLength,nsIMemoryAgent* anAgent) : mAgent(anAgent) {
nsCString::nsCString(const char* aCString,PRInt32 aLength) {
nsStr::Initialize(*this,eOneByte);
Assign(aCString,aLength);
}
@@ -81,7 +81,7 @@ nsCString::nsCString(const char* aCString,PRInt32 aLength,nsIMemoryAgent* anAgen
* @param aString is a ptr to a unichar string
* @param aLength tells us how many chars to copy from given aString
*/
nsCString::nsCString(const PRUnichar* aString,PRInt32 aLength,nsIMemoryAgent* anAgent) : mAgent(anAgent) {
nsCString::nsCString(const PRUnichar* aString,PRInt32 aLength) {
nsStr::Initialize(*this,eOneByte);
if(aString && aLength){
@@ -101,7 +101,7 @@ nsCString::nsCString(const PRUnichar* aString,PRInt32 aLength,nsIMemoryAgent* an
else aLength=temp.mLength=nsCRT::strlen(aString);
if(0<aLength)
nsStr::Append(*this,temp,0,aLength,mAgent);
nsStr::Append(*this,temp,0,aLength);
}
}
@@ -110,9 +110,9 @@ nsCString::nsCString(const PRUnichar* aString,PRInt32 aLength,nsIMemoryAgent* an
* @update gess 1/4/99
* @param reference to another nsCString
*/
nsCString::nsCString(const nsStr &aString,nsIMemoryAgent* anAgent) : mAgent(anAgent) {
nsCString::nsCString(const nsStr &aString) {
nsStr::Initialize(*this,eOneByte);
nsStr::Assign(*this,aString,0,aString.mLength,mAgent);
nsStr::Assign(*this,aString,0,aString.mLength);
}
/**
@@ -120,9 +120,9 @@ nsCString::nsCString(const nsStr &aString,nsIMemoryAgent* anAgent) : mAgent(anAg
* @update gess 1/4/99
* @param reference to another nsCString
*/
nsCString::nsCString(const nsCString& aString) :mAgent(aString.mAgent) {
nsCString::nsCString(const nsCString& aString) {
nsStr::Initialize(*this,aString.mCharSize);
nsStr::Assign(*this,aString,0,aString.mLength,mAgent);
nsStr::Assign(*this,aString,0,aString.mLength);
}
/**
@@ -130,7 +130,7 @@ nsCString::nsCString(const nsCString& aString) :mAgent(aString.mAgent) {
* @update gess 1/4/99
* @param reference to a subsumeString
*/
nsCString::nsCString(nsSubsumeCStr& aSubsumeStr) :mAgent(0) {
nsCString::nsCString(nsSubsumeCStr& aSubsumeStr) {
CSubsume(*this,aSubsumeStr);
}
@@ -138,7 +138,7 @@ nsCString::nsCString(nsSubsumeCStr& aSubsumeStr) :mAgent(0) {
* Destructor
*/
nsCString::~nsCString() {
nsStr::Destroy(*this,mAgent);
nsStr::Destroy(*this);
}
void nsCString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
@@ -155,7 +155,7 @@ void nsCString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
* @return nada
*/
void nsCString::Truncate(PRInt32 anIndex) {
nsStr::Truncate(*this,anIndex,mAgent);
nsStr::Truncate(*this,anIndex);
}
/**
@@ -187,7 +187,7 @@ PRBool nsCString::IsOrdered(void) const {
*/
void nsCString::SetCapacity(PRUint32 aLength) {
if(aLength>mCapacity) {
GrowCapacity(*this,aLength,mAgent);
GrowCapacity(*this,aLength);
}
AddNullTerminator(*this);
}
@@ -262,7 +262,7 @@ PRBool nsCString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
*/
nsSubsumeCStr nsCString::operator+(const nsCString& aString){
nsCString temp(*this); //make a temp string the same size as this...
nsStr::Append(temp,aString,0,aString.mLength,mAgent);
nsStr::Append(temp,aString,0,aString.mLength);
return nsSubsumeCStr(temp);
}
@@ -613,11 +613,19 @@ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) {
}
theDigit=(theChar-'A')+10;
}
else if((theChar>='a') && (theChar<='f')) {
if(10==aRadix){
*anErrorCode=NS_ERROR_ILLEGAL_VALUE;
result=0;
break;
}
theDigit=(theChar-'a')+10;
}
else if('-'==theChar) {
result=-result;
break;
}
else if(('+'==theChar) || (' '==theChar)) { //stop in a good state if you see this...
else if(('+'==theChar) || (' '==theChar) || ('X'==theChar) || ('x'==theChar)) { //stop in a good state if you see this...
break;
}
else {
@@ -634,6 +642,7 @@ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) {
return result;
}
/**
* Call this method to extract the rightmost numeric value from the given
* 1-byte input string, and simultaneously determine the radix.
@@ -645,56 +654,56 @@ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) {
* @param aRadix (an out parm) tells the caller what base we think the string is in.
* @return non-zero error code if this string is non-numeric
*/
PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) {
static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) {
static const char* validChars="0123456789abcdefABCDEF-+#";
aString.ToUpperCase();
const char* cp=aString.GetBuffer();
PRInt32 result=NS_ERROR_ILLEGAL_VALUE;
if(cp) {
PRInt32 decPt=nsStr::FindChar(aString,'.',PR_TRUE,0);
char* cp = (kNotFound==decPt) ? aString.mStr + aString.mLength-1 : aString.mStr+decPt-1;
aRadix=kRadixUnknown; //assume for starters...
//begin by skipping over leading chars that shouldn't be part of the number...
char* to=(char*)cp;
const char* endcp=cp+aString.mLength;
int len=strlen(validChars);
// Skip trailing non-numeric...
while (cp >= aString.mStr) {
if((*cp>='0') && (*cp<='9')){
if(kRadixUnknown==aRadix)
aRadix=kRadix10;
break;
while(cp<endcp){
const char* pos=(const char*)memchr(validChars,*cp,len);
if(!pos) {
cp++;
}
else break;
}
else if((*cp>='A') && (*cp<='F')) {
aRadix=16;
break;
}
cp--;
while(cp<endcp){
char theChar=toupper(*cp);
if((theChar>='0') && (theChar<='9')) {
*to++=theChar;
}
else if((theChar>='A') && (theChar<='F')) {
aRadix=16;
*to++=theChar;
}
else if('X'==theChar){
if('-'==aString.mStr[0])
to=&aString.mStr[1];
else to=aString.mStr;
aRadix=16;
//root=cp;
}
else if('-'==theChar) {
*to++=theChar;
}
else if(('#'==theChar) || ('+'==theChar)){
//just skip this char...
}
else break;
cp++;
}
aString.Truncate(to-aString.mStr);
result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK;
}
aString.Truncate(cp-aString.mStr+1);
//ok, now scan through chars until you find the start of this number...
//we delimit the number by the presence of: +,-,#,X
// Skip trailing non-numeric...
cp++;
while (--cp >= aString.mStr) {
if((*cp>='0') && (*cp<='9')){
continue;
}
else if((*cp>='A') && (*cp<='F')) {
continue;
}
else if((*cp=='-') || (*cp=='+')){
break;
}
else {
if(('#'==(*cp)) || ('X'==(*cp)))
aRadix=kRadix16;
cp++; //move back by one
break;
}
}
if(cp>aString.mStr)
aString.Cut(0,cp-aString.mStr);
PRInt32 result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK;
return result;
}
@@ -726,11 +735,12 @@ PRUint32 nsCString::DetermineRadix(void) {
PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
//copy chars to local buffer -- step down from 2 bytes to 1 if necessary...
PRInt32 result=0;
nsCAutoString theString(*this);
PRUint32 theRadix=aRadix;
PRInt32 result=0;
*anErrorCode=GetNumericSubstring(theString,theRadix); //we actually don't use this radix; use given radix instead
if(NS_OK==*anErrorCode){
if(kAutoDetect==aRadix)
aRadix=theRadix;
@@ -755,13 +765,13 @@ PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
*/
nsCString& nsCString::Assign(const nsStr& aString,PRInt32 aCount) {
if(this!=&aString){
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
if(aCount<0)
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
nsStr::Assign(*this,aString,0,aCount,mAgent);
nsStr::Assign(*this,aString,0,aCount);
}
return *this;
}
@@ -773,7 +783,7 @@ nsCString& nsCString::Assign(const nsStr& aString,PRInt32 aCount) {
* @return this
*/
nsCString& nsCString::Assign(const char* aCString,PRInt32 aCount) {
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
if(aCString){
Append(aCString,aCount);
}
@@ -787,7 +797,7 @@ nsCString& nsCString::Assign(const char* aCString,PRInt32 aCount) {
* @return this
*/
nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) {
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
if(aString){
nsStr temp;
@@ -806,7 +816,7 @@ nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) {
else aCount=temp.mLength=nsCRT::strlen(aString);
if(0<aCount)
nsStr::Append(*this,temp,0,aCount,mAgent);
nsStr::Append(*this,temp,0,aCount);
}
return *this;
}
@@ -818,7 +828,7 @@ nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) {
* @return this
*/
nsCString& nsCString::Assign(PRUnichar aChar) {
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
return Append(aChar);
}
@@ -829,7 +839,7 @@ nsCString& nsCString::Assign(PRUnichar aChar) {
* @return this
*/
nsCString& nsCString::Assign(char aChar) {
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
return Append(aChar);
}
@@ -864,7 +874,24 @@ nsCString& nsCString::Append(const nsCString& aString,PRInt32 aCount) {
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
if(0<aCount)
nsStr::Append(*this,aString,0,aCount,mAgent);
nsStr::Append(*this,aString,0,aCount);
return *this;
}
/**
* append given string to this string;
* @update gess 01/04/99
* @param aString : string to be appended to this
* @return this
*/
nsCString& nsCString::Append(const nsStr& aString,PRInt32 aCount) {
if(aCount<0)
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
if(0<aCount)
nsStr::Append(*this,aString,0,aCount);
return *this;
}
@@ -893,7 +920,7 @@ nsCString& nsCString::Append(const char* aCString,PRInt32 aCount) {
else aCount=temp.mLength=nsCRT::strlen(aCString);
if(0<aCount)
nsStr::Append(*this,temp,0,aCount,mAgent);
nsStr::Append(*this,temp,0,aCount);
}
return *this;
}
@@ -913,7 +940,7 @@ nsCString& nsCString::Append(PRUnichar aChar) {
Initialize(temp,eTwoByte);
temp.mUStr=buf;
temp.mLength=1;
nsStr::Append(*this,temp,0,1,mAgent);
nsStr::Append(*this,temp,0,1);
return *this;
}
@@ -931,7 +958,7 @@ nsCString& nsCString::Append(char aChar) {
Initialize(temp,eOneByte);
temp.mStr=buf;
temp.mLength=1;
nsStr::Append(*this,temp,0,1,mAgent);
nsStr::Append(*this,temp,0,1);
return *this;
}
@@ -962,12 +989,12 @@ nsCString& nsCString::Append(PRInt32 anInteger,PRInt32 aRadix) {
PRBool isfirst=PR_TRUE;
while(mask1>=1) {
PRInt32 div=theInt/mask1;
if((div) || (!isfirst)) {
buf[charpos++]="0123456789abcdef"[div];
PRInt32 theDiv=theInt/mask1;
if((theDiv) || (!isfirst)) {
buf[charpos++]="0123456789abcdef"[theDiv];
isfirst=PR_FALSE;
}
theInt-=div*mask1;
theInt-=theDiv*mask1;
mask1/=aRadix;
}
return Append(buf);
@@ -1001,7 +1028,7 @@ PRUint32 nsCString::Left(nsCString& aDest,PRInt32 aCount) const{
if(aCount<0)
aCount=mLength;
else aCount=MinInt(aCount,mLength);
nsStr::Assign(aDest,*this,0,aCount,mAgent);
nsStr::Assign(aDest,*this,0,aCount);
return aDest.mLength;
}
@@ -1018,7 +1045,7 @@ PRUint32 nsCString::Mid(nsCString& aDest,PRUint32 anOffset,PRInt32 aCount) const
if(aCount<0)
aCount=mLength;
else aCount=MinInt(aCount,mLength);
nsStr::Assign(aDest,*this,anOffset,aCount,mAgent);
nsStr::Assign(aDest,*this,anOffset,aCount);
return aDest.mLength;
}
@@ -1048,7 +1075,7 @@ PRUint32 nsCString::Right(nsCString& aDest,PRInt32 aCount) const{
*/
nsCString& nsCString::Insert(const nsCString& aString,PRUint32 anOffset,PRInt32 aCount) {
nsStr::Insert(*this,anOffset,aString,0,aCount,mAgent);
nsStr::Insert(*this,anOffset,aString,0,aCount);
return *this;
}
@@ -1079,7 +1106,7 @@ nsCString& nsCString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCou
else aCount=temp.mLength=nsCRT::strlen(aCString);
if(temp.mLength && (0<aCount)){
nsStr::Insert(*this,anOffset,temp,0,aCount,0);
nsStr::Insert(*this,anOffset,temp,0,aCount);
}
}
return *this;
@@ -1101,7 +1128,7 @@ nsCString& nsCString::Insert(PRUnichar aChar,PRUint32 anOffset){
nsStr::Initialize(temp,eTwoByte);
temp.mUStr=theBuffer;
temp.mLength=1;
nsStr::Insert(*this,anOffset,temp,0,1,0);
nsStr::Insert(*this,anOffset,temp,0,1);
return *this;
}
@@ -1121,7 +1148,7 @@ nsCString& nsCString::Insert(char aChar,PRUint32 anOffset){
nsStr::Initialize(temp,eOneByte);
temp.mStr=theBuffer;
temp.mLength=1;
nsStr::Insert(*this,anOffset,temp,0,1,0);
nsStr::Insert(*this,anOffset,temp,0,1);
return *this;
}
@@ -1136,7 +1163,7 @@ nsCString& nsCString::Insert(char aChar,PRUint32 anOffset){
*/
nsCString& nsCString::Cut(PRUint32 anOffset, PRInt32 aCount) {
if(0<aCount) {
nsStr::Delete(*this,anOffset,aCount,mAgent);
nsStr::Delete(*this,anOffset,aCount);
}
return *this;
}
@@ -1560,10 +1587,8 @@ PRBool nsCString::Equals(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 aCo
class nsCStringDeallocator: public nsDequeFunctor{
public:
virtual void* operator()(void* anObject) {
static nsMemoryAgent theAgent;
nsCString* aString= (nsCString*)anObject;
if(aString){
aString->mAgent=&theAgent;
delete aString;
}
return 0;
@@ -1722,7 +1747,6 @@ NS_COM int fputs(const nsCString& aString, FILE* out)
*/
nsCAutoString::nsCAutoString() : nsCString(){
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
mAgent=0;
AddNullTerminator(*this);
}
@@ -1732,7 +1756,6 @@ nsCAutoString::nsCAutoString() : nsCString(){
*/
nsCAutoString::nsCAutoString(const nsCAutoString& aString) : nsCString() {
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
mAgent=0;
AddNullTerminator(*this);
Append(aString);
}
@@ -1744,7 +1767,6 @@ nsCAutoString::nsCAutoString(const nsCAutoString& aString) : nsCString() {
*/
nsCAutoString::nsCAutoString(const char* aCString,PRInt32 aLength) : nsCString() {
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
mAgent=0;
AddNullTerminator(*this);
Append(aCString,aLength);
}
@@ -1754,7 +1776,6 @@ nsCAutoString::nsCAutoString(const char* aCString,PRInt32 aLength) : nsCString()
* @param aBuffer -- descibes external buffer
*/
nsCAutoString::nsCAutoString(const CBufDescriptor& aBuffer) : nsCString() {
mAgent=0;
if(!aBuffer.mBuffer) {
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
}
@@ -1770,7 +1791,6 @@ nsCAutoString::nsCAutoString(const CBufDescriptor& aBuffer) : nsCString() {
* @param aString is a ptr to a unistr
*/
nsCAutoString::nsCAutoString(const PRUnichar* aString,PRInt32 aLength) : nsCString() {
mAgent=0;
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
AddNullTerminator(*this);
Append(aString,aLength);
@@ -1781,7 +1801,6 @@ nsCAutoString::nsCAutoString(const PRUnichar* aString,PRInt32 aLength) : nsCStri
* @param
*/
nsCAutoString::nsCAutoString(const nsStr& aString) : nsCString() {
mAgent=0;
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
AddNullTerminator(*this);
Append(aString);
@@ -1794,7 +1813,6 @@ nsCAutoString::nsCAutoString(const nsStr& aString) : nsCString() {
* @param
*/
nsCAutoString::nsCAutoString(PRUnichar aChar) : nsCString(){
mAgent=0;
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
AddNullTerminator(*this);
Append(aChar);
@@ -1807,12 +1825,10 @@ nsCAutoString::nsCAutoString(PRUnichar aChar) : nsCString(){
*/
#ifdef AIX
nsCAutoString::nsCAutoString(const nsSubsumeCStr& aSubsumeStr) :nsCString() {
mAgent=0;
nsSubsumeCStr temp(aSubsumeStr); // a temp is needed for the AIX compiler
CSubsume(*this,temp);
#else
nsCAutoString::nsCAutoString( nsSubsumeCStr& aSubsumeStr) :nsCString() {
mAgent=0;
CSubsume(*this,aSubsumeStr);
#endif // AIX
}

File diff suppressed because it is too large Load Diff

View File

@@ -38,7 +38,7 @@ static const char* kWhitespace="\b\t\r\n ";
static void Subsume(nsStr& aDest,nsStr& aSource){
if(aSource.mStr && aSource.mLength) {
if(aSource.mOwnsBuffer){
nsStr::Destroy(aDest,0);
nsStr::Destroy(aDest);
aDest.mStr=aSource.mStr;
aDest.mLength=aSource.mLength;
aDest.mCharSize=aSource.mCharSize;
@@ -48,17 +48,17 @@ static void Subsume(nsStr& aDest,nsStr& aSource){
aSource.mStr=0;
}
else{
nsStr::Assign(aDest,aSource,0,aSource.mLength,0);
nsStr::Assign(aDest,aSource,0,aSource.mLength);
}
}
else nsStr::Truncate(aDest,0,0);
else nsStr::Truncate(aDest,0);
}
/**
* Default constructor.
*/
nsString::nsString(nsIMemoryAgent* anAgent) : mAgent(anAgent) {
nsString::nsString() {
nsStr::Initialize(*this,eTwoByte);
}
@@ -68,7 +68,7 @@ nsString::nsString(nsIMemoryAgent* anAgent) : mAgent(anAgent) {
* @param aCString is a ptr to a 1-byte cstr
* @param aLength tells us how many chars to copy from given CString
*/
nsString::nsString(const char* aCString,nsIMemoryAgent* anAgent) : mAgent(anAgent) {
nsString::nsString(const char* aCString){
nsStr::Initialize(*this,eTwoByte);
Assign(aCString);
}
@@ -79,7 +79,7 @@ nsString::nsString(const char* aCString,nsIMemoryAgent* anAgent) : mAgent(anAgen
* @param aString is a ptr to a unichar string
* @param aLength tells us how many chars to copy from given aString
*/
nsString::nsString(const PRUnichar* aString,nsIMemoryAgent* anAgent) : mAgent(anAgent) {
nsString::nsString(const PRUnichar* aString) {
nsStr::Initialize(*this,eTwoByte);
Assign(aString);
}
@@ -89,9 +89,9 @@ nsString::nsString(const PRUnichar* aString,nsIMemoryAgent* anAgent) : mAgent(an
* @update gess 1/4/99
* @param reference to another nsCString
*/
nsString::nsString(const nsStr &aString,nsIMemoryAgent* anAgent) : mAgent(anAgent) {
nsString::nsString(const nsStr &aString) {
nsStr::Initialize(*this,eTwoByte);
nsStr::Assign(*this,aString,0,aString.mLength,mAgent);
nsStr::Assign(*this,aString,0,aString.mLength);
}
/**
@@ -99,9 +99,9 @@ nsString::nsString(const nsStr &aString,nsIMemoryAgent* anAgent) : mAgent(anAgen
* @update gess 1/4/99
* @param reference to another nsString
*/
nsString::nsString(const nsString& aString) :mAgent(aString.mAgent) {
nsString::nsString(const nsString& aString) {
nsStr::Initialize(*this,eTwoByte);
nsStr::Assign(*this,aString,0,aString.mLength,mAgent);
nsStr::Assign(*this,aString,0,aString.mLength);
}
/**
@@ -109,7 +109,7 @@ nsString::nsString(const nsString& aString) :mAgent(aString.mAgent) {
* @update gess 1/4/99
* @param reference to a subsumeString
*/
nsString::nsString(nsSubsumeStr& aSubsumeStr) :mAgent(0) {
nsString::nsString(nsSubsumeStr& aSubsumeStr) {
nsStr::Initialize(*this,eTwoByte);
Subsume(*this,aSubsumeStr);
}
@@ -119,7 +119,7 @@ nsString::nsString(nsSubsumeStr& aSubsumeStr) :mAgent(0) {
* Make sure we call nsStr::Destroy.
*/
nsString::~nsString() {
nsStr::Destroy(*this,mAgent);
nsStr::Destroy(*this);
}
void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
@@ -136,7 +136,7 @@ void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
* @return nada
*/
void nsString::Truncate(PRInt32 anIndex) {
nsStr::Truncate(*this,anIndex,mAgent);
nsStr::Truncate(*this,anIndex);
}
/**
@@ -173,7 +173,7 @@ PRBool nsString::IsOrdered(void) const {
*/
void nsString::SetCapacity(PRUint32 aLength) {
if(aLength>mCapacity) {
GrowCapacity(*this,aLength,mAgent);
GrowCapacity(*this,aLength);
}
AddNullTerminator(*this);
}
@@ -270,7 +270,7 @@ PRBool nsString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
*/
nsSubsumeStr nsString::operator+(const nsStr& aString){
nsString temp(*this); //make a temp string the same size as this...
nsStr::Append(temp,aString,0,aString.mLength,mAgent);
nsStr::Append(temp,aString,0,aString.mLength);
return nsSubsumeStr(temp);
}
@@ -282,7 +282,7 @@ nsSubsumeStr nsString::operator+(const nsStr& aString){
*/
nsSubsumeStr nsString::operator+(const nsString& aString){
nsString temp(*this); //make a temp string the same size as this...
nsStr::Append(temp,aString,0,aString.mLength,mAgent);
nsStr::Append(temp,aString,0,aString.mLength);
return nsSubsumeStr(temp);
}
@@ -786,54 +786,55 @@ static PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadi
* @return non-zero error code if this string is non-numeric
*/
static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) {
static const char* validChars="0123456789abcdefABCDEF-+#";
aString.ToUpperCase();
const char* cp=aString.GetBuffer();
PRInt32 result=NS_ERROR_ILLEGAL_VALUE;
if(cp) {
PRInt32 decPt=nsStr::FindChar(aString,'.',PR_TRUE,0);
char* cp = (kNotFound==decPt) ? aString.mStr + aString.mLength-1 : aString.mStr+decPt-1;
aRadix=kRadixUnknown; //assume for starters...
//begin by skipping over leading chars that shouldn't be part of the number...
char* to=(char*)cp;
const char* endcp=cp+aString.mLength;
int len=strlen(validChars);
// Skip trailing non-numeric...
while (cp >= aString.mStr) {
if((*cp>='0') && (*cp<='9')){
if(kRadixUnknown==aRadix)
aRadix=kRadix10;
break;
while(cp<endcp){
const char* pos=(const char*)memchr(validChars,*cp,len);
if(!pos) {
cp++;
}
else break;
}
else if((*cp>='A') && (*cp<='F')) {
aRadix=16;
break;
}
cp--;
while(cp<endcp){
char theChar=toupper(*cp);
if((theChar>='0') && (theChar<='9')) {
*to++=theChar;
}
else if((theChar>='A') && (theChar<='F')) {
aRadix=16;
*to++=theChar;
}
else if('X'==theChar){
if('-'==aString.mStr[0])
to=&aString.mStr[1];
else to=aString.mStr;
aRadix=16;
//root=cp;
}
else if('-'==theChar) {
*to++=theChar;
}
else if(('#'==theChar) || ('+'==theChar)){
//just skip this char...
}
else break;
cp++;
}
aString.Truncate(to-aString.mStr);
result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK;
}
aString.Truncate(cp-aString.mStr+1);
//ok, now scan through chars until you find the start of this number...
//we delimit the number by the presence of: +,-,#,X
// Skip trailing non-numeric...
cp++;
while (--cp >= aString.mStr) {
if((*cp>='0') && (*cp<='9')){
continue;
}
else if((*cp>='A') && (*cp<='F')) {
continue;
}
else if((*cp=='-') || (*cp=='+')){
break;
}
else {
if(('#'==(*cp)) || ('X'==(*cp)))
aRadix=kRadix16;
cp++; //move back by one
break;
}
}
if(cp>aString.mStr)
aString.Cut(0,cp-aString.mStr);
PRInt32 result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK;
return result;
}
@@ -865,10 +866,10 @@ PRUint32 nsString::DetermineRadix(void) {
PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
//copy chars to local buffer -- step down from 2 bytes to 1 if necessary...
PRInt32 result=0;
nsCAutoString theString(*this);
PRUint32 theRadix=aRadix;
PRInt32 result=0;
*anErrorCode=GetNumericSubstring(theString,theRadix); //we actually don't use this radix; use given radix instead
if(NS_OK==*anErrorCode){
if(kAutoDetect==aRadix)
@@ -893,13 +894,13 @@ PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
*/
nsString& nsString::Assign(const nsStr& aString,PRInt32 aCount) {
if(this!=&aString){
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
if(aCount<0)
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
nsStr::Assign(*this,aString,0,aCount,mAgent);
nsStr::Assign(*this,aString,0,aCount);
}
return *this;
}
@@ -912,7 +913,7 @@ nsString& nsString::Assign(const nsStr& aString,PRInt32 aCount) {
* @return this
*/
nsString& nsString::Assign(const char* aCString,PRInt32 aCount) {
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
if(aCString){
Append(aCString,aCount);
}
@@ -926,7 +927,7 @@ nsString& nsString::Assign(const char* aCString,PRInt32 aCount) {
* @return this
*/
nsString& nsString::Assign(const PRUnichar* aString,PRInt32 aCount) {
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
if(aString){
Append(aString,aCount);
}
@@ -940,7 +941,7 @@ nsString& nsString::Assign(const PRUnichar* aString,PRInt32 aCount) {
* @return this
*/
nsString& nsString::Assign(char aChar) {
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
return Append(aChar);
}
@@ -951,7 +952,7 @@ nsString& nsString::Assign(char aChar) {
* @return this
*/
nsString& nsString::Assign(PRUnichar aChar) {
nsStr::Truncate(*this,0,0);
nsStr::Truncate(*this,0);
return Append(aChar);
}
@@ -988,7 +989,7 @@ nsString& nsString::Append(const nsStr& aString,PRInt32 aCount) {
else aCount=MinInt(aCount,aString.mLength);
if(0<aCount)
nsStr::Append(*this,aString,0,aCount,mAgent);
nsStr::Append(*this,aString,0,aCount);
return *this;
}
@@ -1005,7 +1006,7 @@ nsString& nsString::Append(const nsString& aString,PRInt32 aCount) {
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
if(0<aCount)
nsStr::Append(*this,aString,0,aCount,mAgent);
nsStr::Append(*this,aString,0,aCount);
return *this;
}
@@ -1034,7 +1035,7 @@ nsString& nsString::Append(const char* aCString,PRInt32 aCount) {
else aCount=temp.mLength=nsCRT::strlen(aCString);
if(0<aCount)
nsStr::Append(*this,temp,0,aCount,mAgent);
nsStr::Append(*this,temp,0,aCount);
}
return *this;
}
@@ -1064,7 +1065,7 @@ nsString& nsString::Append(const PRUnichar* aString,PRInt32 aCount) {
else aCount=temp.mLength=nsCRT::strlen(aString);
if(0<aCount)
nsStr::Append(*this,temp,0,aCount,mAgent);
nsStr::Append(*this,temp,0,aCount);
}
return *this;
}
@@ -1083,7 +1084,7 @@ nsString& nsString::Append(char aChar) {
Initialize(temp,eOneByte);
temp.mStr=buf;
temp.mLength=1;
nsStr::Append(*this,temp,0,1,mAgent);
nsStr::Append(*this,temp,0,1);
return *this;
}
@@ -1101,7 +1102,7 @@ nsString& nsString::Append(PRUnichar aChar) {
Initialize(temp,eTwoByte);
temp.mUStr=buf;
temp.mLength=1;
nsStr::Append(*this,temp,0,1,mAgent);
nsStr::Append(*this,temp,0,1);
return *this;
}
@@ -1132,12 +1133,12 @@ nsString& nsString::Append(PRInt32 anInteger,PRInt32 aRadix) {
PRBool isfirst=PR_TRUE;
while(mask1>=1) {
PRInt32 div=theInt/mask1;
if((div) || (!isfirst)) {
buf[charpos++]="0123456789abcdef"[div];
PRInt32 theDiv=theInt/mask1;
if((theDiv) || (!isfirst)) {
buf[charpos++]="0123456789abcdef"[theDiv];
isfirst=PR_FALSE;
}
theInt-=div*mask1;
theInt-=theDiv*mask1;
mask1/=aRadix;
}
return Append(buf);
@@ -1173,7 +1174,7 @@ PRUint32 nsString::Left(nsString& aDest,PRInt32 aCount) const{
if(aCount<0)
aCount=mLength;
else aCount=MinInt(aCount,mLength);
nsStr::Assign(aDest,*this,0,aCount,mAgent);
nsStr::Assign(aDest,*this,0,aCount);
return aDest.mLength;
}
@@ -1191,7 +1192,7 @@ PRUint32 nsString::Mid(nsString& aDest,PRUint32 anOffset,PRInt32 aCount) const{
if(aCount<0)
aCount=mLength;
else aCount=MinInt(aCount,mLength);
nsStr::Assign(aDest,*this,anOffset,aCount,mAgent);
nsStr::Assign(aDest,*this,anOffset,aCount);
return aDest.mLength;
}
@@ -1221,7 +1222,7 @@ PRUint32 nsString::Right(nsString& aDest,PRInt32 aCount) const{
* @return this
*/
nsString& nsString::Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) {
nsStr::Insert(*this,anOffset,aCopy,0,aCount,mAgent);
nsStr::Insert(*this,anOffset,aCopy,0,aCount);
return *this;
}
@@ -1252,7 +1253,7 @@ nsString& nsString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCount
else aCount=temp.mLength=nsCRT::strlen(aCString);
if(0<aCount){
nsStr::Insert(*this,anOffset,temp,0,aCount,0);
nsStr::Insert(*this,anOffset,temp,0,aCount);
}
}
return *this;
@@ -1285,7 +1286,7 @@ nsString& nsString::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32 aC
else aCount=temp.mLength=nsCRT::strlen(aString);
if(0<aCount){
nsStr::Insert(*this,anOffset,temp,0,aCount,0);
nsStr::Insert(*this,anOffset,temp,0,aCount);
}
}
return *this;
@@ -1308,7 +1309,7 @@ nsString& nsString::Insert(PRUnichar aChar,PRUint32 anOffset){
nsStr::Initialize(temp,eTwoByte);
temp.mUStr=theBuffer;
temp.mLength=1;
nsStr::Insert(*this,anOffset,temp,0,1,0);
nsStr::Insert(*this,anOffset,temp,0,1);
return *this;
}
@@ -1323,7 +1324,7 @@ nsString& nsString::Insert(PRUnichar aChar,PRUint32 anOffset){
*/
nsString& nsString::Cut(PRUint32 anOffset, PRInt32 aCount) {
if(0<aCount) {
nsStr::Delete(*this,anOffset,aCount,mAgent);
nsStr::Delete(*this,anOffset,aCount);
}
return *this;
}
@@ -1957,10 +1958,8 @@ PRBool nsString::IsDigit(PRUnichar aChar) {
class nsStringDeallocator: public nsDequeFunctor{
public:
virtual void* operator()(void* anObject) {
static nsMemoryAgent theAgent;
nsString* aString= (nsString*)anObject;
if(aString){
aString->mAgent=&theAgent;
delete aString;
}
return 0;
@@ -2116,7 +2115,6 @@ NS_COM int fputs(const nsString& aString, FILE* out)
*/
nsAutoString::nsAutoString() : nsString() {
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
mAgent=0;
AddNullTerminator(*this);
}
@@ -2127,7 +2125,6 @@ nsAutoString::nsAutoString() : nsString() {
*/
nsAutoString::nsAutoString(const char* aCString,PRInt32 aLength) : nsString() {
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
mAgent=0;
AddNullTerminator(*this);
Append(aCString,aLength);
}
@@ -2138,7 +2135,6 @@ nsAutoString::nsAutoString(const char* aCString,PRInt32 aLength) : nsString() {
* @param aLength tells us how many chars to copy from aString
*/
nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString() {
mAgent=0;
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
AddNullTerminator(*this);
Append(aString,aLength);
@@ -2149,7 +2145,6 @@ nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString(
* @param aBuffer describes the external buffer
*/
nsAutoString::nsAutoString(const CBufDescriptor& aBuffer) : nsString() {
mAgent=0;
if(!aBuffer.mBuffer) {
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
}
@@ -2166,7 +2161,6 @@ nsAutoString::nsAutoString(const CBufDescriptor& aBuffer) : nsString() {
* @param
*/
nsAutoString::nsAutoString(const nsStr& aString) : nsString() {
mAgent=0;
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
AddNullTerminator(*this);
Append(aString);
@@ -2176,7 +2170,6 @@ nsAutoString::nsAutoString(const nsStr& aString) : nsString() {
* Default copy constructor
*/
nsAutoString::nsAutoString(const nsAutoString& aString) : nsString() {
mAgent=0;
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
AddNullTerminator(*this);
Append(aString);
@@ -2188,7 +2181,6 @@ nsAutoString::nsAutoString(const nsAutoString& aString) : nsString() {
* @param
*/
nsAutoString::nsAutoString(PRUnichar aChar) : nsString(){
mAgent=0;
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
AddNullTerminator(*this);
Append(aChar);
@@ -2201,12 +2193,10 @@ nsAutoString::nsAutoString(PRUnichar aChar) : nsString(){
*/
#ifdef AIX
nsAutoString::nsAutoString(const nsSubsumeStr& aSubsumeStr) :nsString() {
mAgent=0;
nsSubsumeStr temp(aSubsumeStr); // a temp is needed for the AIX compiler
Subsume(*this,temp);
#else
nsAutoString::nsAutoString( nsSubsumeStr& aSubsumeStr) :nsString() {
mAgent=0;
Subsume(*this,aSubsumeStr);
#endif // AIX
}

File diff suppressed because it is too large Load Diff