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;
//begin by skipping over leading chars that shouldn't be part of the number...
aRadix=kRadixUnknown; //assume for starters...
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;
}
else if((*cp>='A') && (*cp<='F')) {
aRadix=16;
break;
}
cp--;
}
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...
while(cp<endcp){
const char* pos=(const char*)memchr(validChars,*cp,len);
if(!pos) {
cp++;
while (--cp >= aString.mStr) {
if((*cp>='0') && (*cp<='9')){
continue;
}
else if((*cp>='A') && (*cp<='F')) {
continue;
else break;
}
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;
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;
}
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
}

View File

@@ -46,214 +46,217 @@ class NS_COM nsSubsumeCStr;
class NS_COM nsCString : public nsStr {
public:
public:
/**
/**
* Default constructor.
*/
nsCString(nsIMemoryAgent* anAgent=0);
nsCString();
/**
/**
* This constructor accepts an isolatin string
* @param aCString is a ptr to a 1-byte cstr
*/
nsCString(const char* aCString,PRInt32 aLength=-1,nsIMemoryAgent* anAgent=0);
nsCString(const char* aCString,PRInt32 aLength=-1);
/**
/**
* This constructor accepts a unichar string
* @param aCString is a ptr to a 2-byte cstr
*/
nsCString(const PRUnichar* aString,PRInt32 aLength=-1,nsIMemoryAgent* anAgent=0);
nsCString(const PRUnichar* aString,PRInt32 aLength=-1);
/**
/**
* This is a copy constructor that accepts an nsStr
* @param reference to another nsCString
*/
nsCString(const nsStr&,nsIMemoryAgent* anAgent=0);
nsCString(const nsStr&);
/**
/**
* This is our copy constructor
* @param reference to another nsCString
*/
nsCString(const nsCString& aString);
nsCString(const nsCString& aString);
/**
/**
* This constructor takes a subsumestr
* @param reference to subsumestr
*/
nsCString(nsSubsumeCStr& aSubsumeStr);
nsCString(nsSubsumeCStr& aSubsumeStr);
/**
/**
* Destructor
*
*/
virtual ~nsCString();
virtual ~nsCString();
/**
/**
* Retrieve the length of this string
* @return string length
*/
inline PRInt32 Length() const { return (PRInt32)mLength; }
inline PRInt32 Length() const { return (PRInt32)mLength; }
/**
/**
* Retrieve the size of this string
* @return string length
*/
virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
/**
/**
* Call this method if you want to force a different string capacity
* @update gess7/30/98
* @param aLength -- contains new length for mStr
* @return
*/
void SetLength(PRUint32 aLength) {
void SetLength(PRUint32 aLength) {
Truncate(aLength);
}
}
/**
/**
* Sets the new length of the string.
* @param aLength is new string length.
* @return nada
*/
void SetCapacity(PRUint32 aLength);
/**
void SetCapacity(PRUint32 aLength);
/**
* This method truncates this string to given length.
*
* @param anIndex -- new length of string
* @return nada
*/
void Truncate(PRInt32 anIndex=0);
void Truncate(PRInt32 anIndex=0);
/**
/**
* Determine whether or not the characters in this
* string are in sorted order.
*
* @return TRUE if ordered.
*/
PRBool IsOrdered(void) const;
PRBool IsOrdered(void) const;
/**
/**
* Determine whether or not this string has a length of 0
*
* @return TRUE if empty.
*/
PRBool IsEmpty(void) const {
PRBool IsEmpty(void) const {
return PRBool(0==mLength);
}
}
/**********************************************************************
/**********************************************************************
Accessor methods...
*********************************************************************/
const char* GetBuffer(void) const;
/**
* Retrieve const ptr to internal buffer; DO NOT TRY TO FREE IT!
*/
const char* GetBuffer(void) const;
/**
* Get nth character.
*/
PRUnichar operator[](PRUint32 anIndex) const;
PRUnichar CharAt(PRUint32 anIndex) const;
PRUnichar First(void) const;
PRUnichar Last(void) const;
PRUnichar operator[](PRUint32 anIndex) const;
PRUnichar CharAt(PRUint32 anIndex) const;
PRUnichar First(void) const;
PRUnichar Last(void) const;
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
/**********************************************************************
/**********************************************************************
String creation methods...
*********************************************************************/
/**
/**
* Create a new string by appending given string to this
* @param aString -- 2nd string to be appended
* @return new string
*/
nsSubsumeCStr operator+(const nsCString& aString);
nsSubsumeCStr operator+(const nsCString& aString);
/**
/**
* create a new string by adding this to the given char*.
* @param aCString is a ptr to cstring to be added to this
* @return newly created string
*/
nsSubsumeCStr operator+(const char* aCString);
nsSubsumeCStr operator+(const char* aCString);
/**
/**
* create a new string by adding this to the given char.
* @param aChar is a char to be added to this
* @return newly created string
*/
nsSubsumeCStr operator+(PRUnichar aChar);
nsSubsumeCStr operator+(char aChar);
nsSubsumeCStr operator+(PRUnichar aChar);
nsSubsumeCStr operator+(char aChar);
/**********************************************************************
/**********************************************************************
Lexomorphic transforms...
*********************************************************************/
/**
/**
* Converts chars in this to lowercase
* @update gess 7/27/98
*/
void ToLowerCase();
void ToLowerCase();
/**
/**
* Converts chars in this to lowercase, and
* stores them in aOut
* @update gess 7/27/98
* @param aOut is a string to contain result
*/
void ToLowerCase(nsCString& aString) const;
void ToLowerCase(nsCString& aString) const;
/**
/**
* Converts chars in this to uppercase
* @update gess 7/27/98
*/
void ToUpperCase();
void ToUpperCase();
/**
/**
* Converts chars in this to lowercase, and
* stores them in a given output string
* @update gess 7/27/98
* @param aOut is a string to contain result
*/
void ToUpperCase(nsCString& aString) const;
void ToUpperCase(nsCString& aString) const;
/**
/**
* This method is used to remove all occurances of the
* characters found in aSet from this string.
*
* @param aSet -- characters to be cut from this
* @return *this
*/
nsCString& StripChars(const char* aSet);
nsCString& StripChar(char aChar);
nsCString& StripChars(const char* aSet);
nsCString& StripChar(char aChar);
/**
/**
* This method strips whitespace throughout the string
*
* @return this
*/
nsCString& StripWhitespace();
nsCString& StripWhitespace();
/**
/**
* swaps occurence of 1 string for another
*
* @return this
*/
nsCString& ReplaceChar(PRUnichar aOldChar,PRUnichar aNewChar);
nsCString& ReplaceChar(const char* aSet,PRUnichar aNewChar);
nsCString& ReplaceChar(PRUnichar aOldChar,PRUnichar aNewChar);
nsCString& ReplaceChar(const char* aSet,PRUnichar aNewChar);
PRInt32 CountChar(PRUnichar aChar);
PRInt32 CountChar(PRUnichar aChar);
/**
/**
* This method trims characters found in aTrimSet from
* either end of the underlying string.
*
@@ -261,9 +264,9 @@ PRInt32 CountChar(PRUnichar aChar);
* both ends
* @return this
*/
nsCString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
nsCString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/**
/**
* This method strips whitespace from string.
* You can control whether whitespace is yanked from
* start and end of string as well.
@@ -272,9 +275,9 @@ nsCString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aElimin
* @param aEliminateTrailing controls stripping of trailing ws
* @return this
*/
nsCString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
nsCString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/**
/**
* This method strips whitespace from string.
* You can control whether whitespace is yanked from
* start and end of string as well.
@@ -283,142 +286,143 @@ nsCString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeadin
* @param aEliminateTrailing controls stripping of trailing ws
* @return this
*/
nsCString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
nsCString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/**********************************************************************
/**********************************************************************
string conversion methods...
*********************************************************************/
operator char*() {return mStr;}
operator const char*() const {return (const char*)mStr;}
/**
/**
* This method constructs a new nsCString that is a clone
* of this string.
*
*/
nsCString* ToNewString() const;
nsCString* ToNewString() const;
/**
/**
* Creates an ISOLatin1 clone of this string
* Note that calls to this method should be matched with calls to Recycle().
* @return ptr to new isolatin1 string
*/
char* ToNewCString() const;
char* ToNewCString() const;
/**
/**
* Creates a unicode clone of this string
* Note that calls to this method should be matched with calls to Recycle().
* @return ptr to new unicode string
*/
PRUnichar* ToNewUnicode() const;
PRUnichar* ToNewUnicode() const;
/**
/**
* Copies data from internal buffer onto given char* buffer
* NOTE: This only copies as many chars as will fit in given buffer (clips)
* @param aBuf is the buffer where data is stored
* @param aBuflength is the max # of chars to move to buffer
* @return ptr to given buffer
*/
char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const;
char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const;
/**
/**
* Perform string to float conversion.
* @param aErrorCode will contain error if one occurs
* @return float rep of string value
*/
float ToFloat(PRInt32* aErrorCode) const;
float ToFloat(PRInt32* aErrorCode) const;
/**
/**
* Try to derive the radix from the value contained in this string
* @return kRadix10, kRadix16 or kAutoDetect (meaning unknown)
*/
PRUint32 DetermineRadix(void);
PRUint32 DetermineRadix(void);
/**
/**
* Perform string to int conversion.
* @param aErrorCode will contain error if one occurs
* @return int rep of string value
*/
PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const;
PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const;
/**********************************************************************
/**********************************************************************
String manipulation methods...
*********************************************************************/
/**
/**
* Functionally equivalent to assign or operator=
*
*/
nsCString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsCString& SetString(const nsStr& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsCString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsCString& SetString(const nsStr& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
/**
/**
* assign given string to this string
* @param aStr: buffer to be assigned to this
* @param alength is the length of the given str (or -1)
if you want me to determine its length
* @return this
*/
nsCString& Assign(const nsStr& aString,PRInt32 aCount=-1);
nsCString& Assign(const char* aString,PRInt32 aCount=-1);
nsCString& Assign(const PRUnichar* aString,PRInt32 aCount=-1);
nsCString& Assign(PRUnichar aChar);
nsCString& Assign(char aChar);
nsCString& Assign(const nsStr& aString,PRInt32 aCount=-1);
nsCString& Assign(const char* aString,PRInt32 aCount=-1);
nsCString& Assign(const PRUnichar* aString,PRInt32 aCount=-1);
nsCString& Assign(PRUnichar aChar);
nsCString& Assign(char aChar);
/**
/**
* here come a bunch of assignment operators...
* @param aString: string to be added to this
* @return this
*/
nsCString& operator=(const nsCString& aString) {return Assign(aString);}
nsCString& operator=(const nsStr& aString) {return Assign(aString);}
nsCString& operator=(PRUnichar aChar) {return Assign(aChar);}
nsCString& operator=(char aChar) {return Assign(aChar);}
nsCString& operator=(const char* aCString) {return Assign(aCString);}
nsCString& operator=(const PRUnichar* aString) {return Assign(aString);}
#ifdef AIX
nsCString& operator=(const nsSubsumeCStr& aSubsumeString); // AIX requires a const here
#else
nsCString& operator=(nsSubsumeCStr& aSubsumeString);
#endif
nsCString& operator=(const nsCString& aString) {return Assign(aString);}
nsCString& operator=(const nsStr& aString) {return Assign(aString);}
nsCString& operator=(PRUnichar aChar) {return Assign(aChar);}
nsCString& operator=(char aChar) {return Assign(aChar);}
nsCString& operator=(const char* aCString) {return Assign(aCString);}
nsCString& operator=(const PRUnichar* aString) {return Assign(aString);}
#ifdef AIX
nsCString& operator=(const nsSubsumeCStr& aSubsumeString); // AIX requires a const here
#else
nsCString& operator=(nsSubsumeCStr& aSubsumeString);
#endif
/**
/**
* Here's a bunch of methods that append varying types...
* @param various...
* @return this
*/
nsCString& operator+=(const nsCString& aString){return Append(aString,aString.mLength);}
nsCString& operator+=(const char* aCString) {return Append(aCString);}
nsCString& operator+=(PRUnichar aChar){return Append(aChar);}
nsCString& operator+=(char aChar){return Append(aChar);}
nsCString& operator+=(const nsCString& aString){return Append(aString,aString.mLength);}
nsCString& operator+=(const char* aCString) {return Append(aCString);}
nsCString& operator+=(PRUnichar aChar){return Append(aChar);}
nsCString& operator+=(char aChar){return Append(aChar);}
/*
/*
* Appends n characters from given string to this,
* This version computes the length of your given string
*
* @param aString is the source to be appended to this
* @return number of chars copied
*/
nsCString& Append(const nsCString& aString) {return Append(aString,aString.mLength);}
nsCString& Append(const nsCString& aString) {return Append(aString,aString.mLength);}
/*
/*
* Appends n characters from given string to this,
*
* @param aString is the source to be appended to this
* @param aCount -- number of chars to copy; -1 tells us to compute the strlen for you
* @return number of chars copied
*/
nsCString& Append(const nsCString& aString,PRInt32 aCount);
nsCString& Append(const char* aString,PRInt32 aCount=-1);
nsCString& Append(PRUnichar aChar);
nsCString& Append(char aChar);
nsCString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16
nsCString& Append(float aFloat);
nsCString& Append(const nsCString& aString,PRInt32 aCount);
nsCString& Append(const nsStr& aString,PRInt32 aCount=-1);
nsCString& Append(const char* aString,PRInt32 aCount=-1);
nsCString& Append(PRUnichar aChar);
nsCString& Append(char aChar);
nsCString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16
nsCString& Append(float aFloat);
/*
/*
* Copies n characters from this string to given string,
* starting at the leftmost offset.
*
@@ -427,9 +431,9 @@ nsCString& Append(float aFloat);
* @param aCount -- number of chars to copy
* @return number of chars copied
*/
PRUint32 Left(nsCString& aCopy,PRInt32 aCount) const;
PRUint32 Left(nsCString& aCopy,PRInt32 aCount) const;
/*
/*
* Copies n characters from this string to given string,
* starting at the given offset.
*
@@ -439,9 +443,9 @@ PRUint32 Left(nsCString& aCopy,PRInt32 aCount) const;
* @param anOffset -- position where copying begins
* @return number of chars copied
*/
PRUint32 Mid(nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
PRUint32 Mid(nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
/*
/*
* Copies n characters from this string to given string,
* starting at rightmost char.
*
@@ -450,9 +454,9 @@ PRUint32 Mid(nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
* @param aCount -- number of chars to copy
* @return number of chars copied
*/
PRUint32 Right(nsCString& aCopy,PRInt32 aCount) const;
PRUint32 Right(nsCString& aCopy,PRInt32 aCount) const;
/*
/*
* This method inserts n chars from given string into this
* string at str[anOffset].
*
@@ -461,9 +465,9 @@ PRUint32 Right(nsCString& aCopy,PRInt32 aCount) const;
* @param aCount -- number of chars to be copied from aCopy
* @return number of chars inserted into this.
*/
nsCString& Insert(const nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
nsCString& Insert(const nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
/**
/**
* Insert a given string into this string at
* a specified offset.
*
@@ -471,9 +475,9 @@ nsCString& Insert(const nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
* @param anOffset is insert pos in str
* @return the number of chars inserted into this string
*/
nsCString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
nsCString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
/**
/**
* Insert a single char into this string at
* a specified offset.
*
@@ -481,10 +485,10 @@ nsCString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
* @param anOffset is insert pos in str
* @return the number of chars inserted into this string
*/
nsCString& Insert(PRUnichar aChar,PRUint32 anOffset);
nsCString& Insert(char aChar,PRUint32 anOffset);
nsCString& Insert(PRUnichar aChar,PRUint32 anOffset);
nsCString& Insert(char aChar,PRUint32 anOffset);
/*
/*
* This method is used to cut characters in this string
* starting at anOffset, continuing for aCount chars.
*
@@ -492,14 +496,14 @@ nsCString& Insert(char aChar,PRUint32 anOffset);
* @param aCount -- number of chars to be cut
* @return *this
*/
nsCString& Cut(PRUint32 anOffset,PRInt32 aCount);
nsCString& Cut(PRUint32 anOffset,PRInt32 aCount);
/**********************************************************************
/**********************************************************************
Searching methods...
*********************************************************************/
/**
/**
* Search for given character within this string.
* This method does so by using a binary search,
* so your string HAD BETTER BE ORDERED!
@@ -507,9 +511,9 @@ nsCString& Cut(PRUint32 anOffset,PRInt32 aCount);
* @param aChar is the unicode char to be found
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 BinarySearch(PRUnichar aChar) const;
PRInt32 BinarySearch(PRUnichar aChar) const;
/**
/**
* Search for given substring within this string
*
* @param aString is substring to be sought in this
@@ -517,11 +521,11 @@ PRInt32 BinarySearch(PRUnichar aChar) const;
* @param anOffset tells us where in this strig to start searching
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
/**
/**
* Search for given char within this string
*
* @param aString is substring to be sought in this
@@ -529,32 +533,32 @@ PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffs
* @param aIgnoreCase selects case sensitivity
* @return find pos in string, or -1 (kNotFound)
*/
PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
/**
/**
* This method searches this string for the first character
* found in the given charset
* @param aString contains set of chars to be found
* @param anOffset tells us where to start searching in this
* @return -1 if not found, else the offset in this
*/
PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
/**
/**
* This methods scans the string backwards, looking for the given string
* @param aString is substring to be sought in this
* @param aIgnoreCase tells us whether or not to do caseless compare
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
/**
/**
* Search for given char within this string
*
* @param aString is substring to be sought in this
@@ -562,26 +566,26 @@ PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOff
* @param aIgnoreCase selects case sensitivity
* @return find pos in string, or -1 (kNotFound)
*/
PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
/**
/**
* This method searches this string for the last character
* found in the given string
* @param aString contains set of chars to be found
* @param anOffset tells us where to start searching in this
* @return -1 if not found, else the offset in this
*/
PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
/**********************************************************************
/**********************************************************************
Comparison methods...
*********************************************************************/
/**
/**
* Compares a given string type to this string.
* @update gess 7/27/98
* @param S is the string to be compared
@@ -589,65 +593,65 @@ PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
* @param aCount tells us how many chars to compare
* @return -1,0,1
*/
virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
/**
/**
* These methods compare a given string type to this one
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator==(const nsStr &aString) const;
PRBool operator==(const char* aString) const;
PRBool operator==(const PRUnichar* aString) const;
PRBool operator==(const nsStr &aString) const;
PRBool operator==(const char* aString) const;
PRBool operator==(const PRUnichar* aString) const;
/**
/**
* These methods perform a !compare of a given string type to this
* @param aString is the string to be compared to this
* @return TRUE
*/
PRBool operator!=(const nsStr &aString) const;
PRBool operator!=(const char* aString) const;
PRBool operator!=(const PRUnichar* aString) const;
PRBool operator!=(const nsStr &aString) const;
PRBool operator!=(const char* aString) const;
PRBool operator!=(const PRUnichar* aString) const;
/**
/**
* These methods test if a given string is < than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator<(const nsStr &aString) const;
PRBool operator<(const char* aString) const;
PRBool operator<(const PRUnichar* aString) const;
PRBool operator<(const nsStr &aString) const;
PRBool operator<(const char* aString) const;
PRBool operator<(const PRUnichar* aString) const;
/**
/**
* These methods test if a given string is > than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator>(const nsStr &S) const;
PRBool operator>(const char* aString) const;
PRBool operator>(const PRUnichar* aString) const;
PRBool operator>(const nsStr &S) const;
PRBool operator>(const char* aString) const;
PRBool operator>(const PRUnichar* aString) const;
/**
/**
* These methods test if a given string is <= than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator<=(const nsStr &S) const;
PRBool operator<=(const char* aString) const;
PRBool operator<=(const PRUnichar* aString) const;
PRBool operator<=(const nsStr &S) const;
PRBool operator<=(const char* aString) const;
PRBool operator<=(const PRUnichar* aString) const;
/**
/**
* These methods test if a given string is >= than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator>=(const nsStr &S) const;
PRBool operator>=(const char* aString) const;
PRBool operator>=(const PRUnichar* aString) const;
PRBool operator>=(const nsStr &S) const;
PRBool operator>=(const char* aString) const;
PRBool operator>=(const PRUnichar* aString) const;
/**
/**
* Compare this to given string; note that we compare full strings here.
* The optional length argument just lets us know how long the given string is.
* If you provide a length, it is compared to length of this string as an
@@ -657,21 +661,18 @@ PRBool operator>=(const PRUnichar* aString) const;
* @param aCount -- number of chars in given string you want to compare
* @return TRUE if equal
*/
PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(const nsStr& aString) const;
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(const nsStr& aString) const;
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const;
static void Recycle(nsCString* aString);
static nsCString* CreateString(void);
nsIMemoryAgent* mAgent;
static void Recycle(nsCString* aString);
static nsCString* CreateString(void);
};

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;
//begin by skipping over leading chars that shouldn't be part of the number...
aRadix=kRadixUnknown; //assume for starters...
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;
}
else if((*cp>='A') && (*cp<='F')) {
aRadix=16;
break;
}
cp--;
}
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...
while(cp<endcp){
const char* pos=(const char*)memchr(validChars,*cp,len);
if(!pos) {
cp++;
while (--cp >= aString.mStr) {
if((*cp>='0') && (*cp<='9')){
continue;
}
else if((*cp>='A') && (*cp<='F')) {
continue;
else break;
}
else if((*cp=='-') || (*cp=='+')){
break;
while(cp<endcp){
char theChar=toupper(*cp);
if((theChar>='0') && (theChar<='9')) {
*to++=theChar;
}
else {
if(('#'==(*cp)) || ('X'==(*cp)))
aRadix=kRadix16;
cp++; //move back by one
break;
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;
}
if(cp>aString.mStr)
aString.Cut(0,cp-aString.mStr);
PRInt32 result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK;
return result;
}
@@ -865,9 +866,9 @@ 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){
@@ -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
}

View File

@@ -53,242 +53,245 @@ class nsISizeOfHandler;
class NS_COM nsSubsumeStr;
class NS_COM nsString : public nsStr {
public:
public:
/**
/**
* Default constructor.
*/
nsString(nsIMemoryAgent* anAgent=0);
nsString();
/**
/**
* This constructor accepts an isolatin string
* @param aCString is a ptr to a 1-byte cstr
*/
nsString(const char* aCString,nsIMemoryAgent* anAgent=0);
nsString(const char* aCString);
/**
/**
* This constructor accepts a unichar string
* @param aCString is a ptr to a 2-byte cstr
*/
nsString(const PRUnichar* aString,nsIMemoryAgent* anAgent=0);
nsString(const PRUnichar* aString);
/**
/**
* This is a copy constructor that accepts an nsStr
* @param reference to another nsString
*/
nsString(const nsStr&,nsIMemoryAgent* anAgent=0);
nsString(const nsStr&);
/**
/**
* This is our copy constructor
* @param reference to another nsString
*/
nsString(const nsString& aString);
nsString(const nsString& aString);
/**
/**
* This constructor takes a subsumestr
* @param reference to subsumestr
*/
nsString(nsSubsumeStr& aSubsumeStr);
nsString(nsSubsumeStr& aSubsumeStr);
/**
/**
* Destructor
*
*/
virtual ~nsString();
virtual ~nsString();
/**
/**
* Retrieve the length of this string
* @return string length
*/
inline PRInt32 Length() const { return (PRInt32)mLength; }
inline PRInt32 Length() const { return (PRInt32)mLength; }
/**
/**
* Retrieve the size of this string
* @return string length
*/
virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
/**
/**
* Call this method if you want to force a different string length
* @update gess7/30/98
* @param aLength -- contains new length for mStr
* @return
*/
void SetLength(PRUint32 aLength) {
void SetLength(PRUint32 aLength) {
Truncate(aLength);
}
}
/**
/**
* Sets the new length of the string.
* @param aLength is new string length.
* @return nada
*/
void SetCapacity(PRUint32 aLength);
void SetCapacity(PRUint32 aLength);
/**
/**
* This method truncates this string to given length.
*
* @param anIndex -- new length of string
* @return nada
*/
void Truncate(PRInt32 anIndex=0);
void Truncate(PRInt32 anIndex=0);
/**
/**
* Determine whether or not the characters in this
* string are in sorted order.
*
* @return TRUE if ordered.
*/
PRBool IsOrdered(void) const;
PRBool IsOrdered(void) const;
/**
/**
* Determine whether or not the characters in this
* string are in store as 1 or 2 byte (unicode) strings.
*
* @return TRUE if ordered.
*/
PRBool IsUnicode(void) const {
PRBool IsUnicode(void) const {
PRBool result=PRBool(mCharSize==eTwoByte);
return result;
}
}
/**
/**
* Determine whether or not this string has a length of 0
*
* @return TRUE if empty.
*/
PRBool IsEmpty(void) const {
PRBool IsEmpty(void) const {
return PRBool(0==mLength);
}
}
/**********************************************************************
/**********************************************************************
Getters/Setters...
*********************************************************************/
const char* GetBuffer(void) const;
const PRUnichar* GetUnicode(void) const;
/**
* Retrieve const ptr to internal buffer; DO NOT TRY TO FREE IT!
*/
const char* GetBuffer(void) const;
const PRUnichar* GetUnicode(void) const;
/**
* Get nth character.
*/
PRUnichar operator[](PRUint32 anIndex) const;
PRUnichar CharAt(PRUint32 anIndex) const;
PRUnichar First(void) const;
PRUnichar Last(void) const;
PRUnichar operator[](PRUint32 anIndex) const;
PRUnichar CharAt(PRUint32 anIndex) const;
PRUnichar First(void) const;
PRUnichar Last(void) const;
/**
* Set nth character.
*/
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
/**********************************************************************
/**********************************************************************
String concatenation methods...
*********************************************************************/
/**
/**
* Create a new string by appending given string to this
* @param aString -- 2nd string to be appended
* @return new subsumable string
*/
nsSubsumeStr operator+(const nsStr& aString);
nsSubsumeStr operator+(const nsString& aString);
nsSubsumeStr operator+(const nsStr& aString);
nsSubsumeStr operator+(const nsString& aString);
/**
/**
* create a new string by adding this to the given cstring
* @param aCString is a ptr to cstring to be added to this
* @return newly created string
*/
nsSubsumeStr operator+(const char* aCString);
nsSubsumeStr operator+(const char* aCString);
/**
/**
* create a new string by adding this to the given prunichar*.
* @param aString is a ptr to UC-string to be added to this
* @return newly created string
*/
nsSubsumeStr operator+(const PRUnichar* aString);
nsSubsumeStr operator+(const PRUnichar* aString);
/**
/**
* create a new string by adding this to the given char.
* @param aChar is a char to be added to this
* @return newly created string
*/
nsSubsumeStr operator+(char aChar);
nsSubsumeStr operator+(char aChar);
/**
/**
* create a new string by adding this to the given char.
* @param aChar is a unichar to be added to this
* @return newly created string
*/
nsSubsumeStr operator+(PRUnichar aChar);
nsSubsumeStr operator+(PRUnichar aChar);
/**********************************************************************
/**********************************************************************
Lexomorphic transforms...
*********************************************************************/
/**
/**
* Converts chars in this to lowercase
* @update gess 7/27/98
*/
void ToLowerCase();
void ToLowerCase();
/**
/**
* Converts chars in this to lowercase, and
* stores them in aOut
* @update gess 7/27/98
* @param aOut is a string to contain result
*/
void ToLowerCase(nsString& aString) const;
void ToLowerCase(nsString& aString) const;
/**
/**
* Converts chars in this to uppercase
* @update gess 7/27/98
*/
void ToUpperCase();
void ToUpperCase();
/**
/**
* Converts chars in this to lowercase, and
* stores them in a given output string
* @update gess 7/27/98
* @param aOut is a string to contain result
*/
void ToUpperCase(nsString& aString) const;
void ToUpperCase(nsString& aString) const;
/**
/**
* This method is used to remove all occurances of the
* characters found in aSet from this string.
*
* @param aSet -- characters to be cut from this
* @return *this
*/
nsString& StripChars(const char* aSet);
nsString& StripChar(char aChar);
nsString& StripChars(const char* aSet);
nsString& StripChar(char aChar);
/**
/**
* This method strips whitespace throughout the string
*
* @return this
*/
nsString& StripWhitespace();
nsString& StripWhitespace();
/**
/**
* swaps occurence of 1 string for another
*
* @return this
*/
nsString& ReplaceChar(PRUnichar anOldChar,PRUnichar aNewChar);
nsString& ReplaceChar(const char* aSet,PRUnichar aNewChar);
nsString& ReplaceChar(PRUnichar anOldChar,PRUnichar aNewChar);
nsString& ReplaceChar(const char* aSet,PRUnichar aNewChar);
PRInt32 CountChar(PRUnichar aChar);
PRInt32 CountChar(PRUnichar aChar);
/**
/**
* This method trims characters found in aTrimSet from
* either end of the underlying string.
*
@@ -296,9 +299,9 @@ PRInt32 CountChar(PRUnichar aChar);
* both ends
* @return this
*/
nsString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
nsString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/**
/**
* This method strips whitespace from string.
* You can control whether whitespace is yanked from
* start and end of string as well.
@@ -307,9 +310,9 @@ nsString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aElimina
* @param aEliminateTrailing controls stripping of trailing ws
* @return this
*/
nsString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
nsString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/**
/**
* This method strips whitespace from string.
* You can control whether whitespace is yanked from
* start and end of string as well.
@@ -318,151 +321,151 @@ nsString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading
* @param aEliminateTrailing controls stripping of trailing ws
* @return this
*/
nsString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
nsString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/**********************************************************************
/**********************************************************************
string conversion methods...
*********************************************************************/
/**
/**
* This method constructs a new nsString is a clone of this string.
*
*/
nsString* ToNewString() const;
nsString* ToNewString() const;
/**
/**
* Creates an ISOLatin1 clone of this string
* Note that calls to this method should be matched with calls to Recycle().
* @return ptr to new isolatin1 string
*/
char* ToNewCString() const;
char* ToNewCString() const;
/**
/**
* Creates an UTF8 clone of this string
* Note that calls to this method should be matched with calls to Recycle().
* @return ptr to new isolatin1 string
*/
char* ToNewUTF8String() const;
char* ToNewUTF8String() const;
/**
/**
* Creates a unicode clone of this string
* Note that calls to this method should be matched with calls to Recycle().
* @return ptr to new unicode string
*/
PRUnichar* ToNewUnicode() const;
PRUnichar* ToNewUnicode() const;
/**
/**
* Copies data from internal buffer onto given char* buffer
* NOTE: This only copies as many chars as will fit in given buffer (clips)
* @param aBuf is the buffer where data is stored
* @param aBuflength is the max # of chars to move to buffer
* @return ptr to given buffer
*/
char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const;
char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const;
/**
/**
* Perform string to float conversion.
* @param aErrorCode will contain error if one occurs
* @return float rep of string value
*/
float ToFloat(PRInt32* aErrorCode) const;
float ToFloat(PRInt32* aErrorCode) const;
/**
/**
* Try to derive the radix from the value contained in this string
* @return kRadix10, kRadix16 or kAutoDetect (meaning unknown)
*/
PRUint32 DetermineRadix(void);
PRUint32 DetermineRadix(void);
/**
/**
* Perform string to int conversion.
* @param aErrorCode will contain error if one occurs
* @return int rep of string value
*/
PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const;
PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const;
/**********************************************************************
/**********************************************************************
String manipulation methods...
*********************************************************************/
/**
/**
* Functionally equivalent to assign or operator=
*
*/
nsString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsString& SetString(const PRUnichar* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsString& SetString(const nsString& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsString& SetString(const PRUnichar* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsString& SetString(const nsString& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
/**
/**
* assign given string to this string
* @param aStr: buffer to be assigned to this
* @param alength is the length of the given str (or -1)
if you want me to determine its length
* @return this
*/
nsString& Assign(const nsStr& aString,PRInt32 aCount=-1);
nsString& Assign(const char* aString,PRInt32 aCount=-1);
nsString& Assign(const PRUnichar* aString,PRInt32 aCount=-1);
nsString& Assign(char aChar);
nsString& Assign(PRUnichar aChar);
nsString& Assign(const nsStr& aString,PRInt32 aCount=-1);
nsString& Assign(const char* aString,PRInt32 aCount=-1);
nsString& Assign(const PRUnichar* aString,PRInt32 aCount=-1);
nsString& Assign(char aChar);
nsString& Assign(PRUnichar aChar);
/**
/**
* here come a bunch of assignment operators...
* @param aString: string to be added to this
* @return this
*/
nsString& operator=(const nsString& aString) {return Assign(aString);}
nsString& operator=(const nsStr& aString) {return Assign(aString);}
nsString& operator=(char aChar) {return Assign(aChar);}
nsString& operator=(PRUnichar aChar) {return Assign(aChar);}
nsString& operator=(const char* aCString) {return Assign(aCString);}
nsString& operator=(const PRUnichar* aString) {return Assign(aString);}
#ifdef AIX
nsString& operator=(const nsSubsumeStr& aSubsumeString); // AIX requires a const here
#else
nsString& operator=(nsSubsumeStr& aSubsumeString);
#endif
nsString& operator=(const nsString& aString) {return Assign(aString);}
nsString& operator=(const nsStr& aString) {return Assign(aString);}
nsString& operator=(char aChar) {return Assign(aChar);}
nsString& operator=(PRUnichar aChar) {return Assign(aChar);}
nsString& operator=(const char* aCString) {return Assign(aCString);}
nsString& operator=(const PRUnichar* aString) {return Assign(aString);}
#ifdef AIX
nsString& operator=(const nsSubsumeStr& aSubsumeString); // AIX requires a const here
#else
nsString& operator=(nsSubsumeStr& aSubsumeString);
#endif
/**
/**
* Here's a bunch of methods that append varying types...
* @param various...
* @return this
*/
nsString& operator+=(const nsStr& aString){return Append(aString,aString.mLength);}
nsString& operator+=(const nsString& aString){return Append(aString,aString.mLength);}
nsString& operator+=(const char* aCString) {return Append(aCString);}
//nsString& operator+=(char aChar){return Append(aChar);}
nsString& operator+=(const PRUnichar* aUCString) {return Append(aUCString);}
nsString& operator+=(PRUnichar aChar){return Append(aChar);}
nsString& operator+=(const nsStr& aString){return Append(aString,aString.mLength);}
nsString& operator+=(const nsString& aString){return Append(aString,aString.mLength);}
nsString& operator+=(const char* aCString) {return Append(aCString);}
//nsString& operator+=(char aChar){return Append(aChar);}
nsString& operator+=(const PRUnichar* aUCString) {return Append(aUCString);}
nsString& operator+=(PRUnichar aChar){return Append(aChar);}
/*
/*
* Appends n characters from given string to this,
* This version computes the length of your given string
*
* @param aString is the source to be appended to this
* @return number of chars copied
*/
nsString& Append(const nsStr& aString) {return Append(aString,aString.mLength);}
nsString& Append(const nsString& aString) {return Append(aString,aString.mLength);}
nsString& Append(const nsStr& aString) {return Append(aString,aString.mLength);}
nsString& Append(const nsString& aString) {return Append(aString,aString.mLength);}
/*
/*
* Appends n characters from given string to this,
*
* @param aString is the source to be appended to this
* @param aCount -- number of chars to copy; -1 tells us to compute the strlen for you
* @return number of chars copied
*/
nsString& Append(const nsStr& aString,PRInt32 aCount);
nsString& Append(const nsString& aString,PRInt32 aCount);
nsString& Append(const char* aString,PRInt32 aCount=-1);
nsString& Append(const PRUnichar* aString,PRInt32 aCount=-1);
nsString& Append(char aChar);
nsString& Append(PRUnichar aChar);
nsString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16
nsString& Append(float aFloat);
nsString& Append(const nsStr& aString,PRInt32 aCount);
nsString& Append(const nsString& aString,PRInt32 aCount);
nsString& Append(const char* aString,PRInt32 aCount=-1);
nsString& Append(const PRUnichar* aString,PRInt32 aCount=-1);
nsString& Append(char aChar);
nsString& Append(PRUnichar aChar);
nsString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16
nsString& Append(float aFloat);
/*
/*
* Copies n characters from this string to given string,
* starting at the leftmost offset.
*
@@ -471,9 +474,9 @@ nsString& Append(float aFloat);
* @param aCount -- number of chars to copy
* @return number of chars copied
*/
PRUint32 Left(nsString& aCopy,PRInt32 aCount) const;
PRUint32 Left(nsString& aCopy,PRInt32 aCount) const;
/*
/*
* Copies n characters from this string to given string,
* starting at the given offset.
*
@@ -483,9 +486,9 @@ PRUint32 Left(nsString& aCopy,PRInt32 aCount) const;
* @param anOffset -- position where copying begins
* @return number of chars copied
*/
PRUint32 Mid(nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
PRUint32 Mid(nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
/*
/*
* Copies n characters from this string to given string,
* starting at rightmost char.
*
@@ -494,9 +497,9 @@ PRUint32 Mid(nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
* @param aCount -- number of chars to copy
* @return number of chars copied
*/
PRUint32 Right(nsString& aCopy,PRInt32 aCount) const;
PRUint32 Right(nsString& aCopy,PRInt32 aCount) const;
/*
/*
* This method inserts n chars from given string into this
* string at str[anOffset].
*
@@ -505,9 +508,9 @@ PRUint32 Right(nsString& aCopy,PRInt32 aCount) const;
* @param aCount -- number of chars to be copied from aCopy
* @return number of chars inserted into this.
*/
nsString& Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
nsString& Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
/**
/**
* Insert a given string into this string at
* a specified offset.
*
@@ -515,10 +518,10 @@ nsString& Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
* @param anOffset is insert pos in str
* @return the number of chars inserted into this string
*/
nsString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
nsString& Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
nsString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
nsString& Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
/**
/**
* Insert a single char into this string at
* a specified offset.
*
@@ -526,10 +529,10 @@ nsString& Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
* @param anOffset is insert pos in str
* @return the number of chars inserted into this string
*/
//nsString& Insert(char aChar,PRUint32 anOffset);
nsString& Insert(PRUnichar aChar,PRUint32 anOffset);
//nsString& Insert(char aChar,PRUint32 anOffset);
nsString& Insert(PRUnichar aChar,PRUint32 anOffset);
/*
/*
* This method is used to cut characters in this string
* starting at anOffset, continuing for aCount chars.
*
@@ -537,14 +540,14 @@ nsString& Insert(PRUnichar aChar,PRUint32 anOffset);
* @param aCount -- number of chars to be cut
* @return *this
*/
nsString& Cut(PRUint32 anOffset,PRInt32 aCount);
nsString& Cut(PRUint32 anOffset,PRInt32 aCount);
/**********************************************************************
/**********************************************************************
Searching methods...
*********************************************************************/
/**
/**
* Search for given character within this string.
* This method does so by using a binary search,
* so your string HAD BETTER BE ORDERED!
@@ -552,9 +555,9 @@ nsString& Cut(PRUint32 anOffset,PRInt32 aCount);
* @param aChar is the unicode char to be found
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 BinarySearch(PRUnichar aChar) const;
PRInt32 BinarySearch(PRUnichar aChar) const;
/**
/**
* Search for given substring within this string
*
* @param aString is substring to be sought in this
@@ -562,13 +565,13 @@ PRInt32 BinarySearch(PRUnichar aChar) const;
* @param anOffset tells us where in this strig to start searching
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
/**
/**
* Search for given char within this string
*
* @param aString is substring to be sought in this
@@ -576,34 +579,34 @@ PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffs
* @param aIgnoreCase selects case sensitivity
* @return find pos in string, or -1 (kNotFound)
*/
//PRInt32 Find(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
//PRInt32 Find(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
/**
/**
* This method searches this string for the first character
* found in the given charset
* @param aString contains set of chars to be found
* @param anOffset tells us where to start searching in this
* @return -1 if not found, else the offset in this
*/
PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
/**
/**
* This methods scans the string backwards, looking for the given string
* @param aString is substring to be sought in this
* @param aIgnoreCase tells us whether or not to do caseless compare
* @param anOffset tells us where in this strig to start searching (counting from left)
*/
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
/**
/**
* Search for given char within this string
*
* @param aString is substring to be sought in this
@@ -611,26 +614,26 @@ PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOff
* @param aIgnoreCase selects case sensitivity
* @return find pos in string, or -1 (kNotFound)
*/
//PRInt32 RFind(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
//PRInt32 RFind(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
/**
/**
* This method searches this string for the last character
* found in the given string
* @param aString contains set of chars to be found
* @param anOffset tells us where in this strig to start searching (counting from left)
* @return -1 if not found, else the offset in this
*/
PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
/**********************************************************************
/**********************************************************************
Comparison methods...
*********************************************************************/
/**
/**
* Compares a given string type to this string.
* @update gess 7/27/98
* @param S is the string to be compared
@@ -638,72 +641,72 @@ PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
* @param aCount tells us how many chars to compare
* @return -1,0,1
*/
virtual PRInt32 Compare(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
/**
/**
* These methods compare a given string type to this one
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator==(const nsString &aString) const;
PRBool operator==(const nsStr &aString) const;
PRBool operator==(const char *aString) const;
PRBool operator==(const PRUnichar* aString) const;
PRBool operator==(const nsString &aString) const;
PRBool operator==(const nsStr &aString) const;
PRBool operator==(const char *aString) const;
PRBool operator==(const PRUnichar* aString) const;
/**
/**
* These methods perform a !compare of a given string type to this
* @param aString is the string to be compared to this
* @return TRUE
*/
PRBool operator!=(const nsString &aString) const;
PRBool operator!=(const nsStr &aString) const;
PRBool operator!=(const char* aString) const;
PRBool operator!=(const PRUnichar* aString) const;
PRBool operator!=(const nsString &aString) const;
PRBool operator!=(const nsStr &aString) const;
PRBool operator!=(const char* aString) const;
PRBool operator!=(const PRUnichar* aString) const;
/**
/**
* These methods test if a given string is < than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator<(const nsString &aString) const;
PRBool operator<(const nsStr &aString) const;
PRBool operator<(const char* aString) const;
PRBool operator<(const PRUnichar* aString) const;
PRBool operator<(const nsString &aString) const;
PRBool operator<(const nsStr &aString) const;
PRBool operator<(const char* aString) const;
PRBool operator<(const PRUnichar* aString) const;
/**
/**
* These methods test if a given string is > than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator>(const nsString &aString) const;
PRBool operator>(const nsStr &S) const;
PRBool operator>(const char* aString) const;
PRBool operator>(const PRUnichar* aString) const;
PRBool operator>(const nsString &aString) const;
PRBool operator>(const nsStr &S) const;
PRBool operator>(const char* aString) const;
PRBool operator>(const PRUnichar* aString) const;
/**
/**
* These methods test if a given string is <= than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator<=(const nsString &aString) const;
PRBool operator<=(const nsStr &S) const;
PRBool operator<=(const char* aString) const;
PRBool operator<=(const PRUnichar* aString) const;
PRBool operator<=(const nsString &aString) const;
PRBool operator<=(const nsStr &S) const;
PRBool operator<=(const char* aString) const;
PRBool operator<=(const PRUnichar* aString) const;
/**
/**
* These methods test if a given string is >= than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator>=(const nsString &aString) const;
PRBool operator>=(const nsStr &S) const;
PRBool operator>=(const char* aString) const;
PRBool operator>=(const PRUnichar* aString) const;
PRBool operator>=(const nsString &aString) const;
PRBool operator>=(const nsStr &S) const;
PRBool operator>=(const char* aString) const;
PRBool operator>=(const PRUnichar* aString) const;
/**
/**
* Compare this to given string; note that we compare full strings here.
* The optional length argument just lets us know how long the given string is.
* If you provide a length, it is compared to length of this string as an
@@ -713,56 +716,53 @@ PRBool operator>=(const PRUnichar* aString) const;
* @param aCount -- number of chars to be compared.
* @return TRUE if equal
*/
PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const;
PRBool Equals(const PRUnichar* s1, const PRUnichar* s2,PRBool aIgnoreCase=PR_FALSE) const;
PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const;
PRBool Equals(const PRUnichar* s1, const PRUnichar* s2,PRBool aIgnoreCase=PR_FALSE) const;
PRBool EqualsIgnoreCase(const nsString& aString) const;
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const;
PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const;
PRBool EqualsIgnoreCase(const nsString& aString) const;
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const;
PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const;
/**
/**
* Determine if given buffer is plain ascii
*
* @param aBuffer -- if null, then we test *this, otherwise we test given buffer
* @return TRUE if is all ascii chars or if strlen==0
*/
PRBool IsASCII(const PRUnichar* aBuffer=0);
PRBool IsASCII(const PRUnichar* aBuffer=0);
/**
/**
* Determine if given char is a valid space character
*
* @param aChar is character to be tested
* @return TRUE if is valid space char
*/
static PRBool IsSpace(PRUnichar ch);
static PRBool IsSpace(PRUnichar ch);
/**
/**
* Determine if given char in valid alpha range
*
* @param aChar is character to be tested
* @return TRUE if in alpha range
*/
static PRBool IsAlpha(PRUnichar ch);
static PRBool IsAlpha(PRUnichar ch);
/**
/**
* Determine if given char is valid digit
*
* @param aChar is character to be tested
* @return TRUE if char is a valid digit
*/
static PRBool IsDigit(PRUnichar ch);
static PRBool IsDigit(PRUnichar ch);
static void Recycle(nsString* aString);
static nsString* CreateString(void);
nsIMemoryAgent* mAgent;
static void Recycle(nsString* aString);
static nsString* CreateString(void);
};

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;
//begin by skipping over leading chars that shouldn't be part of the number...
aRadix=kRadixUnknown; //assume for starters...
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;
}
else if((*cp>='A') && (*cp<='F')) {
aRadix=16;
break;
}
cp--;
}
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...
while(cp<endcp){
const char* pos=(const char*)memchr(validChars,*cp,len);
if(!pos) {
cp++;
while (--cp >= aString.mStr) {
if((*cp>='0') && (*cp<='9')){
continue;
}
else if((*cp>='A') && (*cp<='F')) {
continue;
else break;
}
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;
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;
}
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
}

View File

@@ -46,214 +46,217 @@ class NS_COM nsSubsumeCStr;
class NS_COM nsCString : public nsStr {
public:
public:
/**
/**
* Default constructor.
*/
nsCString(nsIMemoryAgent* anAgent=0);
nsCString();
/**
/**
* This constructor accepts an isolatin string
* @param aCString is a ptr to a 1-byte cstr
*/
nsCString(const char* aCString,PRInt32 aLength=-1,nsIMemoryAgent* anAgent=0);
nsCString(const char* aCString,PRInt32 aLength=-1);
/**
/**
* This constructor accepts a unichar string
* @param aCString is a ptr to a 2-byte cstr
*/
nsCString(const PRUnichar* aString,PRInt32 aLength=-1,nsIMemoryAgent* anAgent=0);
nsCString(const PRUnichar* aString,PRInt32 aLength=-1);
/**
/**
* This is a copy constructor that accepts an nsStr
* @param reference to another nsCString
*/
nsCString(const nsStr&,nsIMemoryAgent* anAgent=0);
nsCString(const nsStr&);
/**
/**
* This is our copy constructor
* @param reference to another nsCString
*/
nsCString(const nsCString& aString);
nsCString(const nsCString& aString);
/**
/**
* This constructor takes a subsumestr
* @param reference to subsumestr
*/
nsCString(nsSubsumeCStr& aSubsumeStr);
nsCString(nsSubsumeCStr& aSubsumeStr);
/**
/**
* Destructor
*
*/
virtual ~nsCString();
virtual ~nsCString();
/**
/**
* Retrieve the length of this string
* @return string length
*/
inline PRInt32 Length() const { return (PRInt32)mLength; }
inline PRInt32 Length() const { return (PRInt32)mLength; }
/**
/**
* Retrieve the size of this string
* @return string length
*/
virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
/**
/**
* Call this method if you want to force a different string capacity
* @update gess7/30/98
* @param aLength -- contains new length for mStr
* @return
*/
void SetLength(PRUint32 aLength) {
void SetLength(PRUint32 aLength) {
Truncate(aLength);
}
}
/**
/**
* Sets the new length of the string.
* @param aLength is new string length.
* @return nada
*/
void SetCapacity(PRUint32 aLength);
/**
void SetCapacity(PRUint32 aLength);
/**
* This method truncates this string to given length.
*
* @param anIndex -- new length of string
* @return nada
*/
void Truncate(PRInt32 anIndex=0);
void Truncate(PRInt32 anIndex=0);
/**
/**
* Determine whether or not the characters in this
* string are in sorted order.
*
* @return TRUE if ordered.
*/
PRBool IsOrdered(void) const;
PRBool IsOrdered(void) const;
/**
/**
* Determine whether or not this string has a length of 0
*
* @return TRUE if empty.
*/
PRBool IsEmpty(void) const {
PRBool IsEmpty(void) const {
return PRBool(0==mLength);
}
}
/**********************************************************************
/**********************************************************************
Accessor methods...
*********************************************************************/
const char* GetBuffer(void) const;
/**
* Retrieve const ptr to internal buffer; DO NOT TRY TO FREE IT!
*/
const char* GetBuffer(void) const;
/**
* Get nth character.
*/
PRUnichar operator[](PRUint32 anIndex) const;
PRUnichar CharAt(PRUint32 anIndex) const;
PRUnichar First(void) const;
PRUnichar Last(void) const;
PRUnichar operator[](PRUint32 anIndex) const;
PRUnichar CharAt(PRUint32 anIndex) const;
PRUnichar First(void) const;
PRUnichar Last(void) const;
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
/**********************************************************************
/**********************************************************************
String creation methods...
*********************************************************************/
/**
/**
* Create a new string by appending given string to this
* @param aString -- 2nd string to be appended
* @return new string
*/
nsSubsumeCStr operator+(const nsCString& aString);
nsSubsumeCStr operator+(const nsCString& aString);
/**
/**
* create a new string by adding this to the given char*.
* @param aCString is a ptr to cstring to be added to this
* @return newly created string
*/
nsSubsumeCStr operator+(const char* aCString);
nsSubsumeCStr operator+(const char* aCString);
/**
/**
* create a new string by adding this to the given char.
* @param aChar is a char to be added to this
* @return newly created string
*/
nsSubsumeCStr operator+(PRUnichar aChar);
nsSubsumeCStr operator+(char aChar);
nsSubsumeCStr operator+(PRUnichar aChar);
nsSubsumeCStr operator+(char aChar);
/**********************************************************************
/**********************************************************************
Lexomorphic transforms...
*********************************************************************/
/**
/**
* Converts chars in this to lowercase
* @update gess 7/27/98
*/
void ToLowerCase();
void ToLowerCase();
/**
/**
* Converts chars in this to lowercase, and
* stores them in aOut
* @update gess 7/27/98
* @param aOut is a string to contain result
*/
void ToLowerCase(nsCString& aString) const;
void ToLowerCase(nsCString& aString) const;
/**
/**
* Converts chars in this to uppercase
* @update gess 7/27/98
*/
void ToUpperCase();
void ToUpperCase();
/**
/**
* Converts chars in this to lowercase, and
* stores them in a given output string
* @update gess 7/27/98
* @param aOut is a string to contain result
*/
void ToUpperCase(nsCString& aString) const;
void ToUpperCase(nsCString& aString) const;
/**
/**
* This method is used to remove all occurances of the
* characters found in aSet from this string.
*
* @param aSet -- characters to be cut from this
* @return *this
*/
nsCString& StripChars(const char* aSet);
nsCString& StripChar(char aChar);
nsCString& StripChars(const char* aSet);
nsCString& StripChar(char aChar);
/**
/**
* This method strips whitespace throughout the string
*
* @return this
*/
nsCString& StripWhitespace();
nsCString& StripWhitespace();
/**
/**
* swaps occurence of 1 string for another
*
* @return this
*/
nsCString& ReplaceChar(PRUnichar aOldChar,PRUnichar aNewChar);
nsCString& ReplaceChar(const char* aSet,PRUnichar aNewChar);
nsCString& ReplaceChar(PRUnichar aOldChar,PRUnichar aNewChar);
nsCString& ReplaceChar(const char* aSet,PRUnichar aNewChar);
PRInt32 CountChar(PRUnichar aChar);
PRInt32 CountChar(PRUnichar aChar);
/**
/**
* This method trims characters found in aTrimSet from
* either end of the underlying string.
*
@@ -261,9 +264,9 @@ PRInt32 CountChar(PRUnichar aChar);
* both ends
* @return this
*/
nsCString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
nsCString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/**
/**
* This method strips whitespace from string.
* You can control whether whitespace is yanked from
* start and end of string as well.
@@ -272,9 +275,9 @@ nsCString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aElimin
* @param aEliminateTrailing controls stripping of trailing ws
* @return this
*/
nsCString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
nsCString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/**
/**
* This method strips whitespace from string.
* You can control whether whitespace is yanked from
* start and end of string as well.
@@ -283,142 +286,143 @@ nsCString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeadin
* @param aEliminateTrailing controls stripping of trailing ws
* @return this
*/
nsCString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
nsCString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/**********************************************************************
/**********************************************************************
string conversion methods...
*********************************************************************/
operator char*() {return mStr;}
operator const char*() const {return (const char*)mStr;}
/**
/**
* This method constructs a new nsCString that is a clone
* of this string.
*
*/
nsCString* ToNewString() const;
nsCString* ToNewString() const;
/**
/**
* Creates an ISOLatin1 clone of this string
* Note that calls to this method should be matched with calls to Recycle().
* @return ptr to new isolatin1 string
*/
char* ToNewCString() const;
char* ToNewCString() const;
/**
/**
* Creates a unicode clone of this string
* Note that calls to this method should be matched with calls to Recycle().
* @return ptr to new unicode string
*/
PRUnichar* ToNewUnicode() const;
PRUnichar* ToNewUnicode() const;
/**
/**
* Copies data from internal buffer onto given char* buffer
* NOTE: This only copies as many chars as will fit in given buffer (clips)
* @param aBuf is the buffer where data is stored
* @param aBuflength is the max # of chars to move to buffer
* @return ptr to given buffer
*/
char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const;
char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const;
/**
/**
* Perform string to float conversion.
* @param aErrorCode will contain error if one occurs
* @return float rep of string value
*/
float ToFloat(PRInt32* aErrorCode) const;
float ToFloat(PRInt32* aErrorCode) const;
/**
/**
* Try to derive the radix from the value contained in this string
* @return kRadix10, kRadix16 or kAutoDetect (meaning unknown)
*/
PRUint32 DetermineRadix(void);
PRUint32 DetermineRadix(void);
/**
/**
* Perform string to int conversion.
* @param aErrorCode will contain error if one occurs
* @return int rep of string value
*/
PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const;
PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const;
/**********************************************************************
/**********************************************************************
String manipulation methods...
*********************************************************************/
/**
/**
* Functionally equivalent to assign or operator=
*
*/
nsCString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsCString& SetString(const nsStr& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsCString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsCString& SetString(const nsStr& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
/**
/**
* assign given string to this string
* @param aStr: buffer to be assigned to this
* @param alength is the length of the given str (or -1)
if you want me to determine its length
* @return this
*/
nsCString& Assign(const nsStr& aString,PRInt32 aCount=-1);
nsCString& Assign(const char* aString,PRInt32 aCount=-1);
nsCString& Assign(const PRUnichar* aString,PRInt32 aCount=-1);
nsCString& Assign(PRUnichar aChar);
nsCString& Assign(char aChar);
nsCString& Assign(const nsStr& aString,PRInt32 aCount=-1);
nsCString& Assign(const char* aString,PRInt32 aCount=-1);
nsCString& Assign(const PRUnichar* aString,PRInt32 aCount=-1);
nsCString& Assign(PRUnichar aChar);
nsCString& Assign(char aChar);
/**
/**
* here come a bunch of assignment operators...
* @param aString: string to be added to this
* @return this
*/
nsCString& operator=(const nsCString& aString) {return Assign(aString);}
nsCString& operator=(const nsStr& aString) {return Assign(aString);}
nsCString& operator=(PRUnichar aChar) {return Assign(aChar);}
nsCString& operator=(char aChar) {return Assign(aChar);}
nsCString& operator=(const char* aCString) {return Assign(aCString);}
nsCString& operator=(const PRUnichar* aString) {return Assign(aString);}
#ifdef AIX
nsCString& operator=(const nsSubsumeCStr& aSubsumeString); // AIX requires a const here
#else
nsCString& operator=(nsSubsumeCStr& aSubsumeString);
#endif
nsCString& operator=(const nsCString& aString) {return Assign(aString);}
nsCString& operator=(const nsStr& aString) {return Assign(aString);}
nsCString& operator=(PRUnichar aChar) {return Assign(aChar);}
nsCString& operator=(char aChar) {return Assign(aChar);}
nsCString& operator=(const char* aCString) {return Assign(aCString);}
nsCString& operator=(const PRUnichar* aString) {return Assign(aString);}
#ifdef AIX
nsCString& operator=(const nsSubsumeCStr& aSubsumeString); // AIX requires a const here
#else
nsCString& operator=(nsSubsumeCStr& aSubsumeString);
#endif
/**
/**
* Here's a bunch of methods that append varying types...
* @param various...
* @return this
*/
nsCString& operator+=(const nsCString& aString){return Append(aString,aString.mLength);}
nsCString& operator+=(const char* aCString) {return Append(aCString);}
nsCString& operator+=(PRUnichar aChar){return Append(aChar);}
nsCString& operator+=(char aChar){return Append(aChar);}
nsCString& operator+=(const nsCString& aString){return Append(aString,aString.mLength);}
nsCString& operator+=(const char* aCString) {return Append(aCString);}
nsCString& operator+=(PRUnichar aChar){return Append(aChar);}
nsCString& operator+=(char aChar){return Append(aChar);}
/*
/*
* Appends n characters from given string to this,
* This version computes the length of your given string
*
* @param aString is the source to be appended to this
* @return number of chars copied
*/
nsCString& Append(const nsCString& aString) {return Append(aString,aString.mLength);}
nsCString& Append(const nsCString& aString) {return Append(aString,aString.mLength);}
/*
/*
* Appends n characters from given string to this,
*
* @param aString is the source to be appended to this
* @param aCount -- number of chars to copy; -1 tells us to compute the strlen for you
* @return number of chars copied
*/
nsCString& Append(const nsCString& aString,PRInt32 aCount);
nsCString& Append(const char* aString,PRInt32 aCount=-1);
nsCString& Append(PRUnichar aChar);
nsCString& Append(char aChar);
nsCString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16
nsCString& Append(float aFloat);
nsCString& Append(const nsCString& aString,PRInt32 aCount);
nsCString& Append(const nsStr& aString,PRInt32 aCount=-1);
nsCString& Append(const char* aString,PRInt32 aCount=-1);
nsCString& Append(PRUnichar aChar);
nsCString& Append(char aChar);
nsCString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16
nsCString& Append(float aFloat);
/*
/*
* Copies n characters from this string to given string,
* starting at the leftmost offset.
*
@@ -427,9 +431,9 @@ nsCString& Append(float aFloat);
* @param aCount -- number of chars to copy
* @return number of chars copied
*/
PRUint32 Left(nsCString& aCopy,PRInt32 aCount) const;
PRUint32 Left(nsCString& aCopy,PRInt32 aCount) const;
/*
/*
* Copies n characters from this string to given string,
* starting at the given offset.
*
@@ -439,9 +443,9 @@ PRUint32 Left(nsCString& aCopy,PRInt32 aCount) const;
* @param anOffset -- position where copying begins
* @return number of chars copied
*/
PRUint32 Mid(nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
PRUint32 Mid(nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
/*
/*
* Copies n characters from this string to given string,
* starting at rightmost char.
*
@@ -450,9 +454,9 @@ PRUint32 Mid(nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
* @param aCount -- number of chars to copy
* @return number of chars copied
*/
PRUint32 Right(nsCString& aCopy,PRInt32 aCount) const;
PRUint32 Right(nsCString& aCopy,PRInt32 aCount) const;
/*
/*
* This method inserts n chars from given string into this
* string at str[anOffset].
*
@@ -461,9 +465,9 @@ PRUint32 Right(nsCString& aCopy,PRInt32 aCount) const;
* @param aCount -- number of chars to be copied from aCopy
* @return number of chars inserted into this.
*/
nsCString& Insert(const nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
nsCString& Insert(const nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
/**
/**
* Insert a given string into this string at
* a specified offset.
*
@@ -471,9 +475,9 @@ nsCString& Insert(const nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
* @param anOffset is insert pos in str
* @return the number of chars inserted into this string
*/
nsCString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
nsCString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
/**
/**
* Insert a single char into this string at
* a specified offset.
*
@@ -481,10 +485,10 @@ nsCString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
* @param anOffset is insert pos in str
* @return the number of chars inserted into this string
*/
nsCString& Insert(PRUnichar aChar,PRUint32 anOffset);
nsCString& Insert(char aChar,PRUint32 anOffset);
nsCString& Insert(PRUnichar aChar,PRUint32 anOffset);
nsCString& Insert(char aChar,PRUint32 anOffset);
/*
/*
* This method is used to cut characters in this string
* starting at anOffset, continuing for aCount chars.
*
@@ -492,14 +496,14 @@ nsCString& Insert(char aChar,PRUint32 anOffset);
* @param aCount -- number of chars to be cut
* @return *this
*/
nsCString& Cut(PRUint32 anOffset,PRInt32 aCount);
nsCString& Cut(PRUint32 anOffset,PRInt32 aCount);
/**********************************************************************
/**********************************************************************
Searching methods...
*********************************************************************/
/**
/**
* Search for given character within this string.
* This method does so by using a binary search,
* so your string HAD BETTER BE ORDERED!
@@ -507,9 +511,9 @@ nsCString& Cut(PRUint32 anOffset,PRInt32 aCount);
* @param aChar is the unicode char to be found
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 BinarySearch(PRUnichar aChar) const;
PRInt32 BinarySearch(PRUnichar aChar) const;
/**
/**
* Search for given substring within this string
*
* @param aString is substring to be sought in this
@@ -517,11 +521,11 @@ PRInt32 BinarySearch(PRUnichar aChar) const;
* @param anOffset tells us where in this strig to start searching
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
/**
/**
* Search for given char within this string
*
* @param aString is substring to be sought in this
@@ -529,32 +533,32 @@ PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffs
* @param aIgnoreCase selects case sensitivity
* @return find pos in string, or -1 (kNotFound)
*/
PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
/**
/**
* This method searches this string for the first character
* found in the given charset
* @param aString contains set of chars to be found
* @param anOffset tells us where to start searching in this
* @return -1 if not found, else the offset in this
*/
PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
/**
/**
* This methods scans the string backwards, looking for the given string
* @param aString is substring to be sought in this
* @param aIgnoreCase tells us whether or not to do caseless compare
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
/**
/**
* Search for given char within this string
*
* @param aString is substring to be sought in this
@@ -562,26 +566,26 @@ PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOff
* @param aIgnoreCase selects case sensitivity
* @return find pos in string, or -1 (kNotFound)
*/
PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
/**
/**
* This method searches this string for the last character
* found in the given string
* @param aString contains set of chars to be found
* @param anOffset tells us where to start searching in this
* @return -1 if not found, else the offset in this
*/
PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
/**********************************************************************
/**********************************************************************
Comparison methods...
*********************************************************************/
/**
/**
* Compares a given string type to this string.
* @update gess 7/27/98
* @param S is the string to be compared
@@ -589,65 +593,65 @@ PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
* @param aCount tells us how many chars to compare
* @return -1,0,1
*/
virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
/**
/**
* These methods compare a given string type to this one
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator==(const nsStr &aString) const;
PRBool operator==(const char* aString) const;
PRBool operator==(const PRUnichar* aString) const;
PRBool operator==(const nsStr &aString) const;
PRBool operator==(const char* aString) const;
PRBool operator==(const PRUnichar* aString) const;
/**
/**
* These methods perform a !compare of a given string type to this
* @param aString is the string to be compared to this
* @return TRUE
*/
PRBool operator!=(const nsStr &aString) const;
PRBool operator!=(const char* aString) const;
PRBool operator!=(const PRUnichar* aString) const;
PRBool operator!=(const nsStr &aString) const;
PRBool operator!=(const char* aString) const;
PRBool operator!=(const PRUnichar* aString) const;
/**
/**
* These methods test if a given string is < than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator<(const nsStr &aString) const;
PRBool operator<(const char* aString) const;
PRBool operator<(const PRUnichar* aString) const;
PRBool operator<(const nsStr &aString) const;
PRBool operator<(const char* aString) const;
PRBool operator<(const PRUnichar* aString) const;
/**
/**
* These methods test if a given string is > than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator>(const nsStr &S) const;
PRBool operator>(const char* aString) const;
PRBool operator>(const PRUnichar* aString) const;
PRBool operator>(const nsStr &S) const;
PRBool operator>(const char* aString) const;
PRBool operator>(const PRUnichar* aString) const;
/**
/**
* These methods test if a given string is <= than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator<=(const nsStr &S) const;
PRBool operator<=(const char* aString) const;
PRBool operator<=(const PRUnichar* aString) const;
PRBool operator<=(const nsStr &S) const;
PRBool operator<=(const char* aString) const;
PRBool operator<=(const PRUnichar* aString) const;
/**
/**
* These methods test if a given string is >= than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator>=(const nsStr &S) const;
PRBool operator>=(const char* aString) const;
PRBool operator>=(const PRUnichar* aString) const;
PRBool operator>=(const nsStr &S) const;
PRBool operator>=(const char* aString) const;
PRBool operator>=(const PRUnichar* aString) const;
/**
/**
* Compare this to given string; note that we compare full strings here.
* The optional length argument just lets us know how long the given string is.
* If you provide a length, it is compared to length of this string as an
@@ -657,21 +661,18 @@ PRBool operator>=(const PRUnichar* aString) const;
* @param aCount -- number of chars in given string you want to compare
* @return TRUE if equal
*/
PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(const nsStr& aString) const;
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(const nsStr& aString) const;
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const;
static void Recycle(nsCString* aString);
static nsCString* CreateString(void);
nsIMemoryAgent* mAgent;
static void Recycle(nsCString* aString);
static nsCString* CreateString(void);
};

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;
//begin by skipping over leading chars that shouldn't be part of the number...
aRadix=kRadixUnknown; //assume for starters...
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;
}
else if((*cp>='A') && (*cp<='F')) {
aRadix=16;
break;
}
cp--;
}
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...
while(cp<endcp){
const char* pos=(const char*)memchr(validChars,*cp,len);
if(!pos) {
cp++;
while (--cp >= aString.mStr) {
if((*cp>='0') && (*cp<='9')){
continue;
}
else if((*cp>='A') && (*cp<='F')) {
continue;
else break;
}
else if((*cp=='-') || (*cp=='+')){
break;
while(cp<endcp){
char theChar=toupper(*cp);
if((theChar>='0') && (theChar<='9')) {
*to++=theChar;
}
else {
if(('#'==(*cp)) || ('X'==(*cp)))
aRadix=kRadix16;
cp++; //move back by one
break;
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;
}
if(cp>aString.mStr)
aString.Cut(0,cp-aString.mStr);
PRInt32 result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK;
return result;
}
@@ -865,9 +866,9 @@ 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){
@@ -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
}

View File

@@ -53,242 +53,245 @@ class nsISizeOfHandler;
class NS_COM nsSubsumeStr;
class NS_COM nsString : public nsStr {
public:
public:
/**
/**
* Default constructor.
*/
nsString(nsIMemoryAgent* anAgent=0);
nsString();
/**
/**
* This constructor accepts an isolatin string
* @param aCString is a ptr to a 1-byte cstr
*/
nsString(const char* aCString,nsIMemoryAgent* anAgent=0);
nsString(const char* aCString);
/**
/**
* This constructor accepts a unichar string
* @param aCString is a ptr to a 2-byte cstr
*/
nsString(const PRUnichar* aString,nsIMemoryAgent* anAgent=0);
nsString(const PRUnichar* aString);
/**
/**
* This is a copy constructor that accepts an nsStr
* @param reference to another nsString
*/
nsString(const nsStr&,nsIMemoryAgent* anAgent=0);
nsString(const nsStr&);
/**
/**
* This is our copy constructor
* @param reference to another nsString
*/
nsString(const nsString& aString);
nsString(const nsString& aString);
/**
/**
* This constructor takes a subsumestr
* @param reference to subsumestr
*/
nsString(nsSubsumeStr& aSubsumeStr);
nsString(nsSubsumeStr& aSubsumeStr);
/**
/**
* Destructor
*
*/
virtual ~nsString();
virtual ~nsString();
/**
/**
* Retrieve the length of this string
* @return string length
*/
inline PRInt32 Length() const { return (PRInt32)mLength; }
inline PRInt32 Length() const { return (PRInt32)mLength; }
/**
/**
* Retrieve the size of this string
* @return string length
*/
virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
/**
/**
* Call this method if you want to force a different string length
* @update gess7/30/98
* @param aLength -- contains new length for mStr
* @return
*/
void SetLength(PRUint32 aLength) {
void SetLength(PRUint32 aLength) {
Truncate(aLength);
}
}
/**
/**
* Sets the new length of the string.
* @param aLength is new string length.
* @return nada
*/
void SetCapacity(PRUint32 aLength);
void SetCapacity(PRUint32 aLength);
/**
/**
* This method truncates this string to given length.
*
* @param anIndex -- new length of string
* @return nada
*/
void Truncate(PRInt32 anIndex=0);
void Truncate(PRInt32 anIndex=0);
/**
/**
* Determine whether or not the characters in this
* string are in sorted order.
*
* @return TRUE if ordered.
*/
PRBool IsOrdered(void) const;
PRBool IsOrdered(void) const;
/**
/**
* Determine whether or not the characters in this
* string are in store as 1 or 2 byte (unicode) strings.
*
* @return TRUE if ordered.
*/
PRBool IsUnicode(void) const {
PRBool IsUnicode(void) const {
PRBool result=PRBool(mCharSize==eTwoByte);
return result;
}
}
/**
/**
* Determine whether or not this string has a length of 0
*
* @return TRUE if empty.
*/
PRBool IsEmpty(void) const {
PRBool IsEmpty(void) const {
return PRBool(0==mLength);
}
}
/**********************************************************************
/**********************************************************************
Getters/Setters...
*********************************************************************/
const char* GetBuffer(void) const;
const PRUnichar* GetUnicode(void) const;
/**
* Retrieve const ptr to internal buffer; DO NOT TRY TO FREE IT!
*/
const char* GetBuffer(void) const;
const PRUnichar* GetUnicode(void) const;
/**
* Get nth character.
*/
PRUnichar operator[](PRUint32 anIndex) const;
PRUnichar CharAt(PRUint32 anIndex) const;
PRUnichar First(void) const;
PRUnichar Last(void) const;
PRUnichar operator[](PRUint32 anIndex) const;
PRUnichar CharAt(PRUint32 anIndex) const;
PRUnichar First(void) const;
PRUnichar Last(void) const;
/**
* Set nth character.
*/
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
/**********************************************************************
/**********************************************************************
String concatenation methods...
*********************************************************************/
/**
/**
* Create a new string by appending given string to this
* @param aString -- 2nd string to be appended
* @return new subsumable string
*/
nsSubsumeStr operator+(const nsStr& aString);
nsSubsumeStr operator+(const nsString& aString);
nsSubsumeStr operator+(const nsStr& aString);
nsSubsumeStr operator+(const nsString& aString);
/**
/**
* create a new string by adding this to the given cstring
* @param aCString is a ptr to cstring to be added to this
* @return newly created string
*/
nsSubsumeStr operator+(const char* aCString);
nsSubsumeStr operator+(const char* aCString);
/**
/**
* create a new string by adding this to the given prunichar*.
* @param aString is a ptr to UC-string to be added to this
* @return newly created string
*/
nsSubsumeStr operator+(const PRUnichar* aString);
nsSubsumeStr operator+(const PRUnichar* aString);
/**
/**
* create a new string by adding this to the given char.
* @param aChar is a char to be added to this
* @return newly created string
*/
nsSubsumeStr operator+(char aChar);
nsSubsumeStr operator+(char aChar);
/**
/**
* create a new string by adding this to the given char.
* @param aChar is a unichar to be added to this
* @return newly created string
*/
nsSubsumeStr operator+(PRUnichar aChar);
nsSubsumeStr operator+(PRUnichar aChar);
/**********************************************************************
/**********************************************************************
Lexomorphic transforms...
*********************************************************************/
/**
/**
* Converts chars in this to lowercase
* @update gess 7/27/98
*/
void ToLowerCase();
void ToLowerCase();
/**
/**
* Converts chars in this to lowercase, and
* stores them in aOut
* @update gess 7/27/98
* @param aOut is a string to contain result
*/
void ToLowerCase(nsString& aString) const;
void ToLowerCase(nsString& aString) const;
/**
/**
* Converts chars in this to uppercase
* @update gess 7/27/98
*/
void ToUpperCase();
void ToUpperCase();
/**
/**
* Converts chars in this to lowercase, and
* stores them in a given output string
* @update gess 7/27/98
* @param aOut is a string to contain result
*/
void ToUpperCase(nsString& aString) const;
void ToUpperCase(nsString& aString) const;
/**
/**
* This method is used to remove all occurances of the
* characters found in aSet from this string.
*
* @param aSet -- characters to be cut from this
* @return *this
*/
nsString& StripChars(const char* aSet);
nsString& StripChar(char aChar);
nsString& StripChars(const char* aSet);
nsString& StripChar(char aChar);
/**
/**
* This method strips whitespace throughout the string
*
* @return this
*/
nsString& StripWhitespace();
nsString& StripWhitespace();
/**
/**
* swaps occurence of 1 string for another
*
* @return this
*/
nsString& ReplaceChar(PRUnichar anOldChar,PRUnichar aNewChar);
nsString& ReplaceChar(const char* aSet,PRUnichar aNewChar);
nsString& ReplaceChar(PRUnichar anOldChar,PRUnichar aNewChar);
nsString& ReplaceChar(const char* aSet,PRUnichar aNewChar);
PRInt32 CountChar(PRUnichar aChar);
PRInt32 CountChar(PRUnichar aChar);
/**
/**
* This method trims characters found in aTrimSet from
* either end of the underlying string.
*
@@ -296,9 +299,9 @@ PRInt32 CountChar(PRUnichar aChar);
* both ends
* @return this
*/
nsString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
nsString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/**
/**
* This method strips whitespace from string.
* You can control whether whitespace is yanked from
* start and end of string as well.
@@ -307,9 +310,9 @@ nsString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aElimina
* @param aEliminateTrailing controls stripping of trailing ws
* @return this
*/
nsString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
nsString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/**
/**
* This method strips whitespace from string.
* You can control whether whitespace is yanked from
* start and end of string as well.
@@ -318,151 +321,151 @@ nsString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading
* @param aEliminateTrailing controls stripping of trailing ws
* @return this
*/
nsString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
nsString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/**********************************************************************
/**********************************************************************
string conversion methods...
*********************************************************************/
/**
/**
* This method constructs a new nsString is a clone of this string.
*
*/
nsString* ToNewString() const;
nsString* ToNewString() const;
/**
/**
* Creates an ISOLatin1 clone of this string
* Note that calls to this method should be matched with calls to Recycle().
* @return ptr to new isolatin1 string
*/
char* ToNewCString() const;
char* ToNewCString() const;
/**
/**
* Creates an UTF8 clone of this string
* Note that calls to this method should be matched with calls to Recycle().
* @return ptr to new isolatin1 string
*/
char* ToNewUTF8String() const;
char* ToNewUTF8String() const;
/**
/**
* Creates a unicode clone of this string
* Note that calls to this method should be matched with calls to Recycle().
* @return ptr to new unicode string
*/
PRUnichar* ToNewUnicode() const;
PRUnichar* ToNewUnicode() const;
/**
/**
* Copies data from internal buffer onto given char* buffer
* NOTE: This only copies as many chars as will fit in given buffer (clips)
* @param aBuf is the buffer where data is stored
* @param aBuflength is the max # of chars to move to buffer
* @return ptr to given buffer
*/
char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const;
char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const;
/**
/**
* Perform string to float conversion.
* @param aErrorCode will contain error if one occurs
* @return float rep of string value
*/
float ToFloat(PRInt32* aErrorCode) const;
float ToFloat(PRInt32* aErrorCode) const;
/**
/**
* Try to derive the radix from the value contained in this string
* @return kRadix10, kRadix16 or kAutoDetect (meaning unknown)
*/
PRUint32 DetermineRadix(void);
PRUint32 DetermineRadix(void);
/**
/**
* Perform string to int conversion.
* @param aErrorCode will contain error if one occurs
* @return int rep of string value
*/
PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const;
PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const;
/**********************************************************************
/**********************************************************************
String manipulation methods...
*********************************************************************/
/**
/**
* Functionally equivalent to assign or operator=
*
*/
nsString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsString& SetString(const PRUnichar* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsString& SetString(const nsString& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsString& SetString(const PRUnichar* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsString& SetString(const nsString& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
/**
/**
* assign given string to this string
* @param aStr: buffer to be assigned to this
* @param alength is the length of the given str (or -1)
if you want me to determine its length
* @return this
*/
nsString& Assign(const nsStr& aString,PRInt32 aCount=-1);
nsString& Assign(const char* aString,PRInt32 aCount=-1);
nsString& Assign(const PRUnichar* aString,PRInt32 aCount=-1);
nsString& Assign(char aChar);
nsString& Assign(PRUnichar aChar);
nsString& Assign(const nsStr& aString,PRInt32 aCount=-1);
nsString& Assign(const char* aString,PRInt32 aCount=-1);
nsString& Assign(const PRUnichar* aString,PRInt32 aCount=-1);
nsString& Assign(char aChar);
nsString& Assign(PRUnichar aChar);
/**
/**
* here come a bunch of assignment operators...
* @param aString: string to be added to this
* @return this
*/
nsString& operator=(const nsString& aString) {return Assign(aString);}
nsString& operator=(const nsStr& aString) {return Assign(aString);}
nsString& operator=(char aChar) {return Assign(aChar);}
nsString& operator=(PRUnichar aChar) {return Assign(aChar);}
nsString& operator=(const char* aCString) {return Assign(aCString);}
nsString& operator=(const PRUnichar* aString) {return Assign(aString);}
#ifdef AIX
nsString& operator=(const nsSubsumeStr& aSubsumeString); // AIX requires a const here
#else
nsString& operator=(nsSubsumeStr& aSubsumeString);
#endif
nsString& operator=(const nsString& aString) {return Assign(aString);}
nsString& operator=(const nsStr& aString) {return Assign(aString);}
nsString& operator=(char aChar) {return Assign(aChar);}
nsString& operator=(PRUnichar aChar) {return Assign(aChar);}
nsString& operator=(const char* aCString) {return Assign(aCString);}
nsString& operator=(const PRUnichar* aString) {return Assign(aString);}
#ifdef AIX
nsString& operator=(const nsSubsumeStr& aSubsumeString); // AIX requires a const here
#else
nsString& operator=(nsSubsumeStr& aSubsumeString);
#endif
/**
/**
* Here's a bunch of methods that append varying types...
* @param various...
* @return this
*/
nsString& operator+=(const nsStr& aString){return Append(aString,aString.mLength);}
nsString& operator+=(const nsString& aString){return Append(aString,aString.mLength);}
nsString& operator+=(const char* aCString) {return Append(aCString);}
//nsString& operator+=(char aChar){return Append(aChar);}
nsString& operator+=(const PRUnichar* aUCString) {return Append(aUCString);}
nsString& operator+=(PRUnichar aChar){return Append(aChar);}
nsString& operator+=(const nsStr& aString){return Append(aString,aString.mLength);}
nsString& operator+=(const nsString& aString){return Append(aString,aString.mLength);}
nsString& operator+=(const char* aCString) {return Append(aCString);}
//nsString& operator+=(char aChar){return Append(aChar);}
nsString& operator+=(const PRUnichar* aUCString) {return Append(aUCString);}
nsString& operator+=(PRUnichar aChar){return Append(aChar);}
/*
/*
* Appends n characters from given string to this,
* This version computes the length of your given string
*
* @param aString is the source to be appended to this
* @return number of chars copied
*/
nsString& Append(const nsStr& aString) {return Append(aString,aString.mLength);}
nsString& Append(const nsString& aString) {return Append(aString,aString.mLength);}
nsString& Append(const nsStr& aString) {return Append(aString,aString.mLength);}
nsString& Append(const nsString& aString) {return Append(aString,aString.mLength);}
/*
/*
* Appends n characters from given string to this,
*
* @param aString is the source to be appended to this
* @param aCount -- number of chars to copy; -1 tells us to compute the strlen for you
* @return number of chars copied
*/
nsString& Append(const nsStr& aString,PRInt32 aCount);
nsString& Append(const nsString& aString,PRInt32 aCount);
nsString& Append(const char* aString,PRInt32 aCount=-1);
nsString& Append(const PRUnichar* aString,PRInt32 aCount=-1);
nsString& Append(char aChar);
nsString& Append(PRUnichar aChar);
nsString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16
nsString& Append(float aFloat);
nsString& Append(const nsStr& aString,PRInt32 aCount);
nsString& Append(const nsString& aString,PRInt32 aCount);
nsString& Append(const char* aString,PRInt32 aCount=-1);
nsString& Append(const PRUnichar* aString,PRInt32 aCount=-1);
nsString& Append(char aChar);
nsString& Append(PRUnichar aChar);
nsString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16
nsString& Append(float aFloat);
/*
/*
* Copies n characters from this string to given string,
* starting at the leftmost offset.
*
@@ -471,9 +474,9 @@ nsString& Append(float aFloat);
* @param aCount -- number of chars to copy
* @return number of chars copied
*/
PRUint32 Left(nsString& aCopy,PRInt32 aCount) const;
PRUint32 Left(nsString& aCopy,PRInt32 aCount) const;
/*
/*
* Copies n characters from this string to given string,
* starting at the given offset.
*
@@ -483,9 +486,9 @@ PRUint32 Left(nsString& aCopy,PRInt32 aCount) const;
* @param anOffset -- position where copying begins
* @return number of chars copied
*/
PRUint32 Mid(nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
PRUint32 Mid(nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
/*
/*
* Copies n characters from this string to given string,
* starting at rightmost char.
*
@@ -494,9 +497,9 @@ PRUint32 Mid(nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
* @param aCount -- number of chars to copy
* @return number of chars copied
*/
PRUint32 Right(nsString& aCopy,PRInt32 aCount) const;
PRUint32 Right(nsString& aCopy,PRInt32 aCount) const;
/*
/*
* This method inserts n chars from given string into this
* string at str[anOffset].
*
@@ -505,9 +508,9 @@ PRUint32 Right(nsString& aCopy,PRInt32 aCount) const;
* @param aCount -- number of chars to be copied from aCopy
* @return number of chars inserted into this.
*/
nsString& Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
nsString& Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
/**
/**
* Insert a given string into this string at
* a specified offset.
*
@@ -515,10 +518,10 @@ nsString& Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
* @param anOffset is insert pos in str
* @return the number of chars inserted into this string
*/
nsString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
nsString& Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
nsString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
nsString& Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
/**
/**
* Insert a single char into this string at
* a specified offset.
*
@@ -526,10 +529,10 @@ nsString& Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
* @param anOffset is insert pos in str
* @return the number of chars inserted into this string
*/
//nsString& Insert(char aChar,PRUint32 anOffset);
nsString& Insert(PRUnichar aChar,PRUint32 anOffset);
//nsString& Insert(char aChar,PRUint32 anOffset);
nsString& Insert(PRUnichar aChar,PRUint32 anOffset);
/*
/*
* This method is used to cut characters in this string
* starting at anOffset, continuing for aCount chars.
*
@@ -537,14 +540,14 @@ nsString& Insert(PRUnichar aChar,PRUint32 anOffset);
* @param aCount -- number of chars to be cut
* @return *this
*/
nsString& Cut(PRUint32 anOffset,PRInt32 aCount);
nsString& Cut(PRUint32 anOffset,PRInt32 aCount);
/**********************************************************************
/**********************************************************************
Searching methods...
*********************************************************************/
/**
/**
* Search for given character within this string.
* This method does so by using a binary search,
* so your string HAD BETTER BE ORDERED!
@@ -552,9 +555,9 @@ nsString& Cut(PRUint32 anOffset,PRInt32 aCount);
* @param aChar is the unicode char to be found
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 BinarySearch(PRUnichar aChar) const;
PRInt32 BinarySearch(PRUnichar aChar) const;
/**
/**
* Search for given substring within this string
*
* @param aString is substring to be sought in this
@@ -562,13 +565,13 @@ PRInt32 BinarySearch(PRUnichar aChar) const;
* @param anOffset tells us where in this strig to start searching
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
/**
/**
* Search for given char within this string
*
* @param aString is substring to be sought in this
@@ -576,34 +579,34 @@ PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffs
* @param aIgnoreCase selects case sensitivity
* @return find pos in string, or -1 (kNotFound)
*/
//PRInt32 Find(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
//PRInt32 Find(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
/**
/**
* This method searches this string for the first character
* found in the given charset
* @param aString contains set of chars to be found
* @param anOffset tells us where to start searching in this
* @return -1 if not found, else the offset in this
*/
PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
/**
/**
* This methods scans the string backwards, looking for the given string
* @param aString is substring to be sought in this
* @param aIgnoreCase tells us whether or not to do caseless compare
* @param anOffset tells us where in this strig to start searching (counting from left)
*/
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
/**
/**
* Search for given char within this string
*
* @param aString is substring to be sought in this
@@ -611,26 +614,26 @@ PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOff
* @param aIgnoreCase selects case sensitivity
* @return find pos in string, or -1 (kNotFound)
*/
//PRInt32 RFind(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
//PRInt32 RFind(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
/**
/**
* This method searches this string for the last character
* found in the given string
* @param aString contains set of chars to be found
* @param anOffset tells us where in this strig to start searching (counting from left)
* @return -1 if not found, else the offset in this
*/
PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
/**********************************************************************
/**********************************************************************
Comparison methods...
*********************************************************************/
/**
/**
* Compares a given string type to this string.
* @update gess 7/27/98
* @param S is the string to be compared
@@ -638,72 +641,72 @@ PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
* @param aCount tells us how many chars to compare
* @return -1,0,1
*/
virtual PRInt32 Compare(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
/**
/**
* These methods compare a given string type to this one
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator==(const nsString &aString) const;
PRBool operator==(const nsStr &aString) const;
PRBool operator==(const char *aString) const;
PRBool operator==(const PRUnichar* aString) const;
PRBool operator==(const nsString &aString) const;
PRBool operator==(const nsStr &aString) const;
PRBool operator==(const char *aString) const;
PRBool operator==(const PRUnichar* aString) const;
/**
/**
* These methods perform a !compare of a given string type to this
* @param aString is the string to be compared to this
* @return TRUE
*/
PRBool operator!=(const nsString &aString) const;
PRBool operator!=(const nsStr &aString) const;
PRBool operator!=(const char* aString) const;
PRBool operator!=(const PRUnichar* aString) const;
PRBool operator!=(const nsString &aString) const;
PRBool operator!=(const nsStr &aString) const;
PRBool operator!=(const char* aString) const;
PRBool operator!=(const PRUnichar* aString) const;
/**
/**
* These methods test if a given string is < than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator<(const nsString &aString) const;
PRBool operator<(const nsStr &aString) const;
PRBool operator<(const char* aString) const;
PRBool operator<(const PRUnichar* aString) const;
PRBool operator<(const nsString &aString) const;
PRBool operator<(const nsStr &aString) const;
PRBool operator<(const char* aString) const;
PRBool operator<(const PRUnichar* aString) const;
/**
/**
* These methods test if a given string is > than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator>(const nsString &aString) const;
PRBool operator>(const nsStr &S) const;
PRBool operator>(const char* aString) const;
PRBool operator>(const PRUnichar* aString) const;
PRBool operator>(const nsString &aString) const;
PRBool operator>(const nsStr &S) const;
PRBool operator>(const char* aString) const;
PRBool operator>(const PRUnichar* aString) const;
/**
/**
* These methods test if a given string is <= than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator<=(const nsString &aString) const;
PRBool operator<=(const nsStr &S) const;
PRBool operator<=(const char* aString) const;
PRBool operator<=(const PRUnichar* aString) const;
PRBool operator<=(const nsString &aString) const;
PRBool operator<=(const nsStr &S) const;
PRBool operator<=(const char* aString) const;
PRBool operator<=(const PRUnichar* aString) const;
/**
/**
* These methods test if a given string is >= than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator>=(const nsString &aString) const;
PRBool operator>=(const nsStr &S) const;
PRBool operator>=(const char* aString) const;
PRBool operator>=(const PRUnichar* aString) const;
PRBool operator>=(const nsString &aString) const;
PRBool operator>=(const nsStr &S) const;
PRBool operator>=(const char* aString) const;
PRBool operator>=(const PRUnichar* aString) const;
/**
/**
* Compare this to given string; note that we compare full strings here.
* The optional length argument just lets us know how long the given string is.
* If you provide a length, it is compared to length of this string as an
@@ -713,56 +716,53 @@ PRBool operator>=(const PRUnichar* aString) const;
* @param aCount -- number of chars to be compared.
* @return TRUE if equal
*/
PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const;
PRBool Equals(const PRUnichar* s1, const PRUnichar* s2,PRBool aIgnoreCase=PR_FALSE) const;
PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const;
PRBool Equals(const PRUnichar* s1, const PRUnichar* s2,PRBool aIgnoreCase=PR_FALSE) const;
PRBool EqualsIgnoreCase(const nsString& aString) const;
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const;
PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const;
PRBool EqualsIgnoreCase(const nsString& aString) const;
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const;
PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const;
/**
/**
* Determine if given buffer is plain ascii
*
* @param aBuffer -- if null, then we test *this, otherwise we test given buffer
* @return TRUE if is all ascii chars or if strlen==0
*/
PRBool IsASCII(const PRUnichar* aBuffer=0);
PRBool IsASCII(const PRUnichar* aBuffer=0);
/**
/**
* Determine if given char is a valid space character
*
* @param aChar is character to be tested
* @return TRUE if is valid space char
*/
static PRBool IsSpace(PRUnichar ch);
static PRBool IsSpace(PRUnichar ch);
/**
/**
* Determine if given char in valid alpha range
*
* @param aChar is character to be tested
* @return TRUE if in alpha range
*/
static PRBool IsAlpha(PRUnichar ch);
static PRBool IsAlpha(PRUnichar ch);
/**
/**
* Determine if given char is valid digit
*
* @param aChar is character to be tested
* @return TRUE if char is a valid digit
*/
static PRBool IsDigit(PRUnichar ch);
static PRBool IsDigit(PRUnichar ch);
static void Recycle(nsString* aString);
static nsString* CreateString(void);
nsIMemoryAgent* mAgent;
static void Recycle(nsString* aString);
static nsString* CreateString(void);
};

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;
//begin by skipping over leading chars that shouldn't be part of the number...
aRadix=kRadixUnknown; //assume for starters...
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;
}
else if((*cp>='A') && (*cp<='F')) {
aRadix=16;
break;
}
cp--;
}
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...
while(cp<endcp){
const char* pos=(const char*)memchr(validChars,*cp,len);
if(!pos) {
cp++;
while (--cp >= aString.mStr) {
if((*cp>='0') && (*cp<='9')){
continue;
}
else if((*cp>='A') && (*cp<='F')) {
continue;
else break;
}
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;
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;
}
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
}

View File

@@ -46,214 +46,217 @@ class NS_COM nsSubsumeCStr;
class NS_COM nsCString : public nsStr {
public:
public:
/**
/**
* Default constructor.
*/
nsCString(nsIMemoryAgent* anAgent=0);
nsCString();
/**
/**
* This constructor accepts an isolatin string
* @param aCString is a ptr to a 1-byte cstr
*/
nsCString(const char* aCString,PRInt32 aLength=-1,nsIMemoryAgent* anAgent=0);
nsCString(const char* aCString,PRInt32 aLength=-1);
/**
/**
* This constructor accepts a unichar string
* @param aCString is a ptr to a 2-byte cstr
*/
nsCString(const PRUnichar* aString,PRInt32 aLength=-1,nsIMemoryAgent* anAgent=0);
nsCString(const PRUnichar* aString,PRInt32 aLength=-1);
/**
/**
* This is a copy constructor that accepts an nsStr
* @param reference to another nsCString
*/
nsCString(const nsStr&,nsIMemoryAgent* anAgent=0);
nsCString(const nsStr&);
/**
/**
* This is our copy constructor
* @param reference to another nsCString
*/
nsCString(const nsCString& aString);
nsCString(const nsCString& aString);
/**
/**
* This constructor takes a subsumestr
* @param reference to subsumestr
*/
nsCString(nsSubsumeCStr& aSubsumeStr);
nsCString(nsSubsumeCStr& aSubsumeStr);
/**
/**
* Destructor
*
*/
virtual ~nsCString();
virtual ~nsCString();
/**
/**
* Retrieve the length of this string
* @return string length
*/
inline PRInt32 Length() const { return (PRInt32)mLength; }
inline PRInt32 Length() const { return (PRInt32)mLength; }
/**
/**
* Retrieve the size of this string
* @return string length
*/
virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
/**
/**
* Call this method if you want to force a different string capacity
* @update gess7/30/98
* @param aLength -- contains new length for mStr
* @return
*/
void SetLength(PRUint32 aLength) {
void SetLength(PRUint32 aLength) {
Truncate(aLength);
}
}
/**
/**
* Sets the new length of the string.
* @param aLength is new string length.
* @return nada
*/
void SetCapacity(PRUint32 aLength);
/**
void SetCapacity(PRUint32 aLength);
/**
* This method truncates this string to given length.
*
* @param anIndex -- new length of string
* @return nada
*/
void Truncate(PRInt32 anIndex=0);
void Truncate(PRInt32 anIndex=0);
/**
/**
* Determine whether or not the characters in this
* string are in sorted order.
*
* @return TRUE if ordered.
*/
PRBool IsOrdered(void) const;
PRBool IsOrdered(void) const;
/**
/**
* Determine whether or not this string has a length of 0
*
* @return TRUE if empty.
*/
PRBool IsEmpty(void) const {
PRBool IsEmpty(void) const {
return PRBool(0==mLength);
}
}
/**********************************************************************
/**********************************************************************
Accessor methods...
*********************************************************************/
const char* GetBuffer(void) const;
/**
* Retrieve const ptr to internal buffer; DO NOT TRY TO FREE IT!
*/
const char* GetBuffer(void) const;
/**
* Get nth character.
*/
PRUnichar operator[](PRUint32 anIndex) const;
PRUnichar CharAt(PRUint32 anIndex) const;
PRUnichar First(void) const;
PRUnichar Last(void) const;
PRUnichar operator[](PRUint32 anIndex) const;
PRUnichar CharAt(PRUint32 anIndex) const;
PRUnichar First(void) const;
PRUnichar Last(void) const;
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
/**********************************************************************
/**********************************************************************
String creation methods...
*********************************************************************/
/**
/**
* Create a new string by appending given string to this
* @param aString -- 2nd string to be appended
* @return new string
*/
nsSubsumeCStr operator+(const nsCString& aString);
nsSubsumeCStr operator+(const nsCString& aString);
/**
/**
* create a new string by adding this to the given char*.
* @param aCString is a ptr to cstring to be added to this
* @return newly created string
*/
nsSubsumeCStr operator+(const char* aCString);
nsSubsumeCStr operator+(const char* aCString);
/**
/**
* create a new string by adding this to the given char.
* @param aChar is a char to be added to this
* @return newly created string
*/
nsSubsumeCStr operator+(PRUnichar aChar);
nsSubsumeCStr operator+(char aChar);
nsSubsumeCStr operator+(PRUnichar aChar);
nsSubsumeCStr operator+(char aChar);
/**********************************************************************
/**********************************************************************
Lexomorphic transforms...
*********************************************************************/
/**
/**
* Converts chars in this to lowercase
* @update gess 7/27/98
*/
void ToLowerCase();
void ToLowerCase();
/**
/**
* Converts chars in this to lowercase, and
* stores them in aOut
* @update gess 7/27/98
* @param aOut is a string to contain result
*/
void ToLowerCase(nsCString& aString) const;
void ToLowerCase(nsCString& aString) const;
/**
/**
* Converts chars in this to uppercase
* @update gess 7/27/98
*/
void ToUpperCase();
void ToUpperCase();
/**
/**
* Converts chars in this to lowercase, and
* stores them in a given output string
* @update gess 7/27/98
* @param aOut is a string to contain result
*/
void ToUpperCase(nsCString& aString) const;
void ToUpperCase(nsCString& aString) const;
/**
/**
* This method is used to remove all occurances of the
* characters found in aSet from this string.
*
* @param aSet -- characters to be cut from this
* @return *this
*/
nsCString& StripChars(const char* aSet);
nsCString& StripChar(char aChar);
nsCString& StripChars(const char* aSet);
nsCString& StripChar(char aChar);
/**
/**
* This method strips whitespace throughout the string
*
* @return this
*/
nsCString& StripWhitespace();
nsCString& StripWhitespace();
/**
/**
* swaps occurence of 1 string for another
*
* @return this
*/
nsCString& ReplaceChar(PRUnichar aOldChar,PRUnichar aNewChar);
nsCString& ReplaceChar(const char* aSet,PRUnichar aNewChar);
nsCString& ReplaceChar(PRUnichar aOldChar,PRUnichar aNewChar);
nsCString& ReplaceChar(const char* aSet,PRUnichar aNewChar);
PRInt32 CountChar(PRUnichar aChar);
PRInt32 CountChar(PRUnichar aChar);
/**
/**
* This method trims characters found in aTrimSet from
* either end of the underlying string.
*
@@ -261,9 +264,9 @@ PRInt32 CountChar(PRUnichar aChar);
* both ends
* @return this
*/
nsCString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
nsCString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/**
/**
* This method strips whitespace from string.
* You can control whether whitespace is yanked from
* start and end of string as well.
@@ -272,9 +275,9 @@ nsCString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aElimin
* @param aEliminateTrailing controls stripping of trailing ws
* @return this
*/
nsCString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
nsCString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/**
/**
* This method strips whitespace from string.
* You can control whether whitespace is yanked from
* start and end of string as well.
@@ -283,142 +286,143 @@ nsCString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeadin
* @param aEliminateTrailing controls stripping of trailing ws
* @return this
*/
nsCString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
nsCString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/**********************************************************************
/**********************************************************************
string conversion methods...
*********************************************************************/
operator char*() {return mStr;}
operator const char*() const {return (const char*)mStr;}
/**
/**
* This method constructs a new nsCString that is a clone
* of this string.
*
*/
nsCString* ToNewString() const;
nsCString* ToNewString() const;
/**
/**
* Creates an ISOLatin1 clone of this string
* Note that calls to this method should be matched with calls to Recycle().
* @return ptr to new isolatin1 string
*/
char* ToNewCString() const;
char* ToNewCString() const;
/**
/**
* Creates a unicode clone of this string
* Note that calls to this method should be matched with calls to Recycle().
* @return ptr to new unicode string
*/
PRUnichar* ToNewUnicode() const;
PRUnichar* ToNewUnicode() const;
/**
/**
* Copies data from internal buffer onto given char* buffer
* NOTE: This only copies as many chars as will fit in given buffer (clips)
* @param aBuf is the buffer where data is stored
* @param aBuflength is the max # of chars to move to buffer
* @return ptr to given buffer
*/
char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const;
char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const;
/**
/**
* Perform string to float conversion.
* @param aErrorCode will contain error if one occurs
* @return float rep of string value
*/
float ToFloat(PRInt32* aErrorCode) const;
float ToFloat(PRInt32* aErrorCode) const;
/**
/**
* Try to derive the radix from the value contained in this string
* @return kRadix10, kRadix16 or kAutoDetect (meaning unknown)
*/
PRUint32 DetermineRadix(void);
PRUint32 DetermineRadix(void);
/**
/**
* Perform string to int conversion.
* @param aErrorCode will contain error if one occurs
* @return int rep of string value
*/
PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const;
PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const;
/**********************************************************************
/**********************************************************************
String manipulation methods...
*********************************************************************/
/**
/**
* Functionally equivalent to assign or operator=
*
*/
nsCString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsCString& SetString(const nsStr& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsCString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsCString& SetString(const nsStr& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
/**
/**
* assign given string to this string
* @param aStr: buffer to be assigned to this
* @param alength is the length of the given str (or -1)
if you want me to determine its length
* @return this
*/
nsCString& Assign(const nsStr& aString,PRInt32 aCount=-1);
nsCString& Assign(const char* aString,PRInt32 aCount=-1);
nsCString& Assign(const PRUnichar* aString,PRInt32 aCount=-1);
nsCString& Assign(PRUnichar aChar);
nsCString& Assign(char aChar);
nsCString& Assign(const nsStr& aString,PRInt32 aCount=-1);
nsCString& Assign(const char* aString,PRInt32 aCount=-1);
nsCString& Assign(const PRUnichar* aString,PRInt32 aCount=-1);
nsCString& Assign(PRUnichar aChar);
nsCString& Assign(char aChar);
/**
/**
* here come a bunch of assignment operators...
* @param aString: string to be added to this
* @return this
*/
nsCString& operator=(const nsCString& aString) {return Assign(aString);}
nsCString& operator=(const nsStr& aString) {return Assign(aString);}
nsCString& operator=(PRUnichar aChar) {return Assign(aChar);}
nsCString& operator=(char aChar) {return Assign(aChar);}
nsCString& operator=(const char* aCString) {return Assign(aCString);}
nsCString& operator=(const PRUnichar* aString) {return Assign(aString);}
#ifdef AIX
nsCString& operator=(const nsSubsumeCStr& aSubsumeString); // AIX requires a const here
#else
nsCString& operator=(nsSubsumeCStr& aSubsumeString);
#endif
nsCString& operator=(const nsCString& aString) {return Assign(aString);}
nsCString& operator=(const nsStr& aString) {return Assign(aString);}
nsCString& operator=(PRUnichar aChar) {return Assign(aChar);}
nsCString& operator=(char aChar) {return Assign(aChar);}
nsCString& operator=(const char* aCString) {return Assign(aCString);}
nsCString& operator=(const PRUnichar* aString) {return Assign(aString);}
#ifdef AIX
nsCString& operator=(const nsSubsumeCStr& aSubsumeString); // AIX requires a const here
#else
nsCString& operator=(nsSubsumeCStr& aSubsumeString);
#endif
/**
/**
* Here's a bunch of methods that append varying types...
* @param various...
* @return this
*/
nsCString& operator+=(const nsCString& aString){return Append(aString,aString.mLength);}
nsCString& operator+=(const char* aCString) {return Append(aCString);}
nsCString& operator+=(PRUnichar aChar){return Append(aChar);}
nsCString& operator+=(char aChar){return Append(aChar);}
nsCString& operator+=(const nsCString& aString){return Append(aString,aString.mLength);}
nsCString& operator+=(const char* aCString) {return Append(aCString);}
nsCString& operator+=(PRUnichar aChar){return Append(aChar);}
nsCString& operator+=(char aChar){return Append(aChar);}
/*
/*
* Appends n characters from given string to this,
* This version computes the length of your given string
*
* @param aString is the source to be appended to this
* @return number of chars copied
*/
nsCString& Append(const nsCString& aString) {return Append(aString,aString.mLength);}
nsCString& Append(const nsCString& aString) {return Append(aString,aString.mLength);}
/*
/*
* Appends n characters from given string to this,
*
* @param aString is the source to be appended to this
* @param aCount -- number of chars to copy; -1 tells us to compute the strlen for you
* @return number of chars copied
*/
nsCString& Append(const nsCString& aString,PRInt32 aCount);
nsCString& Append(const char* aString,PRInt32 aCount=-1);
nsCString& Append(PRUnichar aChar);
nsCString& Append(char aChar);
nsCString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16
nsCString& Append(float aFloat);
nsCString& Append(const nsCString& aString,PRInt32 aCount);
nsCString& Append(const nsStr& aString,PRInt32 aCount=-1);
nsCString& Append(const char* aString,PRInt32 aCount=-1);
nsCString& Append(PRUnichar aChar);
nsCString& Append(char aChar);
nsCString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16
nsCString& Append(float aFloat);
/*
/*
* Copies n characters from this string to given string,
* starting at the leftmost offset.
*
@@ -427,9 +431,9 @@ nsCString& Append(float aFloat);
* @param aCount -- number of chars to copy
* @return number of chars copied
*/
PRUint32 Left(nsCString& aCopy,PRInt32 aCount) const;
PRUint32 Left(nsCString& aCopy,PRInt32 aCount) const;
/*
/*
* Copies n characters from this string to given string,
* starting at the given offset.
*
@@ -439,9 +443,9 @@ PRUint32 Left(nsCString& aCopy,PRInt32 aCount) const;
* @param anOffset -- position where copying begins
* @return number of chars copied
*/
PRUint32 Mid(nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
PRUint32 Mid(nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
/*
/*
* Copies n characters from this string to given string,
* starting at rightmost char.
*
@@ -450,9 +454,9 @@ PRUint32 Mid(nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
* @param aCount -- number of chars to copy
* @return number of chars copied
*/
PRUint32 Right(nsCString& aCopy,PRInt32 aCount) const;
PRUint32 Right(nsCString& aCopy,PRInt32 aCount) const;
/*
/*
* This method inserts n chars from given string into this
* string at str[anOffset].
*
@@ -461,9 +465,9 @@ PRUint32 Right(nsCString& aCopy,PRInt32 aCount) const;
* @param aCount -- number of chars to be copied from aCopy
* @return number of chars inserted into this.
*/
nsCString& Insert(const nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
nsCString& Insert(const nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
/**
/**
* Insert a given string into this string at
* a specified offset.
*
@@ -471,9 +475,9 @@ nsCString& Insert(const nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
* @param anOffset is insert pos in str
* @return the number of chars inserted into this string
*/
nsCString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
nsCString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
/**
/**
* Insert a single char into this string at
* a specified offset.
*
@@ -481,10 +485,10 @@ nsCString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
* @param anOffset is insert pos in str
* @return the number of chars inserted into this string
*/
nsCString& Insert(PRUnichar aChar,PRUint32 anOffset);
nsCString& Insert(char aChar,PRUint32 anOffset);
nsCString& Insert(PRUnichar aChar,PRUint32 anOffset);
nsCString& Insert(char aChar,PRUint32 anOffset);
/*
/*
* This method is used to cut characters in this string
* starting at anOffset, continuing for aCount chars.
*
@@ -492,14 +496,14 @@ nsCString& Insert(char aChar,PRUint32 anOffset);
* @param aCount -- number of chars to be cut
* @return *this
*/
nsCString& Cut(PRUint32 anOffset,PRInt32 aCount);
nsCString& Cut(PRUint32 anOffset,PRInt32 aCount);
/**********************************************************************
/**********************************************************************
Searching methods...
*********************************************************************/
/**
/**
* Search for given character within this string.
* This method does so by using a binary search,
* so your string HAD BETTER BE ORDERED!
@@ -507,9 +511,9 @@ nsCString& Cut(PRUint32 anOffset,PRInt32 aCount);
* @param aChar is the unicode char to be found
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 BinarySearch(PRUnichar aChar) const;
PRInt32 BinarySearch(PRUnichar aChar) const;
/**
/**
* Search for given substring within this string
*
* @param aString is substring to be sought in this
@@ -517,11 +521,11 @@ PRInt32 BinarySearch(PRUnichar aChar) const;
* @param anOffset tells us where in this strig to start searching
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
/**
/**
* Search for given char within this string
*
* @param aString is substring to be sought in this
@@ -529,32 +533,32 @@ PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffs
* @param aIgnoreCase selects case sensitivity
* @return find pos in string, or -1 (kNotFound)
*/
PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
/**
/**
* This method searches this string for the first character
* found in the given charset
* @param aString contains set of chars to be found
* @param anOffset tells us where to start searching in this
* @return -1 if not found, else the offset in this
*/
PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
/**
/**
* This methods scans the string backwards, looking for the given string
* @param aString is substring to be sought in this
* @param aIgnoreCase tells us whether or not to do caseless compare
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
/**
/**
* Search for given char within this string
*
* @param aString is substring to be sought in this
@@ -562,26 +566,26 @@ PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOff
* @param aIgnoreCase selects case sensitivity
* @return find pos in string, or -1 (kNotFound)
*/
PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
/**
/**
* This method searches this string for the last character
* found in the given string
* @param aString contains set of chars to be found
* @param anOffset tells us where to start searching in this
* @return -1 if not found, else the offset in this
*/
PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
/**********************************************************************
/**********************************************************************
Comparison methods...
*********************************************************************/
/**
/**
* Compares a given string type to this string.
* @update gess 7/27/98
* @param S is the string to be compared
@@ -589,65 +593,65 @@ PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
* @param aCount tells us how many chars to compare
* @return -1,0,1
*/
virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
/**
/**
* These methods compare a given string type to this one
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator==(const nsStr &aString) const;
PRBool operator==(const char* aString) const;
PRBool operator==(const PRUnichar* aString) const;
PRBool operator==(const nsStr &aString) const;
PRBool operator==(const char* aString) const;
PRBool operator==(const PRUnichar* aString) const;
/**
/**
* These methods perform a !compare of a given string type to this
* @param aString is the string to be compared to this
* @return TRUE
*/
PRBool operator!=(const nsStr &aString) const;
PRBool operator!=(const char* aString) const;
PRBool operator!=(const PRUnichar* aString) const;
PRBool operator!=(const nsStr &aString) const;
PRBool operator!=(const char* aString) const;
PRBool operator!=(const PRUnichar* aString) const;
/**
/**
* These methods test if a given string is < than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator<(const nsStr &aString) const;
PRBool operator<(const char* aString) const;
PRBool operator<(const PRUnichar* aString) const;
PRBool operator<(const nsStr &aString) const;
PRBool operator<(const char* aString) const;
PRBool operator<(const PRUnichar* aString) const;
/**
/**
* These methods test if a given string is > than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator>(const nsStr &S) const;
PRBool operator>(const char* aString) const;
PRBool operator>(const PRUnichar* aString) const;
PRBool operator>(const nsStr &S) const;
PRBool operator>(const char* aString) const;
PRBool operator>(const PRUnichar* aString) const;
/**
/**
* These methods test if a given string is <= than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator<=(const nsStr &S) const;
PRBool operator<=(const char* aString) const;
PRBool operator<=(const PRUnichar* aString) const;
PRBool operator<=(const nsStr &S) const;
PRBool operator<=(const char* aString) const;
PRBool operator<=(const PRUnichar* aString) const;
/**
/**
* These methods test if a given string is >= than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator>=(const nsStr &S) const;
PRBool operator>=(const char* aString) const;
PRBool operator>=(const PRUnichar* aString) const;
PRBool operator>=(const nsStr &S) const;
PRBool operator>=(const char* aString) const;
PRBool operator>=(const PRUnichar* aString) const;
/**
/**
* Compare this to given string; note that we compare full strings here.
* The optional length argument just lets us know how long the given string is.
* If you provide a length, it is compared to length of this string as an
@@ -657,21 +661,18 @@ PRBool operator>=(const PRUnichar* aString) const;
* @param aCount -- number of chars in given string you want to compare
* @return TRUE if equal
*/
PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(const nsStr& aString) const;
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(const nsStr& aString) const;
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const;
static void Recycle(nsCString* aString);
static nsCString* CreateString(void);
nsIMemoryAgent* mAgent;
static void Recycle(nsCString* aString);
static nsCString* CreateString(void);
};

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;
//begin by skipping over leading chars that shouldn't be part of the number...
aRadix=kRadixUnknown; //assume for starters...
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;
}
else if((*cp>='A') && (*cp<='F')) {
aRadix=16;
break;
}
cp--;
}
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...
while(cp<endcp){
const char* pos=(const char*)memchr(validChars,*cp,len);
if(!pos) {
cp++;
while (--cp >= aString.mStr) {
if((*cp>='0') && (*cp<='9')){
continue;
}
else if((*cp>='A') && (*cp<='F')) {
continue;
else break;
}
else if((*cp=='-') || (*cp=='+')){
break;
while(cp<endcp){
char theChar=toupper(*cp);
if((theChar>='0') && (theChar<='9')) {
*to++=theChar;
}
else {
if(('#'==(*cp)) || ('X'==(*cp)))
aRadix=kRadix16;
cp++; //move back by one
break;
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;
}
if(cp>aString.mStr)
aString.Cut(0,cp-aString.mStr);
PRInt32 result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK;
return result;
}
@@ -865,9 +866,9 @@ 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){
@@ -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
}

View File

@@ -53,242 +53,245 @@ class nsISizeOfHandler;
class NS_COM nsSubsumeStr;
class NS_COM nsString : public nsStr {
public:
public:
/**
/**
* Default constructor.
*/
nsString(nsIMemoryAgent* anAgent=0);
nsString();
/**
/**
* This constructor accepts an isolatin string
* @param aCString is a ptr to a 1-byte cstr
*/
nsString(const char* aCString,nsIMemoryAgent* anAgent=0);
nsString(const char* aCString);
/**
/**
* This constructor accepts a unichar string
* @param aCString is a ptr to a 2-byte cstr
*/
nsString(const PRUnichar* aString,nsIMemoryAgent* anAgent=0);
nsString(const PRUnichar* aString);
/**
/**
* This is a copy constructor that accepts an nsStr
* @param reference to another nsString
*/
nsString(const nsStr&,nsIMemoryAgent* anAgent=0);
nsString(const nsStr&);
/**
/**
* This is our copy constructor
* @param reference to another nsString
*/
nsString(const nsString& aString);
nsString(const nsString& aString);
/**
/**
* This constructor takes a subsumestr
* @param reference to subsumestr
*/
nsString(nsSubsumeStr& aSubsumeStr);
nsString(nsSubsumeStr& aSubsumeStr);
/**
/**
* Destructor
*
*/
virtual ~nsString();
virtual ~nsString();
/**
/**
* Retrieve the length of this string
* @return string length
*/
inline PRInt32 Length() const { return (PRInt32)mLength; }
inline PRInt32 Length() const { return (PRInt32)mLength; }
/**
/**
* Retrieve the size of this string
* @return string length
*/
virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
/**
/**
* Call this method if you want to force a different string length
* @update gess7/30/98
* @param aLength -- contains new length for mStr
* @return
*/
void SetLength(PRUint32 aLength) {
void SetLength(PRUint32 aLength) {
Truncate(aLength);
}
}
/**
/**
* Sets the new length of the string.
* @param aLength is new string length.
* @return nada
*/
void SetCapacity(PRUint32 aLength);
void SetCapacity(PRUint32 aLength);
/**
/**
* This method truncates this string to given length.
*
* @param anIndex -- new length of string
* @return nada
*/
void Truncate(PRInt32 anIndex=0);
void Truncate(PRInt32 anIndex=0);
/**
/**
* Determine whether or not the characters in this
* string are in sorted order.
*
* @return TRUE if ordered.
*/
PRBool IsOrdered(void) const;
PRBool IsOrdered(void) const;
/**
/**
* Determine whether or not the characters in this
* string are in store as 1 or 2 byte (unicode) strings.
*
* @return TRUE if ordered.
*/
PRBool IsUnicode(void) const {
PRBool IsUnicode(void) const {
PRBool result=PRBool(mCharSize==eTwoByte);
return result;
}
}
/**
/**
* Determine whether or not this string has a length of 0
*
* @return TRUE if empty.
*/
PRBool IsEmpty(void) const {
PRBool IsEmpty(void) const {
return PRBool(0==mLength);
}
}
/**********************************************************************
/**********************************************************************
Getters/Setters...
*********************************************************************/
const char* GetBuffer(void) const;
const PRUnichar* GetUnicode(void) const;
/**
* Retrieve const ptr to internal buffer; DO NOT TRY TO FREE IT!
*/
const char* GetBuffer(void) const;
const PRUnichar* GetUnicode(void) const;
/**
* Get nth character.
*/
PRUnichar operator[](PRUint32 anIndex) const;
PRUnichar CharAt(PRUint32 anIndex) const;
PRUnichar First(void) const;
PRUnichar Last(void) const;
PRUnichar operator[](PRUint32 anIndex) const;
PRUnichar CharAt(PRUint32 anIndex) const;
PRUnichar First(void) const;
PRUnichar Last(void) const;
/**
* Set nth character.
*/
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
/**********************************************************************
/**********************************************************************
String concatenation methods...
*********************************************************************/
/**
/**
* Create a new string by appending given string to this
* @param aString -- 2nd string to be appended
* @return new subsumable string
*/
nsSubsumeStr operator+(const nsStr& aString);
nsSubsumeStr operator+(const nsString& aString);
nsSubsumeStr operator+(const nsStr& aString);
nsSubsumeStr operator+(const nsString& aString);
/**
/**
* create a new string by adding this to the given cstring
* @param aCString is a ptr to cstring to be added to this
* @return newly created string
*/
nsSubsumeStr operator+(const char* aCString);
nsSubsumeStr operator+(const char* aCString);
/**
/**
* create a new string by adding this to the given prunichar*.
* @param aString is a ptr to UC-string to be added to this
* @return newly created string
*/
nsSubsumeStr operator+(const PRUnichar* aString);
nsSubsumeStr operator+(const PRUnichar* aString);
/**
/**
* create a new string by adding this to the given char.
* @param aChar is a char to be added to this
* @return newly created string
*/
nsSubsumeStr operator+(char aChar);
nsSubsumeStr operator+(char aChar);
/**
/**
* create a new string by adding this to the given char.
* @param aChar is a unichar to be added to this
* @return newly created string
*/
nsSubsumeStr operator+(PRUnichar aChar);
nsSubsumeStr operator+(PRUnichar aChar);
/**********************************************************************
/**********************************************************************
Lexomorphic transforms...
*********************************************************************/
/**
/**
* Converts chars in this to lowercase
* @update gess 7/27/98
*/
void ToLowerCase();
void ToLowerCase();
/**
/**
* Converts chars in this to lowercase, and
* stores them in aOut
* @update gess 7/27/98
* @param aOut is a string to contain result
*/
void ToLowerCase(nsString& aString) const;
void ToLowerCase(nsString& aString) const;
/**
/**
* Converts chars in this to uppercase
* @update gess 7/27/98
*/
void ToUpperCase();
void ToUpperCase();
/**
/**
* Converts chars in this to lowercase, and
* stores them in a given output string
* @update gess 7/27/98
* @param aOut is a string to contain result
*/
void ToUpperCase(nsString& aString) const;
void ToUpperCase(nsString& aString) const;
/**
/**
* This method is used to remove all occurances of the
* characters found in aSet from this string.
*
* @param aSet -- characters to be cut from this
* @return *this
*/
nsString& StripChars(const char* aSet);
nsString& StripChar(char aChar);
nsString& StripChars(const char* aSet);
nsString& StripChar(char aChar);
/**
/**
* This method strips whitespace throughout the string
*
* @return this
*/
nsString& StripWhitespace();
nsString& StripWhitespace();
/**
/**
* swaps occurence of 1 string for another
*
* @return this
*/
nsString& ReplaceChar(PRUnichar anOldChar,PRUnichar aNewChar);
nsString& ReplaceChar(const char* aSet,PRUnichar aNewChar);
nsString& ReplaceChar(PRUnichar anOldChar,PRUnichar aNewChar);
nsString& ReplaceChar(const char* aSet,PRUnichar aNewChar);
PRInt32 CountChar(PRUnichar aChar);
PRInt32 CountChar(PRUnichar aChar);
/**
/**
* This method trims characters found in aTrimSet from
* either end of the underlying string.
*
@@ -296,9 +299,9 @@ PRInt32 CountChar(PRUnichar aChar);
* both ends
* @return this
*/
nsString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
nsString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/**
/**
* This method strips whitespace from string.
* You can control whether whitespace is yanked from
* start and end of string as well.
@@ -307,9 +310,9 @@ nsString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aElimina
* @param aEliminateTrailing controls stripping of trailing ws
* @return this
*/
nsString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
nsString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/**
/**
* This method strips whitespace from string.
* You can control whether whitespace is yanked from
* start and end of string as well.
@@ -318,151 +321,151 @@ nsString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading
* @param aEliminateTrailing controls stripping of trailing ws
* @return this
*/
nsString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
nsString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/**********************************************************************
/**********************************************************************
string conversion methods...
*********************************************************************/
/**
/**
* This method constructs a new nsString is a clone of this string.
*
*/
nsString* ToNewString() const;
nsString* ToNewString() const;
/**
/**
* Creates an ISOLatin1 clone of this string
* Note that calls to this method should be matched with calls to Recycle().
* @return ptr to new isolatin1 string
*/
char* ToNewCString() const;
char* ToNewCString() const;
/**
/**
* Creates an UTF8 clone of this string
* Note that calls to this method should be matched with calls to Recycle().
* @return ptr to new isolatin1 string
*/
char* ToNewUTF8String() const;
char* ToNewUTF8String() const;
/**
/**
* Creates a unicode clone of this string
* Note that calls to this method should be matched with calls to Recycle().
* @return ptr to new unicode string
*/
PRUnichar* ToNewUnicode() const;
PRUnichar* ToNewUnicode() const;
/**
/**
* Copies data from internal buffer onto given char* buffer
* NOTE: This only copies as many chars as will fit in given buffer (clips)
* @param aBuf is the buffer where data is stored
* @param aBuflength is the max # of chars to move to buffer
* @return ptr to given buffer
*/
char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const;
char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const;
/**
/**
* Perform string to float conversion.
* @param aErrorCode will contain error if one occurs
* @return float rep of string value
*/
float ToFloat(PRInt32* aErrorCode) const;
float ToFloat(PRInt32* aErrorCode) const;
/**
/**
* Try to derive the radix from the value contained in this string
* @return kRadix10, kRadix16 or kAutoDetect (meaning unknown)
*/
PRUint32 DetermineRadix(void);
PRUint32 DetermineRadix(void);
/**
/**
* Perform string to int conversion.
* @param aErrorCode will contain error if one occurs
* @return int rep of string value
*/
PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const;
PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const;
/**********************************************************************
/**********************************************************************
String manipulation methods...
*********************************************************************/
/**
/**
* Functionally equivalent to assign or operator=
*
*/
nsString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsString& SetString(const PRUnichar* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsString& SetString(const nsString& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsString& SetString(const PRUnichar* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsString& SetString(const nsString& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
/**
/**
* assign given string to this string
* @param aStr: buffer to be assigned to this
* @param alength is the length of the given str (or -1)
if you want me to determine its length
* @return this
*/
nsString& Assign(const nsStr& aString,PRInt32 aCount=-1);
nsString& Assign(const char* aString,PRInt32 aCount=-1);
nsString& Assign(const PRUnichar* aString,PRInt32 aCount=-1);
nsString& Assign(char aChar);
nsString& Assign(PRUnichar aChar);
nsString& Assign(const nsStr& aString,PRInt32 aCount=-1);
nsString& Assign(const char* aString,PRInt32 aCount=-1);
nsString& Assign(const PRUnichar* aString,PRInt32 aCount=-1);
nsString& Assign(char aChar);
nsString& Assign(PRUnichar aChar);
/**
/**
* here come a bunch of assignment operators...
* @param aString: string to be added to this
* @return this
*/
nsString& operator=(const nsString& aString) {return Assign(aString);}
nsString& operator=(const nsStr& aString) {return Assign(aString);}
nsString& operator=(char aChar) {return Assign(aChar);}
nsString& operator=(PRUnichar aChar) {return Assign(aChar);}
nsString& operator=(const char* aCString) {return Assign(aCString);}
nsString& operator=(const PRUnichar* aString) {return Assign(aString);}
#ifdef AIX
nsString& operator=(const nsSubsumeStr& aSubsumeString); // AIX requires a const here
#else
nsString& operator=(nsSubsumeStr& aSubsumeString);
#endif
nsString& operator=(const nsString& aString) {return Assign(aString);}
nsString& operator=(const nsStr& aString) {return Assign(aString);}
nsString& operator=(char aChar) {return Assign(aChar);}
nsString& operator=(PRUnichar aChar) {return Assign(aChar);}
nsString& operator=(const char* aCString) {return Assign(aCString);}
nsString& operator=(const PRUnichar* aString) {return Assign(aString);}
#ifdef AIX
nsString& operator=(const nsSubsumeStr& aSubsumeString); // AIX requires a const here
#else
nsString& operator=(nsSubsumeStr& aSubsumeString);
#endif
/**
/**
* Here's a bunch of methods that append varying types...
* @param various...
* @return this
*/
nsString& operator+=(const nsStr& aString){return Append(aString,aString.mLength);}
nsString& operator+=(const nsString& aString){return Append(aString,aString.mLength);}
nsString& operator+=(const char* aCString) {return Append(aCString);}
//nsString& operator+=(char aChar){return Append(aChar);}
nsString& operator+=(const PRUnichar* aUCString) {return Append(aUCString);}
nsString& operator+=(PRUnichar aChar){return Append(aChar);}
nsString& operator+=(const nsStr& aString){return Append(aString,aString.mLength);}
nsString& operator+=(const nsString& aString){return Append(aString,aString.mLength);}
nsString& operator+=(const char* aCString) {return Append(aCString);}
//nsString& operator+=(char aChar){return Append(aChar);}
nsString& operator+=(const PRUnichar* aUCString) {return Append(aUCString);}
nsString& operator+=(PRUnichar aChar){return Append(aChar);}
/*
/*
* Appends n characters from given string to this,
* This version computes the length of your given string
*
* @param aString is the source to be appended to this
* @return number of chars copied
*/
nsString& Append(const nsStr& aString) {return Append(aString,aString.mLength);}
nsString& Append(const nsString& aString) {return Append(aString,aString.mLength);}
nsString& Append(const nsStr& aString) {return Append(aString,aString.mLength);}
nsString& Append(const nsString& aString) {return Append(aString,aString.mLength);}
/*
/*
* Appends n characters from given string to this,
*
* @param aString is the source to be appended to this
* @param aCount -- number of chars to copy; -1 tells us to compute the strlen for you
* @return number of chars copied
*/
nsString& Append(const nsStr& aString,PRInt32 aCount);
nsString& Append(const nsString& aString,PRInt32 aCount);
nsString& Append(const char* aString,PRInt32 aCount=-1);
nsString& Append(const PRUnichar* aString,PRInt32 aCount=-1);
nsString& Append(char aChar);
nsString& Append(PRUnichar aChar);
nsString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16
nsString& Append(float aFloat);
nsString& Append(const nsStr& aString,PRInt32 aCount);
nsString& Append(const nsString& aString,PRInt32 aCount);
nsString& Append(const char* aString,PRInt32 aCount=-1);
nsString& Append(const PRUnichar* aString,PRInt32 aCount=-1);
nsString& Append(char aChar);
nsString& Append(PRUnichar aChar);
nsString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16
nsString& Append(float aFloat);
/*
/*
* Copies n characters from this string to given string,
* starting at the leftmost offset.
*
@@ -471,9 +474,9 @@ nsString& Append(float aFloat);
* @param aCount -- number of chars to copy
* @return number of chars copied
*/
PRUint32 Left(nsString& aCopy,PRInt32 aCount) const;
PRUint32 Left(nsString& aCopy,PRInt32 aCount) const;
/*
/*
* Copies n characters from this string to given string,
* starting at the given offset.
*
@@ -483,9 +486,9 @@ PRUint32 Left(nsString& aCopy,PRInt32 aCount) const;
* @param anOffset -- position where copying begins
* @return number of chars copied
*/
PRUint32 Mid(nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
PRUint32 Mid(nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
/*
/*
* Copies n characters from this string to given string,
* starting at rightmost char.
*
@@ -494,9 +497,9 @@ PRUint32 Mid(nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
* @param aCount -- number of chars to copy
* @return number of chars copied
*/
PRUint32 Right(nsString& aCopy,PRInt32 aCount) const;
PRUint32 Right(nsString& aCopy,PRInt32 aCount) const;
/*
/*
* This method inserts n chars from given string into this
* string at str[anOffset].
*
@@ -505,9 +508,9 @@ PRUint32 Right(nsString& aCopy,PRInt32 aCount) const;
* @param aCount -- number of chars to be copied from aCopy
* @return number of chars inserted into this.
*/
nsString& Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
nsString& Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
/**
/**
* Insert a given string into this string at
* a specified offset.
*
@@ -515,10 +518,10 @@ nsString& Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
* @param anOffset is insert pos in str
* @return the number of chars inserted into this string
*/
nsString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
nsString& Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
nsString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
nsString& Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
/**
/**
* Insert a single char into this string at
* a specified offset.
*
@@ -526,10 +529,10 @@ nsString& Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
* @param anOffset is insert pos in str
* @return the number of chars inserted into this string
*/
//nsString& Insert(char aChar,PRUint32 anOffset);
nsString& Insert(PRUnichar aChar,PRUint32 anOffset);
//nsString& Insert(char aChar,PRUint32 anOffset);
nsString& Insert(PRUnichar aChar,PRUint32 anOffset);
/*
/*
* This method is used to cut characters in this string
* starting at anOffset, continuing for aCount chars.
*
@@ -537,14 +540,14 @@ nsString& Insert(PRUnichar aChar,PRUint32 anOffset);
* @param aCount -- number of chars to be cut
* @return *this
*/
nsString& Cut(PRUint32 anOffset,PRInt32 aCount);
nsString& Cut(PRUint32 anOffset,PRInt32 aCount);
/**********************************************************************
/**********************************************************************
Searching methods...
*********************************************************************/
/**
/**
* Search for given character within this string.
* This method does so by using a binary search,
* so your string HAD BETTER BE ORDERED!
@@ -552,9 +555,9 @@ nsString& Cut(PRUint32 anOffset,PRInt32 aCount);
* @param aChar is the unicode char to be found
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 BinarySearch(PRUnichar aChar) const;
PRInt32 BinarySearch(PRUnichar aChar) const;
/**
/**
* Search for given substring within this string
*
* @param aString is substring to be sought in this
@@ -562,13 +565,13 @@ PRInt32 BinarySearch(PRUnichar aChar) const;
* @param anOffset tells us where in this strig to start searching
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
/**
/**
* Search for given char within this string
*
* @param aString is substring to be sought in this
@@ -576,34 +579,34 @@ PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffs
* @param aIgnoreCase selects case sensitivity
* @return find pos in string, or -1 (kNotFound)
*/
//PRInt32 Find(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
//PRInt32 Find(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
/**
/**
* This method searches this string for the first character
* found in the given charset
* @param aString contains set of chars to be found
* @param anOffset tells us where to start searching in this
* @return -1 if not found, else the offset in this
*/
PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
/**
/**
* This methods scans the string backwards, looking for the given string
* @param aString is substring to be sought in this
* @param aIgnoreCase tells us whether or not to do caseless compare
* @param anOffset tells us where in this strig to start searching (counting from left)
*/
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
/**
/**
* Search for given char within this string
*
* @param aString is substring to be sought in this
@@ -611,26 +614,26 @@ PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOff
* @param aIgnoreCase selects case sensitivity
* @return find pos in string, or -1 (kNotFound)
*/
//PRInt32 RFind(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
//PRInt32 RFind(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
/**
/**
* This method searches this string for the last character
* found in the given string
* @param aString contains set of chars to be found
* @param anOffset tells us where in this strig to start searching (counting from left)
* @return -1 if not found, else the offset in this
*/
PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
/**********************************************************************
/**********************************************************************
Comparison methods...
*********************************************************************/
/**
/**
* Compares a given string type to this string.
* @update gess 7/27/98
* @param S is the string to be compared
@@ -638,72 +641,72 @@ PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
* @param aCount tells us how many chars to compare
* @return -1,0,1
*/
virtual PRInt32 Compare(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
/**
/**
* These methods compare a given string type to this one
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator==(const nsString &aString) const;
PRBool operator==(const nsStr &aString) const;
PRBool operator==(const char *aString) const;
PRBool operator==(const PRUnichar* aString) const;
PRBool operator==(const nsString &aString) const;
PRBool operator==(const nsStr &aString) const;
PRBool operator==(const char *aString) const;
PRBool operator==(const PRUnichar* aString) const;
/**
/**
* These methods perform a !compare of a given string type to this
* @param aString is the string to be compared to this
* @return TRUE
*/
PRBool operator!=(const nsString &aString) const;
PRBool operator!=(const nsStr &aString) const;
PRBool operator!=(const char* aString) const;
PRBool operator!=(const PRUnichar* aString) const;
PRBool operator!=(const nsString &aString) const;
PRBool operator!=(const nsStr &aString) const;
PRBool operator!=(const char* aString) const;
PRBool operator!=(const PRUnichar* aString) const;
/**
/**
* These methods test if a given string is < than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator<(const nsString &aString) const;
PRBool operator<(const nsStr &aString) const;
PRBool operator<(const char* aString) const;
PRBool operator<(const PRUnichar* aString) const;
PRBool operator<(const nsString &aString) const;
PRBool operator<(const nsStr &aString) const;
PRBool operator<(const char* aString) const;
PRBool operator<(const PRUnichar* aString) const;
/**
/**
* These methods test if a given string is > than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator>(const nsString &aString) const;
PRBool operator>(const nsStr &S) const;
PRBool operator>(const char* aString) const;
PRBool operator>(const PRUnichar* aString) const;
PRBool operator>(const nsString &aString) const;
PRBool operator>(const nsStr &S) const;
PRBool operator>(const char* aString) const;
PRBool operator>(const PRUnichar* aString) const;
/**
/**
* These methods test if a given string is <= than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator<=(const nsString &aString) const;
PRBool operator<=(const nsStr &S) const;
PRBool operator<=(const char* aString) const;
PRBool operator<=(const PRUnichar* aString) const;
PRBool operator<=(const nsString &aString) const;
PRBool operator<=(const nsStr &S) const;
PRBool operator<=(const char* aString) const;
PRBool operator<=(const PRUnichar* aString) const;
/**
/**
* These methods test if a given string is >= than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator>=(const nsString &aString) const;
PRBool operator>=(const nsStr &S) const;
PRBool operator>=(const char* aString) const;
PRBool operator>=(const PRUnichar* aString) const;
PRBool operator>=(const nsString &aString) const;
PRBool operator>=(const nsStr &S) const;
PRBool operator>=(const char* aString) const;
PRBool operator>=(const PRUnichar* aString) const;
/**
/**
* Compare this to given string; note that we compare full strings here.
* The optional length argument just lets us know how long the given string is.
* If you provide a length, it is compared to length of this string as an
@@ -713,56 +716,53 @@ PRBool operator>=(const PRUnichar* aString) const;
* @param aCount -- number of chars to be compared.
* @return TRUE if equal
*/
PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const;
PRBool Equals(const PRUnichar* s1, const PRUnichar* s2,PRBool aIgnoreCase=PR_FALSE) const;
PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const;
PRBool Equals(const PRUnichar* s1, const PRUnichar* s2,PRBool aIgnoreCase=PR_FALSE) const;
PRBool EqualsIgnoreCase(const nsString& aString) const;
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const;
PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const;
PRBool EqualsIgnoreCase(const nsString& aString) const;
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const;
PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const;
/**
/**
* Determine if given buffer is plain ascii
*
* @param aBuffer -- if null, then we test *this, otherwise we test given buffer
* @return TRUE if is all ascii chars or if strlen==0
*/
PRBool IsASCII(const PRUnichar* aBuffer=0);
PRBool IsASCII(const PRUnichar* aBuffer=0);
/**
/**
* Determine if given char is a valid space character
*
* @param aChar is character to be tested
* @return TRUE if is valid space char
*/
static PRBool IsSpace(PRUnichar ch);
static PRBool IsSpace(PRUnichar ch);
/**
/**
* Determine if given char in valid alpha range
*
* @param aChar is character to be tested
* @return TRUE if in alpha range
*/
static PRBool IsAlpha(PRUnichar ch);
static PRBool IsAlpha(PRUnichar ch);
/**
/**
* Determine if given char is valid digit
*
* @param aChar is character to be tested
* @return TRUE if char is a valid digit
*/
static PRBool IsDigit(PRUnichar ch);
static PRBool IsDigit(PRUnichar ch);
static void Recycle(nsString* aString);
static nsString* CreateString(void);
nsIMemoryAgent* mAgent;
static void Recycle(nsString* aString);
static nsString* CreateString(void);
};