зеркало из https://github.com/mozilla/gecko-dev.git
perf update and bug fix: a=chofmann r=buster
This commit is contained in:
Родитель
63e115364d
Коммит
6f744b281a
|
@ -108,12 +108,15 @@ void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) {
|
|||
* @param aNewLength -- new capacity of string in charSize units
|
||||
* @return void
|
||||
*/
|
||||
void nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent) {
|
||||
PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent) {
|
||||
PRBool result=PR_TRUE;
|
||||
if(aNewLength>aString.mCapacity) {
|
||||
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
|
||||
theAgent->Realloc(aString,aNewLength);
|
||||
AddNullTerminator(aString);
|
||||
result=theAgent->Realloc(aString,aNewLength);
|
||||
if(aString.mStr)
|
||||
AddNullTerminator(aString);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -123,24 +126,28 @@ void nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* an
|
|||
* @param aNewLength -- new capacity of string in charSize units
|
||||
* @return void
|
||||
*/
|
||||
void nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAgent) {
|
||||
PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAgent) {
|
||||
PRBool result=PR_TRUE;
|
||||
if(aNewLength>aDest.mCapacity) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,aDest.mCharSize);
|
||||
|
||||
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
|
||||
EnsureCapacity(theTempStr,aNewLength,theAgent);
|
||||
|
||||
if(aDest.mLength) {
|
||||
Append(theTempStr,aDest,0,aDest.mLength,theAgent);
|
||||
}
|
||||
theAgent->Free(aDest);
|
||||
aDest.mStr = theTempStr.mStr;
|
||||
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
|
||||
aDest.mLength=theTempStr.mLength;
|
||||
aDest.mCapacity=theTempStr.mCapacity;
|
||||
aDest.mOwnsBuffer=theTempStr.mOwnsBuffer;
|
||||
result=EnsureCapacity(theTempStr,aNewLength,theAgent);
|
||||
if(result) {
|
||||
if(aDest.mLength) {
|
||||
Append(theTempStr,aDest,0,aDest.mLength,theAgent);
|
||||
}
|
||||
theAgent->Free(aDest);
|
||||
aDest.mStr = theTempStr.mStr;
|
||||
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
|
||||
aDest.mLength=theTempStr.mLength;
|
||||
aDest.mCapacity=theTempStr.mCapacity;
|
||||
aDest.mOwnsBuffer=theTempStr.mOwnsBuffer;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -170,15 +177,19 @@ void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 a
|
|||
PRUint32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
|
||||
PRUint32 theLength=(anOffset+theRealLen<aSource.mLength) ? theRealLen : (aSource.mLength-anOffset);
|
||||
if(0<theLength){
|
||||
|
||||
PRBool isBigEnough=PR_TRUE;
|
||||
if(aDest.mLength+theLength > aDest.mCapacity) {
|
||||
GrowCapacity(aDest,aDest.mLength+theLength,anAgent);
|
||||
isBigEnough=GrowCapacity(aDest,aDest.mLength+theLength,anAgent);
|
||||
}
|
||||
|
||||
//now append new chars, starting at offset
|
||||
(*gCopyChars[aSource.mCharSize][aDest.mCharSize])(aDest.mStr,aDest.mLength,aSource.mStr,anOffset,theLength);
|
||||
if(isBigEnough) {
|
||||
//now append new chars, starting at offset
|
||||
(*gCopyChars[aSource.mCharSize][aDest.mCharSize])(aDest.mStr,aDest.mLength,aSource.mStr,anOffset,theLength);
|
||||
|
||||
aDest.mLength+=theLength;
|
||||
AddNullTerminator(aDest);
|
||||
aDest.mLength+=theLength;
|
||||
AddNullTerminator(aDest);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -213,24 +224,26 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin
|
|||
nsStr::Initialize(theTempStr,aDest.mCharSize);
|
||||
|
||||
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
|
||||
EnsureCapacity(theTempStr,aDest.mLength+theLength,theAgent); //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(aDestOffset) {
|
||||
Append(theTempStr,aDest,0,aDestOffset,theAgent); //first copy leftmost data...
|
||||
}
|
||||
if(isBigEnough) {
|
||||
if(aDestOffset) {
|
||||
Append(theTempStr,aDest,0,aDestOffset,theAgent); //first copy leftmost data...
|
||||
}
|
||||
|
||||
Append(theTempStr,aSource,0,aSource.mLength,theAgent); //next copy inserted (new) data
|
||||
Append(theTempStr,aSource,0,aSource.mLength,theAgent); //next copy inserted (new) data
|
||||
|
||||
PRUint32 theRemains=aDest.mLength-aDestOffset;
|
||||
if(theRemains) {
|
||||
Append(theTempStr,aDest,aDestOffset,theRemains,theAgent); //next copy rightmost data
|
||||
}
|
||||
PRUint32 theRemains=aDest.mLength-aDestOffset;
|
||||
if(theRemains) {
|
||||
Append(theTempStr,aDest,aDestOffset,theRemains,theAgent); //next copy rightmost data
|
||||
}
|
||||
|
||||
theAgent->Free(aDest);
|
||||
aDest.mStr = theTempStr.mStr;
|
||||
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
|
||||
aDest.mCapacity=theTempStr.mCapacity;
|
||||
aDest.mOwnsBuffer=theTempStr.mOwnsBuffer;
|
||||
theAgent->Free(aDest);
|
||||
aDest.mStr = theTempStr.mStr;
|
||||
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
|
||||
aDest.mCapacity=theTempStr.mCapacity;
|
||||
aDest.mOwnsBuffer=theTempStr.mOwnsBuffer;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -365,6 +378,21 @@ void nsStr::CompressSet(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,P
|
|||
aDest.mLength=aNewLen;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess1/7/99
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void nsStr::StripChars(nsStr& aDest,const char* aSet){
|
||||
if((0<aDest.mLength) && (aSet)) {
|
||||
PRUint32 aNewLen=gStripChars[aDest.mCharSize](aDest.mStr,aDest.mLength,aSet);
|
||||
aDest.mLength=aNewLen;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Searching methods...
|
||||
**************************************************************/
|
||||
|
|
|
@ -238,8 +238,8 @@ struct NS_COM nsStr {
|
|||
* @param anAgent is the allocator to be used on the nsStr
|
||||
* @return
|
||||
*/
|
||||
static void EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0);
|
||||
static void GrowCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0);
|
||||
static PRBool EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0);
|
||||
static PRBool GrowCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0);
|
||||
|
||||
/**
|
||||
* These methods are used to append content to the given nsStr
|
||||
|
@ -336,6 +336,18 @@ struct NS_COM nsStr {
|
|||
*/
|
||||
static void CompressSet(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing);
|
||||
|
||||
/**
|
||||
* This method removes all occurances of chars in given set from aDest
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the buffer to be manipulated
|
||||
* @param aSet tells us which chars to compress from given buffer
|
||||
* @param aChar is the replacement char
|
||||
* @param aEliminateLeading tells us whether to strip chars from the start of the buffer
|
||||
* @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
|
||||
*/
|
||||
static void StripChars(nsStr& aDest,const char* aSet);
|
||||
|
||||
/**
|
||||
* This method compares the data bewteen two nsStr's
|
||||
*
|
||||
|
@ -445,8 +457,12 @@ public:
|
|||
PRUint32 theSize=(theNewCapacity<<aDest.mCharSize);
|
||||
aDest.mStr = (char*)nsAllocator::Alloc(theSize);
|
||||
|
||||
aDest.mOwnsBuffer=1;
|
||||
return PR_TRUE;
|
||||
PRBool result=PR_FALSE;
|
||||
if(aDest.mStr) {
|
||||
aDest.mOwnsBuffer=1;
|
||||
result=PR_TRUE;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual PRBool Free(nsStr& aDest){
|
||||
|
@ -462,10 +478,23 @@ public:
|
|||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -355,13 +355,9 @@ void nsCString::ToUpperCase(nsCString& aString) const {
|
|||
* @param aChar -- char to be stripped
|
||||
* @return *this
|
||||
*/
|
||||
nsCString& nsCString::StripChar(PRUnichar aChar){
|
||||
|
||||
PRInt32 theIndex=FindChar(aChar,PR_FALSE,0);
|
||||
while(kNotFound<theIndex) {
|
||||
Cut(theIndex,1);
|
||||
theIndex=FindChar(aChar,PR_FALSE,theIndex);
|
||||
}
|
||||
nsCString& nsCString::StripChar(char aChar){
|
||||
char aSet[2]={aChar,0};
|
||||
nsStr::StripChars(*this,aSet);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -374,13 +370,7 @@ nsCString& nsCString::StripChar(PRUnichar aChar){
|
|||
* @return *this
|
||||
*/
|
||||
nsCString& nsCString::StripChars(const char* aSet){
|
||||
if(aSet){
|
||||
PRInt32 theIndex=FindCharInSet(aSet,0);
|
||||
while(kNotFound<theIndex) {
|
||||
Cut(theIndex,1);
|
||||
theIndex=FindCharInSet(aSet,theIndex);
|
||||
}
|
||||
}
|
||||
nsStr::StripChars(*this,aSet);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -952,43 +942,34 @@ nsCString& nsCString::Append(char aChar) {
|
|||
* @param aRadix:
|
||||
* @return
|
||||
*/
|
||||
nsCString& nsCString::Append(PRInt32 aInteger,PRInt32 aRadix) {
|
||||
nsCString& nsCString::Append(PRInt32 anInteger,PRInt32 aRadix) {
|
||||
|
||||
#if 0
|
||||
char buf[128]={0,0};
|
||||
char* buffer=buf;
|
||||
PRUint32 theInt=(PRUint32)anInteger;
|
||||
|
||||
ldiv_t r; /* result of val / base */
|
||||
if (aRadix> 36 || aRadix< 2) { /* no conversion if wrong base */
|
||||
return *this;
|
||||
char buf[]={'0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
|
||||
PRInt32 radices[] = {1000000000,268435456};
|
||||
PRInt32 mask1=radices[16==aRadix];
|
||||
|
||||
PRInt32 charpos=0;
|
||||
if(anInteger<0) {
|
||||
theInt*=-1;
|
||||
if(10==aRadix) {
|
||||
buf[charpos++]='-';
|
||||
}
|
||||
else theInt=(int)~(theInt-1);
|
||||
}
|
||||
|
||||
if (aInteger < 0)
|
||||
*buffer++ = '-';
|
||||
r = ldiv (labs(aInteger), aRadix);
|
||||
|
||||
/* output digits of val/base first */
|
||||
if (r.quot > 0)
|
||||
buffer = ltoa ( r.quot, buf, aRadix);
|
||||
|
||||
/* output last digit */
|
||||
int len=strlen(buffer);
|
||||
buf[len] = "0123456789abcdefghijklmnopqrstuvwxyz"[(int)r.rem];
|
||||
buf[len+1] =0;
|
||||
|
||||
#endif
|
||||
|
||||
char* fmt = "%d";
|
||||
if (8 == aRadix) {
|
||||
fmt = "%o";
|
||||
} else if (16 == aRadix) {
|
||||
fmt = "%x";
|
||||
PRBool isfirst=true;
|
||||
while(mask1>=1) {
|
||||
PRInt32 div=theInt/mask1;
|
||||
if((div) || (!isfirst)) {
|
||||
buf[charpos++]="0123456789abcdef"[div];
|
||||
isfirst=false;
|
||||
}
|
||||
theInt-=div*mask1;
|
||||
mask1/=aRadix;
|
||||
}
|
||||
char buf[40];
|
||||
// *** XX UNCOMMENT THIS LINE
|
||||
//PR_snprintf(buf, sizeof(buf), fmt, aInteger);
|
||||
sprintf(buf,fmt,aInteger);
|
||||
|
||||
return Append(buf);
|
||||
}
|
||||
|
||||
|
|
|
@ -234,7 +234,7 @@ void ToUpperCase(nsCString& aString) const;
|
|||
* @return *this
|
||||
*/
|
||||
nsCString& StripChars(const char* aSet);
|
||||
nsCString& StripChar(PRUnichar aChar);
|
||||
nsCString& StripChar(char aChar);
|
||||
|
||||
/**
|
||||
* This method strips whitespace throughout the string
|
||||
|
|
|
@ -386,13 +386,9 @@ void nsString::ToUpperCase(nsString& aString) const {
|
|||
* @param aChar -- char to be stripped
|
||||
* @return *this
|
||||
*/
|
||||
nsString& nsString::StripChar(PRUnichar aChar){
|
||||
|
||||
PRInt32 theIndex=FindChar(aChar,PR_FALSE,0);
|
||||
while(kNotFound<theIndex) {
|
||||
Cut(theIndex,1);
|
||||
theIndex=FindChar(aChar,PR_FALSE,theIndex);
|
||||
}
|
||||
nsString& nsString::StripChar(char aChar){
|
||||
char aSet[2]={aChar,0};
|
||||
nsStr::StripChars(*this,aSet);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -405,14 +401,7 @@ nsString& nsString::StripChar(PRUnichar aChar){
|
|||
* @return *this
|
||||
*/
|
||||
nsString& nsString::StripChars(const char* aSet){
|
||||
|
||||
if(aSet){
|
||||
PRInt32 theIndex=FindCharInSet(aSet,0);
|
||||
while(kNotFound<theIndex) {
|
||||
Cut(theIndex,1);
|
||||
theIndex=FindCharInSet(aSet,theIndex);
|
||||
}
|
||||
}
|
||||
nsStr::StripChars(*this,aSet);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -424,8 +413,7 @@ nsString& nsString::StripChars(const char* aSet){
|
|||
* @return this
|
||||
*/
|
||||
nsString& nsString::StripWhitespace() {
|
||||
StripChars(kWhitespace);
|
||||
return *this;
|
||||
return StripChars(kWhitespace);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1124,43 +1112,34 @@ nsString& nsString::Append(PRUnichar aChar) {
|
|||
* @param aRadix:
|
||||
* @return
|
||||
*/
|
||||
nsString& nsString::Append(PRInt32 aInteger,PRInt32 aRadix) {
|
||||
nsString& nsString::Append(PRInt32 anInteger,PRInt32 aRadix) {
|
||||
|
||||
#if 0
|
||||
char buf[128]={0,0};
|
||||
char* buffer=buf;
|
||||
PRUint32 theInt=(PRUint32)anInteger;
|
||||
|
||||
ldiv_t r; /* result of val / base */
|
||||
if (aRadix> 36 || aRadix< 2) { /* no conversion if wrong base */
|
||||
return *this;
|
||||
char buf[]={'0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
|
||||
PRInt32 radices[] = {1000000000,268435456};
|
||||
PRInt32 mask1=radices[16==aRadix];
|
||||
|
||||
PRInt32 charpos=0;
|
||||
if(anInteger<0) {
|
||||
theInt*=-1;
|
||||
if(10==aRadix) {
|
||||
buf[charpos++]='-';
|
||||
}
|
||||
else theInt=(int)~(theInt-1);
|
||||
}
|
||||
|
||||
if (aInteger < 0)
|
||||
*buffer++ = '-';
|
||||
r = ldiv (labs(aInteger), aRadix);
|
||||
|
||||
/* output digits of val/base first */
|
||||
if (r.quot > 0)
|
||||
buffer = ltoa ( r.quot, buf, aRadix);
|
||||
|
||||
/* output last digit */
|
||||
int len=strlen(buffer);
|
||||
buf[len] = "0123456789abcdefghijklmnopqrstuvwxyz"[(int)r.rem];
|
||||
buf[len+1] =0;
|
||||
|
||||
#endif
|
||||
|
||||
char* fmt = "%d";
|
||||
if (8 == aRadix) {
|
||||
fmt = "%o";
|
||||
} else if (16 == aRadix) {
|
||||
fmt = "%x";
|
||||
PRBool isfirst=true;
|
||||
while(mask1>=1) {
|
||||
PRInt32 div=theInt/mask1;
|
||||
if((div) || (!isfirst)) {
|
||||
buf[charpos++]="0123456789abcdef"[div];
|
||||
isfirst=false;
|
||||
}
|
||||
theInt-=div*mask1;
|
||||
mask1/=aRadix;
|
||||
}
|
||||
char buf[40];
|
||||
// *** XX UNCOMMENT THIS LINE
|
||||
//PR_snprintf(buf, sizeof(buf), fmt, aInteger);
|
||||
sprintf(buf,fmt,aInteger);
|
||||
|
||||
return Append(buf);
|
||||
}
|
||||
|
||||
|
|
|
@ -269,7 +269,7 @@ void ToUpperCase(nsString& aString) const;
|
|||
* @return *this
|
||||
*/
|
||||
nsString& StripChars(const char* aSet);
|
||||
nsString& StripChar(PRUnichar aChar);
|
||||
nsString& StripChar(char aChar);
|
||||
|
||||
/**
|
||||
* This method strips whitespace throughout the string
|
||||
|
|
|
@ -253,16 +253,21 @@ inline PRInt32 FindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,co
|
|||
PRInt32 theLength=(PRInt32)aLength;
|
||||
|
||||
if(aIgnoreCase) {
|
||||
PRUnichar theChar=nsCRT::ToUpper(aChar);
|
||||
for(theIndex=(PRInt32)anOffset;theIndex<theLength;theIndex++){
|
||||
if(nsCRT::ToUpper(aDest[theIndex])==theChar)
|
||||
return theIndex;
|
||||
char theChar=(char)nsCRT::ToUpper(aChar);
|
||||
const char* ptr=aDest+(anOffset-1);
|
||||
const char* last=aDest+aLength;
|
||||
while(++ptr<last){
|
||||
if(nsCRT::ToUpper(*ptr)==theChar)
|
||||
return ptr-aDest;
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(theIndex=(PRInt32)anOffset;theIndex<theLength;theIndex++){
|
||||
if(aDest[theIndex]==aChar)
|
||||
return theIndex;
|
||||
|
||||
const char* ptr = aDest+anOffset;
|
||||
char theChar=(char)aChar;
|
||||
const char* result=(const char*)memchr(ptr, theChar,aLength-anOffset);
|
||||
if(result) {
|
||||
return result-aDest;
|
||||
}
|
||||
}
|
||||
return kNotFound;
|
||||
|
@ -280,21 +285,23 @@ inline PRInt32 FindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,co
|
|||
* @return index of pos if found, else -1 (kNotFound)
|
||||
*/
|
||||
inline PRInt32 FindChar2(const char* aDest,PRUint32 aLength,PRUint32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
PRInt32 theIndex=0;
|
||||
PRInt32 theLength=(PRInt32)aLength;
|
||||
PRUnichar* theBuf=(PRUnichar*)aDest;
|
||||
PRInt32 theIndex=0;
|
||||
PRInt32 theLength=(PRInt32)aLength;
|
||||
const PRUnichar* root=(PRUnichar*)aDest;
|
||||
const PRUnichar* ptr=root+(anOffset-1);
|
||||
const PRUnichar* last=root+aLength;
|
||||
|
||||
if(aIgnoreCase) {
|
||||
PRUnichar theChar=nsCRT::ToUpper(aChar);
|
||||
for(theIndex=(PRInt32)anOffset;theIndex<theLength;theIndex++){
|
||||
if(nsCRT::ToUpper(theBuf[theIndex])==theChar)
|
||||
return theIndex;
|
||||
while(++ptr<last){
|
||||
if(nsCRT::ToUpper(*ptr)==theChar)
|
||||
return ptr-root;
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(theIndex=(PRInt32)anOffset;theIndex<theLength;theIndex++){
|
||||
if(theBuf[theIndex]==aChar)
|
||||
return theIndex;
|
||||
while(++ptr<last){
|
||||
if(*ptr==aChar)
|
||||
return (ptr-root);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -514,15 +521,14 @@ static nsICaseConversion * gCaseConv = 0;
|
|||
NS_IMPL_ISUPPORTS(HandleCaseConversionShutdown3, kIShutdownListenerIID);
|
||||
|
||||
nsresult HandleCaseConversionShutdown3::OnShutdown(const nsCID& cid, nsISupports* service) {
|
||||
nsresult rv = NS_OK;
|
||||
if (cid.Equals(kUnicharUtilCID)) {
|
||||
NS_ASSERTION(service == gCaseConv, "wrong service!");
|
||||
if (gCaseConv) {
|
||||
rv = nsServiceManager::ReleaseService(kUnicharUtilCID, gCaseConv);
|
||||
gCaseConv = nsnull;
|
||||
if(gCaseConv){
|
||||
gCaseConv->Release();
|
||||
gCaseConv = 0;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -532,9 +538,7 @@ public:
|
|||
mListener = new HandleCaseConversionShutdown3();
|
||||
if(mListener){
|
||||
mListener->AddRef();
|
||||
nsresult rv = nsServiceManager::GetService(kUnicharUtilCID, kICaseConversionIID,
|
||||
(nsISupports**) &gCaseConv, mListener);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "can't get case conversion service");
|
||||
nsServiceManager::GetService(kUnicharUtilCID, kICaseConversionIID,(nsISupports**) &gCaseConv, mListener);
|
||||
}
|
||||
}
|
||||
protected:
|
||||
|
@ -689,5 +693,70 @@ PRInt32 CompressChars2(char* aString,PRUint32 aLength,const char* aSet){
|
|||
typedef PRInt32 (*CompressChars)(char* aString,PRUint32 aCount,const char* aSet);
|
||||
CompressChars gCompressChars[]={&CompressChars1,&CompressChars2};
|
||||
|
||||
/**
|
||||
* This method strips chars in a given set from the given buffer
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aString is the buffer to be manipulated
|
||||
* @param aLength is the length of the buffer
|
||||
* @param aSet tells us which chars to compress from given buffer
|
||||
* @param aEliminateLeading tells us whether to strip chars from the start of the buffer
|
||||
* @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
|
||||
* @return the new length of the given buffer
|
||||
*/
|
||||
PRInt32 StripChars1(char* aString,PRUint32 aLength,const char* aSet){
|
||||
|
||||
typedef char chartype;
|
||||
chartype* to = aString;
|
||||
chartype* from = aString-1;
|
||||
chartype* end = aString + aLength;
|
||||
|
||||
if(aSet && aString && (0 < aLength)){
|
||||
PRUint32 aSetLen=strlen(aSet);
|
||||
while (++from < end) {
|
||||
chartype theChar = *from;
|
||||
if(kNotFound==FindChar1(aSet,aSetLen,0,theChar,PR_FALSE)){
|
||||
*to++ = theChar;
|
||||
}
|
||||
}
|
||||
*to = 0;
|
||||
}
|
||||
return to - (chartype*)aString;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method strips chars in a given set from the given buffer
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aString is the buffer to be manipulated
|
||||
* @param aLength is the length of the buffer
|
||||
* @param aSet tells us which chars to compress from given buffer
|
||||
* @param aEliminateLeading tells us whether to strip chars from the start of the buffer
|
||||
* @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
|
||||
* @return the new length of the given buffer
|
||||
*/
|
||||
PRInt32 StripChars2(char* aString,PRUint32 aLength,const char* aSet){
|
||||
|
||||
typedef PRUnichar chartype;
|
||||
chartype* to = (chartype*)aString;
|
||||
chartype* from = (chartype*)aString-1;
|
||||
chartype* end = to + aLength;
|
||||
|
||||
if(aSet && aString && (0 < aLength)){
|
||||
PRUint32 aSetLen=strlen(aSet);
|
||||
while (++from < end) {
|
||||
chartype theChar = *from;
|
||||
if(kNotFound==FindChar1(aSet,aSetLen,0,theChar,PR_FALSE)){
|
||||
*to++ = theChar;
|
||||
}
|
||||
}
|
||||
*to = 0;
|
||||
}
|
||||
return to - (chartype*)aString;
|
||||
}
|
||||
|
||||
typedef PRInt32 (*StripChars)(char* aString,PRUint32 aCount,const char* aSet);
|
||||
StripChars gStripChars[]={&StripChars1,&StripChars2};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -78,17 +78,11 @@ nsDeque::~nsDeque() {
|
|||
|
||||
|
||||
/**
|
||||
* Returns the number of elements currently stored in
|
||||
* this deque.
|
||||
*
|
||||
* @update gess4/18/98
|
||||
* @param
|
||||
* @return int contains element count
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsDeque::GetSize(void) const {
|
||||
return mSize;
|
||||
}
|
||||
|
||||
void nsDeque::SetDeallocator(nsDequeFunctor* aDeallocator){
|
||||
if(mDeallocator) {
|
||||
delete mDeallocator;
|
||||
|
|
|
@ -82,8 +82,7 @@ friend class nsDequeIterator;
|
|||
* @param
|
||||
* @return int contains element count
|
||||
*/
|
||||
PRInt32 GetSize() const;
|
||||
|
||||
inline PRInt32 GetSize() const { return mSize;}
|
||||
|
||||
/**
|
||||
* Pushes new member onto the end of the deque
|
||||
|
|
|
@ -108,12 +108,15 @@ void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) {
|
|||
* @param aNewLength -- new capacity of string in charSize units
|
||||
* @return void
|
||||
*/
|
||||
void nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent) {
|
||||
PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent) {
|
||||
PRBool result=PR_TRUE;
|
||||
if(aNewLength>aString.mCapacity) {
|
||||
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
|
||||
theAgent->Realloc(aString,aNewLength);
|
||||
AddNullTerminator(aString);
|
||||
result=theAgent->Realloc(aString,aNewLength);
|
||||
if(aString.mStr)
|
||||
AddNullTerminator(aString);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -123,24 +126,28 @@ void nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* an
|
|||
* @param aNewLength -- new capacity of string in charSize units
|
||||
* @return void
|
||||
*/
|
||||
void nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAgent) {
|
||||
PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAgent) {
|
||||
PRBool result=PR_TRUE;
|
||||
if(aNewLength>aDest.mCapacity) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,aDest.mCharSize);
|
||||
|
||||
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
|
||||
EnsureCapacity(theTempStr,aNewLength,theAgent);
|
||||
|
||||
if(aDest.mLength) {
|
||||
Append(theTempStr,aDest,0,aDest.mLength,theAgent);
|
||||
}
|
||||
theAgent->Free(aDest);
|
||||
aDest.mStr = theTempStr.mStr;
|
||||
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
|
||||
aDest.mLength=theTempStr.mLength;
|
||||
aDest.mCapacity=theTempStr.mCapacity;
|
||||
aDest.mOwnsBuffer=theTempStr.mOwnsBuffer;
|
||||
result=EnsureCapacity(theTempStr,aNewLength,theAgent);
|
||||
if(result) {
|
||||
if(aDest.mLength) {
|
||||
Append(theTempStr,aDest,0,aDest.mLength,theAgent);
|
||||
}
|
||||
theAgent->Free(aDest);
|
||||
aDest.mStr = theTempStr.mStr;
|
||||
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
|
||||
aDest.mLength=theTempStr.mLength;
|
||||
aDest.mCapacity=theTempStr.mCapacity;
|
||||
aDest.mOwnsBuffer=theTempStr.mOwnsBuffer;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -170,15 +177,19 @@ void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 a
|
|||
PRUint32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
|
||||
PRUint32 theLength=(anOffset+theRealLen<aSource.mLength) ? theRealLen : (aSource.mLength-anOffset);
|
||||
if(0<theLength){
|
||||
|
||||
PRBool isBigEnough=PR_TRUE;
|
||||
if(aDest.mLength+theLength > aDest.mCapacity) {
|
||||
GrowCapacity(aDest,aDest.mLength+theLength,anAgent);
|
||||
isBigEnough=GrowCapacity(aDest,aDest.mLength+theLength,anAgent);
|
||||
}
|
||||
|
||||
//now append new chars, starting at offset
|
||||
(*gCopyChars[aSource.mCharSize][aDest.mCharSize])(aDest.mStr,aDest.mLength,aSource.mStr,anOffset,theLength);
|
||||
if(isBigEnough) {
|
||||
//now append new chars, starting at offset
|
||||
(*gCopyChars[aSource.mCharSize][aDest.mCharSize])(aDest.mStr,aDest.mLength,aSource.mStr,anOffset,theLength);
|
||||
|
||||
aDest.mLength+=theLength;
|
||||
AddNullTerminator(aDest);
|
||||
aDest.mLength+=theLength;
|
||||
AddNullTerminator(aDest);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -213,24 +224,26 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin
|
|||
nsStr::Initialize(theTempStr,aDest.mCharSize);
|
||||
|
||||
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
|
||||
EnsureCapacity(theTempStr,aDest.mLength+theLength,theAgent); //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(aDestOffset) {
|
||||
Append(theTempStr,aDest,0,aDestOffset,theAgent); //first copy leftmost data...
|
||||
}
|
||||
if(isBigEnough) {
|
||||
if(aDestOffset) {
|
||||
Append(theTempStr,aDest,0,aDestOffset,theAgent); //first copy leftmost data...
|
||||
}
|
||||
|
||||
Append(theTempStr,aSource,0,aSource.mLength,theAgent); //next copy inserted (new) data
|
||||
Append(theTempStr,aSource,0,aSource.mLength,theAgent); //next copy inserted (new) data
|
||||
|
||||
PRUint32 theRemains=aDest.mLength-aDestOffset;
|
||||
if(theRemains) {
|
||||
Append(theTempStr,aDest,aDestOffset,theRemains,theAgent); //next copy rightmost data
|
||||
}
|
||||
PRUint32 theRemains=aDest.mLength-aDestOffset;
|
||||
if(theRemains) {
|
||||
Append(theTempStr,aDest,aDestOffset,theRemains,theAgent); //next copy rightmost data
|
||||
}
|
||||
|
||||
theAgent->Free(aDest);
|
||||
aDest.mStr = theTempStr.mStr;
|
||||
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
|
||||
aDest.mCapacity=theTempStr.mCapacity;
|
||||
aDest.mOwnsBuffer=theTempStr.mOwnsBuffer;
|
||||
theAgent->Free(aDest);
|
||||
aDest.mStr = theTempStr.mStr;
|
||||
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
|
||||
aDest.mCapacity=theTempStr.mCapacity;
|
||||
aDest.mOwnsBuffer=theTempStr.mOwnsBuffer;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -365,6 +378,21 @@ void nsStr::CompressSet(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,P
|
|||
aDest.mLength=aNewLen;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess1/7/99
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void nsStr::StripChars(nsStr& aDest,const char* aSet){
|
||||
if((0<aDest.mLength) && (aSet)) {
|
||||
PRUint32 aNewLen=gStripChars[aDest.mCharSize](aDest.mStr,aDest.mLength,aSet);
|
||||
aDest.mLength=aNewLen;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Searching methods...
|
||||
**************************************************************/
|
||||
|
|
|
@ -238,8 +238,8 @@ struct NS_COM nsStr {
|
|||
* @param anAgent is the allocator to be used on the nsStr
|
||||
* @return
|
||||
*/
|
||||
static void EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0);
|
||||
static void GrowCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0);
|
||||
static PRBool EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0);
|
||||
static PRBool GrowCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0);
|
||||
|
||||
/**
|
||||
* These methods are used to append content to the given nsStr
|
||||
|
@ -336,6 +336,18 @@ struct NS_COM nsStr {
|
|||
*/
|
||||
static void CompressSet(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing);
|
||||
|
||||
/**
|
||||
* This method removes all occurances of chars in given set from aDest
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the buffer to be manipulated
|
||||
* @param aSet tells us which chars to compress from given buffer
|
||||
* @param aChar is the replacement char
|
||||
* @param aEliminateLeading tells us whether to strip chars from the start of the buffer
|
||||
* @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
|
||||
*/
|
||||
static void StripChars(nsStr& aDest,const char* aSet);
|
||||
|
||||
/**
|
||||
* This method compares the data bewteen two nsStr's
|
||||
*
|
||||
|
@ -445,8 +457,12 @@ public:
|
|||
PRUint32 theSize=(theNewCapacity<<aDest.mCharSize);
|
||||
aDest.mStr = (char*)nsAllocator::Alloc(theSize);
|
||||
|
||||
aDest.mOwnsBuffer=1;
|
||||
return PR_TRUE;
|
||||
PRBool result=PR_FALSE;
|
||||
if(aDest.mStr) {
|
||||
aDest.mOwnsBuffer=1;
|
||||
result=PR_TRUE;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual PRBool Free(nsStr& aDest){
|
||||
|
@ -462,10 +478,23 @@ public:
|
|||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -355,13 +355,9 @@ void nsCString::ToUpperCase(nsCString& aString) const {
|
|||
* @param aChar -- char to be stripped
|
||||
* @return *this
|
||||
*/
|
||||
nsCString& nsCString::StripChar(PRUnichar aChar){
|
||||
|
||||
PRInt32 theIndex=FindChar(aChar,PR_FALSE,0);
|
||||
while(kNotFound<theIndex) {
|
||||
Cut(theIndex,1);
|
||||
theIndex=FindChar(aChar,PR_FALSE,theIndex);
|
||||
}
|
||||
nsCString& nsCString::StripChar(char aChar){
|
||||
char aSet[2]={aChar,0};
|
||||
nsStr::StripChars(*this,aSet);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -374,13 +370,7 @@ nsCString& nsCString::StripChar(PRUnichar aChar){
|
|||
* @return *this
|
||||
*/
|
||||
nsCString& nsCString::StripChars(const char* aSet){
|
||||
if(aSet){
|
||||
PRInt32 theIndex=FindCharInSet(aSet,0);
|
||||
while(kNotFound<theIndex) {
|
||||
Cut(theIndex,1);
|
||||
theIndex=FindCharInSet(aSet,theIndex);
|
||||
}
|
||||
}
|
||||
nsStr::StripChars(*this,aSet);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -952,43 +942,34 @@ nsCString& nsCString::Append(char aChar) {
|
|||
* @param aRadix:
|
||||
* @return
|
||||
*/
|
||||
nsCString& nsCString::Append(PRInt32 aInteger,PRInt32 aRadix) {
|
||||
nsCString& nsCString::Append(PRInt32 anInteger,PRInt32 aRadix) {
|
||||
|
||||
#if 0
|
||||
char buf[128]={0,0};
|
||||
char* buffer=buf;
|
||||
PRUint32 theInt=(PRUint32)anInteger;
|
||||
|
||||
ldiv_t r; /* result of val / base */
|
||||
if (aRadix> 36 || aRadix< 2) { /* no conversion if wrong base */
|
||||
return *this;
|
||||
char buf[]={'0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
|
||||
PRInt32 radices[] = {1000000000,268435456};
|
||||
PRInt32 mask1=radices[16==aRadix];
|
||||
|
||||
PRInt32 charpos=0;
|
||||
if(anInteger<0) {
|
||||
theInt*=-1;
|
||||
if(10==aRadix) {
|
||||
buf[charpos++]='-';
|
||||
}
|
||||
else theInt=(int)~(theInt-1);
|
||||
}
|
||||
|
||||
if (aInteger < 0)
|
||||
*buffer++ = '-';
|
||||
r = ldiv (labs(aInteger), aRadix);
|
||||
|
||||
/* output digits of val/base first */
|
||||
if (r.quot > 0)
|
||||
buffer = ltoa ( r.quot, buf, aRadix);
|
||||
|
||||
/* output last digit */
|
||||
int len=strlen(buffer);
|
||||
buf[len] = "0123456789abcdefghijklmnopqrstuvwxyz"[(int)r.rem];
|
||||
buf[len+1] =0;
|
||||
|
||||
#endif
|
||||
|
||||
char* fmt = "%d";
|
||||
if (8 == aRadix) {
|
||||
fmt = "%o";
|
||||
} else if (16 == aRadix) {
|
||||
fmt = "%x";
|
||||
PRBool isfirst=true;
|
||||
while(mask1>=1) {
|
||||
PRInt32 div=theInt/mask1;
|
||||
if((div) || (!isfirst)) {
|
||||
buf[charpos++]="0123456789abcdef"[div];
|
||||
isfirst=false;
|
||||
}
|
||||
theInt-=div*mask1;
|
||||
mask1/=aRadix;
|
||||
}
|
||||
char buf[40];
|
||||
// *** XX UNCOMMENT THIS LINE
|
||||
//PR_snprintf(buf, sizeof(buf), fmt, aInteger);
|
||||
sprintf(buf,fmt,aInteger);
|
||||
|
||||
return Append(buf);
|
||||
}
|
||||
|
||||
|
|
|
@ -234,7 +234,7 @@ void ToUpperCase(nsCString& aString) const;
|
|||
* @return *this
|
||||
*/
|
||||
nsCString& StripChars(const char* aSet);
|
||||
nsCString& StripChar(PRUnichar aChar);
|
||||
nsCString& StripChar(char aChar);
|
||||
|
||||
/**
|
||||
* This method strips whitespace throughout the string
|
||||
|
|
|
@ -386,13 +386,9 @@ void nsString::ToUpperCase(nsString& aString) const {
|
|||
* @param aChar -- char to be stripped
|
||||
* @return *this
|
||||
*/
|
||||
nsString& nsString::StripChar(PRUnichar aChar){
|
||||
|
||||
PRInt32 theIndex=FindChar(aChar,PR_FALSE,0);
|
||||
while(kNotFound<theIndex) {
|
||||
Cut(theIndex,1);
|
||||
theIndex=FindChar(aChar,PR_FALSE,theIndex);
|
||||
}
|
||||
nsString& nsString::StripChar(char aChar){
|
||||
char aSet[2]={aChar,0};
|
||||
nsStr::StripChars(*this,aSet);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -405,14 +401,7 @@ nsString& nsString::StripChar(PRUnichar aChar){
|
|||
* @return *this
|
||||
*/
|
||||
nsString& nsString::StripChars(const char* aSet){
|
||||
|
||||
if(aSet){
|
||||
PRInt32 theIndex=FindCharInSet(aSet,0);
|
||||
while(kNotFound<theIndex) {
|
||||
Cut(theIndex,1);
|
||||
theIndex=FindCharInSet(aSet,theIndex);
|
||||
}
|
||||
}
|
||||
nsStr::StripChars(*this,aSet);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -424,8 +413,7 @@ nsString& nsString::StripChars(const char* aSet){
|
|||
* @return this
|
||||
*/
|
||||
nsString& nsString::StripWhitespace() {
|
||||
StripChars(kWhitespace);
|
||||
return *this;
|
||||
return StripChars(kWhitespace);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1124,43 +1112,34 @@ nsString& nsString::Append(PRUnichar aChar) {
|
|||
* @param aRadix:
|
||||
* @return
|
||||
*/
|
||||
nsString& nsString::Append(PRInt32 aInteger,PRInt32 aRadix) {
|
||||
nsString& nsString::Append(PRInt32 anInteger,PRInt32 aRadix) {
|
||||
|
||||
#if 0
|
||||
char buf[128]={0,0};
|
||||
char* buffer=buf;
|
||||
PRUint32 theInt=(PRUint32)anInteger;
|
||||
|
||||
ldiv_t r; /* result of val / base */
|
||||
if (aRadix> 36 || aRadix< 2) { /* no conversion if wrong base */
|
||||
return *this;
|
||||
char buf[]={'0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
|
||||
PRInt32 radices[] = {1000000000,268435456};
|
||||
PRInt32 mask1=radices[16==aRadix];
|
||||
|
||||
PRInt32 charpos=0;
|
||||
if(anInteger<0) {
|
||||
theInt*=-1;
|
||||
if(10==aRadix) {
|
||||
buf[charpos++]='-';
|
||||
}
|
||||
else theInt=(int)~(theInt-1);
|
||||
}
|
||||
|
||||
if (aInteger < 0)
|
||||
*buffer++ = '-';
|
||||
r = ldiv (labs(aInteger), aRadix);
|
||||
|
||||
/* output digits of val/base first */
|
||||
if (r.quot > 0)
|
||||
buffer = ltoa ( r.quot, buf, aRadix);
|
||||
|
||||
/* output last digit */
|
||||
int len=strlen(buffer);
|
||||
buf[len] = "0123456789abcdefghijklmnopqrstuvwxyz"[(int)r.rem];
|
||||
buf[len+1] =0;
|
||||
|
||||
#endif
|
||||
|
||||
char* fmt = "%d";
|
||||
if (8 == aRadix) {
|
||||
fmt = "%o";
|
||||
} else if (16 == aRadix) {
|
||||
fmt = "%x";
|
||||
PRBool isfirst=true;
|
||||
while(mask1>=1) {
|
||||
PRInt32 div=theInt/mask1;
|
||||
if((div) || (!isfirst)) {
|
||||
buf[charpos++]="0123456789abcdef"[div];
|
||||
isfirst=false;
|
||||
}
|
||||
theInt-=div*mask1;
|
||||
mask1/=aRadix;
|
||||
}
|
||||
char buf[40];
|
||||
// *** XX UNCOMMENT THIS LINE
|
||||
//PR_snprintf(buf, sizeof(buf), fmt, aInteger);
|
||||
sprintf(buf,fmt,aInteger);
|
||||
|
||||
return Append(buf);
|
||||
}
|
||||
|
||||
|
|
|
@ -269,7 +269,7 @@ void ToUpperCase(nsString& aString) const;
|
|||
* @return *this
|
||||
*/
|
||||
nsString& StripChars(const char* aSet);
|
||||
nsString& StripChar(PRUnichar aChar);
|
||||
nsString& StripChar(char aChar);
|
||||
|
||||
/**
|
||||
* This method strips whitespace throughout the string
|
||||
|
|
|
@ -108,12 +108,15 @@ void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) {
|
|||
* @param aNewLength -- new capacity of string in charSize units
|
||||
* @return void
|
||||
*/
|
||||
void nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent) {
|
||||
PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent) {
|
||||
PRBool result=PR_TRUE;
|
||||
if(aNewLength>aString.mCapacity) {
|
||||
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
|
||||
theAgent->Realloc(aString,aNewLength);
|
||||
AddNullTerminator(aString);
|
||||
result=theAgent->Realloc(aString,aNewLength);
|
||||
if(aString.mStr)
|
||||
AddNullTerminator(aString);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -123,24 +126,28 @@ void nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* an
|
|||
* @param aNewLength -- new capacity of string in charSize units
|
||||
* @return void
|
||||
*/
|
||||
void nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAgent) {
|
||||
PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAgent) {
|
||||
PRBool result=PR_TRUE;
|
||||
if(aNewLength>aDest.mCapacity) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,aDest.mCharSize);
|
||||
|
||||
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
|
||||
EnsureCapacity(theTempStr,aNewLength,theAgent);
|
||||
|
||||
if(aDest.mLength) {
|
||||
Append(theTempStr,aDest,0,aDest.mLength,theAgent);
|
||||
}
|
||||
theAgent->Free(aDest);
|
||||
aDest.mStr = theTempStr.mStr;
|
||||
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
|
||||
aDest.mLength=theTempStr.mLength;
|
||||
aDest.mCapacity=theTempStr.mCapacity;
|
||||
aDest.mOwnsBuffer=theTempStr.mOwnsBuffer;
|
||||
result=EnsureCapacity(theTempStr,aNewLength,theAgent);
|
||||
if(result) {
|
||||
if(aDest.mLength) {
|
||||
Append(theTempStr,aDest,0,aDest.mLength,theAgent);
|
||||
}
|
||||
theAgent->Free(aDest);
|
||||
aDest.mStr = theTempStr.mStr;
|
||||
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
|
||||
aDest.mLength=theTempStr.mLength;
|
||||
aDest.mCapacity=theTempStr.mCapacity;
|
||||
aDest.mOwnsBuffer=theTempStr.mOwnsBuffer;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -170,15 +177,19 @@ void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 a
|
|||
PRUint32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
|
||||
PRUint32 theLength=(anOffset+theRealLen<aSource.mLength) ? theRealLen : (aSource.mLength-anOffset);
|
||||
if(0<theLength){
|
||||
|
||||
PRBool isBigEnough=PR_TRUE;
|
||||
if(aDest.mLength+theLength > aDest.mCapacity) {
|
||||
GrowCapacity(aDest,aDest.mLength+theLength,anAgent);
|
||||
isBigEnough=GrowCapacity(aDest,aDest.mLength+theLength,anAgent);
|
||||
}
|
||||
|
||||
//now append new chars, starting at offset
|
||||
(*gCopyChars[aSource.mCharSize][aDest.mCharSize])(aDest.mStr,aDest.mLength,aSource.mStr,anOffset,theLength);
|
||||
if(isBigEnough) {
|
||||
//now append new chars, starting at offset
|
||||
(*gCopyChars[aSource.mCharSize][aDest.mCharSize])(aDest.mStr,aDest.mLength,aSource.mStr,anOffset,theLength);
|
||||
|
||||
aDest.mLength+=theLength;
|
||||
AddNullTerminator(aDest);
|
||||
aDest.mLength+=theLength;
|
||||
AddNullTerminator(aDest);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -213,24 +224,26 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin
|
|||
nsStr::Initialize(theTempStr,aDest.mCharSize);
|
||||
|
||||
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
|
||||
EnsureCapacity(theTempStr,aDest.mLength+theLength,theAgent); //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(aDestOffset) {
|
||||
Append(theTempStr,aDest,0,aDestOffset,theAgent); //first copy leftmost data...
|
||||
}
|
||||
if(isBigEnough) {
|
||||
if(aDestOffset) {
|
||||
Append(theTempStr,aDest,0,aDestOffset,theAgent); //first copy leftmost data...
|
||||
}
|
||||
|
||||
Append(theTempStr,aSource,0,aSource.mLength,theAgent); //next copy inserted (new) data
|
||||
Append(theTempStr,aSource,0,aSource.mLength,theAgent); //next copy inserted (new) data
|
||||
|
||||
PRUint32 theRemains=aDest.mLength-aDestOffset;
|
||||
if(theRemains) {
|
||||
Append(theTempStr,aDest,aDestOffset,theRemains,theAgent); //next copy rightmost data
|
||||
}
|
||||
PRUint32 theRemains=aDest.mLength-aDestOffset;
|
||||
if(theRemains) {
|
||||
Append(theTempStr,aDest,aDestOffset,theRemains,theAgent); //next copy rightmost data
|
||||
}
|
||||
|
||||
theAgent->Free(aDest);
|
||||
aDest.mStr = theTempStr.mStr;
|
||||
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
|
||||
aDest.mCapacity=theTempStr.mCapacity;
|
||||
aDest.mOwnsBuffer=theTempStr.mOwnsBuffer;
|
||||
theAgent->Free(aDest);
|
||||
aDest.mStr = theTempStr.mStr;
|
||||
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
|
||||
aDest.mCapacity=theTempStr.mCapacity;
|
||||
aDest.mOwnsBuffer=theTempStr.mOwnsBuffer;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -365,6 +378,21 @@ void nsStr::CompressSet(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,P
|
|||
aDest.mLength=aNewLen;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess1/7/99
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void nsStr::StripChars(nsStr& aDest,const char* aSet){
|
||||
if((0<aDest.mLength) && (aSet)) {
|
||||
PRUint32 aNewLen=gStripChars[aDest.mCharSize](aDest.mStr,aDest.mLength,aSet);
|
||||
aDest.mLength=aNewLen;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Searching methods...
|
||||
**************************************************************/
|
||||
|
|
|
@ -238,8 +238,8 @@ struct NS_COM nsStr {
|
|||
* @param anAgent is the allocator to be used on the nsStr
|
||||
* @return
|
||||
*/
|
||||
static void EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0);
|
||||
static void GrowCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0);
|
||||
static PRBool EnsureCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0);
|
||||
static PRBool GrowCapacity(nsStr& aString,PRUint32 aNewLength,nsIMemoryAgent* anAgent=0);
|
||||
|
||||
/**
|
||||
* These methods are used to append content to the given nsStr
|
||||
|
@ -336,6 +336,18 @@ struct NS_COM nsStr {
|
|||
*/
|
||||
static void CompressSet(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing);
|
||||
|
||||
/**
|
||||
* This method removes all occurances of chars in given set from aDest
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the buffer to be manipulated
|
||||
* @param aSet tells us which chars to compress from given buffer
|
||||
* @param aChar is the replacement char
|
||||
* @param aEliminateLeading tells us whether to strip chars from the start of the buffer
|
||||
* @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
|
||||
*/
|
||||
static void StripChars(nsStr& aDest,const char* aSet);
|
||||
|
||||
/**
|
||||
* This method compares the data bewteen two nsStr's
|
||||
*
|
||||
|
@ -445,8 +457,12 @@ public:
|
|||
PRUint32 theSize=(theNewCapacity<<aDest.mCharSize);
|
||||
aDest.mStr = (char*)nsAllocator::Alloc(theSize);
|
||||
|
||||
aDest.mOwnsBuffer=1;
|
||||
return PR_TRUE;
|
||||
PRBool result=PR_FALSE;
|
||||
if(aDest.mStr) {
|
||||
aDest.mOwnsBuffer=1;
|
||||
result=PR_TRUE;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual PRBool Free(nsStr& aDest){
|
||||
|
@ -462,10 +478,23 @@ public:
|
|||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -355,13 +355,9 @@ void nsCString::ToUpperCase(nsCString& aString) const {
|
|||
* @param aChar -- char to be stripped
|
||||
* @return *this
|
||||
*/
|
||||
nsCString& nsCString::StripChar(PRUnichar aChar){
|
||||
|
||||
PRInt32 theIndex=FindChar(aChar,PR_FALSE,0);
|
||||
while(kNotFound<theIndex) {
|
||||
Cut(theIndex,1);
|
||||
theIndex=FindChar(aChar,PR_FALSE,theIndex);
|
||||
}
|
||||
nsCString& nsCString::StripChar(char aChar){
|
||||
char aSet[2]={aChar,0};
|
||||
nsStr::StripChars(*this,aSet);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -374,13 +370,7 @@ nsCString& nsCString::StripChar(PRUnichar aChar){
|
|||
* @return *this
|
||||
*/
|
||||
nsCString& nsCString::StripChars(const char* aSet){
|
||||
if(aSet){
|
||||
PRInt32 theIndex=FindCharInSet(aSet,0);
|
||||
while(kNotFound<theIndex) {
|
||||
Cut(theIndex,1);
|
||||
theIndex=FindCharInSet(aSet,theIndex);
|
||||
}
|
||||
}
|
||||
nsStr::StripChars(*this,aSet);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -952,43 +942,34 @@ nsCString& nsCString::Append(char aChar) {
|
|||
* @param aRadix:
|
||||
* @return
|
||||
*/
|
||||
nsCString& nsCString::Append(PRInt32 aInteger,PRInt32 aRadix) {
|
||||
nsCString& nsCString::Append(PRInt32 anInteger,PRInt32 aRadix) {
|
||||
|
||||
#if 0
|
||||
char buf[128]={0,0};
|
||||
char* buffer=buf;
|
||||
PRUint32 theInt=(PRUint32)anInteger;
|
||||
|
||||
ldiv_t r; /* result of val / base */
|
||||
if (aRadix> 36 || aRadix< 2) { /* no conversion if wrong base */
|
||||
return *this;
|
||||
char buf[]={'0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
|
||||
PRInt32 radices[] = {1000000000,268435456};
|
||||
PRInt32 mask1=radices[16==aRadix];
|
||||
|
||||
PRInt32 charpos=0;
|
||||
if(anInteger<0) {
|
||||
theInt*=-1;
|
||||
if(10==aRadix) {
|
||||
buf[charpos++]='-';
|
||||
}
|
||||
else theInt=(int)~(theInt-1);
|
||||
}
|
||||
|
||||
if (aInteger < 0)
|
||||
*buffer++ = '-';
|
||||
r = ldiv (labs(aInteger), aRadix);
|
||||
|
||||
/* output digits of val/base first */
|
||||
if (r.quot > 0)
|
||||
buffer = ltoa ( r.quot, buf, aRadix);
|
||||
|
||||
/* output last digit */
|
||||
int len=strlen(buffer);
|
||||
buf[len] = "0123456789abcdefghijklmnopqrstuvwxyz"[(int)r.rem];
|
||||
buf[len+1] =0;
|
||||
|
||||
#endif
|
||||
|
||||
char* fmt = "%d";
|
||||
if (8 == aRadix) {
|
||||
fmt = "%o";
|
||||
} else if (16 == aRadix) {
|
||||
fmt = "%x";
|
||||
PRBool isfirst=true;
|
||||
while(mask1>=1) {
|
||||
PRInt32 div=theInt/mask1;
|
||||
if((div) || (!isfirst)) {
|
||||
buf[charpos++]="0123456789abcdef"[div];
|
||||
isfirst=false;
|
||||
}
|
||||
theInt-=div*mask1;
|
||||
mask1/=aRadix;
|
||||
}
|
||||
char buf[40];
|
||||
// *** XX UNCOMMENT THIS LINE
|
||||
//PR_snprintf(buf, sizeof(buf), fmt, aInteger);
|
||||
sprintf(buf,fmt,aInteger);
|
||||
|
||||
return Append(buf);
|
||||
}
|
||||
|
||||
|
|
|
@ -234,7 +234,7 @@ void ToUpperCase(nsCString& aString) const;
|
|||
* @return *this
|
||||
*/
|
||||
nsCString& StripChars(const char* aSet);
|
||||
nsCString& StripChar(PRUnichar aChar);
|
||||
nsCString& StripChar(char aChar);
|
||||
|
||||
/**
|
||||
* This method strips whitespace throughout the string
|
||||
|
|
|
@ -386,13 +386,9 @@ void nsString::ToUpperCase(nsString& aString) const {
|
|||
* @param aChar -- char to be stripped
|
||||
* @return *this
|
||||
*/
|
||||
nsString& nsString::StripChar(PRUnichar aChar){
|
||||
|
||||
PRInt32 theIndex=FindChar(aChar,PR_FALSE,0);
|
||||
while(kNotFound<theIndex) {
|
||||
Cut(theIndex,1);
|
||||
theIndex=FindChar(aChar,PR_FALSE,theIndex);
|
||||
}
|
||||
nsString& nsString::StripChar(char aChar){
|
||||
char aSet[2]={aChar,0};
|
||||
nsStr::StripChars(*this,aSet);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -405,14 +401,7 @@ nsString& nsString::StripChar(PRUnichar aChar){
|
|||
* @return *this
|
||||
*/
|
||||
nsString& nsString::StripChars(const char* aSet){
|
||||
|
||||
if(aSet){
|
||||
PRInt32 theIndex=FindCharInSet(aSet,0);
|
||||
while(kNotFound<theIndex) {
|
||||
Cut(theIndex,1);
|
||||
theIndex=FindCharInSet(aSet,theIndex);
|
||||
}
|
||||
}
|
||||
nsStr::StripChars(*this,aSet);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -424,8 +413,7 @@ nsString& nsString::StripChars(const char* aSet){
|
|||
* @return this
|
||||
*/
|
||||
nsString& nsString::StripWhitespace() {
|
||||
StripChars(kWhitespace);
|
||||
return *this;
|
||||
return StripChars(kWhitespace);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1124,43 +1112,34 @@ nsString& nsString::Append(PRUnichar aChar) {
|
|||
* @param aRadix:
|
||||
* @return
|
||||
*/
|
||||
nsString& nsString::Append(PRInt32 aInteger,PRInt32 aRadix) {
|
||||
nsString& nsString::Append(PRInt32 anInteger,PRInt32 aRadix) {
|
||||
|
||||
#if 0
|
||||
char buf[128]={0,0};
|
||||
char* buffer=buf;
|
||||
PRUint32 theInt=(PRUint32)anInteger;
|
||||
|
||||
ldiv_t r; /* result of val / base */
|
||||
if (aRadix> 36 || aRadix< 2) { /* no conversion if wrong base */
|
||||
return *this;
|
||||
char buf[]={'0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
|
||||
PRInt32 radices[] = {1000000000,268435456};
|
||||
PRInt32 mask1=radices[16==aRadix];
|
||||
|
||||
PRInt32 charpos=0;
|
||||
if(anInteger<0) {
|
||||
theInt*=-1;
|
||||
if(10==aRadix) {
|
||||
buf[charpos++]='-';
|
||||
}
|
||||
else theInt=(int)~(theInt-1);
|
||||
}
|
||||
|
||||
if (aInteger < 0)
|
||||
*buffer++ = '-';
|
||||
r = ldiv (labs(aInteger), aRadix);
|
||||
|
||||
/* output digits of val/base first */
|
||||
if (r.quot > 0)
|
||||
buffer = ltoa ( r.quot, buf, aRadix);
|
||||
|
||||
/* output last digit */
|
||||
int len=strlen(buffer);
|
||||
buf[len] = "0123456789abcdefghijklmnopqrstuvwxyz"[(int)r.rem];
|
||||
buf[len+1] =0;
|
||||
|
||||
#endif
|
||||
|
||||
char* fmt = "%d";
|
||||
if (8 == aRadix) {
|
||||
fmt = "%o";
|
||||
} else if (16 == aRadix) {
|
||||
fmt = "%x";
|
||||
PRBool isfirst=true;
|
||||
while(mask1>=1) {
|
||||
PRInt32 div=theInt/mask1;
|
||||
if((div) || (!isfirst)) {
|
||||
buf[charpos++]="0123456789abcdef"[div];
|
||||
isfirst=false;
|
||||
}
|
||||
theInt-=div*mask1;
|
||||
mask1/=aRadix;
|
||||
}
|
||||
char buf[40];
|
||||
// *** XX UNCOMMENT THIS LINE
|
||||
//PR_snprintf(buf, sizeof(buf), fmt, aInteger);
|
||||
sprintf(buf,fmt,aInteger);
|
||||
|
||||
return Append(buf);
|
||||
}
|
||||
|
||||
|
|
|
@ -269,7 +269,7 @@ void ToUpperCase(nsString& aString) const;
|
|||
* @return *this
|
||||
*/
|
||||
nsString& StripChars(const char* aSet);
|
||||
nsString& StripChar(PRUnichar aChar);
|
||||
nsString& StripChar(char aChar);
|
||||
|
||||
/**
|
||||
* This method strips whitespace throughout the string
|
||||
|
|
Загрузка…
Ссылка в новой задаче