bugs 13038 and 14920; also improved comments. r=kmcclusk
This commit is contained in:
@@ -69,16 +69,6 @@ void nsStr::Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 a
|
|||||||
aDest.mOwnsBuffer=aOwnsBuffer;
|
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)
|
* This member destroys the memory buffer owned by an nsStr object (if it actually owns it)
|
||||||
@@ -86,17 +76,9 @@ nsIMemoryAgent* GetDefaultAgent(void){
|
|||||||
* @param
|
* @param
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) {
|
void nsStr::Destroy(nsStr& aDest) {
|
||||||
if((aDest.mStr) && (aDest.mStr!=(char*)gCommonEmptyBuffer)) {
|
if((aDest.mStr) && (aDest.mStr!=(char*)gCommonEmptyBuffer)) {
|
||||||
if(!anAgent)
|
Free(aDest);
|
||||||
anAgent=GetDefaultAgent();
|
|
||||||
|
|
||||||
if(anAgent) {
|
|
||||||
anAgent->Free(aDest);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
printf("%s\n","Leak occured in nsStr.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,11 +90,10 @@ void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) {
|
|||||||
* @param aNewLength -- new capacity of string in charSize units
|
* @param aNewLength -- new capacity of string in charSize units
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent) {
|
PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength) {
|
||||||
PRBool result=PR_TRUE;
|
PRBool result=PR_TRUE;
|
||||||
if(aNewLength>aString.mCapacity) {
|
if(aNewLength>aString.mCapacity) {
|
||||||
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
|
result=Realloc(aString,aNewLength);
|
||||||
result=theAgent->Realloc(aString,aNewLength);
|
|
||||||
if(aString.mStr)
|
if(aString.mStr)
|
||||||
AddNullTerminator(aString);
|
AddNullTerminator(aString);
|
||||||
}
|
}
|
||||||
@@ -126,20 +107,18 @@ PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent*
|
|||||||
* @param aNewLength -- new capacity of string in charSize units
|
* @param aNewLength -- new capacity of string in charSize units
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAgent) {
|
PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength) {
|
||||||
PRBool result=PR_TRUE;
|
PRBool result=PR_TRUE;
|
||||||
if(aNewLength>aDest.mCapacity) {
|
if(aNewLength>aDest.mCapacity) {
|
||||||
nsStr theTempStr;
|
nsStr theTempStr;
|
||||||
nsStr::Initialize(theTempStr,aDest.mCharSize);
|
nsStr::Initialize(theTempStr,aDest.mCharSize);
|
||||||
|
|
||||||
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
|
result=EnsureCapacity(theTempStr,aNewLength);
|
||||||
|
|
||||||
result=EnsureCapacity(theTempStr,aNewLength,theAgent);
|
|
||||||
if(result) {
|
if(result) {
|
||||||
if(aDest.mLength) {
|
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;
|
aDest.mStr = theTempStr.mStr;
|
||||||
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
|
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
|
||||||
aDest.mLength=theTempStr.mLength;
|
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 aSource is where chars are copied from
|
||||||
* @param aCount is the number of chars copied from aSource
|
* @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){
|
if(&aDest!=&aSource){
|
||||||
Truncate(aDest,0,anAgent);
|
Truncate(aDest,0);
|
||||||
Append(aDest,aSource,anOffset,aCount,anAgent);
|
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
|
* @param aSource is where char are copied from
|
||||||
* @aCount is the number of bytes to be copied
|
* @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){
|
if(anOffset<aSource.mLength){
|
||||||
PRUint32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
|
PRUint32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
|
||||||
PRUint32 theLength=(anOffset+theRealLen<aSource.mLength) ? theRealLen : (aSource.mLength-anOffset);
|
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;
|
PRBool isBigEnough=PR_TRUE;
|
||||||
if(aDest.mLength+theLength > aDest.mCapacity) {
|
if(aDest.mLength+theLength > aDest.mCapacity) {
|
||||||
isBigEnough=GrowCapacity(aDest,aDest.mLength+theLength,anAgent);
|
isBigEnough=GrowCapacity(aDest,aDest.mLength+theLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isBigEnough) {
|
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 aSrcOffset is where in aSource chars are copied from
|
||||||
* @param aCount is the number of chars from aSource to be inserted into aDest
|
* @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:
|
//there are a few cases for insert:
|
||||||
// 1. You're inserting chars into an empty string (assign)
|
// 1. You're inserting chars into an empty string (assign)
|
||||||
// 2. You're inserting onto the end of a string (append)
|
// 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 theTempStr;
|
||||||
nsStr::Initialize(theTempStr,aDest.mCharSize);
|
nsStr::Initialize(theTempStr,aDest.mCharSize);
|
||||||
|
|
||||||
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
|
PRBool isBigEnough=EnsureCapacity(theTempStr,aDest.mLength+theLength); //grow the temp buffer to the right size
|
||||||
PRBool isBigEnough=EnsureCapacity(theTempStr,aDest.mLength+theLength,theAgent); //grow the temp buffer to the right size
|
|
||||||
|
|
||||||
if(isBigEnough) {
|
if(isBigEnough) {
|
||||||
if(aDestOffset) {
|
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;
|
PRUint32 theRemains=aDest.mLength-aDestOffset;
|
||||||
if(theRemains) {
|
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;
|
aDest.mStr = theTempStr.mStr;
|
||||||
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
|
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
|
||||||
aDest.mCapacity=theTempStr.mCapacity;
|
aDest.mCapacity=theTempStr.mCapacity;
|
||||||
@@ -262,9 +240,9 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin
|
|||||||
}//if
|
}//if
|
||||||
//else nothing to do!
|
//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 aDestOffset is where in aDest deletion is to occur
|
||||||
* @param aCount is the number of chars to be deleted in aDest
|
* @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){
|
if(aDestOffset<aDest.mLength){
|
||||||
|
|
||||||
PRUint32 theDelta=aDest.mLength-aDestOffset;
|
PRUint32 theDelta=aDest.mLength-aDestOffset;
|
||||||
@@ -290,7 +268,7 @@ void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAg
|
|||||||
aDest.mLength-=theLength;
|
aDest.mLength-=theLength;
|
||||||
AddNullTerminator(aDest);
|
AddNullTerminator(aDest);
|
||||||
}
|
}
|
||||||
else Truncate(aDest,aDestOffset,anAgent);
|
else Truncate(aDest,aDestOffset);
|
||||||
}//if
|
}//if
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,7 +278,7 @@ void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAg
|
|||||||
* @param aDest is the nsStr to be truncated
|
* @param aDest is the nsStr to be truncated
|
||||||
* @param aDestOffset is where in aDest truncation is to occur
|
* @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){
|
if(aDestOffset<aDest.mLength){
|
||||||
aDest.mLength=aDestOffset;
|
aDest.mLength=aDestOffset;
|
||||||
AddNullTerminator(aDest);
|
AddNullTerminator(aDest);
|
||||||
@@ -342,7 +320,7 @@ void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool a
|
|||||||
}
|
}
|
||||||
if(0<theIndex) {
|
if(0<theIndex) {
|
||||||
if(theIndex<theMax) {
|
if(theIndex<theMax) {
|
||||||
Delete(aDest,0,theIndex,0);
|
Delete(aDest,0,theIndex);
|
||||||
}
|
}
|
||||||
else Truncate(aDest,0);
|
else Truncate(aDest,0);
|
||||||
}
|
}
|
||||||
@@ -515,7 +493,7 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgno
|
|||||||
|
|
||||||
nsStr theCopy;
|
nsStr theCopy;
|
||||||
nsStr::Initialize(theCopy,eOneByte);
|
nsStr::Initialize(theCopy,eOneByte);
|
||||||
nsStr::Assign(theCopy,aTarget,0,aTarget.mLength,0);
|
nsStr::Assign(theCopy,aTarget,0,aTarget.mLength);
|
||||||
if(aIgnoreCase){
|
if(aIgnoreCase){
|
||||||
nsStr::ChangeCase(theCopy,PR_FALSE); //force to lowercase
|
nsStr::ChangeCase(theCopy,PR_FALSE); //force to lowercase
|
||||||
}
|
}
|
||||||
@@ -538,7 +516,7 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgno
|
|||||||
}
|
}
|
||||||
index--;
|
index--;
|
||||||
} //while
|
} //while
|
||||||
nsStr::Destroy(theCopy,0);
|
nsStr::Destroy(theCopy);
|
||||||
}//if
|
}//if
|
||||||
}//if
|
}//if
|
||||||
return result;
|
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) {
|
CBufDescriptor::CBufDescriptor(char* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength) {
|
||||||
mBuffer=aString;
|
mBuffer=aString;
|
||||||
mCharSize=eOneByte;
|
mCharSize=eOneByte;
|
||||||
@@ -683,3 +712,5 @@ CBufDescriptor::CBufDescriptor(const PRUnichar* aString,PRBool aStackBased,PRUin
|
|||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -164,6 +164,7 @@
|
|||||||
|
|
||||||
#include "nscore.h"
|
#include "nscore.h"
|
||||||
#include "nsIAllocator.h"
|
#include "nsIAllocator.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -177,8 +178,6 @@ const PRInt32 kDefaultStringSize = 64;
|
|||||||
const PRInt32 kNotFound = -1;
|
const PRInt32 kNotFound = -1;
|
||||||
|
|
||||||
|
|
||||||
class nsIMemoryAgent;
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
class NS_COM CBufDescriptor {
|
class NS_COM CBufDescriptor {
|
||||||
@@ -228,7 +227,7 @@ struct NS_COM nsStr {
|
|||||||
* @param aString is the nsStr to be manipulated
|
* @param aString is the nsStr to be manipulated
|
||||||
* @param anAgent is the allocator to be used to the nsStr
|
* @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.
|
* 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
|
* @param anAgent is the allocator to be used on the nsStr
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
static PRBool EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0);
|
static PRBool EnsureCapacity(nsStr& aString,PRUint32 aNewLength);
|
||||||
static PRBool GrowCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0);
|
static PRBool GrowCapacity(nsStr& aString,PRUint32 aNewLength);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* These methods are used to append content to the given nsStr
|
* 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 aCount tells us the (max) # of chars to copy
|
||||||
* @param anAgent is the allocator to be used for alloc/free operations
|
* @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
|
* 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 aCount tells us the (max) # of chars to copy
|
||||||
* @param anAgent is the allocator to be used for alloc/free operations
|
* @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
|
* 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 aCount tells us the (max) # of chars to insert
|
||||||
* @param anAgent is the allocator to be used for alloc/free operations
|
* @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.
|
* 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 aCount tells us the (max) # of chars to delete
|
||||||
* @param anAgent is the allocator to be used for alloc/free operations
|
* @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.
|
* 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 aSrcOffset tells us where in source to start copying
|
||||||
* @param anAgent is the allocator to be used for alloc/free operations
|
* @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
|
* This method is used to perform a case conversion on the given string
|
||||||
@@ -388,6 +387,12 @@ struct NS_COM nsStr {
|
|||||||
char* mStr;
|
char* mStr;
|
||||||
PRUnichar* mUStr;
|
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;
|
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
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ static const char* kWhitespace="\b\t\r\n ";
|
|||||||
static void CSubsume(nsStr& aDest,nsStr& aSource){
|
static void CSubsume(nsStr& aDest,nsStr& aSource){
|
||||||
if(aSource.mStr && aSource.mLength) {
|
if(aSource.mStr && aSource.mLength) {
|
||||||
if(aSource.mOwnsBuffer){
|
if(aSource.mOwnsBuffer){
|
||||||
nsStr::Destroy(aDest,0);
|
nsStr::Destroy(aDest);
|
||||||
aDest.mStr=aSource.mStr;
|
aDest.mStr=aSource.mStr;
|
||||||
aDest.mLength=aSource.mLength;
|
aDest.mLength=aSource.mLength;
|
||||||
aDest.mCharSize=aSource.mCharSize;
|
aDest.mCharSize=aSource.mCharSize;
|
||||||
@@ -50,17 +50,17 @@ static void CSubsume(nsStr& aDest,nsStr& aSource){
|
|||||||
aSource.mStr=0;
|
aSource.mStr=0;
|
||||||
}
|
}
|
||||||
else{
|
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.
|
* Default constructor.
|
||||||
*/
|
*/
|
||||||
nsCString::nsCString(nsIMemoryAgent* anAgent) : mAgent(anAgent) {
|
nsCString::nsCString() {
|
||||||
nsStr::Initialize(*this,eOneByte);
|
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 aCString is a ptr to a 1-byte cstr
|
||||||
* @param aLength tells us how many chars to copy from given CString
|
* @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);
|
nsStr::Initialize(*this,eOneByte);
|
||||||
Assign(aCString,aLength);
|
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 aString is a ptr to a unichar string
|
||||||
* @param aLength tells us how many chars to copy from given aString
|
* @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);
|
nsStr::Initialize(*this,eOneByte);
|
||||||
|
|
||||||
if(aString && aLength){
|
if(aString && aLength){
|
||||||
@@ -101,7 +101,7 @@ nsCString::nsCString(const PRUnichar* aString,PRInt32 aLength,nsIMemoryAgent* an
|
|||||||
else aLength=temp.mLength=nsCRT::strlen(aString);
|
else aLength=temp.mLength=nsCRT::strlen(aString);
|
||||||
|
|
||||||
if(0<aLength)
|
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
|
* @update gess 1/4/99
|
||||||
* @param reference to another nsCString
|
* @param reference to another nsCString
|
||||||
*/
|
*/
|
||||||
nsCString::nsCString(const nsStr &aString,nsIMemoryAgent* anAgent) : mAgent(anAgent) {
|
nsCString::nsCString(const nsStr &aString) {
|
||||||
nsStr::Initialize(*this,eOneByte);
|
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
|
* @update gess 1/4/99
|
||||||
* @param reference to another nsCString
|
* @param reference to another nsCString
|
||||||
*/
|
*/
|
||||||
nsCString::nsCString(const nsCString& aString) :mAgent(aString.mAgent) {
|
nsCString::nsCString(const nsCString& aString) {
|
||||||
nsStr::Initialize(*this,aString.mCharSize);
|
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
|
* @update gess 1/4/99
|
||||||
* @param reference to a subsumeString
|
* @param reference to a subsumeString
|
||||||
*/
|
*/
|
||||||
nsCString::nsCString(nsSubsumeCStr& aSubsumeStr) :mAgent(0) {
|
nsCString::nsCString(nsSubsumeCStr& aSubsumeStr) {
|
||||||
CSubsume(*this,aSubsumeStr);
|
CSubsume(*this,aSubsumeStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +138,7 @@ nsCString::nsCString(nsSubsumeCStr& aSubsumeStr) :mAgent(0) {
|
|||||||
* Destructor
|
* Destructor
|
||||||
*/
|
*/
|
||||||
nsCString::~nsCString() {
|
nsCString::~nsCString() {
|
||||||
nsStr::Destroy(*this,mAgent);
|
nsStr::Destroy(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nsCString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
void nsCString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
||||||
@@ -155,7 +155,7 @@ void nsCString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
|||||||
* @return nada
|
* @return nada
|
||||||
*/
|
*/
|
||||||
void nsCString::Truncate(PRInt32 anIndex) {
|
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) {
|
void nsCString::SetCapacity(PRUint32 aLength) {
|
||||||
if(aLength>mCapacity) {
|
if(aLength>mCapacity) {
|
||||||
GrowCapacity(*this,aLength,mAgent);
|
GrowCapacity(*this,aLength);
|
||||||
}
|
}
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
}
|
}
|
||||||
@@ -262,7 +262,7 @@ PRBool nsCString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
|
|||||||
*/
|
*/
|
||||||
nsSubsumeCStr nsCString::operator+(const nsCString& aString){
|
nsSubsumeCStr nsCString::operator+(const nsCString& aString){
|
||||||
nsCString temp(*this); //make a temp string the same size as this...
|
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);
|
return nsSubsumeCStr(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -613,11 +613,19 @@ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) {
|
|||||||
}
|
}
|
||||||
theDigit=(theChar-'A')+10;
|
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) {
|
else if('-'==theChar) {
|
||||||
result=-result;
|
result=-result;
|
||||||
break;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -634,6 +642,7 @@ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call this method to extract the rightmost numeric value from the given
|
* Call this method to extract the rightmost numeric value from the given
|
||||||
* 1-byte input string, and simultaneously determine the radix.
|
* 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.
|
* @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
|
* @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);
|
//begin by skipping over leading chars that shouldn't be part of the number...
|
||||||
char* cp = (kNotFound==decPt) ? aString.mStr + aString.mLength-1 : aString.mStr+decPt-1;
|
|
||||||
|
|
||||||
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<endcp){
|
||||||
while (cp >= aString.mStr) {
|
const char* pos=(const char*)memchr(validChars,*cp,len);
|
||||||
if((*cp>='0') && (*cp<='9')){
|
if(!pos) {
|
||||||
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...
|
|
||||||
cp++;
|
cp++;
|
||||||
while (--cp >= aString.mStr) {
|
|
||||||
if((*cp>='0') && (*cp<='9')){
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
else if((*cp>='A') && (*cp<='F')) {
|
else break;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
else if((*cp=='-') || (*cp=='+')){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if(('#'==(*cp)) || ('X'==(*cp)))
|
|
||||||
aRadix=kRadix16;
|
|
||||||
cp++; //move back by one
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(cp>aString.mStr)
|
|
||||||
aString.Cut(0,cp-aString.mStr);
|
|
||||||
PRInt32 result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK;
|
|
||||||
|
|
||||||
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -726,11 +735,12 @@ PRUint32 nsCString::DetermineRadix(void) {
|
|||||||
PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
||||||
|
|
||||||
//copy chars to local buffer -- step down from 2 bytes to 1 if necessary...
|
//copy chars to local buffer -- step down from 2 bytes to 1 if necessary...
|
||||||
|
PRInt32 result=0;
|
||||||
nsCAutoString theString(*this);
|
nsCAutoString theString(*this);
|
||||||
PRUint32 theRadix=aRadix;
|
PRUint32 theRadix=aRadix;
|
||||||
PRInt32 result=0;
|
|
||||||
|
|
||||||
*anErrorCode=GetNumericSubstring(theString,theRadix); //we actually don't use this radix; use given radix instead
|
*anErrorCode=GetNumericSubstring(theString,theRadix); //we actually don't use this radix; use given radix instead
|
||||||
|
|
||||||
if(NS_OK==*anErrorCode){
|
if(NS_OK==*anErrorCode){
|
||||||
if(kAutoDetect==aRadix)
|
if(kAutoDetect==aRadix)
|
||||||
aRadix=theRadix;
|
aRadix=theRadix;
|
||||||
@@ -755,13 +765,13 @@ PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
|||||||
*/
|
*/
|
||||||
nsCString& nsCString::Assign(const nsStr& aString,PRInt32 aCount) {
|
nsCString& nsCString::Assign(const nsStr& aString,PRInt32 aCount) {
|
||||||
if(this!=&aString){
|
if(this!=&aString){
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
|
|
||||||
if(aCount<0)
|
if(aCount<0)
|
||||||
aCount=aString.mLength;
|
aCount=aString.mLength;
|
||||||
else aCount=MinInt(aCount,aString.mLength);
|
else aCount=MinInt(aCount,aString.mLength);
|
||||||
|
|
||||||
nsStr::Assign(*this,aString,0,aCount,mAgent);
|
nsStr::Assign(*this,aString,0,aCount);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -773,7 +783,7 @@ nsCString& nsCString::Assign(const nsStr& aString,PRInt32 aCount) {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
nsCString& nsCString::Assign(const char* aCString,PRInt32 aCount) {
|
nsCString& nsCString::Assign(const char* aCString,PRInt32 aCount) {
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
if(aCString){
|
if(aCString){
|
||||||
Append(aCString,aCount);
|
Append(aCString,aCount);
|
||||||
}
|
}
|
||||||
@@ -787,7 +797,7 @@ nsCString& nsCString::Assign(const char* aCString,PRInt32 aCount) {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) {
|
nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) {
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
|
|
||||||
if(aString){
|
if(aString){
|
||||||
nsStr temp;
|
nsStr temp;
|
||||||
@@ -806,7 +816,7 @@ nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) {
|
|||||||
else aCount=temp.mLength=nsCRT::strlen(aString);
|
else aCount=temp.mLength=nsCRT::strlen(aString);
|
||||||
|
|
||||||
if(0<aCount)
|
if(0<aCount)
|
||||||
nsStr::Append(*this,temp,0,aCount,mAgent);
|
nsStr::Append(*this,temp,0,aCount);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -818,7 +828,7 @@ nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
nsCString& nsCString::Assign(PRUnichar aChar) {
|
nsCString& nsCString::Assign(PRUnichar aChar) {
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
return Append(aChar);
|
return Append(aChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -829,7 +839,7 @@ nsCString& nsCString::Assign(PRUnichar aChar) {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
nsCString& nsCString::Assign(char aChar) {
|
nsCString& nsCString::Assign(char aChar) {
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
return Append(aChar);
|
return Append(aChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -864,7 +874,24 @@ nsCString& nsCString::Append(const nsCString& aString,PRInt32 aCount) {
|
|||||||
aCount=aString.mLength;
|
aCount=aString.mLength;
|
||||||
else aCount=MinInt(aCount,aString.mLength);
|
else aCount=MinInt(aCount,aString.mLength);
|
||||||
if(0<aCount)
|
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;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -893,7 +920,7 @@ nsCString& nsCString::Append(const char* aCString,PRInt32 aCount) {
|
|||||||
else aCount=temp.mLength=nsCRT::strlen(aCString);
|
else aCount=temp.mLength=nsCRT::strlen(aCString);
|
||||||
|
|
||||||
if(0<aCount)
|
if(0<aCount)
|
||||||
nsStr::Append(*this,temp,0,aCount,mAgent);
|
nsStr::Append(*this,temp,0,aCount);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -913,7 +940,7 @@ nsCString& nsCString::Append(PRUnichar aChar) {
|
|||||||
Initialize(temp,eTwoByte);
|
Initialize(temp,eTwoByte);
|
||||||
temp.mUStr=buf;
|
temp.mUStr=buf;
|
||||||
temp.mLength=1;
|
temp.mLength=1;
|
||||||
nsStr::Append(*this,temp,0,1,mAgent);
|
nsStr::Append(*this,temp,0,1);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -931,7 +958,7 @@ nsCString& nsCString::Append(char aChar) {
|
|||||||
Initialize(temp,eOneByte);
|
Initialize(temp,eOneByte);
|
||||||
temp.mStr=buf;
|
temp.mStr=buf;
|
||||||
temp.mLength=1;
|
temp.mLength=1;
|
||||||
nsStr::Append(*this,temp,0,1,mAgent);
|
nsStr::Append(*this,temp,0,1);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -962,12 +989,12 @@ nsCString& nsCString::Append(PRInt32 anInteger,PRInt32 aRadix) {
|
|||||||
|
|
||||||
PRBool isfirst=PR_TRUE;
|
PRBool isfirst=PR_TRUE;
|
||||||
while(mask1>=1) {
|
while(mask1>=1) {
|
||||||
PRInt32 div=theInt/mask1;
|
PRInt32 theDiv=theInt/mask1;
|
||||||
if((div) || (!isfirst)) {
|
if((theDiv) || (!isfirst)) {
|
||||||
buf[charpos++]="0123456789abcdef"[div];
|
buf[charpos++]="0123456789abcdef"[theDiv];
|
||||||
isfirst=PR_FALSE;
|
isfirst=PR_FALSE;
|
||||||
}
|
}
|
||||||
theInt-=div*mask1;
|
theInt-=theDiv*mask1;
|
||||||
mask1/=aRadix;
|
mask1/=aRadix;
|
||||||
}
|
}
|
||||||
return Append(buf);
|
return Append(buf);
|
||||||
@@ -1001,7 +1028,7 @@ PRUint32 nsCString::Left(nsCString& aDest,PRInt32 aCount) const{
|
|||||||
if(aCount<0)
|
if(aCount<0)
|
||||||
aCount=mLength;
|
aCount=mLength;
|
||||||
else aCount=MinInt(aCount,mLength);
|
else aCount=MinInt(aCount,mLength);
|
||||||
nsStr::Assign(aDest,*this,0,aCount,mAgent);
|
nsStr::Assign(aDest,*this,0,aCount);
|
||||||
return aDest.mLength;
|
return aDest.mLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1018,7 +1045,7 @@ PRUint32 nsCString::Mid(nsCString& aDest,PRUint32 anOffset,PRInt32 aCount) const
|
|||||||
if(aCount<0)
|
if(aCount<0)
|
||||||
aCount=mLength;
|
aCount=mLength;
|
||||||
else aCount=MinInt(aCount,mLength);
|
else aCount=MinInt(aCount,mLength);
|
||||||
nsStr::Assign(aDest,*this,anOffset,aCount,mAgent);
|
nsStr::Assign(aDest,*this,anOffset,aCount);
|
||||||
return aDest.mLength;
|
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) {
|
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;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1079,7 +1106,7 @@ nsCString& nsCString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCou
|
|||||||
else aCount=temp.mLength=nsCRT::strlen(aCString);
|
else aCount=temp.mLength=nsCRT::strlen(aCString);
|
||||||
|
|
||||||
if(temp.mLength && (0<aCount)){
|
if(temp.mLength && (0<aCount)){
|
||||||
nsStr::Insert(*this,anOffset,temp,0,aCount,0);
|
nsStr::Insert(*this,anOffset,temp,0,aCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
@@ -1101,7 +1128,7 @@ nsCString& nsCString::Insert(PRUnichar aChar,PRUint32 anOffset){
|
|||||||
nsStr::Initialize(temp,eTwoByte);
|
nsStr::Initialize(temp,eTwoByte);
|
||||||
temp.mUStr=theBuffer;
|
temp.mUStr=theBuffer;
|
||||||
temp.mLength=1;
|
temp.mLength=1;
|
||||||
nsStr::Insert(*this,anOffset,temp,0,1,0);
|
nsStr::Insert(*this,anOffset,temp,0,1);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1121,7 +1148,7 @@ nsCString& nsCString::Insert(char aChar,PRUint32 anOffset){
|
|||||||
nsStr::Initialize(temp,eOneByte);
|
nsStr::Initialize(temp,eOneByte);
|
||||||
temp.mStr=theBuffer;
|
temp.mStr=theBuffer;
|
||||||
temp.mLength=1;
|
temp.mLength=1;
|
||||||
nsStr::Insert(*this,anOffset,temp,0,1,0);
|
nsStr::Insert(*this,anOffset,temp,0,1);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1136,7 +1163,7 @@ nsCString& nsCString::Insert(char aChar,PRUint32 anOffset){
|
|||||||
*/
|
*/
|
||||||
nsCString& nsCString::Cut(PRUint32 anOffset, PRInt32 aCount) {
|
nsCString& nsCString::Cut(PRUint32 anOffset, PRInt32 aCount) {
|
||||||
if(0<aCount) {
|
if(0<aCount) {
|
||||||
nsStr::Delete(*this,anOffset,aCount,mAgent);
|
nsStr::Delete(*this,anOffset,aCount);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -1560,10 +1587,8 @@ PRBool nsCString::Equals(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 aCo
|
|||||||
class nsCStringDeallocator: public nsDequeFunctor{
|
class nsCStringDeallocator: public nsDequeFunctor{
|
||||||
public:
|
public:
|
||||||
virtual void* operator()(void* anObject) {
|
virtual void* operator()(void* anObject) {
|
||||||
static nsMemoryAgent theAgent;
|
|
||||||
nsCString* aString= (nsCString*)anObject;
|
nsCString* aString= (nsCString*)anObject;
|
||||||
if(aString){
|
if(aString){
|
||||||
aString->mAgent=&theAgent;
|
|
||||||
delete aString;
|
delete aString;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1722,7 +1747,6 @@ NS_COM int fputs(const nsCString& aString, FILE* out)
|
|||||||
*/
|
*/
|
||||||
nsCAutoString::nsCAutoString() : nsCString(){
|
nsCAutoString::nsCAutoString() : nsCString(){
|
||||||
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
||||||
mAgent=0;
|
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1732,7 +1756,6 @@ nsCAutoString::nsCAutoString() : nsCString(){
|
|||||||
*/
|
*/
|
||||||
nsCAutoString::nsCAutoString(const nsCAutoString& aString) : nsCString() {
|
nsCAutoString::nsCAutoString(const nsCAutoString& aString) : nsCString() {
|
||||||
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
||||||
mAgent=0;
|
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aString);
|
Append(aString);
|
||||||
}
|
}
|
||||||
@@ -1744,7 +1767,6 @@ nsCAutoString::nsCAutoString(const nsCAutoString& aString) : nsCString() {
|
|||||||
*/
|
*/
|
||||||
nsCAutoString::nsCAutoString(const char* aCString,PRInt32 aLength) : nsCString() {
|
nsCAutoString::nsCAutoString(const char* aCString,PRInt32 aLength) : nsCString() {
|
||||||
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
||||||
mAgent=0;
|
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aCString,aLength);
|
Append(aCString,aLength);
|
||||||
}
|
}
|
||||||
@@ -1754,7 +1776,6 @@ nsCAutoString::nsCAutoString(const char* aCString,PRInt32 aLength) : nsCString()
|
|||||||
* @param aBuffer -- descibes external buffer
|
* @param aBuffer -- descibes external buffer
|
||||||
*/
|
*/
|
||||||
nsCAutoString::nsCAutoString(const CBufDescriptor& aBuffer) : nsCString() {
|
nsCAutoString::nsCAutoString(const CBufDescriptor& aBuffer) : nsCString() {
|
||||||
mAgent=0;
|
|
||||||
if(!aBuffer.mBuffer) {
|
if(!aBuffer.mBuffer) {
|
||||||
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
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
|
* @param aString is a ptr to a unistr
|
||||||
*/
|
*/
|
||||||
nsCAutoString::nsCAutoString(const PRUnichar* aString,PRInt32 aLength) : nsCString() {
|
nsCAutoString::nsCAutoString(const PRUnichar* aString,PRInt32 aLength) : nsCString() {
|
||||||
mAgent=0;
|
|
||||||
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aString,aLength);
|
Append(aString,aLength);
|
||||||
@@ -1781,7 +1801,6 @@ nsCAutoString::nsCAutoString(const PRUnichar* aString,PRInt32 aLength) : nsCStri
|
|||||||
* @param
|
* @param
|
||||||
*/
|
*/
|
||||||
nsCAutoString::nsCAutoString(const nsStr& aString) : nsCString() {
|
nsCAutoString::nsCAutoString(const nsStr& aString) : nsCString() {
|
||||||
mAgent=0;
|
|
||||||
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aString);
|
Append(aString);
|
||||||
@@ -1794,7 +1813,6 @@ nsCAutoString::nsCAutoString(const nsStr& aString) : nsCString() {
|
|||||||
* @param
|
* @param
|
||||||
*/
|
*/
|
||||||
nsCAutoString::nsCAutoString(PRUnichar aChar) : nsCString(){
|
nsCAutoString::nsCAutoString(PRUnichar aChar) : nsCString(){
|
||||||
mAgent=0;
|
|
||||||
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aChar);
|
Append(aChar);
|
||||||
@@ -1807,12 +1825,10 @@ nsCAutoString::nsCAutoString(PRUnichar aChar) : nsCString(){
|
|||||||
*/
|
*/
|
||||||
#ifdef AIX
|
#ifdef AIX
|
||||||
nsCAutoString::nsCAutoString(const nsSubsumeCStr& aSubsumeStr) :nsCString() {
|
nsCAutoString::nsCAutoString(const nsSubsumeCStr& aSubsumeStr) :nsCString() {
|
||||||
mAgent=0;
|
|
||||||
nsSubsumeCStr temp(aSubsumeStr); // a temp is needed for the AIX compiler
|
nsSubsumeCStr temp(aSubsumeStr); // a temp is needed for the AIX compiler
|
||||||
CSubsume(*this,temp);
|
CSubsume(*this,temp);
|
||||||
#else
|
#else
|
||||||
nsCAutoString::nsCAutoString( nsSubsumeCStr& aSubsumeStr) :nsCString() {
|
nsCAutoString::nsCAutoString( nsSubsumeCStr& aSubsumeStr) :nsCString() {
|
||||||
mAgent=0;
|
|
||||||
CSubsume(*this,aSubsumeStr);
|
CSubsume(*this,aSubsumeStr);
|
||||||
#endif // AIX
|
#endif // AIX
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,26 +51,25 @@ class NS_COM nsCString : public nsStr {
|
|||||||
/**
|
/**
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
*/
|
*/
|
||||||
nsCString(nsIMemoryAgent* anAgent=0);
|
nsCString();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constructor accepts an isolatin string
|
* This constructor accepts an isolatin string
|
||||||
* @param aCString is a ptr to a 1-byte cstr
|
* @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
|
* This constructor accepts a unichar string
|
||||||
* @param aCString is a ptr to a 2-byte cstr
|
* @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
|
* This is a copy constructor that accepts an nsStr
|
||||||
* @param reference to another nsCString
|
* @param reference to another nsCString
|
||||||
*/
|
*/
|
||||||
nsCString(const nsStr&,nsIMemoryAgent* anAgent=0);
|
nsCString(const nsStr&);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is our copy constructor
|
* This is our copy constructor
|
||||||
@@ -150,6 +149,10 @@ PRBool IsEmpty(void) const {
|
|||||||
Accessor methods...
|
Accessor methods...
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve const ptr to internal buffer; DO NOT TRY TO FREE IT!
|
||||||
|
*/
|
||||||
const char* GetBuffer(void) const;
|
const char* GetBuffer(void) const;
|
||||||
|
|
||||||
|
|
||||||
@@ -412,6 +415,7 @@ nsCString& Append(const nsCString& aString) {return Append(aString,aString.mLeng
|
|||||||
* @return number of chars copied
|
* @return number of chars copied
|
||||||
*/
|
*/
|
||||||
nsCString& Append(const nsCString& aString,PRInt32 aCount);
|
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(const char* aString,PRInt32 aCount=-1);
|
||||||
nsCString& Append(PRUnichar aChar);
|
nsCString& Append(PRUnichar aChar);
|
||||||
nsCString& Append(char aChar);
|
nsCString& Append(char aChar);
|
||||||
@@ -670,9 +674,6 @@ PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const;
|
|||||||
static void Recycle(nsCString* aString);
|
static void Recycle(nsCString* aString);
|
||||||
static nsCString* CreateString(void);
|
static nsCString* CreateString(void);
|
||||||
|
|
||||||
|
|
||||||
nsIMemoryAgent* mAgent;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern NS_COM int fputs(const nsCString& aString, FILE* out);
|
extern NS_COM int fputs(const nsCString& aString, FILE* out);
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ static const char* kWhitespace="\b\t\r\n ";
|
|||||||
static void Subsume(nsStr& aDest,nsStr& aSource){
|
static void Subsume(nsStr& aDest,nsStr& aSource){
|
||||||
if(aSource.mStr && aSource.mLength) {
|
if(aSource.mStr && aSource.mLength) {
|
||||||
if(aSource.mOwnsBuffer){
|
if(aSource.mOwnsBuffer){
|
||||||
nsStr::Destroy(aDest,0);
|
nsStr::Destroy(aDest);
|
||||||
aDest.mStr=aSource.mStr;
|
aDest.mStr=aSource.mStr;
|
||||||
aDest.mLength=aSource.mLength;
|
aDest.mLength=aSource.mLength;
|
||||||
aDest.mCharSize=aSource.mCharSize;
|
aDest.mCharSize=aSource.mCharSize;
|
||||||
@@ -48,17 +48,17 @@ static void Subsume(nsStr& aDest,nsStr& aSource){
|
|||||||
aSource.mStr=0;
|
aSource.mStr=0;
|
||||||
}
|
}
|
||||||
else{
|
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.
|
* Default constructor.
|
||||||
*/
|
*/
|
||||||
nsString::nsString(nsIMemoryAgent* anAgent) : mAgent(anAgent) {
|
nsString::nsString() {
|
||||||
nsStr::Initialize(*this,eTwoByte);
|
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 aCString is a ptr to a 1-byte cstr
|
||||||
* @param aLength tells us how many chars to copy from given CString
|
* @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);
|
nsStr::Initialize(*this,eTwoByte);
|
||||||
Assign(aCString);
|
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 aString is a ptr to a unichar string
|
||||||
* @param aLength tells us how many chars to copy from given aString
|
* @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);
|
nsStr::Initialize(*this,eTwoByte);
|
||||||
Assign(aString);
|
Assign(aString);
|
||||||
}
|
}
|
||||||
@@ -89,9 +89,9 @@ nsString::nsString(const PRUnichar* aString,nsIMemoryAgent* anAgent) : mAgent(an
|
|||||||
* @update gess 1/4/99
|
* @update gess 1/4/99
|
||||||
* @param reference to another nsCString
|
* @param reference to another nsCString
|
||||||
*/
|
*/
|
||||||
nsString::nsString(const nsStr &aString,nsIMemoryAgent* anAgent) : mAgent(anAgent) {
|
nsString::nsString(const nsStr &aString) {
|
||||||
nsStr::Initialize(*this,eTwoByte);
|
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
|
* @update gess 1/4/99
|
||||||
* @param reference to another nsString
|
* @param reference to another nsString
|
||||||
*/
|
*/
|
||||||
nsString::nsString(const nsString& aString) :mAgent(aString.mAgent) {
|
nsString::nsString(const nsString& aString) {
|
||||||
nsStr::Initialize(*this,eTwoByte);
|
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
|
* @update gess 1/4/99
|
||||||
* @param reference to a subsumeString
|
* @param reference to a subsumeString
|
||||||
*/
|
*/
|
||||||
nsString::nsString(nsSubsumeStr& aSubsumeStr) :mAgent(0) {
|
nsString::nsString(nsSubsumeStr& aSubsumeStr) {
|
||||||
nsStr::Initialize(*this,eTwoByte);
|
nsStr::Initialize(*this,eTwoByte);
|
||||||
Subsume(*this,aSubsumeStr);
|
Subsume(*this,aSubsumeStr);
|
||||||
}
|
}
|
||||||
@@ -119,7 +119,7 @@ nsString::nsString(nsSubsumeStr& aSubsumeStr) :mAgent(0) {
|
|||||||
* Make sure we call nsStr::Destroy.
|
* Make sure we call nsStr::Destroy.
|
||||||
*/
|
*/
|
||||||
nsString::~nsString() {
|
nsString::~nsString() {
|
||||||
nsStr::Destroy(*this,mAgent);
|
nsStr::Destroy(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
||||||
@@ -136,7 +136,7 @@ void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
|||||||
* @return nada
|
* @return nada
|
||||||
*/
|
*/
|
||||||
void nsString::Truncate(PRInt32 anIndex) {
|
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) {
|
void nsString::SetCapacity(PRUint32 aLength) {
|
||||||
if(aLength>mCapacity) {
|
if(aLength>mCapacity) {
|
||||||
GrowCapacity(*this,aLength,mAgent);
|
GrowCapacity(*this,aLength);
|
||||||
}
|
}
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
}
|
}
|
||||||
@@ -270,7 +270,7 @@ PRBool nsString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
|
|||||||
*/
|
*/
|
||||||
nsSubsumeStr nsString::operator+(const nsStr& aString){
|
nsSubsumeStr nsString::operator+(const nsStr& aString){
|
||||||
nsString temp(*this); //make a temp string the same size as this...
|
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);
|
return nsSubsumeStr(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,7 +282,7 @@ nsSubsumeStr nsString::operator+(const nsStr& aString){
|
|||||||
*/
|
*/
|
||||||
nsSubsumeStr nsString::operator+(const nsString& aString){
|
nsSubsumeStr nsString::operator+(const nsString& aString){
|
||||||
nsString temp(*this); //make a temp string the same size as this...
|
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);
|
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
|
* @return non-zero error code if this string is non-numeric
|
||||||
*/
|
*/
|
||||||
static 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);
|
//begin by skipping over leading chars that shouldn't be part of the number...
|
||||||
char* cp = (kNotFound==decPt) ? aString.mStr + aString.mLength-1 : aString.mStr+decPt-1;
|
|
||||||
|
|
||||||
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<endcp){
|
||||||
while (cp >= aString.mStr) {
|
const char* pos=(const char*)memchr(validChars,*cp,len);
|
||||||
if((*cp>='0') && (*cp<='9')){
|
if(!pos) {
|
||||||
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...
|
|
||||||
cp++;
|
cp++;
|
||||||
while (--cp >= aString.mStr) {
|
|
||||||
if((*cp>='0') && (*cp<='9')){
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
else if((*cp>='A') && (*cp<='F')) {
|
else break;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
else if((*cp=='-') || (*cp=='+')){
|
|
||||||
break;
|
while(cp<endcp){
|
||||||
|
char theChar=toupper(*cp);
|
||||||
|
|
||||||
|
if((theChar>='0') && (theChar<='9')) {
|
||||||
|
*to++=theChar;
|
||||||
}
|
}
|
||||||
else {
|
else if((theChar>='A') && (theChar<='F')) {
|
||||||
if(('#'==(*cp)) || ('X'==(*cp)))
|
aRadix=16;
|
||||||
aRadix=kRadix16;
|
*to++=theChar;
|
||||||
cp++; //move back by one
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -865,9 +866,9 @@ PRUint32 nsString::DetermineRadix(void) {
|
|||||||
PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
||||||
|
|
||||||
//copy chars to local buffer -- step down from 2 bytes to 1 if necessary...
|
//copy chars to local buffer -- step down from 2 bytes to 1 if necessary...
|
||||||
|
PRInt32 result=0;
|
||||||
nsCAutoString theString(*this);
|
nsCAutoString theString(*this);
|
||||||
PRUint32 theRadix=aRadix;
|
PRUint32 theRadix=aRadix;
|
||||||
PRInt32 result=0;
|
|
||||||
|
|
||||||
*anErrorCode=GetNumericSubstring(theString,theRadix); //we actually don't use this radix; use given radix instead
|
*anErrorCode=GetNumericSubstring(theString,theRadix); //we actually don't use this radix; use given radix instead
|
||||||
if(NS_OK==*anErrorCode){
|
if(NS_OK==*anErrorCode){
|
||||||
@@ -893,13 +894,13 @@ PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
|||||||
*/
|
*/
|
||||||
nsString& nsString::Assign(const nsStr& aString,PRInt32 aCount) {
|
nsString& nsString::Assign(const nsStr& aString,PRInt32 aCount) {
|
||||||
if(this!=&aString){
|
if(this!=&aString){
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
|
|
||||||
if(aCount<0)
|
if(aCount<0)
|
||||||
aCount=aString.mLength;
|
aCount=aString.mLength;
|
||||||
else aCount=MinInt(aCount,aString.mLength);
|
else aCount=MinInt(aCount,aString.mLength);
|
||||||
|
|
||||||
nsStr::Assign(*this,aString,0,aCount,mAgent);
|
nsStr::Assign(*this,aString,0,aCount);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -912,7 +913,7 @@ nsString& nsString::Assign(const nsStr& aString,PRInt32 aCount) {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
nsString& nsString::Assign(const char* aCString,PRInt32 aCount) {
|
nsString& nsString::Assign(const char* aCString,PRInt32 aCount) {
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
if(aCString){
|
if(aCString){
|
||||||
Append(aCString,aCount);
|
Append(aCString,aCount);
|
||||||
}
|
}
|
||||||
@@ -926,7 +927,7 @@ nsString& nsString::Assign(const char* aCString,PRInt32 aCount) {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
nsString& nsString::Assign(const PRUnichar* aString,PRInt32 aCount) {
|
nsString& nsString::Assign(const PRUnichar* aString,PRInt32 aCount) {
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
if(aString){
|
if(aString){
|
||||||
Append(aString,aCount);
|
Append(aString,aCount);
|
||||||
}
|
}
|
||||||
@@ -940,7 +941,7 @@ nsString& nsString::Assign(const PRUnichar* aString,PRInt32 aCount) {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
nsString& nsString::Assign(char aChar) {
|
nsString& nsString::Assign(char aChar) {
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
return Append(aChar);
|
return Append(aChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -951,7 +952,7 @@ nsString& nsString::Assign(char aChar) {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
nsString& nsString::Assign(PRUnichar aChar) {
|
nsString& nsString::Assign(PRUnichar aChar) {
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
return Append(aChar);
|
return Append(aChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -988,7 +989,7 @@ nsString& nsString::Append(const nsStr& aString,PRInt32 aCount) {
|
|||||||
else aCount=MinInt(aCount,aString.mLength);
|
else aCount=MinInt(aCount,aString.mLength);
|
||||||
|
|
||||||
if(0<aCount)
|
if(0<aCount)
|
||||||
nsStr::Append(*this,aString,0,aCount,mAgent);
|
nsStr::Append(*this,aString,0,aCount);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1005,7 +1006,7 @@ nsString& nsString::Append(const nsString& aString,PRInt32 aCount) {
|
|||||||
aCount=aString.mLength;
|
aCount=aString.mLength;
|
||||||
else aCount=MinInt(aCount,aString.mLength);
|
else aCount=MinInt(aCount,aString.mLength);
|
||||||
if(0<aCount)
|
if(0<aCount)
|
||||||
nsStr::Append(*this,aString,0,aCount,mAgent);
|
nsStr::Append(*this,aString,0,aCount);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1034,7 +1035,7 @@ nsString& nsString::Append(const char* aCString,PRInt32 aCount) {
|
|||||||
else aCount=temp.mLength=nsCRT::strlen(aCString);
|
else aCount=temp.mLength=nsCRT::strlen(aCString);
|
||||||
|
|
||||||
if(0<aCount)
|
if(0<aCount)
|
||||||
nsStr::Append(*this,temp,0,aCount,mAgent);
|
nsStr::Append(*this,temp,0,aCount);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -1064,7 +1065,7 @@ nsString& nsString::Append(const PRUnichar* aString,PRInt32 aCount) {
|
|||||||
else aCount=temp.mLength=nsCRT::strlen(aString);
|
else aCount=temp.mLength=nsCRT::strlen(aString);
|
||||||
|
|
||||||
if(0<aCount)
|
if(0<aCount)
|
||||||
nsStr::Append(*this,temp,0,aCount,mAgent);
|
nsStr::Append(*this,temp,0,aCount);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -1083,7 +1084,7 @@ nsString& nsString::Append(char aChar) {
|
|||||||
Initialize(temp,eOneByte);
|
Initialize(temp,eOneByte);
|
||||||
temp.mStr=buf;
|
temp.mStr=buf;
|
||||||
temp.mLength=1;
|
temp.mLength=1;
|
||||||
nsStr::Append(*this,temp,0,1,mAgent);
|
nsStr::Append(*this,temp,0,1);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1101,7 +1102,7 @@ nsString& nsString::Append(PRUnichar aChar) {
|
|||||||
Initialize(temp,eTwoByte);
|
Initialize(temp,eTwoByte);
|
||||||
temp.mUStr=buf;
|
temp.mUStr=buf;
|
||||||
temp.mLength=1;
|
temp.mLength=1;
|
||||||
nsStr::Append(*this,temp,0,1,mAgent);
|
nsStr::Append(*this,temp,0,1);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1132,12 +1133,12 @@ nsString& nsString::Append(PRInt32 anInteger,PRInt32 aRadix) {
|
|||||||
|
|
||||||
PRBool isfirst=PR_TRUE;
|
PRBool isfirst=PR_TRUE;
|
||||||
while(mask1>=1) {
|
while(mask1>=1) {
|
||||||
PRInt32 div=theInt/mask1;
|
PRInt32 theDiv=theInt/mask1;
|
||||||
if((div) || (!isfirst)) {
|
if((theDiv) || (!isfirst)) {
|
||||||
buf[charpos++]="0123456789abcdef"[div];
|
buf[charpos++]="0123456789abcdef"[theDiv];
|
||||||
isfirst=PR_FALSE;
|
isfirst=PR_FALSE;
|
||||||
}
|
}
|
||||||
theInt-=div*mask1;
|
theInt-=theDiv*mask1;
|
||||||
mask1/=aRadix;
|
mask1/=aRadix;
|
||||||
}
|
}
|
||||||
return Append(buf);
|
return Append(buf);
|
||||||
@@ -1173,7 +1174,7 @@ PRUint32 nsString::Left(nsString& aDest,PRInt32 aCount) const{
|
|||||||
if(aCount<0)
|
if(aCount<0)
|
||||||
aCount=mLength;
|
aCount=mLength;
|
||||||
else aCount=MinInt(aCount,mLength);
|
else aCount=MinInt(aCount,mLength);
|
||||||
nsStr::Assign(aDest,*this,0,aCount,mAgent);
|
nsStr::Assign(aDest,*this,0,aCount);
|
||||||
|
|
||||||
return aDest.mLength;
|
return aDest.mLength;
|
||||||
}
|
}
|
||||||
@@ -1191,7 +1192,7 @@ PRUint32 nsString::Mid(nsString& aDest,PRUint32 anOffset,PRInt32 aCount) const{
|
|||||||
if(aCount<0)
|
if(aCount<0)
|
||||||
aCount=mLength;
|
aCount=mLength;
|
||||||
else aCount=MinInt(aCount,mLength);
|
else aCount=MinInt(aCount,mLength);
|
||||||
nsStr::Assign(aDest,*this,anOffset,aCount,mAgent);
|
nsStr::Assign(aDest,*this,anOffset,aCount);
|
||||||
|
|
||||||
return aDest.mLength;
|
return aDest.mLength;
|
||||||
}
|
}
|
||||||
@@ -1221,7 +1222,7 @@ PRUint32 nsString::Right(nsString& aDest,PRInt32 aCount) const{
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
nsString& nsString::Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) {
|
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;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1252,7 +1253,7 @@ nsString& nsString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCount
|
|||||||
else aCount=temp.mLength=nsCRT::strlen(aCString);
|
else aCount=temp.mLength=nsCRT::strlen(aCString);
|
||||||
|
|
||||||
if(0<aCount){
|
if(0<aCount){
|
||||||
nsStr::Insert(*this,anOffset,temp,0,aCount,0);
|
nsStr::Insert(*this,anOffset,temp,0,aCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
@@ -1285,7 +1286,7 @@ nsString& nsString::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32 aC
|
|||||||
else aCount=temp.mLength=nsCRT::strlen(aString);
|
else aCount=temp.mLength=nsCRT::strlen(aString);
|
||||||
|
|
||||||
if(0<aCount){
|
if(0<aCount){
|
||||||
nsStr::Insert(*this,anOffset,temp,0,aCount,0);
|
nsStr::Insert(*this,anOffset,temp,0,aCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
@@ -1308,7 +1309,7 @@ nsString& nsString::Insert(PRUnichar aChar,PRUint32 anOffset){
|
|||||||
nsStr::Initialize(temp,eTwoByte);
|
nsStr::Initialize(temp,eTwoByte);
|
||||||
temp.mUStr=theBuffer;
|
temp.mUStr=theBuffer;
|
||||||
temp.mLength=1;
|
temp.mLength=1;
|
||||||
nsStr::Insert(*this,anOffset,temp,0,1,0);
|
nsStr::Insert(*this,anOffset,temp,0,1);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1323,7 +1324,7 @@ nsString& nsString::Insert(PRUnichar aChar,PRUint32 anOffset){
|
|||||||
*/
|
*/
|
||||||
nsString& nsString::Cut(PRUint32 anOffset, PRInt32 aCount) {
|
nsString& nsString::Cut(PRUint32 anOffset, PRInt32 aCount) {
|
||||||
if(0<aCount) {
|
if(0<aCount) {
|
||||||
nsStr::Delete(*this,anOffset,aCount,mAgent);
|
nsStr::Delete(*this,anOffset,aCount);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -1957,10 +1958,8 @@ PRBool nsString::IsDigit(PRUnichar aChar) {
|
|||||||
class nsStringDeallocator: public nsDequeFunctor{
|
class nsStringDeallocator: public nsDequeFunctor{
|
||||||
public:
|
public:
|
||||||
virtual void* operator()(void* anObject) {
|
virtual void* operator()(void* anObject) {
|
||||||
static nsMemoryAgent theAgent;
|
|
||||||
nsString* aString= (nsString*)anObject;
|
nsString* aString= (nsString*)anObject;
|
||||||
if(aString){
|
if(aString){
|
||||||
aString->mAgent=&theAgent;
|
|
||||||
delete aString;
|
delete aString;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -2116,7 +2115,6 @@ NS_COM int fputs(const nsString& aString, FILE* out)
|
|||||||
*/
|
*/
|
||||||
nsAutoString::nsAutoString() : nsString() {
|
nsAutoString::nsAutoString() : nsString() {
|
||||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
||||||
mAgent=0;
|
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2127,7 +2125,6 @@ nsAutoString::nsAutoString() : nsString() {
|
|||||||
*/
|
*/
|
||||||
nsAutoString::nsAutoString(const char* aCString,PRInt32 aLength) : nsString() {
|
nsAutoString::nsAutoString(const char* aCString,PRInt32 aLength) : nsString() {
|
||||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
||||||
mAgent=0;
|
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aCString,aLength);
|
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
|
* @param aLength tells us how many chars to copy from aString
|
||||||
*/
|
*/
|
||||||
nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString() {
|
nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString() {
|
||||||
mAgent=0;
|
|
||||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aString,aLength);
|
Append(aString,aLength);
|
||||||
@@ -2149,7 +2145,6 @@ nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString(
|
|||||||
* @param aBuffer describes the external buffer
|
* @param aBuffer describes the external buffer
|
||||||
*/
|
*/
|
||||||
nsAutoString::nsAutoString(const CBufDescriptor& aBuffer) : nsString() {
|
nsAutoString::nsAutoString(const CBufDescriptor& aBuffer) : nsString() {
|
||||||
mAgent=0;
|
|
||||||
if(!aBuffer.mBuffer) {
|
if(!aBuffer.mBuffer) {
|
||||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
||||||
}
|
}
|
||||||
@@ -2166,7 +2161,6 @@ nsAutoString::nsAutoString(const CBufDescriptor& aBuffer) : nsString() {
|
|||||||
* @param
|
* @param
|
||||||
*/
|
*/
|
||||||
nsAutoString::nsAutoString(const nsStr& aString) : nsString() {
|
nsAutoString::nsAutoString(const nsStr& aString) : nsString() {
|
||||||
mAgent=0;
|
|
||||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aString);
|
Append(aString);
|
||||||
@@ -2176,7 +2170,6 @@ nsAutoString::nsAutoString(const nsStr& aString) : nsString() {
|
|||||||
* Default copy constructor
|
* Default copy constructor
|
||||||
*/
|
*/
|
||||||
nsAutoString::nsAutoString(const nsAutoString& aString) : nsString() {
|
nsAutoString::nsAutoString(const nsAutoString& aString) : nsString() {
|
||||||
mAgent=0;
|
|
||||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aString);
|
Append(aString);
|
||||||
@@ -2188,7 +2181,6 @@ nsAutoString::nsAutoString(const nsAutoString& aString) : nsString() {
|
|||||||
* @param
|
* @param
|
||||||
*/
|
*/
|
||||||
nsAutoString::nsAutoString(PRUnichar aChar) : nsString(){
|
nsAutoString::nsAutoString(PRUnichar aChar) : nsString(){
|
||||||
mAgent=0;
|
|
||||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aChar);
|
Append(aChar);
|
||||||
@@ -2201,12 +2193,10 @@ nsAutoString::nsAutoString(PRUnichar aChar) : nsString(){
|
|||||||
*/
|
*/
|
||||||
#ifdef AIX
|
#ifdef AIX
|
||||||
nsAutoString::nsAutoString(const nsSubsumeStr& aSubsumeStr) :nsString() {
|
nsAutoString::nsAutoString(const nsSubsumeStr& aSubsumeStr) :nsString() {
|
||||||
mAgent=0;
|
|
||||||
nsSubsumeStr temp(aSubsumeStr); // a temp is needed for the AIX compiler
|
nsSubsumeStr temp(aSubsumeStr); // a temp is needed for the AIX compiler
|
||||||
Subsume(*this,temp);
|
Subsume(*this,temp);
|
||||||
#else
|
#else
|
||||||
nsAutoString::nsAutoString( nsSubsumeStr& aSubsumeStr) :nsString() {
|
nsAutoString::nsAutoString( nsSubsumeStr& aSubsumeStr) :nsString() {
|
||||||
mAgent=0;
|
|
||||||
Subsume(*this,aSubsumeStr);
|
Subsume(*this,aSubsumeStr);
|
||||||
#endif // AIX
|
#endif // AIX
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,26 +58,26 @@ class NS_COM nsString : public nsStr {
|
|||||||
/**
|
/**
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
*/
|
*/
|
||||||
nsString(nsIMemoryAgent* anAgent=0);
|
nsString();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constructor accepts an isolatin string
|
* This constructor accepts an isolatin string
|
||||||
* @param aCString is a ptr to a 1-byte cstr
|
* @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
|
* This constructor accepts a unichar string
|
||||||
* @param aCString is a ptr to a 2-byte cstr
|
* @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
|
* This is a copy constructor that accepts an nsStr
|
||||||
* @param reference to another nsString
|
* @param reference to another nsString
|
||||||
*/
|
*/
|
||||||
nsString(const nsStr&,nsIMemoryAgent* anAgent=0);
|
nsString(const nsStr&);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is our copy constructor
|
* This is our copy constructor
|
||||||
@@ -168,6 +168,9 @@ PRBool IsEmpty(void) const {
|
|||||||
Getters/Setters...
|
Getters/Setters...
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve const ptr to internal buffer; DO NOT TRY TO FREE IT!
|
||||||
|
*/
|
||||||
const char* GetBuffer(void) const;
|
const char* GetBuffer(void) const;
|
||||||
const PRUnichar* GetUnicode(void) const;
|
const PRUnichar* GetUnicode(void) const;
|
||||||
|
|
||||||
@@ -761,9 +764,6 @@ static PRBool IsDigit(PRUnichar ch);
|
|||||||
static void Recycle(nsString* aString);
|
static void Recycle(nsString* aString);
|
||||||
static nsString* CreateString(void);
|
static nsString* CreateString(void);
|
||||||
|
|
||||||
|
|
||||||
nsIMemoryAgent* mAgent;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern NS_COM int fputs(const nsString& aString, FILE* out);
|
extern NS_COM int fputs(const nsString& aString, FILE* out);
|
||||||
|
|||||||
@@ -249,8 +249,6 @@ CopyChars gCopyChars[2][2]={
|
|||||||
* @return index of pos if found, else -1 (kNotFound)
|
* @return index of pos if found, else -1 (kNotFound)
|
||||||
*/
|
*/
|
||||||
inline PRInt32 FindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase) {
|
inline PRInt32 FindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase) {
|
||||||
PRInt32 theIndex=0;
|
|
||||||
PRInt32 theLength=(PRInt32)aLength;
|
|
||||||
|
|
||||||
if(aIgnoreCase) {
|
if(aIgnoreCase) {
|
||||||
char theChar=(char)nsCRT::ToUpper(aChar);
|
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)
|
* @return index of pos if found, else -1 (kNotFound)
|
||||||
*/
|
*/
|
||||||
inline PRInt32 FindChar2(const char* aDest,PRUint32 aLength,PRUint32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase) {
|
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* root=(PRUnichar*)aDest;
|
||||||
const PRUnichar* ptr=root+(anOffset-1);
|
const PRUnichar* ptr=root+(anOffset-1);
|
||||||
const PRUnichar* last=root+aLength;
|
const PRUnichar* last=root+aLength;
|
||||||
|
|||||||
@@ -69,16 +69,6 @@ void nsStr::Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 a
|
|||||||
aDest.mOwnsBuffer=aOwnsBuffer;
|
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)
|
* This member destroys the memory buffer owned by an nsStr object (if it actually owns it)
|
||||||
@@ -86,17 +76,9 @@ nsIMemoryAgent* GetDefaultAgent(void){
|
|||||||
* @param
|
* @param
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) {
|
void nsStr::Destroy(nsStr& aDest) {
|
||||||
if((aDest.mStr) && (aDest.mStr!=(char*)gCommonEmptyBuffer)) {
|
if((aDest.mStr) && (aDest.mStr!=(char*)gCommonEmptyBuffer)) {
|
||||||
if(!anAgent)
|
Free(aDest);
|
||||||
anAgent=GetDefaultAgent();
|
|
||||||
|
|
||||||
if(anAgent) {
|
|
||||||
anAgent->Free(aDest);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
printf("%s\n","Leak occured in nsStr.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,11 +90,10 @@ void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) {
|
|||||||
* @param aNewLength -- new capacity of string in charSize units
|
* @param aNewLength -- new capacity of string in charSize units
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent) {
|
PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength) {
|
||||||
PRBool result=PR_TRUE;
|
PRBool result=PR_TRUE;
|
||||||
if(aNewLength>aString.mCapacity) {
|
if(aNewLength>aString.mCapacity) {
|
||||||
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
|
result=Realloc(aString,aNewLength);
|
||||||
result=theAgent->Realloc(aString,aNewLength);
|
|
||||||
if(aString.mStr)
|
if(aString.mStr)
|
||||||
AddNullTerminator(aString);
|
AddNullTerminator(aString);
|
||||||
}
|
}
|
||||||
@@ -126,20 +107,18 @@ PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent*
|
|||||||
* @param aNewLength -- new capacity of string in charSize units
|
* @param aNewLength -- new capacity of string in charSize units
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAgent) {
|
PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength) {
|
||||||
PRBool result=PR_TRUE;
|
PRBool result=PR_TRUE;
|
||||||
if(aNewLength>aDest.mCapacity) {
|
if(aNewLength>aDest.mCapacity) {
|
||||||
nsStr theTempStr;
|
nsStr theTempStr;
|
||||||
nsStr::Initialize(theTempStr,aDest.mCharSize);
|
nsStr::Initialize(theTempStr,aDest.mCharSize);
|
||||||
|
|
||||||
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
|
result=EnsureCapacity(theTempStr,aNewLength);
|
||||||
|
|
||||||
result=EnsureCapacity(theTempStr,aNewLength,theAgent);
|
|
||||||
if(result) {
|
if(result) {
|
||||||
if(aDest.mLength) {
|
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;
|
aDest.mStr = theTempStr.mStr;
|
||||||
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
|
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
|
||||||
aDest.mLength=theTempStr.mLength;
|
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 aSource is where chars are copied from
|
||||||
* @param aCount is the number of chars copied from aSource
|
* @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){
|
if(&aDest!=&aSource){
|
||||||
Truncate(aDest,0,anAgent);
|
Truncate(aDest,0);
|
||||||
Append(aDest,aSource,anOffset,aCount,anAgent);
|
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
|
* @param aSource is where char are copied from
|
||||||
* @aCount is the number of bytes to be copied
|
* @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){
|
if(anOffset<aSource.mLength){
|
||||||
PRUint32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
|
PRUint32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
|
||||||
PRUint32 theLength=(anOffset+theRealLen<aSource.mLength) ? theRealLen : (aSource.mLength-anOffset);
|
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;
|
PRBool isBigEnough=PR_TRUE;
|
||||||
if(aDest.mLength+theLength > aDest.mCapacity) {
|
if(aDest.mLength+theLength > aDest.mCapacity) {
|
||||||
isBigEnough=GrowCapacity(aDest,aDest.mLength+theLength,anAgent);
|
isBigEnough=GrowCapacity(aDest,aDest.mLength+theLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isBigEnough) {
|
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 aSrcOffset is where in aSource chars are copied from
|
||||||
* @param aCount is the number of chars from aSource to be inserted into aDest
|
* @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:
|
//there are a few cases for insert:
|
||||||
// 1. You're inserting chars into an empty string (assign)
|
// 1. You're inserting chars into an empty string (assign)
|
||||||
// 2. You're inserting onto the end of a string (append)
|
// 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 theTempStr;
|
||||||
nsStr::Initialize(theTempStr,aDest.mCharSize);
|
nsStr::Initialize(theTempStr,aDest.mCharSize);
|
||||||
|
|
||||||
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
|
PRBool isBigEnough=EnsureCapacity(theTempStr,aDest.mLength+theLength); //grow the temp buffer to the right size
|
||||||
PRBool isBigEnough=EnsureCapacity(theTempStr,aDest.mLength+theLength,theAgent); //grow the temp buffer to the right size
|
|
||||||
|
|
||||||
if(isBigEnough) {
|
if(isBigEnough) {
|
||||||
if(aDestOffset) {
|
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;
|
PRUint32 theRemains=aDest.mLength-aDestOffset;
|
||||||
if(theRemains) {
|
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;
|
aDest.mStr = theTempStr.mStr;
|
||||||
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
|
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
|
||||||
aDest.mCapacity=theTempStr.mCapacity;
|
aDest.mCapacity=theTempStr.mCapacity;
|
||||||
@@ -262,9 +240,9 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin
|
|||||||
}//if
|
}//if
|
||||||
//else nothing to do!
|
//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 aDestOffset is where in aDest deletion is to occur
|
||||||
* @param aCount is the number of chars to be deleted in aDest
|
* @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){
|
if(aDestOffset<aDest.mLength){
|
||||||
|
|
||||||
PRUint32 theDelta=aDest.mLength-aDestOffset;
|
PRUint32 theDelta=aDest.mLength-aDestOffset;
|
||||||
@@ -290,7 +268,7 @@ void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAg
|
|||||||
aDest.mLength-=theLength;
|
aDest.mLength-=theLength;
|
||||||
AddNullTerminator(aDest);
|
AddNullTerminator(aDest);
|
||||||
}
|
}
|
||||||
else Truncate(aDest,aDestOffset,anAgent);
|
else Truncate(aDest,aDestOffset);
|
||||||
}//if
|
}//if
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,7 +278,7 @@ void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAg
|
|||||||
* @param aDest is the nsStr to be truncated
|
* @param aDest is the nsStr to be truncated
|
||||||
* @param aDestOffset is where in aDest truncation is to occur
|
* @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){
|
if(aDestOffset<aDest.mLength){
|
||||||
aDest.mLength=aDestOffset;
|
aDest.mLength=aDestOffset;
|
||||||
AddNullTerminator(aDest);
|
AddNullTerminator(aDest);
|
||||||
@@ -342,7 +320,7 @@ void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool a
|
|||||||
}
|
}
|
||||||
if(0<theIndex) {
|
if(0<theIndex) {
|
||||||
if(theIndex<theMax) {
|
if(theIndex<theMax) {
|
||||||
Delete(aDest,0,theIndex,0);
|
Delete(aDest,0,theIndex);
|
||||||
}
|
}
|
||||||
else Truncate(aDest,0);
|
else Truncate(aDest,0);
|
||||||
}
|
}
|
||||||
@@ -515,7 +493,7 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgno
|
|||||||
|
|
||||||
nsStr theCopy;
|
nsStr theCopy;
|
||||||
nsStr::Initialize(theCopy,eOneByte);
|
nsStr::Initialize(theCopy,eOneByte);
|
||||||
nsStr::Assign(theCopy,aTarget,0,aTarget.mLength,0);
|
nsStr::Assign(theCopy,aTarget,0,aTarget.mLength);
|
||||||
if(aIgnoreCase){
|
if(aIgnoreCase){
|
||||||
nsStr::ChangeCase(theCopy,PR_FALSE); //force to lowercase
|
nsStr::ChangeCase(theCopy,PR_FALSE); //force to lowercase
|
||||||
}
|
}
|
||||||
@@ -538,7 +516,7 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgno
|
|||||||
}
|
}
|
||||||
index--;
|
index--;
|
||||||
} //while
|
} //while
|
||||||
nsStr::Destroy(theCopy,0);
|
nsStr::Destroy(theCopy);
|
||||||
}//if
|
}//if
|
||||||
}//if
|
}//if
|
||||||
return result;
|
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) {
|
CBufDescriptor::CBufDescriptor(char* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength) {
|
||||||
mBuffer=aString;
|
mBuffer=aString;
|
||||||
mCharSize=eOneByte;
|
mCharSize=eOneByte;
|
||||||
@@ -683,3 +712,5 @@ CBufDescriptor::CBufDescriptor(const PRUnichar* aString,PRBool aStackBased,PRUin
|
|||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -164,6 +164,7 @@
|
|||||||
|
|
||||||
#include "nscore.h"
|
#include "nscore.h"
|
||||||
#include "nsIAllocator.h"
|
#include "nsIAllocator.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -177,8 +178,6 @@ const PRInt32 kDefaultStringSize = 64;
|
|||||||
const PRInt32 kNotFound = -1;
|
const PRInt32 kNotFound = -1;
|
||||||
|
|
||||||
|
|
||||||
class nsIMemoryAgent;
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
class NS_COM CBufDescriptor {
|
class NS_COM CBufDescriptor {
|
||||||
@@ -228,7 +227,7 @@ struct NS_COM nsStr {
|
|||||||
* @param aString is the nsStr to be manipulated
|
* @param aString is the nsStr to be manipulated
|
||||||
* @param anAgent is the allocator to be used to the nsStr
|
* @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.
|
* 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
|
* @param anAgent is the allocator to be used on the nsStr
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
static PRBool EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0);
|
static PRBool EnsureCapacity(nsStr& aString,PRUint32 aNewLength);
|
||||||
static PRBool GrowCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0);
|
static PRBool GrowCapacity(nsStr& aString,PRUint32 aNewLength);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* These methods are used to append content to the given nsStr
|
* 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 aCount tells us the (max) # of chars to copy
|
||||||
* @param anAgent is the allocator to be used for alloc/free operations
|
* @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
|
* 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 aCount tells us the (max) # of chars to copy
|
||||||
* @param anAgent is the allocator to be used for alloc/free operations
|
* @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
|
* 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 aCount tells us the (max) # of chars to insert
|
||||||
* @param anAgent is the allocator to be used for alloc/free operations
|
* @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.
|
* 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 aCount tells us the (max) # of chars to delete
|
||||||
* @param anAgent is the allocator to be used for alloc/free operations
|
* @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.
|
* 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 aSrcOffset tells us where in source to start copying
|
||||||
* @param anAgent is the allocator to be used for alloc/free operations
|
* @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
|
* This method is used to perform a case conversion on the given string
|
||||||
@@ -388,6 +387,12 @@ struct NS_COM nsStr {
|
|||||||
char* mStr;
|
char* mStr;
|
||||||
PRUnichar* mUStr;
|
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;
|
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
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ static const char* kWhitespace="\b\t\r\n ";
|
|||||||
static void CSubsume(nsStr& aDest,nsStr& aSource){
|
static void CSubsume(nsStr& aDest,nsStr& aSource){
|
||||||
if(aSource.mStr && aSource.mLength) {
|
if(aSource.mStr && aSource.mLength) {
|
||||||
if(aSource.mOwnsBuffer){
|
if(aSource.mOwnsBuffer){
|
||||||
nsStr::Destroy(aDest,0);
|
nsStr::Destroy(aDest);
|
||||||
aDest.mStr=aSource.mStr;
|
aDest.mStr=aSource.mStr;
|
||||||
aDest.mLength=aSource.mLength;
|
aDest.mLength=aSource.mLength;
|
||||||
aDest.mCharSize=aSource.mCharSize;
|
aDest.mCharSize=aSource.mCharSize;
|
||||||
@@ -50,17 +50,17 @@ static void CSubsume(nsStr& aDest,nsStr& aSource){
|
|||||||
aSource.mStr=0;
|
aSource.mStr=0;
|
||||||
}
|
}
|
||||||
else{
|
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.
|
* Default constructor.
|
||||||
*/
|
*/
|
||||||
nsCString::nsCString(nsIMemoryAgent* anAgent) : mAgent(anAgent) {
|
nsCString::nsCString() {
|
||||||
nsStr::Initialize(*this,eOneByte);
|
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 aCString is a ptr to a 1-byte cstr
|
||||||
* @param aLength tells us how many chars to copy from given CString
|
* @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);
|
nsStr::Initialize(*this,eOneByte);
|
||||||
Assign(aCString,aLength);
|
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 aString is a ptr to a unichar string
|
||||||
* @param aLength tells us how many chars to copy from given aString
|
* @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);
|
nsStr::Initialize(*this,eOneByte);
|
||||||
|
|
||||||
if(aString && aLength){
|
if(aString && aLength){
|
||||||
@@ -101,7 +101,7 @@ nsCString::nsCString(const PRUnichar* aString,PRInt32 aLength,nsIMemoryAgent* an
|
|||||||
else aLength=temp.mLength=nsCRT::strlen(aString);
|
else aLength=temp.mLength=nsCRT::strlen(aString);
|
||||||
|
|
||||||
if(0<aLength)
|
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
|
* @update gess 1/4/99
|
||||||
* @param reference to another nsCString
|
* @param reference to another nsCString
|
||||||
*/
|
*/
|
||||||
nsCString::nsCString(const nsStr &aString,nsIMemoryAgent* anAgent) : mAgent(anAgent) {
|
nsCString::nsCString(const nsStr &aString) {
|
||||||
nsStr::Initialize(*this,eOneByte);
|
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
|
* @update gess 1/4/99
|
||||||
* @param reference to another nsCString
|
* @param reference to another nsCString
|
||||||
*/
|
*/
|
||||||
nsCString::nsCString(const nsCString& aString) :mAgent(aString.mAgent) {
|
nsCString::nsCString(const nsCString& aString) {
|
||||||
nsStr::Initialize(*this,aString.mCharSize);
|
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
|
* @update gess 1/4/99
|
||||||
* @param reference to a subsumeString
|
* @param reference to a subsumeString
|
||||||
*/
|
*/
|
||||||
nsCString::nsCString(nsSubsumeCStr& aSubsumeStr) :mAgent(0) {
|
nsCString::nsCString(nsSubsumeCStr& aSubsumeStr) {
|
||||||
CSubsume(*this,aSubsumeStr);
|
CSubsume(*this,aSubsumeStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +138,7 @@ nsCString::nsCString(nsSubsumeCStr& aSubsumeStr) :mAgent(0) {
|
|||||||
* Destructor
|
* Destructor
|
||||||
*/
|
*/
|
||||||
nsCString::~nsCString() {
|
nsCString::~nsCString() {
|
||||||
nsStr::Destroy(*this,mAgent);
|
nsStr::Destroy(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nsCString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
void nsCString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
||||||
@@ -155,7 +155,7 @@ void nsCString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
|||||||
* @return nada
|
* @return nada
|
||||||
*/
|
*/
|
||||||
void nsCString::Truncate(PRInt32 anIndex) {
|
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) {
|
void nsCString::SetCapacity(PRUint32 aLength) {
|
||||||
if(aLength>mCapacity) {
|
if(aLength>mCapacity) {
|
||||||
GrowCapacity(*this,aLength,mAgent);
|
GrowCapacity(*this,aLength);
|
||||||
}
|
}
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
}
|
}
|
||||||
@@ -262,7 +262,7 @@ PRBool nsCString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
|
|||||||
*/
|
*/
|
||||||
nsSubsumeCStr nsCString::operator+(const nsCString& aString){
|
nsSubsumeCStr nsCString::operator+(const nsCString& aString){
|
||||||
nsCString temp(*this); //make a temp string the same size as this...
|
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);
|
return nsSubsumeCStr(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -613,11 +613,19 @@ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) {
|
|||||||
}
|
}
|
||||||
theDigit=(theChar-'A')+10;
|
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) {
|
else if('-'==theChar) {
|
||||||
result=-result;
|
result=-result;
|
||||||
break;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -634,6 +642,7 @@ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call this method to extract the rightmost numeric value from the given
|
* Call this method to extract the rightmost numeric value from the given
|
||||||
* 1-byte input string, and simultaneously determine the radix.
|
* 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.
|
* @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
|
* @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);
|
//begin by skipping over leading chars that shouldn't be part of the number...
|
||||||
char* cp = (kNotFound==decPt) ? aString.mStr + aString.mLength-1 : aString.mStr+decPt-1;
|
|
||||||
|
|
||||||
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<endcp){
|
||||||
while (cp >= aString.mStr) {
|
const char* pos=(const char*)memchr(validChars,*cp,len);
|
||||||
if((*cp>='0') && (*cp<='9')){
|
if(!pos) {
|
||||||
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...
|
|
||||||
cp++;
|
cp++;
|
||||||
while (--cp >= aString.mStr) {
|
|
||||||
if((*cp>='0') && (*cp<='9')){
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
else if((*cp>='A') && (*cp<='F')) {
|
else break;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
else if((*cp=='-') || (*cp=='+')){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if(('#'==(*cp)) || ('X'==(*cp)))
|
|
||||||
aRadix=kRadix16;
|
|
||||||
cp++; //move back by one
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(cp>aString.mStr)
|
|
||||||
aString.Cut(0,cp-aString.mStr);
|
|
||||||
PRInt32 result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK;
|
|
||||||
|
|
||||||
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -726,11 +735,12 @@ PRUint32 nsCString::DetermineRadix(void) {
|
|||||||
PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
||||||
|
|
||||||
//copy chars to local buffer -- step down from 2 bytes to 1 if necessary...
|
//copy chars to local buffer -- step down from 2 bytes to 1 if necessary...
|
||||||
|
PRInt32 result=0;
|
||||||
nsCAutoString theString(*this);
|
nsCAutoString theString(*this);
|
||||||
PRUint32 theRadix=aRadix;
|
PRUint32 theRadix=aRadix;
|
||||||
PRInt32 result=0;
|
|
||||||
|
|
||||||
*anErrorCode=GetNumericSubstring(theString,theRadix); //we actually don't use this radix; use given radix instead
|
*anErrorCode=GetNumericSubstring(theString,theRadix); //we actually don't use this radix; use given radix instead
|
||||||
|
|
||||||
if(NS_OK==*anErrorCode){
|
if(NS_OK==*anErrorCode){
|
||||||
if(kAutoDetect==aRadix)
|
if(kAutoDetect==aRadix)
|
||||||
aRadix=theRadix;
|
aRadix=theRadix;
|
||||||
@@ -755,13 +765,13 @@ PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
|||||||
*/
|
*/
|
||||||
nsCString& nsCString::Assign(const nsStr& aString,PRInt32 aCount) {
|
nsCString& nsCString::Assign(const nsStr& aString,PRInt32 aCount) {
|
||||||
if(this!=&aString){
|
if(this!=&aString){
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
|
|
||||||
if(aCount<0)
|
if(aCount<0)
|
||||||
aCount=aString.mLength;
|
aCount=aString.mLength;
|
||||||
else aCount=MinInt(aCount,aString.mLength);
|
else aCount=MinInt(aCount,aString.mLength);
|
||||||
|
|
||||||
nsStr::Assign(*this,aString,0,aCount,mAgent);
|
nsStr::Assign(*this,aString,0,aCount);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -773,7 +783,7 @@ nsCString& nsCString::Assign(const nsStr& aString,PRInt32 aCount) {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
nsCString& nsCString::Assign(const char* aCString,PRInt32 aCount) {
|
nsCString& nsCString::Assign(const char* aCString,PRInt32 aCount) {
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
if(aCString){
|
if(aCString){
|
||||||
Append(aCString,aCount);
|
Append(aCString,aCount);
|
||||||
}
|
}
|
||||||
@@ -787,7 +797,7 @@ nsCString& nsCString::Assign(const char* aCString,PRInt32 aCount) {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) {
|
nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) {
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
|
|
||||||
if(aString){
|
if(aString){
|
||||||
nsStr temp;
|
nsStr temp;
|
||||||
@@ -806,7 +816,7 @@ nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) {
|
|||||||
else aCount=temp.mLength=nsCRT::strlen(aString);
|
else aCount=temp.mLength=nsCRT::strlen(aString);
|
||||||
|
|
||||||
if(0<aCount)
|
if(0<aCount)
|
||||||
nsStr::Append(*this,temp,0,aCount,mAgent);
|
nsStr::Append(*this,temp,0,aCount);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -818,7 +828,7 @@ nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
nsCString& nsCString::Assign(PRUnichar aChar) {
|
nsCString& nsCString::Assign(PRUnichar aChar) {
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
return Append(aChar);
|
return Append(aChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -829,7 +839,7 @@ nsCString& nsCString::Assign(PRUnichar aChar) {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
nsCString& nsCString::Assign(char aChar) {
|
nsCString& nsCString::Assign(char aChar) {
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
return Append(aChar);
|
return Append(aChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -864,7 +874,24 @@ nsCString& nsCString::Append(const nsCString& aString,PRInt32 aCount) {
|
|||||||
aCount=aString.mLength;
|
aCount=aString.mLength;
|
||||||
else aCount=MinInt(aCount,aString.mLength);
|
else aCount=MinInt(aCount,aString.mLength);
|
||||||
if(0<aCount)
|
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;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -893,7 +920,7 @@ nsCString& nsCString::Append(const char* aCString,PRInt32 aCount) {
|
|||||||
else aCount=temp.mLength=nsCRT::strlen(aCString);
|
else aCount=temp.mLength=nsCRT::strlen(aCString);
|
||||||
|
|
||||||
if(0<aCount)
|
if(0<aCount)
|
||||||
nsStr::Append(*this,temp,0,aCount,mAgent);
|
nsStr::Append(*this,temp,0,aCount);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -913,7 +940,7 @@ nsCString& nsCString::Append(PRUnichar aChar) {
|
|||||||
Initialize(temp,eTwoByte);
|
Initialize(temp,eTwoByte);
|
||||||
temp.mUStr=buf;
|
temp.mUStr=buf;
|
||||||
temp.mLength=1;
|
temp.mLength=1;
|
||||||
nsStr::Append(*this,temp,0,1,mAgent);
|
nsStr::Append(*this,temp,0,1);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -931,7 +958,7 @@ nsCString& nsCString::Append(char aChar) {
|
|||||||
Initialize(temp,eOneByte);
|
Initialize(temp,eOneByte);
|
||||||
temp.mStr=buf;
|
temp.mStr=buf;
|
||||||
temp.mLength=1;
|
temp.mLength=1;
|
||||||
nsStr::Append(*this,temp,0,1,mAgent);
|
nsStr::Append(*this,temp,0,1);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -962,12 +989,12 @@ nsCString& nsCString::Append(PRInt32 anInteger,PRInt32 aRadix) {
|
|||||||
|
|
||||||
PRBool isfirst=PR_TRUE;
|
PRBool isfirst=PR_TRUE;
|
||||||
while(mask1>=1) {
|
while(mask1>=1) {
|
||||||
PRInt32 div=theInt/mask1;
|
PRInt32 theDiv=theInt/mask1;
|
||||||
if((div) || (!isfirst)) {
|
if((theDiv) || (!isfirst)) {
|
||||||
buf[charpos++]="0123456789abcdef"[div];
|
buf[charpos++]="0123456789abcdef"[theDiv];
|
||||||
isfirst=PR_FALSE;
|
isfirst=PR_FALSE;
|
||||||
}
|
}
|
||||||
theInt-=div*mask1;
|
theInt-=theDiv*mask1;
|
||||||
mask1/=aRadix;
|
mask1/=aRadix;
|
||||||
}
|
}
|
||||||
return Append(buf);
|
return Append(buf);
|
||||||
@@ -1001,7 +1028,7 @@ PRUint32 nsCString::Left(nsCString& aDest,PRInt32 aCount) const{
|
|||||||
if(aCount<0)
|
if(aCount<0)
|
||||||
aCount=mLength;
|
aCount=mLength;
|
||||||
else aCount=MinInt(aCount,mLength);
|
else aCount=MinInt(aCount,mLength);
|
||||||
nsStr::Assign(aDest,*this,0,aCount,mAgent);
|
nsStr::Assign(aDest,*this,0,aCount);
|
||||||
return aDest.mLength;
|
return aDest.mLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1018,7 +1045,7 @@ PRUint32 nsCString::Mid(nsCString& aDest,PRUint32 anOffset,PRInt32 aCount) const
|
|||||||
if(aCount<0)
|
if(aCount<0)
|
||||||
aCount=mLength;
|
aCount=mLength;
|
||||||
else aCount=MinInt(aCount,mLength);
|
else aCount=MinInt(aCount,mLength);
|
||||||
nsStr::Assign(aDest,*this,anOffset,aCount,mAgent);
|
nsStr::Assign(aDest,*this,anOffset,aCount);
|
||||||
return aDest.mLength;
|
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) {
|
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;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1079,7 +1106,7 @@ nsCString& nsCString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCou
|
|||||||
else aCount=temp.mLength=nsCRT::strlen(aCString);
|
else aCount=temp.mLength=nsCRT::strlen(aCString);
|
||||||
|
|
||||||
if(temp.mLength && (0<aCount)){
|
if(temp.mLength && (0<aCount)){
|
||||||
nsStr::Insert(*this,anOffset,temp,0,aCount,0);
|
nsStr::Insert(*this,anOffset,temp,0,aCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
@@ -1101,7 +1128,7 @@ nsCString& nsCString::Insert(PRUnichar aChar,PRUint32 anOffset){
|
|||||||
nsStr::Initialize(temp,eTwoByte);
|
nsStr::Initialize(temp,eTwoByte);
|
||||||
temp.mUStr=theBuffer;
|
temp.mUStr=theBuffer;
|
||||||
temp.mLength=1;
|
temp.mLength=1;
|
||||||
nsStr::Insert(*this,anOffset,temp,0,1,0);
|
nsStr::Insert(*this,anOffset,temp,0,1);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1121,7 +1148,7 @@ nsCString& nsCString::Insert(char aChar,PRUint32 anOffset){
|
|||||||
nsStr::Initialize(temp,eOneByte);
|
nsStr::Initialize(temp,eOneByte);
|
||||||
temp.mStr=theBuffer;
|
temp.mStr=theBuffer;
|
||||||
temp.mLength=1;
|
temp.mLength=1;
|
||||||
nsStr::Insert(*this,anOffset,temp,0,1,0);
|
nsStr::Insert(*this,anOffset,temp,0,1);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1136,7 +1163,7 @@ nsCString& nsCString::Insert(char aChar,PRUint32 anOffset){
|
|||||||
*/
|
*/
|
||||||
nsCString& nsCString::Cut(PRUint32 anOffset, PRInt32 aCount) {
|
nsCString& nsCString::Cut(PRUint32 anOffset, PRInt32 aCount) {
|
||||||
if(0<aCount) {
|
if(0<aCount) {
|
||||||
nsStr::Delete(*this,anOffset,aCount,mAgent);
|
nsStr::Delete(*this,anOffset,aCount);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -1560,10 +1587,8 @@ PRBool nsCString::Equals(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 aCo
|
|||||||
class nsCStringDeallocator: public nsDequeFunctor{
|
class nsCStringDeallocator: public nsDequeFunctor{
|
||||||
public:
|
public:
|
||||||
virtual void* operator()(void* anObject) {
|
virtual void* operator()(void* anObject) {
|
||||||
static nsMemoryAgent theAgent;
|
|
||||||
nsCString* aString= (nsCString*)anObject;
|
nsCString* aString= (nsCString*)anObject;
|
||||||
if(aString){
|
if(aString){
|
||||||
aString->mAgent=&theAgent;
|
|
||||||
delete aString;
|
delete aString;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1722,7 +1747,6 @@ NS_COM int fputs(const nsCString& aString, FILE* out)
|
|||||||
*/
|
*/
|
||||||
nsCAutoString::nsCAutoString() : nsCString(){
|
nsCAutoString::nsCAutoString() : nsCString(){
|
||||||
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
||||||
mAgent=0;
|
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1732,7 +1756,6 @@ nsCAutoString::nsCAutoString() : nsCString(){
|
|||||||
*/
|
*/
|
||||||
nsCAutoString::nsCAutoString(const nsCAutoString& aString) : nsCString() {
|
nsCAutoString::nsCAutoString(const nsCAutoString& aString) : nsCString() {
|
||||||
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
||||||
mAgent=0;
|
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aString);
|
Append(aString);
|
||||||
}
|
}
|
||||||
@@ -1744,7 +1767,6 @@ nsCAutoString::nsCAutoString(const nsCAutoString& aString) : nsCString() {
|
|||||||
*/
|
*/
|
||||||
nsCAutoString::nsCAutoString(const char* aCString,PRInt32 aLength) : nsCString() {
|
nsCAutoString::nsCAutoString(const char* aCString,PRInt32 aLength) : nsCString() {
|
||||||
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
||||||
mAgent=0;
|
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aCString,aLength);
|
Append(aCString,aLength);
|
||||||
}
|
}
|
||||||
@@ -1754,7 +1776,6 @@ nsCAutoString::nsCAutoString(const char* aCString,PRInt32 aLength) : nsCString()
|
|||||||
* @param aBuffer -- descibes external buffer
|
* @param aBuffer -- descibes external buffer
|
||||||
*/
|
*/
|
||||||
nsCAutoString::nsCAutoString(const CBufDescriptor& aBuffer) : nsCString() {
|
nsCAutoString::nsCAutoString(const CBufDescriptor& aBuffer) : nsCString() {
|
||||||
mAgent=0;
|
|
||||||
if(!aBuffer.mBuffer) {
|
if(!aBuffer.mBuffer) {
|
||||||
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
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
|
* @param aString is a ptr to a unistr
|
||||||
*/
|
*/
|
||||||
nsCAutoString::nsCAutoString(const PRUnichar* aString,PRInt32 aLength) : nsCString() {
|
nsCAutoString::nsCAutoString(const PRUnichar* aString,PRInt32 aLength) : nsCString() {
|
||||||
mAgent=0;
|
|
||||||
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aString,aLength);
|
Append(aString,aLength);
|
||||||
@@ -1781,7 +1801,6 @@ nsCAutoString::nsCAutoString(const PRUnichar* aString,PRInt32 aLength) : nsCStri
|
|||||||
* @param
|
* @param
|
||||||
*/
|
*/
|
||||||
nsCAutoString::nsCAutoString(const nsStr& aString) : nsCString() {
|
nsCAutoString::nsCAutoString(const nsStr& aString) : nsCString() {
|
||||||
mAgent=0;
|
|
||||||
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aString);
|
Append(aString);
|
||||||
@@ -1794,7 +1813,6 @@ nsCAutoString::nsCAutoString(const nsStr& aString) : nsCString() {
|
|||||||
* @param
|
* @param
|
||||||
*/
|
*/
|
||||||
nsCAutoString::nsCAutoString(PRUnichar aChar) : nsCString(){
|
nsCAutoString::nsCAutoString(PRUnichar aChar) : nsCString(){
|
||||||
mAgent=0;
|
|
||||||
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aChar);
|
Append(aChar);
|
||||||
@@ -1807,12 +1825,10 @@ nsCAutoString::nsCAutoString(PRUnichar aChar) : nsCString(){
|
|||||||
*/
|
*/
|
||||||
#ifdef AIX
|
#ifdef AIX
|
||||||
nsCAutoString::nsCAutoString(const nsSubsumeCStr& aSubsumeStr) :nsCString() {
|
nsCAutoString::nsCAutoString(const nsSubsumeCStr& aSubsumeStr) :nsCString() {
|
||||||
mAgent=0;
|
|
||||||
nsSubsumeCStr temp(aSubsumeStr); // a temp is needed for the AIX compiler
|
nsSubsumeCStr temp(aSubsumeStr); // a temp is needed for the AIX compiler
|
||||||
CSubsume(*this,temp);
|
CSubsume(*this,temp);
|
||||||
#else
|
#else
|
||||||
nsCAutoString::nsCAutoString( nsSubsumeCStr& aSubsumeStr) :nsCString() {
|
nsCAutoString::nsCAutoString( nsSubsumeCStr& aSubsumeStr) :nsCString() {
|
||||||
mAgent=0;
|
|
||||||
CSubsume(*this,aSubsumeStr);
|
CSubsume(*this,aSubsumeStr);
|
||||||
#endif // AIX
|
#endif // AIX
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,26 +51,25 @@ class NS_COM nsCString : public nsStr {
|
|||||||
/**
|
/**
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
*/
|
*/
|
||||||
nsCString(nsIMemoryAgent* anAgent=0);
|
nsCString();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constructor accepts an isolatin string
|
* This constructor accepts an isolatin string
|
||||||
* @param aCString is a ptr to a 1-byte cstr
|
* @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
|
* This constructor accepts a unichar string
|
||||||
* @param aCString is a ptr to a 2-byte cstr
|
* @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
|
* This is a copy constructor that accepts an nsStr
|
||||||
* @param reference to another nsCString
|
* @param reference to another nsCString
|
||||||
*/
|
*/
|
||||||
nsCString(const nsStr&,nsIMemoryAgent* anAgent=0);
|
nsCString(const nsStr&);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is our copy constructor
|
* This is our copy constructor
|
||||||
@@ -150,6 +149,10 @@ PRBool IsEmpty(void) const {
|
|||||||
Accessor methods...
|
Accessor methods...
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve const ptr to internal buffer; DO NOT TRY TO FREE IT!
|
||||||
|
*/
|
||||||
const char* GetBuffer(void) const;
|
const char* GetBuffer(void) const;
|
||||||
|
|
||||||
|
|
||||||
@@ -412,6 +415,7 @@ nsCString& Append(const nsCString& aString) {return Append(aString,aString.mLeng
|
|||||||
* @return number of chars copied
|
* @return number of chars copied
|
||||||
*/
|
*/
|
||||||
nsCString& Append(const nsCString& aString,PRInt32 aCount);
|
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(const char* aString,PRInt32 aCount=-1);
|
||||||
nsCString& Append(PRUnichar aChar);
|
nsCString& Append(PRUnichar aChar);
|
||||||
nsCString& Append(char aChar);
|
nsCString& Append(char aChar);
|
||||||
@@ -670,9 +674,6 @@ PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const;
|
|||||||
static void Recycle(nsCString* aString);
|
static void Recycle(nsCString* aString);
|
||||||
static nsCString* CreateString(void);
|
static nsCString* CreateString(void);
|
||||||
|
|
||||||
|
|
||||||
nsIMemoryAgent* mAgent;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern NS_COM int fputs(const nsCString& aString, FILE* out);
|
extern NS_COM int fputs(const nsCString& aString, FILE* out);
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ static const char* kWhitespace="\b\t\r\n ";
|
|||||||
static void Subsume(nsStr& aDest,nsStr& aSource){
|
static void Subsume(nsStr& aDest,nsStr& aSource){
|
||||||
if(aSource.mStr && aSource.mLength) {
|
if(aSource.mStr && aSource.mLength) {
|
||||||
if(aSource.mOwnsBuffer){
|
if(aSource.mOwnsBuffer){
|
||||||
nsStr::Destroy(aDest,0);
|
nsStr::Destroy(aDest);
|
||||||
aDest.mStr=aSource.mStr;
|
aDest.mStr=aSource.mStr;
|
||||||
aDest.mLength=aSource.mLength;
|
aDest.mLength=aSource.mLength;
|
||||||
aDest.mCharSize=aSource.mCharSize;
|
aDest.mCharSize=aSource.mCharSize;
|
||||||
@@ -48,17 +48,17 @@ static void Subsume(nsStr& aDest,nsStr& aSource){
|
|||||||
aSource.mStr=0;
|
aSource.mStr=0;
|
||||||
}
|
}
|
||||||
else{
|
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.
|
* Default constructor.
|
||||||
*/
|
*/
|
||||||
nsString::nsString(nsIMemoryAgent* anAgent) : mAgent(anAgent) {
|
nsString::nsString() {
|
||||||
nsStr::Initialize(*this,eTwoByte);
|
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 aCString is a ptr to a 1-byte cstr
|
||||||
* @param aLength tells us how many chars to copy from given CString
|
* @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);
|
nsStr::Initialize(*this,eTwoByte);
|
||||||
Assign(aCString);
|
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 aString is a ptr to a unichar string
|
||||||
* @param aLength tells us how many chars to copy from given aString
|
* @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);
|
nsStr::Initialize(*this,eTwoByte);
|
||||||
Assign(aString);
|
Assign(aString);
|
||||||
}
|
}
|
||||||
@@ -89,9 +89,9 @@ nsString::nsString(const PRUnichar* aString,nsIMemoryAgent* anAgent) : mAgent(an
|
|||||||
* @update gess 1/4/99
|
* @update gess 1/4/99
|
||||||
* @param reference to another nsCString
|
* @param reference to another nsCString
|
||||||
*/
|
*/
|
||||||
nsString::nsString(const nsStr &aString,nsIMemoryAgent* anAgent) : mAgent(anAgent) {
|
nsString::nsString(const nsStr &aString) {
|
||||||
nsStr::Initialize(*this,eTwoByte);
|
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
|
* @update gess 1/4/99
|
||||||
* @param reference to another nsString
|
* @param reference to another nsString
|
||||||
*/
|
*/
|
||||||
nsString::nsString(const nsString& aString) :mAgent(aString.mAgent) {
|
nsString::nsString(const nsString& aString) {
|
||||||
nsStr::Initialize(*this,eTwoByte);
|
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
|
* @update gess 1/4/99
|
||||||
* @param reference to a subsumeString
|
* @param reference to a subsumeString
|
||||||
*/
|
*/
|
||||||
nsString::nsString(nsSubsumeStr& aSubsumeStr) :mAgent(0) {
|
nsString::nsString(nsSubsumeStr& aSubsumeStr) {
|
||||||
nsStr::Initialize(*this,eTwoByte);
|
nsStr::Initialize(*this,eTwoByte);
|
||||||
Subsume(*this,aSubsumeStr);
|
Subsume(*this,aSubsumeStr);
|
||||||
}
|
}
|
||||||
@@ -119,7 +119,7 @@ nsString::nsString(nsSubsumeStr& aSubsumeStr) :mAgent(0) {
|
|||||||
* Make sure we call nsStr::Destroy.
|
* Make sure we call nsStr::Destroy.
|
||||||
*/
|
*/
|
||||||
nsString::~nsString() {
|
nsString::~nsString() {
|
||||||
nsStr::Destroy(*this,mAgent);
|
nsStr::Destroy(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
||||||
@@ -136,7 +136,7 @@ void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
|||||||
* @return nada
|
* @return nada
|
||||||
*/
|
*/
|
||||||
void nsString::Truncate(PRInt32 anIndex) {
|
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) {
|
void nsString::SetCapacity(PRUint32 aLength) {
|
||||||
if(aLength>mCapacity) {
|
if(aLength>mCapacity) {
|
||||||
GrowCapacity(*this,aLength,mAgent);
|
GrowCapacity(*this,aLength);
|
||||||
}
|
}
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
}
|
}
|
||||||
@@ -270,7 +270,7 @@ PRBool nsString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
|
|||||||
*/
|
*/
|
||||||
nsSubsumeStr nsString::operator+(const nsStr& aString){
|
nsSubsumeStr nsString::operator+(const nsStr& aString){
|
||||||
nsString temp(*this); //make a temp string the same size as this...
|
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);
|
return nsSubsumeStr(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,7 +282,7 @@ nsSubsumeStr nsString::operator+(const nsStr& aString){
|
|||||||
*/
|
*/
|
||||||
nsSubsumeStr nsString::operator+(const nsString& aString){
|
nsSubsumeStr nsString::operator+(const nsString& aString){
|
||||||
nsString temp(*this); //make a temp string the same size as this...
|
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);
|
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
|
* @return non-zero error code if this string is non-numeric
|
||||||
*/
|
*/
|
||||||
static 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);
|
//begin by skipping over leading chars that shouldn't be part of the number...
|
||||||
char* cp = (kNotFound==decPt) ? aString.mStr + aString.mLength-1 : aString.mStr+decPt-1;
|
|
||||||
|
|
||||||
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<endcp){
|
||||||
while (cp >= aString.mStr) {
|
const char* pos=(const char*)memchr(validChars,*cp,len);
|
||||||
if((*cp>='0') && (*cp<='9')){
|
if(!pos) {
|
||||||
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...
|
|
||||||
cp++;
|
cp++;
|
||||||
while (--cp >= aString.mStr) {
|
|
||||||
if((*cp>='0') && (*cp<='9')){
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
else if((*cp>='A') && (*cp<='F')) {
|
else break;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
else if((*cp=='-') || (*cp=='+')){
|
|
||||||
break;
|
while(cp<endcp){
|
||||||
|
char theChar=toupper(*cp);
|
||||||
|
|
||||||
|
if((theChar>='0') && (theChar<='9')) {
|
||||||
|
*to++=theChar;
|
||||||
}
|
}
|
||||||
else {
|
else if((theChar>='A') && (theChar<='F')) {
|
||||||
if(('#'==(*cp)) || ('X'==(*cp)))
|
aRadix=16;
|
||||||
aRadix=kRadix16;
|
*to++=theChar;
|
||||||
cp++; //move back by one
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -865,9 +866,9 @@ PRUint32 nsString::DetermineRadix(void) {
|
|||||||
PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
||||||
|
|
||||||
//copy chars to local buffer -- step down from 2 bytes to 1 if necessary...
|
//copy chars to local buffer -- step down from 2 bytes to 1 if necessary...
|
||||||
|
PRInt32 result=0;
|
||||||
nsCAutoString theString(*this);
|
nsCAutoString theString(*this);
|
||||||
PRUint32 theRadix=aRadix;
|
PRUint32 theRadix=aRadix;
|
||||||
PRInt32 result=0;
|
|
||||||
|
|
||||||
*anErrorCode=GetNumericSubstring(theString,theRadix); //we actually don't use this radix; use given radix instead
|
*anErrorCode=GetNumericSubstring(theString,theRadix); //we actually don't use this radix; use given radix instead
|
||||||
if(NS_OK==*anErrorCode){
|
if(NS_OK==*anErrorCode){
|
||||||
@@ -893,13 +894,13 @@ PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
|||||||
*/
|
*/
|
||||||
nsString& nsString::Assign(const nsStr& aString,PRInt32 aCount) {
|
nsString& nsString::Assign(const nsStr& aString,PRInt32 aCount) {
|
||||||
if(this!=&aString){
|
if(this!=&aString){
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
|
|
||||||
if(aCount<0)
|
if(aCount<0)
|
||||||
aCount=aString.mLength;
|
aCount=aString.mLength;
|
||||||
else aCount=MinInt(aCount,aString.mLength);
|
else aCount=MinInt(aCount,aString.mLength);
|
||||||
|
|
||||||
nsStr::Assign(*this,aString,0,aCount,mAgent);
|
nsStr::Assign(*this,aString,0,aCount);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -912,7 +913,7 @@ nsString& nsString::Assign(const nsStr& aString,PRInt32 aCount) {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
nsString& nsString::Assign(const char* aCString,PRInt32 aCount) {
|
nsString& nsString::Assign(const char* aCString,PRInt32 aCount) {
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
if(aCString){
|
if(aCString){
|
||||||
Append(aCString,aCount);
|
Append(aCString,aCount);
|
||||||
}
|
}
|
||||||
@@ -926,7 +927,7 @@ nsString& nsString::Assign(const char* aCString,PRInt32 aCount) {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
nsString& nsString::Assign(const PRUnichar* aString,PRInt32 aCount) {
|
nsString& nsString::Assign(const PRUnichar* aString,PRInt32 aCount) {
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
if(aString){
|
if(aString){
|
||||||
Append(aString,aCount);
|
Append(aString,aCount);
|
||||||
}
|
}
|
||||||
@@ -940,7 +941,7 @@ nsString& nsString::Assign(const PRUnichar* aString,PRInt32 aCount) {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
nsString& nsString::Assign(char aChar) {
|
nsString& nsString::Assign(char aChar) {
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
return Append(aChar);
|
return Append(aChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -951,7 +952,7 @@ nsString& nsString::Assign(char aChar) {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
nsString& nsString::Assign(PRUnichar aChar) {
|
nsString& nsString::Assign(PRUnichar aChar) {
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
return Append(aChar);
|
return Append(aChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -988,7 +989,7 @@ nsString& nsString::Append(const nsStr& aString,PRInt32 aCount) {
|
|||||||
else aCount=MinInt(aCount,aString.mLength);
|
else aCount=MinInt(aCount,aString.mLength);
|
||||||
|
|
||||||
if(0<aCount)
|
if(0<aCount)
|
||||||
nsStr::Append(*this,aString,0,aCount,mAgent);
|
nsStr::Append(*this,aString,0,aCount);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1005,7 +1006,7 @@ nsString& nsString::Append(const nsString& aString,PRInt32 aCount) {
|
|||||||
aCount=aString.mLength;
|
aCount=aString.mLength;
|
||||||
else aCount=MinInt(aCount,aString.mLength);
|
else aCount=MinInt(aCount,aString.mLength);
|
||||||
if(0<aCount)
|
if(0<aCount)
|
||||||
nsStr::Append(*this,aString,0,aCount,mAgent);
|
nsStr::Append(*this,aString,0,aCount);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1034,7 +1035,7 @@ nsString& nsString::Append(const char* aCString,PRInt32 aCount) {
|
|||||||
else aCount=temp.mLength=nsCRT::strlen(aCString);
|
else aCount=temp.mLength=nsCRT::strlen(aCString);
|
||||||
|
|
||||||
if(0<aCount)
|
if(0<aCount)
|
||||||
nsStr::Append(*this,temp,0,aCount,mAgent);
|
nsStr::Append(*this,temp,0,aCount);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -1064,7 +1065,7 @@ nsString& nsString::Append(const PRUnichar* aString,PRInt32 aCount) {
|
|||||||
else aCount=temp.mLength=nsCRT::strlen(aString);
|
else aCount=temp.mLength=nsCRT::strlen(aString);
|
||||||
|
|
||||||
if(0<aCount)
|
if(0<aCount)
|
||||||
nsStr::Append(*this,temp,0,aCount,mAgent);
|
nsStr::Append(*this,temp,0,aCount);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -1083,7 +1084,7 @@ nsString& nsString::Append(char aChar) {
|
|||||||
Initialize(temp,eOneByte);
|
Initialize(temp,eOneByte);
|
||||||
temp.mStr=buf;
|
temp.mStr=buf;
|
||||||
temp.mLength=1;
|
temp.mLength=1;
|
||||||
nsStr::Append(*this,temp,0,1,mAgent);
|
nsStr::Append(*this,temp,0,1);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1101,7 +1102,7 @@ nsString& nsString::Append(PRUnichar aChar) {
|
|||||||
Initialize(temp,eTwoByte);
|
Initialize(temp,eTwoByte);
|
||||||
temp.mUStr=buf;
|
temp.mUStr=buf;
|
||||||
temp.mLength=1;
|
temp.mLength=1;
|
||||||
nsStr::Append(*this,temp,0,1,mAgent);
|
nsStr::Append(*this,temp,0,1);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1132,12 +1133,12 @@ nsString& nsString::Append(PRInt32 anInteger,PRInt32 aRadix) {
|
|||||||
|
|
||||||
PRBool isfirst=PR_TRUE;
|
PRBool isfirst=PR_TRUE;
|
||||||
while(mask1>=1) {
|
while(mask1>=1) {
|
||||||
PRInt32 div=theInt/mask1;
|
PRInt32 theDiv=theInt/mask1;
|
||||||
if((div) || (!isfirst)) {
|
if((theDiv) || (!isfirst)) {
|
||||||
buf[charpos++]="0123456789abcdef"[div];
|
buf[charpos++]="0123456789abcdef"[theDiv];
|
||||||
isfirst=PR_FALSE;
|
isfirst=PR_FALSE;
|
||||||
}
|
}
|
||||||
theInt-=div*mask1;
|
theInt-=theDiv*mask1;
|
||||||
mask1/=aRadix;
|
mask1/=aRadix;
|
||||||
}
|
}
|
||||||
return Append(buf);
|
return Append(buf);
|
||||||
@@ -1173,7 +1174,7 @@ PRUint32 nsString::Left(nsString& aDest,PRInt32 aCount) const{
|
|||||||
if(aCount<0)
|
if(aCount<0)
|
||||||
aCount=mLength;
|
aCount=mLength;
|
||||||
else aCount=MinInt(aCount,mLength);
|
else aCount=MinInt(aCount,mLength);
|
||||||
nsStr::Assign(aDest,*this,0,aCount,mAgent);
|
nsStr::Assign(aDest,*this,0,aCount);
|
||||||
|
|
||||||
return aDest.mLength;
|
return aDest.mLength;
|
||||||
}
|
}
|
||||||
@@ -1191,7 +1192,7 @@ PRUint32 nsString::Mid(nsString& aDest,PRUint32 anOffset,PRInt32 aCount) const{
|
|||||||
if(aCount<0)
|
if(aCount<0)
|
||||||
aCount=mLength;
|
aCount=mLength;
|
||||||
else aCount=MinInt(aCount,mLength);
|
else aCount=MinInt(aCount,mLength);
|
||||||
nsStr::Assign(aDest,*this,anOffset,aCount,mAgent);
|
nsStr::Assign(aDest,*this,anOffset,aCount);
|
||||||
|
|
||||||
return aDest.mLength;
|
return aDest.mLength;
|
||||||
}
|
}
|
||||||
@@ -1221,7 +1222,7 @@ PRUint32 nsString::Right(nsString& aDest,PRInt32 aCount) const{
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
nsString& nsString::Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) {
|
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;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1252,7 +1253,7 @@ nsString& nsString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCount
|
|||||||
else aCount=temp.mLength=nsCRT::strlen(aCString);
|
else aCount=temp.mLength=nsCRT::strlen(aCString);
|
||||||
|
|
||||||
if(0<aCount){
|
if(0<aCount){
|
||||||
nsStr::Insert(*this,anOffset,temp,0,aCount,0);
|
nsStr::Insert(*this,anOffset,temp,0,aCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
@@ -1285,7 +1286,7 @@ nsString& nsString::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32 aC
|
|||||||
else aCount=temp.mLength=nsCRT::strlen(aString);
|
else aCount=temp.mLength=nsCRT::strlen(aString);
|
||||||
|
|
||||||
if(0<aCount){
|
if(0<aCount){
|
||||||
nsStr::Insert(*this,anOffset,temp,0,aCount,0);
|
nsStr::Insert(*this,anOffset,temp,0,aCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
@@ -1308,7 +1309,7 @@ nsString& nsString::Insert(PRUnichar aChar,PRUint32 anOffset){
|
|||||||
nsStr::Initialize(temp,eTwoByte);
|
nsStr::Initialize(temp,eTwoByte);
|
||||||
temp.mUStr=theBuffer;
|
temp.mUStr=theBuffer;
|
||||||
temp.mLength=1;
|
temp.mLength=1;
|
||||||
nsStr::Insert(*this,anOffset,temp,0,1,0);
|
nsStr::Insert(*this,anOffset,temp,0,1);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1323,7 +1324,7 @@ nsString& nsString::Insert(PRUnichar aChar,PRUint32 anOffset){
|
|||||||
*/
|
*/
|
||||||
nsString& nsString::Cut(PRUint32 anOffset, PRInt32 aCount) {
|
nsString& nsString::Cut(PRUint32 anOffset, PRInt32 aCount) {
|
||||||
if(0<aCount) {
|
if(0<aCount) {
|
||||||
nsStr::Delete(*this,anOffset,aCount,mAgent);
|
nsStr::Delete(*this,anOffset,aCount);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -1957,10 +1958,8 @@ PRBool nsString::IsDigit(PRUnichar aChar) {
|
|||||||
class nsStringDeallocator: public nsDequeFunctor{
|
class nsStringDeallocator: public nsDequeFunctor{
|
||||||
public:
|
public:
|
||||||
virtual void* operator()(void* anObject) {
|
virtual void* operator()(void* anObject) {
|
||||||
static nsMemoryAgent theAgent;
|
|
||||||
nsString* aString= (nsString*)anObject;
|
nsString* aString= (nsString*)anObject;
|
||||||
if(aString){
|
if(aString){
|
||||||
aString->mAgent=&theAgent;
|
|
||||||
delete aString;
|
delete aString;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -2116,7 +2115,6 @@ NS_COM int fputs(const nsString& aString, FILE* out)
|
|||||||
*/
|
*/
|
||||||
nsAutoString::nsAutoString() : nsString() {
|
nsAutoString::nsAutoString() : nsString() {
|
||||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
||||||
mAgent=0;
|
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2127,7 +2125,6 @@ nsAutoString::nsAutoString() : nsString() {
|
|||||||
*/
|
*/
|
||||||
nsAutoString::nsAutoString(const char* aCString,PRInt32 aLength) : nsString() {
|
nsAutoString::nsAutoString(const char* aCString,PRInt32 aLength) : nsString() {
|
||||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
||||||
mAgent=0;
|
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aCString,aLength);
|
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
|
* @param aLength tells us how many chars to copy from aString
|
||||||
*/
|
*/
|
||||||
nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString() {
|
nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString() {
|
||||||
mAgent=0;
|
|
||||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aString,aLength);
|
Append(aString,aLength);
|
||||||
@@ -2149,7 +2145,6 @@ nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString(
|
|||||||
* @param aBuffer describes the external buffer
|
* @param aBuffer describes the external buffer
|
||||||
*/
|
*/
|
||||||
nsAutoString::nsAutoString(const CBufDescriptor& aBuffer) : nsString() {
|
nsAutoString::nsAutoString(const CBufDescriptor& aBuffer) : nsString() {
|
||||||
mAgent=0;
|
|
||||||
if(!aBuffer.mBuffer) {
|
if(!aBuffer.mBuffer) {
|
||||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
||||||
}
|
}
|
||||||
@@ -2166,7 +2161,6 @@ nsAutoString::nsAutoString(const CBufDescriptor& aBuffer) : nsString() {
|
|||||||
* @param
|
* @param
|
||||||
*/
|
*/
|
||||||
nsAutoString::nsAutoString(const nsStr& aString) : nsString() {
|
nsAutoString::nsAutoString(const nsStr& aString) : nsString() {
|
||||||
mAgent=0;
|
|
||||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aString);
|
Append(aString);
|
||||||
@@ -2176,7 +2170,6 @@ nsAutoString::nsAutoString(const nsStr& aString) : nsString() {
|
|||||||
* Default copy constructor
|
* Default copy constructor
|
||||||
*/
|
*/
|
||||||
nsAutoString::nsAutoString(const nsAutoString& aString) : nsString() {
|
nsAutoString::nsAutoString(const nsAutoString& aString) : nsString() {
|
||||||
mAgent=0;
|
|
||||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aString);
|
Append(aString);
|
||||||
@@ -2188,7 +2181,6 @@ nsAutoString::nsAutoString(const nsAutoString& aString) : nsString() {
|
|||||||
* @param
|
* @param
|
||||||
*/
|
*/
|
||||||
nsAutoString::nsAutoString(PRUnichar aChar) : nsString(){
|
nsAutoString::nsAutoString(PRUnichar aChar) : nsString(){
|
||||||
mAgent=0;
|
|
||||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aChar);
|
Append(aChar);
|
||||||
@@ -2201,12 +2193,10 @@ nsAutoString::nsAutoString(PRUnichar aChar) : nsString(){
|
|||||||
*/
|
*/
|
||||||
#ifdef AIX
|
#ifdef AIX
|
||||||
nsAutoString::nsAutoString(const nsSubsumeStr& aSubsumeStr) :nsString() {
|
nsAutoString::nsAutoString(const nsSubsumeStr& aSubsumeStr) :nsString() {
|
||||||
mAgent=0;
|
|
||||||
nsSubsumeStr temp(aSubsumeStr); // a temp is needed for the AIX compiler
|
nsSubsumeStr temp(aSubsumeStr); // a temp is needed for the AIX compiler
|
||||||
Subsume(*this,temp);
|
Subsume(*this,temp);
|
||||||
#else
|
#else
|
||||||
nsAutoString::nsAutoString( nsSubsumeStr& aSubsumeStr) :nsString() {
|
nsAutoString::nsAutoString( nsSubsumeStr& aSubsumeStr) :nsString() {
|
||||||
mAgent=0;
|
|
||||||
Subsume(*this,aSubsumeStr);
|
Subsume(*this,aSubsumeStr);
|
||||||
#endif // AIX
|
#endif // AIX
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,26 +58,26 @@ class NS_COM nsString : public nsStr {
|
|||||||
/**
|
/**
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
*/
|
*/
|
||||||
nsString(nsIMemoryAgent* anAgent=0);
|
nsString();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constructor accepts an isolatin string
|
* This constructor accepts an isolatin string
|
||||||
* @param aCString is a ptr to a 1-byte cstr
|
* @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
|
* This constructor accepts a unichar string
|
||||||
* @param aCString is a ptr to a 2-byte cstr
|
* @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
|
* This is a copy constructor that accepts an nsStr
|
||||||
* @param reference to another nsString
|
* @param reference to another nsString
|
||||||
*/
|
*/
|
||||||
nsString(const nsStr&,nsIMemoryAgent* anAgent=0);
|
nsString(const nsStr&);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is our copy constructor
|
* This is our copy constructor
|
||||||
@@ -168,6 +168,9 @@ PRBool IsEmpty(void) const {
|
|||||||
Getters/Setters...
|
Getters/Setters...
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve const ptr to internal buffer; DO NOT TRY TO FREE IT!
|
||||||
|
*/
|
||||||
const char* GetBuffer(void) const;
|
const char* GetBuffer(void) const;
|
||||||
const PRUnichar* GetUnicode(void) const;
|
const PRUnichar* GetUnicode(void) const;
|
||||||
|
|
||||||
@@ -761,9 +764,6 @@ static PRBool IsDigit(PRUnichar ch);
|
|||||||
static void Recycle(nsString* aString);
|
static void Recycle(nsString* aString);
|
||||||
static nsString* CreateString(void);
|
static nsString* CreateString(void);
|
||||||
|
|
||||||
|
|
||||||
nsIMemoryAgent* mAgent;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern NS_COM int fputs(const nsString& aString, FILE* out);
|
extern NS_COM int fputs(const nsString& aString, FILE* out);
|
||||||
|
|||||||
@@ -69,16 +69,6 @@ void nsStr::Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 a
|
|||||||
aDest.mOwnsBuffer=aOwnsBuffer;
|
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)
|
* This member destroys the memory buffer owned by an nsStr object (if it actually owns it)
|
||||||
@@ -86,17 +76,9 @@ nsIMemoryAgent* GetDefaultAgent(void){
|
|||||||
* @param
|
* @param
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) {
|
void nsStr::Destroy(nsStr& aDest) {
|
||||||
if((aDest.mStr) && (aDest.mStr!=(char*)gCommonEmptyBuffer)) {
|
if((aDest.mStr) && (aDest.mStr!=(char*)gCommonEmptyBuffer)) {
|
||||||
if(!anAgent)
|
Free(aDest);
|
||||||
anAgent=GetDefaultAgent();
|
|
||||||
|
|
||||||
if(anAgent) {
|
|
||||||
anAgent->Free(aDest);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
printf("%s\n","Leak occured in nsStr.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,11 +90,10 @@ void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) {
|
|||||||
* @param aNewLength -- new capacity of string in charSize units
|
* @param aNewLength -- new capacity of string in charSize units
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent) {
|
PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength) {
|
||||||
PRBool result=PR_TRUE;
|
PRBool result=PR_TRUE;
|
||||||
if(aNewLength>aString.mCapacity) {
|
if(aNewLength>aString.mCapacity) {
|
||||||
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
|
result=Realloc(aString,aNewLength);
|
||||||
result=theAgent->Realloc(aString,aNewLength);
|
|
||||||
if(aString.mStr)
|
if(aString.mStr)
|
||||||
AddNullTerminator(aString);
|
AddNullTerminator(aString);
|
||||||
}
|
}
|
||||||
@@ -126,20 +107,18 @@ PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent*
|
|||||||
* @param aNewLength -- new capacity of string in charSize units
|
* @param aNewLength -- new capacity of string in charSize units
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAgent) {
|
PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength) {
|
||||||
PRBool result=PR_TRUE;
|
PRBool result=PR_TRUE;
|
||||||
if(aNewLength>aDest.mCapacity) {
|
if(aNewLength>aDest.mCapacity) {
|
||||||
nsStr theTempStr;
|
nsStr theTempStr;
|
||||||
nsStr::Initialize(theTempStr,aDest.mCharSize);
|
nsStr::Initialize(theTempStr,aDest.mCharSize);
|
||||||
|
|
||||||
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
|
result=EnsureCapacity(theTempStr,aNewLength);
|
||||||
|
|
||||||
result=EnsureCapacity(theTempStr,aNewLength,theAgent);
|
|
||||||
if(result) {
|
if(result) {
|
||||||
if(aDest.mLength) {
|
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;
|
aDest.mStr = theTempStr.mStr;
|
||||||
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
|
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
|
||||||
aDest.mLength=theTempStr.mLength;
|
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 aSource is where chars are copied from
|
||||||
* @param aCount is the number of chars copied from aSource
|
* @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){
|
if(&aDest!=&aSource){
|
||||||
Truncate(aDest,0,anAgent);
|
Truncate(aDest,0);
|
||||||
Append(aDest,aSource,anOffset,aCount,anAgent);
|
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
|
* @param aSource is where char are copied from
|
||||||
* @aCount is the number of bytes to be copied
|
* @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){
|
if(anOffset<aSource.mLength){
|
||||||
PRUint32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
|
PRUint32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
|
||||||
PRUint32 theLength=(anOffset+theRealLen<aSource.mLength) ? theRealLen : (aSource.mLength-anOffset);
|
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;
|
PRBool isBigEnough=PR_TRUE;
|
||||||
if(aDest.mLength+theLength > aDest.mCapacity) {
|
if(aDest.mLength+theLength > aDest.mCapacity) {
|
||||||
isBigEnough=GrowCapacity(aDest,aDest.mLength+theLength,anAgent);
|
isBigEnough=GrowCapacity(aDest,aDest.mLength+theLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isBigEnough) {
|
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 aSrcOffset is where in aSource chars are copied from
|
||||||
* @param aCount is the number of chars from aSource to be inserted into aDest
|
* @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:
|
//there are a few cases for insert:
|
||||||
// 1. You're inserting chars into an empty string (assign)
|
// 1. You're inserting chars into an empty string (assign)
|
||||||
// 2. You're inserting onto the end of a string (append)
|
// 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 theTempStr;
|
||||||
nsStr::Initialize(theTempStr,aDest.mCharSize);
|
nsStr::Initialize(theTempStr,aDest.mCharSize);
|
||||||
|
|
||||||
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
|
PRBool isBigEnough=EnsureCapacity(theTempStr,aDest.mLength+theLength); //grow the temp buffer to the right size
|
||||||
PRBool isBigEnough=EnsureCapacity(theTempStr,aDest.mLength+theLength,theAgent); //grow the temp buffer to the right size
|
|
||||||
|
|
||||||
if(isBigEnough) {
|
if(isBigEnough) {
|
||||||
if(aDestOffset) {
|
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;
|
PRUint32 theRemains=aDest.mLength-aDestOffset;
|
||||||
if(theRemains) {
|
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;
|
aDest.mStr = theTempStr.mStr;
|
||||||
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
|
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
|
||||||
aDest.mCapacity=theTempStr.mCapacity;
|
aDest.mCapacity=theTempStr.mCapacity;
|
||||||
@@ -262,9 +240,9 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin
|
|||||||
}//if
|
}//if
|
||||||
//else nothing to do!
|
//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 aDestOffset is where in aDest deletion is to occur
|
||||||
* @param aCount is the number of chars to be deleted in aDest
|
* @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){
|
if(aDestOffset<aDest.mLength){
|
||||||
|
|
||||||
PRUint32 theDelta=aDest.mLength-aDestOffset;
|
PRUint32 theDelta=aDest.mLength-aDestOffset;
|
||||||
@@ -290,7 +268,7 @@ void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAg
|
|||||||
aDest.mLength-=theLength;
|
aDest.mLength-=theLength;
|
||||||
AddNullTerminator(aDest);
|
AddNullTerminator(aDest);
|
||||||
}
|
}
|
||||||
else Truncate(aDest,aDestOffset,anAgent);
|
else Truncate(aDest,aDestOffset);
|
||||||
}//if
|
}//if
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,7 +278,7 @@ void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAg
|
|||||||
* @param aDest is the nsStr to be truncated
|
* @param aDest is the nsStr to be truncated
|
||||||
* @param aDestOffset is where in aDest truncation is to occur
|
* @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){
|
if(aDestOffset<aDest.mLength){
|
||||||
aDest.mLength=aDestOffset;
|
aDest.mLength=aDestOffset;
|
||||||
AddNullTerminator(aDest);
|
AddNullTerminator(aDest);
|
||||||
@@ -342,7 +320,7 @@ void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool a
|
|||||||
}
|
}
|
||||||
if(0<theIndex) {
|
if(0<theIndex) {
|
||||||
if(theIndex<theMax) {
|
if(theIndex<theMax) {
|
||||||
Delete(aDest,0,theIndex,0);
|
Delete(aDest,0,theIndex);
|
||||||
}
|
}
|
||||||
else Truncate(aDest,0);
|
else Truncate(aDest,0);
|
||||||
}
|
}
|
||||||
@@ -515,7 +493,7 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgno
|
|||||||
|
|
||||||
nsStr theCopy;
|
nsStr theCopy;
|
||||||
nsStr::Initialize(theCopy,eOneByte);
|
nsStr::Initialize(theCopy,eOneByte);
|
||||||
nsStr::Assign(theCopy,aTarget,0,aTarget.mLength,0);
|
nsStr::Assign(theCopy,aTarget,0,aTarget.mLength);
|
||||||
if(aIgnoreCase){
|
if(aIgnoreCase){
|
||||||
nsStr::ChangeCase(theCopy,PR_FALSE); //force to lowercase
|
nsStr::ChangeCase(theCopy,PR_FALSE); //force to lowercase
|
||||||
}
|
}
|
||||||
@@ -538,7 +516,7 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgno
|
|||||||
}
|
}
|
||||||
index--;
|
index--;
|
||||||
} //while
|
} //while
|
||||||
nsStr::Destroy(theCopy,0);
|
nsStr::Destroy(theCopy);
|
||||||
}//if
|
}//if
|
||||||
}//if
|
}//if
|
||||||
return result;
|
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) {
|
CBufDescriptor::CBufDescriptor(char* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength) {
|
||||||
mBuffer=aString;
|
mBuffer=aString;
|
||||||
mCharSize=eOneByte;
|
mCharSize=eOneByte;
|
||||||
@@ -683,3 +712,5 @@ CBufDescriptor::CBufDescriptor(const PRUnichar* aString,PRBool aStackBased,PRUin
|
|||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -164,6 +164,7 @@
|
|||||||
|
|
||||||
#include "nscore.h"
|
#include "nscore.h"
|
||||||
#include "nsIAllocator.h"
|
#include "nsIAllocator.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -177,8 +178,6 @@ const PRInt32 kDefaultStringSize = 64;
|
|||||||
const PRInt32 kNotFound = -1;
|
const PRInt32 kNotFound = -1;
|
||||||
|
|
||||||
|
|
||||||
class nsIMemoryAgent;
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
class NS_COM CBufDescriptor {
|
class NS_COM CBufDescriptor {
|
||||||
@@ -228,7 +227,7 @@ struct NS_COM nsStr {
|
|||||||
* @param aString is the nsStr to be manipulated
|
* @param aString is the nsStr to be manipulated
|
||||||
* @param anAgent is the allocator to be used to the nsStr
|
* @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.
|
* 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
|
* @param anAgent is the allocator to be used on the nsStr
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
static PRBool EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0);
|
static PRBool EnsureCapacity(nsStr& aString,PRUint32 aNewLength);
|
||||||
static PRBool GrowCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0);
|
static PRBool GrowCapacity(nsStr& aString,PRUint32 aNewLength);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* These methods are used to append content to the given nsStr
|
* 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 aCount tells us the (max) # of chars to copy
|
||||||
* @param anAgent is the allocator to be used for alloc/free operations
|
* @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
|
* 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 aCount tells us the (max) # of chars to copy
|
||||||
* @param anAgent is the allocator to be used for alloc/free operations
|
* @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
|
* 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 aCount tells us the (max) # of chars to insert
|
||||||
* @param anAgent is the allocator to be used for alloc/free operations
|
* @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.
|
* 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 aCount tells us the (max) # of chars to delete
|
||||||
* @param anAgent is the allocator to be used for alloc/free operations
|
* @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.
|
* 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 aSrcOffset tells us where in source to start copying
|
||||||
* @param anAgent is the allocator to be used for alloc/free operations
|
* @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
|
* This method is used to perform a case conversion on the given string
|
||||||
@@ -388,6 +387,12 @@ struct NS_COM nsStr {
|
|||||||
char* mStr;
|
char* mStr;
|
||||||
PRUnichar* mUStr;
|
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;
|
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
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ static const char* kWhitespace="\b\t\r\n ";
|
|||||||
static void CSubsume(nsStr& aDest,nsStr& aSource){
|
static void CSubsume(nsStr& aDest,nsStr& aSource){
|
||||||
if(aSource.mStr && aSource.mLength) {
|
if(aSource.mStr && aSource.mLength) {
|
||||||
if(aSource.mOwnsBuffer){
|
if(aSource.mOwnsBuffer){
|
||||||
nsStr::Destroy(aDest,0);
|
nsStr::Destroy(aDest);
|
||||||
aDest.mStr=aSource.mStr;
|
aDest.mStr=aSource.mStr;
|
||||||
aDest.mLength=aSource.mLength;
|
aDest.mLength=aSource.mLength;
|
||||||
aDest.mCharSize=aSource.mCharSize;
|
aDest.mCharSize=aSource.mCharSize;
|
||||||
@@ -50,17 +50,17 @@ static void CSubsume(nsStr& aDest,nsStr& aSource){
|
|||||||
aSource.mStr=0;
|
aSource.mStr=0;
|
||||||
}
|
}
|
||||||
else{
|
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.
|
* Default constructor.
|
||||||
*/
|
*/
|
||||||
nsCString::nsCString(nsIMemoryAgent* anAgent) : mAgent(anAgent) {
|
nsCString::nsCString() {
|
||||||
nsStr::Initialize(*this,eOneByte);
|
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 aCString is a ptr to a 1-byte cstr
|
||||||
* @param aLength tells us how many chars to copy from given CString
|
* @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);
|
nsStr::Initialize(*this,eOneByte);
|
||||||
Assign(aCString,aLength);
|
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 aString is a ptr to a unichar string
|
||||||
* @param aLength tells us how many chars to copy from given aString
|
* @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);
|
nsStr::Initialize(*this,eOneByte);
|
||||||
|
|
||||||
if(aString && aLength){
|
if(aString && aLength){
|
||||||
@@ -101,7 +101,7 @@ nsCString::nsCString(const PRUnichar* aString,PRInt32 aLength,nsIMemoryAgent* an
|
|||||||
else aLength=temp.mLength=nsCRT::strlen(aString);
|
else aLength=temp.mLength=nsCRT::strlen(aString);
|
||||||
|
|
||||||
if(0<aLength)
|
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
|
* @update gess 1/4/99
|
||||||
* @param reference to another nsCString
|
* @param reference to another nsCString
|
||||||
*/
|
*/
|
||||||
nsCString::nsCString(const nsStr &aString,nsIMemoryAgent* anAgent) : mAgent(anAgent) {
|
nsCString::nsCString(const nsStr &aString) {
|
||||||
nsStr::Initialize(*this,eOneByte);
|
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
|
* @update gess 1/4/99
|
||||||
* @param reference to another nsCString
|
* @param reference to another nsCString
|
||||||
*/
|
*/
|
||||||
nsCString::nsCString(const nsCString& aString) :mAgent(aString.mAgent) {
|
nsCString::nsCString(const nsCString& aString) {
|
||||||
nsStr::Initialize(*this,aString.mCharSize);
|
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
|
* @update gess 1/4/99
|
||||||
* @param reference to a subsumeString
|
* @param reference to a subsumeString
|
||||||
*/
|
*/
|
||||||
nsCString::nsCString(nsSubsumeCStr& aSubsumeStr) :mAgent(0) {
|
nsCString::nsCString(nsSubsumeCStr& aSubsumeStr) {
|
||||||
CSubsume(*this,aSubsumeStr);
|
CSubsume(*this,aSubsumeStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +138,7 @@ nsCString::nsCString(nsSubsumeCStr& aSubsumeStr) :mAgent(0) {
|
|||||||
* Destructor
|
* Destructor
|
||||||
*/
|
*/
|
||||||
nsCString::~nsCString() {
|
nsCString::~nsCString() {
|
||||||
nsStr::Destroy(*this,mAgent);
|
nsStr::Destroy(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nsCString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
void nsCString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
||||||
@@ -155,7 +155,7 @@ void nsCString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
|||||||
* @return nada
|
* @return nada
|
||||||
*/
|
*/
|
||||||
void nsCString::Truncate(PRInt32 anIndex) {
|
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) {
|
void nsCString::SetCapacity(PRUint32 aLength) {
|
||||||
if(aLength>mCapacity) {
|
if(aLength>mCapacity) {
|
||||||
GrowCapacity(*this,aLength,mAgent);
|
GrowCapacity(*this,aLength);
|
||||||
}
|
}
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
}
|
}
|
||||||
@@ -262,7 +262,7 @@ PRBool nsCString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
|
|||||||
*/
|
*/
|
||||||
nsSubsumeCStr nsCString::operator+(const nsCString& aString){
|
nsSubsumeCStr nsCString::operator+(const nsCString& aString){
|
||||||
nsCString temp(*this); //make a temp string the same size as this...
|
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);
|
return nsSubsumeCStr(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -613,11 +613,19 @@ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) {
|
|||||||
}
|
}
|
||||||
theDigit=(theChar-'A')+10;
|
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) {
|
else if('-'==theChar) {
|
||||||
result=-result;
|
result=-result;
|
||||||
break;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -634,6 +642,7 @@ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call this method to extract the rightmost numeric value from the given
|
* Call this method to extract the rightmost numeric value from the given
|
||||||
* 1-byte input string, and simultaneously determine the radix.
|
* 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.
|
* @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
|
* @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);
|
//begin by skipping over leading chars that shouldn't be part of the number...
|
||||||
char* cp = (kNotFound==decPt) ? aString.mStr + aString.mLength-1 : aString.mStr+decPt-1;
|
|
||||||
|
|
||||||
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<endcp){
|
||||||
while (cp >= aString.mStr) {
|
const char* pos=(const char*)memchr(validChars,*cp,len);
|
||||||
if((*cp>='0') && (*cp<='9')){
|
if(!pos) {
|
||||||
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...
|
|
||||||
cp++;
|
cp++;
|
||||||
while (--cp >= aString.mStr) {
|
|
||||||
if((*cp>='0') && (*cp<='9')){
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
else if((*cp>='A') && (*cp<='F')) {
|
else break;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
else if((*cp=='-') || (*cp=='+')){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if(('#'==(*cp)) || ('X'==(*cp)))
|
|
||||||
aRadix=kRadix16;
|
|
||||||
cp++; //move back by one
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(cp>aString.mStr)
|
|
||||||
aString.Cut(0,cp-aString.mStr);
|
|
||||||
PRInt32 result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK;
|
|
||||||
|
|
||||||
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -726,11 +735,12 @@ PRUint32 nsCString::DetermineRadix(void) {
|
|||||||
PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
||||||
|
|
||||||
//copy chars to local buffer -- step down from 2 bytes to 1 if necessary...
|
//copy chars to local buffer -- step down from 2 bytes to 1 if necessary...
|
||||||
|
PRInt32 result=0;
|
||||||
nsCAutoString theString(*this);
|
nsCAutoString theString(*this);
|
||||||
PRUint32 theRadix=aRadix;
|
PRUint32 theRadix=aRadix;
|
||||||
PRInt32 result=0;
|
|
||||||
|
|
||||||
*anErrorCode=GetNumericSubstring(theString,theRadix); //we actually don't use this radix; use given radix instead
|
*anErrorCode=GetNumericSubstring(theString,theRadix); //we actually don't use this radix; use given radix instead
|
||||||
|
|
||||||
if(NS_OK==*anErrorCode){
|
if(NS_OK==*anErrorCode){
|
||||||
if(kAutoDetect==aRadix)
|
if(kAutoDetect==aRadix)
|
||||||
aRadix=theRadix;
|
aRadix=theRadix;
|
||||||
@@ -755,13 +765,13 @@ PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
|||||||
*/
|
*/
|
||||||
nsCString& nsCString::Assign(const nsStr& aString,PRInt32 aCount) {
|
nsCString& nsCString::Assign(const nsStr& aString,PRInt32 aCount) {
|
||||||
if(this!=&aString){
|
if(this!=&aString){
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
|
|
||||||
if(aCount<0)
|
if(aCount<0)
|
||||||
aCount=aString.mLength;
|
aCount=aString.mLength;
|
||||||
else aCount=MinInt(aCount,aString.mLength);
|
else aCount=MinInt(aCount,aString.mLength);
|
||||||
|
|
||||||
nsStr::Assign(*this,aString,0,aCount,mAgent);
|
nsStr::Assign(*this,aString,0,aCount);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -773,7 +783,7 @@ nsCString& nsCString::Assign(const nsStr& aString,PRInt32 aCount) {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
nsCString& nsCString::Assign(const char* aCString,PRInt32 aCount) {
|
nsCString& nsCString::Assign(const char* aCString,PRInt32 aCount) {
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
if(aCString){
|
if(aCString){
|
||||||
Append(aCString,aCount);
|
Append(aCString,aCount);
|
||||||
}
|
}
|
||||||
@@ -787,7 +797,7 @@ nsCString& nsCString::Assign(const char* aCString,PRInt32 aCount) {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) {
|
nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) {
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
|
|
||||||
if(aString){
|
if(aString){
|
||||||
nsStr temp;
|
nsStr temp;
|
||||||
@@ -806,7 +816,7 @@ nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) {
|
|||||||
else aCount=temp.mLength=nsCRT::strlen(aString);
|
else aCount=temp.mLength=nsCRT::strlen(aString);
|
||||||
|
|
||||||
if(0<aCount)
|
if(0<aCount)
|
||||||
nsStr::Append(*this,temp,0,aCount,mAgent);
|
nsStr::Append(*this,temp,0,aCount);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -818,7 +828,7 @@ nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
nsCString& nsCString::Assign(PRUnichar aChar) {
|
nsCString& nsCString::Assign(PRUnichar aChar) {
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
return Append(aChar);
|
return Append(aChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -829,7 +839,7 @@ nsCString& nsCString::Assign(PRUnichar aChar) {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
nsCString& nsCString::Assign(char aChar) {
|
nsCString& nsCString::Assign(char aChar) {
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
return Append(aChar);
|
return Append(aChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -864,7 +874,24 @@ nsCString& nsCString::Append(const nsCString& aString,PRInt32 aCount) {
|
|||||||
aCount=aString.mLength;
|
aCount=aString.mLength;
|
||||||
else aCount=MinInt(aCount,aString.mLength);
|
else aCount=MinInt(aCount,aString.mLength);
|
||||||
if(0<aCount)
|
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;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -893,7 +920,7 @@ nsCString& nsCString::Append(const char* aCString,PRInt32 aCount) {
|
|||||||
else aCount=temp.mLength=nsCRT::strlen(aCString);
|
else aCount=temp.mLength=nsCRT::strlen(aCString);
|
||||||
|
|
||||||
if(0<aCount)
|
if(0<aCount)
|
||||||
nsStr::Append(*this,temp,0,aCount,mAgent);
|
nsStr::Append(*this,temp,0,aCount);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -913,7 +940,7 @@ nsCString& nsCString::Append(PRUnichar aChar) {
|
|||||||
Initialize(temp,eTwoByte);
|
Initialize(temp,eTwoByte);
|
||||||
temp.mUStr=buf;
|
temp.mUStr=buf;
|
||||||
temp.mLength=1;
|
temp.mLength=1;
|
||||||
nsStr::Append(*this,temp,0,1,mAgent);
|
nsStr::Append(*this,temp,0,1);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -931,7 +958,7 @@ nsCString& nsCString::Append(char aChar) {
|
|||||||
Initialize(temp,eOneByte);
|
Initialize(temp,eOneByte);
|
||||||
temp.mStr=buf;
|
temp.mStr=buf;
|
||||||
temp.mLength=1;
|
temp.mLength=1;
|
||||||
nsStr::Append(*this,temp,0,1,mAgent);
|
nsStr::Append(*this,temp,0,1);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -962,12 +989,12 @@ nsCString& nsCString::Append(PRInt32 anInteger,PRInt32 aRadix) {
|
|||||||
|
|
||||||
PRBool isfirst=PR_TRUE;
|
PRBool isfirst=PR_TRUE;
|
||||||
while(mask1>=1) {
|
while(mask1>=1) {
|
||||||
PRInt32 div=theInt/mask1;
|
PRInt32 theDiv=theInt/mask1;
|
||||||
if((div) || (!isfirst)) {
|
if((theDiv) || (!isfirst)) {
|
||||||
buf[charpos++]="0123456789abcdef"[div];
|
buf[charpos++]="0123456789abcdef"[theDiv];
|
||||||
isfirst=PR_FALSE;
|
isfirst=PR_FALSE;
|
||||||
}
|
}
|
||||||
theInt-=div*mask1;
|
theInt-=theDiv*mask1;
|
||||||
mask1/=aRadix;
|
mask1/=aRadix;
|
||||||
}
|
}
|
||||||
return Append(buf);
|
return Append(buf);
|
||||||
@@ -1001,7 +1028,7 @@ PRUint32 nsCString::Left(nsCString& aDest,PRInt32 aCount) const{
|
|||||||
if(aCount<0)
|
if(aCount<0)
|
||||||
aCount=mLength;
|
aCount=mLength;
|
||||||
else aCount=MinInt(aCount,mLength);
|
else aCount=MinInt(aCount,mLength);
|
||||||
nsStr::Assign(aDest,*this,0,aCount,mAgent);
|
nsStr::Assign(aDest,*this,0,aCount);
|
||||||
return aDest.mLength;
|
return aDest.mLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1018,7 +1045,7 @@ PRUint32 nsCString::Mid(nsCString& aDest,PRUint32 anOffset,PRInt32 aCount) const
|
|||||||
if(aCount<0)
|
if(aCount<0)
|
||||||
aCount=mLength;
|
aCount=mLength;
|
||||||
else aCount=MinInt(aCount,mLength);
|
else aCount=MinInt(aCount,mLength);
|
||||||
nsStr::Assign(aDest,*this,anOffset,aCount,mAgent);
|
nsStr::Assign(aDest,*this,anOffset,aCount);
|
||||||
return aDest.mLength;
|
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) {
|
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;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1079,7 +1106,7 @@ nsCString& nsCString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCou
|
|||||||
else aCount=temp.mLength=nsCRT::strlen(aCString);
|
else aCount=temp.mLength=nsCRT::strlen(aCString);
|
||||||
|
|
||||||
if(temp.mLength && (0<aCount)){
|
if(temp.mLength && (0<aCount)){
|
||||||
nsStr::Insert(*this,anOffset,temp,0,aCount,0);
|
nsStr::Insert(*this,anOffset,temp,0,aCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
@@ -1101,7 +1128,7 @@ nsCString& nsCString::Insert(PRUnichar aChar,PRUint32 anOffset){
|
|||||||
nsStr::Initialize(temp,eTwoByte);
|
nsStr::Initialize(temp,eTwoByte);
|
||||||
temp.mUStr=theBuffer;
|
temp.mUStr=theBuffer;
|
||||||
temp.mLength=1;
|
temp.mLength=1;
|
||||||
nsStr::Insert(*this,anOffset,temp,0,1,0);
|
nsStr::Insert(*this,anOffset,temp,0,1);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1121,7 +1148,7 @@ nsCString& nsCString::Insert(char aChar,PRUint32 anOffset){
|
|||||||
nsStr::Initialize(temp,eOneByte);
|
nsStr::Initialize(temp,eOneByte);
|
||||||
temp.mStr=theBuffer;
|
temp.mStr=theBuffer;
|
||||||
temp.mLength=1;
|
temp.mLength=1;
|
||||||
nsStr::Insert(*this,anOffset,temp,0,1,0);
|
nsStr::Insert(*this,anOffset,temp,0,1);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1136,7 +1163,7 @@ nsCString& nsCString::Insert(char aChar,PRUint32 anOffset){
|
|||||||
*/
|
*/
|
||||||
nsCString& nsCString::Cut(PRUint32 anOffset, PRInt32 aCount) {
|
nsCString& nsCString::Cut(PRUint32 anOffset, PRInt32 aCount) {
|
||||||
if(0<aCount) {
|
if(0<aCount) {
|
||||||
nsStr::Delete(*this,anOffset,aCount,mAgent);
|
nsStr::Delete(*this,anOffset,aCount);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -1560,10 +1587,8 @@ PRBool nsCString::Equals(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 aCo
|
|||||||
class nsCStringDeallocator: public nsDequeFunctor{
|
class nsCStringDeallocator: public nsDequeFunctor{
|
||||||
public:
|
public:
|
||||||
virtual void* operator()(void* anObject) {
|
virtual void* operator()(void* anObject) {
|
||||||
static nsMemoryAgent theAgent;
|
|
||||||
nsCString* aString= (nsCString*)anObject;
|
nsCString* aString= (nsCString*)anObject;
|
||||||
if(aString){
|
if(aString){
|
||||||
aString->mAgent=&theAgent;
|
|
||||||
delete aString;
|
delete aString;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1722,7 +1747,6 @@ NS_COM int fputs(const nsCString& aString, FILE* out)
|
|||||||
*/
|
*/
|
||||||
nsCAutoString::nsCAutoString() : nsCString(){
|
nsCAutoString::nsCAutoString() : nsCString(){
|
||||||
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
||||||
mAgent=0;
|
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1732,7 +1756,6 @@ nsCAutoString::nsCAutoString() : nsCString(){
|
|||||||
*/
|
*/
|
||||||
nsCAutoString::nsCAutoString(const nsCAutoString& aString) : nsCString() {
|
nsCAutoString::nsCAutoString(const nsCAutoString& aString) : nsCString() {
|
||||||
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
||||||
mAgent=0;
|
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aString);
|
Append(aString);
|
||||||
}
|
}
|
||||||
@@ -1744,7 +1767,6 @@ nsCAutoString::nsCAutoString(const nsCAutoString& aString) : nsCString() {
|
|||||||
*/
|
*/
|
||||||
nsCAutoString::nsCAutoString(const char* aCString,PRInt32 aLength) : nsCString() {
|
nsCAutoString::nsCAutoString(const char* aCString,PRInt32 aLength) : nsCString() {
|
||||||
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
||||||
mAgent=0;
|
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aCString,aLength);
|
Append(aCString,aLength);
|
||||||
}
|
}
|
||||||
@@ -1754,7 +1776,6 @@ nsCAutoString::nsCAutoString(const char* aCString,PRInt32 aLength) : nsCString()
|
|||||||
* @param aBuffer -- descibes external buffer
|
* @param aBuffer -- descibes external buffer
|
||||||
*/
|
*/
|
||||||
nsCAutoString::nsCAutoString(const CBufDescriptor& aBuffer) : nsCString() {
|
nsCAutoString::nsCAutoString(const CBufDescriptor& aBuffer) : nsCString() {
|
||||||
mAgent=0;
|
|
||||||
if(!aBuffer.mBuffer) {
|
if(!aBuffer.mBuffer) {
|
||||||
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
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
|
* @param aString is a ptr to a unistr
|
||||||
*/
|
*/
|
||||||
nsCAutoString::nsCAutoString(const PRUnichar* aString,PRInt32 aLength) : nsCString() {
|
nsCAutoString::nsCAutoString(const PRUnichar* aString,PRInt32 aLength) : nsCString() {
|
||||||
mAgent=0;
|
|
||||||
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aString,aLength);
|
Append(aString,aLength);
|
||||||
@@ -1781,7 +1801,6 @@ nsCAutoString::nsCAutoString(const PRUnichar* aString,PRInt32 aLength) : nsCStri
|
|||||||
* @param
|
* @param
|
||||||
*/
|
*/
|
||||||
nsCAutoString::nsCAutoString(const nsStr& aString) : nsCString() {
|
nsCAutoString::nsCAutoString(const nsStr& aString) : nsCString() {
|
||||||
mAgent=0;
|
|
||||||
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aString);
|
Append(aString);
|
||||||
@@ -1794,7 +1813,6 @@ nsCAutoString::nsCAutoString(const nsStr& aString) : nsCString() {
|
|||||||
* @param
|
* @param
|
||||||
*/
|
*/
|
||||||
nsCAutoString::nsCAutoString(PRUnichar aChar) : nsCString(){
|
nsCAutoString::nsCAutoString(PRUnichar aChar) : nsCString(){
|
||||||
mAgent=0;
|
|
||||||
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aChar);
|
Append(aChar);
|
||||||
@@ -1807,12 +1825,10 @@ nsCAutoString::nsCAutoString(PRUnichar aChar) : nsCString(){
|
|||||||
*/
|
*/
|
||||||
#ifdef AIX
|
#ifdef AIX
|
||||||
nsCAutoString::nsCAutoString(const nsSubsumeCStr& aSubsumeStr) :nsCString() {
|
nsCAutoString::nsCAutoString(const nsSubsumeCStr& aSubsumeStr) :nsCString() {
|
||||||
mAgent=0;
|
|
||||||
nsSubsumeCStr temp(aSubsumeStr); // a temp is needed for the AIX compiler
|
nsSubsumeCStr temp(aSubsumeStr); // a temp is needed for the AIX compiler
|
||||||
CSubsume(*this,temp);
|
CSubsume(*this,temp);
|
||||||
#else
|
#else
|
||||||
nsCAutoString::nsCAutoString( nsSubsumeCStr& aSubsumeStr) :nsCString() {
|
nsCAutoString::nsCAutoString( nsSubsumeCStr& aSubsumeStr) :nsCString() {
|
||||||
mAgent=0;
|
|
||||||
CSubsume(*this,aSubsumeStr);
|
CSubsume(*this,aSubsumeStr);
|
||||||
#endif // AIX
|
#endif // AIX
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,26 +51,25 @@ class NS_COM nsCString : public nsStr {
|
|||||||
/**
|
/**
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
*/
|
*/
|
||||||
nsCString(nsIMemoryAgent* anAgent=0);
|
nsCString();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constructor accepts an isolatin string
|
* This constructor accepts an isolatin string
|
||||||
* @param aCString is a ptr to a 1-byte cstr
|
* @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
|
* This constructor accepts a unichar string
|
||||||
* @param aCString is a ptr to a 2-byte cstr
|
* @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
|
* This is a copy constructor that accepts an nsStr
|
||||||
* @param reference to another nsCString
|
* @param reference to another nsCString
|
||||||
*/
|
*/
|
||||||
nsCString(const nsStr&,nsIMemoryAgent* anAgent=0);
|
nsCString(const nsStr&);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is our copy constructor
|
* This is our copy constructor
|
||||||
@@ -150,6 +149,10 @@ PRBool IsEmpty(void) const {
|
|||||||
Accessor methods...
|
Accessor methods...
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve const ptr to internal buffer; DO NOT TRY TO FREE IT!
|
||||||
|
*/
|
||||||
const char* GetBuffer(void) const;
|
const char* GetBuffer(void) const;
|
||||||
|
|
||||||
|
|
||||||
@@ -412,6 +415,7 @@ nsCString& Append(const nsCString& aString) {return Append(aString,aString.mLeng
|
|||||||
* @return number of chars copied
|
* @return number of chars copied
|
||||||
*/
|
*/
|
||||||
nsCString& Append(const nsCString& aString,PRInt32 aCount);
|
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(const char* aString,PRInt32 aCount=-1);
|
||||||
nsCString& Append(PRUnichar aChar);
|
nsCString& Append(PRUnichar aChar);
|
||||||
nsCString& Append(char aChar);
|
nsCString& Append(char aChar);
|
||||||
@@ -670,9 +674,6 @@ PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const;
|
|||||||
static void Recycle(nsCString* aString);
|
static void Recycle(nsCString* aString);
|
||||||
static nsCString* CreateString(void);
|
static nsCString* CreateString(void);
|
||||||
|
|
||||||
|
|
||||||
nsIMemoryAgent* mAgent;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern NS_COM int fputs(const nsCString& aString, FILE* out);
|
extern NS_COM int fputs(const nsCString& aString, FILE* out);
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ static const char* kWhitespace="\b\t\r\n ";
|
|||||||
static void Subsume(nsStr& aDest,nsStr& aSource){
|
static void Subsume(nsStr& aDest,nsStr& aSource){
|
||||||
if(aSource.mStr && aSource.mLength) {
|
if(aSource.mStr && aSource.mLength) {
|
||||||
if(aSource.mOwnsBuffer){
|
if(aSource.mOwnsBuffer){
|
||||||
nsStr::Destroy(aDest,0);
|
nsStr::Destroy(aDest);
|
||||||
aDest.mStr=aSource.mStr;
|
aDest.mStr=aSource.mStr;
|
||||||
aDest.mLength=aSource.mLength;
|
aDest.mLength=aSource.mLength;
|
||||||
aDest.mCharSize=aSource.mCharSize;
|
aDest.mCharSize=aSource.mCharSize;
|
||||||
@@ -48,17 +48,17 @@ static void Subsume(nsStr& aDest,nsStr& aSource){
|
|||||||
aSource.mStr=0;
|
aSource.mStr=0;
|
||||||
}
|
}
|
||||||
else{
|
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.
|
* Default constructor.
|
||||||
*/
|
*/
|
||||||
nsString::nsString(nsIMemoryAgent* anAgent) : mAgent(anAgent) {
|
nsString::nsString() {
|
||||||
nsStr::Initialize(*this,eTwoByte);
|
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 aCString is a ptr to a 1-byte cstr
|
||||||
* @param aLength tells us how many chars to copy from given CString
|
* @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);
|
nsStr::Initialize(*this,eTwoByte);
|
||||||
Assign(aCString);
|
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 aString is a ptr to a unichar string
|
||||||
* @param aLength tells us how many chars to copy from given aString
|
* @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);
|
nsStr::Initialize(*this,eTwoByte);
|
||||||
Assign(aString);
|
Assign(aString);
|
||||||
}
|
}
|
||||||
@@ -89,9 +89,9 @@ nsString::nsString(const PRUnichar* aString,nsIMemoryAgent* anAgent) : mAgent(an
|
|||||||
* @update gess 1/4/99
|
* @update gess 1/4/99
|
||||||
* @param reference to another nsCString
|
* @param reference to another nsCString
|
||||||
*/
|
*/
|
||||||
nsString::nsString(const nsStr &aString,nsIMemoryAgent* anAgent) : mAgent(anAgent) {
|
nsString::nsString(const nsStr &aString) {
|
||||||
nsStr::Initialize(*this,eTwoByte);
|
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
|
* @update gess 1/4/99
|
||||||
* @param reference to another nsString
|
* @param reference to another nsString
|
||||||
*/
|
*/
|
||||||
nsString::nsString(const nsString& aString) :mAgent(aString.mAgent) {
|
nsString::nsString(const nsString& aString) {
|
||||||
nsStr::Initialize(*this,eTwoByte);
|
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
|
* @update gess 1/4/99
|
||||||
* @param reference to a subsumeString
|
* @param reference to a subsumeString
|
||||||
*/
|
*/
|
||||||
nsString::nsString(nsSubsumeStr& aSubsumeStr) :mAgent(0) {
|
nsString::nsString(nsSubsumeStr& aSubsumeStr) {
|
||||||
nsStr::Initialize(*this,eTwoByte);
|
nsStr::Initialize(*this,eTwoByte);
|
||||||
Subsume(*this,aSubsumeStr);
|
Subsume(*this,aSubsumeStr);
|
||||||
}
|
}
|
||||||
@@ -119,7 +119,7 @@ nsString::nsString(nsSubsumeStr& aSubsumeStr) :mAgent(0) {
|
|||||||
* Make sure we call nsStr::Destroy.
|
* Make sure we call nsStr::Destroy.
|
||||||
*/
|
*/
|
||||||
nsString::~nsString() {
|
nsString::~nsString() {
|
||||||
nsStr::Destroy(*this,mAgent);
|
nsStr::Destroy(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
||||||
@@ -136,7 +136,7 @@ void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
|||||||
* @return nada
|
* @return nada
|
||||||
*/
|
*/
|
||||||
void nsString::Truncate(PRInt32 anIndex) {
|
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) {
|
void nsString::SetCapacity(PRUint32 aLength) {
|
||||||
if(aLength>mCapacity) {
|
if(aLength>mCapacity) {
|
||||||
GrowCapacity(*this,aLength,mAgent);
|
GrowCapacity(*this,aLength);
|
||||||
}
|
}
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
}
|
}
|
||||||
@@ -270,7 +270,7 @@ PRBool nsString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
|
|||||||
*/
|
*/
|
||||||
nsSubsumeStr nsString::operator+(const nsStr& aString){
|
nsSubsumeStr nsString::operator+(const nsStr& aString){
|
||||||
nsString temp(*this); //make a temp string the same size as this...
|
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);
|
return nsSubsumeStr(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,7 +282,7 @@ nsSubsumeStr nsString::operator+(const nsStr& aString){
|
|||||||
*/
|
*/
|
||||||
nsSubsumeStr nsString::operator+(const nsString& aString){
|
nsSubsumeStr nsString::operator+(const nsString& aString){
|
||||||
nsString temp(*this); //make a temp string the same size as this...
|
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);
|
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
|
* @return non-zero error code if this string is non-numeric
|
||||||
*/
|
*/
|
||||||
static 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);
|
//begin by skipping over leading chars that shouldn't be part of the number...
|
||||||
char* cp = (kNotFound==decPt) ? aString.mStr + aString.mLength-1 : aString.mStr+decPt-1;
|
|
||||||
|
|
||||||
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<endcp){
|
||||||
while (cp >= aString.mStr) {
|
const char* pos=(const char*)memchr(validChars,*cp,len);
|
||||||
if((*cp>='0') && (*cp<='9')){
|
if(!pos) {
|
||||||
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...
|
|
||||||
cp++;
|
cp++;
|
||||||
while (--cp >= aString.mStr) {
|
|
||||||
if((*cp>='0') && (*cp<='9')){
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
else if((*cp>='A') && (*cp<='F')) {
|
else break;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
else if((*cp=='-') || (*cp=='+')){
|
|
||||||
break;
|
while(cp<endcp){
|
||||||
|
char theChar=toupper(*cp);
|
||||||
|
|
||||||
|
if((theChar>='0') && (theChar<='9')) {
|
||||||
|
*to++=theChar;
|
||||||
}
|
}
|
||||||
else {
|
else if((theChar>='A') && (theChar<='F')) {
|
||||||
if(('#'==(*cp)) || ('X'==(*cp)))
|
aRadix=16;
|
||||||
aRadix=kRadix16;
|
*to++=theChar;
|
||||||
cp++; //move back by one
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -865,9 +866,9 @@ PRUint32 nsString::DetermineRadix(void) {
|
|||||||
PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
||||||
|
|
||||||
//copy chars to local buffer -- step down from 2 bytes to 1 if necessary...
|
//copy chars to local buffer -- step down from 2 bytes to 1 if necessary...
|
||||||
|
PRInt32 result=0;
|
||||||
nsCAutoString theString(*this);
|
nsCAutoString theString(*this);
|
||||||
PRUint32 theRadix=aRadix;
|
PRUint32 theRadix=aRadix;
|
||||||
PRInt32 result=0;
|
|
||||||
|
|
||||||
*anErrorCode=GetNumericSubstring(theString,theRadix); //we actually don't use this radix; use given radix instead
|
*anErrorCode=GetNumericSubstring(theString,theRadix); //we actually don't use this radix; use given radix instead
|
||||||
if(NS_OK==*anErrorCode){
|
if(NS_OK==*anErrorCode){
|
||||||
@@ -893,13 +894,13 @@ PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
|||||||
*/
|
*/
|
||||||
nsString& nsString::Assign(const nsStr& aString,PRInt32 aCount) {
|
nsString& nsString::Assign(const nsStr& aString,PRInt32 aCount) {
|
||||||
if(this!=&aString){
|
if(this!=&aString){
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
|
|
||||||
if(aCount<0)
|
if(aCount<0)
|
||||||
aCount=aString.mLength;
|
aCount=aString.mLength;
|
||||||
else aCount=MinInt(aCount,aString.mLength);
|
else aCount=MinInt(aCount,aString.mLength);
|
||||||
|
|
||||||
nsStr::Assign(*this,aString,0,aCount,mAgent);
|
nsStr::Assign(*this,aString,0,aCount);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -912,7 +913,7 @@ nsString& nsString::Assign(const nsStr& aString,PRInt32 aCount) {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
nsString& nsString::Assign(const char* aCString,PRInt32 aCount) {
|
nsString& nsString::Assign(const char* aCString,PRInt32 aCount) {
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
if(aCString){
|
if(aCString){
|
||||||
Append(aCString,aCount);
|
Append(aCString,aCount);
|
||||||
}
|
}
|
||||||
@@ -926,7 +927,7 @@ nsString& nsString::Assign(const char* aCString,PRInt32 aCount) {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
nsString& nsString::Assign(const PRUnichar* aString,PRInt32 aCount) {
|
nsString& nsString::Assign(const PRUnichar* aString,PRInt32 aCount) {
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
if(aString){
|
if(aString){
|
||||||
Append(aString,aCount);
|
Append(aString,aCount);
|
||||||
}
|
}
|
||||||
@@ -940,7 +941,7 @@ nsString& nsString::Assign(const PRUnichar* aString,PRInt32 aCount) {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
nsString& nsString::Assign(char aChar) {
|
nsString& nsString::Assign(char aChar) {
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
return Append(aChar);
|
return Append(aChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -951,7 +952,7 @@ nsString& nsString::Assign(char aChar) {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
nsString& nsString::Assign(PRUnichar aChar) {
|
nsString& nsString::Assign(PRUnichar aChar) {
|
||||||
nsStr::Truncate(*this,0,0);
|
nsStr::Truncate(*this,0);
|
||||||
return Append(aChar);
|
return Append(aChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -988,7 +989,7 @@ nsString& nsString::Append(const nsStr& aString,PRInt32 aCount) {
|
|||||||
else aCount=MinInt(aCount,aString.mLength);
|
else aCount=MinInt(aCount,aString.mLength);
|
||||||
|
|
||||||
if(0<aCount)
|
if(0<aCount)
|
||||||
nsStr::Append(*this,aString,0,aCount,mAgent);
|
nsStr::Append(*this,aString,0,aCount);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1005,7 +1006,7 @@ nsString& nsString::Append(const nsString& aString,PRInt32 aCount) {
|
|||||||
aCount=aString.mLength;
|
aCount=aString.mLength;
|
||||||
else aCount=MinInt(aCount,aString.mLength);
|
else aCount=MinInt(aCount,aString.mLength);
|
||||||
if(0<aCount)
|
if(0<aCount)
|
||||||
nsStr::Append(*this,aString,0,aCount,mAgent);
|
nsStr::Append(*this,aString,0,aCount);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1034,7 +1035,7 @@ nsString& nsString::Append(const char* aCString,PRInt32 aCount) {
|
|||||||
else aCount=temp.mLength=nsCRT::strlen(aCString);
|
else aCount=temp.mLength=nsCRT::strlen(aCString);
|
||||||
|
|
||||||
if(0<aCount)
|
if(0<aCount)
|
||||||
nsStr::Append(*this,temp,0,aCount,mAgent);
|
nsStr::Append(*this,temp,0,aCount);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -1064,7 +1065,7 @@ nsString& nsString::Append(const PRUnichar* aString,PRInt32 aCount) {
|
|||||||
else aCount=temp.mLength=nsCRT::strlen(aString);
|
else aCount=temp.mLength=nsCRT::strlen(aString);
|
||||||
|
|
||||||
if(0<aCount)
|
if(0<aCount)
|
||||||
nsStr::Append(*this,temp,0,aCount,mAgent);
|
nsStr::Append(*this,temp,0,aCount);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -1083,7 +1084,7 @@ nsString& nsString::Append(char aChar) {
|
|||||||
Initialize(temp,eOneByte);
|
Initialize(temp,eOneByte);
|
||||||
temp.mStr=buf;
|
temp.mStr=buf;
|
||||||
temp.mLength=1;
|
temp.mLength=1;
|
||||||
nsStr::Append(*this,temp,0,1,mAgent);
|
nsStr::Append(*this,temp,0,1);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1101,7 +1102,7 @@ nsString& nsString::Append(PRUnichar aChar) {
|
|||||||
Initialize(temp,eTwoByte);
|
Initialize(temp,eTwoByte);
|
||||||
temp.mUStr=buf;
|
temp.mUStr=buf;
|
||||||
temp.mLength=1;
|
temp.mLength=1;
|
||||||
nsStr::Append(*this,temp,0,1,mAgent);
|
nsStr::Append(*this,temp,0,1);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1132,12 +1133,12 @@ nsString& nsString::Append(PRInt32 anInteger,PRInt32 aRadix) {
|
|||||||
|
|
||||||
PRBool isfirst=PR_TRUE;
|
PRBool isfirst=PR_TRUE;
|
||||||
while(mask1>=1) {
|
while(mask1>=1) {
|
||||||
PRInt32 div=theInt/mask1;
|
PRInt32 theDiv=theInt/mask1;
|
||||||
if((div) || (!isfirst)) {
|
if((theDiv) || (!isfirst)) {
|
||||||
buf[charpos++]="0123456789abcdef"[div];
|
buf[charpos++]="0123456789abcdef"[theDiv];
|
||||||
isfirst=PR_FALSE;
|
isfirst=PR_FALSE;
|
||||||
}
|
}
|
||||||
theInt-=div*mask1;
|
theInt-=theDiv*mask1;
|
||||||
mask1/=aRadix;
|
mask1/=aRadix;
|
||||||
}
|
}
|
||||||
return Append(buf);
|
return Append(buf);
|
||||||
@@ -1173,7 +1174,7 @@ PRUint32 nsString::Left(nsString& aDest,PRInt32 aCount) const{
|
|||||||
if(aCount<0)
|
if(aCount<0)
|
||||||
aCount=mLength;
|
aCount=mLength;
|
||||||
else aCount=MinInt(aCount,mLength);
|
else aCount=MinInt(aCount,mLength);
|
||||||
nsStr::Assign(aDest,*this,0,aCount,mAgent);
|
nsStr::Assign(aDest,*this,0,aCount);
|
||||||
|
|
||||||
return aDest.mLength;
|
return aDest.mLength;
|
||||||
}
|
}
|
||||||
@@ -1191,7 +1192,7 @@ PRUint32 nsString::Mid(nsString& aDest,PRUint32 anOffset,PRInt32 aCount) const{
|
|||||||
if(aCount<0)
|
if(aCount<0)
|
||||||
aCount=mLength;
|
aCount=mLength;
|
||||||
else aCount=MinInt(aCount,mLength);
|
else aCount=MinInt(aCount,mLength);
|
||||||
nsStr::Assign(aDest,*this,anOffset,aCount,mAgent);
|
nsStr::Assign(aDest,*this,anOffset,aCount);
|
||||||
|
|
||||||
return aDest.mLength;
|
return aDest.mLength;
|
||||||
}
|
}
|
||||||
@@ -1221,7 +1222,7 @@ PRUint32 nsString::Right(nsString& aDest,PRInt32 aCount) const{
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
nsString& nsString::Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) {
|
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;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1252,7 +1253,7 @@ nsString& nsString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCount
|
|||||||
else aCount=temp.mLength=nsCRT::strlen(aCString);
|
else aCount=temp.mLength=nsCRT::strlen(aCString);
|
||||||
|
|
||||||
if(0<aCount){
|
if(0<aCount){
|
||||||
nsStr::Insert(*this,anOffset,temp,0,aCount,0);
|
nsStr::Insert(*this,anOffset,temp,0,aCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
@@ -1285,7 +1286,7 @@ nsString& nsString::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32 aC
|
|||||||
else aCount=temp.mLength=nsCRT::strlen(aString);
|
else aCount=temp.mLength=nsCRT::strlen(aString);
|
||||||
|
|
||||||
if(0<aCount){
|
if(0<aCount){
|
||||||
nsStr::Insert(*this,anOffset,temp,0,aCount,0);
|
nsStr::Insert(*this,anOffset,temp,0,aCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
@@ -1308,7 +1309,7 @@ nsString& nsString::Insert(PRUnichar aChar,PRUint32 anOffset){
|
|||||||
nsStr::Initialize(temp,eTwoByte);
|
nsStr::Initialize(temp,eTwoByte);
|
||||||
temp.mUStr=theBuffer;
|
temp.mUStr=theBuffer;
|
||||||
temp.mLength=1;
|
temp.mLength=1;
|
||||||
nsStr::Insert(*this,anOffset,temp,0,1,0);
|
nsStr::Insert(*this,anOffset,temp,0,1);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1323,7 +1324,7 @@ nsString& nsString::Insert(PRUnichar aChar,PRUint32 anOffset){
|
|||||||
*/
|
*/
|
||||||
nsString& nsString::Cut(PRUint32 anOffset, PRInt32 aCount) {
|
nsString& nsString::Cut(PRUint32 anOffset, PRInt32 aCount) {
|
||||||
if(0<aCount) {
|
if(0<aCount) {
|
||||||
nsStr::Delete(*this,anOffset,aCount,mAgent);
|
nsStr::Delete(*this,anOffset,aCount);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -1957,10 +1958,8 @@ PRBool nsString::IsDigit(PRUnichar aChar) {
|
|||||||
class nsStringDeallocator: public nsDequeFunctor{
|
class nsStringDeallocator: public nsDequeFunctor{
|
||||||
public:
|
public:
|
||||||
virtual void* operator()(void* anObject) {
|
virtual void* operator()(void* anObject) {
|
||||||
static nsMemoryAgent theAgent;
|
|
||||||
nsString* aString= (nsString*)anObject;
|
nsString* aString= (nsString*)anObject;
|
||||||
if(aString){
|
if(aString){
|
||||||
aString->mAgent=&theAgent;
|
|
||||||
delete aString;
|
delete aString;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -2116,7 +2115,6 @@ NS_COM int fputs(const nsString& aString, FILE* out)
|
|||||||
*/
|
*/
|
||||||
nsAutoString::nsAutoString() : nsString() {
|
nsAutoString::nsAutoString() : nsString() {
|
||||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
||||||
mAgent=0;
|
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2127,7 +2125,6 @@ nsAutoString::nsAutoString() : nsString() {
|
|||||||
*/
|
*/
|
||||||
nsAutoString::nsAutoString(const char* aCString,PRInt32 aLength) : nsString() {
|
nsAutoString::nsAutoString(const char* aCString,PRInt32 aLength) : nsString() {
|
||||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
||||||
mAgent=0;
|
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aCString,aLength);
|
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
|
* @param aLength tells us how many chars to copy from aString
|
||||||
*/
|
*/
|
||||||
nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString() {
|
nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString() {
|
||||||
mAgent=0;
|
|
||||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aString,aLength);
|
Append(aString,aLength);
|
||||||
@@ -2149,7 +2145,6 @@ nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString(
|
|||||||
* @param aBuffer describes the external buffer
|
* @param aBuffer describes the external buffer
|
||||||
*/
|
*/
|
||||||
nsAutoString::nsAutoString(const CBufDescriptor& aBuffer) : nsString() {
|
nsAutoString::nsAutoString(const CBufDescriptor& aBuffer) : nsString() {
|
||||||
mAgent=0;
|
|
||||||
if(!aBuffer.mBuffer) {
|
if(!aBuffer.mBuffer) {
|
||||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
||||||
}
|
}
|
||||||
@@ -2166,7 +2161,6 @@ nsAutoString::nsAutoString(const CBufDescriptor& aBuffer) : nsString() {
|
|||||||
* @param
|
* @param
|
||||||
*/
|
*/
|
||||||
nsAutoString::nsAutoString(const nsStr& aString) : nsString() {
|
nsAutoString::nsAutoString(const nsStr& aString) : nsString() {
|
||||||
mAgent=0;
|
|
||||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aString);
|
Append(aString);
|
||||||
@@ -2176,7 +2170,6 @@ nsAutoString::nsAutoString(const nsStr& aString) : nsString() {
|
|||||||
* Default copy constructor
|
* Default copy constructor
|
||||||
*/
|
*/
|
||||||
nsAutoString::nsAutoString(const nsAutoString& aString) : nsString() {
|
nsAutoString::nsAutoString(const nsAutoString& aString) : nsString() {
|
||||||
mAgent=0;
|
|
||||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aString);
|
Append(aString);
|
||||||
@@ -2188,7 +2181,6 @@ nsAutoString::nsAutoString(const nsAutoString& aString) : nsString() {
|
|||||||
* @param
|
* @param
|
||||||
*/
|
*/
|
||||||
nsAutoString::nsAutoString(PRUnichar aChar) : nsString(){
|
nsAutoString::nsAutoString(PRUnichar aChar) : nsString(){
|
||||||
mAgent=0;
|
|
||||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
||||||
AddNullTerminator(*this);
|
AddNullTerminator(*this);
|
||||||
Append(aChar);
|
Append(aChar);
|
||||||
@@ -2201,12 +2193,10 @@ nsAutoString::nsAutoString(PRUnichar aChar) : nsString(){
|
|||||||
*/
|
*/
|
||||||
#ifdef AIX
|
#ifdef AIX
|
||||||
nsAutoString::nsAutoString(const nsSubsumeStr& aSubsumeStr) :nsString() {
|
nsAutoString::nsAutoString(const nsSubsumeStr& aSubsumeStr) :nsString() {
|
||||||
mAgent=0;
|
|
||||||
nsSubsumeStr temp(aSubsumeStr); // a temp is needed for the AIX compiler
|
nsSubsumeStr temp(aSubsumeStr); // a temp is needed for the AIX compiler
|
||||||
Subsume(*this,temp);
|
Subsume(*this,temp);
|
||||||
#else
|
#else
|
||||||
nsAutoString::nsAutoString( nsSubsumeStr& aSubsumeStr) :nsString() {
|
nsAutoString::nsAutoString( nsSubsumeStr& aSubsumeStr) :nsString() {
|
||||||
mAgent=0;
|
|
||||||
Subsume(*this,aSubsumeStr);
|
Subsume(*this,aSubsumeStr);
|
||||||
#endif // AIX
|
#endif // AIX
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,26 +58,26 @@ class NS_COM nsString : public nsStr {
|
|||||||
/**
|
/**
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
*/
|
*/
|
||||||
nsString(nsIMemoryAgent* anAgent=0);
|
nsString();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constructor accepts an isolatin string
|
* This constructor accepts an isolatin string
|
||||||
* @param aCString is a ptr to a 1-byte cstr
|
* @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
|
* This constructor accepts a unichar string
|
||||||
* @param aCString is a ptr to a 2-byte cstr
|
* @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
|
* This is a copy constructor that accepts an nsStr
|
||||||
* @param reference to another nsString
|
* @param reference to another nsString
|
||||||
*/
|
*/
|
||||||
nsString(const nsStr&,nsIMemoryAgent* anAgent=0);
|
nsString(const nsStr&);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is our copy constructor
|
* This is our copy constructor
|
||||||
@@ -168,6 +168,9 @@ PRBool IsEmpty(void) const {
|
|||||||
Getters/Setters...
|
Getters/Setters...
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve const ptr to internal buffer; DO NOT TRY TO FREE IT!
|
||||||
|
*/
|
||||||
const char* GetBuffer(void) const;
|
const char* GetBuffer(void) const;
|
||||||
const PRUnichar* GetUnicode(void) const;
|
const PRUnichar* GetUnicode(void) const;
|
||||||
|
|
||||||
@@ -761,9 +764,6 @@ static PRBool IsDigit(PRUnichar ch);
|
|||||||
static void Recycle(nsString* aString);
|
static void Recycle(nsString* aString);
|
||||||
static nsString* CreateString(void);
|
static nsString* CreateString(void);
|
||||||
|
|
||||||
|
|
||||||
nsIMemoryAgent* mAgent;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern NS_COM int fputs(const nsString& aString, FILE* out);
|
extern NS_COM int fputs(const nsString& aString, FILE* out);
|
||||||
|
|||||||
Reference in New Issue
Block a user