зеркало из https://github.com/mozilla/pjs.git
added recycler to nsString2
This commit is contained in:
Родитель
8a4ca6d27e
Коммит
2ba72879d7
|
@ -66,12 +66,12 @@ char* GetSharedEmptyBuffer() {
|
|||
* @return
|
||||
*/
|
||||
void nsStr::Initialize(nsStr& aDest,eCharSize aCharSize) {
|
||||
aDest.mStr.mCharBuf=GetSharedEmptyBuffer();
|
||||
aDest.mStr=GetSharedEmptyBuffer();
|
||||
aDest.mLength=0;
|
||||
aDest.mCapacity=0;
|
||||
aDest.mMultibyte=aCharSize;
|
||||
aDest.mOwnsBuffer=0;
|
||||
NS_ASSERTION(aDest.mStr.mCharBuf[0]==0,kFoolMsg);
|
||||
NS_ASSERTION(aDest.mStr[0]==0,kFoolMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -97,7 +97,7 @@ nsIMemoryAgent* GetDefaultAgent(void){
|
|||
* @return
|
||||
*/
|
||||
void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) {
|
||||
if((aDest.mStr.mCharBuf) && (aDest.mStr.mCharBuf!=GetSharedEmptyBuffer())) {
|
||||
if((aDest.mStr) && (aDest.mStr!=GetSharedEmptyBuffer())) {
|
||||
if(!anAgent)
|
||||
anAgent=GetDefaultAgent();
|
||||
|
||||
|
@ -119,7 +119,7 @@ void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) {
|
|||
PRUnichar nsStr::GetCharAt(const nsStr& aDest,PRUint32 anIndex) {
|
||||
PRUnichar result=0;
|
||||
if((anIndex>=0) && (anIndex<aDest.mLength)) {
|
||||
result=(eTwoByte==aDest.mMultibyte) ? aDest.mStr.mUnicharBuf[anIndex] : aDest.mStr.mCharBuf[anIndex];
|
||||
result=(eTwoByte==aDest.mMultibyte) ? aDest.mUStr[anIndex] : aDest.mStr[anIndex];
|
||||
}//if
|
||||
return result;
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ void nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAgen
|
|||
}
|
||||
theAgent->Free(aDest);
|
||||
aDest.mStr = theTempStr.mStr;
|
||||
theTempStr.mStr.mCharBuf=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.mCapacity=theTempStr.mCapacity;
|
||||
aDest.mOwnsBuffer=theTempStr.mOwnsBuffer;
|
||||
|
@ -198,7 +198,7 @@ void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 a
|
|||
}
|
||||
|
||||
//now append new chars, starting at offset
|
||||
(*gCopyChars[aSource.mMultibyte][aDest.mMultibyte])(aDest.mStr.mCharBuf,aDest.mLength,aSource.mStr.mCharBuf,anOffset,theLength);
|
||||
(*gCopyChars[aSource.mMultibyte][aDest.mMultibyte])(aDest.mStr,aDest.mLength,aSource.mStr,anOffset,theLength);
|
||||
|
||||
aDest.mLength+=theLength;
|
||||
AddNullTerminator(aDest);
|
||||
|
@ -235,10 +235,10 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin
|
|||
GrowCapacity(aDest,aDest.mLength+theLength,anAgent);
|
||||
|
||||
//shift the chars right by theDelta...
|
||||
(*gShiftChars[aDest.mMultibyte][PR_TRUE])(aDest.mStr.mCharBuf,aDest.mLength,aDestOffset,theLength);
|
||||
(*gShiftChars[aDest.mMultibyte][PR_TRUE])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
|
||||
|
||||
//now insert new chars, starting at offset
|
||||
(*gCopyChars[aSource.mMultibyte][aDest.mMultibyte])(aDest.mStr.mCharBuf,aDestOffset,aSource.mStr.mCharBuf,aSrcOffset,theLength);
|
||||
(*gCopyChars[aSource.mMultibyte][aDest.mMultibyte])(aDest.mStr,aDestOffset,aSource.mStr,aSrcOffset,theLength);
|
||||
|
||||
//finally, make sure to update the string length...
|
||||
aDest.mLength+=theLength;
|
||||
|
@ -271,7 +271,7 @@ void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,nsIMemoryAge
|
|||
|
||||
//if you're here, it means we're cutting chars out of the middle of the string...
|
||||
//so shift the chars left by theLength...
|
||||
(*gShiftChars[aDest.mMultibyte][PR_FALSE])(aDest.mStr.mCharBuf,aDest.mLength,aDestOffset,theLength);
|
||||
(*gShiftChars[aDest.mMultibyte][PR_FALSE])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
|
||||
aDest.mLength-=theLength;
|
||||
}
|
||||
else Truncate(aDest,aDestOffset,anAgent);
|
||||
|
@ -301,7 +301,7 @@ void nsStr::Truncate(nsStr& aDest,PRUint32 aDestOffset,nsIMemoryAgent* anAgent){
|
|||
*/
|
||||
void nsStr::ChangeCase(nsStr& aDest,PRBool aToUpper) {
|
||||
// somehow UnicharUtil return failed, fallback to the old ascii only code
|
||||
gCaseConverters[aDest.mMultibyte](aDest.mStr.mCharBuf,aDest.mLength,aToUpper);
|
||||
gCaseConverters[aDest.mMultibyte](aDest.mStr,aDest.mLength,aToUpper);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -311,7 +311,7 @@ void nsStr::ChangeCase(nsStr& aDest,PRBool aToUpper) {
|
|||
* @return
|
||||
*/
|
||||
void nsStr::StripChars(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,const char* aCharSet){
|
||||
PRUint32 aNewLen=gStripChars[aDest.mMultibyte](aDest.mStr.mCharBuf,aDestOffset,aCount,aCharSet);
|
||||
PRUint32 aNewLen=gStripChars[aDest.mMultibyte](aDest.mStr,aDestOffset,aCount,aCharSet);
|
||||
aDest.mLength=aNewLen;
|
||||
}
|
||||
|
||||
|
@ -323,7 +323,7 @@ void nsStr::StripChars(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,const ch
|
|||
* @return
|
||||
*/
|
||||
void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
||||
PRUint32 aNewLen=gTrimChars[aDest.mMultibyte](aDest.mStr.mCharBuf,aDest.mLength,aSet,aEliminateLeading,aEliminateTrailing);
|
||||
PRUint32 aNewLen=gTrimChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,aSet,aEliminateLeading,aEliminateTrailing);
|
||||
aDest.mLength=aNewLen;
|
||||
}
|
||||
|
||||
|
@ -334,7 +334,7 @@ void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool a
|
|||
* @return
|
||||
*/
|
||||
void nsStr::CompressSet(nsStr& aDest,const char* aSet,PRUint32 aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
||||
PRUint32 aNewLen=gCompressChars[aDest.mMultibyte](aDest.mStr.mCharBuf,aDest.mLength,aSet,aChar,aEliminateLeading,aEliminateTrailing);
|
||||
PRUint32 aNewLen=gCompressChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,aSet,aChar,aEliminateLeading,aEliminateTrailing);
|
||||
aDest.mLength=aNewLen;
|
||||
}
|
||||
|
||||
|
@ -385,7 +385,7 @@ PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnor
|
|||
* @return
|
||||
*/
|
||||
PRInt32 nsStr::FindChar(const nsStr& aDest,const PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gFindChars[aDest.mMultibyte](aDest.mStr.mCharBuf,aDest.mLength,0,aChar,aIgnoreCase);
|
||||
PRInt32 result=gFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,0,aChar,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -403,7 +403,7 @@ PRInt32 nsStr::FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnore
|
|||
|
||||
while(++index<aDest.mLength) {
|
||||
PRUnichar theChar=GetCharAt(aDest,index);
|
||||
thePos=gFindChars[aSet.mMultibyte](aSet.mStr.mCharBuf,aSet.mLength,0,theChar,aIgnoreCase);
|
||||
thePos=gFindChars[aSet.mMultibyte](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase);
|
||||
if(kNotFound!=thePos)
|
||||
return index;
|
||||
} //while
|
||||
|
@ -460,7 +460,7 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgno
|
|||
* @return
|
||||
*/
|
||||
PRInt32 nsStr::RFindChar(const nsStr& aDest,const PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gRFindChars[aDest.mMultibyte](aDest.mStr.mCharBuf,aDest.mLength,0,aChar,aIgnoreCase);
|
||||
PRInt32 result=gRFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,0,aChar,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -477,7 +477,7 @@ PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnor
|
|||
|
||||
while(--offset>=0) {
|
||||
PRUnichar theChar=GetCharAt(aDest,offset);
|
||||
thePos=gRFindChars[aSet.mMultibyte](aSet.mStr.mCharBuf,aSet.mLength,0,theChar,aIgnoreCase);
|
||||
thePos=gRFindChars[aSet.mMultibyte](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase);
|
||||
if(kNotFound!=thePos)
|
||||
return offset;
|
||||
} //while
|
||||
|
@ -503,7 +503,7 @@ PRInt32 nsStr::Compare(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PR
|
|||
}
|
||||
|
||||
int maxlen=(aSource.mLength<aDest.mLength) ? aDest.mLength : aSource.mLength;
|
||||
PRInt32 result=(*gCompare[aDest.mMultibyte][aSource.mMultibyte])(aDest.mStr.mCharBuf,aSource.mStr.mCharBuf,maxlen,aIgnoreCase);
|
||||
PRInt32 result=(*gCompare[aDest.mMultibyte][aSource.mMultibyte])(aDest.mStr,aSource.mStr,maxlen,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ union UStrPtr {
|
|||
|
||||
struct nsBufDescriptor {
|
||||
nsBufDescriptor(char* aBuffer,PRUint32 aBufferSize,eCharSize aCharSize,PRBool aOwnsBuffer) {
|
||||
mStr.mCharBuf=aBuffer;
|
||||
mStr=aBuffer;
|
||||
mMultibyte=aCharSize;
|
||||
mCapacity=(aBufferSize>>mMultibyte)-1;
|
||||
mOwnsBuffer=aOwnsBuffer;
|
||||
|
@ -73,7 +73,11 @@ struct nsBufDescriptor {
|
|||
PRUint32 mCapacity;
|
||||
PRBool mOwnsBuffer;
|
||||
eCharSize mMultibyte;
|
||||
UStrPtr mStr;
|
||||
// UStrPtr mStr;
|
||||
union {
|
||||
char* mStr;
|
||||
PRUnichar* mUStr;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
@ -265,7 +269,10 @@ struct nsStr {
|
|||
PRUint32 mCapacity: 30;
|
||||
PRUint32 mOwnsBuffer: 1;
|
||||
PRUint32 mUnused: 1;
|
||||
UStrPtr mStr;
|
||||
union {
|
||||
char* mStr;
|
||||
PRUnichar* mUStr;
|
||||
};
|
||||
};
|
||||
|
||||
/**************************************************************
|
||||
|
@ -296,8 +303,8 @@ inline void ToRange(PRUint32& aValue,PRUint32 aMin,PRUint32 aMax){
|
|||
|
||||
inline void AddNullTerminator(nsStr& aDest) {
|
||||
if(eTwoByte==aDest.mMultibyte)
|
||||
aDest.mStr.mUnicharBuf[aDest.mLength]=0;
|
||||
else aDest.mStr.mCharBuf[aDest.mLength]=0;
|
||||
aDest.mUStr[aDest.mLength]=0;
|
||||
else aDest.mStr[aDest.mLength]=0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
@ -331,17 +338,17 @@ public:
|
|||
|
||||
aDest.mCapacity=theNewCapacity++;
|
||||
size_t theSize=(theNewCapacity<<aDest.mMultibyte);
|
||||
aDest.mStr.mCharBuf=new char[theSize];
|
||||
aDest.mStr=new char[theSize];
|
||||
aDest.mOwnsBuffer=1;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
virtual PRBool Free(nsStr& aDest){
|
||||
if(aDest.mStr.mCharBuf){
|
||||
if(aDest.mStr){
|
||||
if(aDest.mOwnsBuffer){
|
||||
delete [] aDest.mStr.mCharBuf;
|
||||
delete [] aDest.mStr;
|
||||
}
|
||||
aDest.mStr.mCharBuf=0;
|
||||
aDest.mStr=0;
|
||||
aDest.mOwnsBuffer=0;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
|
|
@ -295,7 +295,7 @@ void nsString2::SetCapacity(PRUint32 aLength) {
|
|||
*/
|
||||
char* nsString2::GetBuffer(void) const {
|
||||
if(!mMultibyte)
|
||||
return mStr.mCharBuf;
|
||||
return mStr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -307,7 +307,7 @@ char* nsString2::GetBuffer(void) const {
|
|||
*/
|
||||
PRUnichar* nsString2::GetUnicode(void) const {
|
||||
if(mMultibyte)
|
||||
return (PRUnichar*)mStr.mUnicharBuf;
|
||||
return (PRUnichar*)mUStr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -334,8 +334,8 @@ PRBool nsString2::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
|
|||
PRBool result=PR_FALSE;
|
||||
if(anIndex<mLength){
|
||||
if(!mMultibyte)
|
||||
mStr.mCharBuf[anIndex]=char(aChar);
|
||||
else mStr.mUnicharBuf[anIndex]=aChar;
|
||||
mStr[anIndex]=char(aChar);
|
||||
else mUStr[anIndex]=aChar;
|
||||
result=PR_TRUE;
|
||||
}
|
||||
return result;
|
||||
|
@ -433,9 +433,9 @@ void nsString2::ToUCS2(PRUint32 aStartOffset){
|
|||
if(mMultibyte) {
|
||||
PRUint32 theIndex=0;
|
||||
for(theIndex=aStartOffset;theIndex<mLength;theIndex++){
|
||||
unsigned char ch = (unsigned char)mStr.mUnicharBuf[theIndex];
|
||||
if( 0x0080 == (0xFFE0 & (mStr.mUnicharBuf[theIndex])) ) // limit to only 0x0080 to 0x009F
|
||||
mStr.mUnicharBuf[theIndex]=gToUCS2[ch];
|
||||
unsigned char ch = (unsigned char)mUStr[theIndex];
|
||||
if( 0x0080 == (0xFFE0 & (mUStr[theIndex])) ) // limit to only 0x0080 to 0x009F
|
||||
mUStr[theIndex]=gToUCS2[ch];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -517,12 +517,12 @@ nsString2& nsString2::ReplaceChar(PRUnichar aSourceChar, PRUnichar aDestChar) {
|
|||
PRUint32 theIndex=0;
|
||||
for(theIndex=0;theIndex<mLength;theIndex++){
|
||||
if(mMultibyte) {
|
||||
if(mStr.mUnicharBuf[theIndex]==aSourceChar)
|
||||
mStr.mUnicharBuf[theIndex]=aDestChar;
|
||||
if(mUStr[theIndex]==aSourceChar)
|
||||
mUStr[theIndex]=aDestChar;
|
||||
}
|
||||
else {
|
||||
if(mStr.mCharBuf[theIndex]==aSourceChar)
|
||||
mStr.mCharBuf[theIndex]=(char)aDestChar;
|
||||
if(mStr[theIndex]==aSourceChar)
|
||||
mStr[theIndex]=(char)aDestChar;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
|
@ -596,8 +596,8 @@ nsString2* nsString2::ToNewString() const {
|
|||
*/
|
||||
char* nsString2::ToNewCString() const {
|
||||
nsString2 temp(*this,eOneByte);
|
||||
char* result=temp.mStr.mCharBuf;
|
||||
temp.mStr.mCharBuf=0;
|
||||
char* result=temp.mStr;
|
||||
temp.mStr=0;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -608,8 +608,8 @@ char* nsString2::ToNewCString() const {
|
|||
*/
|
||||
PRUnichar* nsString2::ToNewUnicode() const {
|
||||
nsString2 temp(*this,eTwoByte);
|
||||
PRUnichar* result=temp.mStr.mUnicharBuf;
|
||||
temp.mStr.mUnicharBuf=0;
|
||||
PRUnichar* result=temp.mUStr;
|
||||
temp.mUStr=0;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -623,7 +623,7 @@ char* nsString2::ToCString(char* aBuf, PRUint32 aBufLength) const{
|
|||
if(aBuf) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mStr.mCharBuf=aBuf;
|
||||
theTempStr.mStr=aBuf;
|
||||
theTempStr.mCapacity=aBufLength;
|
||||
nsStr::Assign(theTempStr,*this,0,mLength,mAgent);
|
||||
}
|
||||
|
@ -666,7 +666,7 @@ PRInt32 nsString2::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
|||
nsAutoString2 theString(*this,eOneByte);
|
||||
|
||||
PRInt32 decPt=theString.FindChar(theString,'.',PR_TRUE,0);
|
||||
char* cp = (kNotFound==decPt) ? theString.mStr.mCharBuf + theString.mLength-1 : theString.mStr.mCharBuf+decPt-1;
|
||||
char* cp = (kNotFound==decPt) ? theString.mStr + theString.mLength-1 : theString.mStr+decPt-1;
|
||||
char digit=0;
|
||||
char theChar;
|
||||
// PRInt32 theShift=0;
|
||||
|
@ -675,7 +675,7 @@ PRInt32 nsString2::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
|||
*anErrorCode = (0<theString.mLength) ? NS_OK : NS_ERROR_ILLEGAL_VALUE;
|
||||
|
||||
// Skip trailing non-numeric...
|
||||
while (cp >= theString.mStr.mCharBuf) {
|
||||
while (cp >= theString.mStr) {
|
||||
theChar = toupper(*cp);
|
||||
if((theChar>='0') && (theChar<='9')){
|
||||
break;
|
||||
|
@ -687,7 +687,7 @@ PRInt32 nsString2::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
|||
}
|
||||
|
||||
//now iterate the numeric chars and build our result
|
||||
while(cp>=theString.mStr.mCharBuf) {
|
||||
while(cp>=theString.mStr) {
|
||||
theChar=toupper(*cp--);
|
||||
if((theChar>='0') && (theChar<='9')){
|
||||
digit=theChar-'0';
|
||||
|
@ -845,7 +845,7 @@ nsString2& nsString2::Append(const char* aCString,PRInt32 aCount) {
|
|||
if(aCString){
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eOneByte);
|
||||
theTemp.mStr.mCharBuf=(char*)aCString;
|
||||
theTemp.mStr=(char*)aCString;
|
||||
theTemp.mLength=nsCRT::strlen(aCString);
|
||||
if(-1==aCount) aCount=theTemp.mLength;
|
||||
nsStr::Append(*this,theTemp,0,aCount,mAgent);
|
||||
|
@ -864,7 +864,7 @@ nsString2& nsString2::Append(const PRUnichar* aString,PRInt32 aCount) {
|
|||
if(aString){
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eTwoByte);
|
||||
theTemp.mStr.mUnicharBuf=(PRUnichar*)aString;
|
||||
theTemp.mUStr=(PRUnichar*)aString;
|
||||
theTemp.mLength=nsCRT::strlen(aString);
|
||||
if(-1==aCount) aCount=theTemp.mLength;
|
||||
nsStr::Append(*this,theTemp,0,aCount,mAgent);
|
||||
|
@ -884,7 +884,7 @@ nsString2& nsString2::Append(char aChar) {
|
|||
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eOneByte);
|
||||
theTemp.mStr.mCharBuf=buf;
|
||||
theTemp.mStr=buf;
|
||||
theTemp.mLength=1;
|
||||
nsStr::Append(*this,theTemp,0,1,mAgent);
|
||||
return *this;
|
||||
|
@ -902,7 +902,7 @@ nsString2& nsString2::Append(PRUnichar aChar) {
|
|||
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eTwoByte);
|
||||
theTemp.mStr.mUnicharBuf=buf;
|
||||
theTemp.mUStr=buf;
|
||||
theTemp.mLength=1;
|
||||
nsStr::Append(*this,theTemp,0,1,mAgent);
|
||||
return *this;
|
||||
|
@ -1020,7 +1020,7 @@ nsString2& nsString2::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCou
|
|||
if(0<aCount) {
|
||||
nsStr theTemp;
|
||||
nsStr::Initialize(theTemp,eOneByte);
|
||||
theTemp.mStr.mCharBuf=(char*)aCString;
|
||||
theTemp.mStr=(char*)aCString;
|
||||
theTemp.mLength=nsCRT::strlen(aCString);
|
||||
if(theTemp.mLength){
|
||||
nsStr::Insert(*this,anOffset,theTemp,0,aCount,0);
|
||||
|
@ -1067,7 +1067,7 @@ nsString2& nsString2::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32
|
|||
if(0<aCount) {
|
||||
nsStr theTemp;
|
||||
nsStr::Initialize(theTemp,eTwoByte);
|
||||
theTemp.mStr.mUnicharBuf=(PRUnichar*)aString;
|
||||
theTemp.mUStr=(PRUnichar*)aString;
|
||||
theTemp.mLength=nsCRT::strlen(aString);
|
||||
if(theTemp.mLength){
|
||||
nsStr::Insert(*this,anOffset,theTemp,0,aCount,0);
|
||||
|
@ -1092,7 +1092,7 @@ nsString2& nsString2::Insert(PRUnichar aChar,PRUint32 anOffset){
|
|||
theBuffer[0]=aChar;
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mStr.mUnicharBuf=theBuffer;
|
||||
theTempStr.mUStr=theBuffer;
|
||||
theTempStr.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,theTempStr,0,1,0);
|
||||
return *this;
|
||||
|
@ -1156,7 +1156,7 @@ PRInt32 nsString2::Find(const char* aCString,PRBool aIgnoreCase) const{
|
|||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCString);
|
||||
theTempStr.mStr.mCharBuf=(char*)aCString;
|
||||
theTempStr.mStr=(char*)aCString;
|
||||
result=nsStr::FindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
|
@ -1177,7 +1177,7 @@ PRInt32 nsString2::Find(const PRUnichar* aString,PRBool aIgnoreCase) const{
|
|||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mStr.mUnicharBuf=(PRUnichar*)aString;
|
||||
theTempStr.mUStr=(PRUnichar*)aString;
|
||||
result=nsStr::FindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
|
@ -1222,7 +1222,7 @@ PRInt32 nsString2::FindCharInSet(const char* aCStringSet,PRUint32 anOffset) cons
|
|||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCStringSet);
|
||||
theTempStr.mStr.mCharBuf=(char*)aCStringSet;
|
||||
theTempStr.mStr=(char*)aCStringSet;
|
||||
result=nsStr::FindCharInSet(*this,theTempStr,PR_FALSE,anOffset);
|
||||
}
|
||||
return result;
|
||||
|
@ -1255,7 +1255,7 @@ PRInt32 nsString2::RFindCharInSet(const char* aCStringSet,PRUint32 anOffset) con
|
|||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCStringSet);
|
||||
theTempStr.mStr.mCharBuf=(char*)aCStringSet;
|
||||
theTempStr.mStr=(char*)aCStringSet;
|
||||
result=nsStr::RFindCharInSet(*this,theTempStr,PR_FALSE,anOffset);
|
||||
}
|
||||
return result;
|
||||
|
@ -1300,7 +1300,7 @@ PRInt32 nsString2::RFind(const char* aString,PRBool aIgnoreCase) const{
|
|||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mStr.mCharBuf=(char*)aString;
|
||||
theTempStr.mStr=(char*)aString;
|
||||
result=nsStr::RFindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
|
@ -1337,7 +1337,7 @@ PRInt32 nsString2::Compare(const char *aCString,PRBool aIgnoreCase,PRInt32 aLeng
|
|||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCString);
|
||||
theTempStr.mStr.mCharBuf=(char*)aCString;
|
||||
theTempStr.mStr=(char*)aCString;
|
||||
return nsStr::Compare(*this,theTempStr,aLength,aIgnoreCase);
|
||||
}
|
||||
return 0;
|
||||
|
@ -1357,7 +1357,7 @@ PRInt32 nsString2::Compare(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 a
|
|||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mStr.mUnicharBuf=(PRUnichar*)aString;
|
||||
theTempStr.mUStr=(PRUnichar*)aString;
|
||||
return nsStr::Compare(*this,theTempStr,aLength,aIgnoreCase);
|
||||
}
|
||||
return 0;
|
||||
|
@ -1501,7 +1501,7 @@ PRBool nsString2::Equals(const nsIAtom* aAtom,PRBool aIgnoreCase) const{
|
|||
NS_ASSERTION(0!=aAtom,kNullPointerError);
|
||||
PRBool result=PR_FALSE;
|
||||
if(aAtom){
|
||||
PRInt32 cmp=nsCRT::strcasecmp(mStr.mUnicharBuf,aAtom->GetUnicode());
|
||||
PRInt32 cmp=nsCRT::strcasecmp(mUStr,aAtom->GetUnicode());
|
||||
result=PRBool(0==cmp);
|
||||
}
|
||||
return result;
|
||||
|
@ -1573,7 +1573,6 @@ PRBool nsString2::IsDigit(PRUnichar aChar) {
|
|||
****************************************************************************/
|
||||
|
||||
#if 0
|
||||
|
||||
class nsStringRecycler {
|
||||
public:
|
||||
nsStringRecycler() : mDeque(0) {
|
||||
|
@ -1634,7 +1633,7 @@ void nsString2::Recycle(nsString2* aString){
|
|||
*/
|
||||
void nsString2::DebugDump(ostream& aStream) const {
|
||||
for(PRUint32 i=0;i<mLength;i++) {
|
||||
aStream <<mStr.mCharBuf[i];
|
||||
aStream <<mStr[i];
|
||||
}
|
||||
aStream << endl;
|
||||
}
|
||||
|
@ -1647,7 +1646,7 @@ void nsString2::DebugDump(ostream& aStream) const {
|
|||
*/
|
||||
ostream& operator<<(ostream& os,nsString2& aString){
|
||||
if(PR_FALSE==aString.mMultibyte) {
|
||||
os<<aString.mStr.mCharBuf;
|
||||
os<<aString.mStr;
|
||||
}
|
||||
else{
|
||||
char* theStr=aString.ToNewCString();
|
||||
|
|
|
@ -66,12 +66,12 @@ char* GetSharedEmptyBuffer() {
|
|||
* @return
|
||||
*/
|
||||
void nsStr::Initialize(nsStr& aDest,eCharSize aCharSize) {
|
||||
aDest.mStr.mCharBuf=GetSharedEmptyBuffer();
|
||||
aDest.mStr=GetSharedEmptyBuffer();
|
||||
aDest.mLength=0;
|
||||
aDest.mCapacity=0;
|
||||
aDest.mMultibyte=aCharSize;
|
||||
aDest.mOwnsBuffer=0;
|
||||
NS_ASSERTION(aDest.mStr.mCharBuf[0]==0,kFoolMsg);
|
||||
NS_ASSERTION(aDest.mStr[0]==0,kFoolMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -97,7 +97,7 @@ nsIMemoryAgent* GetDefaultAgent(void){
|
|||
* @return
|
||||
*/
|
||||
void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) {
|
||||
if((aDest.mStr.mCharBuf) && (aDest.mStr.mCharBuf!=GetSharedEmptyBuffer())) {
|
||||
if((aDest.mStr) && (aDest.mStr!=GetSharedEmptyBuffer())) {
|
||||
if(!anAgent)
|
||||
anAgent=GetDefaultAgent();
|
||||
|
||||
|
@ -119,7 +119,7 @@ void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) {
|
|||
PRUnichar nsStr::GetCharAt(const nsStr& aDest,PRUint32 anIndex) {
|
||||
PRUnichar result=0;
|
||||
if((anIndex>=0) && (anIndex<aDest.mLength)) {
|
||||
result=(eTwoByte==aDest.mMultibyte) ? aDest.mStr.mUnicharBuf[anIndex] : aDest.mStr.mCharBuf[anIndex];
|
||||
result=(eTwoByte==aDest.mMultibyte) ? aDest.mUStr[anIndex] : aDest.mStr[anIndex];
|
||||
}//if
|
||||
return result;
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ void nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAgen
|
|||
}
|
||||
theAgent->Free(aDest);
|
||||
aDest.mStr = theTempStr.mStr;
|
||||
theTempStr.mStr.mCharBuf=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.mCapacity=theTempStr.mCapacity;
|
||||
aDest.mOwnsBuffer=theTempStr.mOwnsBuffer;
|
||||
|
@ -198,7 +198,7 @@ void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 a
|
|||
}
|
||||
|
||||
//now append new chars, starting at offset
|
||||
(*gCopyChars[aSource.mMultibyte][aDest.mMultibyte])(aDest.mStr.mCharBuf,aDest.mLength,aSource.mStr.mCharBuf,anOffset,theLength);
|
||||
(*gCopyChars[aSource.mMultibyte][aDest.mMultibyte])(aDest.mStr,aDest.mLength,aSource.mStr,anOffset,theLength);
|
||||
|
||||
aDest.mLength+=theLength;
|
||||
AddNullTerminator(aDest);
|
||||
|
@ -235,10 +235,10 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin
|
|||
GrowCapacity(aDest,aDest.mLength+theLength,anAgent);
|
||||
|
||||
//shift the chars right by theDelta...
|
||||
(*gShiftChars[aDest.mMultibyte][PR_TRUE])(aDest.mStr.mCharBuf,aDest.mLength,aDestOffset,theLength);
|
||||
(*gShiftChars[aDest.mMultibyte][PR_TRUE])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
|
||||
|
||||
//now insert new chars, starting at offset
|
||||
(*gCopyChars[aSource.mMultibyte][aDest.mMultibyte])(aDest.mStr.mCharBuf,aDestOffset,aSource.mStr.mCharBuf,aSrcOffset,theLength);
|
||||
(*gCopyChars[aSource.mMultibyte][aDest.mMultibyte])(aDest.mStr,aDestOffset,aSource.mStr,aSrcOffset,theLength);
|
||||
|
||||
//finally, make sure to update the string length...
|
||||
aDest.mLength+=theLength;
|
||||
|
@ -271,7 +271,7 @@ void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,nsIMemoryAge
|
|||
|
||||
//if you're here, it means we're cutting chars out of the middle of the string...
|
||||
//so shift the chars left by theLength...
|
||||
(*gShiftChars[aDest.mMultibyte][PR_FALSE])(aDest.mStr.mCharBuf,aDest.mLength,aDestOffset,theLength);
|
||||
(*gShiftChars[aDest.mMultibyte][PR_FALSE])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
|
||||
aDest.mLength-=theLength;
|
||||
}
|
||||
else Truncate(aDest,aDestOffset,anAgent);
|
||||
|
@ -301,7 +301,7 @@ void nsStr::Truncate(nsStr& aDest,PRUint32 aDestOffset,nsIMemoryAgent* anAgent){
|
|||
*/
|
||||
void nsStr::ChangeCase(nsStr& aDest,PRBool aToUpper) {
|
||||
// somehow UnicharUtil return failed, fallback to the old ascii only code
|
||||
gCaseConverters[aDest.mMultibyte](aDest.mStr.mCharBuf,aDest.mLength,aToUpper);
|
||||
gCaseConverters[aDest.mMultibyte](aDest.mStr,aDest.mLength,aToUpper);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -311,7 +311,7 @@ void nsStr::ChangeCase(nsStr& aDest,PRBool aToUpper) {
|
|||
* @return
|
||||
*/
|
||||
void nsStr::StripChars(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,const char* aCharSet){
|
||||
PRUint32 aNewLen=gStripChars[aDest.mMultibyte](aDest.mStr.mCharBuf,aDestOffset,aCount,aCharSet);
|
||||
PRUint32 aNewLen=gStripChars[aDest.mMultibyte](aDest.mStr,aDestOffset,aCount,aCharSet);
|
||||
aDest.mLength=aNewLen;
|
||||
}
|
||||
|
||||
|
@ -323,7 +323,7 @@ void nsStr::StripChars(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,const ch
|
|||
* @return
|
||||
*/
|
||||
void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
||||
PRUint32 aNewLen=gTrimChars[aDest.mMultibyte](aDest.mStr.mCharBuf,aDest.mLength,aSet,aEliminateLeading,aEliminateTrailing);
|
||||
PRUint32 aNewLen=gTrimChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,aSet,aEliminateLeading,aEliminateTrailing);
|
||||
aDest.mLength=aNewLen;
|
||||
}
|
||||
|
||||
|
@ -334,7 +334,7 @@ void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool a
|
|||
* @return
|
||||
*/
|
||||
void nsStr::CompressSet(nsStr& aDest,const char* aSet,PRUint32 aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
||||
PRUint32 aNewLen=gCompressChars[aDest.mMultibyte](aDest.mStr.mCharBuf,aDest.mLength,aSet,aChar,aEliminateLeading,aEliminateTrailing);
|
||||
PRUint32 aNewLen=gCompressChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,aSet,aChar,aEliminateLeading,aEliminateTrailing);
|
||||
aDest.mLength=aNewLen;
|
||||
}
|
||||
|
||||
|
@ -385,7 +385,7 @@ PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnor
|
|||
* @return
|
||||
*/
|
||||
PRInt32 nsStr::FindChar(const nsStr& aDest,const PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gFindChars[aDest.mMultibyte](aDest.mStr.mCharBuf,aDest.mLength,0,aChar,aIgnoreCase);
|
||||
PRInt32 result=gFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,0,aChar,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -403,7 +403,7 @@ PRInt32 nsStr::FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnore
|
|||
|
||||
while(++index<aDest.mLength) {
|
||||
PRUnichar theChar=GetCharAt(aDest,index);
|
||||
thePos=gFindChars[aSet.mMultibyte](aSet.mStr.mCharBuf,aSet.mLength,0,theChar,aIgnoreCase);
|
||||
thePos=gFindChars[aSet.mMultibyte](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase);
|
||||
if(kNotFound!=thePos)
|
||||
return index;
|
||||
} //while
|
||||
|
@ -460,7 +460,7 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgno
|
|||
* @return
|
||||
*/
|
||||
PRInt32 nsStr::RFindChar(const nsStr& aDest,const PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gRFindChars[aDest.mMultibyte](aDest.mStr.mCharBuf,aDest.mLength,0,aChar,aIgnoreCase);
|
||||
PRInt32 result=gRFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,0,aChar,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -477,7 +477,7 @@ PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnor
|
|||
|
||||
while(--offset>=0) {
|
||||
PRUnichar theChar=GetCharAt(aDest,offset);
|
||||
thePos=gRFindChars[aSet.mMultibyte](aSet.mStr.mCharBuf,aSet.mLength,0,theChar,aIgnoreCase);
|
||||
thePos=gRFindChars[aSet.mMultibyte](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase);
|
||||
if(kNotFound!=thePos)
|
||||
return offset;
|
||||
} //while
|
||||
|
@ -503,7 +503,7 @@ PRInt32 nsStr::Compare(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PR
|
|||
}
|
||||
|
||||
int maxlen=(aSource.mLength<aDest.mLength) ? aDest.mLength : aSource.mLength;
|
||||
PRInt32 result=(*gCompare[aDest.mMultibyte][aSource.mMultibyte])(aDest.mStr.mCharBuf,aSource.mStr.mCharBuf,maxlen,aIgnoreCase);
|
||||
PRInt32 result=(*gCompare[aDest.mMultibyte][aSource.mMultibyte])(aDest.mStr,aSource.mStr,maxlen,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ union UStrPtr {
|
|||
|
||||
struct nsBufDescriptor {
|
||||
nsBufDescriptor(char* aBuffer,PRUint32 aBufferSize,eCharSize aCharSize,PRBool aOwnsBuffer) {
|
||||
mStr.mCharBuf=aBuffer;
|
||||
mStr=aBuffer;
|
||||
mMultibyte=aCharSize;
|
||||
mCapacity=(aBufferSize>>mMultibyte)-1;
|
||||
mOwnsBuffer=aOwnsBuffer;
|
||||
|
@ -73,7 +73,11 @@ struct nsBufDescriptor {
|
|||
PRUint32 mCapacity;
|
||||
PRBool mOwnsBuffer;
|
||||
eCharSize mMultibyte;
|
||||
UStrPtr mStr;
|
||||
// UStrPtr mStr;
|
||||
union {
|
||||
char* mStr;
|
||||
PRUnichar* mUStr;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
@ -265,7 +269,10 @@ struct nsStr {
|
|||
PRUint32 mCapacity: 30;
|
||||
PRUint32 mOwnsBuffer: 1;
|
||||
PRUint32 mUnused: 1;
|
||||
UStrPtr mStr;
|
||||
union {
|
||||
char* mStr;
|
||||
PRUnichar* mUStr;
|
||||
};
|
||||
};
|
||||
|
||||
/**************************************************************
|
||||
|
@ -296,8 +303,8 @@ inline void ToRange(PRUint32& aValue,PRUint32 aMin,PRUint32 aMax){
|
|||
|
||||
inline void AddNullTerminator(nsStr& aDest) {
|
||||
if(eTwoByte==aDest.mMultibyte)
|
||||
aDest.mStr.mUnicharBuf[aDest.mLength]=0;
|
||||
else aDest.mStr.mCharBuf[aDest.mLength]=0;
|
||||
aDest.mUStr[aDest.mLength]=0;
|
||||
else aDest.mStr[aDest.mLength]=0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
@ -331,17 +338,17 @@ public:
|
|||
|
||||
aDest.mCapacity=theNewCapacity++;
|
||||
size_t theSize=(theNewCapacity<<aDest.mMultibyte);
|
||||
aDest.mStr.mCharBuf=new char[theSize];
|
||||
aDest.mStr=new char[theSize];
|
||||
aDest.mOwnsBuffer=1;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
virtual PRBool Free(nsStr& aDest){
|
||||
if(aDest.mStr.mCharBuf){
|
||||
if(aDest.mStr){
|
||||
if(aDest.mOwnsBuffer){
|
||||
delete [] aDest.mStr.mCharBuf;
|
||||
delete [] aDest.mStr;
|
||||
}
|
||||
aDest.mStr.mCharBuf=0;
|
||||
aDest.mStr=0;
|
||||
aDest.mOwnsBuffer=0;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
|
|
@ -295,7 +295,7 @@ void nsString2::SetCapacity(PRUint32 aLength) {
|
|||
*/
|
||||
char* nsString2::GetBuffer(void) const {
|
||||
if(!mMultibyte)
|
||||
return mStr.mCharBuf;
|
||||
return mStr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -307,7 +307,7 @@ char* nsString2::GetBuffer(void) const {
|
|||
*/
|
||||
PRUnichar* nsString2::GetUnicode(void) const {
|
||||
if(mMultibyte)
|
||||
return (PRUnichar*)mStr.mUnicharBuf;
|
||||
return (PRUnichar*)mUStr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -334,8 +334,8 @@ PRBool nsString2::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
|
|||
PRBool result=PR_FALSE;
|
||||
if(anIndex<mLength){
|
||||
if(!mMultibyte)
|
||||
mStr.mCharBuf[anIndex]=char(aChar);
|
||||
else mStr.mUnicharBuf[anIndex]=aChar;
|
||||
mStr[anIndex]=char(aChar);
|
||||
else mUStr[anIndex]=aChar;
|
||||
result=PR_TRUE;
|
||||
}
|
||||
return result;
|
||||
|
@ -433,9 +433,9 @@ void nsString2::ToUCS2(PRUint32 aStartOffset){
|
|||
if(mMultibyte) {
|
||||
PRUint32 theIndex=0;
|
||||
for(theIndex=aStartOffset;theIndex<mLength;theIndex++){
|
||||
unsigned char ch = (unsigned char)mStr.mUnicharBuf[theIndex];
|
||||
if( 0x0080 == (0xFFE0 & (mStr.mUnicharBuf[theIndex])) ) // limit to only 0x0080 to 0x009F
|
||||
mStr.mUnicharBuf[theIndex]=gToUCS2[ch];
|
||||
unsigned char ch = (unsigned char)mUStr[theIndex];
|
||||
if( 0x0080 == (0xFFE0 & (mUStr[theIndex])) ) // limit to only 0x0080 to 0x009F
|
||||
mUStr[theIndex]=gToUCS2[ch];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -517,12 +517,12 @@ nsString2& nsString2::ReplaceChar(PRUnichar aSourceChar, PRUnichar aDestChar) {
|
|||
PRUint32 theIndex=0;
|
||||
for(theIndex=0;theIndex<mLength;theIndex++){
|
||||
if(mMultibyte) {
|
||||
if(mStr.mUnicharBuf[theIndex]==aSourceChar)
|
||||
mStr.mUnicharBuf[theIndex]=aDestChar;
|
||||
if(mUStr[theIndex]==aSourceChar)
|
||||
mUStr[theIndex]=aDestChar;
|
||||
}
|
||||
else {
|
||||
if(mStr.mCharBuf[theIndex]==aSourceChar)
|
||||
mStr.mCharBuf[theIndex]=(char)aDestChar;
|
||||
if(mStr[theIndex]==aSourceChar)
|
||||
mStr[theIndex]=(char)aDestChar;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
|
@ -596,8 +596,8 @@ nsString2* nsString2::ToNewString() const {
|
|||
*/
|
||||
char* nsString2::ToNewCString() const {
|
||||
nsString2 temp(*this,eOneByte);
|
||||
char* result=temp.mStr.mCharBuf;
|
||||
temp.mStr.mCharBuf=0;
|
||||
char* result=temp.mStr;
|
||||
temp.mStr=0;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -608,8 +608,8 @@ char* nsString2::ToNewCString() const {
|
|||
*/
|
||||
PRUnichar* nsString2::ToNewUnicode() const {
|
||||
nsString2 temp(*this,eTwoByte);
|
||||
PRUnichar* result=temp.mStr.mUnicharBuf;
|
||||
temp.mStr.mUnicharBuf=0;
|
||||
PRUnichar* result=temp.mUStr;
|
||||
temp.mUStr=0;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -623,7 +623,7 @@ char* nsString2::ToCString(char* aBuf, PRUint32 aBufLength) const{
|
|||
if(aBuf) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mStr.mCharBuf=aBuf;
|
||||
theTempStr.mStr=aBuf;
|
||||
theTempStr.mCapacity=aBufLength;
|
||||
nsStr::Assign(theTempStr,*this,0,mLength,mAgent);
|
||||
}
|
||||
|
@ -666,7 +666,7 @@ PRInt32 nsString2::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
|||
nsAutoString2 theString(*this,eOneByte);
|
||||
|
||||
PRInt32 decPt=theString.FindChar(theString,'.',PR_TRUE,0);
|
||||
char* cp = (kNotFound==decPt) ? theString.mStr.mCharBuf + theString.mLength-1 : theString.mStr.mCharBuf+decPt-1;
|
||||
char* cp = (kNotFound==decPt) ? theString.mStr + theString.mLength-1 : theString.mStr+decPt-1;
|
||||
char digit=0;
|
||||
char theChar;
|
||||
// PRInt32 theShift=0;
|
||||
|
@ -675,7 +675,7 @@ PRInt32 nsString2::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
|||
*anErrorCode = (0<theString.mLength) ? NS_OK : NS_ERROR_ILLEGAL_VALUE;
|
||||
|
||||
// Skip trailing non-numeric...
|
||||
while (cp >= theString.mStr.mCharBuf) {
|
||||
while (cp >= theString.mStr) {
|
||||
theChar = toupper(*cp);
|
||||
if((theChar>='0') && (theChar<='9')){
|
||||
break;
|
||||
|
@ -687,7 +687,7 @@ PRInt32 nsString2::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
|||
}
|
||||
|
||||
//now iterate the numeric chars and build our result
|
||||
while(cp>=theString.mStr.mCharBuf) {
|
||||
while(cp>=theString.mStr) {
|
||||
theChar=toupper(*cp--);
|
||||
if((theChar>='0') && (theChar<='9')){
|
||||
digit=theChar-'0';
|
||||
|
@ -845,7 +845,7 @@ nsString2& nsString2::Append(const char* aCString,PRInt32 aCount) {
|
|||
if(aCString){
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eOneByte);
|
||||
theTemp.mStr.mCharBuf=(char*)aCString;
|
||||
theTemp.mStr=(char*)aCString;
|
||||
theTemp.mLength=nsCRT::strlen(aCString);
|
||||
if(-1==aCount) aCount=theTemp.mLength;
|
||||
nsStr::Append(*this,theTemp,0,aCount,mAgent);
|
||||
|
@ -864,7 +864,7 @@ nsString2& nsString2::Append(const PRUnichar* aString,PRInt32 aCount) {
|
|||
if(aString){
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eTwoByte);
|
||||
theTemp.mStr.mUnicharBuf=(PRUnichar*)aString;
|
||||
theTemp.mUStr=(PRUnichar*)aString;
|
||||
theTemp.mLength=nsCRT::strlen(aString);
|
||||
if(-1==aCount) aCount=theTemp.mLength;
|
||||
nsStr::Append(*this,theTemp,0,aCount,mAgent);
|
||||
|
@ -884,7 +884,7 @@ nsString2& nsString2::Append(char aChar) {
|
|||
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eOneByte);
|
||||
theTemp.mStr.mCharBuf=buf;
|
||||
theTemp.mStr=buf;
|
||||
theTemp.mLength=1;
|
||||
nsStr::Append(*this,theTemp,0,1,mAgent);
|
||||
return *this;
|
||||
|
@ -902,7 +902,7 @@ nsString2& nsString2::Append(PRUnichar aChar) {
|
|||
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eTwoByte);
|
||||
theTemp.mStr.mUnicharBuf=buf;
|
||||
theTemp.mUStr=buf;
|
||||
theTemp.mLength=1;
|
||||
nsStr::Append(*this,theTemp,0,1,mAgent);
|
||||
return *this;
|
||||
|
@ -1020,7 +1020,7 @@ nsString2& nsString2::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCou
|
|||
if(0<aCount) {
|
||||
nsStr theTemp;
|
||||
nsStr::Initialize(theTemp,eOneByte);
|
||||
theTemp.mStr.mCharBuf=(char*)aCString;
|
||||
theTemp.mStr=(char*)aCString;
|
||||
theTemp.mLength=nsCRT::strlen(aCString);
|
||||
if(theTemp.mLength){
|
||||
nsStr::Insert(*this,anOffset,theTemp,0,aCount,0);
|
||||
|
@ -1067,7 +1067,7 @@ nsString2& nsString2::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32
|
|||
if(0<aCount) {
|
||||
nsStr theTemp;
|
||||
nsStr::Initialize(theTemp,eTwoByte);
|
||||
theTemp.mStr.mUnicharBuf=(PRUnichar*)aString;
|
||||
theTemp.mUStr=(PRUnichar*)aString;
|
||||
theTemp.mLength=nsCRT::strlen(aString);
|
||||
if(theTemp.mLength){
|
||||
nsStr::Insert(*this,anOffset,theTemp,0,aCount,0);
|
||||
|
@ -1092,7 +1092,7 @@ nsString2& nsString2::Insert(PRUnichar aChar,PRUint32 anOffset){
|
|||
theBuffer[0]=aChar;
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mStr.mUnicharBuf=theBuffer;
|
||||
theTempStr.mUStr=theBuffer;
|
||||
theTempStr.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,theTempStr,0,1,0);
|
||||
return *this;
|
||||
|
@ -1156,7 +1156,7 @@ PRInt32 nsString2::Find(const char* aCString,PRBool aIgnoreCase) const{
|
|||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCString);
|
||||
theTempStr.mStr.mCharBuf=(char*)aCString;
|
||||
theTempStr.mStr=(char*)aCString;
|
||||
result=nsStr::FindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
|
@ -1177,7 +1177,7 @@ PRInt32 nsString2::Find(const PRUnichar* aString,PRBool aIgnoreCase) const{
|
|||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mStr.mUnicharBuf=(PRUnichar*)aString;
|
||||
theTempStr.mUStr=(PRUnichar*)aString;
|
||||
result=nsStr::FindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
|
@ -1222,7 +1222,7 @@ PRInt32 nsString2::FindCharInSet(const char* aCStringSet,PRUint32 anOffset) cons
|
|||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCStringSet);
|
||||
theTempStr.mStr.mCharBuf=(char*)aCStringSet;
|
||||
theTempStr.mStr=(char*)aCStringSet;
|
||||
result=nsStr::FindCharInSet(*this,theTempStr,PR_FALSE,anOffset);
|
||||
}
|
||||
return result;
|
||||
|
@ -1255,7 +1255,7 @@ PRInt32 nsString2::RFindCharInSet(const char* aCStringSet,PRUint32 anOffset) con
|
|||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCStringSet);
|
||||
theTempStr.mStr.mCharBuf=(char*)aCStringSet;
|
||||
theTempStr.mStr=(char*)aCStringSet;
|
||||
result=nsStr::RFindCharInSet(*this,theTempStr,PR_FALSE,anOffset);
|
||||
}
|
||||
return result;
|
||||
|
@ -1300,7 +1300,7 @@ PRInt32 nsString2::RFind(const char* aString,PRBool aIgnoreCase) const{
|
|||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mStr.mCharBuf=(char*)aString;
|
||||
theTempStr.mStr=(char*)aString;
|
||||
result=nsStr::RFindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
|
@ -1337,7 +1337,7 @@ PRInt32 nsString2::Compare(const char *aCString,PRBool aIgnoreCase,PRInt32 aLeng
|
|||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCString);
|
||||
theTempStr.mStr.mCharBuf=(char*)aCString;
|
||||
theTempStr.mStr=(char*)aCString;
|
||||
return nsStr::Compare(*this,theTempStr,aLength,aIgnoreCase);
|
||||
}
|
||||
return 0;
|
||||
|
@ -1357,7 +1357,7 @@ PRInt32 nsString2::Compare(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 a
|
|||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mStr.mUnicharBuf=(PRUnichar*)aString;
|
||||
theTempStr.mUStr=(PRUnichar*)aString;
|
||||
return nsStr::Compare(*this,theTempStr,aLength,aIgnoreCase);
|
||||
}
|
||||
return 0;
|
||||
|
@ -1501,7 +1501,7 @@ PRBool nsString2::Equals(const nsIAtom* aAtom,PRBool aIgnoreCase) const{
|
|||
NS_ASSERTION(0!=aAtom,kNullPointerError);
|
||||
PRBool result=PR_FALSE;
|
||||
if(aAtom){
|
||||
PRInt32 cmp=nsCRT::strcasecmp(mStr.mUnicharBuf,aAtom->GetUnicode());
|
||||
PRInt32 cmp=nsCRT::strcasecmp(mUStr,aAtom->GetUnicode());
|
||||
result=PRBool(0==cmp);
|
||||
}
|
||||
return result;
|
||||
|
@ -1573,7 +1573,6 @@ PRBool nsString2::IsDigit(PRUnichar aChar) {
|
|||
****************************************************************************/
|
||||
|
||||
#if 0
|
||||
|
||||
class nsStringRecycler {
|
||||
public:
|
||||
nsStringRecycler() : mDeque(0) {
|
||||
|
@ -1634,7 +1633,7 @@ void nsString2::Recycle(nsString2* aString){
|
|||
*/
|
||||
void nsString2::DebugDump(ostream& aStream) const {
|
||||
for(PRUint32 i=0;i<mLength;i++) {
|
||||
aStream <<mStr.mCharBuf[i];
|
||||
aStream <<mStr[i];
|
||||
}
|
||||
aStream << endl;
|
||||
}
|
||||
|
@ -1647,7 +1646,7 @@ void nsString2::DebugDump(ostream& aStream) const {
|
|||
*/
|
||||
ostream& operator<<(ostream& os,nsString2& aString){
|
||||
if(PR_FALSE==aString.mMultibyte) {
|
||||
os<<aString.mStr.mCharBuf;
|
||||
os<<aString.mStr;
|
||||
}
|
||||
else{
|
||||
char* theStr=aString.ToNewCString();
|
||||
|
|
|
@ -66,12 +66,12 @@ char* GetSharedEmptyBuffer() {
|
|||
* @return
|
||||
*/
|
||||
void nsStr::Initialize(nsStr& aDest,eCharSize aCharSize) {
|
||||
aDest.mStr.mCharBuf=GetSharedEmptyBuffer();
|
||||
aDest.mStr=GetSharedEmptyBuffer();
|
||||
aDest.mLength=0;
|
||||
aDest.mCapacity=0;
|
||||
aDest.mMultibyte=aCharSize;
|
||||
aDest.mOwnsBuffer=0;
|
||||
NS_ASSERTION(aDest.mStr.mCharBuf[0]==0,kFoolMsg);
|
||||
NS_ASSERTION(aDest.mStr[0]==0,kFoolMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -97,7 +97,7 @@ nsIMemoryAgent* GetDefaultAgent(void){
|
|||
* @return
|
||||
*/
|
||||
void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) {
|
||||
if((aDest.mStr.mCharBuf) && (aDest.mStr.mCharBuf!=GetSharedEmptyBuffer())) {
|
||||
if((aDest.mStr) && (aDest.mStr!=GetSharedEmptyBuffer())) {
|
||||
if(!anAgent)
|
||||
anAgent=GetDefaultAgent();
|
||||
|
||||
|
@ -119,7 +119,7 @@ void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) {
|
|||
PRUnichar nsStr::GetCharAt(const nsStr& aDest,PRUint32 anIndex) {
|
||||
PRUnichar result=0;
|
||||
if((anIndex>=0) && (anIndex<aDest.mLength)) {
|
||||
result=(eTwoByte==aDest.mMultibyte) ? aDest.mStr.mUnicharBuf[anIndex] : aDest.mStr.mCharBuf[anIndex];
|
||||
result=(eTwoByte==aDest.mMultibyte) ? aDest.mUStr[anIndex] : aDest.mStr[anIndex];
|
||||
}//if
|
||||
return result;
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ void nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAgen
|
|||
}
|
||||
theAgent->Free(aDest);
|
||||
aDest.mStr = theTempStr.mStr;
|
||||
theTempStr.mStr.mCharBuf=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.mCapacity=theTempStr.mCapacity;
|
||||
aDest.mOwnsBuffer=theTempStr.mOwnsBuffer;
|
||||
|
@ -198,7 +198,7 @@ void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 a
|
|||
}
|
||||
|
||||
//now append new chars, starting at offset
|
||||
(*gCopyChars[aSource.mMultibyte][aDest.mMultibyte])(aDest.mStr.mCharBuf,aDest.mLength,aSource.mStr.mCharBuf,anOffset,theLength);
|
||||
(*gCopyChars[aSource.mMultibyte][aDest.mMultibyte])(aDest.mStr,aDest.mLength,aSource.mStr,anOffset,theLength);
|
||||
|
||||
aDest.mLength+=theLength;
|
||||
AddNullTerminator(aDest);
|
||||
|
@ -235,10 +235,10 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin
|
|||
GrowCapacity(aDest,aDest.mLength+theLength,anAgent);
|
||||
|
||||
//shift the chars right by theDelta...
|
||||
(*gShiftChars[aDest.mMultibyte][PR_TRUE])(aDest.mStr.mCharBuf,aDest.mLength,aDestOffset,theLength);
|
||||
(*gShiftChars[aDest.mMultibyte][PR_TRUE])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
|
||||
|
||||
//now insert new chars, starting at offset
|
||||
(*gCopyChars[aSource.mMultibyte][aDest.mMultibyte])(aDest.mStr.mCharBuf,aDestOffset,aSource.mStr.mCharBuf,aSrcOffset,theLength);
|
||||
(*gCopyChars[aSource.mMultibyte][aDest.mMultibyte])(aDest.mStr,aDestOffset,aSource.mStr,aSrcOffset,theLength);
|
||||
|
||||
//finally, make sure to update the string length...
|
||||
aDest.mLength+=theLength;
|
||||
|
@ -271,7 +271,7 @@ void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,nsIMemoryAge
|
|||
|
||||
//if you're here, it means we're cutting chars out of the middle of the string...
|
||||
//so shift the chars left by theLength...
|
||||
(*gShiftChars[aDest.mMultibyte][PR_FALSE])(aDest.mStr.mCharBuf,aDest.mLength,aDestOffset,theLength);
|
||||
(*gShiftChars[aDest.mMultibyte][PR_FALSE])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
|
||||
aDest.mLength-=theLength;
|
||||
}
|
||||
else Truncate(aDest,aDestOffset,anAgent);
|
||||
|
@ -301,7 +301,7 @@ void nsStr::Truncate(nsStr& aDest,PRUint32 aDestOffset,nsIMemoryAgent* anAgent){
|
|||
*/
|
||||
void nsStr::ChangeCase(nsStr& aDest,PRBool aToUpper) {
|
||||
// somehow UnicharUtil return failed, fallback to the old ascii only code
|
||||
gCaseConverters[aDest.mMultibyte](aDest.mStr.mCharBuf,aDest.mLength,aToUpper);
|
||||
gCaseConverters[aDest.mMultibyte](aDest.mStr,aDest.mLength,aToUpper);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -311,7 +311,7 @@ void nsStr::ChangeCase(nsStr& aDest,PRBool aToUpper) {
|
|||
* @return
|
||||
*/
|
||||
void nsStr::StripChars(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,const char* aCharSet){
|
||||
PRUint32 aNewLen=gStripChars[aDest.mMultibyte](aDest.mStr.mCharBuf,aDestOffset,aCount,aCharSet);
|
||||
PRUint32 aNewLen=gStripChars[aDest.mMultibyte](aDest.mStr,aDestOffset,aCount,aCharSet);
|
||||
aDest.mLength=aNewLen;
|
||||
}
|
||||
|
||||
|
@ -323,7 +323,7 @@ void nsStr::StripChars(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,const ch
|
|||
* @return
|
||||
*/
|
||||
void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
||||
PRUint32 aNewLen=gTrimChars[aDest.mMultibyte](aDest.mStr.mCharBuf,aDest.mLength,aSet,aEliminateLeading,aEliminateTrailing);
|
||||
PRUint32 aNewLen=gTrimChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,aSet,aEliminateLeading,aEliminateTrailing);
|
||||
aDest.mLength=aNewLen;
|
||||
}
|
||||
|
||||
|
@ -334,7 +334,7 @@ void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool a
|
|||
* @return
|
||||
*/
|
||||
void nsStr::CompressSet(nsStr& aDest,const char* aSet,PRUint32 aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
||||
PRUint32 aNewLen=gCompressChars[aDest.mMultibyte](aDest.mStr.mCharBuf,aDest.mLength,aSet,aChar,aEliminateLeading,aEliminateTrailing);
|
||||
PRUint32 aNewLen=gCompressChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,aSet,aChar,aEliminateLeading,aEliminateTrailing);
|
||||
aDest.mLength=aNewLen;
|
||||
}
|
||||
|
||||
|
@ -385,7 +385,7 @@ PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnor
|
|||
* @return
|
||||
*/
|
||||
PRInt32 nsStr::FindChar(const nsStr& aDest,const PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gFindChars[aDest.mMultibyte](aDest.mStr.mCharBuf,aDest.mLength,0,aChar,aIgnoreCase);
|
||||
PRInt32 result=gFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,0,aChar,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -403,7 +403,7 @@ PRInt32 nsStr::FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnore
|
|||
|
||||
while(++index<aDest.mLength) {
|
||||
PRUnichar theChar=GetCharAt(aDest,index);
|
||||
thePos=gFindChars[aSet.mMultibyte](aSet.mStr.mCharBuf,aSet.mLength,0,theChar,aIgnoreCase);
|
||||
thePos=gFindChars[aSet.mMultibyte](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase);
|
||||
if(kNotFound!=thePos)
|
||||
return index;
|
||||
} //while
|
||||
|
@ -460,7 +460,7 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgno
|
|||
* @return
|
||||
*/
|
||||
PRInt32 nsStr::RFindChar(const nsStr& aDest,const PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gRFindChars[aDest.mMultibyte](aDest.mStr.mCharBuf,aDest.mLength,0,aChar,aIgnoreCase);
|
||||
PRInt32 result=gRFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,0,aChar,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -477,7 +477,7 @@ PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnor
|
|||
|
||||
while(--offset>=0) {
|
||||
PRUnichar theChar=GetCharAt(aDest,offset);
|
||||
thePos=gRFindChars[aSet.mMultibyte](aSet.mStr.mCharBuf,aSet.mLength,0,theChar,aIgnoreCase);
|
||||
thePos=gRFindChars[aSet.mMultibyte](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase);
|
||||
if(kNotFound!=thePos)
|
||||
return offset;
|
||||
} //while
|
||||
|
@ -503,7 +503,7 @@ PRInt32 nsStr::Compare(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PR
|
|||
}
|
||||
|
||||
int maxlen=(aSource.mLength<aDest.mLength) ? aDest.mLength : aSource.mLength;
|
||||
PRInt32 result=(*gCompare[aDest.mMultibyte][aSource.mMultibyte])(aDest.mStr.mCharBuf,aSource.mStr.mCharBuf,maxlen,aIgnoreCase);
|
||||
PRInt32 result=(*gCompare[aDest.mMultibyte][aSource.mMultibyte])(aDest.mStr,aSource.mStr,maxlen,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ union UStrPtr {
|
|||
|
||||
struct nsBufDescriptor {
|
||||
nsBufDescriptor(char* aBuffer,PRUint32 aBufferSize,eCharSize aCharSize,PRBool aOwnsBuffer) {
|
||||
mStr.mCharBuf=aBuffer;
|
||||
mStr=aBuffer;
|
||||
mMultibyte=aCharSize;
|
||||
mCapacity=(aBufferSize>>mMultibyte)-1;
|
||||
mOwnsBuffer=aOwnsBuffer;
|
||||
|
@ -73,7 +73,11 @@ struct nsBufDescriptor {
|
|||
PRUint32 mCapacity;
|
||||
PRBool mOwnsBuffer;
|
||||
eCharSize mMultibyte;
|
||||
UStrPtr mStr;
|
||||
// UStrPtr mStr;
|
||||
union {
|
||||
char* mStr;
|
||||
PRUnichar* mUStr;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
@ -265,7 +269,10 @@ struct nsStr {
|
|||
PRUint32 mCapacity: 30;
|
||||
PRUint32 mOwnsBuffer: 1;
|
||||
PRUint32 mUnused: 1;
|
||||
UStrPtr mStr;
|
||||
union {
|
||||
char* mStr;
|
||||
PRUnichar* mUStr;
|
||||
};
|
||||
};
|
||||
|
||||
/**************************************************************
|
||||
|
@ -296,8 +303,8 @@ inline void ToRange(PRUint32& aValue,PRUint32 aMin,PRUint32 aMax){
|
|||
|
||||
inline void AddNullTerminator(nsStr& aDest) {
|
||||
if(eTwoByte==aDest.mMultibyte)
|
||||
aDest.mStr.mUnicharBuf[aDest.mLength]=0;
|
||||
else aDest.mStr.mCharBuf[aDest.mLength]=0;
|
||||
aDest.mUStr[aDest.mLength]=0;
|
||||
else aDest.mStr[aDest.mLength]=0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
@ -331,17 +338,17 @@ public:
|
|||
|
||||
aDest.mCapacity=theNewCapacity++;
|
||||
size_t theSize=(theNewCapacity<<aDest.mMultibyte);
|
||||
aDest.mStr.mCharBuf=new char[theSize];
|
||||
aDest.mStr=new char[theSize];
|
||||
aDest.mOwnsBuffer=1;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
virtual PRBool Free(nsStr& aDest){
|
||||
if(aDest.mStr.mCharBuf){
|
||||
if(aDest.mStr){
|
||||
if(aDest.mOwnsBuffer){
|
||||
delete [] aDest.mStr.mCharBuf;
|
||||
delete [] aDest.mStr;
|
||||
}
|
||||
aDest.mStr.mCharBuf=0;
|
||||
aDest.mStr=0;
|
||||
aDest.mOwnsBuffer=0;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
|
|
@ -295,7 +295,7 @@ void nsString2::SetCapacity(PRUint32 aLength) {
|
|||
*/
|
||||
char* nsString2::GetBuffer(void) const {
|
||||
if(!mMultibyte)
|
||||
return mStr.mCharBuf;
|
||||
return mStr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -307,7 +307,7 @@ char* nsString2::GetBuffer(void) const {
|
|||
*/
|
||||
PRUnichar* nsString2::GetUnicode(void) const {
|
||||
if(mMultibyte)
|
||||
return (PRUnichar*)mStr.mUnicharBuf;
|
||||
return (PRUnichar*)mUStr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -334,8 +334,8 @@ PRBool nsString2::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
|
|||
PRBool result=PR_FALSE;
|
||||
if(anIndex<mLength){
|
||||
if(!mMultibyte)
|
||||
mStr.mCharBuf[anIndex]=char(aChar);
|
||||
else mStr.mUnicharBuf[anIndex]=aChar;
|
||||
mStr[anIndex]=char(aChar);
|
||||
else mUStr[anIndex]=aChar;
|
||||
result=PR_TRUE;
|
||||
}
|
||||
return result;
|
||||
|
@ -433,9 +433,9 @@ void nsString2::ToUCS2(PRUint32 aStartOffset){
|
|||
if(mMultibyte) {
|
||||
PRUint32 theIndex=0;
|
||||
for(theIndex=aStartOffset;theIndex<mLength;theIndex++){
|
||||
unsigned char ch = (unsigned char)mStr.mUnicharBuf[theIndex];
|
||||
if( 0x0080 == (0xFFE0 & (mStr.mUnicharBuf[theIndex])) ) // limit to only 0x0080 to 0x009F
|
||||
mStr.mUnicharBuf[theIndex]=gToUCS2[ch];
|
||||
unsigned char ch = (unsigned char)mUStr[theIndex];
|
||||
if( 0x0080 == (0xFFE0 & (mUStr[theIndex])) ) // limit to only 0x0080 to 0x009F
|
||||
mUStr[theIndex]=gToUCS2[ch];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -517,12 +517,12 @@ nsString2& nsString2::ReplaceChar(PRUnichar aSourceChar, PRUnichar aDestChar) {
|
|||
PRUint32 theIndex=0;
|
||||
for(theIndex=0;theIndex<mLength;theIndex++){
|
||||
if(mMultibyte) {
|
||||
if(mStr.mUnicharBuf[theIndex]==aSourceChar)
|
||||
mStr.mUnicharBuf[theIndex]=aDestChar;
|
||||
if(mUStr[theIndex]==aSourceChar)
|
||||
mUStr[theIndex]=aDestChar;
|
||||
}
|
||||
else {
|
||||
if(mStr.mCharBuf[theIndex]==aSourceChar)
|
||||
mStr.mCharBuf[theIndex]=(char)aDestChar;
|
||||
if(mStr[theIndex]==aSourceChar)
|
||||
mStr[theIndex]=(char)aDestChar;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
|
@ -596,8 +596,8 @@ nsString2* nsString2::ToNewString() const {
|
|||
*/
|
||||
char* nsString2::ToNewCString() const {
|
||||
nsString2 temp(*this,eOneByte);
|
||||
char* result=temp.mStr.mCharBuf;
|
||||
temp.mStr.mCharBuf=0;
|
||||
char* result=temp.mStr;
|
||||
temp.mStr=0;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -608,8 +608,8 @@ char* nsString2::ToNewCString() const {
|
|||
*/
|
||||
PRUnichar* nsString2::ToNewUnicode() const {
|
||||
nsString2 temp(*this,eTwoByte);
|
||||
PRUnichar* result=temp.mStr.mUnicharBuf;
|
||||
temp.mStr.mUnicharBuf=0;
|
||||
PRUnichar* result=temp.mUStr;
|
||||
temp.mUStr=0;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -623,7 +623,7 @@ char* nsString2::ToCString(char* aBuf, PRUint32 aBufLength) const{
|
|||
if(aBuf) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mStr.mCharBuf=aBuf;
|
||||
theTempStr.mStr=aBuf;
|
||||
theTempStr.mCapacity=aBufLength;
|
||||
nsStr::Assign(theTempStr,*this,0,mLength,mAgent);
|
||||
}
|
||||
|
@ -666,7 +666,7 @@ PRInt32 nsString2::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
|||
nsAutoString2 theString(*this,eOneByte);
|
||||
|
||||
PRInt32 decPt=theString.FindChar(theString,'.',PR_TRUE,0);
|
||||
char* cp = (kNotFound==decPt) ? theString.mStr.mCharBuf + theString.mLength-1 : theString.mStr.mCharBuf+decPt-1;
|
||||
char* cp = (kNotFound==decPt) ? theString.mStr + theString.mLength-1 : theString.mStr+decPt-1;
|
||||
char digit=0;
|
||||
char theChar;
|
||||
// PRInt32 theShift=0;
|
||||
|
@ -675,7 +675,7 @@ PRInt32 nsString2::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
|||
*anErrorCode = (0<theString.mLength) ? NS_OK : NS_ERROR_ILLEGAL_VALUE;
|
||||
|
||||
// Skip trailing non-numeric...
|
||||
while (cp >= theString.mStr.mCharBuf) {
|
||||
while (cp >= theString.mStr) {
|
||||
theChar = toupper(*cp);
|
||||
if((theChar>='0') && (theChar<='9')){
|
||||
break;
|
||||
|
@ -687,7 +687,7 @@ PRInt32 nsString2::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
|||
}
|
||||
|
||||
//now iterate the numeric chars and build our result
|
||||
while(cp>=theString.mStr.mCharBuf) {
|
||||
while(cp>=theString.mStr) {
|
||||
theChar=toupper(*cp--);
|
||||
if((theChar>='0') && (theChar<='9')){
|
||||
digit=theChar-'0';
|
||||
|
@ -845,7 +845,7 @@ nsString2& nsString2::Append(const char* aCString,PRInt32 aCount) {
|
|||
if(aCString){
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eOneByte);
|
||||
theTemp.mStr.mCharBuf=(char*)aCString;
|
||||
theTemp.mStr=(char*)aCString;
|
||||
theTemp.mLength=nsCRT::strlen(aCString);
|
||||
if(-1==aCount) aCount=theTemp.mLength;
|
||||
nsStr::Append(*this,theTemp,0,aCount,mAgent);
|
||||
|
@ -864,7 +864,7 @@ nsString2& nsString2::Append(const PRUnichar* aString,PRInt32 aCount) {
|
|||
if(aString){
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eTwoByte);
|
||||
theTemp.mStr.mUnicharBuf=(PRUnichar*)aString;
|
||||
theTemp.mUStr=(PRUnichar*)aString;
|
||||
theTemp.mLength=nsCRT::strlen(aString);
|
||||
if(-1==aCount) aCount=theTemp.mLength;
|
||||
nsStr::Append(*this,theTemp,0,aCount,mAgent);
|
||||
|
@ -884,7 +884,7 @@ nsString2& nsString2::Append(char aChar) {
|
|||
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eOneByte);
|
||||
theTemp.mStr.mCharBuf=buf;
|
||||
theTemp.mStr=buf;
|
||||
theTemp.mLength=1;
|
||||
nsStr::Append(*this,theTemp,0,1,mAgent);
|
||||
return *this;
|
||||
|
@ -902,7 +902,7 @@ nsString2& nsString2::Append(PRUnichar aChar) {
|
|||
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eTwoByte);
|
||||
theTemp.mStr.mUnicharBuf=buf;
|
||||
theTemp.mUStr=buf;
|
||||
theTemp.mLength=1;
|
||||
nsStr::Append(*this,theTemp,0,1,mAgent);
|
||||
return *this;
|
||||
|
@ -1020,7 +1020,7 @@ nsString2& nsString2::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCou
|
|||
if(0<aCount) {
|
||||
nsStr theTemp;
|
||||
nsStr::Initialize(theTemp,eOneByte);
|
||||
theTemp.mStr.mCharBuf=(char*)aCString;
|
||||
theTemp.mStr=(char*)aCString;
|
||||
theTemp.mLength=nsCRT::strlen(aCString);
|
||||
if(theTemp.mLength){
|
||||
nsStr::Insert(*this,anOffset,theTemp,0,aCount,0);
|
||||
|
@ -1067,7 +1067,7 @@ nsString2& nsString2::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32
|
|||
if(0<aCount) {
|
||||
nsStr theTemp;
|
||||
nsStr::Initialize(theTemp,eTwoByte);
|
||||
theTemp.mStr.mUnicharBuf=(PRUnichar*)aString;
|
||||
theTemp.mUStr=(PRUnichar*)aString;
|
||||
theTemp.mLength=nsCRT::strlen(aString);
|
||||
if(theTemp.mLength){
|
||||
nsStr::Insert(*this,anOffset,theTemp,0,aCount,0);
|
||||
|
@ -1092,7 +1092,7 @@ nsString2& nsString2::Insert(PRUnichar aChar,PRUint32 anOffset){
|
|||
theBuffer[0]=aChar;
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mStr.mUnicharBuf=theBuffer;
|
||||
theTempStr.mUStr=theBuffer;
|
||||
theTempStr.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,theTempStr,0,1,0);
|
||||
return *this;
|
||||
|
@ -1156,7 +1156,7 @@ PRInt32 nsString2::Find(const char* aCString,PRBool aIgnoreCase) const{
|
|||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCString);
|
||||
theTempStr.mStr.mCharBuf=(char*)aCString;
|
||||
theTempStr.mStr=(char*)aCString;
|
||||
result=nsStr::FindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
|
@ -1177,7 +1177,7 @@ PRInt32 nsString2::Find(const PRUnichar* aString,PRBool aIgnoreCase) const{
|
|||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mStr.mUnicharBuf=(PRUnichar*)aString;
|
||||
theTempStr.mUStr=(PRUnichar*)aString;
|
||||
result=nsStr::FindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
|
@ -1222,7 +1222,7 @@ PRInt32 nsString2::FindCharInSet(const char* aCStringSet,PRUint32 anOffset) cons
|
|||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCStringSet);
|
||||
theTempStr.mStr.mCharBuf=(char*)aCStringSet;
|
||||
theTempStr.mStr=(char*)aCStringSet;
|
||||
result=nsStr::FindCharInSet(*this,theTempStr,PR_FALSE,anOffset);
|
||||
}
|
||||
return result;
|
||||
|
@ -1255,7 +1255,7 @@ PRInt32 nsString2::RFindCharInSet(const char* aCStringSet,PRUint32 anOffset) con
|
|||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCStringSet);
|
||||
theTempStr.mStr.mCharBuf=(char*)aCStringSet;
|
||||
theTempStr.mStr=(char*)aCStringSet;
|
||||
result=nsStr::RFindCharInSet(*this,theTempStr,PR_FALSE,anOffset);
|
||||
}
|
||||
return result;
|
||||
|
@ -1300,7 +1300,7 @@ PRInt32 nsString2::RFind(const char* aString,PRBool aIgnoreCase) const{
|
|||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mStr.mCharBuf=(char*)aString;
|
||||
theTempStr.mStr=(char*)aString;
|
||||
result=nsStr::RFindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
|
@ -1337,7 +1337,7 @@ PRInt32 nsString2::Compare(const char *aCString,PRBool aIgnoreCase,PRInt32 aLeng
|
|||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCString);
|
||||
theTempStr.mStr.mCharBuf=(char*)aCString;
|
||||
theTempStr.mStr=(char*)aCString;
|
||||
return nsStr::Compare(*this,theTempStr,aLength,aIgnoreCase);
|
||||
}
|
||||
return 0;
|
||||
|
@ -1357,7 +1357,7 @@ PRInt32 nsString2::Compare(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 a
|
|||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mStr.mUnicharBuf=(PRUnichar*)aString;
|
||||
theTempStr.mUStr=(PRUnichar*)aString;
|
||||
return nsStr::Compare(*this,theTempStr,aLength,aIgnoreCase);
|
||||
}
|
||||
return 0;
|
||||
|
@ -1501,7 +1501,7 @@ PRBool nsString2::Equals(const nsIAtom* aAtom,PRBool aIgnoreCase) const{
|
|||
NS_ASSERTION(0!=aAtom,kNullPointerError);
|
||||
PRBool result=PR_FALSE;
|
||||
if(aAtom){
|
||||
PRInt32 cmp=nsCRT::strcasecmp(mStr.mUnicharBuf,aAtom->GetUnicode());
|
||||
PRInt32 cmp=nsCRT::strcasecmp(mUStr,aAtom->GetUnicode());
|
||||
result=PRBool(0==cmp);
|
||||
}
|
||||
return result;
|
||||
|
@ -1573,7 +1573,6 @@ PRBool nsString2::IsDigit(PRUnichar aChar) {
|
|||
****************************************************************************/
|
||||
|
||||
#if 0
|
||||
|
||||
class nsStringRecycler {
|
||||
public:
|
||||
nsStringRecycler() : mDeque(0) {
|
||||
|
@ -1634,7 +1633,7 @@ void nsString2::Recycle(nsString2* aString){
|
|||
*/
|
||||
void nsString2::DebugDump(ostream& aStream) const {
|
||||
for(PRUint32 i=0;i<mLength;i++) {
|
||||
aStream <<mStr.mCharBuf[i];
|
||||
aStream <<mStr[i];
|
||||
}
|
||||
aStream << endl;
|
||||
}
|
||||
|
@ -1647,7 +1646,7 @@ void nsString2::DebugDump(ostream& aStream) const {
|
|||
*/
|
||||
ostream& operator<<(ostream& os,nsString2& aString){
|
||||
if(PR_FALSE==aString.mMultibyte) {
|
||||
os<<aString.mStr.mCharBuf;
|
||||
os<<aString.mStr;
|
||||
}
|
||||
else{
|
||||
char* theStr=aString.ToNewCString();
|
||||
|
|
|
@ -66,12 +66,12 @@ char* GetSharedEmptyBuffer() {
|
|||
* @return
|
||||
*/
|
||||
void nsStr::Initialize(nsStr& aDest,eCharSize aCharSize) {
|
||||
aDest.mStr.mCharBuf=GetSharedEmptyBuffer();
|
||||
aDest.mStr=GetSharedEmptyBuffer();
|
||||
aDest.mLength=0;
|
||||
aDest.mCapacity=0;
|
||||
aDest.mMultibyte=aCharSize;
|
||||
aDest.mOwnsBuffer=0;
|
||||
NS_ASSERTION(aDest.mStr.mCharBuf[0]==0,kFoolMsg);
|
||||
NS_ASSERTION(aDest.mStr[0]==0,kFoolMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -97,7 +97,7 @@ nsIMemoryAgent* GetDefaultAgent(void){
|
|||
* @return
|
||||
*/
|
||||
void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) {
|
||||
if((aDest.mStr.mCharBuf) && (aDest.mStr.mCharBuf!=GetSharedEmptyBuffer())) {
|
||||
if((aDest.mStr) && (aDest.mStr!=GetSharedEmptyBuffer())) {
|
||||
if(!anAgent)
|
||||
anAgent=GetDefaultAgent();
|
||||
|
||||
|
@ -119,7 +119,7 @@ void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) {
|
|||
PRUnichar nsStr::GetCharAt(const nsStr& aDest,PRUint32 anIndex) {
|
||||
PRUnichar result=0;
|
||||
if((anIndex>=0) && (anIndex<aDest.mLength)) {
|
||||
result=(eTwoByte==aDest.mMultibyte) ? aDest.mStr.mUnicharBuf[anIndex] : aDest.mStr.mCharBuf[anIndex];
|
||||
result=(eTwoByte==aDest.mMultibyte) ? aDest.mUStr[anIndex] : aDest.mStr[anIndex];
|
||||
}//if
|
||||
return result;
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ void nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAgen
|
|||
}
|
||||
theAgent->Free(aDest);
|
||||
aDest.mStr = theTempStr.mStr;
|
||||
theTempStr.mStr.mCharBuf=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.mCapacity=theTempStr.mCapacity;
|
||||
aDest.mOwnsBuffer=theTempStr.mOwnsBuffer;
|
||||
|
@ -198,7 +198,7 @@ void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 a
|
|||
}
|
||||
|
||||
//now append new chars, starting at offset
|
||||
(*gCopyChars[aSource.mMultibyte][aDest.mMultibyte])(aDest.mStr.mCharBuf,aDest.mLength,aSource.mStr.mCharBuf,anOffset,theLength);
|
||||
(*gCopyChars[aSource.mMultibyte][aDest.mMultibyte])(aDest.mStr,aDest.mLength,aSource.mStr,anOffset,theLength);
|
||||
|
||||
aDest.mLength+=theLength;
|
||||
AddNullTerminator(aDest);
|
||||
|
@ -235,10 +235,10 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin
|
|||
GrowCapacity(aDest,aDest.mLength+theLength,anAgent);
|
||||
|
||||
//shift the chars right by theDelta...
|
||||
(*gShiftChars[aDest.mMultibyte][PR_TRUE])(aDest.mStr.mCharBuf,aDest.mLength,aDestOffset,theLength);
|
||||
(*gShiftChars[aDest.mMultibyte][PR_TRUE])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
|
||||
|
||||
//now insert new chars, starting at offset
|
||||
(*gCopyChars[aSource.mMultibyte][aDest.mMultibyte])(aDest.mStr.mCharBuf,aDestOffset,aSource.mStr.mCharBuf,aSrcOffset,theLength);
|
||||
(*gCopyChars[aSource.mMultibyte][aDest.mMultibyte])(aDest.mStr,aDestOffset,aSource.mStr,aSrcOffset,theLength);
|
||||
|
||||
//finally, make sure to update the string length...
|
||||
aDest.mLength+=theLength;
|
||||
|
@ -271,7 +271,7 @@ void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,nsIMemoryAge
|
|||
|
||||
//if you're here, it means we're cutting chars out of the middle of the string...
|
||||
//so shift the chars left by theLength...
|
||||
(*gShiftChars[aDest.mMultibyte][PR_FALSE])(aDest.mStr.mCharBuf,aDest.mLength,aDestOffset,theLength);
|
||||
(*gShiftChars[aDest.mMultibyte][PR_FALSE])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
|
||||
aDest.mLength-=theLength;
|
||||
}
|
||||
else Truncate(aDest,aDestOffset,anAgent);
|
||||
|
@ -301,7 +301,7 @@ void nsStr::Truncate(nsStr& aDest,PRUint32 aDestOffset,nsIMemoryAgent* anAgent){
|
|||
*/
|
||||
void nsStr::ChangeCase(nsStr& aDest,PRBool aToUpper) {
|
||||
// somehow UnicharUtil return failed, fallback to the old ascii only code
|
||||
gCaseConverters[aDest.mMultibyte](aDest.mStr.mCharBuf,aDest.mLength,aToUpper);
|
||||
gCaseConverters[aDest.mMultibyte](aDest.mStr,aDest.mLength,aToUpper);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -311,7 +311,7 @@ void nsStr::ChangeCase(nsStr& aDest,PRBool aToUpper) {
|
|||
* @return
|
||||
*/
|
||||
void nsStr::StripChars(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,const char* aCharSet){
|
||||
PRUint32 aNewLen=gStripChars[aDest.mMultibyte](aDest.mStr.mCharBuf,aDestOffset,aCount,aCharSet);
|
||||
PRUint32 aNewLen=gStripChars[aDest.mMultibyte](aDest.mStr,aDestOffset,aCount,aCharSet);
|
||||
aDest.mLength=aNewLen;
|
||||
}
|
||||
|
||||
|
@ -323,7 +323,7 @@ void nsStr::StripChars(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,const ch
|
|||
* @return
|
||||
*/
|
||||
void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
||||
PRUint32 aNewLen=gTrimChars[aDest.mMultibyte](aDest.mStr.mCharBuf,aDest.mLength,aSet,aEliminateLeading,aEliminateTrailing);
|
||||
PRUint32 aNewLen=gTrimChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,aSet,aEliminateLeading,aEliminateTrailing);
|
||||
aDest.mLength=aNewLen;
|
||||
}
|
||||
|
||||
|
@ -334,7 +334,7 @@ void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool a
|
|||
* @return
|
||||
*/
|
||||
void nsStr::CompressSet(nsStr& aDest,const char* aSet,PRUint32 aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
||||
PRUint32 aNewLen=gCompressChars[aDest.mMultibyte](aDest.mStr.mCharBuf,aDest.mLength,aSet,aChar,aEliminateLeading,aEliminateTrailing);
|
||||
PRUint32 aNewLen=gCompressChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,aSet,aChar,aEliminateLeading,aEliminateTrailing);
|
||||
aDest.mLength=aNewLen;
|
||||
}
|
||||
|
||||
|
@ -385,7 +385,7 @@ PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnor
|
|||
* @return
|
||||
*/
|
||||
PRInt32 nsStr::FindChar(const nsStr& aDest,const PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gFindChars[aDest.mMultibyte](aDest.mStr.mCharBuf,aDest.mLength,0,aChar,aIgnoreCase);
|
||||
PRInt32 result=gFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,0,aChar,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -403,7 +403,7 @@ PRInt32 nsStr::FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnore
|
|||
|
||||
while(++index<aDest.mLength) {
|
||||
PRUnichar theChar=GetCharAt(aDest,index);
|
||||
thePos=gFindChars[aSet.mMultibyte](aSet.mStr.mCharBuf,aSet.mLength,0,theChar,aIgnoreCase);
|
||||
thePos=gFindChars[aSet.mMultibyte](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase);
|
||||
if(kNotFound!=thePos)
|
||||
return index;
|
||||
} //while
|
||||
|
@ -460,7 +460,7 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgno
|
|||
* @return
|
||||
*/
|
||||
PRInt32 nsStr::RFindChar(const nsStr& aDest,const PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gRFindChars[aDest.mMultibyte](aDest.mStr.mCharBuf,aDest.mLength,0,aChar,aIgnoreCase);
|
||||
PRInt32 result=gRFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,0,aChar,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -477,7 +477,7 @@ PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnor
|
|||
|
||||
while(--offset>=0) {
|
||||
PRUnichar theChar=GetCharAt(aDest,offset);
|
||||
thePos=gRFindChars[aSet.mMultibyte](aSet.mStr.mCharBuf,aSet.mLength,0,theChar,aIgnoreCase);
|
||||
thePos=gRFindChars[aSet.mMultibyte](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase);
|
||||
if(kNotFound!=thePos)
|
||||
return offset;
|
||||
} //while
|
||||
|
@ -503,7 +503,7 @@ PRInt32 nsStr::Compare(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PR
|
|||
}
|
||||
|
||||
int maxlen=(aSource.mLength<aDest.mLength) ? aDest.mLength : aSource.mLength;
|
||||
PRInt32 result=(*gCompare[aDest.mMultibyte][aSource.mMultibyte])(aDest.mStr.mCharBuf,aSource.mStr.mCharBuf,maxlen,aIgnoreCase);
|
||||
PRInt32 result=(*gCompare[aDest.mMultibyte][aSource.mMultibyte])(aDest.mStr,aSource.mStr,maxlen,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ union UStrPtr {
|
|||
|
||||
struct nsBufDescriptor {
|
||||
nsBufDescriptor(char* aBuffer,PRUint32 aBufferSize,eCharSize aCharSize,PRBool aOwnsBuffer) {
|
||||
mStr.mCharBuf=aBuffer;
|
||||
mStr=aBuffer;
|
||||
mMultibyte=aCharSize;
|
||||
mCapacity=(aBufferSize>>mMultibyte)-1;
|
||||
mOwnsBuffer=aOwnsBuffer;
|
||||
|
@ -73,7 +73,11 @@ struct nsBufDescriptor {
|
|||
PRUint32 mCapacity;
|
||||
PRBool mOwnsBuffer;
|
||||
eCharSize mMultibyte;
|
||||
UStrPtr mStr;
|
||||
// UStrPtr mStr;
|
||||
union {
|
||||
char* mStr;
|
||||
PRUnichar* mUStr;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
@ -265,7 +269,10 @@ struct nsStr {
|
|||
PRUint32 mCapacity: 30;
|
||||
PRUint32 mOwnsBuffer: 1;
|
||||
PRUint32 mUnused: 1;
|
||||
UStrPtr mStr;
|
||||
union {
|
||||
char* mStr;
|
||||
PRUnichar* mUStr;
|
||||
};
|
||||
};
|
||||
|
||||
/**************************************************************
|
||||
|
@ -296,8 +303,8 @@ inline void ToRange(PRUint32& aValue,PRUint32 aMin,PRUint32 aMax){
|
|||
|
||||
inline void AddNullTerminator(nsStr& aDest) {
|
||||
if(eTwoByte==aDest.mMultibyte)
|
||||
aDest.mStr.mUnicharBuf[aDest.mLength]=0;
|
||||
else aDest.mStr.mCharBuf[aDest.mLength]=0;
|
||||
aDest.mUStr[aDest.mLength]=0;
|
||||
else aDest.mStr[aDest.mLength]=0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
@ -331,17 +338,17 @@ public:
|
|||
|
||||
aDest.mCapacity=theNewCapacity++;
|
||||
size_t theSize=(theNewCapacity<<aDest.mMultibyte);
|
||||
aDest.mStr.mCharBuf=new char[theSize];
|
||||
aDest.mStr=new char[theSize];
|
||||
aDest.mOwnsBuffer=1;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
virtual PRBool Free(nsStr& aDest){
|
||||
if(aDest.mStr.mCharBuf){
|
||||
if(aDest.mStr){
|
||||
if(aDest.mOwnsBuffer){
|
||||
delete [] aDest.mStr.mCharBuf;
|
||||
delete [] aDest.mStr;
|
||||
}
|
||||
aDest.mStr.mCharBuf=0;
|
||||
aDest.mStr=0;
|
||||
aDest.mOwnsBuffer=0;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
|
|
@ -295,7 +295,7 @@ void nsString2::SetCapacity(PRUint32 aLength) {
|
|||
*/
|
||||
char* nsString2::GetBuffer(void) const {
|
||||
if(!mMultibyte)
|
||||
return mStr.mCharBuf;
|
||||
return mStr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -307,7 +307,7 @@ char* nsString2::GetBuffer(void) const {
|
|||
*/
|
||||
PRUnichar* nsString2::GetUnicode(void) const {
|
||||
if(mMultibyte)
|
||||
return (PRUnichar*)mStr.mUnicharBuf;
|
||||
return (PRUnichar*)mUStr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -334,8 +334,8 @@ PRBool nsString2::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
|
|||
PRBool result=PR_FALSE;
|
||||
if(anIndex<mLength){
|
||||
if(!mMultibyte)
|
||||
mStr.mCharBuf[anIndex]=char(aChar);
|
||||
else mStr.mUnicharBuf[anIndex]=aChar;
|
||||
mStr[anIndex]=char(aChar);
|
||||
else mUStr[anIndex]=aChar;
|
||||
result=PR_TRUE;
|
||||
}
|
||||
return result;
|
||||
|
@ -433,9 +433,9 @@ void nsString2::ToUCS2(PRUint32 aStartOffset){
|
|||
if(mMultibyte) {
|
||||
PRUint32 theIndex=0;
|
||||
for(theIndex=aStartOffset;theIndex<mLength;theIndex++){
|
||||
unsigned char ch = (unsigned char)mStr.mUnicharBuf[theIndex];
|
||||
if( 0x0080 == (0xFFE0 & (mStr.mUnicharBuf[theIndex])) ) // limit to only 0x0080 to 0x009F
|
||||
mStr.mUnicharBuf[theIndex]=gToUCS2[ch];
|
||||
unsigned char ch = (unsigned char)mUStr[theIndex];
|
||||
if( 0x0080 == (0xFFE0 & (mUStr[theIndex])) ) // limit to only 0x0080 to 0x009F
|
||||
mUStr[theIndex]=gToUCS2[ch];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -517,12 +517,12 @@ nsString2& nsString2::ReplaceChar(PRUnichar aSourceChar, PRUnichar aDestChar) {
|
|||
PRUint32 theIndex=0;
|
||||
for(theIndex=0;theIndex<mLength;theIndex++){
|
||||
if(mMultibyte) {
|
||||
if(mStr.mUnicharBuf[theIndex]==aSourceChar)
|
||||
mStr.mUnicharBuf[theIndex]=aDestChar;
|
||||
if(mUStr[theIndex]==aSourceChar)
|
||||
mUStr[theIndex]=aDestChar;
|
||||
}
|
||||
else {
|
||||
if(mStr.mCharBuf[theIndex]==aSourceChar)
|
||||
mStr.mCharBuf[theIndex]=(char)aDestChar;
|
||||
if(mStr[theIndex]==aSourceChar)
|
||||
mStr[theIndex]=(char)aDestChar;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
|
@ -596,8 +596,8 @@ nsString2* nsString2::ToNewString() const {
|
|||
*/
|
||||
char* nsString2::ToNewCString() const {
|
||||
nsString2 temp(*this,eOneByte);
|
||||
char* result=temp.mStr.mCharBuf;
|
||||
temp.mStr.mCharBuf=0;
|
||||
char* result=temp.mStr;
|
||||
temp.mStr=0;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -608,8 +608,8 @@ char* nsString2::ToNewCString() const {
|
|||
*/
|
||||
PRUnichar* nsString2::ToNewUnicode() const {
|
||||
nsString2 temp(*this,eTwoByte);
|
||||
PRUnichar* result=temp.mStr.mUnicharBuf;
|
||||
temp.mStr.mUnicharBuf=0;
|
||||
PRUnichar* result=temp.mUStr;
|
||||
temp.mUStr=0;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -623,7 +623,7 @@ char* nsString2::ToCString(char* aBuf, PRUint32 aBufLength) const{
|
|||
if(aBuf) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mStr.mCharBuf=aBuf;
|
||||
theTempStr.mStr=aBuf;
|
||||
theTempStr.mCapacity=aBufLength;
|
||||
nsStr::Assign(theTempStr,*this,0,mLength,mAgent);
|
||||
}
|
||||
|
@ -666,7 +666,7 @@ PRInt32 nsString2::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
|||
nsAutoString2 theString(*this,eOneByte);
|
||||
|
||||
PRInt32 decPt=theString.FindChar(theString,'.',PR_TRUE,0);
|
||||
char* cp = (kNotFound==decPt) ? theString.mStr.mCharBuf + theString.mLength-1 : theString.mStr.mCharBuf+decPt-1;
|
||||
char* cp = (kNotFound==decPt) ? theString.mStr + theString.mLength-1 : theString.mStr+decPt-1;
|
||||
char digit=0;
|
||||
char theChar;
|
||||
// PRInt32 theShift=0;
|
||||
|
@ -675,7 +675,7 @@ PRInt32 nsString2::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
|||
*anErrorCode = (0<theString.mLength) ? NS_OK : NS_ERROR_ILLEGAL_VALUE;
|
||||
|
||||
// Skip trailing non-numeric...
|
||||
while (cp >= theString.mStr.mCharBuf) {
|
||||
while (cp >= theString.mStr) {
|
||||
theChar = toupper(*cp);
|
||||
if((theChar>='0') && (theChar<='9')){
|
||||
break;
|
||||
|
@ -687,7 +687,7 @@ PRInt32 nsString2::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
|||
}
|
||||
|
||||
//now iterate the numeric chars and build our result
|
||||
while(cp>=theString.mStr.mCharBuf) {
|
||||
while(cp>=theString.mStr) {
|
||||
theChar=toupper(*cp--);
|
||||
if((theChar>='0') && (theChar<='9')){
|
||||
digit=theChar-'0';
|
||||
|
@ -845,7 +845,7 @@ nsString2& nsString2::Append(const char* aCString,PRInt32 aCount) {
|
|||
if(aCString){
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eOneByte);
|
||||
theTemp.mStr.mCharBuf=(char*)aCString;
|
||||
theTemp.mStr=(char*)aCString;
|
||||
theTemp.mLength=nsCRT::strlen(aCString);
|
||||
if(-1==aCount) aCount=theTemp.mLength;
|
||||
nsStr::Append(*this,theTemp,0,aCount,mAgent);
|
||||
|
@ -864,7 +864,7 @@ nsString2& nsString2::Append(const PRUnichar* aString,PRInt32 aCount) {
|
|||
if(aString){
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eTwoByte);
|
||||
theTemp.mStr.mUnicharBuf=(PRUnichar*)aString;
|
||||
theTemp.mUStr=(PRUnichar*)aString;
|
||||
theTemp.mLength=nsCRT::strlen(aString);
|
||||
if(-1==aCount) aCount=theTemp.mLength;
|
||||
nsStr::Append(*this,theTemp,0,aCount,mAgent);
|
||||
|
@ -884,7 +884,7 @@ nsString2& nsString2::Append(char aChar) {
|
|||
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eOneByte);
|
||||
theTemp.mStr.mCharBuf=buf;
|
||||
theTemp.mStr=buf;
|
||||
theTemp.mLength=1;
|
||||
nsStr::Append(*this,theTemp,0,1,mAgent);
|
||||
return *this;
|
||||
|
@ -902,7 +902,7 @@ nsString2& nsString2::Append(PRUnichar aChar) {
|
|||
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eTwoByte);
|
||||
theTemp.mStr.mUnicharBuf=buf;
|
||||
theTemp.mUStr=buf;
|
||||
theTemp.mLength=1;
|
||||
nsStr::Append(*this,theTemp,0,1,mAgent);
|
||||
return *this;
|
||||
|
@ -1020,7 +1020,7 @@ nsString2& nsString2::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCou
|
|||
if(0<aCount) {
|
||||
nsStr theTemp;
|
||||
nsStr::Initialize(theTemp,eOneByte);
|
||||
theTemp.mStr.mCharBuf=(char*)aCString;
|
||||
theTemp.mStr=(char*)aCString;
|
||||
theTemp.mLength=nsCRT::strlen(aCString);
|
||||
if(theTemp.mLength){
|
||||
nsStr::Insert(*this,anOffset,theTemp,0,aCount,0);
|
||||
|
@ -1067,7 +1067,7 @@ nsString2& nsString2::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32
|
|||
if(0<aCount) {
|
||||
nsStr theTemp;
|
||||
nsStr::Initialize(theTemp,eTwoByte);
|
||||
theTemp.mStr.mUnicharBuf=(PRUnichar*)aString;
|
||||
theTemp.mUStr=(PRUnichar*)aString;
|
||||
theTemp.mLength=nsCRT::strlen(aString);
|
||||
if(theTemp.mLength){
|
||||
nsStr::Insert(*this,anOffset,theTemp,0,aCount,0);
|
||||
|
@ -1092,7 +1092,7 @@ nsString2& nsString2::Insert(PRUnichar aChar,PRUint32 anOffset){
|
|||
theBuffer[0]=aChar;
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mStr.mUnicharBuf=theBuffer;
|
||||
theTempStr.mUStr=theBuffer;
|
||||
theTempStr.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,theTempStr,0,1,0);
|
||||
return *this;
|
||||
|
@ -1156,7 +1156,7 @@ PRInt32 nsString2::Find(const char* aCString,PRBool aIgnoreCase) const{
|
|||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCString);
|
||||
theTempStr.mStr.mCharBuf=(char*)aCString;
|
||||
theTempStr.mStr=(char*)aCString;
|
||||
result=nsStr::FindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
|
@ -1177,7 +1177,7 @@ PRInt32 nsString2::Find(const PRUnichar* aString,PRBool aIgnoreCase) const{
|
|||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mStr.mUnicharBuf=(PRUnichar*)aString;
|
||||
theTempStr.mUStr=(PRUnichar*)aString;
|
||||
result=nsStr::FindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
|
@ -1222,7 +1222,7 @@ PRInt32 nsString2::FindCharInSet(const char* aCStringSet,PRUint32 anOffset) cons
|
|||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCStringSet);
|
||||
theTempStr.mStr.mCharBuf=(char*)aCStringSet;
|
||||
theTempStr.mStr=(char*)aCStringSet;
|
||||
result=nsStr::FindCharInSet(*this,theTempStr,PR_FALSE,anOffset);
|
||||
}
|
||||
return result;
|
||||
|
@ -1255,7 +1255,7 @@ PRInt32 nsString2::RFindCharInSet(const char* aCStringSet,PRUint32 anOffset) con
|
|||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCStringSet);
|
||||
theTempStr.mStr.mCharBuf=(char*)aCStringSet;
|
||||
theTempStr.mStr=(char*)aCStringSet;
|
||||
result=nsStr::RFindCharInSet(*this,theTempStr,PR_FALSE,anOffset);
|
||||
}
|
||||
return result;
|
||||
|
@ -1300,7 +1300,7 @@ PRInt32 nsString2::RFind(const char* aString,PRBool aIgnoreCase) const{
|
|||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mStr.mCharBuf=(char*)aString;
|
||||
theTempStr.mStr=(char*)aString;
|
||||
result=nsStr::RFindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
|
@ -1337,7 +1337,7 @@ PRInt32 nsString2::Compare(const char *aCString,PRBool aIgnoreCase,PRInt32 aLeng
|
|||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCString);
|
||||
theTempStr.mStr.mCharBuf=(char*)aCString;
|
||||
theTempStr.mStr=(char*)aCString;
|
||||
return nsStr::Compare(*this,theTempStr,aLength,aIgnoreCase);
|
||||
}
|
||||
return 0;
|
||||
|
@ -1357,7 +1357,7 @@ PRInt32 nsString2::Compare(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 a
|
|||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mStr.mUnicharBuf=(PRUnichar*)aString;
|
||||
theTempStr.mUStr=(PRUnichar*)aString;
|
||||
return nsStr::Compare(*this,theTempStr,aLength,aIgnoreCase);
|
||||
}
|
||||
return 0;
|
||||
|
@ -1501,7 +1501,7 @@ PRBool nsString2::Equals(const nsIAtom* aAtom,PRBool aIgnoreCase) const{
|
|||
NS_ASSERTION(0!=aAtom,kNullPointerError);
|
||||
PRBool result=PR_FALSE;
|
||||
if(aAtom){
|
||||
PRInt32 cmp=nsCRT::strcasecmp(mStr.mUnicharBuf,aAtom->GetUnicode());
|
||||
PRInt32 cmp=nsCRT::strcasecmp(mUStr,aAtom->GetUnicode());
|
||||
result=PRBool(0==cmp);
|
||||
}
|
||||
return result;
|
||||
|
@ -1573,7 +1573,6 @@ PRBool nsString2::IsDigit(PRUnichar aChar) {
|
|||
****************************************************************************/
|
||||
|
||||
#if 0
|
||||
|
||||
class nsStringRecycler {
|
||||
public:
|
||||
nsStringRecycler() : mDeque(0) {
|
||||
|
@ -1634,7 +1633,7 @@ void nsString2::Recycle(nsString2* aString){
|
|||
*/
|
||||
void nsString2::DebugDump(ostream& aStream) const {
|
||||
for(PRUint32 i=0;i<mLength;i++) {
|
||||
aStream <<mStr.mCharBuf[i];
|
||||
aStream <<mStr[i];
|
||||
}
|
||||
aStream << endl;
|
||||
}
|
||||
|
@ -1647,7 +1646,7 @@ void nsString2::DebugDump(ostream& aStream) const {
|
|||
*/
|
||||
ostream& operator<<(ostream& os,nsString2& aString){
|
||||
if(PR_FALSE==aString.mMultibyte) {
|
||||
os<<aString.mStr.mCharBuf;
|
||||
os<<aString.mStr;
|
||||
}
|
||||
else{
|
||||
char* theStr=aString.ToNewCString();
|
||||
|
|
Загрузка…
Ссылка в новой задаче