back out erroneously updated files

git-svn-id: svn://10.0.0.236/trunk@38890 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
rickg%netscape.com 1999-07-09 06:01:55 +00:00
parent 627e7710d1
commit 0dd1673f17
20 changed files with 11041 additions and 8004 deletions

View File

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

View File

@ -48,10 +48,6 @@
enum eCharSize {eOneByte=0,eTwoByte=1};
#define kDefaultCharSize eTwoByte
#define kRadix10 (10)
#define kRadix16 (16)
#define kAutoDetect (100)
#define kRadixUnknown (kAutoDetect+1)
const PRInt32 kNotFound = -1;
@ -59,21 +55,6 @@ 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 {
@ -188,6 +169,16 @@ struct nsStr {
*/
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
@ -210,7 +201,7 @@ struct nsStr {
* @param aEliminateLeading tells us whether to strip chars from the start of the buffer
* @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
*/
static void CompressSet(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing);
static void CompressSet(nsStr& aDest,const char* aSet,PRUint32 aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing);
/**
* This method compares the data bewteen two nsStr's

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -93,7 +93,7 @@ void ShiftCharsRight(char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUint32 aCo
char* to = aDest+aLength+aCount;
//Copy rightmost chars, up to offset+theDelta...
while(first<last) {
while(first<=last) {
*to=*last;
to--;
last--;
@ -141,7 +141,7 @@ void ShiftDoubleCharsRight(char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUint
PRUnichar* to = theBuf+aLength+aCount;
//Copy rightmost chars, up to offset+theDelta...
while(first<last) {
while(first<=last) {
*to=*last;
to--;
last--;
@ -289,7 +289,7 @@ inline PRInt32 FindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,co
PRInt32 theIndex=0;
PRInt32 theLength=(PRInt32)aLength;
for(theIndex=(PRInt32)anOffset;theIndex<theLength;theIndex++){
PRUnichar theChar=aDest[theIndex];
PRUnichar theChar=GetCharAt(aDest,theIndex);
if(aIgnoreCase)
theChar=nsCRT::ToUpper(theChar);
if(theChar==theCmpChar)
@ -311,11 +311,10 @@ 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) {
PRUnichar theCmpChar=(aIgnoreCase ? nsCRT::ToUpper(aChar) : aChar);
PRInt32 theIndex=0;
PRInt32 theLength=(PRInt32)aLength;
PRUnichar* theBuf=(PRUnichar*)aDest;
PRInt32 theIndex=0;
PRInt32 theLength=(PRInt32)aLength;
for(theIndex=(PRInt32)anOffset;theIndex<theLength;theIndex++){
PRUnichar theChar=theBuf[theIndex];
PRUnichar theChar=GetUnicharAt(aDest,theIndex);
if(aIgnoreCase)
theChar=nsCRT::ToUpper(theChar);
if(theChar==theCmpChar)
@ -599,7 +598,199 @@ PRInt32 ConvertCase2(char* aString,PRUint32 aCount,PRBool aToUpper){
typedef PRInt32 (*CaseConverters)(char*,PRUint32,PRBool);
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};
//----------------------------------------------------------------------------------------
//
@ -618,9 +809,11 @@ CaseConverters gCaseConverters[]={&ConvertCase1,&ConvertCase2};
* @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
* @return the new length of the given buffer
*/
PRInt32 CompressChars1(char* aString,PRUint32 aLength,const char* aSet){
PRInt32 CompressChars1(char* aString,PRUint32 aLength,const char* aSet,PRUint32 aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing){
PRInt32 result=0;
TrimChars1(aString,aLength,aSet,aEliminateLeading,aEliminateTrailing);
typedef char chartype;
chartype* from = aString;
chartype* end = aString + aLength-1;
@ -631,18 +824,18 @@ PRInt32 CompressChars1(char* aString,PRUint32 aLength,const char* aSet){
if(aSet){
PRUint32 aSetLen=strlen(aSet);
while (from <= end) {
chartype theChar = *from++;
if(kNotFound!=FindChar1(aSet,aSetLen,0,theChar,PR_FALSE)){
to++;
chartype ch = *from++;
if(kNotFound!=FindChar1(aSet,aSetLen,0,ch,PR_FALSE)){
*to++ = (char)aChar;
while (from <= end) {
theChar = *from++;
if(kNotFound==FindChar1(aSet,aSetLen,0,theChar,PR_FALSE)){
*to++ = theChar;
ch = *from++;
if(kNotFound==FindChar1(aSet,aSetLen,0,ch,PR_FALSE)){
*to++ = ch;
break;
}
}
} else {
*to++ = theChar;
*to++ = ch;
}
}
*to = 0;
@ -662,9 +855,11 @@ PRInt32 CompressChars1(char* aString,PRUint32 aLength,const char* aSet){
* @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
* @return the new length of the given buffer
*/
PRInt32 CompressChars2(char* aString,PRUint32 aLength,const char* aSet){
PRInt32 CompressChars2(char* aString,PRUint32 aLength,const char* aSet,PRUint32 aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing){
PRInt32 result=0;
TrimChars2(aString,aLength,aSet,aEliminateLeading,aEliminateTrailing);
typedef PRUnichar chartype;
chartype* from = (chartype*)aString;
chartype* end = from + aLength-1;
@ -675,18 +870,18 @@ PRInt32 CompressChars2(char* aString,PRUint32 aLength,const char* aSet){
if(aSet){
PRUint32 aSetLen=strlen(aSet);
while (from <= end) {
chartype theChar = *from++;
if(kNotFound!=FindChar1(aSet,aSetLen,0,theChar,PR_FALSE)){
to++;
chartype ch = *from++;
if(kNotFound!=FindChar1(aSet,aSetLen,0,ch,PR_FALSE)){
*to++ = (PRUnichar)aChar;
while (from <= end) {
theChar = *from++;
if(kNotFound==FindChar1(aSet,aSetLen,0,theChar,PR_FALSE)){
*to++ = theChar;
ch = *from++;
if(kNotFound==FindChar1(aSet,aSetLen,0,ch,PR_FALSE)){
*to++ = ch;
break;
}
}
} else {
*to++ = theChar;
*to++ = ch;
}
}
*to = 0;
@ -694,7 +889,7 @@ PRInt32 CompressChars2(char* aString,PRUint32 aLength,const char* aSet){
return to - (chartype*)aString;
}
typedef PRInt32 (*CompressChars)(char* aString,PRUint32 aCount,const char* aSet);
typedef PRInt32 (*CompressChars)(char* aString,PRUint32 aCount,const char* aSet,PRUint32 aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing);
CompressChars gCompressChars[]={&CompressChars1,&CompressChars2};

View File

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

View File

@ -48,10 +48,6 @@
enum eCharSize {eOneByte=0,eTwoByte=1};
#define kDefaultCharSize eTwoByte
#define kRadix10 (10)
#define kRadix16 (16)
#define kAutoDetect (100)
#define kRadixUnknown (kAutoDetect+1)
const PRInt32 kNotFound = -1;
@ -59,21 +55,6 @@ 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 {
@ -188,6 +169,16 @@ struct nsStr {
*/
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
@ -210,7 +201,7 @@ struct nsStr {
* @param aEliminateLeading tells us whether to strip chars from the start of the buffer
* @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
*/
static void CompressSet(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing);
static void CompressSet(nsStr& aDest,const char* aSet,PRUint32 aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing);
/**
* This method compares the data bewteen two nsStr's

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -0,0 +1,145 @@
/* -*- 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.
*/
/**
* MODULE NOTES:
* @update gess 4/1/98
*
* This class knows how to read delimited data from a string.
* Here are the 2 things you need to know to use this class effectively:
*
* ================================================
* How To Setup The Tokenizer
* ================================================
*
* The input charset can be either constrained or uncontrained. Constrained means
* that you've chosen to allow only certain chars into your tokens. Unconstrained
* means that any char (other than delimiters) are legal in your tokens.
* If you want unconstrained input, use [*-*] your dataspec. To contrain your token
* charset, you set ranges or single chars in the dataspec like this:
* "abc[0-9]" -- which allow numbers and the letters a,b,c
*
* Dataspecifier rules:
* abc -- allows a set of characters
* [a-z] -- allows all chars in given range
* [*-*] -- allows all characters
* ^abc -- disallows a set of characters //NOT_YET_IMPLEMENTED
* [a^z] -- disallows all characters in given range //NOT_YET_IMPLEMENTED
* [a*b] -- specifies a delimiter pair for the entire token
* [a+b] -- specifies a delimiter pair for substrings in the token
*
* One other note: there is an optional argument called allowQuoting, which tells
* the tokenizer whether to allow quoted strings within your fields. If you set this
* to TRUE, then we allow nested quoted strings, which themselves can contain any data.
* It's considered an error to set allowQuoting=TRUE and use a quote as a token or record delimiter.
*
* The other thing you need to set up for the tokenizer to work correctly are the delimiters.
* They seperate fields and records, and be different. You can also have more than one kind
* of delimiter for each. The distinguishment between tokens are records allows the caller
* to deal with multi-line text files (where \n is the record seperator). Again, you don't have
* to have a record seperator if it doesn't make sense in the context of your input dataset.
*
*
* ================================================
* How To Iterate Tokens
* ================================================
*
* There are 2 ways to iterate tokens, either manually or automatically.
* The manual method requires that you call a set of methods in the right order,
* but gives you slightly more control. Here's the calling pattern:
*
* {
* nsString theBuffer("xxxxxxx");
* nsStringTokenizer tok(...);
* tok.SetBuffer(theBuffer);
* tok.FirstRecord();
* while(tok.HasNextToken()){
* while(tok.HasNextToken()){
* nsAutoString theToken;
* tok.GetNextToken(theToken);
* //do something with your token here...
* } //while
* tok.NextRecord();
* } //while
* }
*
* The automatic method handles all the iteration for you. You provide a callback functor
* and you'll get called once for each token per record. To use that technique, you need
* to define an object that provides the ITokenizeFunctor interface (1 method). Then
* call the tokenizer method Iterate(...). Voila.
*
*/
#ifndef nsStringTokenizer_
#define nsStringTokenizer_
#include "nsString.h"
class ITokenizeFunctor {
public:
virtual operator ()(nsString& aToken,PRInt32 aRecordCount,PRInt32 aTokenCount)=0;
};
class nsStringTokenizer {
public:
nsStringTokenizer(const char* aDataSpecifier="\"",const char* aFieldSep=",",const char* aRecordSep="\n");
~nsStringTokenizer();
//Call these methods if you want to iterate the tokens yourself
void SetBuffer(nsString& aBuffer);
PRBool FirstRecord(void);
PRBool NextRecord(void);
PRBool HasNextToken(void);
PRInt32 GetNextToken(nsString& aToken);
//Call this one (exclusively) if you want to be called back iteratively
PRInt32 Iterate(nsString& aBuffer,ITokenizeFunctor& aFunctor);
protected:
enum eCharTypes {eUnknown,eDataChar,eFieldSeparator,eDataDelimiter,eRecordSeparator};
enum eCharSpec {eGivenChars,eAllChars,eExceptChars};
PRInt32 SkipOver(nsString& aSkipSet);
PRInt32 SkipOver(PRUnichar aSkipChar);
PRInt32 ReadUntil(nsString& aString,PRUnichar* aTermSet,PRBool aState);
PRInt32 ReadUntil(nsString& aString,PRUnichar aChar,PRBool aState);
PRBool More(void);
PRInt32 GetChar(PRUnichar& aChar);
void UnGetChar(PRUnichar aChar);
PRBool SkipToValidData(void);
void ExpandDataSpecifier(const char* aDataSpec) ;
inline PRBool IsValidDataChar(PRUnichar aChar);
eCharTypes DetermineCharType(PRUnichar aChar);
PRInt32 mValidChars[4];
PRInt32 mInvalidChars[4];
nsString mDataStartDelimiter;
nsString mDataEndDelimiter;
nsString mSubstrStartDelimiter;
nsString mSubstrEndDelimiter;
nsString mFieldSeparator;
nsString mRecordSeparator;
PRInt32 mOffset;
eCharSpec mCharSpec;
nsString* mBuffer;
};
#endif

View File

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

View File

@ -48,10 +48,6 @@
enum eCharSize {eOneByte=0,eTwoByte=1};
#define kDefaultCharSize eTwoByte
#define kRadix10 (10)
#define kRadix16 (16)
#define kAutoDetect (100)
#define kRadixUnknown (kAutoDetect+1)
const PRInt32 kNotFound = -1;
@ -59,21 +55,6 @@ 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 {
@ -188,6 +169,16 @@ struct nsStr {
*/
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
@ -210,7 +201,7 @@ struct nsStr {
* @param aEliminateLeading tells us whether to strip chars from the start of the buffer
* @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
*/
static void CompressSet(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing);
static void CompressSet(nsStr& aDest,const char* aSet,PRUint32 aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing);
/**
* This method compares the data bewteen two nsStr's

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

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