added nsStringTokenizer.* files; but not in the makefiles yet

This commit is contained in:
rickg%netscape.com 1999-07-09 05:11:25 +00:00
Родитель a010c41a75
Коммит 805dbdcc10
20 изменённых файлов: 8193 добавлений и 10557 удалений

Просмотреть файл

@ -31,8 +31,8 @@
#include "nsStr.h" #include "nsStr.h"
#include "bufferRoutines.h" #include "bufferRoutines.h"
#include "stdio.h" //only used for printf #include "stdio.h" //only used for printf
#include "nsDeque.h"
#include "nsCRT.h" #include "nsCRT.h"
#include "nsDeque.h"
static const char* kFoolMsg = "Error: Some fool overwrote the shared buffer."; static const char* kFoolMsg = "Error: Some fool overwrote the shared buffer.";
@ -44,6 +44,8 @@ static const char* kFoolMsg = "Error: Some fool overwrote the shared buffer.";
/************************************************************** /**************************************************************
Define the char* (pooled) deallocator class... Define the char* (pooled) deallocator class...
**************************************************************/ **************************************************************/
/*
class nsBufferDeallocator: public nsDequeFunctor{ class nsBufferDeallocator: public nsDequeFunctor{
public: public:
virtual void* operator()(void* anObject) { virtual void* operator()(void* anObject) {
@ -53,12 +55,6 @@ public:
} }
}; };
/**
*
* @update gess10/30/98
* @param
* @return
*/
class nsPoolingMemoryAgent : public nsMemoryAgent{ class nsPoolingMemoryAgent : public nsMemoryAgent{
public: public:
nsPoolingMemoryAgent() { nsPoolingMemoryAgent() {
@ -128,6 +124,8 @@ public:
nsDeque* mPools[16]; nsDeque* mPools[16];
}; };
*/
static char* gCommonEmptyBuffer=0; static char* gCommonEmptyBuffer=0;
/** /**
* *
@ -151,7 +149,8 @@ char* GetSharedEmptyBuffer() {
} }
/** /**
* * This method initializes all the members of the nsStr structure
*
* @update gess10/30/98 * @update gess10/30/98
* @param * @param
* @return * @return
@ -166,7 +165,7 @@ void nsStr::Initialize(nsStr& aDest,eCharSize aCharSize) {
} }
/** /**
* * This method initializes all the members of the nsStr structure
* @update gess10/30/98 * @update gess10/30/98
* @param * @param
* @return * @return
@ -193,7 +192,7 @@ nsIMemoryAgent* GetDefaultAgent(void){
} }
/** /**
* * This member destroys the memory buffer owned by an nsStr object (if it actually owns it)
* @update gess10/30/98 * @update gess10/30/98
* @param * @param
* @return * @return
@ -386,9 +385,10 @@ void nsStr::Truncate(nsStr& aDest,PRUint32 aDestOffset,nsIMemoryAgent* anAgent){
/** /**
* * This method forces the given string to upper or lowercase
* @update gess1/7/99 * @update gess1/7/99
* @param * @param aDest is the string you're going to change
* @param aToUpper: if TRUE, then we go uppercase, otherwise we go lowercase
* @return * @return
*/ */
void nsStr::ChangeCase(nsStr& aDest,PRBool aToUpper) { void nsStr::ChangeCase(nsStr& aDest,PRBool aToUpper) {
@ -397,19 +397,6 @@ void nsStr::ChangeCase(nsStr& aDest,PRBool aToUpper) {
NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg); NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg);
} }
/**
*
* @update gess1/7/99
* @param
* @return
*/
void nsStr::StripChars(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,const char* aCharSet){
PRUint32 aNewLen=gStripChars[aDest.mCharSize](aDest.mStr,aDestOffset,aCount,aCharSet);
aDest.mLength=aNewLen;
NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg);
}
/** /**
* *
* @update gess1/7/99 * @update gess1/7/99
@ -417,8 +404,43 @@ void nsStr::StripChars(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,const ch
* @return * @return
*/ */
void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){ void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){
PRUint32 aNewLen=gTrimChars[aDest.mCharSize](aDest.mStr,aDest.mLength,aSet,aEliminateLeading,aEliminateTrailing);
aDest.mLength=aNewLen; if((aDest.mLength>0) && aSet){
PRInt32 theIndex=-1;
PRInt32 theMax=aDest.mLength;
PRInt32 theSetLen=nsCRT::strlen(aSet);
if(aEliminateLeading) {
while(++theIndex<=theMax) {
PRUnichar theChar=GetCharAt(aDest,theIndex);
PRInt32 thePos=gFindChars[eOneByte](aSet,theSetLen,0,theChar,PR_FALSE);
if(kNotFound==thePos)
break;
}
if(0<theIndex) {
if(theIndex<theMax) {
Delete(aDest,0,theIndex,0);
}
else Truncate(aDest,0);
}
}
if(aEliminateTrailing) {
theIndex=aDest.mLength;
PRInt32 theNewLen=theIndex;
while(--theIndex>0) {
PRUnichar theChar=GetCharAt(aDest,theIndex); //read at end now...
PRInt32 thePos=gFindChars[eOneByte](aSet,theSetLen,0,theChar,PR_FALSE);
if(kNotFound<thePos)
theNewLen=theIndex;
else break;
}
if(theNewLen<theMax) {
Truncate(aDest,theNewLen);
}
}
}
NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg); NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg);
} }
@ -428,8 +450,9 @@ void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool a
* @param * @param
* @return * @return
*/ */
void nsStr::CompressSet(nsStr& aDest,const char* aSet,PRUint32 aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing){ void nsStr::CompressSet(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){
PRUint32 aNewLen=gCompressChars[aDest.mCharSize](aDest.mStr,aDest.mLength,aSet,aChar,aEliminateLeading,aEliminateTrailing); Trim(aDest,aSet,aEliminateLeading,aEliminateTrailing);
PRUint32 aNewLen=gCompressChars[aDest.mCharSize](aDest.mStr,aDest.mLength,aSet);
aDest.mLength=aNewLen; aDest.mLength=aNewLen;
NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg); NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg);
} }
@ -439,15 +462,28 @@ void nsStr::CompressSet(nsStr& aDest,const char* aSet,PRUint32 aChar,PRBool aEli
**************************************************************/ **************************************************************/
/**
* This searches aDest for a given substring
*
* @update gess 3/25/98
* @param aDest string to search
* @param aTarget is the substring you're trying to find.
* @param aIgnorecase indicates case sensitivity of search
* @param anOffset tells us where to start the search
* @return index in aDest where member of aSet occurs, or -1 if not found
*/
PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRUint32 anOffset) { PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRUint32 anOffset) {
if((aDest.mLength>0) && (aTarget.mLength>0) && (anOffset<aTarget.mLength)){
int32 index=anOffset-1; PRInt32 result=kNotFound;
int32 theMax=aDest.mLength-aTarget.mLength;
if((aDest.mLength>0) && (aTarget.mLength>0)){ if(anOffset<aDest.mLength) {
int32 theTargetMax=aTarget.mLength; PRInt32 theMax=aDest.mLength-aTarget.mLength;
while(++index<=theMax) { PRInt32 index=(anOffset ? anOffset : theMax);
int32 theSubIndex=-1;
if((aDest.mLength>=aTarget.mLength) && (aTarget.mLength>0) && (index>=0)){
PRInt32 theTargetMax=aTarget.mLength;
while(index<=theMax) {
PRInt32 theSubIndex=-1;
PRBool matches=PR_TRUE; PRBool matches=PR_TRUE;
while((++theSubIndex<theTargetMax) && (matches)){ while((++theSubIndex<theTargetMax) && (matches)){
PRUnichar theChar=(aIgnoreCase) ? nsCRT::ToLower(GetCharAt(aDest,index+theSubIndex)) : GetCharAt(aDest,index+theSubIndex); PRUnichar theChar=(aIgnoreCase) ? nsCRT::ToLower(GetCharAt(aDest,index+theSubIndex)) : GetCharAt(aDest,index+theSubIndex);
@ -455,20 +491,26 @@ PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnor
matches=PRBool(theChar==theTargetChar); matches=PRBool(theChar==theTargetChar);
} }
if(matches) { if(matches) {
return index; result=index;
break;
} }
} index++;
} //while
}//if }//if
} }//if
return kNotFound; return result;
} }
/** /**
* * This searches aDest for a given character
* @update gess1/7/99 *
* @param * @update gess 3/25/98
* @return * @param aDest string to search
* @param char is the character you're trying to find.
* @param aIgnorecase indicates case sensitivity of search
* @param anOffset tells us where to start the search
* @return index in aDest where member of aSet occurs, or -1 if not found
*/ */
PRInt32 nsStr::FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) { PRInt32 nsStr::FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
PRInt32 result=gFindChars[aDest.mCharSize](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase); PRInt32 result=gFindChars[aDest.mCharSize](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase);
@ -477,17 +519,20 @@ PRInt32 nsStr::FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,P
/** /**
* * This searches aDest for a character found in aSet.
* *
* @update gess 3/25/98 * @update gess 3/25/98
* @param * @param aDest string to search
* @return * @param aSet contains a list of chars to be searched for
* @param aIgnorecase indicates case sensitivity of search
* @param anOffset tells us where to start the search
* @return index in aDest where member of aSet occurs, or -1 if not found
*/ */
PRInt32 nsStr::FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRUint32 anOffset) { PRInt32 nsStr::FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRUint32 anOffset) {
PRUint32 index=anOffset-1; PRInt32 index=anOffset-1;
PRInt32 thePos; PRInt32 thePos;
while(++index<aDest.mLength) { while(++index<(PRInt32)aDest.mLength) {
PRUnichar theChar=GetCharAt(aDest,index); PRUnichar theChar=GetCharAt(aDest,index);
thePos=gFindChars[aSet.mCharSize](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase); thePos=gFindChars[aSet.mCharSize](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase);
if(kNotFound!=thePos) if(kNotFound!=thePos)
@ -501,46 +546,64 @@ PRInt32 nsStr::FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnore
**************************************************************/ **************************************************************/
/**
* This searches aDest (in reverse) for a given substring
*
* @update gess 3/25/98
* @param aDest string to search
* @param aTarget is the substring you're trying to find.
* @param aIgnorecase indicates case sensitivity of search
* @param anOffset tells us where to start the search
* @return index in aDest where member of aSet occurs, or -1 if not found
*/
PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRUint32 anOffset) { PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRUint32 anOffset) {
PRInt32 index=(anOffset ? anOffset : aDest.mLength-aTarget.mLength+1);
PRInt32 result=kNotFound; PRInt32 result=kNotFound;
if((aDest.mLength>0) && (aTarget.mLength>0)){ if(anOffset<aDest.mLength) {
PRInt32 index=(anOffset ? anOffset : aDest.mLength-aTarget.mLength);
if((aDest.mLength>=aTarget.mLength) && (aTarget.mLength>0) && (index>=0)){
nsStr theCopy; nsStr theCopy;
nsStr::Initialize(theCopy,eOneByte); nsStr::Initialize(theCopy,eOneByte);
nsStr::Assign(theCopy,aTarget,0,aTarget.mLength,0); nsStr::Assign(theCopy,aTarget,0,aTarget.mLength,0);
if(aIgnoreCase){ if(aIgnoreCase){
nsStr::ChangeCase(theCopy,PR_FALSE); //force to lowercase nsStr::ChangeCase(theCopy,PR_FALSE); //force to lowercase
}
int32 theTargetMax=theCopy.mLength;
while(index--) {
int32 theSubIndex=-1;
PRBool matches=PR_TRUE;
if(anOffset+theCopy.mLength<=aDest.mLength) {
while((++theSubIndex<theTargetMax) && (matches)){
PRUnichar theDestChar=(aIgnoreCase) ? nsCRT::ToLower(GetCharAt(aDest,index+theSubIndex)) : GetCharAt(aDest,index+theSubIndex);
PRUnichar theTargetChar=GetCharAt(theCopy,theSubIndex);
matches=PRBool(theDestChar==theTargetChar);
} //while
} //if
if(matches) {
result=index;
break;
} }
} //while
nsStr::Destroy(theCopy,0); PRInt32 theTargetMax=theCopy.mLength;
while(index>=0) {
PRInt32 theSubIndex=-1;
PRBool matches=PR_FALSE;
if(index+theCopy.mLength<=aDest.mLength) {
matches=PR_TRUE;
while((++theSubIndex<theTargetMax) && (matches)){
PRUnichar theDestChar=(aIgnoreCase) ? nsCRT::ToLower(GetCharAt(aDest,index+theSubIndex)) : GetCharAt(aDest,index+theSubIndex);
PRUnichar theTargetChar=GetCharAt(theCopy,theSubIndex);
matches=PRBool(theDestChar==theTargetChar);
} //while
} //if
if(matches) {
result=index;
break;
}
index--;
} //while
nsStr::Destroy(theCopy,0);
}//if
}//if }//if
return result; return result;
} }
/** /**
* * This searches aDest (in reverse) for a given character
* @update gess1/7/99 *
* @param * @update gess 3/25/98
* @return * @param aDest string to search
* @param char is the character you're trying to find.
* @param aIgnorecase indicates case sensitivity of search
* @param anOffset tells us where to start the search
* @return index in aDest where member of aSet occurs, or -1 if not found
*/ */
PRInt32 nsStr::RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) { PRInt32 nsStr::RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
PRInt32 result=gRFindChars[aDest.mCharSize](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase); PRInt32 result=gRFindChars[aDest.mCharSize](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase);
@ -548,14 +611,17 @@ PRInt32 nsStr::RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,
} }
/** /**
* * This searches aDest (in reverese) for a character found in aSet.
* *
* @update gess 3/25/98 * @update gess 3/25/98
* @param * @param aDest string to search
* @return * @param aSet contains a list of chars to be searched for
* @param aIgnorecase indicates case sensitivity of search
* @param anOffset tells us where to start the search
* @return index in aDest where member of aSet occurs, or -1 if not found
*/ */
PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRUint32 anOffset) { PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRUint32 anOffset) {
PRUint32 offset=aDest.mLength-anOffset; PRInt32 offset=aDest.mLength-anOffset;
PRInt32 thePos; PRInt32 thePos;
while(--offset>=0) { while(--offset>=0) {
@ -569,24 +635,61 @@ PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnor
/** /**
* * Compare source and dest strings, up to an (optional max) number of chars
* @update gess11/12/98 * @param aDest is the first str to compare
* @param * @param aSource is the second str to compare
* @param aCount -- if (-1), then we use length of longer string; if (0<aCount) then it gives the max # of chars to compare
* @param aIgnorecase tells us whether to search with case sensitivity
* @return aDest<aSource=-1;aDest==aSource==0;aDest>aSource=1 * @return aDest<aSource=-1;aDest==aSource==0;aDest>aSource=1
*/ */
PRInt32 nsStr::Compare(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) { PRInt32 nsStr::Compare(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) {
int minlen=(aSource.mLength<aDest.mLength) ? aSource.mLength : aDest.mLength; PRInt32 result=0;
if(0==minlen) { if(aCount) {
if ((aDest.mLength == 0) && (aSource.mLength == 0)) PRInt32 minlen=(aSource.mLength<aDest.mLength) ? aSource.mLength : aDest.mLength;
return 0;
if (aDest.mLength == 0) if(0==minlen) {
return -1; if ((aDest.mLength == 0) && (aSource.mLength == 0))
return 1; return 0;
if (aDest.mLength == 0)
return -1;
return 1;
}
PRInt32 maxlen=(aSource.mLength<aDest.mLength) ? aDest.mLength : aSource.mLength;
aCount = (aCount<0) ? maxlen : MinInt(aCount,maxlen);
result=(*gCompare[aDest.mCharSize][aSource.mCharSize])(aDest.mStr,aSource.mStr,aCount,aIgnoreCase);
} }
int maxlen=(aSource.mLength<aDest.mLength) ? aDest.mLength : aSource.mLength;
PRInt32 result=(*gCompare[aDest.mCharSize][aSource.mCharSize])(aDest.mStr,aSource.mStr,maxlen,aIgnoreCase);
return result; return result;
} }
//----------------------------------------------------------------------------------------
CSharedStrBuffer::CSharedStrBuffer(char* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength) {
mBuffer=aString;
mCharSize=eOneByte;
mStackBased=aStackBased;
mLength=mCapacity=0;
if(aString && aCapacity>1) {
mCapacity=aCapacity-1;
mLength=(-1==aLength) ? strlen(aString) : aLength;
if(mLength>PRInt32(mCapacity))
mLength=mCapacity;
}
}
CSharedStrBuffer::CSharedStrBuffer(PRUnichar* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength) {
mBuffer=(char*)aString;
mCharSize=eTwoByte;
mStackBased=aStackBased;
mLength=mCapacity=0;
if(aString && aCapacity>1) {
mCapacity=aCapacity-1;
mLength=(-1==aLength) ? nsCRT::strlen(aString) : aLength;
if(mLength>PRInt32(mCapacity))
mLength=mCapacity;
}
}
//----------------------------------------------------------------------------------------

Просмотреть файл

@ -48,6 +48,10 @@
enum eCharSize {eOneByte=0,eTwoByte=1}; enum eCharSize {eOneByte=0,eTwoByte=1};
#define kDefaultCharSize eTwoByte #define kDefaultCharSize eTwoByte
#define kRadix10 (10)
#define kRadix16 (16)
#define kAutoDetect (100)
#define kRadixUnknown (kAutoDetect+1)
const PRInt32 kNotFound = -1; const PRInt32 kNotFound = -1;
@ -55,6 +59,21 @@ class nsIMemoryAgent;
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
class CSharedStrBuffer {
public:
CSharedStrBuffer(char* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength=-1);
CSharedStrBuffer(PRUnichar* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength=-1);
char* mBuffer;
eCharSize mCharSize;
PRUint32 mCapacity;
PRInt32 mLength;
PRBool mStackBased;
};
//----------------------------------------------------------------------------------------
struct nsStr { struct nsStr {
@ -169,16 +188,6 @@ struct nsStr {
*/ */
static void ChangeCase(nsStr& aDest,PRBool aToUpper); static void ChangeCase(nsStr& aDest,PRBool aToUpper);
/**
* This method removes chars (given in aSet) from the given buffer
*
* @update gess 01/04/99
* @param aString is the buffer to be manipulated
* @param aDestOffset is starting pos in buffer for manipulation
* @param aCount is the number of chars to compare
* @param aSet tells us which chars to remove from given buffer
*/
static void StripChars(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,const char* aCharSet);
/** /**
* This method trims chars (given in aSet) from the edges of given buffer * This method trims chars (given in aSet) from the edges of given buffer
@ -201,7 +210,7 @@ struct nsStr {
* @param aEliminateLeading tells us whether to strip chars from the start of the 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 * @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
*/ */
static void CompressSet(nsStr& aDest,const char* aSet,PRUint32 aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing); static void CompressSet(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing);
/** /**
* This method compares the data bewteen two nsStr's * This method compares the data bewteen two nsStr's

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -30,19 +30,17 @@
***********************************************************************/ ***********************************************************************/
#ifndef _nsString2 #ifndef _nsString_
#define _nsString2 #define _nsString_
#include "prtypes.h" #include "prtypes.h"
#include "nscore.h" #include "nscore.h"
#include <iostream.h> #include <iostream.h>
#include <stdio.h> #include <stdio.h>
#include "nsCRT.h" #include "nsCRT.h"
#include "nsString.h"
#include "nsStr.h"
#include <iostream.h>
#include <stdio.h>
#include "nsIAtom.h" #include "nsIAtom.h"
#include "nsStr.h"
class nsISizeOfHandler; class nsISizeOfHandler;
@ -50,14 +48,9 @@ class nsISizeOfHandler;
#define nsString2 nsString #define nsString2 nsString
#define nsAutoString2 nsAutoString #define nsAutoString2 nsAutoString
#define kRadix10 (10)
#define kRadix16 (16)
#define kAutoDetect (100)
#define kRadixUnknown (kAutoDetect+1)
class NS_COM nsSubsumeStr; class NS_COM nsSubsumeStr;
class NS_COM nsString2 : public nsStr { class NS_COM nsString : public nsStr {
public: public:
@ -67,44 +60,44 @@ class NS_COM nsString2 : public nsStr {
* was to allow developers direct access to the underlying buffer for * was to allow developers direct access to the underlying buffer for
* performance reasons. * performance reasons.
*/ */
nsString2(eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAgent=0); nsString(eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAgent=0);
/** /**
* This constructor accepts an isolatin string * This constructor accepts an isolatin string
* @param aCString is a ptr to a 1-byte cstr * @param aCString is a ptr to a 1-byte cstr
*/ */
nsString2(const char* aCString,eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAgent=0); nsString(const char* aCString,eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAgent=0);
/** /**
* This constructor accepts a unichar string * This constructor accepts a unichar string
* @param aCString is a ptr to a 2-byte cstr * @param aCString is a ptr to a 2-byte cstr
*/ */
nsString2(const PRUnichar* aString,eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAgent=0); nsString(const PRUnichar* aString,eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAgent=0);
/** /**
* This is a copy constructor that accepts an nsStr * This is a copy constructor that accepts an nsStr
* @param reference to another nsString2 * @param reference to another nsString
*/ */
nsString2(const nsStr&,eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAgent=0); nsString(const nsStr&,eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAgent=0);
/** /**
* This is our copy constructor * This is our copy constructor
* @param reference to another nsString2 * @param reference to another nsString
*/ */
nsString2(const nsString2& aString); nsString(const nsString& aString);
/** /**
* This constructor takes a subsumestr * This constructor takes a subsumestr
* @param reference to subsumestr * @param reference to subsumestr
*/ */
nsString2(nsSubsumeStr& aSubsumeStr); nsString(nsSubsumeStr& aSubsumeStr);
/** /**
* Destructor * Destructor
* *
*/ */
virtual ~nsString2(); virtual ~nsString();
/** /**
* Retrieve the length of this string * Retrieve the length of this string
@ -120,13 +113,13 @@ virtual void SizeOf(nsISizeOfHandler* aHandler) const;
/** /**
* Call this method if you want to force a different string capacity * Call this method if you want to force a different string length
* @update gess7/30/98 * @update gess7/30/98
* @param aLength -- contains new length for mStr * @param aLength -- contains new length for mStr
* @return * @return
*/ */
void SetLength(PRUint32 aLength) { void SetLength(PRUint32 aLength) {
SetCapacity(aLength); Truncate(aLength);
} }
/** /**
@ -173,7 +166,7 @@ PRBool IsEmpty(void) const {
} }
/********************************************************************** /**********************************************************************
Accessor methods... Getters/Setters...
*********************************************************************/ *********************************************************************/
const char* GetBuffer(void) const; const char* GetBuffer(void) const;
@ -188,11 +181,14 @@ PRUnichar CharAt(PRUint32 anIndex) const;
PRUnichar First(void) const; PRUnichar First(void) const;
PRUnichar Last(void) const; PRUnichar Last(void) const;
/**
* Set nth character.
*/
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex); PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
/********************************************************************** /**********************************************************************
String creation methods... String concatenation methods...
*********************************************************************/ *********************************************************************/
/** /**
@ -201,13 +197,7 @@ PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
* @return new string * @return new string
*/ */
nsSubsumeStr operator+(const nsStr& aString); nsSubsumeStr operator+(const nsStr& aString);
nsSubsumeStr operator+(const nsString& aString);
/**
* Create a new string by appending given string to this
* @param aString -- 2nd string to be appended
* @return new string
*/
nsSubsumeStr operator+(const nsString2& aString);
/** /**
* create a new string by adding this to the given buffer. * create a new string by adding this to the given buffer.
@ -260,7 +250,7 @@ void ToLowerCase();
* @update gess 7/27/98 * @update gess 7/27/98
* @param aOut is a string to contain result * @param aOut is a string to contain result
*/ */
void ToLowerCase(nsString2& aString) const; void ToLowerCase(nsString& aString) const;
/** /**
* Converts chars in this to uppercase * Converts chars in this to uppercase
@ -274,7 +264,7 @@ void ToUpperCase();
* @update gess 7/27/98 * @update gess 7/27/98
* @param aOut is a string to contain result * @param aOut is a string to contain result
*/ */
void ToUpperCase(nsString2& aString) const; void ToUpperCase(nsString& aString) const;
/** /**
@ -284,21 +274,22 @@ void ToUpperCase(nsString2& aString) const;
* @param aSet -- characters to be cut from this * @param aSet -- characters to be cut from this
* @return *this * @return *this
*/ */
nsString2& StripChars(const char* aSet); nsString& StripChars(const char* aSet);
/** /**
* This method strips whitespace throughout the string * This method strips whitespace throughout the string
* *
* @return this * @return this
*/ */
nsString2& StripWhitespace(); nsString& StripWhitespace();
/** /**
* swaps occurence of 1 string for another * swaps occurence of 1 string for another
* *
* @return this * @return this
*/ */
nsString2& ReplaceChar(PRUnichar aSourceChar,PRUnichar aDestChar); nsString& ReplaceChar(PRUnichar anOldChar,PRUnichar aNewChar);
nsString& ReplaceChar(const char* aSet,PRUnichar aNewChar);
/** /**
* This method trims characters found in aTrimSet from * This method trims characters found in aTrimSet from
@ -308,7 +299,7 @@ nsString2& ReplaceChar(PRUnichar aSourceChar,PRUnichar aDestChar);
* both ends * both ends
* @return this * @return this
*/ */
nsString2& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); nsString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/** /**
* This method strips whitespace from string. * This method strips whitespace from string.
@ -319,7 +310,7 @@ nsString2& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aElimin
* @param aEliminateTrailing controls stripping of trailing ws * @param aEliminateTrailing controls stripping of trailing ws
* @return this * @return this
*/ */
nsString2& CompressSet(const char* aSet, char aChar, PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); nsString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/** /**
* This method strips whitespace from string. * This method strips whitespace from string.
@ -330,18 +321,18 @@ nsString2& CompressSet(const char* aSet, char aChar, PRBool aEliminateLeading=PR
* @param aEliminateTrailing controls stripping of trailing ws * @param aEliminateTrailing controls stripping of trailing ws
* @return this * @return this
*/ */
nsString2& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); nsString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/********************************************************************** /**********************************************************************
string conversion methods... string conversion methods...
*********************************************************************/ *********************************************************************/
/** /**
* This method constructs a new nsString2 on the stack that is a copy * This method constructs a new nsString on the stack that is a copy
* of this string. * of this string.
* *
*/ */
nsString2* ToNewString() const; nsString* ToNewString() const;
/** /**
* Creates an ISOLatin1 clone of this string * Creates an ISOLatin1 clone of this string
@ -392,9 +383,9 @@ PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const;
* Functionally equivalent to assign or operator= * Functionally equivalent to assign or operator=
* *
*/ */
nsString2& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} nsString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsString2& SetString(const PRUnichar* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} nsString& SetString(const PRUnichar* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsString2& SetString(const nsString2& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} nsString& SetString(const nsString& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
/** /**
* assign given string to this string * assign given string to this string
@ -403,28 +394,27 @@ nsString2& SetString(const nsString2& aString,PRInt32 aLength=-1) {return Assign
if you want me to determine its length if you want me to determine its length
* @return this * @return this
*/ */
nsString2& Assign(const nsString2& aString,PRInt32 aCount=-1); nsString& Assign(const nsStr& aString,PRInt32 aCount=-1);
nsString2& Assign(const nsStr& aString,PRInt32 aCount=-1); nsString& Assign(const char* aString,PRInt32 aCount=-1);
nsString2& Assign(const char* aString,PRInt32 aCount=-1); nsString& Assign(const PRUnichar* aString,PRInt32 aCount=-1);
nsString2& Assign(const PRUnichar* aString,PRInt32 aCount=-1); nsString& Assign(char aChar);
nsString2& Assign(char aChar); nsString& Assign(PRUnichar aChar);
nsString2& Assign(PRUnichar aChar);
/** /**
* here come a bunch of assignment operators... * here come a bunch of assignment operators...
* @param aString: string to be added to this * @param aString: string to be added to this
* @return this * @return this
*/ */
nsString2& operator=(const nsString2& aString) {return Assign(aString);} nsString& operator=(const nsString& aString) {return Assign(aString);}
nsString2& operator=(const nsStr& aString) {return Assign(aString);} nsString& operator=(const nsStr& aString) {return Assign(aString);}
nsString2& operator=(char aChar) {return Assign(aChar);} nsString& operator=(char aChar) {return Assign(aChar);}
nsString2& operator=(PRUnichar aChar) {return Assign(aChar);} nsString& operator=(PRUnichar aChar) {return Assign(aChar);}
nsString2& operator=(const char* aCString) {return Assign(aCString);} nsString& operator=(const char* aCString) {return Assign(aCString);}
nsString2& operator=(const PRUnichar* aString) {return Assign(aString);} nsString& operator=(const PRUnichar* aString) {return Assign(aString);}
#ifdef AIX #ifdef AIX
nsString2& operator=(const nsSubsumeStr& aSubsumeString); // AIX requires a const here nsString& operator=(const nsSubsumeStr& aSubsumeString); // AIX requires a const here
#else #else
nsString2& operator=(nsSubsumeStr& aSubsumeString); nsString& operator=(nsSubsumeStr& aSubsumeString);
#endif #endif
/** /**
@ -432,12 +422,12 @@ nsString2& operator=(nsSubsumeStr& aSubsumeString);
* @param aString : string to be appended to this * @param aString : string to be appended to this
* @return this * @return this
*/ */
nsString2& operator+=(const nsStr& aString){return Append(aString,aString.mLength);} nsString& operator+=(const nsStr& aString){return Append(aString,aString.mLength);}
nsString2& operator+=(const nsString2& aString){return Append(aString,aString.mLength);} nsString& operator+=(const nsString& aString){return Append(aString,aString.mLength);}
nsString2& operator+=(const char* aCString) {return Append(aCString);} nsString& operator+=(const char* aCString) {return Append(aCString);}
//nsString2& operator+=(char aChar){return Append(aChar);} //nsString& operator+=(char aChar){return Append(aChar);}
nsString2& operator+=(const PRUnichar* aUCString) {return Append(aUCString);} nsString& operator+=(const PRUnichar* aUCString) {return Append(aUCString);}
nsString2& operator+=(PRUnichar aChar){return Append(aChar);} nsString& operator+=(PRUnichar aChar){return Append(aChar);}
/* /*
* Appends n characters from given string to this, * Appends n characters from given string to this,
@ -446,8 +436,8 @@ nsString2& operator+=(PRUnichar aChar){return Append(aChar);}
* @param aString is the source to be appended to this * @param aString is the source to be appended to this
* @return number of chars copied * @return number of chars copied
*/ */
nsString2& Append(const nsStr& aString) {return Append(aString,aString.mLength);} nsString& Append(const nsStr& aString) {return Append(aString,aString.mLength);}
nsString2& Append(const nsString2& aString) {return Append(aString,aString.mLength);} nsString& Append(const nsString& aString) {return Append(aString,aString.mLength);}
/* /*
@ -457,14 +447,14 @@ nsString2& Append(const nsString2& aString) {return Append(aString,aString.mLeng
* @param aCount -- number of chars to copy * @param aCount -- number of chars to copy
* @return number of chars copied * @return number of chars copied
*/ */
nsString2& Append(const nsStr& aString,PRInt32 aCount); nsString& Append(const nsStr& aString,PRInt32 aCount);
nsString2& Append(const nsString2& aString,PRInt32 aCount); nsString& Append(const nsString& aString,PRInt32 aCount);
nsString2& Append(const char* aString,PRInt32 aCount=-1); nsString& Append(const char* aString,PRInt32 aCount=-1);
nsString2& Append(const PRUnichar* aString,PRInt32 aCount=-1); nsString& Append(const PRUnichar* aString,PRInt32 aCount=-1);
nsString2& Append(char aChar); nsString& Append(char aChar);
nsString2& Append(PRUnichar aChar); nsString& Append(PRUnichar aChar);
nsString2& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16 nsString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16
nsString2& Append(float aFloat); nsString& Append(float aFloat);
/* /*
* Copies n characters from this string to given string, * Copies n characters from this string to given string,
@ -475,7 +465,7 @@ nsString2& Append(float aFloat);
* @param aCount -- number of chars to copy * @param aCount -- number of chars to copy
* @return number of chars copied * @return number of chars copied
*/ */
PRUint32 Left(nsString2& aCopy,PRInt32 aCount) const; PRUint32 Left(nsString& aCopy,PRInt32 aCount) const;
/* /*
* Copies n characters from this string to given string, * Copies n characters from this string to given string,
@ -487,7 +477,7 @@ PRUint32 Left(nsString2& aCopy,PRInt32 aCount) const;
* @param anOffset -- position where copying begins * @param anOffset -- position where copying begins
* @return number of chars copied * @return number of chars copied
*/ */
PRUint32 Mid(nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount) const; PRUint32 Mid(nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
/* /*
* Copies n characters from this string to given string, * Copies n characters from this string to given string,
@ -498,7 +488,7 @@ PRUint32 Mid(nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
* @param aCount -- number of chars to copy * @param aCount -- number of chars to copy
* @return number of chars copied * @return number of chars copied
*/ */
PRUint32 Right(nsString2& aCopy,PRInt32 aCount) const; PRUint32 Right(nsString& aCopy,PRInt32 aCount) const;
/* /*
* This method inserts n chars from given string into this * This method inserts n chars from given string into this
@ -509,7 +499,7 @@ PRUint32 Right(nsString2& aCopy,PRInt32 aCount) const;
* @param aCount -- number of chars to be copied from aCopy * @param aCount -- number of chars to be copied from aCopy
* @return number of chars inserted into this. * @return number of chars inserted into this.
*/ */
nsString2& Insert(const nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount=-1); nsString& Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
/** /**
* Insert a given string into this string at * Insert a given string into this string at
@ -519,8 +509,8 @@ nsString2& Insert(const nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
* @param anOffset is insert pos in str * @param anOffset is insert pos in str
* @return the number of chars inserted into this string * @return the number of chars inserted into this string
*/ */
nsString2& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1); nsString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
nsString2& Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1); nsString& Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
/** /**
* Insert a single char into this string at * Insert a single char into this string at
@ -530,8 +520,8 @@ nsString2& Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
* @param anOffset is insert pos in str * @param anOffset is insert pos in str
* @return the number of chars inserted into this string * @return the number of chars inserted into this string
*/ */
//nsString2& Insert(char aChar,PRUint32 anOffset); //nsString& Insert(char aChar,PRUint32 anOffset);
nsString2& Insert(PRUnichar aChar,PRUint32 anOffset); nsString& Insert(PRUnichar aChar,PRUint32 anOffset);
/* /*
* This method is used to cut characters in this string * This method is used to cut characters in this string
@ -541,7 +531,7 @@ nsString2& Insert(PRUnichar aChar,PRUint32 anOffset);
* @param aCount -- number of chars to be cut * @param aCount -- number of chars to be cut
* @return *this * @return *this
*/ */
nsString2& Cut(PRUint32 anOffset,PRInt32 aCount); nsString& Cut(PRUint32 anOffset,PRInt32 aCount);
/********************************************************************** /**********************************************************************
@ -564,11 +554,22 @@ PRInt32 BinarySearch(PRUnichar aChar) const;
* @param aString is substring to be sought in this * @param aString is substring to be sought in this
* @return offset in string, or -1 (kNotFound) * @return offset in string, or -1 (kNotFound)
*/ */
PRInt32 Find(const nsString2& aString,PRBool aIgnoreCase=PR_FALSE) const; PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE) const; PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE) const; PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE) const; PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
/**
* Search for given char within this string
*
* @param aString is substring to be sought in this
* @param anOffset tells us where in this strig to start searching
* @param aIgnoreCase selects case sensitivity
* @return find pos in string, or -1 (kNotFound)
*/
PRInt32 Find(PRUnichar aChar,PRUint32 offset=0,PRBool aIgnoreCase=PR_FALSE) const; PRInt32 Find(PRUnichar aChar,PRUint32 offset=0,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
/** /**
* This method searches this string for the first character * This method searches this string for the first character
@ -579,7 +580,31 @@ PRInt32 Find(PRUnichar aChar,PRUint32 offset=0,PRBool aIgnoreCase=PR_FALSE) cons
*/ */
PRInt32 FindCharInSet(const char* aString,PRUint32 anOffset=0) const; PRInt32 FindCharInSet(const char* aString,PRUint32 anOffset=0) const;
PRInt32 FindCharInSet(const PRUnichar* aString,PRUint32 anOffset=0) const; PRInt32 FindCharInSet(const PRUnichar* aString,PRUint32 anOffset=0) const;
PRInt32 FindCharInSet(const nsString2& aString,PRUint32 anOffset=0) const; PRInt32 FindCharInSet(const nsStr& aString,PRUint32 anOffset=0) const;
/**
* This methods scans the string backwards, looking for the given string
* @param aString is substring to be sought in this
* @param aIgnoreCase tells us whether or not to do caseless compare
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
/**
* Search for given char within this string
*
* @param aString is substring to be sought in this
* @param anOffset tells us where in this strig to start searching
* @param aIgnoreCase selects case sensitivity
* @return find pos in string, or -1 (kNotFound)
*/
PRInt32 RFind(PRUnichar aChar,PRUint32 offset=0,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
/** /**
* This method searches this string for the last character * This method searches this string for the last character
@ -590,21 +615,9 @@ PRInt32 FindCharInSet(const nsString2& aString,PRUint32 anOffset=0) const;
*/ */
PRInt32 RFindCharInSet(const char* aString,PRUint32 anOffset=0) const; PRInt32 RFindCharInSet(const char* aString,PRUint32 anOffset=0) const;
PRInt32 RFindCharInSet(const PRUnichar* aString,PRUint32 anOffset=0) const; PRInt32 RFindCharInSet(const PRUnichar* aString,PRUint32 anOffset=0) const;
PRInt32 RFindCharInSet(const nsString2& aString,PRUint32 anOffset=0) const; PRInt32 RFindCharInSet(const nsStr& aString,PRUint32 anOffset=0) const;
/**
* This methods scans the string backwards, looking for the given string
* @param aString is substring to be sought in this
* @param aIgnoreCase tells us whether or not to do caseless compare
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 RFind(const nsString2& aString,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 RFind(PRUnichar aChar,PRUint32 offset=0,PRBool aIgnoreCase=PR_FALSE) const;
/********************************************************************** /**********************************************************************
Comparison methods... Comparison methods...
*********************************************************************/ *********************************************************************/
@ -616,7 +629,7 @@ PRInt32 RFind(PRUnichar aChar,PRUint32 offset=0,PRBool aIgnoreCase=PR_FALSE) con
* @param aIgnoreCase tells us how to treat case * @param aIgnoreCase tells us how to treat case
* @return -1,0,1 * @return -1,0,1
*/ */
virtual PRInt32 Compare(const nsString2& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const; virtual PRInt32 Compare(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const;
virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const; virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const;
virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const; virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const;
virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const; virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const;
@ -626,7 +639,7 @@ virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRI
* @param aString is the string to be compared to this * @param aString is the string to be compared to this
* @return TRUE or FALSE * @return TRUE or FALSE
*/ */
PRBool operator==(const nsString2 &aString) const; PRBool operator==(const nsString &aString) const;
PRBool operator==(const nsStr &aString) const; PRBool operator==(const nsStr &aString) const;
PRBool operator==(const char *aString) const; PRBool operator==(const char *aString) const;
PRBool operator==(const PRUnichar* aString) const; PRBool operator==(const PRUnichar* aString) const;
@ -636,7 +649,7 @@ PRBool operator==(const PRUnichar* aString) const;
* @param aString is the string to be compared to this * @param aString is the string to be compared to this
* @return TRUE * @return TRUE
*/ */
PRBool operator!=(const nsString2 &aString) const; PRBool operator!=(const nsString &aString) const;
PRBool operator!=(const nsStr &aString) const; PRBool operator!=(const nsStr &aString) const;
PRBool operator!=(const char* aString) const; PRBool operator!=(const char* aString) const;
PRBool operator!=(const PRUnichar* aString) const; PRBool operator!=(const PRUnichar* aString) const;
@ -646,7 +659,7 @@ PRBool operator!=(const PRUnichar* aString) const;
* @param aString is the string to be compared to this * @param aString is the string to be compared to this
* @return TRUE or FALSE * @return TRUE or FALSE
*/ */
PRBool operator<(const nsString2 &aString) const; PRBool operator<(const nsString &aString) const;
PRBool operator<(const nsStr &aString) const; PRBool operator<(const nsStr &aString) const;
PRBool operator<(const char* aString) const; PRBool operator<(const char* aString) const;
PRBool operator<(const PRUnichar* aString) const; PRBool operator<(const PRUnichar* aString) const;
@ -656,7 +669,7 @@ PRBool operator<(const PRUnichar* aString) const;
* @param aString is the string to be compared to this * @param aString is the string to be compared to this
* @return TRUE or FALSE * @return TRUE or FALSE
*/ */
PRBool operator>(const nsString2 &aString) const; PRBool operator>(const nsString &aString) const;
PRBool operator>(const nsStr &S) const; PRBool operator>(const nsStr &S) const;
PRBool operator>(const char* aString) const; PRBool operator>(const char* aString) const;
PRBool operator>(const PRUnichar* aString) const; PRBool operator>(const PRUnichar* aString) const;
@ -666,7 +679,7 @@ PRBool operator>(const PRUnichar* aString) const;
* @param aString is the string to be compared to this * @param aString is the string to be compared to this
* @return TRUE or FALSE * @return TRUE or FALSE
*/ */
PRBool operator<=(const nsString2 &aString) const; PRBool operator<=(const nsString &aString) const;
PRBool operator<=(const nsStr &S) const; PRBool operator<=(const nsStr &S) const;
PRBool operator<=(const char* aString) const; PRBool operator<=(const char* aString) const;
PRBool operator<=(const PRUnichar* aString) const; PRBool operator<=(const PRUnichar* aString) const;
@ -676,7 +689,7 @@ PRBool operator<=(const PRUnichar* aString) const;
* @param aString is the string to be compared to this * @param aString is the string to be compared to this
* @return TRUE or FALSE * @return TRUE or FALSE
*/ */
PRBool operator>=(const nsString2 &aString) const; PRBool operator>=(const nsString &aString) const;
PRBool operator>=(const nsStr &S) const; PRBool operator>=(const nsStr &S) const;
PRBool operator>=(const char* aString) const; PRBool operator>=(const char* aString) const;
PRBool operator>=(const PRUnichar* aString) const; PRBool operator>=(const PRUnichar* aString) const;
@ -688,20 +701,18 @@ PRBool operator>=(const PRUnichar* aString) const;
* optimization. * optimization.
* *
* @param aString -- the string to compare to this * @param aString -- the string to compare to this
* @param aLength -- optional length of given string. * @param aCount -- number of chars to be compared.
* @return TRUE if equal * @return TRUE if equal
*/ */
PRBool Equals(const nsString2 &aString,PRBool aIgnoreCase=PR_FALSE) const; PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE) const; PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE) const; PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const char* aString,PRUint32 aCount,PRBool aIgnoreCase) const; PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE) const;
PRBool Equals(const PRUnichar* aString,PRUint32 aCount,PRBool aIgnoreCase) const;
PRBool Equals(const nsIAtom* anAtom,PRBool aIgnoreCase) const; PRBool Equals(const nsIAtom* anAtom,PRBool aIgnoreCase) const;
PRBool Equals(const PRUnichar* s1, const PRUnichar* s2,PRBool aIgnoreCase=PR_FALSE) const; PRBool Equals(const PRUnichar* s1, const PRUnichar* s2,PRBool aIgnoreCase=PR_FALSE) const;
PRBool EqualsIgnoreCase(const nsString2& aString) const; PRBool EqualsIgnoreCase(const nsString& aString) const;
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aLength=-1) const; PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(const nsIAtom *aAtom) const; PRBool EqualsIgnoreCase(const nsIAtom *aAtom) const;
PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const; PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const;
@ -730,8 +741,8 @@ static PRBool IsAlpha(PRUnichar ch);
*/ */
static PRBool IsDigit(PRUnichar ch); static PRBool IsDigit(PRUnichar ch);
static void Recycle(nsString2* aString); static void Recycle(nsString* aString);
static nsString2* CreateString(eCharSize aCharSize=eTwoByte); static nsString* CreateString(eCharSize aCharSize=eTwoByte);
virtual void DebugDump(ostream& aStream) const; virtual void DebugDump(ostream& aStream) const;
@ -739,8 +750,8 @@ virtual void DebugDump(ostream& aStream) const;
}; };
extern NS_COM int fputs(const nsString2& aString, FILE* out); extern NS_COM int fputs(const nsString& aString, FILE* out);
ostream& operator<<(ostream& aStream,const nsString2& aString); ostream& operator<<(ostream& aStream,const nsString& aString);
/************************************************************** /**************************************************************
@ -749,36 +760,30 @@ ostream& operator<<(ostream& aStream,const nsString2& aString);
If the buffer needs to grow, it gets reallocated on the heap. If the buffer needs to grow, it gets reallocated on the heap.
**************************************************************/ **************************************************************/
class NS_COM nsAutoString2 : public nsString2 { class NS_COM nsAutoString : public nsString {
public: public:
nsAutoString2(eCharSize aCharSize=kDefaultCharSize); nsAutoString(eCharSize aCharSize=kDefaultCharSize);
nsAutoString2(nsStr& anExtBuffer,const char* aCString); nsAutoString(const char* aCString,eCharSize aCharSize=kDefaultCharSize,PRInt32 aLength=-1);
nsAutoString(const PRUnichar* aString,eCharSize aCharSize=kDefaultCharSize,PRInt32 aLength=-1);
nsAutoString(CSharedStrBuffer& aBuffer);
nsAutoString2(const char* aCString,eCharSize aCharSize=kDefaultCharSize); nsAutoString(const nsStr& aString,eCharSize aCharSize=kDefaultCharSize);
nsAutoString2(char* aCString,PRInt32 aCapacity=-1,eCharSize aCharSize=kDefaultCharSize,PRBool assumeOwnership=PR_FALSE); nsAutoString(const nsAutoString& aString,eCharSize aCharSize=kDefaultCharSize);
nsAutoString2(const PRUnichar* aString,eCharSize aCharSize=kDefaultCharSize);
nsAutoString2(PRUnichar* aString,PRInt32 aCapacity=-1,eCharSize aCharSize=kDefaultCharSize,PRBool assumeOwnership=PR_FALSE);
nsAutoString2(const nsStr& aString,eCharSize aCharSize=kDefaultCharSize);
nsAutoString2(const nsString2& aString,eCharSize aCharSize=kDefaultCharSize);
nsAutoString2(const nsAutoString2& aString,eCharSize aCharSize=kDefaultCharSize);
#ifdef AIX #ifdef AIX
nsAutoString2(const nsSubsumeStr& aSubsumeStr); // AIX requires a const nsAutoString(const nsSubsumeStr& aSubsumeStr); // AIX requires a const
#else #else
nsAutoString2(nsSubsumeStr& aSubsumeStr); nsAutoString(nsSubsumeStr& aSubsumeStr);
#endif // AIX #endif // AIX
nsAutoString2(PRUnichar aChar,eCharSize aCharSize=kDefaultCharSize); nsAutoString(PRUnichar aChar,eCharSize aCharSize=kDefaultCharSize);
virtual ~nsAutoString2(); virtual ~nsAutoString();
nsAutoString2& operator=(const nsString2& aString) {nsString2::operator=(aString); return *this;} nsAutoString& operator=(const nsStr& aString) {nsString::Assign(aString); return *this;}
nsAutoString2& operator=(const nsStr& aString) {nsString2::Assign(aString); return *this;} nsAutoString& operator=(const nsAutoString& aString) {nsString::operator=(aString); return *this;}
nsAutoString2& operator=(const nsAutoString2& aString) {nsString2::operator=(aString); return *this;} nsAutoString& operator=(const char* aCString) {nsString::operator=(aCString); return *this;}
nsAutoString2& operator=(const char* aCString) {nsString2::operator=(aCString); return *this;} nsAutoString& operator=(char aChar) {nsString::operator=(aChar); return *this;}
nsAutoString2& operator=(char aChar) {nsString2::operator=(aChar); return *this;} nsAutoString& operator=(const PRUnichar* aBuffer) {nsString::operator=(aBuffer); return *this;}
nsAutoString2& operator=(const PRUnichar* aBuffer) {nsString2::operator=(aBuffer); return *this;} nsAutoString& operator=(PRUnichar aChar) {nsString::operator=(aChar); return *this;}
nsAutoString2& operator=(PRUnichar aChar) {nsString2::operator=(aChar); return *this;}
/** /**
* Retrieve the size of this string * Retrieve the size of this string
@ -803,24 +808,14 @@ public:
You should probably not use this class unless you really know You should probably not use this class unless you really know
what you're doing. what you're doing.
***************************************************************/ ***************************************************************/
class NS_COM nsSubsumeStr : public nsString2 { class NS_COM nsSubsumeStr : public nsString {
public: public:
nsSubsumeStr(nsString2& aString);
nsSubsumeStr(nsStr& aString); nsSubsumeStr(nsStr& aString);
nsSubsumeStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1); nsSubsumeStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
nsSubsumeStr(char* aString,PRBool assumeOwnership,PRInt32 aLength=-1); nsSubsumeStr(char* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
}; };
/***************************************************************
***************************************************************/
class NS_COM nsCAutoString: public nsAutoString{
public:
nsCAutoString(const nsString2& aString);
operator const char*() const;
};
#endif #endif

Просмотреть файл

@ -93,7 +93,7 @@ void ShiftCharsRight(char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUint32 aCo
char* to = aDest+aLength+aCount; char* to = aDest+aLength+aCount;
//Copy rightmost chars, up to offset+theDelta... //Copy rightmost chars, up to offset+theDelta...
while(first<=last) { while(first<last) {
*to=*last; *to=*last;
to--; to--;
last--; last--;
@ -141,7 +141,7 @@ void ShiftDoubleCharsRight(char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUint
PRUnichar* to = theBuf+aLength+aCount; PRUnichar* to = theBuf+aLength+aCount;
//Copy rightmost chars, up to offset+theDelta... //Copy rightmost chars, up to offset+theDelta...
while(first<=last) { while(first<last) {
*to=*last; *to=*last;
to--; to--;
last--; last--;
@ -289,7 +289,7 @@ inline PRInt32 FindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,co
PRInt32 theIndex=0; PRInt32 theIndex=0;
PRInt32 theLength=(PRInt32)aLength; PRInt32 theLength=(PRInt32)aLength;
for(theIndex=(PRInt32)anOffset;theIndex<theLength;theIndex++){ for(theIndex=(PRInt32)anOffset;theIndex<theLength;theIndex++){
PRUnichar theChar=GetCharAt(aDest,theIndex); PRUnichar theChar=aDest[theIndex];
if(aIgnoreCase) if(aIgnoreCase)
theChar=nsCRT::ToUpper(theChar); theChar=nsCRT::ToUpper(theChar);
if(theChar==theCmpChar) if(theChar==theCmpChar)
@ -311,10 +311,11 @@ inline PRInt32 FindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,co
*/ */
inline PRInt32 FindChar2(const char* aDest,PRUint32 aLength,PRUint32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase) { inline PRInt32 FindChar2(const char* aDest,PRUint32 aLength,PRUint32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase) {
PRUnichar theCmpChar=(aIgnoreCase ? nsCRT::ToUpper(aChar) : aChar); PRUnichar theCmpChar=(aIgnoreCase ? nsCRT::ToUpper(aChar) : aChar);
PRInt32 theIndex=0; PRInt32 theIndex=0;
PRInt32 theLength=(PRInt32)aLength; PRInt32 theLength=(PRInt32)aLength;
PRUnichar* theBuf=(PRUnichar*)aDest;
for(theIndex=(PRInt32)anOffset;theIndex<theLength;theIndex++){ for(theIndex=(PRInt32)anOffset;theIndex<theLength;theIndex++){
PRUnichar theChar=GetUnicharAt(aDest,theIndex); PRUnichar theChar=theBuf[theIndex];
if(aIgnoreCase) if(aIgnoreCase)
theChar=nsCRT::ToUpper(theChar); theChar=nsCRT::ToUpper(theChar);
if(theChar==theCmpChar) if(theChar==theCmpChar)
@ -598,199 +599,7 @@ PRInt32 ConvertCase2(char* aString,PRUint32 aCount,PRBool aToUpper){
typedef PRInt32 (*CaseConverters)(char*,PRUint32,PRBool); typedef PRInt32 (*CaseConverters)(char*,PRUint32,PRBool);
CaseConverters gCaseConverters[]={&ConvertCase1,&ConvertCase2}; CaseConverters gCaseConverters[]={&ConvertCase1,&ConvertCase2};
//----------------------------------------------------------------------------------------
//
// This set of methods is used strip chars from a given buffer...
//
/**
* This method removes chars (given in aSet) from the given buffer
*
* @update gess 01/04/99
* @param aString is the buffer to be manipulated
* @param anOffset is starting pos in buffer for manipulation
* @param aCount is the number of chars to compare
* @param aSet tells us which chars to remove from given buffer
* @return the new length of the given buffer
*/
PRInt32 StripChars1(char* aString,PRUint32 anOffset,PRUint32 aCount,const char* aSet){
PRInt32 result=0;
typedef char chartype;
chartype* from = (chartype*)&aString[anOffset];
chartype* end = (chartype*)from + aCount-1;
chartype* to = from;
if(aSet){
PRUint32 aSetLen=strlen(aSet);
while (from <= end) {
chartype ch = *from;
if(kNotFound==FindChar1(aSet,aSetLen,0,ch,PR_FALSE)){
*to++=*from;
}
from++;
}
*to = 0;
}
return to - (chartype*)aString;
}
/**
* This method removes chars (given in aSet) from the given buffer
*
* @update gess 01/04/99
* @param aString is the buffer to be manipulated
* @param anOffset is starting pos in buffer for manipulation
* @param aCount is the number of chars to compare
* @param aSet tells us which chars to remove from given buffer
* @return the new length of the given buffer
*/
PRInt32 StripChars2(char* aString,PRUint32 anOffset,PRUint32 aCount,const char* aSet){
PRInt32 result=0;
typedef PRUnichar chartype;
chartype* from = (chartype*)&aString[anOffset];
chartype* end = (chartype*)from + aCount-1;
chartype* to = from;
if(aSet){
PRUint32 aSetLen=strlen(aSet);
while (from <= end) {
chartype ch = *from;
if(kNotFound==FindChar1(aSet,aSetLen,0,ch,PR_FALSE)){
*to++=*from;
}
from++;
}
*to = 0;
}
return to - (chartype*)aString;
}
typedef PRInt32 (*StripChars)(char* aString,PRUint32 aDestOffset,PRUint32 aCount,const char* aSet);
StripChars gStripChars[]={&StripChars1,&StripChars2};
//----------------------------------------------------------------------------------------
//
// This set of methods is used trim chars from the edges of a buffer...
//
/**
* This method trims chars (given in aSet) from the edges of 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 remove 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 TrimChars1(char* aString,PRUint32 aLength,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){
PRInt32 result=0;
typedef char chartype;
chartype* from = (chartype*)aString;
chartype* end = from + aLength -1;
chartype* to = from;
if(aSet) {
PRUint32 aSetLen=strlen(aSet);
//begin by find the first char not in aTrimSet
if(aEliminateLeading) {
while (from <= end) {
chartype ch = *from;
if(kNotFound==FindChar1(aSet,aSetLen,0,ch,PR_FALSE)){
break;
}
from++;
}
}
//Now, find last char not in aTrimSet
if(aEliminateTrailing) {
while(from<=end) {
chartype ch = *end;
if(kNotFound==FindChar1(aSet,aSetLen,0,ch,PR_FALSE)){
break;
}
end--;
}
}
//now rewrite your string without unwanted
//leading or trailing characters.
if (from != to) {
while (from <= end) {
*to++ = *from++;
}
}
else {
to = ++end;
}
*to = 0;
}
return to - (chartype*)aString;
}
/**
* This method trims chars (given in aSet) from the edges of 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 remove 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 TrimChars2(char* aString,PRUint32 aLength,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){
PRInt32 result=0;
typedef PRUnichar chartype;
chartype* from = (chartype*)aString;
chartype* end = from + aLength -1;
chartype* to = from;
if(aSet) {
PRUint32 aSetLen=strlen(aSet);
//begin by find the first char not in aTrimSet
if(aEliminateLeading) {
while (from <= end) {
chartype ch = *from;
if(kNotFound==FindChar1(aSet,aSetLen,0,ch,PR_FALSE)){
break;
}
from++;
}
}
//Now, find last char not in aTrimSet
if(aEliminateTrailing) {
while(from<=end) {
chartype ch = *end;
if(kNotFound==FindChar1(aSet,aSetLen,0,ch,PR_FALSE)){
break;
}
end--;
}
}
//now rewrite your string without unwanted
//leading or trailing characters.
if (from != to) {
while (from <= end) {
*to++ = *from++;
}
}
else {
to = ++end;
}
*to = 0;
}
return to - (chartype*)aString;
}
typedef PRInt32 (*TrimChars)(char* aString,PRUint32 aCount,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing);
TrimChars gTrimChars[]={&TrimChars1,&TrimChars2};
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
// //
@ -809,11 +618,9 @@ TrimChars gTrimChars[]={&TrimChars1,&TrimChars2};
* @param aEliminateTrailing 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 * @return the new length of the given buffer
*/ */
PRInt32 CompressChars1(char* aString,PRUint32 aLength,const char* aSet,PRUint32 aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing){ PRInt32 CompressChars1(char* aString,PRUint32 aLength,const char* aSet){
PRInt32 result=0; PRInt32 result=0;
TrimChars1(aString,aLength,aSet,aEliminateLeading,aEliminateTrailing);
typedef char chartype; typedef char chartype;
chartype* from = aString; chartype* from = aString;
chartype* end = aString + aLength-1; chartype* end = aString + aLength-1;
@ -824,18 +631,18 @@ PRInt32 CompressChars1(char* aString,PRUint32 aLength,const char* aSet,PRUint32
if(aSet){ if(aSet){
PRUint32 aSetLen=strlen(aSet); PRUint32 aSetLen=strlen(aSet);
while (from <= end) { while (from <= end) {
chartype ch = *from++; chartype theChar = *from++;
if(kNotFound!=FindChar1(aSet,aSetLen,0,ch,PR_FALSE)){ if(kNotFound!=FindChar1(aSet,aSetLen,0,theChar,PR_FALSE)){
*to++ = (char)aChar; to++;
while (from <= end) { while (from <= end) {
ch = *from++; theChar = *from++;
if(kNotFound==FindChar1(aSet,aSetLen,0,ch,PR_FALSE)){ if(kNotFound==FindChar1(aSet,aSetLen,0,theChar,PR_FALSE)){
*to++ = ch; *to++ = theChar;
break; break;
} }
} }
} else { } else {
*to++ = ch; *to++ = theChar;
} }
} }
*to = 0; *to = 0;
@ -855,11 +662,9 @@ PRInt32 CompressChars1(char* aString,PRUint32 aLength,const char* aSet,PRUint32
* @param aEliminateTrailing 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 * @return the new length of the given buffer
*/ */
PRInt32 CompressChars2(char* aString,PRUint32 aLength,const char* aSet,PRUint32 aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing){ PRInt32 CompressChars2(char* aString,PRUint32 aLength,const char* aSet){
PRInt32 result=0; PRInt32 result=0;
TrimChars2(aString,aLength,aSet,aEliminateLeading,aEliminateTrailing);
typedef PRUnichar chartype; typedef PRUnichar chartype;
chartype* from = (chartype*)aString; chartype* from = (chartype*)aString;
chartype* end = from + aLength-1; chartype* end = from + aLength-1;
@ -870,18 +675,18 @@ PRInt32 CompressChars2(char* aString,PRUint32 aLength,const char* aSet,PRUint32
if(aSet){ if(aSet){
PRUint32 aSetLen=strlen(aSet); PRUint32 aSetLen=strlen(aSet);
while (from <= end) { while (from <= end) {
chartype ch = *from++; chartype theChar = *from++;
if(kNotFound!=FindChar1(aSet,aSetLen,0,ch,PR_FALSE)){ if(kNotFound!=FindChar1(aSet,aSetLen,0,theChar,PR_FALSE)){
*to++ = (PRUnichar)aChar; to++;
while (from <= end) { while (from <= end) {
ch = *from++; theChar = *from++;
if(kNotFound==FindChar1(aSet,aSetLen,0,ch,PR_FALSE)){ if(kNotFound==FindChar1(aSet,aSetLen,0,theChar,PR_FALSE)){
*to++ = ch; *to++ = theChar;
break; break;
} }
} }
} else { } else {
*to++ = ch; *to++ = theChar;
} }
} }
*to = 0; *to = 0;
@ -889,7 +694,7 @@ PRInt32 CompressChars2(char* aString,PRUint32 aLength,const char* aSet,PRUint32
return to - (chartype*)aString; return to - (chartype*)aString;
} }
typedef PRInt32 (*CompressChars)(char* aString,PRUint32 aCount,const char* aSet,PRUint32 aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing); typedef PRInt32 (*CompressChars)(char* aString,PRUint32 aCount,const char* aSet);
CompressChars gCompressChars[]={&CompressChars1,&CompressChars2}; CompressChars gCompressChars[]={&CompressChars1,&CompressChars2};

Просмотреть файл

@ -31,8 +31,8 @@
#include "nsStr.h" #include "nsStr.h"
#include "bufferRoutines.h" #include "bufferRoutines.h"
#include "stdio.h" //only used for printf #include "stdio.h" //only used for printf
#include "nsDeque.h"
#include "nsCRT.h" #include "nsCRT.h"
#include "nsDeque.h"
static const char* kFoolMsg = "Error: Some fool overwrote the shared buffer."; static const char* kFoolMsg = "Error: Some fool overwrote the shared buffer.";
@ -44,6 +44,8 @@ static const char* kFoolMsg = "Error: Some fool overwrote the shared buffer.";
/************************************************************** /**************************************************************
Define the char* (pooled) deallocator class... Define the char* (pooled) deallocator class...
**************************************************************/ **************************************************************/
/*
class nsBufferDeallocator: public nsDequeFunctor{ class nsBufferDeallocator: public nsDequeFunctor{
public: public:
virtual void* operator()(void* anObject) { virtual void* operator()(void* anObject) {
@ -53,12 +55,6 @@ public:
} }
}; };
/**
*
* @update gess10/30/98
* @param
* @return
*/
class nsPoolingMemoryAgent : public nsMemoryAgent{ class nsPoolingMemoryAgent : public nsMemoryAgent{
public: public:
nsPoolingMemoryAgent() { nsPoolingMemoryAgent() {
@ -128,6 +124,8 @@ public:
nsDeque* mPools[16]; nsDeque* mPools[16];
}; };
*/
static char* gCommonEmptyBuffer=0; static char* gCommonEmptyBuffer=0;
/** /**
* *
@ -151,7 +149,8 @@ char* GetSharedEmptyBuffer() {
} }
/** /**
* * This method initializes all the members of the nsStr structure
*
* @update gess10/30/98 * @update gess10/30/98
* @param * @param
* @return * @return
@ -166,7 +165,7 @@ void nsStr::Initialize(nsStr& aDest,eCharSize aCharSize) {
} }
/** /**
* * This method initializes all the members of the nsStr structure
* @update gess10/30/98 * @update gess10/30/98
* @param * @param
* @return * @return
@ -193,7 +192,7 @@ nsIMemoryAgent* GetDefaultAgent(void){
} }
/** /**
* * This member destroys the memory buffer owned by an nsStr object (if it actually owns it)
* @update gess10/30/98 * @update gess10/30/98
* @param * @param
* @return * @return
@ -386,9 +385,10 @@ void nsStr::Truncate(nsStr& aDest,PRUint32 aDestOffset,nsIMemoryAgent* anAgent){
/** /**
* * This method forces the given string to upper or lowercase
* @update gess1/7/99 * @update gess1/7/99
* @param * @param aDest is the string you're going to change
* @param aToUpper: if TRUE, then we go uppercase, otherwise we go lowercase
* @return * @return
*/ */
void nsStr::ChangeCase(nsStr& aDest,PRBool aToUpper) { void nsStr::ChangeCase(nsStr& aDest,PRBool aToUpper) {
@ -397,19 +397,6 @@ void nsStr::ChangeCase(nsStr& aDest,PRBool aToUpper) {
NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg); NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg);
} }
/**
*
* @update gess1/7/99
* @param
* @return
*/
void nsStr::StripChars(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,const char* aCharSet){
PRUint32 aNewLen=gStripChars[aDest.mCharSize](aDest.mStr,aDestOffset,aCount,aCharSet);
aDest.mLength=aNewLen;
NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg);
}
/** /**
* *
* @update gess1/7/99 * @update gess1/7/99
@ -417,8 +404,43 @@ void nsStr::StripChars(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,const ch
* @return * @return
*/ */
void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){ void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){
PRUint32 aNewLen=gTrimChars[aDest.mCharSize](aDest.mStr,aDest.mLength,aSet,aEliminateLeading,aEliminateTrailing);
aDest.mLength=aNewLen; if((aDest.mLength>0) && aSet){
PRInt32 theIndex=-1;
PRInt32 theMax=aDest.mLength;
PRInt32 theSetLen=nsCRT::strlen(aSet);
if(aEliminateLeading) {
while(++theIndex<=theMax) {
PRUnichar theChar=GetCharAt(aDest,theIndex);
PRInt32 thePos=gFindChars[eOneByte](aSet,theSetLen,0,theChar,PR_FALSE);
if(kNotFound==thePos)
break;
}
if(0<theIndex) {
if(theIndex<theMax) {
Delete(aDest,0,theIndex,0);
}
else Truncate(aDest,0);
}
}
if(aEliminateTrailing) {
theIndex=aDest.mLength;
PRInt32 theNewLen=theIndex;
while(--theIndex>0) {
PRUnichar theChar=GetCharAt(aDest,theIndex); //read at end now...
PRInt32 thePos=gFindChars[eOneByte](aSet,theSetLen,0,theChar,PR_FALSE);
if(kNotFound<thePos)
theNewLen=theIndex;
else break;
}
if(theNewLen<theMax) {
Truncate(aDest,theNewLen);
}
}
}
NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg); NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg);
} }
@ -428,8 +450,9 @@ void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool a
* @param * @param
* @return * @return
*/ */
void nsStr::CompressSet(nsStr& aDest,const char* aSet,PRUint32 aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing){ void nsStr::CompressSet(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){
PRUint32 aNewLen=gCompressChars[aDest.mCharSize](aDest.mStr,aDest.mLength,aSet,aChar,aEliminateLeading,aEliminateTrailing); Trim(aDest,aSet,aEliminateLeading,aEliminateTrailing);
PRUint32 aNewLen=gCompressChars[aDest.mCharSize](aDest.mStr,aDest.mLength,aSet);
aDest.mLength=aNewLen; aDest.mLength=aNewLen;
NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg); NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg);
} }
@ -439,15 +462,28 @@ void nsStr::CompressSet(nsStr& aDest,const char* aSet,PRUint32 aChar,PRBool aEli
**************************************************************/ **************************************************************/
/**
* This searches aDest for a given substring
*
* @update gess 3/25/98
* @param aDest string to search
* @param aTarget is the substring you're trying to find.
* @param aIgnorecase indicates case sensitivity of search
* @param anOffset tells us where to start the search
* @return index in aDest where member of aSet occurs, or -1 if not found
*/
PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRUint32 anOffset) { PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRUint32 anOffset) {
if((aDest.mLength>0) && (aTarget.mLength>0) && (anOffset<aTarget.mLength)){
int32 index=anOffset-1; PRInt32 result=kNotFound;
int32 theMax=aDest.mLength-aTarget.mLength;
if((aDest.mLength>0) && (aTarget.mLength>0)){ if(anOffset<aDest.mLength) {
int32 theTargetMax=aTarget.mLength; PRInt32 theMax=aDest.mLength-aTarget.mLength;
while(++index<=theMax) { PRInt32 index=(anOffset ? anOffset : theMax);
int32 theSubIndex=-1;
if((aDest.mLength>=aTarget.mLength) && (aTarget.mLength>0) && (index>=0)){
PRInt32 theTargetMax=aTarget.mLength;
while(index<=theMax) {
PRInt32 theSubIndex=-1;
PRBool matches=PR_TRUE; PRBool matches=PR_TRUE;
while((++theSubIndex<theTargetMax) && (matches)){ while((++theSubIndex<theTargetMax) && (matches)){
PRUnichar theChar=(aIgnoreCase) ? nsCRT::ToLower(GetCharAt(aDest,index+theSubIndex)) : GetCharAt(aDest,index+theSubIndex); PRUnichar theChar=(aIgnoreCase) ? nsCRT::ToLower(GetCharAt(aDest,index+theSubIndex)) : GetCharAt(aDest,index+theSubIndex);
@ -455,20 +491,26 @@ PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnor
matches=PRBool(theChar==theTargetChar); matches=PRBool(theChar==theTargetChar);
} }
if(matches) { if(matches) {
return index; result=index;
break;
} }
} index++;
} //while
}//if }//if
} }//if
return kNotFound; return result;
} }
/** /**
* * This searches aDest for a given character
* @update gess1/7/99 *
* @param * @update gess 3/25/98
* @return * @param aDest string to search
* @param char is the character you're trying to find.
* @param aIgnorecase indicates case sensitivity of search
* @param anOffset tells us where to start the search
* @return index in aDest where member of aSet occurs, or -1 if not found
*/ */
PRInt32 nsStr::FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) { PRInt32 nsStr::FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
PRInt32 result=gFindChars[aDest.mCharSize](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase); PRInt32 result=gFindChars[aDest.mCharSize](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase);
@ -477,17 +519,20 @@ PRInt32 nsStr::FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,P
/** /**
* * This searches aDest for a character found in aSet.
* *
* @update gess 3/25/98 * @update gess 3/25/98
* @param * @param aDest string to search
* @return * @param aSet contains a list of chars to be searched for
* @param aIgnorecase indicates case sensitivity of search
* @param anOffset tells us where to start the search
* @return index in aDest where member of aSet occurs, or -1 if not found
*/ */
PRInt32 nsStr::FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRUint32 anOffset) { PRInt32 nsStr::FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRUint32 anOffset) {
PRUint32 index=anOffset-1; PRInt32 index=anOffset-1;
PRInt32 thePos; PRInt32 thePos;
while(++index<aDest.mLength) { while(++index<(PRInt32)aDest.mLength) {
PRUnichar theChar=GetCharAt(aDest,index); PRUnichar theChar=GetCharAt(aDest,index);
thePos=gFindChars[aSet.mCharSize](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase); thePos=gFindChars[aSet.mCharSize](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase);
if(kNotFound!=thePos) if(kNotFound!=thePos)
@ -501,46 +546,64 @@ PRInt32 nsStr::FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnore
**************************************************************/ **************************************************************/
/**
* This searches aDest (in reverse) for a given substring
*
* @update gess 3/25/98
* @param aDest string to search
* @param aTarget is the substring you're trying to find.
* @param aIgnorecase indicates case sensitivity of search
* @param anOffset tells us where to start the search
* @return index in aDest where member of aSet occurs, or -1 if not found
*/
PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRUint32 anOffset) { PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRUint32 anOffset) {
PRInt32 index=(anOffset ? anOffset : aDest.mLength-aTarget.mLength+1);
PRInt32 result=kNotFound; PRInt32 result=kNotFound;
if((aDest.mLength>0) && (aTarget.mLength>0)){ if(anOffset<aDest.mLength) {
PRInt32 index=(anOffset ? anOffset : aDest.mLength-aTarget.mLength);
if((aDest.mLength>=aTarget.mLength) && (aTarget.mLength>0) && (index>=0)){
nsStr theCopy; nsStr theCopy;
nsStr::Initialize(theCopy,eOneByte); nsStr::Initialize(theCopy,eOneByte);
nsStr::Assign(theCopy,aTarget,0,aTarget.mLength,0); nsStr::Assign(theCopy,aTarget,0,aTarget.mLength,0);
if(aIgnoreCase){ if(aIgnoreCase){
nsStr::ChangeCase(theCopy,PR_FALSE); //force to lowercase nsStr::ChangeCase(theCopy,PR_FALSE); //force to lowercase
}
int32 theTargetMax=theCopy.mLength;
while(index--) {
int32 theSubIndex=-1;
PRBool matches=PR_TRUE;
if(anOffset+theCopy.mLength<=aDest.mLength) {
while((++theSubIndex<theTargetMax) && (matches)){
PRUnichar theDestChar=(aIgnoreCase) ? nsCRT::ToLower(GetCharAt(aDest,index+theSubIndex)) : GetCharAt(aDest,index+theSubIndex);
PRUnichar theTargetChar=GetCharAt(theCopy,theSubIndex);
matches=PRBool(theDestChar==theTargetChar);
} //while
} //if
if(matches) {
result=index;
break;
} }
} //while
nsStr::Destroy(theCopy,0); PRInt32 theTargetMax=theCopy.mLength;
while(index>=0) {
PRInt32 theSubIndex=-1;
PRBool matches=PR_FALSE;
if(index+theCopy.mLength<=aDest.mLength) {
matches=PR_TRUE;
while((++theSubIndex<theTargetMax) && (matches)){
PRUnichar theDestChar=(aIgnoreCase) ? nsCRT::ToLower(GetCharAt(aDest,index+theSubIndex)) : GetCharAt(aDest,index+theSubIndex);
PRUnichar theTargetChar=GetCharAt(theCopy,theSubIndex);
matches=PRBool(theDestChar==theTargetChar);
} //while
} //if
if(matches) {
result=index;
break;
}
index--;
} //while
nsStr::Destroy(theCopy,0);
}//if
}//if }//if
return result; return result;
} }
/** /**
* * This searches aDest (in reverse) for a given character
* @update gess1/7/99 *
* @param * @update gess 3/25/98
* @return * @param aDest string to search
* @param char is the character you're trying to find.
* @param aIgnorecase indicates case sensitivity of search
* @param anOffset tells us where to start the search
* @return index in aDest where member of aSet occurs, or -1 if not found
*/ */
PRInt32 nsStr::RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) { PRInt32 nsStr::RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
PRInt32 result=gRFindChars[aDest.mCharSize](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase); PRInt32 result=gRFindChars[aDest.mCharSize](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase);
@ -548,14 +611,17 @@ PRInt32 nsStr::RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,
} }
/** /**
* * This searches aDest (in reverese) for a character found in aSet.
* *
* @update gess 3/25/98 * @update gess 3/25/98
* @param * @param aDest string to search
* @return * @param aSet contains a list of chars to be searched for
* @param aIgnorecase indicates case sensitivity of search
* @param anOffset tells us where to start the search
* @return index in aDest where member of aSet occurs, or -1 if not found
*/ */
PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRUint32 anOffset) { PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRUint32 anOffset) {
PRUint32 offset=aDest.mLength-anOffset; PRInt32 offset=aDest.mLength-anOffset;
PRInt32 thePos; PRInt32 thePos;
while(--offset>=0) { while(--offset>=0) {
@ -569,24 +635,61 @@ PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnor
/** /**
* * Compare source and dest strings, up to an (optional max) number of chars
* @update gess11/12/98 * @param aDest is the first str to compare
* @param * @param aSource is the second str to compare
* @param aCount -- if (-1), then we use length of longer string; if (0<aCount) then it gives the max # of chars to compare
* @param aIgnorecase tells us whether to search with case sensitivity
* @return aDest<aSource=-1;aDest==aSource==0;aDest>aSource=1 * @return aDest<aSource=-1;aDest==aSource==0;aDest>aSource=1
*/ */
PRInt32 nsStr::Compare(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) { PRInt32 nsStr::Compare(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) {
int minlen=(aSource.mLength<aDest.mLength) ? aSource.mLength : aDest.mLength; PRInt32 result=0;
if(0==minlen) { if(aCount) {
if ((aDest.mLength == 0) && (aSource.mLength == 0)) PRInt32 minlen=(aSource.mLength<aDest.mLength) ? aSource.mLength : aDest.mLength;
return 0;
if (aDest.mLength == 0) if(0==minlen) {
return -1; if ((aDest.mLength == 0) && (aSource.mLength == 0))
return 1; return 0;
if (aDest.mLength == 0)
return -1;
return 1;
}
PRInt32 maxlen=(aSource.mLength<aDest.mLength) ? aDest.mLength : aSource.mLength;
aCount = (aCount<0) ? maxlen : MinInt(aCount,maxlen);
result=(*gCompare[aDest.mCharSize][aSource.mCharSize])(aDest.mStr,aSource.mStr,aCount,aIgnoreCase);
} }
int maxlen=(aSource.mLength<aDest.mLength) ? aDest.mLength : aSource.mLength;
PRInt32 result=(*gCompare[aDest.mCharSize][aSource.mCharSize])(aDest.mStr,aSource.mStr,maxlen,aIgnoreCase);
return result; return result;
} }
//----------------------------------------------------------------------------------------
CSharedStrBuffer::CSharedStrBuffer(char* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength) {
mBuffer=aString;
mCharSize=eOneByte;
mStackBased=aStackBased;
mLength=mCapacity=0;
if(aString && aCapacity>1) {
mCapacity=aCapacity-1;
mLength=(-1==aLength) ? strlen(aString) : aLength;
if(mLength>PRInt32(mCapacity))
mLength=mCapacity;
}
}
CSharedStrBuffer::CSharedStrBuffer(PRUnichar* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength) {
mBuffer=(char*)aString;
mCharSize=eTwoByte;
mStackBased=aStackBased;
mLength=mCapacity=0;
if(aString && aCapacity>1) {
mCapacity=aCapacity-1;
mLength=(-1==aLength) ? nsCRT::strlen(aString) : aLength;
if(mLength>PRInt32(mCapacity))
mLength=mCapacity;
}
}
//----------------------------------------------------------------------------------------

Просмотреть файл

@ -48,6 +48,10 @@
enum eCharSize {eOneByte=0,eTwoByte=1}; enum eCharSize {eOneByte=0,eTwoByte=1};
#define kDefaultCharSize eTwoByte #define kDefaultCharSize eTwoByte
#define kRadix10 (10)
#define kRadix16 (16)
#define kAutoDetect (100)
#define kRadixUnknown (kAutoDetect+1)
const PRInt32 kNotFound = -1; const PRInt32 kNotFound = -1;
@ -55,6 +59,21 @@ class nsIMemoryAgent;
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
class CSharedStrBuffer {
public:
CSharedStrBuffer(char* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength=-1);
CSharedStrBuffer(PRUnichar* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength=-1);
char* mBuffer;
eCharSize mCharSize;
PRUint32 mCapacity;
PRInt32 mLength;
PRBool mStackBased;
};
//----------------------------------------------------------------------------------------
struct nsStr { struct nsStr {
@ -169,16 +188,6 @@ struct nsStr {
*/ */
static void ChangeCase(nsStr& aDest,PRBool aToUpper); static void ChangeCase(nsStr& aDest,PRBool aToUpper);
/**
* This method removes chars (given in aSet) from the given buffer
*
* @update gess 01/04/99
* @param aString is the buffer to be manipulated
* @param aDestOffset is starting pos in buffer for manipulation
* @param aCount is the number of chars to compare
* @param aSet tells us which chars to remove from given buffer
*/
static void StripChars(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,const char* aCharSet);
/** /**
* This method trims chars (given in aSet) from the edges of given buffer * This method trims chars (given in aSet) from the edges of given buffer
@ -201,7 +210,7 @@ struct nsStr {
* @param aEliminateLeading tells us whether to strip chars from the start of the 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 * @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
*/ */
static void CompressSet(nsStr& aDest,const char* aSet,PRUint32 aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing); static void CompressSet(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing);
/** /**
* This method compares the data bewteen two nsStr's * This method compares the data bewteen two nsStr's

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -30,19 +30,17 @@
***********************************************************************/ ***********************************************************************/
#ifndef _nsString2 #ifndef _nsString_
#define _nsString2 #define _nsString_
#include "prtypes.h" #include "prtypes.h"
#include "nscore.h" #include "nscore.h"
#include <iostream.h> #include <iostream.h>
#include <stdio.h> #include <stdio.h>
#include "nsCRT.h" #include "nsCRT.h"
#include "nsString.h"
#include "nsStr.h"
#include <iostream.h>
#include <stdio.h>
#include "nsIAtom.h" #include "nsIAtom.h"
#include "nsStr.h"
class nsISizeOfHandler; class nsISizeOfHandler;
@ -50,14 +48,9 @@ class nsISizeOfHandler;
#define nsString2 nsString #define nsString2 nsString
#define nsAutoString2 nsAutoString #define nsAutoString2 nsAutoString
#define kRadix10 (10)
#define kRadix16 (16)
#define kAutoDetect (100)
#define kRadixUnknown (kAutoDetect+1)
class NS_COM nsSubsumeStr; class NS_COM nsSubsumeStr;
class NS_COM nsString2 : public nsStr { class NS_COM nsString : public nsStr {
public: public:
@ -67,44 +60,44 @@ class NS_COM nsString2 : public nsStr {
* was to allow developers direct access to the underlying buffer for * was to allow developers direct access to the underlying buffer for
* performance reasons. * performance reasons.
*/ */
nsString2(eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAgent=0); nsString(eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAgent=0);
/** /**
* This constructor accepts an isolatin string * This constructor accepts an isolatin string
* @param aCString is a ptr to a 1-byte cstr * @param aCString is a ptr to a 1-byte cstr
*/ */
nsString2(const char* aCString,eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAgent=0); nsString(const char* aCString,eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAgent=0);
/** /**
* This constructor accepts a unichar string * This constructor accepts a unichar string
* @param aCString is a ptr to a 2-byte cstr * @param aCString is a ptr to a 2-byte cstr
*/ */
nsString2(const PRUnichar* aString,eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAgent=0); nsString(const PRUnichar* aString,eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAgent=0);
/** /**
* This is a copy constructor that accepts an nsStr * This is a copy constructor that accepts an nsStr
* @param reference to another nsString2 * @param reference to another nsString
*/ */
nsString2(const nsStr&,eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAgent=0); nsString(const nsStr&,eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAgent=0);
/** /**
* This is our copy constructor * This is our copy constructor
* @param reference to another nsString2 * @param reference to another nsString
*/ */
nsString2(const nsString2& aString); nsString(const nsString& aString);
/** /**
* This constructor takes a subsumestr * This constructor takes a subsumestr
* @param reference to subsumestr * @param reference to subsumestr
*/ */
nsString2(nsSubsumeStr& aSubsumeStr); nsString(nsSubsumeStr& aSubsumeStr);
/** /**
* Destructor * Destructor
* *
*/ */
virtual ~nsString2(); virtual ~nsString();
/** /**
* Retrieve the length of this string * Retrieve the length of this string
@ -120,13 +113,13 @@ virtual void SizeOf(nsISizeOfHandler* aHandler) const;
/** /**
* Call this method if you want to force a different string capacity * Call this method if you want to force a different string length
* @update gess7/30/98 * @update gess7/30/98
* @param aLength -- contains new length for mStr * @param aLength -- contains new length for mStr
* @return * @return
*/ */
void SetLength(PRUint32 aLength) { void SetLength(PRUint32 aLength) {
SetCapacity(aLength); Truncate(aLength);
} }
/** /**
@ -173,7 +166,7 @@ PRBool IsEmpty(void) const {
} }
/********************************************************************** /**********************************************************************
Accessor methods... Getters/Setters...
*********************************************************************/ *********************************************************************/
const char* GetBuffer(void) const; const char* GetBuffer(void) const;
@ -188,11 +181,14 @@ PRUnichar CharAt(PRUint32 anIndex) const;
PRUnichar First(void) const; PRUnichar First(void) const;
PRUnichar Last(void) const; PRUnichar Last(void) const;
/**
* Set nth character.
*/
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex); PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
/********************************************************************** /**********************************************************************
String creation methods... String concatenation methods...
*********************************************************************/ *********************************************************************/
/** /**
@ -201,13 +197,7 @@ PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
* @return new string * @return new string
*/ */
nsSubsumeStr operator+(const nsStr& aString); nsSubsumeStr operator+(const nsStr& aString);
nsSubsumeStr operator+(const nsString& aString);
/**
* Create a new string by appending given string to this
* @param aString -- 2nd string to be appended
* @return new string
*/
nsSubsumeStr operator+(const nsString2& aString);
/** /**
* create a new string by adding this to the given buffer. * create a new string by adding this to the given buffer.
@ -260,7 +250,7 @@ void ToLowerCase();
* @update gess 7/27/98 * @update gess 7/27/98
* @param aOut is a string to contain result * @param aOut is a string to contain result
*/ */
void ToLowerCase(nsString2& aString) const; void ToLowerCase(nsString& aString) const;
/** /**
* Converts chars in this to uppercase * Converts chars in this to uppercase
@ -274,7 +264,7 @@ void ToUpperCase();
* @update gess 7/27/98 * @update gess 7/27/98
* @param aOut is a string to contain result * @param aOut is a string to contain result
*/ */
void ToUpperCase(nsString2& aString) const; void ToUpperCase(nsString& aString) const;
/** /**
@ -284,21 +274,22 @@ void ToUpperCase(nsString2& aString) const;
* @param aSet -- characters to be cut from this * @param aSet -- characters to be cut from this
* @return *this * @return *this
*/ */
nsString2& StripChars(const char* aSet); nsString& StripChars(const char* aSet);
/** /**
* This method strips whitespace throughout the string * This method strips whitespace throughout the string
* *
* @return this * @return this
*/ */
nsString2& StripWhitespace(); nsString& StripWhitespace();
/** /**
* swaps occurence of 1 string for another * swaps occurence of 1 string for another
* *
* @return this * @return this
*/ */
nsString2& ReplaceChar(PRUnichar aSourceChar,PRUnichar aDestChar); nsString& ReplaceChar(PRUnichar anOldChar,PRUnichar aNewChar);
nsString& ReplaceChar(const char* aSet,PRUnichar aNewChar);
/** /**
* This method trims characters found in aTrimSet from * This method trims characters found in aTrimSet from
@ -308,7 +299,7 @@ nsString2& ReplaceChar(PRUnichar aSourceChar,PRUnichar aDestChar);
* both ends * both ends
* @return this * @return this
*/ */
nsString2& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); nsString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/** /**
* This method strips whitespace from string. * This method strips whitespace from string.
@ -319,7 +310,7 @@ nsString2& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aElimin
* @param aEliminateTrailing controls stripping of trailing ws * @param aEliminateTrailing controls stripping of trailing ws
* @return this * @return this
*/ */
nsString2& CompressSet(const char* aSet, char aChar, PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); nsString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/** /**
* This method strips whitespace from string. * This method strips whitespace from string.
@ -330,18 +321,18 @@ nsString2& CompressSet(const char* aSet, char aChar, PRBool aEliminateLeading=PR
* @param aEliminateTrailing controls stripping of trailing ws * @param aEliminateTrailing controls stripping of trailing ws
* @return this * @return this
*/ */
nsString2& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); nsString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/********************************************************************** /**********************************************************************
string conversion methods... string conversion methods...
*********************************************************************/ *********************************************************************/
/** /**
* This method constructs a new nsString2 on the stack that is a copy * This method constructs a new nsString on the stack that is a copy
* of this string. * of this string.
* *
*/ */
nsString2* ToNewString() const; nsString* ToNewString() const;
/** /**
* Creates an ISOLatin1 clone of this string * Creates an ISOLatin1 clone of this string
@ -392,9 +383,9 @@ PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const;
* Functionally equivalent to assign or operator= * Functionally equivalent to assign or operator=
* *
*/ */
nsString2& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} nsString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsString2& SetString(const PRUnichar* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} nsString& SetString(const PRUnichar* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsString2& SetString(const nsString2& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} nsString& SetString(const nsString& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
/** /**
* assign given string to this string * assign given string to this string
@ -403,28 +394,27 @@ nsString2& SetString(const nsString2& aString,PRInt32 aLength=-1) {return Assign
if you want me to determine its length if you want me to determine its length
* @return this * @return this
*/ */
nsString2& Assign(const nsString2& aString,PRInt32 aCount=-1); nsString& Assign(const nsStr& aString,PRInt32 aCount=-1);
nsString2& Assign(const nsStr& aString,PRInt32 aCount=-1); nsString& Assign(const char* aString,PRInt32 aCount=-1);
nsString2& Assign(const char* aString,PRInt32 aCount=-1); nsString& Assign(const PRUnichar* aString,PRInt32 aCount=-1);
nsString2& Assign(const PRUnichar* aString,PRInt32 aCount=-1); nsString& Assign(char aChar);
nsString2& Assign(char aChar); nsString& Assign(PRUnichar aChar);
nsString2& Assign(PRUnichar aChar);
/** /**
* here come a bunch of assignment operators... * here come a bunch of assignment operators...
* @param aString: string to be added to this * @param aString: string to be added to this
* @return this * @return this
*/ */
nsString2& operator=(const nsString2& aString) {return Assign(aString);} nsString& operator=(const nsString& aString) {return Assign(aString);}
nsString2& operator=(const nsStr& aString) {return Assign(aString);} nsString& operator=(const nsStr& aString) {return Assign(aString);}
nsString2& operator=(char aChar) {return Assign(aChar);} nsString& operator=(char aChar) {return Assign(aChar);}
nsString2& operator=(PRUnichar aChar) {return Assign(aChar);} nsString& operator=(PRUnichar aChar) {return Assign(aChar);}
nsString2& operator=(const char* aCString) {return Assign(aCString);} nsString& operator=(const char* aCString) {return Assign(aCString);}
nsString2& operator=(const PRUnichar* aString) {return Assign(aString);} nsString& operator=(const PRUnichar* aString) {return Assign(aString);}
#ifdef AIX #ifdef AIX
nsString2& operator=(const nsSubsumeStr& aSubsumeString); // AIX requires a const here nsString& operator=(const nsSubsumeStr& aSubsumeString); // AIX requires a const here
#else #else
nsString2& operator=(nsSubsumeStr& aSubsumeString); nsString& operator=(nsSubsumeStr& aSubsumeString);
#endif #endif
/** /**
@ -432,12 +422,12 @@ nsString2& operator=(nsSubsumeStr& aSubsumeString);
* @param aString : string to be appended to this * @param aString : string to be appended to this
* @return this * @return this
*/ */
nsString2& operator+=(const nsStr& aString){return Append(aString,aString.mLength);} nsString& operator+=(const nsStr& aString){return Append(aString,aString.mLength);}
nsString2& operator+=(const nsString2& aString){return Append(aString,aString.mLength);} nsString& operator+=(const nsString& aString){return Append(aString,aString.mLength);}
nsString2& operator+=(const char* aCString) {return Append(aCString);} nsString& operator+=(const char* aCString) {return Append(aCString);}
//nsString2& operator+=(char aChar){return Append(aChar);} //nsString& operator+=(char aChar){return Append(aChar);}
nsString2& operator+=(const PRUnichar* aUCString) {return Append(aUCString);} nsString& operator+=(const PRUnichar* aUCString) {return Append(aUCString);}
nsString2& operator+=(PRUnichar aChar){return Append(aChar);} nsString& operator+=(PRUnichar aChar){return Append(aChar);}
/* /*
* Appends n characters from given string to this, * Appends n characters from given string to this,
@ -446,8 +436,8 @@ nsString2& operator+=(PRUnichar aChar){return Append(aChar);}
* @param aString is the source to be appended to this * @param aString is the source to be appended to this
* @return number of chars copied * @return number of chars copied
*/ */
nsString2& Append(const nsStr& aString) {return Append(aString,aString.mLength);} nsString& Append(const nsStr& aString) {return Append(aString,aString.mLength);}
nsString2& Append(const nsString2& aString) {return Append(aString,aString.mLength);} nsString& Append(const nsString& aString) {return Append(aString,aString.mLength);}
/* /*
@ -457,14 +447,14 @@ nsString2& Append(const nsString2& aString) {return Append(aString,aString.mLeng
* @param aCount -- number of chars to copy * @param aCount -- number of chars to copy
* @return number of chars copied * @return number of chars copied
*/ */
nsString2& Append(const nsStr& aString,PRInt32 aCount); nsString& Append(const nsStr& aString,PRInt32 aCount);
nsString2& Append(const nsString2& aString,PRInt32 aCount); nsString& Append(const nsString& aString,PRInt32 aCount);
nsString2& Append(const char* aString,PRInt32 aCount=-1); nsString& Append(const char* aString,PRInt32 aCount=-1);
nsString2& Append(const PRUnichar* aString,PRInt32 aCount=-1); nsString& Append(const PRUnichar* aString,PRInt32 aCount=-1);
nsString2& Append(char aChar); nsString& Append(char aChar);
nsString2& Append(PRUnichar aChar); nsString& Append(PRUnichar aChar);
nsString2& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16 nsString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16
nsString2& Append(float aFloat); nsString& Append(float aFloat);
/* /*
* Copies n characters from this string to given string, * Copies n characters from this string to given string,
@ -475,7 +465,7 @@ nsString2& Append(float aFloat);
* @param aCount -- number of chars to copy * @param aCount -- number of chars to copy
* @return number of chars copied * @return number of chars copied
*/ */
PRUint32 Left(nsString2& aCopy,PRInt32 aCount) const; PRUint32 Left(nsString& aCopy,PRInt32 aCount) const;
/* /*
* Copies n characters from this string to given string, * Copies n characters from this string to given string,
@ -487,7 +477,7 @@ PRUint32 Left(nsString2& aCopy,PRInt32 aCount) const;
* @param anOffset -- position where copying begins * @param anOffset -- position where copying begins
* @return number of chars copied * @return number of chars copied
*/ */
PRUint32 Mid(nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount) const; PRUint32 Mid(nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
/* /*
* Copies n characters from this string to given string, * Copies n characters from this string to given string,
@ -498,7 +488,7 @@ PRUint32 Mid(nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
* @param aCount -- number of chars to copy * @param aCount -- number of chars to copy
* @return number of chars copied * @return number of chars copied
*/ */
PRUint32 Right(nsString2& aCopy,PRInt32 aCount) const; PRUint32 Right(nsString& aCopy,PRInt32 aCount) const;
/* /*
* This method inserts n chars from given string into this * This method inserts n chars from given string into this
@ -509,7 +499,7 @@ PRUint32 Right(nsString2& aCopy,PRInt32 aCount) const;
* @param aCount -- number of chars to be copied from aCopy * @param aCount -- number of chars to be copied from aCopy
* @return number of chars inserted into this. * @return number of chars inserted into this.
*/ */
nsString2& Insert(const nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount=-1); nsString& Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
/** /**
* Insert a given string into this string at * Insert a given string into this string at
@ -519,8 +509,8 @@ nsString2& Insert(const nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
* @param anOffset is insert pos in str * @param anOffset is insert pos in str
* @return the number of chars inserted into this string * @return the number of chars inserted into this string
*/ */
nsString2& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1); nsString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
nsString2& Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1); nsString& Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
/** /**
* Insert a single char into this string at * Insert a single char into this string at
@ -530,8 +520,8 @@ nsString2& Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
* @param anOffset is insert pos in str * @param anOffset is insert pos in str
* @return the number of chars inserted into this string * @return the number of chars inserted into this string
*/ */
//nsString2& Insert(char aChar,PRUint32 anOffset); //nsString& Insert(char aChar,PRUint32 anOffset);
nsString2& Insert(PRUnichar aChar,PRUint32 anOffset); nsString& Insert(PRUnichar aChar,PRUint32 anOffset);
/* /*
* This method is used to cut characters in this string * This method is used to cut characters in this string
@ -541,7 +531,7 @@ nsString2& Insert(PRUnichar aChar,PRUint32 anOffset);
* @param aCount -- number of chars to be cut * @param aCount -- number of chars to be cut
* @return *this * @return *this
*/ */
nsString2& Cut(PRUint32 anOffset,PRInt32 aCount); nsString& Cut(PRUint32 anOffset,PRInt32 aCount);
/********************************************************************** /**********************************************************************
@ -564,11 +554,22 @@ PRInt32 BinarySearch(PRUnichar aChar) const;
* @param aString is substring to be sought in this * @param aString is substring to be sought in this
* @return offset in string, or -1 (kNotFound) * @return offset in string, or -1 (kNotFound)
*/ */
PRInt32 Find(const nsString2& aString,PRBool aIgnoreCase=PR_FALSE) const; PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE) const; PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE) const; PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE) const; PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
/**
* Search for given char within this string
*
* @param aString is substring to be sought in this
* @param anOffset tells us where in this strig to start searching
* @param aIgnoreCase selects case sensitivity
* @return find pos in string, or -1 (kNotFound)
*/
PRInt32 Find(PRUnichar aChar,PRUint32 offset=0,PRBool aIgnoreCase=PR_FALSE) const; PRInt32 Find(PRUnichar aChar,PRUint32 offset=0,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
/** /**
* This method searches this string for the first character * This method searches this string for the first character
@ -579,7 +580,31 @@ PRInt32 Find(PRUnichar aChar,PRUint32 offset=0,PRBool aIgnoreCase=PR_FALSE) cons
*/ */
PRInt32 FindCharInSet(const char* aString,PRUint32 anOffset=0) const; PRInt32 FindCharInSet(const char* aString,PRUint32 anOffset=0) const;
PRInt32 FindCharInSet(const PRUnichar* aString,PRUint32 anOffset=0) const; PRInt32 FindCharInSet(const PRUnichar* aString,PRUint32 anOffset=0) const;
PRInt32 FindCharInSet(const nsString2& aString,PRUint32 anOffset=0) const; PRInt32 FindCharInSet(const nsStr& aString,PRUint32 anOffset=0) const;
/**
* This methods scans the string backwards, looking for the given string
* @param aString is substring to be sought in this
* @param aIgnoreCase tells us whether or not to do caseless compare
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
/**
* Search for given char within this string
*
* @param aString is substring to be sought in this
* @param anOffset tells us where in this strig to start searching
* @param aIgnoreCase selects case sensitivity
* @return find pos in string, or -1 (kNotFound)
*/
PRInt32 RFind(PRUnichar aChar,PRUint32 offset=0,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
/** /**
* This method searches this string for the last character * This method searches this string for the last character
@ -590,21 +615,9 @@ PRInt32 FindCharInSet(const nsString2& aString,PRUint32 anOffset=0) const;
*/ */
PRInt32 RFindCharInSet(const char* aString,PRUint32 anOffset=0) const; PRInt32 RFindCharInSet(const char* aString,PRUint32 anOffset=0) const;
PRInt32 RFindCharInSet(const PRUnichar* aString,PRUint32 anOffset=0) const; PRInt32 RFindCharInSet(const PRUnichar* aString,PRUint32 anOffset=0) const;
PRInt32 RFindCharInSet(const nsString2& aString,PRUint32 anOffset=0) const; PRInt32 RFindCharInSet(const nsStr& aString,PRUint32 anOffset=0) const;
/**
* This methods scans the string backwards, looking for the given string
* @param aString is substring to be sought in this
* @param aIgnoreCase tells us whether or not to do caseless compare
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 RFind(const nsString2& aString,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 RFind(PRUnichar aChar,PRUint32 offset=0,PRBool aIgnoreCase=PR_FALSE) const;
/********************************************************************** /**********************************************************************
Comparison methods... Comparison methods...
*********************************************************************/ *********************************************************************/
@ -616,7 +629,7 @@ PRInt32 RFind(PRUnichar aChar,PRUint32 offset=0,PRBool aIgnoreCase=PR_FALSE) con
* @param aIgnoreCase tells us how to treat case * @param aIgnoreCase tells us how to treat case
* @return -1,0,1 * @return -1,0,1
*/ */
virtual PRInt32 Compare(const nsString2& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const; virtual PRInt32 Compare(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const;
virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const; virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const;
virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const; virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const;
virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const; virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const;
@ -626,7 +639,7 @@ virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRI
* @param aString is the string to be compared to this * @param aString is the string to be compared to this
* @return TRUE or FALSE * @return TRUE or FALSE
*/ */
PRBool operator==(const nsString2 &aString) const; PRBool operator==(const nsString &aString) const;
PRBool operator==(const nsStr &aString) const; PRBool operator==(const nsStr &aString) const;
PRBool operator==(const char *aString) const; PRBool operator==(const char *aString) const;
PRBool operator==(const PRUnichar* aString) const; PRBool operator==(const PRUnichar* aString) const;
@ -636,7 +649,7 @@ PRBool operator==(const PRUnichar* aString) const;
* @param aString is the string to be compared to this * @param aString is the string to be compared to this
* @return TRUE * @return TRUE
*/ */
PRBool operator!=(const nsString2 &aString) const; PRBool operator!=(const nsString &aString) const;
PRBool operator!=(const nsStr &aString) const; PRBool operator!=(const nsStr &aString) const;
PRBool operator!=(const char* aString) const; PRBool operator!=(const char* aString) const;
PRBool operator!=(const PRUnichar* aString) const; PRBool operator!=(const PRUnichar* aString) const;
@ -646,7 +659,7 @@ PRBool operator!=(const PRUnichar* aString) const;
* @param aString is the string to be compared to this * @param aString is the string to be compared to this
* @return TRUE or FALSE * @return TRUE or FALSE
*/ */
PRBool operator<(const nsString2 &aString) const; PRBool operator<(const nsString &aString) const;
PRBool operator<(const nsStr &aString) const; PRBool operator<(const nsStr &aString) const;
PRBool operator<(const char* aString) const; PRBool operator<(const char* aString) const;
PRBool operator<(const PRUnichar* aString) const; PRBool operator<(const PRUnichar* aString) const;
@ -656,7 +669,7 @@ PRBool operator<(const PRUnichar* aString) const;
* @param aString is the string to be compared to this * @param aString is the string to be compared to this
* @return TRUE or FALSE * @return TRUE or FALSE
*/ */
PRBool operator>(const nsString2 &aString) const; PRBool operator>(const nsString &aString) const;
PRBool operator>(const nsStr &S) const; PRBool operator>(const nsStr &S) const;
PRBool operator>(const char* aString) const; PRBool operator>(const char* aString) const;
PRBool operator>(const PRUnichar* aString) const; PRBool operator>(const PRUnichar* aString) const;
@ -666,7 +679,7 @@ PRBool operator>(const PRUnichar* aString) const;
* @param aString is the string to be compared to this * @param aString is the string to be compared to this
* @return TRUE or FALSE * @return TRUE or FALSE
*/ */
PRBool operator<=(const nsString2 &aString) const; PRBool operator<=(const nsString &aString) const;
PRBool operator<=(const nsStr &S) const; PRBool operator<=(const nsStr &S) const;
PRBool operator<=(const char* aString) const; PRBool operator<=(const char* aString) const;
PRBool operator<=(const PRUnichar* aString) const; PRBool operator<=(const PRUnichar* aString) const;
@ -676,7 +689,7 @@ PRBool operator<=(const PRUnichar* aString) const;
* @param aString is the string to be compared to this * @param aString is the string to be compared to this
* @return TRUE or FALSE * @return TRUE or FALSE
*/ */
PRBool operator>=(const nsString2 &aString) const; PRBool operator>=(const nsString &aString) const;
PRBool operator>=(const nsStr &S) const; PRBool operator>=(const nsStr &S) const;
PRBool operator>=(const char* aString) const; PRBool operator>=(const char* aString) const;
PRBool operator>=(const PRUnichar* aString) const; PRBool operator>=(const PRUnichar* aString) const;
@ -688,20 +701,18 @@ PRBool operator>=(const PRUnichar* aString) const;
* optimization. * optimization.
* *
* @param aString -- the string to compare to this * @param aString -- the string to compare to this
* @param aLength -- optional length of given string. * @param aCount -- number of chars to be compared.
* @return TRUE if equal * @return TRUE if equal
*/ */
PRBool Equals(const nsString2 &aString,PRBool aIgnoreCase=PR_FALSE) const; PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE) const; PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE) const; PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const char* aString,PRUint32 aCount,PRBool aIgnoreCase) const; PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE) const;
PRBool Equals(const PRUnichar* aString,PRUint32 aCount,PRBool aIgnoreCase) const;
PRBool Equals(const nsIAtom* anAtom,PRBool aIgnoreCase) const; PRBool Equals(const nsIAtom* anAtom,PRBool aIgnoreCase) const;
PRBool Equals(const PRUnichar* s1, const PRUnichar* s2,PRBool aIgnoreCase=PR_FALSE) const; PRBool Equals(const PRUnichar* s1, const PRUnichar* s2,PRBool aIgnoreCase=PR_FALSE) const;
PRBool EqualsIgnoreCase(const nsString2& aString) const; PRBool EqualsIgnoreCase(const nsString& aString) const;
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aLength=-1) const; PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(const nsIAtom *aAtom) const; PRBool EqualsIgnoreCase(const nsIAtom *aAtom) const;
PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const; PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const;
@ -730,8 +741,8 @@ static PRBool IsAlpha(PRUnichar ch);
*/ */
static PRBool IsDigit(PRUnichar ch); static PRBool IsDigit(PRUnichar ch);
static void Recycle(nsString2* aString); static void Recycle(nsString* aString);
static nsString2* CreateString(eCharSize aCharSize=eTwoByte); static nsString* CreateString(eCharSize aCharSize=eTwoByte);
virtual void DebugDump(ostream& aStream) const; virtual void DebugDump(ostream& aStream) const;
@ -739,8 +750,8 @@ virtual void DebugDump(ostream& aStream) const;
}; };
extern NS_COM int fputs(const nsString2& aString, FILE* out); extern NS_COM int fputs(const nsString& aString, FILE* out);
ostream& operator<<(ostream& aStream,const nsString2& aString); ostream& operator<<(ostream& aStream,const nsString& aString);
/************************************************************** /**************************************************************
@ -749,36 +760,30 @@ ostream& operator<<(ostream& aStream,const nsString2& aString);
If the buffer needs to grow, it gets reallocated on the heap. If the buffer needs to grow, it gets reallocated on the heap.
**************************************************************/ **************************************************************/
class NS_COM nsAutoString2 : public nsString2 { class NS_COM nsAutoString : public nsString {
public: public:
nsAutoString2(eCharSize aCharSize=kDefaultCharSize); nsAutoString(eCharSize aCharSize=kDefaultCharSize);
nsAutoString2(nsStr& anExtBuffer,const char* aCString); nsAutoString(const char* aCString,eCharSize aCharSize=kDefaultCharSize,PRInt32 aLength=-1);
nsAutoString(const PRUnichar* aString,eCharSize aCharSize=kDefaultCharSize,PRInt32 aLength=-1);
nsAutoString(CSharedStrBuffer& aBuffer);
nsAutoString2(const char* aCString,eCharSize aCharSize=kDefaultCharSize); nsAutoString(const nsStr& aString,eCharSize aCharSize=kDefaultCharSize);
nsAutoString2(char* aCString,PRInt32 aCapacity=-1,eCharSize aCharSize=kDefaultCharSize,PRBool assumeOwnership=PR_FALSE); nsAutoString(const nsAutoString& aString,eCharSize aCharSize=kDefaultCharSize);
nsAutoString2(const PRUnichar* aString,eCharSize aCharSize=kDefaultCharSize);
nsAutoString2(PRUnichar* aString,PRInt32 aCapacity=-1,eCharSize aCharSize=kDefaultCharSize,PRBool assumeOwnership=PR_FALSE);
nsAutoString2(const nsStr& aString,eCharSize aCharSize=kDefaultCharSize);
nsAutoString2(const nsString2& aString,eCharSize aCharSize=kDefaultCharSize);
nsAutoString2(const nsAutoString2& aString,eCharSize aCharSize=kDefaultCharSize);
#ifdef AIX #ifdef AIX
nsAutoString2(const nsSubsumeStr& aSubsumeStr); // AIX requires a const nsAutoString(const nsSubsumeStr& aSubsumeStr); // AIX requires a const
#else #else
nsAutoString2(nsSubsumeStr& aSubsumeStr); nsAutoString(nsSubsumeStr& aSubsumeStr);
#endif // AIX #endif // AIX
nsAutoString2(PRUnichar aChar,eCharSize aCharSize=kDefaultCharSize); nsAutoString(PRUnichar aChar,eCharSize aCharSize=kDefaultCharSize);
virtual ~nsAutoString2(); virtual ~nsAutoString();
nsAutoString2& operator=(const nsString2& aString) {nsString2::operator=(aString); return *this;} nsAutoString& operator=(const nsStr& aString) {nsString::Assign(aString); return *this;}
nsAutoString2& operator=(const nsStr& aString) {nsString2::Assign(aString); return *this;} nsAutoString& operator=(const nsAutoString& aString) {nsString::operator=(aString); return *this;}
nsAutoString2& operator=(const nsAutoString2& aString) {nsString2::operator=(aString); return *this;} nsAutoString& operator=(const char* aCString) {nsString::operator=(aCString); return *this;}
nsAutoString2& operator=(const char* aCString) {nsString2::operator=(aCString); return *this;} nsAutoString& operator=(char aChar) {nsString::operator=(aChar); return *this;}
nsAutoString2& operator=(char aChar) {nsString2::operator=(aChar); return *this;} nsAutoString& operator=(const PRUnichar* aBuffer) {nsString::operator=(aBuffer); return *this;}
nsAutoString2& operator=(const PRUnichar* aBuffer) {nsString2::operator=(aBuffer); return *this;} nsAutoString& operator=(PRUnichar aChar) {nsString::operator=(aChar); return *this;}
nsAutoString2& operator=(PRUnichar aChar) {nsString2::operator=(aChar); return *this;}
/** /**
* Retrieve the size of this string * Retrieve the size of this string
@ -803,24 +808,14 @@ public:
You should probably not use this class unless you really know You should probably not use this class unless you really know
what you're doing. what you're doing.
***************************************************************/ ***************************************************************/
class NS_COM nsSubsumeStr : public nsString2 { class NS_COM nsSubsumeStr : public nsString {
public: public:
nsSubsumeStr(nsString2& aString);
nsSubsumeStr(nsStr& aString); nsSubsumeStr(nsStr& aString);
nsSubsumeStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1); nsSubsumeStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
nsSubsumeStr(char* aString,PRBool assumeOwnership,PRInt32 aLength=-1); nsSubsumeStr(char* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
}; };
/***************************************************************
***************************************************************/
class NS_COM nsCAutoString: public nsAutoString{
public:
nsCAutoString(const nsString2& aString);
operator const char*() const;
};
#endif #endif

Просмотреть файл

@ -0,0 +1,528 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsStringTokenizer.h"
nsStringTokenizer::nsStringTokenizer(const char* aDataSpec,const char* aFieldSep,const char* aRecordSep) :
mDataStartDelimiter(""),
mDataEndDelimiter(""),
mSubstrStartDelimiter(""),
mSubstrEndDelimiter(""),
mFieldSeparator(aFieldSep),
mRecordSeparator(aRecordSep)
{
mBuffer=0;
mOffset=0;
mValidChars[0]=mValidChars[1]=mValidChars[2]=mValidChars[3]=0;
mInvalidChars[0]=mInvalidChars[1]=mInvalidChars[2]=mInvalidChars[3]=0;
ExpandDataSpecifier(aDataSpec);
mCharSpec=eGivenChars;
}
nsStringTokenizer::~nsStringTokenizer(){
}
/**
* This method can tell you whether a given char is in the valid set
* given by the user in the constructor
* @update gess7/10/99
*/
void nsStringTokenizer::SetBuffer(nsString& aBuffer) {
mBuffer=&aBuffer;
}
/**
* This method can tell you whether a given char is in the valid set
* given by the user in the constructor
* @update gess7/10/99
*/
inline PRBool nsStringTokenizer::IsValidDataChar(PRUnichar aChar) {
PRInt32 theByteNum=aChar/32;
PRInt32 theBitNum=aChar-(theByteNum*32);
PRInt32 shift=(1<<theBitNum);
PRInt32 value=PRInt32(mValidChars[theByteNum]&shift);
return PRBool(value>0);
}
inline void SetChars(PRInt32 array[3],PRUnichar aStart,PRUnichar aStop){
PRInt32 theChar;
for(theChar=aStart;theChar<=aStop;theChar++){
PRInt32 theByteNum=theChar/32;
PRInt32 theBitNum=theChar-(theByteNum*32);
PRInt32 shift=(1<<theBitNum);
array[theByteNum]|=shift;
}
}
inline void ClearChars(PRInt32 array[3],PRUnichar aStart,PRUnichar aStop){
PRInt32 theChar;
for(theChar=aStart;theChar<=aStop;theChar++){
PRInt32 theByteNum=theChar/32;
PRInt32 theBitNum=theChar-(theByteNum*32);
PRInt32 shift=(1<<theBitNum);
array[theByteNum]&=(~shift);
}
}
/**
* This method constructs the legal charset and data delimiter pairs.
* Specifier rules are:
* abc -- allows a set of characters
* [a-z] -- allows all chars in given range
* [*-*] -- allows all characters
* ^abc -- disallows a set of characters
* [a^z] -- disallows all characters in given range
* [a*b] -- specifies a delimiter pair for the entire token
* [a+b] -- specifies a delimiter pair for substrings in the token
* @update gess7/10/99
*/
void nsStringTokenizer::ExpandDataSpecifier(const char* aDataSpec) {
if(aDataSpec) {
PRInt32 theIndex=-1;
char theChar=0;
while(theChar=aDataSpec[++theIndex]) {
switch(theChar) {
case '[':
switch(aDataSpec[theIndex+2]){
case '-':
{
char theStart=aDataSpec[theIndex+1];
char theEnd=aDataSpec[theIndex+3];
if(('*'==theStart) && (theStart==theEnd)) {
mCharSpec=eAllChars;
}
else {
SetChars(mValidChars,theStart,theEnd);
}
}
break;
case '^': //specify a range of invalid chars
{
char theStart=aDataSpec[theIndex+1];
char theEnd=aDataSpec[theIndex+3];
SetChars(mInvalidChars,theStart,theEnd);
}
break;
case '*': //this char signals a delimiter pair
mDataStartDelimiter+=aDataSpec[theIndex+1];
mDataEndDelimiter+=aDataSpec[theIndex+3];
break;
case '+': //this char signals a delimiter pair for substrings
mSubstrStartDelimiter+=aDataSpec[theIndex+1];
mSubstrEndDelimiter+=aDataSpec[theIndex+3];
break;
default:
break;
}
theIndex+=4;
break;
case '^'://they've given us a list (not a range) of invalid chars
{
while(theChar=aDataSpec[++theIndex]) {
if('['!=theChar) {
SetChars(mInvalidChars,theChar,theChar);
}
else {
--theIndex;
break;
}
}
}
break;
default:
SetChars(mValidChars,theChar,theChar);
break;
}//switch
}
}
/* DEBUG CODE TO SHOW STRING OF GIVEN CHARSET
CAutoString temp;
for(PRInt32 theChar=0;theChar<128;theChar++){
if(IsValidDataChar(theChar))
temp+=theChar;
}
PRInt32 x=10;
*/
}
nsStringTokenizer::eCharTypes nsStringTokenizer::DetermineCharType(PRUnichar ch) {
eCharTypes result=eUnknown;
if(mRecordSeparator[0]==ch)
result=eRecordSeparator;
else if(mFieldSeparator[0]==ch)
result=eFieldSeparator;
else if((mDataStartDelimiter[0]==ch) || (mDataEndDelimiter[0]==ch))
result=eDataDelimiter;
else if(IsValidDataChar(ch))
result=eDataChar;
return result;
}
/**
* Moves the input stream to the start of the file.
* @update gess7/25/98
* @return yes if all is well
*/
PRBool nsStringTokenizer::FirstRecord(void){
mOffset=0;
return PRBool(mBuffer!=0);
}
/**
* Seeks to next record
* @update gess7/25/98
* @return PR_TRUE if there IS a next record
*/
PRBool nsStringTokenizer::NextRecord(void){
PRBool result=PR_FALSE;
if(mBuffer) {
PRInt32 status=SkipOver(mRecordSeparator);
if(NS_OK==status) {
if(SkipToValidData()) {
if(NS_OK==status) {
result=HasNextToken();
}
}
else result=PR_FALSE;
}
}
return result;
}
/*
* LAST MODS: gess 12Aug94
* PARMS: «»
* RETURNS: YES if there is another field to be read.
* PURPOSE: Allows a client to ask the io system to test for
the presence of another field.
*/
PRBool nsStringTokenizer::HasNextToken(void){
PRBool result=PR_FALSE;
if(mBuffer){
while(More()) {
//Now go test to see if there is any other field data in this record.
//The appropriate algorithm here is to scan the file until you
//find one of following things occurs:
// 1. You find a field separator
// 2. You find a record separator
// 3. You hit the end of the file
// 4. You find a valid char.
PRUnichar theChar;
GetChar(theChar);
switch(DetermineCharType(theChar)){
case eUnknown: //ok to skip junk between delimiters...
if(-1<mSubstrStartDelimiter.Find(theChar)) {
break;
}
case eDataChar:
if(kSpace<theChar) {
UnGetChar(theChar);
return PR_TRUE;
}
break;
case eDataDelimiter:
UnGetChar(theChar);
return PR_TRUE;
case eFieldSeparator:
SkipOver(mFieldSeparator[0]);
return PR_TRUE;
case eRecordSeparator:
UnGetChar(theChar);
return PR_FALSE;
default:
return PR_FALSE;
}
}
}//if
return result;
}
/**
* LAST MODS: gess 4Jul94
* PARMS:
* RETURNS: error code; 0 means all is well.
* PURPOSE: Gets the next field of data from the stream.
* NOTES: This does not currently handle fields that have
field delimiters (ie quotes).
* WARNING: You should have called HasNextToken prior
to calling this method, so that you can
fail gracefully if you encounter the end
of your input stream (unexpectedly). If
this method hits EOF, it returns an error.
*/
PRInt32 nsStringTokenizer::GetNextToken(nsString& aToken){
PRInt32 result=0;
if(mBuffer && More()) {
PRUnichar theChar;
if(mDataStartDelimiter.Length()) {
result=GetChar(theChar); //skip delimiter...
if(mFieldSeparator[0]==theChar)
return result;
aToken+=theChar;
}
if(NS_OK==result) {
PRUnichar theTerm[]={mFieldSeparator[0],mRecordSeparator[0],0,0};
if(mDataEndDelimiter.Length()) {
theTerm[2]=mDataEndDelimiter[0];
}
result=ReadUntil(aToken,theTerm,PRBool(0!=mDataEndDelimiter[0]));
if(NS_OK==result) {
PRInt32 status=SkipOver(mFieldSeparator[0]);
}
}
}
return result;
}
/*
* This method gets called when the system wants to jump over any garbage before that may be in a
* string. Typically, this happens before, inbetween and after valid data rows.
*
* LAST MODS: gess 11Aug94
* RETURNS: 0 if all is well; non-zero for error. If you hit EOF, return 0.
*/
PRBool nsStringTokenizer::SkipToValidData(void){
PRInt32 result=0;
PRUnichar ch;
if(mBuffer) {
while(More()) {
result=GetChar(ch);
switch(DetermineCharType(ch)){
case eDataChar:
if(!mDataStartDelimiter[0]) {
UnGetChar(ch);
return PR_TRUE;
}
break;
case eDataDelimiter:
if(ch==mDataStartDelimiter[0]) {
UnGetChar(ch);
return PR_TRUE;
}
break;
case eFieldSeparator:
case eRecordSeparator:
UnGetChar(ch);
return PR_TRUE;
default:
break;
} //switch
} //while
}//if
return PR_FALSE;
}
PRInt32 nsStringTokenizer::SkipOver(PRUnichar aSkipChar) {
PRUnichar theChar=0;
PRInt32 result=NS_OK;
if(mBuffer) {
while(NS_OK==result) {
result=GetChar(theChar);
if(NS_OK == result) {
if(theChar!=aSkipChar) {
UnGetChar(theChar);
break;
}
}
else break;
} //while
}//if
return result;
}
PRInt32 nsStringTokenizer::SkipOver(nsString& aString) {
PRUnichar theChar=0;
PRInt32 result=NS_OK;
if(mBuffer) {
while(NS_OK==result) {
result=GetChar(theChar);
if(NS_OK == result) {
PRInt32 index=aString.Find(theChar);
if(-1==index) {
UnGetChar(theChar);
break;
}
}
else break;
} //while
} //if
return result;
}
PRInt32 nsStringTokenizer::ReadUntil(nsString& aString,PRUnichar* aTermSet,PRBool addTerminal){
PRInt32 result=NS_OK;
PRUnichar theChar=0;
PRBool theCharIsValid;
if(mBuffer) {
while(NS_OK == result) {
result=GetChar(theChar);
if(NS_OK==result) {
PRBool found=PR_FALSE;
PRInt32 index=-1;
while(aTermSet[++index]){
if(theChar==aTermSet[index]){
found=PR_TRUE;
break;
}
}
if(found) {
if(addTerminal)
aString+=theChar;
else UnGetChar(theChar);
break;
}
else {
PRInt32 pos=mSubstrStartDelimiter.Find(theChar);
if(-1<pos) {
aString+=theChar;
result=ReadUntil(aString,mSubstrEndDelimiter[pos],PR_TRUE);
}
else if(theCharIsValid){
if(IsValidDataChar(theChar)){
aString+=theChar;
}
else theCharIsValid=PR_FALSE;
}
} //else
} //if
} //while
}//if
return result;
}
PRInt32 nsStringTokenizer::ReadUntil(nsString& aString,PRUnichar aTerminalChar,PRBool addTerminal){
PRInt32 result=NS_OK;
PRUnichar theChar=0;
if(mBuffer) {
while(NS_OK == result) {
result=GetChar(theChar);
if(NS_OK==result) {
if(theChar==aTerminalChar){
if(addTerminal)
aString+=theChar;
else UnGetChar(theChar);
break;
}
else aString+=theChar;
}//if
} //while
}//if
return result;
}
PRBool nsStringTokenizer::More(void){
PRBool result=PR_FALSE;
if(mBuffer) {
if(mOffset<mBuffer->Length())
result=PR_TRUE;
}
return result;
}
PRInt32 nsStringTokenizer::GetChar(PRUnichar& aChar){
PRInt32 result=kEOF;
if(mBuffer) {
if(mOffset<mBuffer->Length()) {
aChar=(*mBuffer)[mOffset++];
result=0;
}
}
return result;
}
void nsStringTokenizer::UnGetChar(PRUnichar aChar){
if(mOffset>0)
mOffset--;
}
/*
* Call this method if you want the tokenizer to iterate your string
* and automatically call you back with each token
*
* @parm aFunctor is the object you want me to notify
* @update gess 07/10/99
* RETURNS: 0 if all went well
*/
PRInt32 nsStringTokenizer::Iterate(nsString& aBuffer,ITokenizeFunctor& aFunctor) {
PRInt32 result=0;
PRInt32 theRecordNum=-1;
nsString* theOldBuffer=mBuffer;
mBuffer=&aBuffer;
FirstRecord();
while(HasNextToken()){
theRecordNum++;
PRInt32 theTokenNum=-1;
while(HasNextToken()){
theTokenNum++;
nsAutoString theString;
GetNextToken(theString);
aFunctor(theString,theRecordNum,theTokenNum);
}
NextRecord();
}
mBuffer=theOldBuffer;
return result;
}

Просмотреть файл

@ -31,8 +31,8 @@
#include "nsStr.h" #include "nsStr.h"
#include "bufferRoutines.h" #include "bufferRoutines.h"
#include "stdio.h" //only used for printf #include "stdio.h" //only used for printf
#include "nsDeque.h"
#include "nsCRT.h" #include "nsCRT.h"
#include "nsDeque.h"
static const char* kFoolMsg = "Error: Some fool overwrote the shared buffer."; static const char* kFoolMsg = "Error: Some fool overwrote the shared buffer.";
@ -44,6 +44,8 @@ static const char* kFoolMsg = "Error: Some fool overwrote the shared buffer.";
/************************************************************** /**************************************************************
Define the char* (pooled) deallocator class... Define the char* (pooled) deallocator class...
**************************************************************/ **************************************************************/
/*
class nsBufferDeallocator: public nsDequeFunctor{ class nsBufferDeallocator: public nsDequeFunctor{
public: public:
virtual void* operator()(void* anObject) { virtual void* operator()(void* anObject) {
@ -53,12 +55,6 @@ public:
} }
}; };
/**
*
* @update gess10/30/98
* @param
* @return
*/
class nsPoolingMemoryAgent : public nsMemoryAgent{ class nsPoolingMemoryAgent : public nsMemoryAgent{
public: public:
nsPoolingMemoryAgent() { nsPoolingMemoryAgent() {
@ -128,6 +124,8 @@ public:
nsDeque* mPools[16]; nsDeque* mPools[16];
}; };
*/
static char* gCommonEmptyBuffer=0; static char* gCommonEmptyBuffer=0;
/** /**
* *
@ -151,7 +149,8 @@ char* GetSharedEmptyBuffer() {
} }
/** /**
* * This method initializes all the members of the nsStr structure
*
* @update gess10/30/98 * @update gess10/30/98
* @param * @param
* @return * @return
@ -166,7 +165,7 @@ void nsStr::Initialize(nsStr& aDest,eCharSize aCharSize) {
} }
/** /**
* * This method initializes all the members of the nsStr structure
* @update gess10/30/98 * @update gess10/30/98
* @param * @param
* @return * @return
@ -193,7 +192,7 @@ nsIMemoryAgent* GetDefaultAgent(void){
} }
/** /**
* * This member destroys the memory buffer owned by an nsStr object (if it actually owns it)
* @update gess10/30/98 * @update gess10/30/98
* @param * @param
* @return * @return
@ -386,9 +385,10 @@ void nsStr::Truncate(nsStr& aDest,PRUint32 aDestOffset,nsIMemoryAgent* anAgent){
/** /**
* * This method forces the given string to upper or lowercase
* @update gess1/7/99 * @update gess1/7/99
* @param * @param aDest is the string you're going to change
* @param aToUpper: if TRUE, then we go uppercase, otherwise we go lowercase
* @return * @return
*/ */
void nsStr::ChangeCase(nsStr& aDest,PRBool aToUpper) { void nsStr::ChangeCase(nsStr& aDest,PRBool aToUpper) {
@ -397,19 +397,6 @@ void nsStr::ChangeCase(nsStr& aDest,PRBool aToUpper) {
NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg); NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg);
} }
/**
*
* @update gess1/7/99
* @param
* @return
*/
void nsStr::StripChars(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,const char* aCharSet){
PRUint32 aNewLen=gStripChars[aDest.mCharSize](aDest.mStr,aDestOffset,aCount,aCharSet);
aDest.mLength=aNewLen;
NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg);
}
/** /**
* *
* @update gess1/7/99 * @update gess1/7/99
@ -417,8 +404,43 @@ void nsStr::StripChars(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,const ch
* @return * @return
*/ */
void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){ void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){
PRUint32 aNewLen=gTrimChars[aDest.mCharSize](aDest.mStr,aDest.mLength,aSet,aEliminateLeading,aEliminateTrailing);
aDest.mLength=aNewLen; if((aDest.mLength>0) && aSet){
PRInt32 theIndex=-1;
PRInt32 theMax=aDest.mLength;
PRInt32 theSetLen=nsCRT::strlen(aSet);
if(aEliminateLeading) {
while(++theIndex<=theMax) {
PRUnichar theChar=GetCharAt(aDest,theIndex);
PRInt32 thePos=gFindChars[eOneByte](aSet,theSetLen,0,theChar,PR_FALSE);
if(kNotFound==thePos)
break;
}
if(0<theIndex) {
if(theIndex<theMax) {
Delete(aDest,0,theIndex,0);
}
else Truncate(aDest,0);
}
}
if(aEliminateTrailing) {
theIndex=aDest.mLength;
PRInt32 theNewLen=theIndex;
while(--theIndex>0) {
PRUnichar theChar=GetCharAt(aDest,theIndex); //read at end now...
PRInt32 thePos=gFindChars[eOneByte](aSet,theSetLen,0,theChar,PR_FALSE);
if(kNotFound<thePos)
theNewLen=theIndex;
else break;
}
if(theNewLen<theMax) {
Truncate(aDest,theNewLen);
}
}
}
NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg); NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg);
} }
@ -428,8 +450,9 @@ void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool a
* @param * @param
* @return * @return
*/ */
void nsStr::CompressSet(nsStr& aDest,const char* aSet,PRUint32 aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing){ void nsStr::CompressSet(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){
PRUint32 aNewLen=gCompressChars[aDest.mCharSize](aDest.mStr,aDest.mLength,aSet,aChar,aEliminateLeading,aEliminateTrailing); Trim(aDest,aSet,aEliminateLeading,aEliminateTrailing);
PRUint32 aNewLen=gCompressChars[aDest.mCharSize](aDest.mStr,aDest.mLength,aSet);
aDest.mLength=aNewLen; aDest.mLength=aNewLen;
NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg); NS_ASSERTION(gCommonEmptyBuffer[0]==0,kFoolMsg);
} }
@ -439,15 +462,28 @@ void nsStr::CompressSet(nsStr& aDest,const char* aSet,PRUint32 aChar,PRBool aEli
**************************************************************/ **************************************************************/
/**
* This searches aDest for a given substring
*
* @update gess 3/25/98
* @param aDest string to search
* @param aTarget is the substring you're trying to find.
* @param aIgnorecase indicates case sensitivity of search
* @param anOffset tells us where to start the search
* @return index in aDest where member of aSet occurs, or -1 if not found
*/
PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRUint32 anOffset) { PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRUint32 anOffset) {
if((aDest.mLength>0) && (aTarget.mLength>0) && (anOffset<aTarget.mLength)){
int32 index=anOffset-1; PRInt32 result=kNotFound;
int32 theMax=aDest.mLength-aTarget.mLength;
if((aDest.mLength>0) && (aTarget.mLength>0)){ if(anOffset<aDest.mLength) {
int32 theTargetMax=aTarget.mLength; PRInt32 theMax=aDest.mLength-aTarget.mLength;
while(++index<=theMax) { PRInt32 index=(anOffset ? anOffset : theMax);
int32 theSubIndex=-1;
if((aDest.mLength>=aTarget.mLength) && (aTarget.mLength>0) && (index>=0)){
PRInt32 theTargetMax=aTarget.mLength;
while(index<=theMax) {
PRInt32 theSubIndex=-1;
PRBool matches=PR_TRUE; PRBool matches=PR_TRUE;
while((++theSubIndex<theTargetMax) && (matches)){ while((++theSubIndex<theTargetMax) && (matches)){
PRUnichar theChar=(aIgnoreCase) ? nsCRT::ToLower(GetCharAt(aDest,index+theSubIndex)) : GetCharAt(aDest,index+theSubIndex); PRUnichar theChar=(aIgnoreCase) ? nsCRT::ToLower(GetCharAt(aDest,index+theSubIndex)) : GetCharAt(aDest,index+theSubIndex);
@ -455,20 +491,26 @@ PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnor
matches=PRBool(theChar==theTargetChar); matches=PRBool(theChar==theTargetChar);
} }
if(matches) { if(matches) {
return index; result=index;
break;
} }
} index++;
} //while
}//if }//if
} }//if
return kNotFound; return result;
} }
/** /**
* * This searches aDest for a given character
* @update gess1/7/99 *
* @param * @update gess 3/25/98
* @return * @param aDest string to search
* @param char is the character you're trying to find.
* @param aIgnorecase indicates case sensitivity of search
* @param anOffset tells us where to start the search
* @return index in aDest where member of aSet occurs, or -1 if not found
*/ */
PRInt32 nsStr::FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) { PRInt32 nsStr::FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
PRInt32 result=gFindChars[aDest.mCharSize](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase); PRInt32 result=gFindChars[aDest.mCharSize](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase);
@ -477,17 +519,20 @@ PRInt32 nsStr::FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,P
/** /**
* * This searches aDest for a character found in aSet.
* *
* @update gess 3/25/98 * @update gess 3/25/98
* @param * @param aDest string to search
* @return * @param aSet contains a list of chars to be searched for
* @param aIgnorecase indicates case sensitivity of search
* @param anOffset tells us where to start the search
* @return index in aDest where member of aSet occurs, or -1 if not found
*/ */
PRInt32 nsStr::FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRUint32 anOffset) { PRInt32 nsStr::FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRUint32 anOffset) {
PRUint32 index=anOffset-1; PRInt32 index=anOffset-1;
PRInt32 thePos; PRInt32 thePos;
while(++index<aDest.mLength) { while(++index<(PRInt32)aDest.mLength) {
PRUnichar theChar=GetCharAt(aDest,index); PRUnichar theChar=GetCharAt(aDest,index);
thePos=gFindChars[aSet.mCharSize](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase); thePos=gFindChars[aSet.mCharSize](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase);
if(kNotFound!=thePos) if(kNotFound!=thePos)
@ -501,46 +546,64 @@ PRInt32 nsStr::FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnore
**************************************************************/ **************************************************************/
/**
* This searches aDest (in reverse) for a given substring
*
* @update gess 3/25/98
* @param aDest string to search
* @param aTarget is the substring you're trying to find.
* @param aIgnorecase indicates case sensitivity of search
* @param anOffset tells us where to start the search
* @return index in aDest where member of aSet occurs, or -1 if not found
*/
PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRUint32 anOffset) { PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRUint32 anOffset) {
PRInt32 index=(anOffset ? anOffset : aDest.mLength-aTarget.mLength+1);
PRInt32 result=kNotFound; PRInt32 result=kNotFound;
if((aDest.mLength>0) && (aTarget.mLength>0)){ if(anOffset<aDest.mLength) {
PRInt32 index=(anOffset ? anOffset : aDest.mLength-aTarget.mLength);
if((aDest.mLength>=aTarget.mLength) && (aTarget.mLength>0) && (index>=0)){
nsStr theCopy; nsStr theCopy;
nsStr::Initialize(theCopy,eOneByte); nsStr::Initialize(theCopy,eOneByte);
nsStr::Assign(theCopy,aTarget,0,aTarget.mLength,0); nsStr::Assign(theCopy,aTarget,0,aTarget.mLength,0);
if(aIgnoreCase){ if(aIgnoreCase){
nsStr::ChangeCase(theCopy,PR_FALSE); //force to lowercase nsStr::ChangeCase(theCopy,PR_FALSE); //force to lowercase
}
int32 theTargetMax=theCopy.mLength;
while(index--) {
int32 theSubIndex=-1;
PRBool matches=PR_TRUE;
if(anOffset+theCopy.mLength<=aDest.mLength) {
while((++theSubIndex<theTargetMax) && (matches)){
PRUnichar theDestChar=(aIgnoreCase) ? nsCRT::ToLower(GetCharAt(aDest,index+theSubIndex)) : GetCharAt(aDest,index+theSubIndex);
PRUnichar theTargetChar=GetCharAt(theCopy,theSubIndex);
matches=PRBool(theDestChar==theTargetChar);
} //while
} //if
if(matches) {
result=index;
break;
} }
} //while
nsStr::Destroy(theCopy,0); PRInt32 theTargetMax=theCopy.mLength;
while(index>=0) {
PRInt32 theSubIndex=-1;
PRBool matches=PR_FALSE;
if(index+theCopy.mLength<=aDest.mLength) {
matches=PR_TRUE;
while((++theSubIndex<theTargetMax) && (matches)){
PRUnichar theDestChar=(aIgnoreCase) ? nsCRT::ToLower(GetCharAt(aDest,index+theSubIndex)) : GetCharAt(aDest,index+theSubIndex);
PRUnichar theTargetChar=GetCharAt(theCopy,theSubIndex);
matches=PRBool(theDestChar==theTargetChar);
} //while
} //if
if(matches) {
result=index;
break;
}
index--;
} //while
nsStr::Destroy(theCopy,0);
}//if
}//if }//if
return result; return result;
} }
/** /**
* * This searches aDest (in reverse) for a given character
* @update gess1/7/99 *
* @param * @update gess 3/25/98
* @return * @param aDest string to search
* @param char is the character you're trying to find.
* @param aIgnorecase indicates case sensitivity of search
* @param anOffset tells us where to start the search
* @return index in aDest where member of aSet occurs, or -1 if not found
*/ */
PRInt32 nsStr::RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) { PRInt32 nsStr::RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
PRInt32 result=gRFindChars[aDest.mCharSize](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase); PRInt32 result=gRFindChars[aDest.mCharSize](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase);
@ -548,14 +611,17 @@ PRInt32 nsStr::RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,
} }
/** /**
* * This searches aDest (in reverese) for a character found in aSet.
* *
* @update gess 3/25/98 * @update gess 3/25/98
* @param * @param aDest string to search
* @return * @param aSet contains a list of chars to be searched for
* @param aIgnorecase indicates case sensitivity of search
* @param anOffset tells us where to start the search
* @return index in aDest where member of aSet occurs, or -1 if not found
*/ */
PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRUint32 anOffset) { PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRUint32 anOffset) {
PRUint32 offset=aDest.mLength-anOffset; PRInt32 offset=aDest.mLength-anOffset;
PRInt32 thePos; PRInt32 thePos;
while(--offset>=0) { while(--offset>=0) {
@ -569,24 +635,61 @@ PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnor
/** /**
* * Compare source and dest strings, up to an (optional max) number of chars
* @update gess11/12/98 * @param aDest is the first str to compare
* @param * @param aSource is the second str to compare
* @param aCount -- if (-1), then we use length of longer string; if (0<aCount) then it gives the max # of chars to compare
* @param aIgnorecase tells us whether to search with case sensitivity
* @return aDest<aSource=-1;aDest==aSource==0;aDest>aSource=1 * @return aDest<aSource=-1;aDest==aSource==0;aDest>aSource=1
*/ */
PRInt32 nsStr::Compare(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) { PRInt32 nsStr::Compare(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) {
int minlen=(aSource.mLength<aDest.mLength) ? aSource.mLength : aDest.mLength; PRInt32 result=0;
if(0==minlen) { if(aCount) {
if ((aDest.mLength == 0) && (aSource.mLength == 0)) PRInt32 minlen=(aSource.mLength<aDest.mLength) ? aSource.mLength : aDest.mLength;
return 0;
if (aDest.mLength == 0) if(0==minlen) {
return -1; if ((aDest.mLength == 0) && (aSource.mLength == 0))
return 1; return 0;
if (aDest.mLength == 0)
return -1;
return 1;
}
PRInt32 maxlen=(aSource.mLength<aDest.mLength) ? aDest.mLength : aSource.mLength;
aCount = (aCount<0) ? maxlen : MinInt(aCount,maxlen);
result=(*gCompare[aDest.mCharSize][aSource.mCharSize])(aDest.mStr,aSource.mStr,aCount,aIgnoreCase);
} }
int maxlen=(aSource.mLength<aDest.mLength) ? aDest.mLength : aSource.mLength;
PRInt32 result=(*gCompare[aDest.mCharSize][aSource.mCharSize])(aDest.mStr,aSource.mStr,maxlen,aIgnoreCase);
return result; return result;
} }
//----------------------------------------------------------------------------------------
CSharedStrBuffer::CSharedStrBuffer(char* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength) {
mBuffer=aString;
mCharSize=eOneByte;
mStackBased=aStackBased;
mLength=mCapacity=0;
if(aString && aCapacity>1) {
mCapacity=aCapacity-1;
mLength=(-1==aLength) ? strlen(aString) : aLength;
if(mLength>PRInt32(mCapacity))
mLength=mCapacity;
}
}
CSharedStrBuffer::CSharedStrBuffer(PRUnichar* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength) {
mBuffer=(char*)aString;
mCharSize=eTwoByte;
mStackBased=aStackBased;
mLength=mCapacity=0;
if(aString && aCapacity>1) {
mCapacity=aCapacity-1;
mLength=(-1==aLength) ? nsCRT::strlen(aString) : aLength;
if(mLength>PRInt32(mCapacity))
mLength=mCapacity;
}
}
//----------------------------------------------------------------------------------------

Просмотреть файл

@ -48,6 +48,10 @@
enum eCharSize {eOneByte=0,eTwoByte=1}; enum eCharSize {eOneByte=0,eTwoByte=1};
#define kDefaultCharSize eTwoByte #define kDefaultCharSize eTwoByte
#define kRadix10 (10)
#define kRadix16 (16)
#define kAutoDetect (100)
#define kRadixUnknown (kAutoDetect+1)
const PRInt32 kNotFound = -1; const PRInt32 kNotFound = -1;
@ -55,6 +59,21 @@ class nsIMemoryAgent;
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
class CSharedStrBuffer {
public:
CSharedStrBuffer(char* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength=-1);
CSharedStrBuffer(PRUnichar* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength=-1);
char* mBuffer;
eCharSize mCharSize;
PRUint32 mCapacity;
PRInt32 mLength;
PRBool mStackBased;
};
//----------------------------------------------------------------------------------------
struct nsStr { struct nsStr {
@ -169,16 +188,6 @@ struct nsStr {
*/ */
static void ChangeCase(nsStr& aDest,PRBool aToUpper); static void ChangeCase(nsStr& aDest,PRBool aToUpper);
/**
* This method removes chars (given in aSet) from the given buffer
*
* @update gess 01/04/99
* @param aString is the buffer to be manipulated
* @param aDestOffset is starting pos in buffer for manipulation
* @param aCount is the number of chars to compare
* @param aSet tells us which chars to remove from given buffer
*/
static void StripChars(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,const char* aCharSet);
/** /**
* This method trims chars (given in aSet) from the edges of given buffer * This method trims chars (given in aSet) from the edges of given buffer
@ -201,7 +210,7 @@ struct nsStr {
* @param aEliminateLeading tells us whether to strip chars from the start of the 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 * @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
*/ */
static void CompressSet(nsStr& aDest,const char* aSet,PRUint32 aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing); static void CompressSet(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing);
/** /**
* This method compares the data bewteen two nsStr's * This method compares the data bewteen two nsStr's

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -30,19 +30,17 @@
***********************************************************************/ ***********************************************************************/
#ifndef _nsString2 #ifndef _nsString_
#define _nsString2 #define _nsString_
#include "prtypes.h" #include "prtypes.h"
#include "nscore.h" #include "nscore.h"
#include <iostream.h> #include <iostream.h>
#include <stdio.h> #include <stdio.h>
#include "nsCRT.h" #include "nsCRT.h"
#include "nsString.h"
#include "nsStr.h"
#include <iostream.h>
#include <stdio.h>
#include "nsIAtom.h" #include "nsIAtom.h"
#include "nsStr.h"
class nsISizeOfHandler; class nsISizeOfHandler;
@ -50,14 +48,9 @@ class nsISizeOfHandler;
#define nsString2 nsString #define nsString2 nsString
#define nsAutoString2 nsAutoString #define nsAutoString2 nsAutoString
#define kRadix10 (10)
#define kRadix16 (16)
#define kAutoDetect (100)
#define kRadixUnknown (kAutoDetect+1)
class NS_COM nsSubsumeStr; class NS_COM nsSubsumeStr;
class NS_COM nsString2 : public nsStr { class NS_COM nsString : public nsStr {
public: public:
@ -67,44 +60,44 @@ class NS_COM nsString2 : public nsStr {
* was to allow developers direct access to the underlying buffer for * was to allow developers direct access to the underlying buffer for
* performance reasons. * performance reasons.
*/ */
nsString2(eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAgent=0); nsString(eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAgent=0);
/** /**
* This constructor accepts an isolatin string * This constructor accepts an isolatin string
* @param aCString is a ptr to a 1-byte cstr * @param aCString is a ptr to a 1-byte cstr
*/ */
nsString2(const char* aCString,eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAgent=0); nsString(const char* aCString,eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAgent=0);
/** /**
* This constructor accepts a unichar string * This constructor accepts a unichar string
* @param aCString is a ptr to a 2-byte cstr * @param aCString is a ptr to a 2-byte cstr
*/ */
nsString2(const PRUnichar* aString,eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAgent=0); nsString(const PRUnichar* aString,eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAgent=0);
/** /**
* This is a copy constructor that accepts an nsStr * This is a copy constructor that accepts an nsStr
* @param reference to another nsString2 * @param reference to another nsString
*/ */
nsString2(const nsStr&,eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAgent=0); nsString(const nsStr&,eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAgent=0);
/** /**
* This is our copy constructor * This is our copy constructor
* @param reference to another nsString2 * @param reference to another nsString
*/ */
nsString2(const nsString2& aString); nsString(const nsString& aString);
/** /**
* This constructor takes a subsumestr * This constructor takes a subsumestr
* @param reference to subsumestr * @param reference to subsumestr
*/ */
nsString2(nsSubsumeStr& aSubsumeStr); nsString(nsSubsumeStr& aSubsumeStr);
/** /**
* Destructor * Destructor
* *
*/ */
virtual ~nsString2(); virtual ~nsString();
/** /**
* Retrieve the length of this string * Retrieve the length of this string
@ -120,13 +113,13 @@ virtual void SizeOf(nsISizeOfHandler* aHandler) const;
/** /**
* Call this method if you want to force a different string capacity * Call this method if you want to force a different string length
* @update gess7/30/98 * @update gess7/30/98
* @param aLength -- contains new length for mStr * @param aLength -- contains new length for mStr
* @return * @return
*/ */
void SetLength(PRUint32 aLength) { void SetLength(PRUint32 aLength) {
SetCapacity(aLength); Truncate(aLength);
} }
/** /**
@ -173,7 +166,7 @@ PRBool IsEmpty(void) const {
} }
/********************************************************************** /**********************************************************************
Accessor methods... Getters/Setters...
*********************************************************************/ *********************************************************************/
const char* GetBuffer(void) const; const char* GetBuffer(void) const;
@ -188,11 +181,14 @@ PRUnichar CharAt(PRUint32 anIndex) const;
PRUnichar First(void) const; PRUnichar First(void) const;
PRUnichar Last(void) const; PRUnichar Last(void) const;
/**
* Set nth character.
*/
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex); PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
/********************************************************************** /**********************************************************************
String creation methods... String concatenation methods...
*********************************************************************/ *********************************************************************/
/** /**
@ -201,13 +197,7 @@ PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
* @return new string * @return new string
*/ */
nsSubsumeStr operator+(const nsStr& aString); nsSubsumeStr operator+(const nsStr& aString);
nsSubsumeStr operator+(const nsString& aString);
/**
* Create a new string by appending given string to this
* @param aString -- 2nd string to be appended
* @return new string
*/
nsSubsumeStr operator+(const nsString2& aString);
/** /**
* create a new string by adding this to the given buffer. * create a new string by adding this to the given buffer.
@ -260,7 +250,7 @@ void ToLowerCase();
* @update gess 7/27/98 * @update gess 7/27/98
* @param aOut is a string to contain result * @param aOut is a string to contain result
*/ */
void ToLowerCase(nsString2& aString) const; void ToLowerCase(nsString& aString) const;
/** /**
* Converts chars in this to uppercase * Converts chars in this to uppercase
@ -274,7 +264,7 @@ void ToUpperCase();
* @update gess 7/27/98 * @update gess 7/27/98
* @param aOut is a string to contain result * @param aOut is a string to contain result
*/ */
void ToUpperCase(nsString2& aString) const; void ToUpperCase(nsString& aString) const;
/** /**
@ -284,21 +274,22 @@ void ToUpperCase(nsString2& aString) const;
* @param aSet -- characters to be cut from this * @param aSet -- characters to be cut from this
* @return *this * @return *this
*/ */
nsString2& StripChars(const char* aSet); nsString& StripChars(const char* aSet);
/** /**
* This method strips whitespace throughout the string * This method strips whitespace throughout the string
* *
* @return this * @return this
*/ */
nsString2& StripWhitespace(); nsString& StripWhitespace();
/** /**
* swaps occurence of 1 string for another * swaps occurence of 1 string for another
* *
* @return this * @return this
*/ */
nsString2& ReplaceChar(PRUnichar aSourceChar,PRUnichar aDestChar); nsString& ReplaceChar(PRUnichar anOldChar,PRUnichar aNewChar);
nsString& ReplaceChar(const char* aSet,PRUnichar aNewChar);
/** /**
* This method trims characters found in aTrimSet from * This method trims characters found in aTrimSet from
@ -308,7 +299,7 @@ nsString2& ReplaceChar(PRUnichar aSourceChar,PRUnichar aDestChar);
* both ends * both ends
* @return this * @return this
*/ */
nsString2& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); nsString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/** /**
* This method strips whitespace from string. * This method strips whitespace from string.
@ -319,7 +310,7 @@ nsString2& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aElimin
* @param aEliminateTrailing controls stripping of trailing ws * @param aEliminateTrailing controls stripping of trailing ws
* @return this * @return this
*/ */
nsString2& CompressSet(const char* aSet, char aChar, PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); nsString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/** /**
* This method strips whitespace from string. * This method strips whitespace from string.
@ -330,18 +321,18 @@ nsString2& CompressSet(const char* aSet, char aChar, PRBool aEliminateLeading=PR
* @param aEliminateTrailing controls stripping of trailing ws * @param aEliminateTrailing controls stripping of trailing ws
* @return this * @return this
*/ */
nsString2& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); nsString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/********************************************************************** /**********************************************************************
string conversion methods... string conversion methods...
*********************************************************************/ *********************************************************************/
/** /**
* This method constructs a new nsString2 on the stack that is a copy * This method constructs a new nsString on the stack that is a copy
* of this string. * of this string.
* *
*/ */
nsString2* ToNewString() const; nsString* ToNewString() const;
/** /**
* Creates an ISOLatin1 clone of this string * Creates an ISOLatin1 clone of this string
@ -392,9 +383,9 @@ PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const;
* Functionally equivalent to assign or operator= * Functionally equivalent to assign or operator=
* *
*/ */
nsString2& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} nsString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsString2& SetString(const PRUnichar* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} nsString& SetString(const PRUnichar* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
nsString2& SetString(const nsString2& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);} nsString& SetString(const nsString& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
/** /**
* assign given string to this string * assign given string to this string
@ -403,28 +394,27 @@ nsString2& SetString(const nsString2& aString,PRInt32 aLength=-1) {return Assign
if you want me to determine its length if you want me to determine its length
* @return this * @return this
*/ */
nsString2& Assign(const nsString2& aString,PRInt32 aCount=-1); nsString& Assign(const nsStr& aString,PRInt32 aCount=-1);
nsString2& Assign(const nsStr& aString,PRInt32 aCount=-1); nsString& Assign(const char* aString,PRInt32 aCount=-1);
nsString2& Assign(const char* aString,PRInt32 aCount=-1); nsString& Assign(const PRUnichar* aString,PRInt32 aCount=-1);
nsString2& Assign(const PRUnichar* aString,PRInt32 aCount=-1); nsString& Assign(char aChar);
nsString2& Assign(char aChar); nsString& Assign(PRUnichar aChar);
nsString2& Assign(PRUnichar aChar);
/** /**
* here come a bunch of assignment operators... * here come a bunch of assignment operators...
* @param aString: string to be added to this * @param aString: string to be added to this
* @return this * @return this
*/ */
nsString2& operator=(const nsString2& aString) {return Assign(aString);} nsString& operator=(const nsString& aString) {return Assign(aString);}
nsString2& operator=(const nsStr& aString) {return Assign(aString);} nsString& operator=(const nsStr& aString) {return Assign(aString);}
nsString2& operator=(char aChar) {return Assign(aChar);} nsString& operator=(char aChar) {return Assign(aChar);}
nsString2& operator=(PRUnichar aChar) {return Assign(aChar);} nsString& operator=(PRUnichar aChar) {return Assign(aChar);}
nsString2& operator=(const char* aCString) {return Assign(aCString);} nsString& operator=(const char* aCString) {return Assign(aCString);}
nsString2& operator=(const PRUnichar* aString) {return Assign(aString);} nsString& operator=(const PRUnichar* aString) {return Assign(aString);}
#ifdef AIX #ifdef AIX
nsString2& operator=(const nsSubsumeStr& aSubsumeString); // AIX requires a const here nsString& operator=(const nsSubsumeStr& aSubsumeString); // AIX requires a const here
#else #else
nsString2& operator=(nsSubsumeStr& aSubsumeString); nsString& operator=(nsSubsumeStr& aSubsumeString);
#endif #endif
/** /**
@ -432,12 +422,12 @@ nsString2& operator=(nsSubsumeStr& aSubsumeString);
* @param aString : string to be appended to this * @param aString : string to be appended to this
* @return this * @return this
*/ */
nsString2& operator+=(const nsStr& aString){return Append(aString,aString.mLength);} nsString& operator+=(const nsStr& aString){return Append(aString,aString.mLength);}
nsString2& operator+=(const nsString2& aString){return Append(aString,aString.mLength);} nsString& operator+=(const nsString& aString){return Append(aString,aString.mLength);}
nsString2& operator+=(const char* aCString) {return Append(aCString);} nsString& operator+=(const char* aCString) {return Append(aCString);}
//nsString2& operator+=(char aChar){return Append(aChar);} //nsString& operator+=(char aChar){return Append(aChar);}
nsString2& operator+=(const PRUnichar* aUCString) {return Append(aUCString);} nsString& operator+=(const PRUnichar* aUCString) {return Append(aUCString);}
nsString2& operator+=(PRUnichar aChar){return Append(aChar);} nsString& operator+=(PRUnichar aChar){return Append(aChar);}
/* /*
* Appends n characters from given string to this, * Appends n characters from given string to this,
@ -446,8 +436,8 @@ nsString2& operator+=(PRUnichar aChar){return Append(aChar);}
* @param aString is the source to be appended to this * @param aString is the source to be appended to this
* @return number of chars copied * @return number of chars copied
*/ */
nsString2& Append(const nsStr& aString) {return Append(aString,aString.mLength);} nsString& Append(const nsStr& aString) {return Append(aString,aString.mLength);}
nsString2& Append(const nsString2& aString) {return Append(aString,aString.mLength);} nsString& Append(const nsString& aString) {return Append(aString,aString.mLength);}
/* /*
@ -457,14 +447,14 @@ nsString2& Append(const nsString2& aString) {return Append(aString,aString.mLeng
* @param aCount -- number of chars to copy * @param aCount -- number of chars to copy
* @return number of chars copied * @return number of chars copied
*/ */
nsString2& Append(const nsStr& aString,PRInt32 aCount); nsString& Append(const nsStr& aString,PRInt32 aCount);
nsString2& Append(const nsString2& aString,PRInt32 aCount); nsString& Append(const nsString& aString,PRInt32 aCount);
nsString2& Append(const char* aString,PRInt32 aCount=-1); nsString& Append(const char* aString,PRInt32 aCount=-1);
nsString2& Append(const PRUnichar* aString,PRInt32 aCount=-1); nsString& Append(const PRUnichar* aString,PRInt32 aCount=-1);
nsString2& Append(char aChar); nsString& Append(char aChar);
nsString2& Append(PRUnichar aChar); nsString& Append(PRUnichar aChar);
nsString2& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16 nsString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16
nsString2& Append(float aFloat); nsString& Append(float aFloat);
/* /*
* Copies n characters from this string to given string, * Copies n characters from this string to given string,
@ -475,7 +465,7 @@ nsString2& Append(float aFloat);
* @param aCount -- number of chars to copy * @param aCount -- number of chars to copy
* @return number of chars copied * @return number of chars copied
*/ */
PRUint32 Left(nsString2& aCopy,PRInt32 aCount) const; PRUint32 Left(nsString& aCopy,PRInt32 aCount) const;
/* /*
* Copies n characters from this string to given string, * Copies n characters from this string to given string,
@ -487,7 +477,7 @@ PRUint32 Left(nsString2& aCopy,PRInt32 aCount) const;
* @param anOffset -- position where copying begins * @param anOffset -- position where copying begins
* @return number of chars copied * @return number of chars copied
*/ */
PRUint32 Mid(nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount) const; PRUint32 Mid(nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
/* /*
* Copies n characters from this string to given string, * Copies n characters from this string to given string,
@ -498,7 +488,7 @@ PRUint32 Mid(nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
* @param aCount -- number of chars to copy * @param aCount -- number of chars to copy
* @return number of chars copied * @return number of chars copied
*/ */
PRUint32 Right(nsString2& aCopy,PRInt32 aCount) const; PRUint32 Right(nsString& aCopy,PRInt32 aCount) const;
/* /*
* This method inserts n chars from given string into this * This method inserts n chars from given string into this
@ -509,7 +499,7 @@ PRUint32 Right(nsString2& aCopy,PRInt32 aCount) const;
* @param aCount -- number of chars to be copied from aCopy * @param aCount -- number of chars to be copied from aCopy
* @return number of chars inserted into this. * @return number of chars inserted into this.
*/ */
nsString2& Insert(const nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount=-1); nsString& Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
/** /**
* Insert a given string into this string at * Insert a given string into this string at
@ -519,8 +509,8 @@ nsString2& Insert(const nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
* @param anOffset is insert pos in str * @param anOffset is insert pos in str
* @return the number of chars inserted into this string * @return the number of chars inserted into this string
*/ */
nsString2& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1); nsString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
nsString2& Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1); nsString& Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
/** /**
* Insert a single char into this string at * Insert a single char into this string at
@ -530,8 +520,8 @@ nsString2& Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
* @param anOffset is insert pos in str * @param anOffset is insert pos in str
* @return the number of chars inserted into this string * @return the number of chars inserted into this string
*/ */
//nsString2& Insert(char aChar,PRUint32 anOffset); //nsString& Insert(char aChar,PRUint32 anOffset);
nsString2& Insert(PRUnichar aChar,PRUint32 anOffset); nsString& Insert(PRUnichar aChar,PRUint32 anOffset);
/* /*
* This method is used to cut characters in this string * This method is used to cut characters in this string
@ -541,7 +531,7 @@ nsString2& Insert(PRUnichar aChar,PRUint32 anOffset);
* @param aCount -- number of chars to be cut * @param aCount -- number of chars to be cut
* @return *this * @return *this
*/ */
nsString2& Cut(PRUint32 anOffset,PRInt32 aCount); nsString& Cut(PRUint32 anOffset,PRInt32 aCount);
/********************************************************************** /**********************************************************************
@ -564,11 +554,22 @@ PRInt32 BinarySearch(PRUnichar aChar) const;
* @param aString is substring to be sought in this * @param aString is substring to be sought in this
* @return offset in string, or -1 (kNotFound) * @return offset in string, or -1 (kNotFound)
*/ */
PRInt32 Find(const nsString2& aString,PRBool aIgnoreCase=PR_FALSE) const; PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE) const; PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE) const; PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE) const; PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
/**
* Search for given char within this string
*
* @param aString is substring to be sought in this
* @param anOffset tells us where in this strig to start searching
* @param aIgnoreCase selects case sensitivity
* @return find pos in string, or -1 (kNotFound)
*/
PRInt32 Find(PRUnichar aChar,PRUint32 offset=0,PRBool aIgnoreCase=PR_FALSE) const; PRInt32 Find(PRUnichar aChar,PRUint32 offset=0,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
/** /**
* This method searches this string for the first character * This method searches this string for the first character
@ -579,7 +580,31 @@ PRInt32 Find(PRUnichar aChar,PRUint32 offset=0,PRBool aIgnoreCase=PR_FALSE) cons
*/ */
PRInt32 FindCharInSet(const char* aString,PRUint32 anOffset=0) const; PRInt32 FindCharInSet(const char* aString,PRUint32 anOffset=0) const;
PRInt32 FindCharInSet(const PRUnichar* aString,PRUint32 anOffset=0) const; PRInt32 FindCharInSet(const PRUnichar* aString,PRUint32 anOffset=0) const;
PRInt32 FindCharInSet(const nsString2& aString,PRUint32 anOffset=0) const; PRInt32 FindCharInSet(const nsStr& aString,PRUint32 anOffset=0) const;
/**
* This methods scans the string backwards, looking for the given string
* @param aString is substring to be sought in this
* @param aIgnoreCase tells us whether or not to do caseless compare
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
/**
* Search for given char within this string
*
* @param aString is substring to be sought in this
* @param anOffset tells us where in this strig to start searching
* @param aIgnoreCase selects case sensitivity
* @return find pos in string, or -1 (kNotFound)
*/
PRInt32 RFind(PRUnichar aChar,PRUint32 offset=0,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0) const;
/** /**
* This method searches this string for the last character * This method searches this string for the last character
@ -590,21 +615,9 @@ PRInt32 FindCharInSet(const nsString2& aString,PRUint32 anOffset=0) const;
*/ */
PRInt32 RFindCharInSet(const char* aString,PRUint32 anOffset=0) const; PRInt32 RFindCharInSet(const char* aString,PRUint32 anOffset=0) const;
PRInt32 RFindCharInSet(const PRUnichar* aString,PRUint32 anOffset=0) const; PRInt32 RFindCharInSet(const PRUnichar* aString,PRUint32 anOffset=0) const;
PRInt32 RFindCharInSet(const nsString2& aString,PRUint32 anOffset=0) const; PRInt32 RFindCharInSet(const nsStr& aString,PRUint32 anOffset=0) const;
/**
* This methods scans the string backwards, looking for the given string
* @param aString is substring to be sought in this
* @param aIgnoreCase tells us whether or not to do caseless compare
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 RFind(const nsString2& aString,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE) const;
PRInt32 RFind(PRUnichar aChar,PRUint32 offset=0,PRBool aIgnoreCase=PR_FALSE) const;
/********************************************************************** /**********************************************************************
Comparison methods... Comparison methods...
*********************************************************************/ *********************************************************************/
@ -616,7 +629,7 @@ PRInt32 RFind(PRUnichar aChar,PRUint32 offset=0,PRBool aIgnoreCase=PR_FALSE) con
* @param aIgnoreCase tells us how to treat case * @param aIgnoreCase tells us how to treat case
* @return -1,0,1 * @return -1,0,1
*/ */
virtual PRInt32 Compare(const nsString2& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const; virtual PRInt32 Compare(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const;
virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const; virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const;
virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const; virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const;
virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const; virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const;
@ -626,7 +639,7 @@ virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRI
* @param aString is the string to be compared to this * @param aString is the string to be compared to this
* @return TRUE or FALSE * @return TRUE or FALSE
*/ */
PRBool operator==(const nsString2 &aString) const; PRBool operator==(const nsString &aString) const;
PRBool operator==(const nsStr &aString) const; PRBool operator==(const nsStr &aString) const;
PRBool operator==(const char *aString) const; PRBool operator==(const char *aString) const;
PRBool operator==(const PRUnichar* aString) const; PRBool operator==(const PRUnichar* aString) const;
@ -636,7 +649,7 @@ PRBool operator==(const PRUnichar* aString) const;
* @param aString is the string to be compared to this * @param aString is the string to be compared to this
* @return TRUE * @return TRUE
*/ */
PRBool operator!=(const nsString2 &aString) const; PRBool operator!=(const nsString &aString) const;
PRBool operator!=(const nsStr &aString) const; PRBool operator!=(const nsStr &aString) const;
PRBool operator!=(const char* aString) const; PRBool operator!=(const char* aString) const;
PRBool operator!=(const PRUnichar* aString) const; PRBool operator!=(const PRUnichar* aString) const;
@ -646,7 +659,7 @@ PRBool operator!=(const PRUnichar* aString) const;
* @param aString is the string to be compared to this * @param aString is the string to be compared to this
* @return TRUE or FALSE * @return TRUE or FALSE
*/ */
PRBool operator<(const nsString2 &aString) const; PRBool operator<(const nsString &aString) const;
PRBool operator<(const nsStr &aString) const; PRBool operator<(const nsStr &aString) const;
PRBool operator<(const char* aString) const; PRBool operator<(const char* aString) const;
PRBool operator<(const PRUnichar* aString) const; PRBool operator<(const PRUnichar* aString) const;
@ -656,7 +669,7 @@ PRBool operator<(const PRUnichar* aString) const;
* @param aString is the string to be compared to this * @param aString is the string to be compared to this
* @return TRUE or FALSE * @return TRUE or FALSE
*/ */
PRBool operator>(const nsString2 &aString) const; PRBool operator>(const nsString &aString) const;
PRBool operator>(const nsStr &S) const; PRBool operator>(const nsStr &S) const;
PRBool operator>(const char* aString) const; PRBool operator>(const char* aString) const;
PRBool operator>(const PRUnichar* aString) const; PRBool operator>(const PRUnichar* aString) const;
@ -666,7 +679,7 @@ PRBool operator>(const PRUnichar* aString) const;
* @param aString is the string to be compared to this * @param aString is the string to be compared to this
* @return TRUE or FALSE * @return TRUE or FALSE
*/ */
PRBool operator<=(const nsString2 &aString) const; PRBool operator<=(const nsString &aString) const;
PRBool operator<=(const nsStr &S) const; PRBool operator<=(const nsStr &S) const;
PRBool operator<=(const char* aString) const; PRBool operator<=(const char* aString) const;
PRBool operator<=(const PRUnichar* aString) const; PRBool operator<=(const PRUnichar* aString) const;
@ -676,7 +689,7 @@ PRBool operator<=(const PRUnichar* aString) const;
* @param aString is the string to be compared to this * @param aString is the string to be compared to this
* @return TRUE or FALSE * @return TRUE or FALSE
*/ */
PRBool operator>=(const nsString2 &aString) const; PRBool operator>=(const nsString &aString) const;
PRBool operator>=(const nsStr &S) const; PRBool operator>=(const nsStr &S) const;
PRBool operator>=(const char* aString) const; PRBool operator>=(const char* aString) const;
PRBool operator>=(const PRUnichar* aString) const; PRBool operator>=(const PRUnichar* aString) const;
@ -688,20 +701,18 @@ PRBool operator>=(const PRUnichar* aString) const;
* optimization. * optimization.
* *
* @param aString -- the string to compare to this * @param aString -- the string to compare to this
* @param aLength -- optional length of given string. * @param aCount -- number of chars to be compared.
* @return TRUE if equal * @return TRUE if equal
*/ */
PRBool Equals(const nsString2 &aString,PRBool aIgnoreCase=PR_FALSE) const; PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE) const; PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE) const; PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const char* aString,PRUint32 aCount,PRBool aIgnoreCase) const; PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE) const;
PRBool Equals(const PRUnichar* aString,PRUint32 aCount,PRBool aIgnoreCase) const;
PRBool Equals(const nsIAtom* anAtom,PRBool aIgnoreCase) const; PRBool Equals(const nsIAtom* anAtom,PRBool aIgnoreCase) const;
PRBool Equals(const PRUnichar* s1, const PRUnichar* s2,PRBool aIgnoreCase=PR_FALSE) const; PRBool Equals(const PRUnichar* s1, const PRUnichar* s2,PRBool aIgnoreCase=PR_FALSE) const;
PRBool EqualsIgnoreCase(const nsString2& aString) const; PRBool EqualsIgnoreCase(const nsString& aString) const;
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aLength=-1) const; PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(const nsIAtom *aAtom) const; PRBool EqualsIgnoreCase(const nsIAtom *aAtom) const;
PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const; PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const;
@ -730,8 +741,8 @@ static PRBool IsAlpha(PRUnichar ch);
*/ */
static PRBool IsDigit(PRUnichar ch); static PRBool IsDigit(PRUnichar ch);
static void Recycle(nsString2* aString); static void Recycle(nsString* aString);
static nsString2* CreateString(eCharSize aCharSize=eTwoByte); static nsString* CreateString(eCharSize aCharSize=eTwoByte);
virtual void DebugDump(ostream& aStream) const; virtual void DebugDump(ostream& aStream) const;
@ -739,8 +750,8 @@ virtual void DebugDump(ostream& aStream) const;
}; };
extern NS_COM int fputs(const nsString2& aString, FILE* out); extern NS_COM int fputs(const nsString& aString, FILE* out);
ostream& operator<<(ostream& aStream,const nsString2& aString); ostream& operator<<(ostream& aStream,const nsString& aString);
/************************************************************** /**************************************************************
@ -749,36 +760,30 @@ ostream& operator<<(ostream& aStream,const nsString2& aString);
If the buffer needs to grow, it gets reallocated on the heap. If the buffer needs to grow, it gets reallocated on the heap.
**************************************************************/ **************************************************************/
class NS_COM nsAutoString2 : public nsString2 { class NS_COM nsAutoString : public nsString {
public: public:
nsAutoString2(eCharSize aCharSize=kDefaultCharSize); nsAutoString(eCharSize aCharSize=kDefaultCharSize);
nsAutoString2(nsStr& anExtBuffer,const char* aCString); nsAutoString(const char* aCString,eCharSize aCharSize=kDefaultCharSize,PRInt32 aLength=-1);
nsAutoString(const PRUnichar* aString,eCharSize aCharSize=kDefaultCharSize,PRInt32 aLength=-1);
nsAutoString(CSharedStrBuffer& aBuffer);
nsAutoString2(const char* aCString,eCharSize aCharSize=kDefaultCharSize); nsAutoString(const nsStr& aString,eCharSize aCharSize=kDefaultCharSize);
nsAutoString2(char* aCString,PRInt32 aCapacity=-1,eCharSize aCharSize=kDefaultCharSize,PRBool assumeOwnership=PR_FALSE); nsAutoString(const nsAutoString& aString,eCharSize aCharSize=kDefaultCharSize);
nsAutoString2(const PRUnichar* aString,eCharSize aCharSize=kDefaultCharSize);
nsAutoString2(PRUnichar* aString,PRInt32 aCapacity=-1,eCharSize aCharSize=kDefaultCharSize,PRBool assumeOwnership=PR_FALSE);
nsAutoString2(const nsStr& aString,eCharSize aCharSize=kDefaultCharSize);
nsAutoString2(const nsString2& aString,eCharSize aCharSize=kDefaultCharSize);
nsAutoString2(const nsAutoString2& aString,eCharSize aCharSize=kDefaultCharSize);
#ifdef AIX #ifdef AIX
nsAutoString2(const nsSubsumeStr& aSubsumeStr); // AIX requires a const nsAutoString(const nsSubsumeStr& aSubsumeStr); // AIX requires a const
#else #else
nsAutoString2(nsSubsumeStr& aSubsumeStr); nsAutoString(nsSubsumeStr& aSubsumeStr);
#endif // AIX #endif // AIX
nsAutoString2(PRUnichar aChar,eCharSize aCharSize=kDefaultCharSize); nsAutoString(PRUnichar aChar,eCharSize aCharSize=kDefaultCharSize);
virtual ~nsAutoString2(); virtual ~nsAutoString();
nsAutoString2& operator=(const nsString2& aString) {nsString2::operator=(aString); return *this;} nsAutoString& operator=(const nsStr& aString) {nsString::Assign(aString); return *this;}
nsAutoString2& operator=(const nsStr& aString) {nsString2::Assign(aString); return *this;} nsAutoString& operator=(const nsAutoString& aString) {nsString::operator=(aString); return *this;}
nsAutoString2& operator=(const nsAutoString2& aString) {nsString2::operator=(aString); return *this;} nsAutoString& operator=(const char* aCString) {nsString::operator=(aCString); return *this;}
nsAutoString2& operator=(const char* aCString) {nsString2::operator=(aCString); return *this;} nsAutoString& operator=(char aChar) {nsString::operator=(aChar); return *this;}
nsAutoString2& operator=(char aChar) {nsString2::operator=(aChar); return *this;} nsAutoString& operator=(const PRUnichar* aBuffer) {nsString::operator=(aBuffer); return *this;}
nsAutoString2& operator=(const PRUnichar* aBuffer) {nsString2::operator=(aBuffer); return *this;} nsAutoString& operator=(PRUnichar aChar) {nsString::operator=(aChar); return *this;}
nsAutoString2& operator=(PRUnichar aChar) {nsString2::operator=(aChar); return *this;}
/** /**
* Retrieve the size of this string * Retrieve the size of this string
@ -803,24 +808,14 @@ public:
You should probably not use this class unless you really know You should probably not use this class unless you really know
what you're doing. what you're doing.
***************************************************************/ ***************************************************************/
class NS_COM nsSubsumeStr : public nsString2 { class NS_COM nsSubsumeStr : public nsString {
public: public:
nsSubsumeStr(nsString2& aString);
nsSubsumeStr(nsStr& aString); nsSubsumeStr(nsStr& aString);
nsSubsumeStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1); nsSubsumeStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
nsSubsumeStr(char* aString,PRBool assumeOwnership,PRInt32 aLength=-1); nsSubsumeStr(char* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
}; };
/***************************************************************
***************************************************************/
class NS_COM nsCAutoString: public nsAutoString{
public:
nsCAutoString(const nsString2& aString);
operator const char*() const;
};
#endif #endif