removed PRUnichar* operator() and other WIP for nsString2
git-svn-id: svn://10.0.0.236/trunk@29089 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -31,7 +31,12 @@
|
||||
|
||||
#include "nsCRT.h"
|
||||
|
||||
static const PRInt32 kNotFound=-1;
|
||||
#ifndef RICKG_TESTBED
|
||||
#include "nsUnicharUtilCIID.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsICaseConversion.h"
|
||||
#endif
|
||||
|
||||
|
||||
inline PRUnichar GetUnicharAt(const char* aString,PRUint32 anIndex) {
|
||||
return ((PRUnichar*)aString)[anIndex];
|
||||
@@ -57,7 +62,7 @@ inline PRUnichar GetCharAt(const char* aString,PRUint32 anIndex) {
|
||||
*/
|
||||
void ShiftCharsLeft(char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUint32 aCount) {
|
||||
PRUint32 theMax=aLength-anOffset;
|
||||
// PRUint32 theLength=(theMax<aCount) ? theMax : aCount;
|
||||
PRUint32 theLength=(theMax<aCount) ? theMax : aCount;
|
||||
|
||||
char* first= aDest+anOffset+aCount;
|
||||
char* last = aDest+aLength;
|
||||
@@ -102,7 +107,7 @@ void ShiftCharsRight(char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUint32 aCo
|
||||
*/
|
||||
void ShiftDoubleCharsLeft(char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUint32 aCount) {
|
||||
PRUint32 theMax=aLength-anOffset;
|
||||
// PRUint32 theLength=(theMax<aCount) ? theMax : aCount;
|
||||
PRUint32 theLength=(theMax<aCount) ? theMax : aCount;
|
||||
|
||||
PRUnichar* theBuf=(PRUnichar*)aDest;
|
||||
PRUnichar* first= theBuf+anOffset+aCount;
|
||||
@@ -279,7 +284,7 @@ CopyChars gCopyChars[2][2]={
|
||||
* @param aIgnorecase tells us whether to use a case sensitive search
|
||||
* @return index of pos if found, else -1 (kNotFound)
|
||||
*/
|
||||
inline PRInt32 FindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
inline PRInt32 FindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
PRUnichar theCmpChar=(aIgnoreCase ? nsCRT::ToUpper(aChar) : aChar);
|
||||
PRUint32 theIndex=0;
|
||||
for(theIndex=0;theIndex<aLength;theIndex++){
|
||||
@@ -303,7 +308,7 @@ inline PRInt32 FindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,PR
|
||||
* @param aIgnorecase tells us whether to use a case sensitive search
|
||||
* @return index of pos if found, else -1 (kNotFound)
|
||||
*/
|
||||
inline PRInt32 FindChar2(const char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
inline PRInt32 FindChar2(const char* aDest,PRUint32 aLength,PRUint32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
PRUnichar theCmpChar=(aIgnoreCase ? nsCRT::ToUpper(aChar) : aChar);
|
||||
PRUint32 theIndex=0;
|
||||
for(theIndex=0;theIndex<aLength;theIndex++){
|
||||
@@ -329,7 +334,7 @@ inline PRInt32 FindChar2(const char* aDest,PRUint32 aLength,PRUint32 anOffset,PR
|
||||
* @param aIgnorecase tells us whether to use a case sensitive search
|
||||
* @return index of pos if found, else -1 (kNotFound)
|
||||
*/
|
||||
inline PRInt32 RFindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
inline PRInt32 RFindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
PRUnichar theCmpChar=(aIgnoreCase ? nsCRT::ToUpper(aChar) : aChar);
|
||||
PRUint32 theIndex=0;
|
||||
for(theIndex=aLength-1;theIndex>=0;theIndex--){
|
||||
@@ -355,7 +360,7 @@ inline PRInt32 RFindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,P
|
||||
* @param aIgnorecase tells us whether to use a case sensitive search
|
||||
* @return index of pos if found, else -1 (kNotFound)
|
||||
*/
|
||||
inline PRInt32 RFindChar2(const char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
inline PRInt32 RFindChar2(const char* aDest,PRUint32 aLength,PRUint32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
PRUnichar theCmpChar=(aIgnoreCase ? nsCRT::ToUpper(aChar) : aChar);
|
||||
PRUint32 theIndex=0;
|
||||
for(theIndex=aLength-1;theIndex>=0;theIndex--){
|
||||
@@ -368,7 +373,7 @@ inline PRInt32 RFindChar2(const char* aDest,PRUint32 aLength,PRUint32 anOffset,P
|
||||
return kNotFound;
|
||||
}
|
||||
|
||||
typedef PRInt32 (*FindChars)(const char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUnichar aChar,PRBool aIgnoreCase);
|
||||
typedef PRInt32 (*FindChars)(const char* aDest,PRUint32 aLength,PRUint32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase);
|
||||
FindChars gFindChars[]={&FindChar1,&FindChar2};
|
||||
FindChars gRFindChars[]={&RFindChar1,&RFindChar2};
|
||||
|
||||
@@ -496,6 +501,53 @@ PRInt32 ConvertCase1(char* aString,PRUint32 aCount,PRBool aToUpper){
|
||||
return result;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef RICKG_TESTBED
|
||||
class HandleCaseConversionShutdown3 : public nsIShutdownListener {
|
||||
public :
|
||||
NS_IMETHOD OnShutdown(const nsCID& cid, nsISupports* service);
|
||||
HandleCaseConversionShutdown3(void) { NS_INIT_REFCNT(); }
|
||||
virtual ~HandleCaseConversionShutdown3(void) {}
|
||||
NS_DECL_ISUPPORTS
|
||||
};
|
||||
|
||||
static NS_DEFINE_CID(kUnicharUtilCID, NS_UNICHARUTIL_CID);
|
||||
static NS_DEFINE_IID(kICaseConversionIID, NS_ICASECONVERSION_IID);
|
||||
static NS_DEFINE_IID(kIShutdownListenerIID, NS_ISHUTDOWNLISTENER_IID);
|
||||
static nsICaseConversion * gCaseConv = 0;
|
||||
|
||||
NS_IMPL_ISUPPORTS(HandleCaseConversionShutdown3, kIShutdownListenerIID);
|
||||
|
||||
nsresult HandleCaseConversionShutdown3::OnShutdown(const nsCID& cid, nsISupports* service) {
|
||||
if (cid.Equals(kUnicharUtilCID)) {
|
||||
NS_ASSERTION(service == gCaseConv, "wrong service!");
|
||||
if(gCaseConv){
|
||||
gCaseConv->Release();
|
||||
gCaseConv = 0;
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
class CCaseConversionServiceInitializer {
|
||||
public:
|
||||
CCaseConversionServiceInitializer(){
|
||||
mListener = new HandleCaseConversionShutdown3();
|
||||
if(mListener){
|
||||
mListener->AddRef();
|
||||
nsresult result=nsServiceManager::GetService(kUnicharUtilCID, kICaseConversionIID,(nsISupports**) &gCaseConv, mListener);
|
||||
}
|
||||
}
|
||||
protected:
|
||||
HandleCaseConversionShutdown3* mListener;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* This method performs a case conversion the data in the given buffer
|
||||
*
|
||||
@@ -506,14 +558,25 @@ PRInt32 ConvertCase1(char* aString,PRUint32 aCount,PRBool aToUpper){
|
||||
* @return 0
|
||||
*/
|
||||
PRInt32 ConvertCase2(char* aString,PRUint32 aCount,PRBool aToUpper){
|
||||
PRUnichar* cp = (PRUnichar*)aString;
|
||||
PRUnichar* end = cp + aCount-1;
|
||||
PRInt32 result=0;
|
||||
|
||||
typedef PRUnichar chartype;
|
||||
chartype* cp = (chartype*)aString;
|
||||
chartype* end = cp + aCount-1;
|
||||
#ifndef RICKG_TESTBED
|
||||
static CCaseConversionServiceInitializer gCaseConversionServiceInitializer;
|
||||
|
||||
// I18N code begin
|
||||
if(gCaseConv) {
|
||||
nsresult err=(aToUpper) ? gCaseConv->ToUpper(cp, cp, aCount) : gCaseConv->ToLower(cp, cp, aCount);
|
||||
if(NS_SUCCEEDED(err))
|
||||
return 0;
|
||||
}
|
||||
// I18N code end
|
||||
#endif
|
||||
|
||||
|
||||
while (cp <= end) {
|
||||
chartype ch = *cp;
|
||||
PRUnichar ch = *cp;
|
||||
if(aToUpper) {
|
||||
if ((ch >= 'a') && (ch <= 'z')) {
|
||||
*cp = 'A' + (ch - 'a');
|
||||
@@ -549,7 +612,7 @@ CaseConverters gCaseConverters[]={&ConvertCase1,&ConvertCase2};
|
||||
* @return the new length of the given buffer
|
||||
*/
|
||||
PRInt32 StripChars1(char* aString,PRUint32 anOffset,PRUint32 aCount,const char* aSet){
|
||||
// PRInt32 result=0;
|
||||
PRInt32 result=0;
|
||||
|
||||
typedef char chartype;
|
||||
chartype* from = (chartype*)&aString[anOffset];
|
||||
@@ -581,7 +644,7 @@ PRInt32 StripChars1(char* aString,PRUint32 anOffset,PRUint32 aCount,const char*
|
||||
* @return the new length of the given buffer
|
||||
*/
|
||||
PRInt32 StripChars2(char* aString,PRUint32 anOffset,PRUint32 aCount,const char* aSet){
|
||||
// PRInt32 result=0;
|
||||
PRInt32 result=0;
|
||||
|
||||
typedef PRUnichar chartype;
|
||||
chartype* from = (chartype*)&aString[anOffset];
|
||||
@@ -622,7 +685,7 @@ StripChars gStripChars[]={&StripChars1,&StripChars2};
|
||||
* @return the new length of the given buffer
|
||||
*/
|
||||
PRInt32 TrimChars1(char* aString,PRUint32 aLength,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
||||
// PRInt32 result=0;
|
||||
PRInt32 result=0;
|
||||
|
||||
typedef char chartype;
|
||||
chartype* from = (chartype*)aString;
|
||||
@@ -745,7 +808,7 @@ TrimChars gTrimChars[]={&TrimChars1,&TrimChars2};
|
||||
* @return the new length of the given buffer
|
||||
*/
|
||||
PRInt32 CompressChars1(char* aString,PRUint32 aLength,const char* aSet,PRUint32 aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
||||
// PRInt32 result=0;
|
||||
PRInt32 result=0;
|
||||
|
||||
TrimChars1(aString,aLength,aSet,aEliminateLeading,aEliminateTrailing);
|
||||
|
||||
@@ -791,7 +854,7 @@ PRInt32 CompressChars1(char* aString,PRUint32 aLength,const char* aSet,PRUint32
|
||||
* @return the new length of the given buffer
|
||||
*/
|
||||
PRInt32 CompressChars2(char* aString,PRUint32 aLength,const char* aSet,PRUint32 aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
||||
// PRInt32 result=0;
|
||||
PRInt32 result=0;
|
||||
|
||||
TrimChars2(aString,aLength,aSet,aEliminateLeading,aEliminateTrailing);
|
||||
|
||||
|
||||
@@ -31,11 +31,103 @@
|
||||
#include "nsStr.h"
|
||||
#include "bufferRoutines.h"
|
||||
#include "stdio.h" //only used for printf
|
||||
#include "nsDeque.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
|
||||
static const char* kFoolMsg = "Error: Some fool overwrote the shared buffer.";
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// The following is a memory agent who knows how to recycled (pool) freed memory...
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
/**************************************************************
|
||||
Define the char* (pooled) deallocator class...
|
||||
**************************************************************/
|
||||
class nsBufferDeallocator: public nsDequeFunctor{
|
||||
public:
|
||||
virtual void* operator()(void* anObject) {
|
||||
char* aCString= (char*)anObject;
|
||||
delete [] aCString;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess10/30/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
class nsPoolingMemoryAgent : public nsMemoryAgent{
|
||||
public:
|
||||
nsPoolingMemoryAgent() {
|
||||
memset(mPools,0,sizeof(mPools));
|
||||
}
|
||||
|
||||
~nsPoolingMemoryAgent() {
|
||||
nsBufferDeallocator theDeallocator;
|
||||
int i=0;
|
||||
for(i=0;i<10;i++){
|
||||
if(mPools[i]){
|
||||
mPools[i]->ForEach(theDeallocator); //now delete the buffers
|
||||
}
|
||||
delete mPools[i];
|
||||
mPools[i]=0;
|
||||
}
|
||||
}
|
||||
|
||||
virtual PRBool Alloc(nsStr& aDest,PRInt32 aCount) {
|
||||
|
||||
//we're given the acount value in charunits; we have to scale up by the charsize.
|
||||
int theShift=4;
|
||||
PRInt32 theNewCapacity=eDefaultSize;
|
||||
while(theNewCapacity<aCount){
|
||||
theNewCapacity<<=1;
|
||||
theShift++;
|
||||
}
|
||||
|
||||
aDest.mCapacity=theNewCapacity++;
|
||||
theShift=(theShift<<aDest.mMultibyte)-4;
|
||||
if((theShift<12) && (mPools[theShift])){
|
||||
aDest.mStr=(char*)mPools[theShift]->Pop();
|
||||
}
|
||||
if(!aDest.mStr) {
|
||||
//we're given the acount value in charunits; we have to scale up by the charsize.
|
||||
size_t theSize=(theNewCapacity<<aDest.mMultibyte);
|
||||
aDest.mStr=new char[theSize];
|
||||
}
|
||||
aDest.mOwnsBuffer=1;
|
||||
return PR_TRUE;
|
||||
|
||||
}
|
||||
|
||||
virtual PRBool Free(nsStr& aDest){
|
||||
if(aDest.mStr){
|
||||
if(aDest.mOwnsBuffer){
|
||||
int theShift=1;
|
||||
unsigned int theValue=1;
|
||||
while((theValue<<=1)<aDest.mCapacity){
|
||||
theShift++;
|
||||
}
|
||||
theShift-=4;
|
||||
if(theShift<12){
|
||||
if(!mPools[theShift]){
|
||||
mPools[theShift]=new nsDeque(0);
|
||||
}
|
||||
mPools[theShift]->Push(aDest.mStr);
|
||||
}
|
||||
else delete [] aDest.mStr; //it's too big. Just delete it.
|
||||
}
|
||||
aDest.mStr=0;
|
||||
aDest.mOwnsBuffer=0;
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
nsDeque* mPools[16];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -71,6 +163,7 @@ void nsStr::Initialize(nsStr& aDest,eCharSize aCharSize) {
|
||||
aDest.mCapacity=0;
|
||||
aDest.mMultibyte=aCharSize;
|
||||
aDest.mOwnsBuffer=0;
|
||||
aDest.mUnused=0;
|
||||
NS_ASSERTION(aDest.mStr[0]==0,kFoolMsg);
|
||||
}
|
||||
|
||||
@@ -80,14 +173,25 @@ void nsStr::Initialize(nsStr& aDest,eCharSize aCharSize) {
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsIMemoryAgent* GetDefaultAgent(void){
|
||||
static nsIMemoryAgent* gDefaultAgent=0;
|
||||
if(!gDefaultAgent)
|
||||
gDefaultAgent=new nsMemoryAgent();
|
||||
|
||||
NS_ASSERTION(gDefaultAgent,"You MUST always have an allocator!");
|
||||
void nsStr::Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 aLength,eCharSize aCharSize,PRBool aOwnsBuffer){
|
||||
aDest.mStr=(aCString) ? aCString : GetSharedEmptyBuffer();
|
||||
aDest.mLength=aLength;
|
||||
aDest.mCapacity=aCapacity;
|
||||
aDest.mMultibyte=aCharSize;
|
||||
aDest.mOwnsBuffer=aOwnsBuffer;
|
||||
aDest.mUnused=0;
|
||||
}
|
||||
|
||||
return gDefaultAgent;
|
||||
/**
|
||||
*
|
||||
* @update gess10/30/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsIMemoryAgent* GetDefaultAgent(void){
|
||||
// static nsPoolingMemoryAgent gDefaultAgent;
|
||||
static nsMemoryAgent gDefaultAgent;
|
||||
return (nsIMemoryAgent*)&gDefaultAgent;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,20 +214,6 @@ void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess11/12/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRUnichar nsStr::GetCharAt(const nsStr& aDest,PRUint32 anIndex) {
|
||||
PRUnichar result=0;
|
||||
if((anIndex>=0) && (anIndex<aDest.mLength)) {
|
||||
result=(eTwoByte==aDest.mMultibyte) ? aDest.mUStr[anIndex] : aDest.mStr[anIndex];
|
||||
}//if
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method gets called when the internal buffer needs
|
||||
@@ -155,8 +245,8 @@ void nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAgen
|
||||
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
|
||||
EnsureCapacity(theTempStr,aNewLength,theAgent);
|
||||
|
||||
if(0<aDest.mLength) {
|
||||
Append(theTempStr,aDest,0,aDest.mLength,anAgent);
|
||||
if(aDest.mLength) {
|
||||
Append(theTempStr,aDest,0,aDest.mLength,theAgent);
|
||||
}
|
||||
theAgent->Free(aDest);
|
||||
aDest.mStr = theTempStr.mStr;
|
||||
@@ -182,13 +272,12 @@ void nsStr::Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 a
|
||||
/**
|
||||
* This method appends the given nsStr to this one. Note that we have to
|
||||
* pay attention to the underlying char-size of both structs.
|
||||
* @update gess 04/04/99
|
||||
* @update gess10/30/98
|
||||
* @param aDest is the nsStr to be manipulated
|
||||
* @param aSource is where char are copied from
|
||||
* @aCount is the number of bytes to be copied
|
||||
*/
|
||||
void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){
|
||||
|
||||
if(anOffset<aSource.mLength){
|
||||
PRUint32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
|
||||
PRUint32 theLength=(anOffset+theRealLen<aSource.mLength) ? theRealLen : (aSource.mLength-anOffset);
|
||||
@@ -221,30 +310,30 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin
|
||||
// 1. You're inserting chars into an empty string (assign)
|
||||
// 2. You're inserting onto the end of a string (append)
|
||||
// 3. You're inserting onto the 1..n-1 pos of a string (the hard case).
|
||||
if((0<aSource.mLength) && (aDestOffset<aDest.mLength-1)){
|
||||
if(0<aSource.mLength){
|
||||
ToRange(aDestOffset,0,aDest.mLength);
|
||||
if(aDest.mLength){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
if(aSrcOffset<aSource.mLength-1) {
|
||||
PRInt32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
|
||||
PRInt32 theLength=(aSrcOffset+theRealLen<aSource.mLength) ? theRealLen : (aSource.mLength-aSrcOffset);
|
||||
//ToRange(aSrcOffset,0,aSource.mLength-1);
|
||||
PRInt32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
|
||||
PRInt32 theLength=(aSrcOffset+theRealLen<aSource.mLength) ? theRealLen : (aSource.mLength-aSrcOffset);
|
||||
|
||||
if(aSrcOffset<aSource.mLength) {
|
||||
//here's the only new case we have to handle.
|
||||
//chars are really being inserted into our buffer...
|
||||
GrowCapacity(aDest,aDest.mLength+theLength,anAgent);
|
||||
if(aSrcOffset<aSource.mLength) {
|
||||
//here's the only new case we have to handle.
|
||||
//chars are really being inserted into our buffer...
|
||||
GrowCapacity(aDest,aDest.mLength+theLength,anAgent);
|
||||
|
||||
//shift the chars right by theDelta...
|
||||
(*gShiftChars[aDest.mMultibyte][PR_TRUE])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
|
||||
//shift the chars right by theDelta...
|
||||
(*gShiftChars[aDest.mMultibyte][PR_TRUE])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
|
||||
|
||||
//now insert new chars, starting at offset
|
||||
(*gCopyChars[aSource.mMultibyte][aDest.mMultibyte])(aDest.mStr,aDestOffset,aSource.mStr,aSrcOffset,theLength);
|
||||
//now insert new chars, starting at offset
|
||||
(*gCopyChars[aSource.mMultibyte][aDest.mMultibyte])(aDest.mStr,aDestOffset,aSource.mStr,aSrcOffset,theLength);
|
||||
|
||||
//finally, make sure to update the string length...
|
||||
aDest.mLength+=theLength;
|
||||
//finally, make sure to update the string length...
|
||||
aDest.mLength+=theLength;
|
||||
|
||||
}//if
|
||||
//else nothing to do!
|
||||
}
|
||||
}//if
|
||||
//else nothing to do!
|
||||
}
|
||||
else Append(aDest,aSource,0,aCount,anAgent);
|
||||
}
|
||||
@@ -260,22 +349,20 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin
|
||||
* @param aDestOffset is where in aDest deletion is to occur
|
||||
* @param aCount is the number of chars to be deleted in aDest
|
||||
*/
|
||||
void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){
|
||||
if(0<aCount){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAgent* anAgent){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
|
||||
PRInt32 theDelta=aDest.mLength-aDestOffset;
|
||||
PRInt32 theLength=(theDelta<aCount) ? theDelta : aCount;
|
||||
PRUint32 theDelta=aDest.mLength-aDestOffset;
|
||||
PRUint32 theLength=(theDelta<aCount) ? theDelta : aCount;
|
||||
|
||||
if(aDestOffset+theLength<aDest.mLength) {
|
||||
if(aDestOffset+theLength<aDest.mLength) {
|
||||
|
||||
//if you're here, it means we're cutting chars out of the middle of the string...
|
||||
//so shift the chars left by theLength...
|
||||
(*gShiftChars[aDest.mMultibyte][PR_FALSE])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
|
||||
aDest.mLength-=theLength;
|
||||
}
|
||||
else Truncate(aDest,aDestOffset,anAgent);
|
||||
}//if
|
||||
//if you're here, it means we're cutting chars out of the middle of the string...
|
||||
//so shift the chars left by theLength...
|
||||
(*gShiftChars[aDest.mMultibyte][PR_FALSE])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
|
||||
aDest.mLength-=theLength;
|
||||
}
|
||||
else Truncate(aDest,aDestOffset,anAgent);
|
||||
}//if
|
||||
}
|
||||
|
||||
@@ -343,28 +430,28 @@ void nsStr::CompressSet(nsStr& aDest,const char* aSet,PRUint32 aChar,PRBool aEli
|
||||
**************************************************************/
|
||||
|
||||
|
||||
PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool /*aIgnoreCase*/,PRUint32 anOffset) {
|
||||
PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 index=anOffset-1;
|
||||
PRInt32 theMax=aDest.mLength-aTarget.mLength;
|
||||
if((aDest.mLength>0) && (aTarget.mLength>0)){
|
||||
PRInt32 theNewStartPos=-1;
|
||||
PRUnichar theFirstTargetChar=nsStr::GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=nsStr::GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRUnichar theFirstTargetChar=GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRInt32 theTargetMax=aTarget.mLength;
|
||||
while(++index<=theMax) {
|
||||
PRInt32 theSubIndex=-1;
|
||||
PRBool matches=PR_TRUE;
|
||||
while((++theSubIndex<theTargetMax) && (matches)){
|
||||
PRUnichar theChar=nsStr::GetCharAt(aDest,index+theSubIndex);
|
||||
PRUnichar theChar=GetCharAt(aDest,index+theSubIndex);
|
||||
if(theSubIndex>0) {
|
||||
if(theFirstTargetChar==theChar){
|
||||
PRUnichar theDestJumpChar=nsStr::GetCharAt(aDest,index+theTargetMax);
|
||||
PRUnichar theDestJumpChar=GetCharAt(aDest,index+theTargetMax);
|
||||
if(theDestJumpChar==theLastTargetChar) {
|
||||
theNewStartPos=index; //this lets us jump ahead during our search where possible.
|
||||
}//if
|
||||
}//if
|
||||
}//if
|
||||
PRUnichar theTargetChar=nsStr::GetCharAt(aTarget,theSubIndex);
|
||||
PRUnichar theTargetChar=GetCharAt(aTarget,theSubIndex);
|
||||
matches=PRBool(theChar==theTargetChar);
|
||||
}
|
||||
if(matches)
|
||||
@@ -384,8 +471,8 @@ PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool /*aIgn
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsStr::FindChar(const nsStr& aDest, PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase);
|
||||
PRInt32 nsStr::FindChar(const nsStr& aDest,const PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,0,aChar,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -415,12 +502,12 @@ PRInt32 nsStr::FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnore
|
||||
**************************************************************/
|
||||
|
||||
|
||||
PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool /*aIgnoreCase*/,PRUint32 anOffset) {
|
||||
PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 index=(anOffset ? anOffset : aDest.mLength-aTarget.mLength+1);
|
||||
if((aDest.mLength>0) && (aTarget.mLength>0)){
|
||||
PRInt32 theNewStartPos=-1;
|
||||
PRUnichar theFirstTargetChar=nsStr::GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=nsStr::GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRUnichar theFirstTargetChar=GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRInt32 theTargetMax=aTarget.mLength;
|
||||
|
||||
while(index--) {
|
||||
@@ -429,16 +516,16 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool /*aIg
|
||||
|
||||
if(anOffset+aTarget.mLength<=aDest.mLength) {
|
||||
while((++theSubIndex<theTargetMax) && (matches)){
|
||||
PRUnichar theChar=nsStr::GetCharAt(aDest,index+theSubIndex);
|
||||
PRUnichar theChar=GetCharAt(aDest,index+theSubIndex);
|
||||
if(theSubIndex>0) {
|
||||
if(theFirstTargetChar==theChar){
|
||||
PRUnichar theDestJumpChar=nsStr::GetCharAt(aDest,index+theTargetMax);
|
||||
PRUnichar theDestJumpChar=GetCharAt(aDest,index+theTargetMax);
|
||||
if(theDestJumpChar==theLastTargetChar) {
|
||||
theNewStartPos=index; //this lets us jump ahead during our search where possible.
|
||||
}//if
|
||||
}//if
|
||||
}//if
|
||||
PRUnichar theTargetChar=nsStr::GetCharAt(aTarget,theSubIndex);
|
||||
PRUnichar theTargetChar=GetCharAt(aTarget,theSubIndex);
|
||||
matches=PRBool(theChar==theTargetChar);
|
||||
} //while
|
||||
} //if
|
||||
@@ -459,8 +546,8 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool /*aIg
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsStr::RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gRFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase);
|
||||
PRInt32 nsStr::RFindChar(const nsStr& aDest,const PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gRFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,0,aChar,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -472,11 +559,11 @@ PRInt32 nsStr::RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,
|
||||
* @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) {
|
||||
PRUnichar theChar=GetCharAt(aDest,PRUint32(offset));
|
||||
PRUnichar theChar=GetCharAt(aDest,offset);
|
||||
thePos=gRFindChars[aSet.mMultibyte](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase);
|
||||
if(kNotFound!=thePos)
|
||||
return offset;
|
||||
@@ -491,7 +578,7 @@ PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnor
|
||||
* @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 nsStr::Compare(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) {
|
||||
int minlen=(aSource.mLength<aDest.mLength) ? aSource.mLength : aDest.mLength;
|
||||
|
||||
if(0==minlen) {
|
||||
|
||||
@@ -27,8 +27,6 @@
|
||||
We chose the option B for performance reasons.
|
||||
|
||||
2 Our internal buffer always holds capacity+1 bytes.
|
||||
3. Note that our internal format for this class makes our memory
|
||||
layout compatible with BStrings.
|
||||
|
||||
The nsStr struct is a simple structure (no methods) that contains
|
||||
the necessary info to be described as a string. This simple struct
|
||||
@@ -44,41 +42,13 @@
|
||||
#ifndef _nsStr
|
||||
#define _nsStr
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nscore.h"
|
||||
#include "nsCore.h"
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
enum eCharSize {eOneByte=0,eTwoByte=1};
|
||||
#define kDefaultCharSize eTwoByte
|
||||
|
||||
|
||||
union UStrPtr {
|
||||
char* mCharBuf;
|
||||
PRUnichar* mUnicharBuf;
|
||||
};
|
||||
|
||||
/**************************************************************************
|
||||
Here comes the nsBufDescriptor class which describes buffer properties.
|
||||
**************************************************************************/
|
||||
|
||||
struct nsBufDescriptor {
|
||||
nsBufDescriptor(char* aBuffer,PRUint32 aBufferSize,eCharSize aCharSize,PRBool aOwnsBuffer) {
|
||||
mStr=aBuffer;
|
||||
mMultibyte=aCharSize;
|
||||
mCapacity=(aBufferSize>>mMultibyte)-1;
|
||||
mOwnsBuffer=aOwnsBuffer;
|
||||
}
|
||||
|
||||
PRUint32 mCapacity;
|
||||
PRBool mOwnsBuffer;
|
||||
eCharSize mMultibyte;
|
||||
// UStrPtr mStr;
|
||||
union {
|
||||
char* mStr;
|
||||
PRUnichar* mUStr;
|
||||
};
|
||||
};
|
||||
const PRInt32 kNotFound = -1;
|
||||
|
||||
|
||||
class nsIMemoryAgent;
|
||||
@@ -97,6 +67,15 @@ struct nsStr {
|
||||
*/
|
||||
static void Initialize(nsStr& aDest,eCharSize aCharSize);
|
||||
|
||||
/**
|
||||
* This method initializes an nsStr for use
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aString is the nsStr to be initialized
|
||||
* @param aCharSize tells us the requested char size (1 or 2 bytes)
|
||||
*/
|
||||
static void Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 aLength,eCharSize aCharSize,PRBool aOwnsBuffer);
|
||||
|
||||
/**
|
||||
* This method destroys the given nsStr, and *MAY*
|
||||
* deallocate it's memory depending on the setting
|
||||
@@ -166,7 +145,7 @@ struct nsStr {
|
||||
* @param aCount tells us the (max) # of chars to delete
|
||||
* @param anAgent is the allocator to be used for alloc/free operations
|
||||
*/
|
||||
static void Delete(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0);
|
||||
static void Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAgent* anAgent=0);
|
||||
|
||||
/**
|
||||
* This method is used to truncate the given string.
|
||||
@@ -254,21 +233,20 @@ struct nsStr {
|
||||
static PRInt32 RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset);
|
||||
static PRInt32 RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRUint32 anOffset);
|
||||
|
||||
/**
|
||||
* This method is used to access a given char in the given string
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the nsStr to be appended to
|
||||
* @param anIndex tells us where in dest to get the char from
|
||||
* @return the given char, or 0 if anIndex is out of range
|
||||
*/
|
||||
static PRUnichar GetCharAt(const nsStr& aDest,PRUint32 anIndex);
|
||||
|
||||
PRUint32 mLength : 30;
|
||||
eCharSize mMultibyte : 2;
|
||||
#ifdef NS_DEBUG
|
||||
PRUint32 mLength;
|
||||
eCharSize mMultibyte;
|
||||
PRUint32 mCapacity;
|
||||
PRUint32 mOwnsBuffer;
|
||||
PRUint32 mUnused;
|
||||
#else
|
||||
PRUint32 mLength: 30;
|
||||
eCharSize mMultibyte: 2;
|
||||
PRUint32 mCapacity: 30;
|
||||
PRUint32 mOwnsBuffer: 1;
|
||||
PRUint32 mUnused: 1;
|
||||
PRUint32 mOwnsBuffer: 1;
|
||||
PRUint32 mUnused: 1;
|
||||
#endif
|
||||
union {
|
||||
char* mStr;
|
||||
PRUnichar* mUStr;
|
||||
@@ -307,6 +285,21 @@ inline void AddNullTerminator(nsStr& aDest) {
|
||||
else aDest.mStr[aDest.mLength]=0;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to access a given char in the given string
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the nsStr to be appended to
|
||||
* @param anIndex tells us where in dest to get the char from
|
||||
* @return the given char, or 0 if anIndex is out of range
|
||||
*/
|
||||
inline PRUnichar GetCharAt(const nsStr& aDest,PRUint32 anIndex){
|
||||
if(anIndex<aDest.mLength) {
|
||||
return (eTwoByte==aDest.mMultibyte) ? aDest.mUStr[anIndex] : aDest.mStr[anIndex];
|
||||
}//if
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
class nsIMemoryAgent {
|
||||
@@ -317,25 +310,18 @@ public:
|
||||
};
|
||||
|
||||
class nsMemoryAgent : public nsIMemoryAgent {
|
||||
enum eDelta{eGrowthDelta=8};
|
||||
protected:
|
||||
enum eDelta{eDefaultSize=16};
|
||||
public:
|
||||
|
||||
virtual PRBool Alloc(nsStr& aDest,PRInt32 aCount) {
|
||||
|
||||
//we're given the acount value in charunits; we have to scale up by the charsize.
|
||||
|
||||
PRInt32 theNewCapacity;
|
||||
if (aDest.mCapacity > 64) {
|
||||
// When the string starts getting large, double the capacity as we grow.
|
||||
theNewCapacity = aDest.mCapacity * 2;
|
||||
if (theNewCapacity < aCount) {
|
||||
theNewCapacity = aDest.mCapacity + aCount;
|
||||
}
|
||||
} else {
|
||||
// When the string is small, keep it's capacity a multiple of kGrowthDelta
|
||||
PRInt32 unitDelta=(aCount/eGrowthDelta)+1;
|
||||
theNewCapacity=unitDelta*eGrowthDelta;
|
||||
//we're given the acount value in charunits; now scale up to next multiple.
|
||||
PRInt32 theNewCapacity=eDefaultSize;
|
||||
while(theNewCapacity<aCount){
|
||||
theNewCapacity<<=1;
|
||||
}
|
||||
|
||||
|
||||
aDest.mCapacity=theNewCapacity++;
|
||||
size_t theSize=(theNewCapacity<<aDest.mMultibyte);
|
||||
aDest.mStr=new char[theSize];
|
||||
@@ -362,6 +348,5 @@ public:
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -30,8 +30,8 @@
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef _NSSTRING
|
||||
#define _NSSTRING
|
||||
#ifndef _nsString1
|
||||
#define _nsString1
|
||||
|
||||
|
||||
#include "prtypes.h"
|
||||
@@ -39,9 +39,18 @@
|
||||
#include "nsIAtom.h"
|
||||
#include <iostream.h>
|
||||
#include <stdio.h>
|
||||
#include "nsStr.h"
|
||||
|
||||
#ifndef USE_STRING2
|
||||
#define nsString1 nsString
|
||||
#define nsAutoString1 nsAutoString
|
||||
#else
|
||||
#include "nsString2.h" //get new string class
|
||||
#endif
|
||||
|
||||
class nsISizeOfHandler;
|
||||
|
||||
class NS_BASE nsString {
|
||||
class NS_BASE nsString1 {
|
||||
public:
|
||||
|
||||
/**
|
||||
@@ -50,30 +59,30 @@ class NS_BASE nsString {
|
||||
* was to allow developers direct access to the underlying buffer for
|
||||
* performance reasons.
|
||||
*/
|
||||
nsString();
|
||||
nsString1();
|
||||
|
||||
/**
|
||||
* This constructor accepts an isolatin string
|
||||
* @param an ascii is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsString(const char* aCString);
|
||||
nsString1(const char* aCString);
|
||||
|
||||
/**
|
||||
* This is our copy constructor
|
||||
* @param reference to another nsString
|
||||
* @param reference to another nsString1
|
||||
*/
|
||||
nsString(const nsString&);
|
||||
nsString1(const nsString1&);
|
||||
|
||||
/**
|
||||
* Constructor from a unicode string
|
||||
* @param anicodestr pts to a unicode string
|
||||
*/
|
||||
nsString(const PRUnichar* aUnicode);
|
||||
nsString1(const PRUnichar* aUnicode);
|
||||
|
||||
/**
|
||||
* Virtual Destructor
|
||||
*/
|
||||
virtual ~nsString();
|
||||
virtual ~nsString1();
|
||||
|
||||
|
||||
/**
|
||||
@@ -136,14 +145,14 @@ const PRUnichar* GetUnicode(void) const;
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
operator const PRUnichar*() const;
|
||||
//operator const PRUnichar*() const;
|
||||
|
||||
/**
|
||||
* Retrieve unicode char at given index
|
||||
* @param offset into string
|
||||
* @return PRUnichar* to internal string
|
||||
*/
|
||||
PRUnichar operator()(PRInt32 anIndex) const;
|
||||
//PRUnichar operator()(PRInt32 anIndex) const;
|
||||
|
||||
/**
|
||||
* Retrieve reference to unicode char at given index
|
||||
@@ -183,35 +192,35 @@ PRBool SetCharAt(PRUnichar aChar,PRInt32 anIndex);
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsString operator+(const nsString& aString);
|
||||
nsString1 operator+(const nsString1& aString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given buffer.
|
||||
* @param aCString is a ptr to cstring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString operator+(const char* aCString);
|
||||
nsString1 operator+(const char* aCString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given char.
|
||||
* @param aChar is a char to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString operator+(char aChar);
|
||||
nsString1 operator+(char aChar);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given buffer.
|
||||
* @param aStr unichar buffer to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString operator+(const PRUnichar* aBuffer);
|
||||
nsString1 operator+(const PRUnichar* aBuffer);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given char.
|
||||
* @param aChar is a unichar to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString operator+(PRUnichar aChar);
|
||||
nsString1 operator+(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* Converts all chars in internal string to lower
|
||||
@@ -221,7 +230,7 @@ void ToLowerCase();
|
||||
/**
|
||||
* Converts all chars in given string to lower
|
||||
*/
|
||||
void ToLowerCase(nsString& aString) const;
|
||||
void ToLowerCase(nsString1& aString) const;
|
||||
|
||||
/**
|
||||
* Converts all chars in given string to upper
|
||||
@@ -237,13 +246,13 @@ void ToUCS2(PRInt32 aStartOffset);
|
||||
/**
|
||||
* Converts all chars in internal string to upper
|
||||
*/
|
||||
void ToUpperCase(nsString& aString) const;
|
||||
void ToUpperCase(nsString1& aString) const;
|
||||
|
||||
/**
|
||||
* Creates a duplicate clone (ptr) of this string.
|
||||
* @return ptr to clone of this string
|
||||
*/
|
||||
nsString* ToNewString() const;
|
||||
nsString1* ToNewString() const;
|
||||
|
||||
/**
|
||||
* Creates an ascii clone of this string
|
||||
@@ -265,7 +274,7 @@ char* ToCString(char* aBuf,PRInt32 aBufLength) const;
|
||||
* @param aString to hold copy of this
|
||||
* @return nada.
|
||||
*/
|
||||
void Copy(nsString& aString) const;
|
||||
void Copy(nsString1& aString) const;
|
||||
|
||||
/**
|
||||
* Creates an unichar clone of this string
|
||||
@@ -298,79 +307,72 @@ PRInt32 ToInteger(PRInt32* aErrorCode,PRInt32 aRadix=10) const;
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString& SetString(const PRUnichar* aStr,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* assign given char* to this string
|
||||
* @param aCString: buffer to be assigned to this
|
||||
* @param alength is the length of the given str (or -1)
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString& SetString(const char* aCString,PRInt32 aLength=-1);
|
||||
nsString1& SetString(const PRUnichar* aStr,PRInt32 aLength=-1);
|
||||
nsString1& SetString(const char* aCString,PRInt32 aLength=-1);
|
||||
nsString1& SetString(const nsString1& aString);
|
||||
|
||||
/**
|
||||
* assign given string to this one
|
||||
* @param aString: string to be added to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator=(const nsString& aString);
|
||||
nsString1& operator=(const nsString1& aString);
|
||||
|
||||
/**
|
||||
* assign given char* to this string
|
||||
* @param aCString: buffer to be assigned to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator=(const char* aCString);
|
||||
nsString1& operator=(const char* aCString);
|
||||
|
||||
/**
|
||||
* assign given char to this string
|
||||
* @param aChar: char to be assignd to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator=(char aChar);
|
||||
nsString1& operator=(char aChar);
|
||||
|
||||
/**
|
||||
* assign given unichar* to this string
|
||||
* @param aBuffer: unichar buffer to be assigned to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator=(const PRUnichar* aBuffer);
|
||||
nsString1& operator=(const PRUnichar* aBuffer);
|
||||
|
||||
/**
|
||||
* assign given char to this string
|
||||
* @param aChar: char to be assignd to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator=(PRUnichar aChar);
|
||||
nsString1& operator=(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @param aString : string to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator+=(const nsString& aString);
|
||||
nsString1& operator+=(const nsString1& aString);
|
||||
|
||||
/**
|
||||
* append given buffer to this string
|
||||
* @param aCString: buffer to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator+=(const char* aCString);
|
||||
nsString1& operator+=(const char* aCString);
|
||||
|
||||
/**
|
||||
* append given buffer to this string
|
||||
* @param aBuffer: buffer to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator+=(const PRUnichar* aBuffer);
|
||||
nsString1& operator+=(const PRUnichar* aBuffer);
|
||||
|
||||
/**
|
||||
* append given char to this string
|
||||
* @param aChar: char to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator+=(PRUnichar aChar);
|
||||
nsString1& operator+=(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
@@ -379,7 +381,7 @@ nsString& operator+=(PRUnichar aChar);
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(const nsString& aString,PRInt32 aLength=-1);
|
||||
nsString1& Append(const nsString1& aString,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
@@ -388,14 +390,14 @@ nsString& Append(const nsString& aString,PRInt32 aLength=-1);
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(const char* aCString,PRInt32 aLength=-1);
|
||||
nsString1& Append(const char* aCString,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @param aString : string to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(char aChar);
|
||||
nsString1& Append(char aChar);
|
||||
|
||||
/**
|
||||
* append given unichar buffer to this string
|
||||
@@ -404,14 +406,14 @@ nsString& Append(char aChar);
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(const PRUnichar* aBuffer,PRInt32 aLength=-1);
|
||||
nsString1& Append(const PRUnichar* aBuffer,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* append given unichar character to this string
|
||||
* @param aChar is the char to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(PRUnichar aChar);
|
||||
nsString1& Append(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* Append an integer onto this string
|
||||
@@ -419,14 +421,14 @@ nsString& Append(PRUnichar aChar);
|
||||
* @param aRadix specifies 8,10,16
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(PRInt32 aInteger,PRInt32 aRadix); //radix=8,10 or 16
|
||||
nsString1& Append(PRInt32 aInteger,PRInt32 aRadix); //radix=8,10 or 16
|
||||
|
||||
/**
|
||||
* Append a float value onto this string
|
||||
* @param aFloat is the float to be appended
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(float aFloat);
|
||||
nsString1& Append(float aFloat);
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
@@ -437,7 +439,7 @@ nsString& Append(float aFloat);
|
||||
* @param aCount -- number of chars to copy
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Left(nsString& aCopy,PRInt32 aCount) const;
|
||||
PRInt32 Left(nsString1& aCopy,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
@@ -449,7 +451,7 @@ PRInt32 Left(nsString& aCopy,PRInt32 aCount) const;
|
||||
* @param anOffset -- position where copying begins
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Mid(nsString& aCopy,PRInt32 anOffset,PRInt32 aCount) const;
|
||||
PRInt32 Mid(nsString1& aCopy,PRInt32 anOffset,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
@@ -460,7 +462,7 @@ PRInt32 Mid(nsString& aCopy,PRInt32 anOffset,PRInt32 aCount) const;
|
||||
* @param aCount -- number of chars to copy
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Right(nsString& aCopy,PRInt32 aCount) const;
|
||||
PRInt32 Right(nsString1& aCopy,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* This method inserts n chars from given string into this
|
||||
@@ -471,7 +473,7 @@ PRInt32 Right(nsString& aCopy,PRInt32 aCount) const;
|
||||
* @param aCount -- number of chars to be copied from aCopy
|
||||
* @return number of chars inserted into this.
|
||||
*/
|
||||
PRInt32 Insert(const nsString& aCopy,PRInt32 anOffset,PRInt32 aCount=-1);
|
||||
PRInt32 Insert(const nsString1& aCopy,PRInt32 anOffset,PRInt32 aCount=-1);
|
||||
|
||||
/**
|
||||
* Insert a single unicode char into this string at
|
||||
@@ -491,7 +493,7 @@ PRInt32 Insert(PRUnichar aChar,PRInt32 anOffset);
|
||||
* @param aCount -- number of chars to be cut
|
||||
* @return *this
|
||||
*/
|
||||
nsString& Cut(PRInt32 anOffset,PRInt32 aCount);
|
||||
nsString1& Cut(PRInt32 anOffset,PRInt32 aCount);
|
||||
|
||||
/**
|
||||
* This method is used to remove all occurances of the
|
||||
@@ -500,7 +502,7 @@ nsString& Cut(PRInt32 anOffset,PRInt32 aCount);
|
||||
* @param aSet -- characters to be cut from this
|
||||
* @return *this
|
||||
*/
|
||||
nsString& StripChars(const char* aSet);
|
||||
nsString1& StripChars(const char* aSet);
|
||||
|
||||
/**
|
||||
* This method is used to replace all occurances of the
|
||||
@@ -509,14 +511,14 @@ nsString& StripChars(const char* aSet);
|
||||
* @param
|
||||
* @return *this
|
||||
*/
|
||||
nsString& ReplaceChar(PRUnichar aSourceChar, PRUnichar aDestChar);
|
||||
nsString1& ReplaceChar(PRUnichar aSourceChar, PRUnichar aDestChar);
|
||||
|
||||
/**
|
||||
* This method strips whitespace throughout the string
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
nsString& StripWhitespace();
|
||||
nsString1& StripWhitespace();
|
||||
|
||||
/**
|
||||
* This method trims characters found in aTrimSet from
|
||||
@@ -526,7 +528,7 @@ nsString& StripWhitespace();
|
||||
* both ends
|
||||
* @return this
|
||||
*/
|
||||
nsString& Trim(const char* aSet,
|
||||
nsString1& Trim(const char* aSet,
|
||||
PRBool aEliminateLeading=PR_TRUE,
|
||||
PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
@@ -539,7 +541,7 @@ nsString& Trim(const char* aSet,
|
||||
* @param aEliminateTrailing controls stripping of trailing ws
|
||||
* @return this
|
||||
*/
|
||||
nsString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,
|
||||
nsString1& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,
|
||||
PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
/**
|
||||
@@ -588,7 +590,7 @@ PRInt32 BinarySearch(PRUnichar aChar) const;
|
||||
*/
|
||||
PRInt32 Find(const char* aString) const;
|
||||
PRInt32 Find(const PRUnichar* aString) const;
|
||||
PRInt32 Find(const nsString& aString) const;
|
||||
PRInt32 Find(const nsString1& aString) const;
|
||||
|
||||
/**
|
||||
* Search for given char within this string
|
||||
@@ -606,7 +608,7 @@ PRInt32 Find(PRUnichar aChar,PRInt32 offset=0) const;
|
||||
* @return -1 if not found, else the offset in this
|
||||
*/
|
||||
PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 FindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 FindCharInSet(nsString1& aString,PRInt32 anOffset=0) const;
|
||||
|
||||
/**
|
||||
* This method searches this string for the last character
|
||||
@@ -616,7 +618,7 @@ PRInt32 FindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
||||
* @return -1 if not found, else the offset in this
|
||||
*/
|
||||
PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 RFindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 RFindCharInSet(nsString1& aString,PRInt32 anOffset=0) const;
|
||||
|
||||
|
||||
/**
|
||||
@@ -627,7 +629,7 @@ PRInt32 RFindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
||||
*/
|
||||
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFind(const nsString1& aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
|
||||
/**
|
||||
* This methods scans the string backwards, looking for the given char
|
||||
@@ -648,7 +650,7 @@ PRInt32 RFind(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
* @param aIgnoreCase tells us how to treat case
|
||||
* @return -1,0,1
|
||||
*/
|
||||
virtual PRInt32 Compare(const nsString &aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
virtual PRInt32 Compare(const nsString1 &aString,PRBool aIgnoreCase=PR_FALSE) 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;
|
||||
|
||||
@@ -657,7 +659,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 nsString1 &aString) const;
|
||||
PRBool operator==(const char *aString) const;
|
||||
PRBool operator==(const PRUnichar* aString) const;
|
||||
PRBool operator==(PRUnichar* aString) const;
|
||||
@@ -667,7 +669,7 @@ PRBool operator==(PRUnichar* aString) const;
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE
|
||||
*/
|
||||
PRBool operator!=(const nsString &aString) const;
|
||||
PRBool operator!=(const nsString1 &aString) const;
|
||||
PRBool operator!=(const char *aString) const;
|
||||
PRBool operator!=(const PRUnichar* aString) const;
|
||||
|
||||
@@ -676,7 +678,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 nsString1 &aString) const;
|
||||
PRBool operator<(const char *aString) const;
|
||||
PRBool operator<(const PRUnichar* aString) const;
|
||||
|
||||
@@ -685,7 +687,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 &S) const;
|
||||
PRBool operator>(const nsString1 &S) const;
|
||||
PRBool operator>(const char *aCString) const;
|
||||
PRBool operator>(const PRUnichar* aString) const;
|
||||
|
||||
@@ -694,7 +696,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 &S) const;
|
||||
PRBool operator<=(const nsString1 &S) const;
|
||||
PRBool operator<=(const char *aCString) const;
|
||||
PRBool operator<=(const PRUnichar* aString) const;
|
||||
|
||||
@@ -703,7 +705,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 &S) const;
|
||||
PRBool operator>=(const nsString1 &S) const;
|
||||
PRBool operator>=(const char* aCString) const;
|
||||
PRBool operator>=(const PRUnichar* aString) const;
|
||||
|
||||
@@ -717,7 +719,7 @@ PRBool operator>=(const PRUnichar* aString) const;
|
||||
* @param aLength -- optional length of given string.
|
||||
* @return TRUE if equal
|
||||
*/
|
||||
PRBool Equals(const nsString& aString) const;
|
||||
PRBool Equals(const nsString1& aString) const;
|
||||
PRBool Equals(const char* aString,PRInt32 aLength=-1) const;
|
||||
PRBool Equals(const nsIAtom *aAtom) const;
|
||||
|
||||
@@ -740,7 +742,7 @@ PRBool Equals(const PRUnichar* s1, const PRUnichar* s2) const;
|
||||
* @param aLength -- optional length of given string.
|
||||
* @return TRUE if equal
|
||||
*/
|
||||
PRBool EqualsIgnoreCase(const nsString& aString) const;
|
||||
PRBool EqualsIgnoreCase(const nsString1& aString) const;
|
||||
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aLength=-1) const;
|
||||
PRBool EqualsIgnoreCase(const nsIAtom *aAtom) const;
|
||||
|
||||
@@ -768,34 +770,34 @@ typedef PRUnichar chartype;
|
||||
#endif
|
||||
};
|
||||
|
||||
ostream& operator<<(ostream& os,nsString& aString);
|
||||
extern NS_BASE int fputs(const nsString& aString, FILE* out);
|
||||
ostream& operator<<(ostream& os,nsString1& aString);
|
||||
extern NS_BASE int fputs(const nsString1& aString, FILE* out);
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* A version of nsString which is designed to be used as an automatic
|
||||
* A version of nsString1 which is designed to be used as an automatic
|
||||
* variable. It attempts to operate out of a fixed size internal
|
||||
* buffer until too much data is added; then a dynamic buffer is
|
||||
* allocated and grown as necessary.
|
||||
*/
|
||||
// XXX template this with a parameter for the size of the buffer?
|
||||
class NS_BASE nsAutoString : public nsString {
|
||||
class NS_BASE nsAutoString1 : public nsString1 {
|
||||
public:
|
||||
nsAutoString();
|
||||
nsAutoString(const nsString& other);
|
||||
nsAutoString(const nsAutoString& other);
|
||||
nsAutoString(PRUnichar aChar);
|
||||
nsAutoString(const char* aCString);
|
||||
nsAutoString(const PRUnichar* us, PRInt32 uslen = -1);
|
||||
virtual ~nsAutoString();
|
||||
nsAutoString1();
|
||||
nsAutoString1(const nsString1& other);
|
||||
nsAutoString1(const nsAutoString1& other);
|
||||
nsAutoString1(PRUnichar aChar);
|
||||
nsAutoString1(const char* aCString);
|
||||
nsAutoString1(const PRUnichar* us, PRInt32 uslen = -1);
|
||||
virtual ~nsAutoString1();
|
||||
|
||||
nsAutoString& operator=(const nsString& aString) {nsString::operator=(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;}
|
||||
nsAutoString1& operator=(const nsString1& aString) {nsString1::operator=(aString); return *this;}
|
||||
nsAutoString1& operator=(const nsAutoString1& aString) {nsString1::operator=(aString); return *this;}
|
||||
nsAutoString1& operator=(const char* aCString) {nsString1::operator=(aCString); return *this;}
|
||||
nsAutoString1& operator=(char aChar) {nsString1::operator=(aChar); return *this;}
|
||||
nsAutoString1& operator=(const PRUnichar* aBuffer) {nsString1::operator=(aBuffer); return *this;}
|
||||
nsAutoString1& operator=(PRUnichar aChar) {nsString1::operator=(aChar); return *this;}
|
||||
|
||||
virtual void SizeOf(nsISizeOfHandler* aHandler) const;
|
||||
|
||||
@@ -807,7 +809,7 @@ protected:
|
||||
chartype mBuf[32];
|
||||
};
|
||||
|
||||
ostream& operator<<(ostream& os,nsAutoString& aString);
|
||||
ostream& operator<<(ostream& os,nsAutoString1& aString);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -25,18 +25,15 @@
|
||||
#include "nsDebug.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsISizeOfHandler.h"
|
||||
#include "prprf.h"
|
||||
#include "prdtoa.h"
|
||||
#include "nsDeque.h"
|
||||
|
||||
#include "nsUnicharUtilCIID.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsICaseConversion.h"
|
||||
#ifndef RICKG_TESTBED
|
||||
#include "prdtoa.h"
|
||||
#include "nsISizeOfHandler.h"
|
||||
#endif
|
||||
|
||||
static const char* kNullPointerError = "Error: unexpected null ptr";
|
||||
static const char* kWhitespace="\b\t\r\n ";
|
||||
static const PRInt32 kNotFound=-1;
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
PRBool nsString2::mSelfTested = PR_FALSE;
|
||||
@@ -97,58 +94,7 @@ public:
|
||||
}
|
||||
}
|
||||
};
|
||||
static CTableConstructor gTableConstructor;
|
||||
|
||||
//---- XPCOM code to connect with UnicharUtil
|
||||
|
||||
class HandleCaseConversionShutdown3 : public nsIShutdownListener {
|
||||
public :
|
||||
NS_IMETHOD OnShutdown(const nsCID& cid, nsISupports* service);
|
||||
HandleCaseConversionShutdown3(void) { NS_INIT_REFCNT(); }
|
||||
virtual ~HandleCaseConversionShutdown3(void) {}
|
||||
NS_DECL_ISUPPORTS
|
||||
};
|
||||
static NS_DEFINE_CID(kUnicharUtilCID, NS_UNICHARUTIL_CID);
|
||||
static NS_DEFINE_IID(kICaseConversionIID, NS_ICASECONVERSION_IID);
|
||||
|
||||
static nsICaseConversion * gCaseConv = NULL;
|
||||
|
||||
static NS_DEFINE_IID(kIShutdownListenerIID, NS_ISHUTDOWNLISTENER_IID);
|
||||
NS_IMPL_ISUPPORTS(HandleCaseConversionShutdown3, kIShutdownListenerIID);
|
||||
|
||||
nsresult
|
||||
HandleCaseConversionShutdown3::OnShutdown(const nsCID& cid, nsISupports* service)
|
||||
{
|
||||
if (cid.Equals(kUnicharUtilCID)) {
|
||||
NS_ASSERTION(service == gCaseConv, "wrong service!");
|
||||
gCaseConv->Release();
|
||||
gCaseConv = NULL;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static HandleCaseConversionShutdown3* gListener = NULL;
|
||||
|
||||
static void StartUpCaseConversion()
|
||||
{
|
||||
nsresult err;
|
||||
|
||||
if ( NULL == gListener )
|
||||
{
|
||||
gListener = new HandleCaseConversionShutdown3();
|
||||
gListener->AddRef();
|
||||
}
|
||||
err = nsServiceManager::GetService(kUnicharUtilCID, kICaseConversionIID,
|
||||
(nsISupports**) &gCaseConv, gListener);
|
||||
}
|
||||
static void CheckCaseConversion()
|
||||
{
|
||||
if(NULL == gCaseConv )
|
||||
StartUpCaseConversion();
|
||||
|
||||
// NS_ASSERTION( gCaseConv != NULL , "cannot obtain UnicharUtil");
|
||||
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
IMPLEMENTATION NOTES:
|
||||
@@ -158,6 +104,15 @@ static void CheckCaseConversion()
|
||||
that no poor soul would ever have to do this again. Sigh.
|
||||
***********************************************************************/
|
||||
|
||||
void Subsume(nsStr& aDest,nsStr& aSource){
|
||||
aDest.mStr=aSource.mStr;
|
||||
aDest.mLength=aSource.mLength;
|
||||
aDest.mMultibyte=aSource.mMultibyte;
|
||||
aDest.mCapacity=aSource.mCapacity;
|
||||
aDest.mOwnsBuffer=aSource.mOwnsBuffer;
|
||||
aSource.mOwnsBuffer=PR_FALSE;
|
||||
aSource.mStr=0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor. Note that we actually allocate a small buffer
|
||||
@@ -216,6 +171,15 @@ nsString2::nsString2(const nsString2& aString) :mAgent(aString.mAgent) {
|
||||
nsStr::Assign(*this,aString,0,aString.mLength,mAgent);
|
||||
}
|
||||
|
||||
/**
|
||||
* construct off a subsumeable string
|
||||
* @update gess 1/4/99
|
||||
* @param reference to a subsumeString
|
||||
*/
|
||||
nsString2::nsString2(nsSubsumeStr& aSubsumeStr) :mAgent(0) {
|
||||
Subsume(*this,aSubsumeStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
* Make sure we call nsStr::Destroy.
|
||||
@@ -293,7 +257,7 @@ void nsString2::SetCapacity(PRUint32 aLength) {
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
char* nsString2::GetBuffer(void) const {
|
||||
const char* nsString2::GetBuffer(void) const {
|
||||
if(!mMultibyte)
|
||||
return mStr;
|
||||
return 0;
|
||||
@@ -305,7 +269,7 @@ char* nsString2::GetBuffer(void) const {
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRUnichar* nsString2::GetUnicode(void) const {
|
||||
const PRUnichar* nsString2::GetUnicode(void) const {
|
||||
if(mMultibyte)
|
||||
return (PRUnichar*)mUStr;
|
||||
return 0;
|
||||
@@ -314,11 +278,11 @@ PRUnichar* nsString2::GetUnicode(void) const {
|
||||
/**
|
||||
* Get nth character.
|
||||
*/
|
||||
PRUnichar nsString2::operator[](int anIndex) const {
|
||||
PRUnichar nsString2::operator[](PRUint32 anIndex) const {
|
||||
return GetCharAt(*this,anIndex);
|
||||
}
|
||||
|
||||
PRUnichar nsString2::CharAt(int anIndex) const {
|
||||
PRUnichar nsString2::CharAt(PRUint32 anIndex) const {
|
||||
return GetCharAt(*this,anIndex);
|
||||
}
|
||||
|
||||
@@ -352,10 +316,10 @@ PRBool nsString2::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsString2 nsString2::operator+(const nsStr& aString){
|
||||
nsSubsumeStr nsString2::operator+(const nsStr& aString){
|
||||
nsString2 temp(*this); //make a temp string the same size as this...
|
||||
nsStr::Append(temp,aString,0,aString.mLength,mAgent);
|
||||
return temp;
|
||||
return nsSubsumeStr(temp);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -364,10 +328,10 @@ nsString2 nsString2::operator+(const nsStr& aString){
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsString2 nsString2::operator+(const nsString2& aString){
|
||||
nsSubsumeStr nsString2::operator+(const nsString2& aString){
|
||||
nsString2 temp(*this); //make a temp string the same size as this...
|
||||
nsStr::Append(temp,aString,0,aString.mLength,mAgent);
|
||||
return temp;
|
||||
return nsSubsumeStr(temp);
|
||||
}
|
||||
|
||||
|
||||
@@ -377,10 +341,10 @@ nsString2 nsString2::operator+(const nsString2& aString){
|
||||
* @param aCString is a ptr to cstring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 nsString2::operator+(const char* aCString) {
|
||||
nsSubsumeStr nsString2::operator+(const char* aCString) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(aCString);
|
||||
return temp;
|
||||
return nsSubsumeStr(temp);
|
||||
}
|
||||
|
||||
|
||||
@@ -390,10 +354,10 @@ nsString2 nsString2::operator+(const char* aCString) {
|
||||
* @param aChar is a char to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 nsString2::operator+(char aChar) {
|
||||
nsSubsumeStr nsString2::operator+(char aChar) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(char(aChar));
|
||||
return temp;
|
||||
return nsSubsumeStr(temp);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -402,10 +366,10 @@ nsString2 nsString2::operator+(char aChar) {
|
||||
* @param aString is a ptr to unistring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 nsString2::operator+(const PRUnichar* aString) {
|
||||
nsSubsumeStr nsString2::operator+(const PRUnichar* aString) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(aString);
|
||||
return temp;
|
||||
return nsSubsumeStr(temp);
|
||||
}
|
||||
|
||||
|
||||
@@ -415,10 +379,10 @@ nsString2 nsString2::operator+(const PRUnichar* aString) {
|
||||
* @param aChar is a unichar to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 nsString2::operator+(PRUnichar aChar) {
|
||||
nsSubsumeStr nsString2::operator+(PRUnichar aChar) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(char(aChar));
|
||||
return temp;
|
||||
return nsSubsumeStr(temp);
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
@@ -429,6 +393,7 @@ nsString2 nsString2::operator+(PRUnichar aChar) {
|
||||
* Converts all chars in given string to UCS2
|
||||
*/
|
||||
void nsString2::ToUCS2(PRUint32 aStartOffset){
|
||||
static CTableConstructor gTableConstructor;
|
||||
if(aStartOffset<mLength){
|
||||
if(mMultibyte) {
|
||||
PRUint32 theIndex=0;
|
||||
@@ -621,11 +586,11 @@ PRUnichar* nsString2::ToNewUnicode() const {
|
||||
*/
|
||||
char* nsString2::ToCString(char* aBuf, PRUint32 aBufLength) const{
|
||||
if(aBuf) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mStr=aBuf;
|
||||
theTempStr.mCapacity=aBufLength;
|
||||
nsStr::Assign(theTempStr,*this,0,mLength,mAgent);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mStr=aBuf;
|
||||
temp.mCapacity=aBufLength;
|
||||
nsStr::Assign(temp,*this,0,mLength,mAgent);
|
||||
}
|
||||
return aBuf;
|
||||
}
|
||||
@@ -800,15 +765,19 @@ nsString2& nsString2::Assign(PRUnichar aChar) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies contents of this onto given string.
|
||||
* @update gess 7/27/98
|
||||
* @param aString to hold copy of this
|
||||
* @return nada.
|
||||
* WARNING! THIS IS A VERY SPECIAL METHOD.
|
||||
* This method "steals" the contents of aSource and hands it to aDest.
|
||||
* Ordinarily a copy is made, but not in this version.
|
||||
* @update gess10/30/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void nsString2::Copy(nsString2& aString) const{
|
||||
aString.SetString(*this);
|
||||
nsString2& nsString2::operator=(nsSubsumeStr& aSubsumeString) {
|
||||
Subsume(*this,aSubsumeString);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @update gess 01/04/99
|
||||
@@ -843,12 +812,12 @@ nsString2& nsString2::Append(const nsString2& aString,PRInt32 aCount) {
|
||||
*/
|
||||
nsString2& nsString2::Append(const char* aCString,PRInt32 aCount) {
|
||||
if(aCString){
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eOneByte);
|
||||
theTemp.mStr=(char*)aCString;
|
||||
theTemp.mLength=nsCRT::strlen(aCString);
|
||||
if(-1==aCount) aCount=theTemp.mLength;
|
||||
nsStr::Append(*this,theTemp,0,aCount,mAgent);
|
||||
nsStr temp;
|
||||
Initialize(temp,eOneByte);
|
||||
temp.mStr=(char*)aCString;
|
||||
temp.mLength=nsCRT::strlen(aCString);
|
||||
if(-1==aCount) aCount=temp.mLength;
|
||||
nsStr::Append(*this,temp,0,aCount,mAgent);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -862,12 +831,12 @@ nsString2& nsString2::Append(const char* aCString,PRInt32 aCount) {
|
||||
*/
|
||||
nsString2& nsString2::Append(const PRUnichar* aString,PRInt32 aCount) {
|
||||
if(aString){
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eTwoByte);
|
||||
theTemp.mUStr=(PRUnichar*)aString;
|
||||
theTemp.mLength=nsCRT::strlen(aString);
|
||||
if(-1==aCount) aCount=theTemp.mLength;
|
||||
nsStr::Append(*this,theTemp,0,aCount,mAgent);
|
||||
nsStr temp;
|
||||
Initialize(temp,eTwoByte);
|
||||
temp.mUStr=(PRUnichar*)aString;
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
if(-1==aCount) aCount=temp.mLength;
|
||||
nsStr::Append(*this,temp,0,aCount,mAgent);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -882,11 +851,11 @@ nsString2& nsString2::Append(char aChar) {
|
||||
char buf[2]={0,0};
|
||||
buf[0]=aChar;
|
||||
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eOneByte);
|
||||
theTemp.mStr=buf;
|
||||
theTemp.mLength=1;
|
||||
nsStr::Append(*this,theTemp,0,1,mAgent);
|
||||
nsStr temp;
|
||||
Initialize(temp,eOneByte);
|
||||
temp.mStr=buf;
|
||||
temp.mLength=1;
|
||||
nsStr::Append(*this,temp,0,1,mAgent);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -900,11 +869,11 @@ nsString2& nsString2::Append(PRUnichar aChar) {
|
||||
PRUnichar buf[2]={0,0};
|
||||
buf[0]=aChar;
|
||||
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eTwoByte);
|
||||
theTemp.mUStr=buf;
|
||||
theTemp.mLength=1;
|
||||
nsStr::Append(*this,theTemp,0,1,mAgent);
|
||||
nsStr temp;
|
||||
Initialize(temp,eTwoByte);
|
||||
temp.mUStr=buf;
|
||||
temp.mLength=1;
|
||||
nsStr::Append(*this,temp,0,1,mAgent);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -1001,7 +970,7 @@ PRUint32 nsString2::Right(nsString2& aCopy,PRInt32 aCount) const{
|
||||
* @param aCount -- number of chars to be copied from aCopy
|
||||
* @return number of chars inserted into this.
|
||||
*/
|
||||
nsString2& nsString2::Insert(nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount) {
|
||||
nsString2& nsString2::Insert(const nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount) {
|
||||
nsStr::Insert(*this,anOffset,aCopy,0,aCount,mAgent);
|
||||
return *this;
|
||||
}
|
||||
@@ -1018,12 +987,12 @@ nsString2& nsString2::Insert(nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount)
|
||||
nsString2& nsString2::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCount){
|
||||
if(aCString){
|
||||
if(0<aCount) {
|
||||
nsStr theTemp;
|
||||
nsStr::Initialize(theTemp,eOneByte);
|
||||
theTemp.mStr=(char*)aCString;
|
||||
theTemp.mLength=nsCRT::strlen(aCString);
|
||||
if(theTemp.mLength){
|
||||
nsStr::Insert(*this,anOffset,theTemp,0,aCount,0);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mStr=(char*)aCString;
|
||||
temp.mLength=nsCRT::strlen(aCString);
|
||||
if(temp.mLength){
|
||||
nsStr::Insert(*this,anOffset,temp,0,aCount,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1044,11 +1013,11 @@ nsString2& nsString2::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCou
|
||||
nsString2& nsString2::Insert(char aChar,PRUint32 anOffset){
|
||||
char theBuffer[2]={0,0};
|
||||
theBuffer[0]=aChar;
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mStr=(char*)theBuffer;
|
||||
theTempStr.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,theTempStr,0,1,0);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mStr=(char*)theBuffer;
|
||||
temp.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,temp,0,1,0);
|
||||
return *this;
|
||||
}
|
||||
*/
|
||||
@@ -1065,12 +1034,12 @@ nsString2& nsString2::Insert(char aChar,PRUint32 anOffset){
|
||||
nsString2& nsString2::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32 aCount){
|
||||
if(aString){
|
||||
if(0<aCount) {
|
||||
nsStr theTemp;
|
||||
nsStr::Initialize(theTemp,eTwoByte);
|
||||
theTemp.mUStr=(PRUnichar*)aString;
|
||||
theTemp.mLength=nsCRT::strlen(aString);
|
||||
if(theTemp.mLength){
|
||||
nsStr::Insert(*this,anOffset,theTemp,0,aCount,0);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eTwoByte);
|
||||
temp.mUStr=(PRUnichar*)aString;
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
if(temp.mLength){
|
||||
nsStr::Insert(*this,anOffset,temp,0,aCount,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1090,11 +1059,11 @@ nsString2& nsString2::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32
|
||||
nsString2& nsString2::Insert(PRUnichar aChar,PRUint32 anOffset){
|
||||
PRUnichar theBuffer[2]={0,0};
|
||||
theBuffer[0]=aChar;
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mUStr=theBuffer;
|
||||
theTempStr.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,theTempStr,0,1,0);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eTwoByte);
|
||||
temp.mUStr=theBuffer;
|
||||
temp.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,temp,0,1,0);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -1153,11 +1122,11 @@ PRInt32 nsString2::Find(const char* aCString,PRBool aIgnoreCase) const{
|
||||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aCString) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCString);
|
||||
theTempStr.mStr=(char*)aCString;
|
||||
result=nsStr::FindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCString);
|
||||
temp.mStr=(char*)aCString;
|
||||
result=nsStr::FindSubstr(*this,temp,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1174,11 +1143,11 @@ PRInt32 nsString2::Find(const PRUnichar* aString,PRBool aIgnoreCase) const{
|
||||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aString) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mUStr=(PRUnichar*)aString;
|
||||
result=nsStr::FindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eTwoByte);
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
temp.mUStr=(PRUnichar*)aString;
|
||||
result=nsStr::FindSubstr(*this,temp,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1195,6 +1164,18 @@ PRInt32 nsString2::Find(const nsStr& aString,PRBool aIgnoreCase) const{
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for given buffer within this string
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param nsString2 -- buffer to be found
|
||||
* @return offset in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 nsString2::Find(const nsString2& aString,PRBool aIgnoreCase) const{
|
||||
PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,0);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for a given char, starting at given offset
|
||||
*
|
||||
@@ -1219,11 +1200,11 @@ PRInt32 nsString2::FindCharInSet(const char* aCStringSet,PRUint32 anOffset) cons
|
||||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aCStringSet) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCStringSet);
|
||||
theTempStr.mStr=(char*)aCStringSet;
|
||||
result=nsStr::FindCharInSet(*this,theTempStr,PR_FALSE,anOffset);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCStringSet);
|
||||
temp.mStr=(char*)aCStringSet;
|
||||
result=nsStr::FindCharInSet(*this,temp,PR_FALSE,anOffset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1252,11 +1233,11 @@ PRInt32 nsString2::RFindCharInSet(const char* aCStringSet,PRUint32 anOffset) con
|
||||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aCStringSet) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCStringSet);
|
||||
theTempStr.mStr=(char*)aCStringSet;
|
||||
result=nsStr::RFindCharInSet(*this,theTempStr,PR_FALSE,anOffset);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCStringSet);
|
||||
temp.mStr=(char*)aCStringSet;
|
||||
result=nsStr::RFindCharInSet(*this,temp,PR_FALSE,anOffset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1285,6 +1266,18 @@ PRInt32 nsString2::RFind(const nsStr& aString,PRBool aIgnoreCase) const{
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsString2::RFind(const nsString2& aString,PRBool aIgnoreCase) const{
|
||||
PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,0);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
@@ -1297,11 +1290,11 @@ PRInt32 nsString2::RFind(const char* aString,PRBool aIgnoreCase) const{
|
||||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aString) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mStr=(char*)aString;
|
||||
result=nsStr::RFindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
temp.mStr=(char*)aString;
|
||||
result=nsStr::RFindSubstr(*this,temp,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1334,11 +1327,11 @@ PRInt32 nsString2::Compare(const char *aCString,PRBool aIgnoreCase,PRInt32 aLeng
|
||||
NS_ASSERTION(0!=aCString,kNullPointerError);
|
||||
|
||||
if(aCString) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCString);
|
||||
theTempStr.mStr=(char*)aCString;
|
||||
return nsStr::Compare(*this,theTempStr,aLength,aIgnoreCase);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCString);
|
||||
temp.mStr=(char*)aCString;
|
||||
return nsStr::Compare(*this,temp,aLength,aIgnoreCase);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1354,11 +1347,11 @@ PRInt32 nsString2::Compare(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 a
|
||||
NS_ASSERTION(0!=aString,kNullPointerError);
|
||||
|
||||
if(aString) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mUStr=(PRUnichar*)aString;
|
||||
return nsStr::Compare(*this,theTempStr,aLength,aIgnoreCase);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eTwoByte);
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
temp.mUStr=(PRUnichar*)aString;
|
||||
return nsStr::Compare(*this,temp,aLength,aIgnoreCase);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1568,16 +1561,37 @@ PRBool nsString2::IsDigit(PRUnichar aChar) {
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Define the string deallocator class...
|
||||
**************************************************************/
|
||||
class nsStringDeallocator: public nsDequeFunctor{
|
||||
public:
|
||||
virtual void* operator()(void* anObject) {
|
||||
static nsMemoryAgent theAgent;
|
||||
nsString2* aString= (nsString2*)anObject;
|
||||
if(aString){
|
||||
aString->mAgent=&theAgent;
|
||||
delete aString;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* This class, appropriately enough, creates and recycles nsString2 objects..
|
||||
****************************************************************************/
|
||||
|
||||
#if 0
|
||||
|
||||
class nsStringRecycler {
|
||||
public:
|
||||
nsStringRecycler() : mDeque(0) {
|
||||
}
|
||||
|
||||
~nsStringRecycler() {
|
||||
nsStringDeallocator theDeallocator;
|
||||
mDeque.ForEach(theDeallocator); //now delete the strings
|
||||
}
|
||||
|
||||
void Recycle(nsString2* aString) {
|
||||
mDeque.Push(aString);
|
||||
}
|
||||
@@ -1623,7 +1637,6 @@ void nsString2::Recycle(nsString2* aString){
|
||||
GetRecycler().Recycle(aString);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -1690,14 +1703,12 @@ NS_BASE int fputs(const nsString2& aString, FILE* out)
|
||||
*/
|
||||
void nsString2::SelfTest(void) {
|
||||
|
||||
#if 0
|
||||
#ifdef NS_DEBUG
|
||||
static const char* kConstructorError = kConstructorError;
|
||||
static const char* kComparisonError = "Comparision error!";
|
||||
static const char* kEqualsError = "Equals error!";
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
mSelfTested=PR_TRUE;
|
||||
#endif
|
||||
|
||||
eCharSize theSize=eOneByte;
|
||||
|
||||
@@ -1705,8 +1716,18 @@ void nsString2::SelfTest(void) {
|
||||
{
|
||||
{
|
||||
nsString2 theString0("foo",theSize); //watch it construct and destruct
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
nsString2 theString("hello");
|
||||
nsString2 temp1=theString+" there!";
|
||||
nsString2 temp2=theString+'!';
|
||||
nsSubsumeStr temp3=theString+'?';
|
||||
nsString2 temp4(temp3);
|
||||
temp1=temp3;
|
||||
nsSubsumeStr temp5("hello");
|
||||
}
|
||||
|
||||
nsString2 theString1(theSize);
|
||||
nsString2 theString("hello",theSize);
|
||||
nsString2 theString3(theString,theSize);
|
||||
@@ -1721,6 +1742,8 @@ void nsString2::SelfTest(void) {
|
||||
//while we're here, let's try truncation and setting the length.
|
||||
theString3.Truncate(3);
|
||||
theLen=theString3.Length();
|
||||
|
||||
|
||||
theString.SetCapacity(3);
|
||||
const char* theBuffer=theString.GetBuffer();
|
||||
const char* theOther=theBuffer;
|
||||
@@ -1736,12 +1759,17 @@ void nsString2::SelfTest(void) {
|
||||
theString5.StripWhitespace();
|
||||
|
||||
nsString2* theString6=theString5.ToNewString();
|
||||
nsString2::Recycle(theString6);
|
||||
|
||||
char* str=theString5.ToNewCString();
|
||||
delete [] str;
|
||||
|
||||
char buffer[100];
|
||||
theString5.ToCString(buffer,sizeof(buffer)-1);
|
||||
theOther=theString5.GetBuffer();
|
||||
}
|
||||
//try a few numeric conversion routines...
|
||||
|
||||
//try a few numeric conversion routines...
|
||||
{
|
||||
nsString2 str1("10000",theSize);
|
||||
PRInt32 err;
|
||||
@@ -1753,11 +1781,12 @@ void nsString2::SelfTest(void) {
|
||||
{
|
||||
nsString2 theString("hello",theSize);
|
||||
PRUint32 len=theString.Length();
|
||||
PRUnichar ch;
|
||||
for(PRUint32 i=0;i<len;i++) {
|
||||
PRUnichar ch3=theString.CharAt(i);
|
||||
ch=theString.CharAt(i);
|
||||
}
|
||||
PRUnichar ch4=theString.First();
|
||||
PRUnichar ch5=theString.Last();
|
||||
ch=theString.First();
|
||||
ch=theString.Last();
|
||||
}
|
||||
|
||||
//**********************************************
|
||||
@@ -1826,7 +1855,6 @@ void nsString2::SelfTest(void) {
|
||||
temp1.Right(temp2,4);
|
||||
}
|
||||
|
||||
|
||||
//**********************************************
|
||||
//Now let's test the INSERTION methods...
|
||||
//**********************************************
|
||||
@@ -1973,6 +2001,15 @@ void nsString2::SelfTest(void) {
|
||||
pos=find1.BinarySearch('i');
|
||||
pos=find1.BinarySearch('z');
|
||||
}
|
||||
|
||||
{
|
||||
//now let's try a memory allocation test...
|
||||
nsString2 temp;
|
||||
for(int i=0;i<100;i++){
|
||||
temp+="hello ";
|
||||
}
|
||||
int x=5;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1981,14 +2018,6 @@ void nsString2::SelfTest(void) {
|
||||
IMPLEMENTATION NOTES: AUTOSTRING...
|
||||
***********************************************************************/
|
||||
|
||||
void InitAutoStr(nsAutoString2& aDest,nsBufDescriptor& aBufDescriptor){
|
||||
aDest.mAgent=0;
|
||||
aDest.mStr=aBufDescriptor.mStr;
|
||||
aDest.mMultibyte=aBufDescriptor.mMultibyte;
|
||||
aDest.mCapacity=(sizeof(aDest.mBuffer)>>aDest.mMultibyte)-1;
|
||||
aDest.mOwnsBuffer=aBufDescriptor.mOwnsBuffer;
|
||||
AddNullTerminator(aDest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Special case constructor, that allows the consumer to provide
|
||||
@@ -1998,8 +2027,9 @@ void InitAutoStr(nsAutoString2& aDest,nsBufDescriptor& aBufDescriptor){
|
||||
* @param aCurrentLength tells us the current length of the buffer
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(eCharSize aCharSize) : nsString2(aCharSize){
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
mAgent=0;
|
||||
AddNullTerminator(*this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2007,8 +2037,10 @@ nsAutoString2::nsAutoString2(eCharSize aCharSize) : nsString2(aCharSize){
|
||||
* @param anExtBuffer describes an external buffer
|
||||
* @param aCString is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(nsBufDescriptor& aBufDescriptor,const char* aCString) : nsString2(aBufDescriptor.mMultibyte) {
|
||||
InitAutoStr(*this,aBufDescriptor);
|
||||
nsAutoString2::nsAutoString2(nsStr& aStr,const char* aCString) : nsString2(aStr.mMultibyte) {
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aStr.mMultibyte)-1,0,aStr.mMultibyte,PR_FALSE);
|
||||
mAgent=0;
|
||||
AddNullTerminator(*this);
|
||||
Assign(aCString);
|
||||
}
|
||||
|
||||
@@ -2017,8 +2049,9 @@ nsAutoString2::nsAutoString2(nsBufDescriptor& aBufDescriptor,const char* aCStrin
|
||||
* @param aCString is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const char* aCString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
mAgent=0;
|
||||
AddNullTerminator(*this);
|
||||
Assign(aCString);
|
||||
}
|
||||
|
||||
@@ -2026,15 +2059,15 @@ nsAutoString2::nsAutoString2(const char* aCString,eCharSize aCharSize) : nsStrin
|
||||
* Copy construct from ascii c-string
|
||||
* @param aCString is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(char* aCString,PRUint32 aLen,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
nsAutoString2::nsAutoString2(char* aCString,PRUint32 aCapacity,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
mAgent=0;
|
||||
if(assumeOwnership) {
|
||||
nsBufDescriptor theDescriptor(aCString,aLen,eOneByte,PR_TRUE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
nsStr::Initialize(*this,aCString,aCapacity,0,eOneByte,PR_TRUE);
|
||||
}
|
||||
else {
|
||||
nsBufDescriptor theDescriptor(mBuffer,aLen,aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
}
|
||||
AddNullTerminator(*this);
|
||||
Assign(aCString);
|
||||
}
|
||||
|
||||
@@ -2043,8 +2076,9 @@ nsAutoString2::nsAutoString2(char* aCString,PRUint32 aLen,eCharSize aCharSize,PR
|
||||
* @param aString is a ptr to a unistr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const PRUnichar* aString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
@@ -2052,15 +2086,15 @@ nsAutoString2::nsAutoString2(const PRUnichar* aString,eCharSize aCharSize) : nsS
|
||||
* Copy construct from uni-string
|
||||
* @param aString is a ptr to a unistr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(PRUnichar* aString,PRUint32 aLength,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
nsAutoString2::nsAutoString2(PRUnichar* aString,PRUint32 aCapacity,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
mAgent=0;
|
||||
if(assumeOwnership) {
|
||||
nsBufDescriptor theDescriptor((char*)aString,aLength,eTwoByte,PR_TRUE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
nsStr::Initialize(*this,(char*)aString,aCapacity,0,eTwoByte,PR_TRUE);
|
||||
}
|
||||
else {
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
}
|
||||
AddNullTerminator(*this);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
@@ -2070,8 +2104,9 @@ nsAutoString2::nsAutoString2(PRUnichar* aString,PRUint32 aLength,eCharSize aChar
|
||||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const nsStr& aString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
@@ -2080,8 +2115,9 @@ nsAutoString2::nsAutoString2(const nsStr& aString,eCharSize aCharSize) : nsStrin
|
||||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const nsAutoString2& aString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
@@ -2090,8 +2126,9 @@ nsAutoString2::nsAutoString2(const nsAutoString2& aString,eCharSize aCharSize) :
|
||||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const nsString2& aString,eCharSize aCharSize) : nsString2(aCharSize){
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
@@ -2101,11 +2138,22 @@ nsAutoString2::nsAutoString2(const nsString2& aString,eCharSize aCharSize) : nsS
|
||||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(PRUnichar aChar,eCharSize aCharSize) : nsString2(aCharSize){
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
Assign(aChar);
|
||||
}
|
||||
|
||||
/**
|
||||
* construct from a subsumeable string
|
||||
* @update gess 1/4/99
|
||||
* @param reference to a subsumeString
|
||||
*/
|
||||
nsAutoString2::nsAutoString2( nsSubsumeStr& aSubsumeStr) :nsString2(aSubsumeStr.mMultibyte) {
|
||||
mAgent=0;
|
||||
Subsume(*this,aSubsumeStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* deconstruct the autstring
|
||||
* @param
|
||||
@@ -2120,3 +2168,16 @@ void nsAutoString2::SizeOf(nsISizeOfHandler* aHandler) const {
|
||||
aHandler->Add(mCapacity << mMultibyte);
|
||||
}
|
||||
|
||||
nsSubsumeStr::nsSubsumeStr(nsString2& aString) : nsString2() {
|
||||
Subsume(*this,aString);
|
||||
}
|
||||
|
||||
nsSubsumeStr::nsSubsumeStr(nsStr& aString) : nsString2() {
|
||||
Subsume(*this,aString);
|
||||
}
|
||||
|
||||
nsSubsumeStr::nsSubsumeStr(const PRUnichar* aString) : nsString2(aString,eTwoByte) {
|
||||
}
|
||||
|
||||
nsSubsumeStr::nsSubsumeStr(const char* aString) : nsString2(aString,eOneByte) {
|
||||
}
|
||||
|
||||
@@ -20,18 +20,19 @@
|
||||
/***********************************************************************
|
||||
MODULE NOTES:
|
||||
|
||||
This class provides a 1-byte ASCII string implementation that shares
|
||||
a common API with all other strImpl derivatives.
|
||||
This version of the nsString class offers many improvements over the
|
||||
original version:
|
||||
1. Wide and narrow chars
|
||||
2. Allocators
|
||||
3. Much smarter autostrings
|
||||
4. Subsumable strings
|
||||
5. Memory pools and recycling
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef _nsString2
|
||||
#define _nsString2
|
||||
|
||||
//#define nsString2 nsString
|
||||
//#define nsAutoString2 nsAutoString
|
||||
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nscore.h"
|
||||
#include <iostream.h>
|
||||
@@ -46,6 +47,13 @@
|
||||
class nsISizeOfHandler;
|
||||
|
||||
|
||||
#ifdef USE_STRING2
|
||||
#define nsString2 nsString
|
||||
#define nsAutoString2 nsAutoString
|
||||
#endif
|
||||
|
||||
class NS_BASE nsSubsumeStr;
|
||||
|
||||
class NS_BASE nsString2 : public nsStr {
|
||||
|
||||
public:
|
||||
@@ -83,6 +91,12 @@ nsString2(const nsStr&,eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAg
|
||||
*/
|
||||
nsString2(const nsString2& aString);
|
||||
|
||||
/**
|
||||
* This constructor takes a subsumestr
|
||||
* @param reference to subsumestr
|
||||
*/
|
||||
nsString2(nsSubsumeStr& aSubsumeStr);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*
|
||||
@@ -139,16 +153,15 @@ PRBool IsOrdered(void) const;
|
||||
Accessor methods...
|
||||
*********************************************************************/
|
||||
|
||||
char* GetBuffer(void) const;
|
||||
PRUnichar* GetUnicode(void) const;
|
||||
operator PRUnichar*() const {return GetUnicode();}
|
||||
const char* GetBuffer(void) const;
|
||||
const PRUnichar* GetUnicode(void) const;
|
||||
|
||||
|
||||
/**
|
||||
* Get nth character.
|
||||
*/
|
||||
PRUnichar operator[](int anIndex) const;
|
||||
PRUnichar CharAt(int anIndex) const;
|
||||
PRUnichar operator[](PRUint32 anIndex) const;
|
||||
PRUnichar CharAt(PRUint32 anIndex) const;
|
||||
PRUnichar First(void) const;
|
||||
PRUnichar Last(void) const;
|
||||
|
||||
@@ -164,42 +177,42 @@ PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsString2 operator+(const nsStr& aString);
|
||||
nsSubsumeStr operator+(const nsStr& aString);
|
||||
|
||||
/**
|
||||
* Create a new string by appending given string to this
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsString2 operator+(const nsString2& aString);
|
||||
nsSubsumeStr operator+(const nsString2& aString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given buffer.
|
||||
* @param aCString is a ptr to cstring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 operator+(const char* aCString);
|
||||
nsSubsumeStr operator+(const char* aCString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given wide buffer.
|
||||
* @param aString is a ptr to UC-string to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 operator+(const PRUnichar* aString);
|
||||
nsSubsumeStr operator+(const PRUnichar* aString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given char.
|
||||
* @param aChar is a char to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 operator+(char aChar);
|
||||
nsSubsumeStr operator+(char aChar);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given char.
|
||||
* @param aChar is a unichar to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 operator+(PRUnichar aChar);
|
||||
nsSubsumeStr operator+(PRUnichar aChar);
|
||||
|
||||
/**********************************************************************
|
||||
Lexomorphic transforms...
|
||||
@@ -353,7 +366,6 @@ PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=10) const;
|
||||
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);}
|
||||
void Copy(nsString2& aString) const;
|
||||
|
||||
/**
|
||||
* assign given string to this string
|
||||
@@ -380,6 +392,7 @@ 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);}
|
||||
nsString2& operator=(nsSubsumeStr& aSubsumeString);
|
||||
|
||||
/**
|
||||
* Here's a bunch of append mehtods for varying types...
|
||||
@@ -402,8 +415,7 @@ nsString2& operator+=(PRUnichar aChar){return Append(aChar);}
|
||||
*/
|
||||
nsString2& Append(const nsStr& aString) {return Append(aString,aString.mLength);}
|
||||
nsString2& Append(const nsString2& aString) {return Append(aString,aString.mLength);}
|
||||
nsString2& Append(const char* aString) {if(aString) {Append(aString,nsCRT::strlen(aString));} return *this;}
|
||||
nsString2& Append(const PRUnichar* aString) {if(aString) {Append(aString,nsCRT::strlen(aString));} return *this;}
|
||||
|
||||
|
||||
/*
|
||||
* Appends n characters from given string to this,
|
||||
@@ -414,13 +426,13 @@ nsString2& Append(const PRUnichar* aString) {if(aString) {Append(aString,nsCRT::
|
||||
*/
|
||||
nsString2& Append(const nsStr& aString,PRInt32 aCount);
|
||||
nsString2& Append(const nsString2& aString,PRInt32 aCount);
|
||||
nsString2& Append(const char* aString,PRInt32 aCount);
|
||||
nsString2& Append(const PRUnichar* 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,
|
||||
* starting at the leftmost offset.
|
||||
@@ -464,7 +476,7 @@ PRUint32 Right(nsString2& aCopy,PRInt32 aCount) const;
|
||||
* @param aCount -- number of chars to be copied from aCopy
|
||||
* @return number of chars inserted into this.
|
||||
*/
|
||||
nsString2& Insert(nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
|
||||
nsString2& Insert(const nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
|
||||
|
||||
/**
|
||||
* Insert a given string into this string at
|
||||
@@ -519,6 +531,7 @@ PRInt32 BinarySearch(PRUnichar aChar) const;
|
||||
* @param aString is substring to be sought in this
|
||||
* @return offset 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;
|
||||
@@ -554,6 +567,7 @@ PRInt32 RFindCharInSet(const nsString2& aString,PRUint32 anOffset=0) const;
|
||||
* @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,PRBool aIgnoreCase=PR_FALSE,PRUint32 offset=0) const;
|
||||
@@ -675,10 +689,8 @@ static PRBool IsAlpha(PRUnichar ch);
|
||||
*/
|
||||
static PRBool IsDigit(PRUnichar ch);
|
||||
|
||||
#if 0
|
||||
static void Recycle(nsString2* aString);
|
||||
static nsString2* NewString(eCharSize aCharSize=eTwoByte);
|
||||
#endif
|
||||
|
||||
static void SelfTest();
|
||||
virtual void DebugDump(ostream& aStream) const;
|
||||
@@ -701,12 +713,11 @@ ostream& operator<<(ostream& os,nsString2& aString);
|
||||
If the buffer needs to grow, it gets reallocated on the heap.
|
||||
**************************************************************/
|
||||
|
||||
|
||||
class NS_BASE nsAutoString2 : public nsString2 {
|
||||
public:
|
||||
|
||||
nsAutoString2(eCharSize aCharSize=kDefaultCharSize);
|
||||
nsAutoString2(nsBufDescriptor& anExtBuffer,const char* aCString);
|
||||
nsAutoString2(nsStr& anExtBuffer,const char* aCString);
|
||||
|
||||
|
||||
nsAutoString2(const char* aCString,eCharSize aCharSize=kDefaultCharSize);
|
||||
@@ -717,6 +728,7 @@ public:
|
||||
nsAutoString2(const nsStr& aString,eCharSize aCharSize=kDefaultCharSize);
|
||||
nsAutoString2(const nsString2& aString,eCharSize aCharSize=kDefaultCharSize);
|
||||
nsAutoString2(const nsAutoString2& aString,eCharSize aCharSize=kDefaultCharSize);
|
||||
nsAutoString2(nsSubsumeStr& aSubsumeStr);
|
||||
nsAutoString2(PRUnichar aChar,eCharSize aCharSize=kDefaultCharSize);
|
||||
virtual ~nsAutoString2();
|
||||
|
||||
@@ -738,5 +750,28 @@ public:
|
||||
};
|
||||
|
||||
|
||||
/***************************************************************
|
||||
The subsumestr class is very unusual.
|
||||
It differs from a normal string in that it doesn't use normal
|
||||
copy semantics when another string is assign to this.
|
||||
Instead, it "steals" the contents of the source string.
|
||||
|
||||
This is very handy for returning nsString classes as part of
|
||||
an operator+(...) for example, in that it cuts down the number
|
||||
of copy operations that must occur.
|
||||
|
||||
You should probably not use this class unless you really know
|
||||
what you're doing.
|
||||
***************************************************************/
|
||||
class NS_BASE nsSubsumeStr : public nsString2 {
|
||||
public:
|
||||
nsSubsumeStr(nsString2& aString);
|
||||
nsSubsumeStr(nsStr& aString);
|
||||
nsSubsumeStr(const PRUnichar* aString);
|
||||
nsSubsumeStr(const char* aString);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -31,11 +31,103 @@
|
||||
#include "nsStr.h"
|
||||
#include "bufferRoutines.h"
|
||||
#include "stdio.h" //only used for printf
|
||||
#include "nsDeque.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
|
||||
static const char* kFoolMsg = "Error: Some fool overwrote the shared buffer.";
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// The following is a memory agent who knows how to recycled (pool) freed memory...
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
/**************************************************************
|
||||
Define the char* (pooled) deallocator class...
|
||||
**************************************************************/
|
||||
class nsBufferDeallocator: public nsDequeFunctor{
|
||||
public:
|
||||
virtual void* operator()(void* anObject) {
|
||||
char* aCString= (char*)anObject;
|
||||
delete [] aCString;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess10/30/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
class nsPoolingMemoryAgent : public nsMemoryAgent{
|
||||
public:
|
||||
nsPoolingMemoryAgent() {
|
||||
memset(mPools,0,sizeof(mPools));
|
||||
}
|
||||
|
||||
~nsPoolingMemoryAgent() {
|
||||
nsBufferDeallocator theDeallocator;
|
||||
int i=0;
|
||||
for(i=0;i<10;i++){
|
||||
if(mPools[i]){
|
||||
mPools[i]->ForEach(theDeallocator); //now delete the buffers
|
||||
}
|
||||
delete mPools[i];
|
||||
mPools[i]=0;
|
||||
}
|
||||
}
|
||||
|
||||
virtual PRBool Alloc(nsStr& aDest,PRInt32 aCount) {
|
||||
|
||||
//we're given the acount value in charunits; we have to scale up by the charsize.
|
||||
int theShift=4;
|
||||
PRInt32 theNewCapacity=eDefaultSize;
|
||||
while(theNewCapacity<aCount){
|
||||
theNewCapacity<<=1;
|
||||
theShift++;
|
||||
}
|
||||
|
||||
aDest.mCapacity=theNewCapacity++;
|
||||
theShift=(theShift<<aDest.mMultibyte)-4;
|
||||
if((theShift<12) && (mPools[theShift])){
|
||||
aDest.mStr=(char*)mPools[theShift]->Pop();
|
||||
}
|
||||
if(!aDest.mStr) {
|
||||
//we're given the acount value in charunits; we have to scale up by the charsize.
|
||||
size_t theSize=(theNewCapacity<<aDest.mMultibyte);
|
||||
aDest.mStr=new char[theSize];
|
||||
}
|
||||
aDest.mOwnsBuffer=1;
|
||||
return PR_TRUE;
|
||||
|
||||
}
|
||||
|
||||
virtual PRBool Free(nsStr& aDest){
|
||||
if(aDest.mStr){
|
||||
if(aDest.mOwnsBuffer){
|
||||
int theShift=1;
|
||||
unsigned int theValue=1;
|
||||
while((theValue<<=1)<aDest.mCapacity){
|
||||
theShift++;
|
||||
}
|
||||
theShift-=4;
|
||||
if(theShift<12){
|
||||
if(!mPools[theShift]){
|
||||
mPools[theShift]=new nsDeque(0);
|
||||
}
|
||||
mPools[theShift]->Push(aDest.mStr);
|
||||
}
|
||||
else delete [] aDest.mStr; //it's too big. Just delete it.
|
||||
}
|
||||
aDest.mStr=0;
|
||||
aDest.mOwnsBuffer=0;
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
nsDeque* mPools[16];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -71,6 +163,7 @@ void nsStr::Initialize(nsStr& aDest,eCharSize aCharSize) {
|
||||
aDest.mCapacity=0;
|
||||
aDest.mMultibyte=aCharSize;
|
||||
aDest.mOwnsBuffer=0;
|
||||
aDest.mUnused=0;
|
||||
NS_ASSERTION(aDest.mStr[0]==0,kFoolMsg);
|
||||
}
|
||||
|
||||
@@ -80,14 +173,25 @@ void nsStr::Initialize(nsStr& aDest,eCharSize aCharSize) {
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsIMemoryAgent* GetDefaultAgent(void){
|
||||
static nsIMemoryAgent* gDefaultAgent=0;
|
||||
if(!gDefaultAgent)
|
||||
gDefaultAgent=new nsMemoryAgent();
|
||||
|
||||
NS_ASSERTION(gDefaultAgent,"You MUST always have an allocator!");
|
||||
void nsStr::Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 aLength,eCharSize aCharSize,PRBool aOwnsBuffer){
|
||||
aDest.mStr=(aCString) ? aCString : GetSharedEmptyBuffer();
|
||||
aDest.mLength=aLength;
|
||||
aDest.mCapacity=aCapacity;
|
||||
aDest.mMultibyte=aCharSize;
|
||||
aDest.mOwnsBuffer=aOwnsBuffer;
|
||||
aDest.mUnused=0;
|
||||
}
|
||||
|
||||
return gDefaultAgent;
|
||||
/**
|
||||
*
|
||||
* @update gess10/30/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsIMemoryAgent* GetDefaultAgent(void){
|
||||
// static nsPoolingMemoryAgent gDefaultAgent;
|
||||
static nsMemoryAgent gDefaultAgent;
|
||||
return (nsIMemoryAgent*)&gDefaultAgent;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,20 +214,6 @@ void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess11/12/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRUnichar nsStr::GetCharAt(const nsStr& aDest,PRUint32 anIndex) {
|
||||
PRUnichar result=0;
|
||||
if((anIndex>=0) && (anIndex<aDest.mLength)) {
|
||||
result=(eTwoByte==aDest.mMultibyte) ? aDest.mUStr[anIndex] : aDest.mStr[anIndex];
|
||||
}//if
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method gets called when the internal buffer needs
|
||||
@@ -155,8 +245,8 @@ void nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAgen
|
||||
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
|
||||
EnsureCapacity(theTempStr,aNewLength,theAgent);
|
||||
|
||||
if(0<aDest.mLength) {
|
||||
Append(theTempStr,aDest,0,aDest.mLength,anAgent);
|
||||
if(aDest.mLength) {
|
||||
Append(theTempStr,aDest,0,aDest.mLength,theAgent);
|
||||
}
|
||||
theAgent->Free(aDest);
|
||||
aDest.mStr = theTempStr.mStr;
|
||||
@@ -182,13 +272,12 @@ void nsStr::Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 a
|
||||
/**
|
||||
* This method appends the given nsStr to this one. Note that we have to
|
||||
* pay attention to the underlying char-size of both structs.
|
||||
* @update gess 04/04/99
|
||||
* @update gess10/30/98
|
||||
* @param aDest is the nsStr to be manipulated
|
||||
* @param aSource is where char are copied from
|
||||
* @aCount is the number of bytes to be copied
|
||||
*/
|
||||
void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){
|
||||
|
||||
if(anOffset<aSource.mLength){
|
||||
PRUint32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
|
||||
PRUint32 theLength=(anOffset+theRealLen<aSource.mLength) ? theRealLen : (aSource.mLength-anOffset);
|
||||
@@ -221,30 +310,30 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin
|
||||
// 1. You're inserting chars into an empty string (assign)
|
||||
// 2. You're inserting onto the end of a string (append)
|
||||
// 3. You're inserting onto the 1..n-1 pos of a string (the hard case).
|
||||
if((0<aSource.mLength) && (aDestOffset<aDest.mLength-1)){
|
||||
if(0<aSource.mLength){
|
||||
ToRange(aDestOffset,0,aDest.mLength);
|
||||
if(aDest.mLength){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
if(aSrcOffset<aSource.mLength-1) {
|
||||
PRInt32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
|
||||
PRInt32 theLength=(aSrcOffset+theRealLen<aSource.mLength) ? theRealLen : (aSource.mLength-aSrcOffset);
|
||||
//ToRange(aSrcOffset,0,aSource.mLength-1);
|
||||
PRInt32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
|
||||
PRInt32 theLength=(aSrcOffset+theRealLen<aSource.mLength) ? theRealLen : (aSource.mLength-aSrcOffset);
|
||||
|
||||
if(aSrcOffset<aSource.mLength) {
|
||||
//here's the only new case we have to handle.
|
||||
//chars are really being inserted into our buffer...
|
||||
GrowCapacity(aDest,aDest.mLength+theLength,anAgent);
|
||||
if(aSrcOffset<aSource.mLength) {
|
||||
//here's the only new case we have to handle.
|
||||
//chars are really being inserted into our buffer...
|
||||
GrowCapacity(aDest,aDest.mLength+theLength,anAgent);
|
||||
|
||||
//shift the chars right by theDelta...
|
||||
(*gShiftChars[aDest.mMultibyte][PR_TRUE])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
|
||||
//shift the chars right by theDelta...
|
||||
(*gShiftChars[aDest.mMultibyte][PR_TRUE])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
|
||||
|
||||
//now insert new chars, starting at offset
|
||||
(*gCopyChars[aSource.mMultibyte][aDest.mMultibyte])(aDest.mStr,aDestOffset,aSource.mStr,aSrcOffset,theLength);
|
||||
//now insert new chars, starting at offset
|
||||
(*gCopyChars[aSource.mMultibyte][aDest.mMultibyte])(aDest.mStr,aDestOffset,aSource.mStr,aSrcOffset,theLength);
|
||||
|
||||
//finally, make sure to update the string length...
|
||||
aDest.mLength+=theLength;
|
||||
//finally, make sure to update the string length...
|
||||
aDest.mLength+=theLength;
|
||||
|
||||
}//if
|
||||
//else nothing to do!
|
||||
}
|
||||
}//if
|
||||
//else nothing to do!
|
||||
}
|
||||
else Append(aDest,aSource,0,aCount,anAgent);
|
||||
}
|
||||
@@ -260,22 +349,20 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin
|
||||
* @param aDestOffset is where in aDest deletion is to occur
|
||||
* @param aCount is the number of chars to be deleted in aDest
|
||||
*/
|
||||
void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){
|
||||
if(0<aCount){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAgent* anAgent){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
|
||||
PRInt32 theDelta=aDest.mLength-aDestOffset;
|
||||
PRInt32 theLength=(theDelta<aCount) ? theDelta : aCount;
|
||||
PRUint32 theDelta=aDest.mLength-aDestOffset;
|
||||
PRUint32 theLength=(theDelta<aCount) ? theDelta : aCount;
|
||||
|
||||
if(aDestOffset+theLength<aDest.mLength) {
|
||||
if(aDestOffset+theLength<aDest.mLength) {
|
||||
|
||||
//if you're here, it means we're cutting chars out of the middle of the string...
|
||||
//so shift the chars left by theLength...
|
||||
(*gShiftChars[aDest.mMultibyte][PR_FALSE])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
|
||||
aDest.mLength-=theLength;
|
||||
}
|
||||
else Truncate(aDest,aDestOffset,anAgent);
|
||||
}//if
|
||||
//if you're here, it means we're cutting chars out of the middle of the string...
|
||||
//so shift the chars left by theLength...
|
||||
(*gShiftChars[aDest.mMultibyte][PR_FALSE])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
|
||||
aDest.mLength-=theLength;
|
||||
}
|
||||
else Truncate(aDest,aDestOffset,anAgent);
|
||||
}//if
|
||||
}
|
||||
|
||||
@@ -343,28 +430,28 @@ void nsStr::CompressSet(nsStr& aDest,const char* aSet,PRUint32 aChar,PRBool aEli
|
||||
**************************************************************/
|
||||
|
||||
|
||||
PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool /*aIgnoreCase*/,PRUint32 anOffset) {
|
||||
PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 index=anOffset-1;
|
||||
PRInt32 theMax=aDest.mLength-aTarget.mLength;
|
||||
if((aDest.mLength>0) && (aTarget.mLength>0)){
|
||||
PRInt32 theNewStartPos=-1;
|
||||
PRUnichar theFirstTargetChar=nsStr::GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=nsStr::GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRUnichar theFirstTargetChar=GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRInt32 theTargetMax=aTarget.mLength;
|
||||
while(++index<=theMax) {
|
||||
PRInt32 theSubIndex=-1;
|
||||
PRBool matches=PR_TRUE;
|
||||
while((++theSubIndex<theTargetMax) && (matches)){
|
||||
PRUnichar theChar=nsStr::GetCharAt(aDest,index+theSubIndex);
|
||||
PRUnichar theChar=GetCharAt(aDest,index+theSubIndex);
|
||||
if(theSubIndex>0) {
|
||||
if(theFirstTargetChar==theChar){
|
||||
PRUnichar theDestJumpChar=nsStr::GetCharAt(aDest,index+theTargetMax);
|
||||
PRUnichar theDestJumpChar=GetCharAt(aDest,index+theTargetMax);
|
||||
if(theDestJumpChar==theLastTargetChar) {
|
||||
theNewStartPos=index; //this lets us jump ahead during our search where possible.
|
||||
}//if
|
||||
}//if
|
||||
}//if
|
||||
PRUnichar theTargetChar=nsStr::GetCharAt(aTarget,theSubIndex);
|
||||
PRUnichar theTargetChar=GetCharAt(aTarget,theSubIndex);
|
||||
matches=PRBool(theChar==theTargetChar);
|
||||
}
|
||||
if(matches)
|
||||
@@ -384,8 +471,8 @@ PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool /*aIgn
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsStr::FindChar(const nsStr& aDest, PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase);
|
||||
PRInt32 nsStr::FindChar(const nsStr& aDest,const PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,0,aChar,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -415,12 +502,12 @@ PRInt32 nsStr::FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnore
|
||||
**************************************************************/
|
||||
|
||||
|
||||
PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool /*aIgnoreCase*/,PRUint32 anOffset) {
|
||||
PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 index=(anOffset ? anOffset : aDest.mLength-aTarget.mLength+1);
|
||||
if((aDest.mLength>0) && (aTarget.mLength>0)){
|
||||
PRInt32 theNewStartPos=-1;
|
||||
PRUnichar theFirstTargetChar=nsStr::GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=nsStr::GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRUnichar theFirstTargetChar=GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRInt32 theTargetMax=aTarget.mLength;
|
||||
|
||||
while(index--) {
|
||||
@@ -429,16 +516,16 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool /*aIg
|
||||
|
||||
if(anOffset+aTarget.mLength<=aDest.mLength) {
|
||||
while((++theSubIndex<theTargetMax) && (matches)){
|
||||
PRUnichar theChar=nsStr::GetCharAt(aDest,index+theSubIndex);
|
||||
PRUnichar theChar=GetCharAt(aDest,index+theSubIndex);
|
||||
if(theSubIndex>0) {
|
||||
if(theFirstTargetChar==theChar){
|
||||
PRUnichar theDestJumpChar=nsStr::GetCharAt(aDest,index+theTargetMax);
|
||||
PRUnichar theDestJumpChar=GetCharAt(aDest,index+theTargetMax);
|
||||
if(theDestJumpChar==theLastTargetChar) {
|
||||
theNewStartPos=index; //this lets us jump ahead during our search where possible.
|
||||
}//if
|
||||
}//if
|
||||
}//if
|
||||
PRUnichar theTargetChar=nsStr::GetCharAt(aTarget,theSubIndex);
|
||||
PRUnichar theTargetChar=GetCharAt(aTarget,theSubIndex);
|
||||
matches=PRBool(theChar==theTargetChar);
|
||||
} //while
|
||||
} //if
|
||||
@@ -459,8 +546,8 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool /*aIg
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsStr::RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gRFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase);
|
||||
PRInt32 nsStr::RFindChar(const nsStr& aDest,const PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gRFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,0,aChar,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -472,11 +559,11 @@ PRInt32 nsStr::RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,
|
||||
* @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) {
|
||||
PRUnichar theChar=GetCharAt(aDest,PRUint32(offset));
|
||||
PRUnichar theChar=GetCharAt(aDest,offset);
|
||||
thePos=gRFindChars[aSet.mMultibyte](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase);
|
||||
if(kNotFound!=thePos)
|
||||
return offset;
|
||||
@@ -491,7 +578,7 @@ PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnor
|
||||
* @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 nsStr::Compare(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) {
|
||||
int minlen=(aSource.mLength<aDest.mLength) ? aSource.mLength : aDest.mLength;
|
||||
|
||||
if(0==minlen) {
|
||||
|
||||
@@ -27,8 +27,6 @@
|
||||
We chose the option B for performance reasons.
|
||||
|
||||
2 Our internal buffer always holds capacity+1 bytes.
|
||||
3. Note that our internal format for this class makes our memory
|
||||
layout compatible with BStrings.
|
||||
|
||||
The nsStr struct is a simple structure (no methods) that contains
|
||||
the necessary info to be described as a string. This simple struct
|
||||
@@ -44,41 +42,13 @@
|
||||
#ifndef _nsStr
|
||||
#define _nsStr
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nscore.h"
|
||||
#include "nsCore.h"
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
enum eCharSize {eOneByte=0,eTwoByte=1};
|
||||
#define kDefaultCharSize eTwoByte
|
||||
|
||||
|
||||
union UStrPtr {
|
||||
char* mCharBuf;
|
||||
PRUnichar* mUnicharBuf;
|
||||
};
|
||||
|
||||
/**************************************************************************
|
||||
Here comes the nsBufDescriptor class which describes buffer properties.
|
||||
**************************************************************************/
|
||||
|
||||
struct nsBufDescriptor {
|
||||
nsBufDescriptor(char* aBuffer,PRUint32 aBufferSize,eCharSize aCharSize,PRBool aOwnsBuffer) {
|
||||
mStr=aBuffer;
|
||||
mMultibyte=aCharSize;
|
||||
mCapacity=(aBufferSize>>mMultibyte)-1;
|
||||
mOwnsBuffer=aOwnsBuffer;
|
||||
}
|
||||
|
||||
PRUint32 mCapacity;
|
||||
PRBool mOwnsBuffer;
|
||||
eCharSize mMultibyte;
|
||||
// UStrPtr mStr;
|
||||
union {
|
||||
char* mStr;
|
||||
PRUnichar* mUStr;
|
||||
};
|
||||
};
|
||||
const PRInt32 kNotFound = -1;
|
||||
|
||||
|
||||
class nsIMemoryAgent;
|
||||
@@ -97,6 +67,15 @@ struct nsStr {
|
||||
*/
|
||||
static void Initialize(nsStr& aDest,eCharSize aCharSize);
|
||||
|
||||
/**
|
||||
* This method initializes an nsStr for use
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aString is the nsStr to be initialized
|
||||
* @param aCharSize tells us the requested char size (1 or 2 bytes)
|
||||
*/
|
||||
static void Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 aLength,eCharSize aCharSize,PRBool aOwnsBuffer);
|
||||
|
||||
/**
|
||||
* This method destroys the given nsStr, and *MAY*
|
||||
* deallocate it's memory depending on the setting
|
||||
@@ -166,7 +145,7 @@ struct nsStr {
|
||||
* @param aCount tells us the (max) # of chars to delete
|
||||
* @param anAgent is the allocator to be used for alloc/free operations
|
||||
*/
|
||||
static void Delete(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0);
|
||||
static void Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAgent* anAgent=0);
|
||||
|
||||
/**
|
||||
* This method is used to truncate the given string.
|
||||
@@ -254,21 +233,20 @@ struct nsStr {
|
||||
static PRInt32 RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset);
|
||||
static PRInt32 RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRUint32 anOffset);
|
||||
|
||||
/**
|
||||
* This method is used to access a given char in the given string
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the nsStr to be appended to
|
||||
* @param anIndex tells us where in dest to get the char from
|
||||
* @return the given char, or 0 if anIndex is out of range
|
||||
*/
|
||||
static PRUnichar GetCharAt(const nsStr& aDest,PRUint32 anIndex);
|
||||
|
||||
PRUint32 mLength : 30;
|
||||
eCharSize mMultibyte : 2;
|
||||
#ifdef NS_DEBUG
|
||||
PRUint32 mLength;
|
||||
eCharSize mMultibyte;
|
||||
PRUint32 mCapacity;
|
||||
PRUint32 mOwnsBuffer;
|
||||
PRUint32 mUnused;
|
||||
#else
|
||||
PRUint32 mLength: 30;
|
||||
eCharSize mMultibyte: 2;
|
||||
PRUint32 mCapacity: 30;
|
||||
PRUint32 mOwnsBuffer: 1;
|
||||
PRUint32 mUnused: 1;
|
||||
PRUint32 mOwnsBuffer: 1;
|
||||
PRUint32 mUnused: 1;
|
||||
#endif
|
||||
union {
|
||||
char* mStr;
|
||||
PRUnichar* mUStr;
|
||||
@@ -307,6 +285,21 @@ inline void AddNullTerminator(nsStr& aDest) {
|
||||
else aDest.mStr[aDest.mLength]=0;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to access a given char in the given string
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the nsStr to be appended to
|
||||
* @param anIndex tells us where in dest to get the char from
|
||||
* @return the given char, or 0 if anIndex is out of range
|
||||
*/
|
||||
inline PRUnichar GetCharAt(const nsStr& aDest,PRUint32 anIndex){
|
||||
if(anIndex<aDest.mLength) {
|
||||
return (eTwoByte==aDest.mMultibyte) ? aDest.mUStr[anIndex] : aDest.mStr[anIndex];
|
||||
}//if
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
class nsIMemoryAgent {
|
||||
@@ -317,25 +310,18 @@ public:
|
||||
};
|
||||
|
||||
class nsMemoryAgent : public nsIMemoryAgent {
|
||||
enum eDelta{eGrowthDelta=8};
|
||||
protected:
|
||||
enum eDelta{eDefaultSize=16};
|
||||
public:
|
||||
|
||||
virtual PRBool Alloc(nsStr& aDest,PRInt32 aCount) {
|
||||
|
||||
//we're given the acount value in charunits; we have to scale up by the charsize.
|
||||
|
||||
PRInt32 theNewCapacity;
|
||||
if (aDest.mCapacity > 64) {
|
||||
// When the string starts getting large, double the capacity as we grow.
|
||||
theNewCapacity = aDest.mCapacity * 2;
|
||||
if (theNewCapacity < aCount) {
|
||||
theNewCapacity = aDest.mCapacity + aCount;
|
||||
}
|
||||
} else {
|
||||
// When the string is small, keep it's capacity a multiple of kGrowthDelta
|
||||
PRInt32 unitDelta=(aCount/eGrowthDelta)+1;
|
||||
theNewCapacity=unitDelta*eGrowthDelta;
|
||||
//we're given the acount value in charunits; now scale up to next multiple.
|
||||
PRInt32 theNewCapacity=eDefaultSize;
|
||||
while(theNewCapacity<aCount){
|
||||
theNewCapacity<<=1;
|
||||
}
|
||||
|
||||
|
||||
aDest.mCapacity=theNewCapacity++;
|
||||
size_t theSize=(theNewCapacity<<aDest.mMultibyte);
|
||||
aDest.mStr=new char[theSize];
|
||||
@@ -362,6 +348,5 @@ public:
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -30,8 +30,8 @@
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef _NSSTRING
|
||||
#define _NSSTRING
|
||||
#ifndef _nsString1
|
||||
#define _nsString1
|
||||
|
||||
|
||||
#include "prtypes.h"
|
||||
@@ -39,9 +39,18 @@
|
||||
#include "nsIAtom.h"
|
||||
#include <iostream.h>
|
||||
#include <stdio.h>
|
||||
#include "nsStr.h"
|
||||
|
||||
#ifndef USE_STRING2
|
||||
#define nsString1 nsString
|
||||
#define nsAutoString1 nsAutoString
|
||||
#else
|
||||
#include "nsString2.h" //get new string class
|
||||
#endif
|
||||
|
||||
class nsISizeOfHandler;
|
||||
|
||||
class NS_BASE nsString {
|
||||
class NS_BASE nsString1 {
|
||||
public:
|
||||
|
||||
/**
|
||||
@@ -50,30 +59,30 @@ class NS_BASE nsString {
|
||||
* was to allow developers direct access to the underlying buffer for
|
||||
* performance reasons.
|
||||
*/
|
||||
nsString();
|
||||
nsString1();
|
||||
|
||||
/**
|
||||
* This constructor accepts an isolatin string
|
||||
* @param an ascii is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsString(const char* aCString);
|
||||
nsString1(const char* aCString);
|
||||
|
||||
/**
|
||||
* This is our copy constructor
|
||||
* @param reference to another nsString
|
||||
* @param reference to another nsString1
|
||||
*/
|
||||
nsString(const nsString&);
|
||||
nsString1(const nsString1&);
|
||||
|
||||
/**
|
||||
* Constructor from a unicode string
|
||||
* @param anicodestr pts to a unicode string
|
||||
*/
|
||||
nsString(const PRUnichar* aUnicode);
|
||||
nsString1(const PRUnichar* aUnicode);
|
||||
|
||||
/**
|
||||
* Virtual Destructor
|
||||
*/
|
||||
virtual ~nsString();
|
||||
virtual ~nsString1();
|
||||
|
||||
|
||||
/**
|
||||
@@ -136,14 +145,14 @@ const PRUnichar* GetUnicode(void) const;
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
operator const PRUnichar*() const;
|
||||
//operator const PRUnichar*() const;
|
||||
|
||||
/**
|
||||
* Retrieve unicode char at given index
|
||||
* @param offset into string
|
||||
* @return PRUnichar* to internal string
|
||||
*/
|
||||
PRUnichar operator()(PRInt32 anIndex) const;
|
||||
//PRUnichar operator()(PRInt32 anIndex) const;
|
||||
|
||||
/**
|
||||
* Retrieve reference to unicode char at given index
|
||||
@@ -183,35 +192,35 @@ PRBool SetCharAt(PRUnichar aChar,PRInt32 anIndex);
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsString operator+(const nsString& aString);
|
||||
nsString1 operator+(const nsString1& aString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given buffer.
|
||||
* @param aCString is a ptr to cstring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString operator+(const char* aCString);
|
||||
nsString1 operator+(const char* aCString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given char.
|
||||
* @param aChar is a char to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString operator+(char aChar);
|
||||
nsString1 operator+(char aChar);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given buffer.
|
||||
* @param aStr unichar buffer to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString operator+(const PRUnichar* aBuffer);
|
||||
nsString1 operator+(const PRUnichar* aBuffer);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given char.
|
||||
* @param aChar is a unichar to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString operator+(PRUnichar aChar);
|
||||
nsString1 operator+(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* Converts all chars in internal string to lower
|
||||
@@ -221,7 +230,7 @@ void ToLowerCase();
|
||||
/**
|
||||
* Converts all chars in given string to lower
|
||||
*/
|
||||
void ToLowerCase(nsString& aString) const;
|
||||
void ToLowerCase(nsString1& aString) const;
|
||||
|
||||
/**
|
||||
* Converts all chars in given string to upper
|
||||
@@ -237,13 +246,13 @@ void ToUCS2(PRInt32 aStartOffset);
|
||||
/**
|
||||
* Converts all chars in internal string to upper
|
||||
*/
|
||||
void ToUpperCase(nsString& aString) const;
|
||||
void ToUpperCase(nsString1& aString) const;
|
||||
|
||||
/**
|
||||
* Creates a duplicate clone (ptr) of this string.
|
||||
* @return ptr to clone of this string
|
||||
*/
|
||||
nsString* ToNewString() const;
|
||||
nsString1* ToNewString() const;
|
||||
|
||||
/**
|
||||
* Creates an ascii clone of this string
|
||||
@@ -265,7 +274,7 @@ char* ToCString(char* aBuf,PRInt32 aBufLength) const;
|
||||
* @param aString to hold copy of this
|
||||
* @return nada.
|
||||
*/
|
||||
void Copy(nsString& aString) const;
|
||||
void Copy(nsString1& aString) const;
|
||||
|
||||
/**
|
||||
* Creates an unichar clone of this string
|
||||
@@ -298,79 +307,72 @@ PRInt32 ToInteger(PRInt32* aErrorCode,PRInt32 aRadix=10) const;
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString& SetString(const PRUnichar* aStr,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* assign given char* to this string
|
||||
* @param aCString: buffer to be assigned to this
|
||||
* @param alength is the length of the given str (or -1)
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString& SetString(const char* aCString,PRInt32 aLength=-1);
|
||||
nsString1& SetString(const PRUnichar* aStr,PRInt32 aLength=-1);
|
||||
nsString1& SetString(const char* aCString,PRInt32 aLength=-1);
|
||||
nsString1& SetString(const nsString1& aString);
|
||||
|
||||
/**
|
||||
* assign given string to this one
|
||||
* @param aString: string to be added to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator=(const nsString& aString);
|
||||
nsString1& operator=(const nsString1& aString);
|
||||
|
||||
/**
|
||||
* assign given char* to this string
|
||||
* @param aCString: buffer to be assigned to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator=(const char* aCString);
|
||||
nsString1& operator=(const char* aCString);
|
||||
|
||||
/**
|
||||
* assign given char to this string
|
||||
* @param aChar: char to be assignd to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator=(char aChar);
|
||||
nsString1& operator=(char aChar);
|
||||
|
||||
/**
|
||||
* assign given unichar* to this string
|
||||
* @param aBuffer: unichar buffer to be assigned to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator=(const PRUnichar* aBuffer);
|
||||
nsString1& operator=(const PRUnichar* aBuffer);
|
||||
|
||||
/**
|
||||
* assign given char to this string
|
||||
* @param aChar: char to be assignd to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator=(PRUnichar aChar);
|
||||
nsString1& operator=(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @param aString : string to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator+=(const nsString& aString);
|
||||
nsString1& operator+=(const nsString1& aString);
|
||||
|
||||
/**
|
||||
* append given buffer to this string
|
||||
* @param aCString: buffer to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator+=(const char* aCString);
|
||||
nsString1& operator+=(const char* aCString);
|
||||
|
||||
/**
|
||||
* append given buffer to this string
|
||||
* @param aBuffer: buffer to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator+=(const PRUnichar* aBuffer);
|
||||
nsString1& operator+=(const PRUnichar* aBuffer);
|
||||
|
||||
/**
|
||||
* append given char to this string
|
||||
* @param aChar: char to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator+=(PRUnichar aChar);
|
||||
nsString1& operator+=(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
@@ -379,7 +381,7 @@ nsString& operator+=(PRUnichar aChar);
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(const nsString& aString,PRInt32 aLength=-1);
|
||||
nsString1& Append(const nsString1& aString,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
@@ -388,14 +390,14 @@ nsString& Append(const nsString& aString,PRInt32 aLength=-1);
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(const char* aCString,PRInt32 aLength=-1);
|
||||
nsString1& Append(const char* aCString,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @param aString : string to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(char aChar);
|
||||
nsString1& Append(char aChar);
|
||||
|
||||
/**
|
||||
* append given unichar buffer to this string
|
||||
@@ -404,14 +406,14 @@ nsString& Append(char aChar);
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(const PRUnichar* aBuffer,PRInt32 aLength=-1);
|
||||
nsString1& Append(const PRUnichar* aBuffer,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* append given unichar character to this string
|
||||
* @param aChar is the char to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(PRUnichar aChar);
|
||||
nsString1& Append(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* Append an integer onto this string
|
||||
@@ -419,14 +421,14 @@ nsString& Append(PRUnichar aChar);
|
||||
* @param aRadix specifies 8,10,16
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(PRInt32 aInteger,PRInt32 aRadix); //radix=8,10 or 16
|
||||
nsString1& Append(PRInt32 aInteger,PRInt32 aRadix); //radix=8,10 or 16
|
||||
|
||||
/**
|
||||
* Append a float value onto this string
|
||||
* @param aFloat is the float to be appended
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(float aFloat);
|
||||
nsString1& Append(float aFloat);
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
@@ -437,7 +439,7 @@ nsString& Append(float aFloat);
|
||||
* @param aCount -- number of chars to copy
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Left(nsString& aCopy,PRInt32 aCount) const;
|
||||
PRInt32 Left(nsString1& aCopy,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
@@ -449,7 +451,7 @@ PRInt32 Left(nsString& aCopy,PRInt32 aCount) const;
|
||||
* @param anOffset -- position where copying begins
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Mid(nsString& aCopy,PRInt32 anOffset,PRInt32 aCount) const;
|
||||
PRInt32 Mid(nsString1& aCopy,PRInt32 anOffset,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
@@ -460,7 +462,7 @@ PRInt32 Mid(nsString& aCopy,PRInt32 anOffset,PRInt32 aCount) const;
|
||||
* @param aCount -- number of chars to copy
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Right(nsString& aCopy,PRInt32 aCount) const;
|
||||
PRInt32 Right(nsString1& aCopy,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* This method inserts n chars from given string into this
|
||||
@@ -471,7 +473,7 @@ PRInt32 Right(nsString& aCopy,PRInt32 aCount) const;
|
||||
* @param aCount -- number of chars to be copied from aCopy
|
||||
* @return number of chars inserted into this.
|
||||
*/
|
||||
PRInt32 Insert(const nsString& aCopy,PRInt32 anOffset,PRInt32 aCount=-1);
|
||||
PRInt32 Insert(const nsString1& aCopy,PRInt32 anOffset,PRInt32 aCount=-1);
|
||||
|
||||
/**
|
||||
* Insert a single unicode char into this string at
|
||||
@@ -491,7 +493,7 @@ PRInt32 Insert(PRUnichar aChar,PRInt32 anOffset);
|
||||
* @param aCount -- number of chars to be cut
|
||||
* @return *this
|
||||
*/
|
||||
nsString& Cut(PRInt32 anOffset,PRInt32 aCount);
|
||||
nsString1& Cut(PRInt32 anOffset,PRInt32 aCount);
|
||||
|
||||
/**
|
||||
* This method is used to remove all occurances of the
|
||||
@@ -500,7 +502,7 @@ nsString& Cut(PRInt32 anOffset,PRInt32 aCount);
|
||||
* @param aSet -- characters to be cut from this
|
||||
* @return *this
|
||||
*/
|
||||
nsString& StripChars(const char* aSet);
|
||||
nsString1& StripChars(const char* aSet);
|
||||
|
||||
/**
|
||||
* This method is used to replace all occurances of the
|
||||
@@ -509,14 +511,14 @@ nsString& StripChars(const char* aSet);
|
||||
* @param
|
||||
* @return *this
|
||||
*/
|
||||
nsString& ReplaceChar(PRUnichar aSourceChar, PRUnichar aDestChar);
|
||||
nsString1& ReplaceChar(PRUnichar aSourceChar, PRUnichar aDestChar);
|
||||
|
||||
/**
|
||||
* This method strips whitespace throughout the string
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
nsString& StripWhitespace();
|
||||
nsString1& StripWhitespace();
|
||||
|
||||
/**
|
||||
* This method trims characters found in aTrimSet from
|
||||
@@ -526,7 +528,7 @@ nsString& StripWhitespace();
|
||||
* both ends
|
||||
* @return this
|
||||
*/
|
||||
nsString& Trim(const char* aSet,
|
||||
nsString1& Trim(const char* aSet,
|
||||
PRBool aEliminateLeading=PR_TRUE,
|
||||
PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
@@ -539,7 +541,7 @@ nsString& Trim(const char* aSet,
|
||||
* @param aEliminateTrailing controls stripping of trailing ws
|
||||
* @return this
|
||||
*/
|
||||
nsString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,
|
||||
nsString1& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,
|
||||
PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
/**
|
||||
@@ -588,7 +590,7 @@ PRInt32 BinarySearch(PRUnichar aChar) const;
|
||||
*/
|
||||
PRInt32 Find(const char* aString) const;
|
||||
PRInt32 Find(const PRUnichar* aString) const;
|
||||
PRInt32 Find(const nsString& aString) const;
|
||||
PRInt32 Find(const nsString1& aString) const;
|
||||
|
||||
/**
|
||||
* Search for given char within this string
|
||||
@@ -606,7 +608,7 @@ PRInt32 Find(PRUnichar aChar,PRInt32 offset=0) const;
|
||||
* @return -1 if not found, else the offset in this
|
||||
*/
|
||||
PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 FindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 FindCharInSet(nsString1& aString,PRInt32 anOffset=0) const;
|
||||
|
||||
/**
|
||||
* This method searches this string for the last character
|
||||
@@ -616,7 +618,7 @@ PRInt32 FindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
||||
* @return -1 if not found, else the offset in this
|
||||
*/
|
||||
PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 RFindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 RFindCharInSet(nsString1& aString,PRInt32 anOffset=0) const;
|
||||
|
||||
|
||||
/**
|
||||
@@ -627,7 +629,7 @@ PRInt32 RFindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
||||
*/
|
||||
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFind(const nsString1& aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
|
||||
/**
|
||||
* This methods scans the string backwards, looking for the given char
|
||||
@@ -648,7 +650,7 @@ PRInt32 RFind(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
* @param aIgnoreCase tells us how to treat case
|
||||
* @return -1,0,1
|
||||
*/
|
||||
virtual PRInt32 Compare(const nsString &aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
virtual PRInt32 Compare(const nsString1 &aString,PRBool aIgnoreCase=PR_FALSE) 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;
|
||||
|
||||
@@ -657,7 +659,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 nsString1 &aString) const;
|
||||
PRBool operator==(const char *aString) const;
|
||||
PRBool operator==(const PRUnichar* aString) const;
|
||||
PRBool operator==(PRUnichar* aString) const;
|
||||
@@ -667,7 +669,7 @@ PRBool operator==(PRUnichar* aString) const;
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE
|
||||
*/
|
||||
PRBool operator!=(const nsString &aString) const;
|
||||
PRBool operator!=(const nsString1 &aString) const;
|
||||
PRBool operator!=(const char *aString) const;
|
||||
PRBool operator!=(const PRUnichar* aString) const;
|
||||
|
||||
@@ -676,7 +678,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 nsString1 &aString) const;
|
||||
PRBool operator<(const char *aString) const;
|
||||
PRBool operator<(const PRUnichar* aString) const;
|
||||
|
||||
@@ -685,7 +687,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 &S) const;
|
||||
PRBool operator>(const nsString1 &S) const;
|
||||
PRBool operator>(const char *aCString) const;
|
||||
PRBool operator>(const PRUnichar* aString) const;
|
||||
|
||||
@@ -694,7 +696,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 &S) const;
|
||||
PRBool operator<=(const nsString1 &S) const;
|
||||
PRBool operator<=(const char *aCString) const;
|
||||
PRBool operator<=(const PRUnichar* aString) const;
|
||||
|
||||
@@ -703,7 +705,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 &S) const;
|
||||
PRBool operator>=(const nsString1 &S) const;
|
||||
PRBool operator>=(const char* aCString) const;
|
||||
PRBool operator>=(const PRUnichar* aString) const;
|
||||
|
||||
@@ -717,7 +719,7 @@ PRBool operator>=(const PRUnichar* aString) const;
|
||||
* @param aLength -- optional length of given string.
|
||||
* @return TRUE if equal
|
||||
*/
|
||||
PRBool Equals(const nsString& aString) const;
|
||||
PRBool Equals(const nsString1& aString) const;
|
||||
PRBool Equals(const char* aString,PRInt32 aLength=-1) const;
|
||||
PRBool Equals(const nsIAtom *aAtom) const;
|
||||
|
||||
@@ -740,7 +742,7 @@ PRBool Equals(const PRUnichar* s1, const PRUnichar* s2) const;
|
||||
* @param aLength -- optional length of given string.
|
||||
* @return TRUE if equal
|
||||
*/
|
||||
PRBool EqualsIgnoreCase(const nsString& aString) const;
|
||||
PRBool EqualsIgnoreCase(const nsString1& aString) const;
|
||||
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aLength=-1) const;
|
||||
PRBool EqualsIgnoreCase(const nsIAtom *aAtom) const;
|
||||
|
||||
@@ -768,34 +770,34 @@ typedef PRUnichar chartype;
|
||||
#endif
|
||||
};
|
||||
|
||||
ostream& operator<<(ostream& os,nsString& aString);
|
||||
extern NS_BASE int fputs(const nsString& aString, FILE* out);
|
||||
ostream& operator<<(ostream& os,nsString1& aString);
|
||||
extern NS_BASE int fputs(const nsString1& aString, FILE* out);
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* A version of nsString which is designed to be used as an automatic
|
||||
* A version of nsString1 which is designed to be used as an automatic
|
||||
* variable. It attempts to operate out of a fixed size internal
|
||||
* buffer until too much data is added; then a dynamic buffer is
|
||||
* allocated and grown as necessary.
|
||||
*/
|
||||
// XXX template this with a parameter for the size of the buffer?
|
||||
class NS_BASE nsAutoString : public nsString {
|
||||
class NS_BASE nsAutoString1 : public nsString1 {
|
||||
public:
|
||||
nsAutoString();
|
||||
nsAutoString(const nsString& other);
|
||||
nsAutoString(const nsAutoString& other);
|
||||
nsAutoString(PRUnichar aChar);
|
||||
nsAutoString(const char* aCString);
|
||||
nsAutoString(const PRUnichar* us, PRInt32 uslen = -1);
|
||||
virtual ~nsAutoString();
|
||||
nsAutoString1();
|
||||
nsAutoString1(const nsString1& other);
|
||||
nsAutoString1(const nsAutoString1& other);
|
||||
nsAutoString1(PRUnichar aChar);
|
||||
nsAutoString1(const char* aCString);
|
||||
nsAutoString1(const PRUnichar* us, PRInt32 uslen = -1);
|
||||
virtual ~nsAutoString1();
|
||||
|
||||
nsAutoString& operator=(const nsString& aString) {nsString::operator=(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;}
|
||||
nsAutoString1& operator=(const nsString1& aString) {nsString1::operator=(aString); return *this;}
|
||||
nsAutoString1& operator=(const nsAutoString1& aString) {nsString1::operator=(aString); return *this;}
|
||||
nsAutoString1& operator=(const char* aCString) {nsString1::operator=(aCString); return *this;}
|
||||
nsAutoString1& operator=(char aChar) {nsString1::operator=(aChar); return *this;}
|
||||
nsAutoString1& operator=(const PRUnichar* aBuffer) {nsString1::operator=(aBuffer); return *this;}
|
||||
nsAutoString1& operator=(PRUnichar aChar) {nsString1::operator=(aChar); return *this;}
|
||||
|
||||
virtual void SizeOf(nsISizeOfHandler* aHandler) const;
|
||||
|
||||
@@ -807,7 +809,7 @@ protected:
|
||||
chartype mBuf[32];
|
||||
};
|
||||
|
||||
ostream& operator<<(ostream& os,nsAutoString& aString);
|
||||
ostream& operator<<(ostream& os,nsAutoString1& aString);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -25,18 +25,15 @@
|
||||
#include "nsDebug.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsISizeOfHandler.h"
|
||||
#include "prprf.h"
|
||||
#include "prdtoa.h"
|
||||
#include "nsDeque.h"
|
||||
|
||||
#include "nsUnicharUtilCIID.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsICaseConversion.h"
|
||||
#ifndef RICKG_TESTBED
|
||||
#include "prdtoa.h"
|
||||
#include "nsISizeOfHandler.h"
|
||||
#endif
|
||||
|
||||
static const char* kNullPointerError = "Error: unexpected null ptr";
|
||||
static const char* kWhitespace="\b\t\r\n ";
|
||||
static const PRInt32 kNotFound=-1;
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
PRBool nsString2::mSelfTested = PR_FALSE;
|
||||
@@ -97,58 +94,7 @@ public:
|
||||
}
|
||||
}
|
||||
};
|
||||
static CTableConstructor gTableConstructor;
|
||||
|
||||
//---- XPCOM code to connect with UnicharUtil
|
||||
|
||||
class HandleCaseConversionShutdown3 : public nsIShutdownListener {
|
||||
public :
|
||||
NS_IMETHOD OnShutdown(const nsCID& cid, nsISupports* service);
|
||||
HandleCaseConversionShutdown3(void) { NS_INIT_REFCNT(); }
|
||||
virtual ~HandleCaseConversionShutdown3(void) {}
|
||||
NS_DECL_ISUPPORTS
|
||||
};
|
||||
static NS_DEFINE_CID(kUnicharUtilCID, NS_UNICHARUTIL_CID);
|
||||
static NS_DEFINE_IID(kICaseConversionIID, NS_ICASECONVERSION_IID);
|
||||
|
||||
static nsICaseConversion * gCaseConv = NULL;
|
||||
|
||||
static NS_DEFINE_IID(kIShutdownListenerIID, NS_ISHUTDOWNLISTENER_IID);
|
||||
NS_IMPL_ISUPPORTS(HandleCaseConversionShutdown3, kIShutdownListenerIID);
|
||||
|
||||
nsresult
|
||||
HandleCaseConversionShutdown3::OnShutdown(const nsCID& cid, nsISupports* service)
|
||||
{
|
||||
if (cid.Equals(kUnicharUtilCID)) {
|
||||
NS_ASSERTION(service == gCaseConv, "wrong service!");
|
||||
gCaseConv->Release();
|
||||
gCaseConv = NULL;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static HandleCaseConversionShutdown3* gListener = NULL;
|
||||
|
||||
static void StartUpCaseConversion()
|
||||
{
|
||||
nsresult err;
|
||||
|
||||
if ( NULL == gListener )
|
||||
{
|
||||
gListener = new HandleCaseConversionShutdown3();
|
||||
gListener->AddRef();
|
||||
}
|
||||
err = nsServiceManager::GetService(kUnicharUtilCID, kICaseConversionIID,
|
||||
(nsISupports**) &gCaseConv, gListener);
|
||||
}
|
||||
static void CheckCaseConversion()
|
||||
{
|
||||
if(NULL == gCaseConv )
|
||||
StartUpCaseConversion();
|
||||
|
||||
// NS_ASSERTION( gCaseConv != NULL , "cannot obtain UnicharUtil");
|
||||
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
IMPLEMENTATION NOTES:
|
||||
@@ -158,6 +104,15 @@ static void CheckCaseConversion()
|
||||
that no poor soul would ever have to do this again. Sigh.
|
||||
***********************************************************************/
|
||||
|
||||
void Subsume(nsStr& aDest,nsStr& aSource){
|
||||
aDest.mStr=aSource.mStr;
|
||||
aDest.mLength=aSource.mLength;
|
||||
aDest.mMultibyte=aSource.mMultibyte;
|
||||
aDest.mCapacity=aSource.mCapacity;
|
||||
aDest.mOwnsBuffer=aSource.mOwnsBuffer;
|
||||
aSource.mOwnsBuffer=PR_FALSE;
|
||||
aSource.mStr=0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor. Note that we actually allocate a small buffer
|
||||
@@ -216,6 +171,15 @@ nsString2::nsString2(const nsString2& aString) :mAgent(aString.mAgent) {
|
||||
nsStr::Assign(*this,aString,0,aString.mLength,mAgent);
|
||||
}
|
||||
|
||||
/**
|
||||
* construct off a subsumeable string
|
||||
* @update gess 1/4/99
|
||||
* @param reference to a subsumeString
|
||||
*/
|
||||
nsString2::nsString2(nsSubsumeStr& aSubsumeStr) :mAgent(0) {
|
||||
Subsume(*this,aSubsumeStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
* Make sure we call nsStr::Destroy.
|
||||
@@ -293,7 +257,7 @@ void nsString2::SetCapacity(PRUint32 aLength) {
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
char* nsString2::GetBuffer(void) const {
|
||||
const char* nsString2::GetBuffer(void) const {
|
||||
if(!mMultibyte)
|
||||
return mStr;
|
||||
return 0;
|
||||
@@ -305,7 +269,7 @@ char* nsString2::GetBuffer(void) const {
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRUnichar* nsString2::GetUnicode(void) const {
|
||||
const PRUnichar* nsString2::GetUnicode(void) const {
|
||||
if(mMultibyte)
|
||||
return (PRUnichar*)mUStr;
|
||||
return 0;
|
||||
@@ -314,11 +278,11 @@ PRUnichar* nsString2::GetUnicode(void) const {
|
||||
/**
|
||||
* Get nth character.
|
||||
*/
|
||||
PRUnichar nsString2::operator[](int anIndex) const {
|
||||
PRUnichar nsString2::operator[](PRUint32 anIndex) const {
|
||||
return GetCharAt(*this,anIndex);
|
||||
}
|
||||
|
||||
PRUnichar nsString2::CharAt(int anIndex) const {
|
||||
PRUnichar nsString2::CharAt(PRUint32 anIndex) const {
|
||||
return GetCharAt(*this,anIndex);
|
||||
}
|
||||
|
||||
@@ -352,10 +316,10 @@ PRBool nsString2::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsString2 nsString2::operator+(const nsStr& aString){
|
||||
nsSubsumeStr nsString2::operator+(const nsStr& aString){
|
||||
nsString2 temp(*this); //make a temp string the same size as this...
|
||||
nsStr::Append(temp,aString,0,aString.mLength,mAgent);
|
||||
return temp;
|
||||
return nsSubsumeStr(temp);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -364,10 +328,10 @@ nsString2 nsString2::operator+(const nsStr& aString){
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsString2 nsString2::operator+(const nsString2& aString){
|
||||
nsSubsumeStr nsString2::operator+(const nsString2& aString){
|
||||
nsString2 temp(*this); //make a temp string the same size as this...
|
||||
nsStr::Append(temp,aString,0,aString.mLength,mAgent);
|
||||
return temp;
|
||||
return nsSubsumeStr(temp);
|
||||
}
|
||||
|
||||
|
||||
@@ -377,10 +341,10 @@ nsString2 nsString2::operator+(const nsString2& aString){
|
||||
* @param aCString is a ptr to cstring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 nsString2::operator+(const char* aCString) {
|
||||
nsSubsumeStr nsString2::operator+(const char* aCString) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(aCString);
|
||||
return temp;
|
||||
return nsSubsumeStr(temp);
|
||||
}
|
||||
|
||||
|
||||
@@ -390,10 +354,10 @@ nsString2 nsString2::operator+(const char* aCString) {
|
||||
* @param aChar is a char to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 nsString2::operator+(char aChar) {
|
||||
nsSubsumeStr nsString2::operator+(char aChar) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(char(aChar));
|
||||
return temp;
|
||||
return nsSubsumeStr(temp);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -402,10 +366,10 @@ nsString2 nsString2::operator+(char aChar) {
|
||||
* @param aString is a ptr to unistring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 nsString2::operator+(const PRUnichar* aString) {
|
||||
nsSubsumeStr nsString2::operator+(const PRUnichar* aString) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(aString);
|
||||
return temp;
|
||||
return nsSubsumeStr(temp);
|
||||
}
|
||||
|
||||
|
||||
@@ -415,10 +379,10 @@ nsString2 nsString2::operator+(const PRUnichar* aString) {
|
||||
* @param aChar is a unichar to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 nsString2::operator+(PRUnichar aChar) {
|
||||
nsSubsumeStr nsString2::operator+(PRUnichar aChar) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(char(aChar));
|
||||
return temp;
|
||||
return nsSubsumeStr(temp);
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
@@ -429,6 +393,7 @@ nsString2 nsString2::operator+(PRUnichar aChar) {
|
||||
* Converts all chars in given string to UCS2
|
||||
*/
|
||||
void nsString2::ToUCS2(PRUint32 aStartOffset){
|
||||
static CTableConstructor gTableConstructor;
|
||||
if(aStartOffset<mLength){
|
||||
if(mMultibyte) {
|
||||
PRUint32 theIndex=0;
|
||||
@@ -621,11 +586,11 @@ PRUnichar* nsString2::ToNewUnicode() const {
|
||||
*/
|
||||
char* nsString2::ToCString(char* aBuf, PRUint32 aBufLength) const{
|
||||
if(aBuf) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mStr=aBuf;
|
||||
theTempStr.mCapacity=aBufLength;
|
||||
nsStr::Assign(theTempStr,*this,0,mLength,mAgent);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mStr=aBuf;
|
||||
temp.mCapacity=aBufLength;
|
||||
nsStr::Assign(temp,*this,0,mLength,mAgent);
|
||||
}
|
||||
return aBuf;
|
||||
}
|
||||
@@ -800,15 +765,19 @@ nsString2& nsString2::Assign(PRUnichar aChar) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies contents of this onto given string.
|
||||
* @update gess 7/27/98
|
||||
* @param aString to hold copy of this
|
||||
* @return nada.
|
||||
* WARNING! THIS IS A VERY SPECIAL METHOD.
|
||||
* This method "steals" the contents of aSource and hands it to aDest.
|
||||
* Ordinarily a copy is made, but not in this version.
|
||||
* @update gess10/30/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void nsString2::Copy(nsString2& aString) const{
|
||||
aString.SetString(*this);
|
||||
nsString2& nsString2::operator=(nsSubsumeStr& aSubsumeString) {
|
||||
Subsume(*this,aSubsumeString);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @update gess 01/04/99
|
||||
@@ -843,12 +812,12 @@ nsString2& nsString2::Append(const nsString2& aString,PRInt32 aCount) {
|
||||
*/
|
||||
nsString2& nsString2::Append(const char* aCString,PRInt32 aCount) {
|
||||
if(aCString){
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eOneByte);
|
||||
theTemp.mStr=(char*)aCString;
|
||||
theTemp.mLength=nsCRT::strlen(aCString);
|
||||
if(-1==aCount) aCount=theTemp.mLength;
|
||||
nsStr::Append(*this,theTemp,0,aCount,mAgent);
|
||||
nsStr temp;
|
||||
Initialize(temp,eOneByte);
|
||||
temp.mStr=(char*)aCString;
|
||||
temp.mLength=nsCRT::strlen(aCString);
|
||||
if(-1==aCount) aCount=temp.mLength;
|
||||
nsStr::Append(*this,temp,0,aCount,mAgent);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -862,12 +831,12 @@ nsString2& nsString2::Append(const char* aCString,PRInt32 aCount) {
|
||||
*/
|
||||
nsString2& nsString2::Append(const PRUnichar* aString,PRInt32 aCount) {
|
||||
if(aString){
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eTwoByte);
|
||||
theTemp.mUStr=(PRUnichar*)aString;
|
||||
theTemp.mLength=nsCRT::strlen(aString);
|
||||
if(-1==aCount) aCount=theTemp.mLength;
|
||||
nsStr::Append(*this,theTemp,0,aCount,mAgent);
|
||||
nsStr temp;
|
||||
Initialize(temp,eTwoByte);
|
||||
temp.mUStr=(PRUnichar*)aString;
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
if(-1==aCount) aCount=temp.mLength;
|
||||
nsStr::Append(*this,temp,0,aCount,mAgent);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -882,11 +851,11 @@ nsString2& nsString2::Append(char aChar) {
|
||||
char buf[2]={0,0};
|
||||
buf[0]=aChar;
|
||||
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eOneByte);
|
||||
theTemp.mStr=buf;
|
||||
theTemp.mLength=1;
|
||||
nsStr::Append(*this,theTemp,0,1,mAgent);
|
||||
nsStr temp;
|
||||
Initialize(temp,eOneByte);
|
||||
temp.mStr=buf;
|
||||
temp.mLength=1;
|
||||
nsStr::Append(*this,temp,0,1,mAgent);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -900,11 +869,11 @@ nsString2& nsString2::Append(PRUnichar aChar) {
|
||||
PRUnichar buf[2]={0,0};
|
||||
buf[0]=aChar;
|
||||
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eTwoByte);
|
||||
theTemp.mUStr=buf;
|
||||
theTemp.mLength=1;
|
||||
nsStr::Append(*this,theTemp,0,1,mAgent);
|
||||
nsStr temp;
|
||||
Initialize(temp,eTwoByte);
|
||||
temp.mUStr=buf;
|
||||
temp.mLength=1;
|
||||
nsStr::Append(*this,temp,0,1,mAgent);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -1001,7 +970,7 @@ PRUint32 nsString2::Right(nsString2& aCopy,PRInt32 aCount) const{
|
||||
* @param aCount -- number of chars to be copied from aCopy
|
||||
* @return number of chars inserted into this.
|
||||
*/
|
||||
nsString2& nsString2::Insert(nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount) {
|
||||
nsString2& nsString2::Insert(const nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount) {
|
||||
nsStr::Insert(*this,anOffset,aCopy,0,aCount,mAgent);
|
||||
return *this;
|
||||
}
|
||||
@@ -1018,12 +987,12 @@ nsString2& nsString2::Insert(nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount)
|
||||
nsString2& nsString2::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCount){
|
||||
if(aCString){
|
||||
if(0<aCount) {
|
||||
nsStr theTemp;
|
||||
nsStr::Initialize(theTemp,eOneByte);
|
||||
theTemp.mStr=(char*)aCString;
|
||||
theTemp.mLength=nsCRT::strlen(aCString);
|
||||
if(theTemp.mLength){
|
||||
nsStr::Insert(*this,anOffset,theTemp,0,aCount,0);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mStr=(char*)aCString;
|
||||
temp.mLength=nsCRT::strlen(aCString);
|
||||
if(temp.mLength){
|
||||
nsStr::Insert(*this,anOffset,temp,0,aCount,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1044,11 +1013,11 @@ nsString2& nsString2::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCou
|
||||
nsString2& nsString2::Insert(char aChar,PRUint32 anOffset){
|
||||
char theBuffer[2]={0,0};
|
||||
theBuffer[0]=aChar;
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mStr=(char*)theBuffer;
|
||||
theTempStr.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,theTempStr,0,1,0);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mStr=(char*)theBuffer;
|
||||
temp.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,temp,0,1,0);
|
||||
return *this;
|
||||
}
|
||||
*/
|
||||
@@ -1065,12 +1034,12 @@ nsString2& nsString2::Insert(char aChar,PRUint32 anOffset){
|
||||
nsString2& nsString2::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32 aCount){
|
||||
if(aString){
|
||||
if(0<aCount) {
|
||||
nsStr theTemp;
|
||||
nsStr::Initialize(theTemp,eTwoByte);
|
||||
theTemp.mUStr=(PRUnichar*)aString;
|
||||
theTemp.mLength=nsCRT::strlen(aString);
|
||||
if(theTemp.mLength){
|
||||
nsStr::Insert(*this,anOffset,theTemp,0,aCount,0);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eTwoByte);
|
||||
temp.mUStr=(PRUnichar*)aString;
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
if(temp.mLength){
|
||||
nsStr::Insert(*this,anOffset,temp,0,aCount,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1090,11 +1059,11 @@ nsString2& nsString2::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32
|
||||
nsString2& nsString2::Insert(PRUnichar aChar,PRUint32 anOffset){
|
||||
PRUnichar theBuffer[2]={0,0};
|
||||
theBuffer[0]=aChar;
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mUStr=theBuffer;
|
||||
theTempStr.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,theTempStr,0,1,0);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eTwoByte);
|
||||
temp.mUStr=theBuffer;
|
||||
temp.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,temp,0,1,0);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -1153,11 +1122,11 @@ PRInt32 nsString2::Find(const char* aCString,PRBool aIgnoreCase) const{
|
||||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aCString) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCString);
|
||||
theTempStr.mStr=(char*)aCString;
|
||||
result=nsStr::FindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCString);
|
||||
temp.mStr=(char*)aCString;
|
||||
result=nsStr::FindSubstr(*this,temp,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1174,11 +1143,11 @@ PRInt32 nsString2::Find(const PRUnichar* aString,PRBool aIgnoreCase) const{
|
||||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aString) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mUStr=(PRUnichar*)aString;
|
||||
result=nsStr::FindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eTwoByte);
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
temp.mUStr=(PRUnichar*)aString;
|
||||
result=nsStr::FindSubstr(*this,temp,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1195,6 +1164,18 @@ PRInt32 nsString2::Find(const nsStr& aString,PRBool aIgnoreCase) const{
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for given buffer within this string
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param nsString2 -- buffer to be found
|
||||
* @return offset in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 nsString2::Find(const nsString2& aString,PRBool aIgnoreCase) const{
|
||||
PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,0);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for a given char, starting at given offset
|
||||
*
|
||||
@@ -1219,11 +1200,11 @@ PRInt32 nsString2::FindCharInSet(const char* aCStringSet,PRUint32 anOffset) cons
|
||||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aCStringSet) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCStringSet);
|
||||
theTempStr.mStr=(char*)aCStringSet;
|
||||
result=nsStr::FindCharInSet(*this,theTempStr,PR_FALSE,anOffset);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCStringSet);
|
||||
temp.mStr=(char*)aCStringSet;
|
||||
result=nsStr::FindCharInSet(*this,temp,PR_FALSE,anOffset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1252,11 +1233,11 @@ PRInt32 nsString2::RFindCharInSet(const char* aCStringSet,PRUint32 anOffset) con
|
||||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aCStringSet) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCStringSet);
|
||||
theTempStr.mStr=(char*)aCStringSet;
|
||||
result=nsStr::RFindCharInSet(*this,theTempStr,PR_FALSE,anOffset);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCStringSet);
|
||||
temp.mStr=(char*)aCStringSet;
|
||||
result=nsStr::RFindCharInSet(*this,temp,PR_FALSE,anOffset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1285,6 +1266,18 @@ PRInt32 nsString2::RFind(const nsStr& aString,PRBool aIgnoreCase) const{
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsString2::RFind(const nsString2& aString,PRBool aIgnoreCase) const{
|
||||
PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,0);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
@@ -1297,11 +1290,11 @@ PRInt32 nsString2::RFind(const char* aString,PRBool aIgnoreCase) const{
|
||||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aString) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mStr=(char*)aString;
|
||||
result=nsStr::RFindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
temp.mStr=(char*)aString;
|
||||
result=nsStr::RFindSubstr(*this,temp,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1334,11 +1327,11 @@ PRInt32 nsString2::Compare(const char *aCString,PRBool aIgnoreCase,PRInt32 aLeng
|
||||
NS_ASSERTION(0!=aCString,kNullPointerError);
|
||||
|
||||
if(aCString) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCString);
|
||||
theTempStr.mStr=(char*)aCString;
|
||||
return nsStr::Compare(*this,theTempStr,aLength,aIgnoreCase);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCString);
|
||||
temp.mStr=(char*)aCString;
|
||||
return nsStr::Compare(*this,temp,aLength,aIgnoreCase);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1354,11 +1347,11 @@ PRInt32 nsString2::Compare(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 a
|
||||
NS_ASSERTION(0!=aString,kNullPointerError);
|
||||
|
||||
if(aString) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mUStr=(PRUnichar*)aString;
|
||||
return nsStr::Compare(*this,theTempStr,aLength,aIgnoreCase);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eTwoByte);
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
temp.mUStr=(PRUnichar*)aString;
|
||||
return nsStr::Compare(*this,temp,aLength,aIgnoreCase);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1568,16 +1561,37 @@ PRBool nsString2::IsDigit(PRUnichar aChar) {
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Define the string deallocator class...
|
||||
**************************************************************/
|
||||
class nsStringDeallocator: public nsDequeFunctor{
|
||||
public:
|
||||
virtual void* operator()(void* anObject) {
|
||||
static nsMemoryAgent theAgent;
|
||||
nsString2* aString= (nsString2*)anObject;
|
||||
if(aString){
|
||||
aString->mAgent=&theAgent;
|
||||
delete aString;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* This class, appropriately enough, creates and recycles nsString2 objects..
|
||||
****************************************************************************/
|
||||
|
||||
#if 0
|
||||
|
||||
class nsStringRecycler {
|
||||
public:
|
||||
nsStringRecycler() : mDeque(0) {
|
||||
}
|
||||
|
||||
~nsStringRecycler() {
|
||||
nsStringDeallocator theDeallocator;
|
||||
mDeque.ForEach(theDeallocator); //now delete the strings
|
||||
}
|
||||
|
||||
void Recycle(nsString2* aString) {
|
||||
mDeque.Push(aString);
|
||||
}
|
||||
@@ -1623,7 +1637,6 @@ void nsString2::Recycle(nsString2* aString){
|
||||
GetRecycler().Recycle(aString);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -1690,14 +1703,12 @@ NS_BASE int fputs(const nsString2& aString, FILE* out)
|
||||
*/
|
||||
void nsString2::SelfTest(void) {
|
||||
|
||||
#if 0
|
||||
#ifdef NS_DEBUG
|
||||
static const char* kConstructorError = kConstructorError;
|
||||
static const char* kComparisonError = "Comparision error!";
|
||||
static const char* kEqualsError = "Equals error!";
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
mSelfTested=PR_TRUE;
|
||||
#endif
|
||||
|
||||
eCharSize theSize=eOneByte;
|
||||
|
||||
@@ -1705,8 +1716,18 @@ void nsString2::SelfTest(void) {
|
||||
{
|
||||
{
|
||||
nsString2 theString0("foo",theSize); //watch it construct and destruct
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
nsString2 theString("hello");
|
||||
nsString2 temp1=theString+" there!";
|
||||
nsString2 temp2=theString+'!';
|
||||
nsSubsumeStr temp3=theString+'?';
|
||||
nsString2 temp4(temp3);
|
||||
temp1=temp3;
|
||||
nsSubsumeStr temp5("hello");
|
||||
}
|
||||
|
||||
nsString2 theString1(theSize);
|
||||
nsString2 theString("hello",theSize);
|
||||
nsString2 theString3(theString,theSize);
|
||||
@@ -1721,6 +1742,8 @@ void nsString2::SelfTest(void) {
|
||||
//while we're here, let's try truncation and setting the length.
|
||||
theString3.Truncate(3);
|
||||
theLen=theString3.Length();
|
||||
|
||||
|
||||
theString.SetCapacity(3);
|
||||
const char* theBuffer=theString.GetBuffer();
|
||||
const char* theOther=theBuffer;
|
||||
@@ -1736,12 +1759,17 @@ void nsString2::SelfTest(void) {
|
||||
theString5.StripWhitespace();
|
||||
|
||||
nsString2* theString6=theString5.ToNewString();
|
||||
nsString2::Recycle(theString6);
|
||||
|
||||
char* str=theString5.ToNewCString();
|
||||
delete [] str;
|
||||
|
||||
char buffer[100];
|
||||
theString5.ToCString(buffer,sizeof(buffer)-1);
|
||||
theOther=theString5.GetBuffer();
|
||||
}
|
||||
//try a few numeric conversion routines...
|
||||
|
||||
//try a few numeric conversion routines...
|
||||
{
|
||||
nsString2 str1("10000",theSize);
|
||||
PRInt32 err;
|
||||
@@ -1753,11 +1781,12 @@ void nsString2::SelfTest(void) {
|
||||
{
|
||||
nsString2 theString("hello",theSize);
|
||||
PRUint32 len=theString.Length();
|
||||
PRUnichar ch;
|
||||
for(PRUint32 i=0;i<len;i++) {
|
||||
PRUnichar ch3=theString.CharAt(i);
|
||||
ch=theString.CharAt(i);
|
||||
}
|
||||
PRUnichar ch4=theString.First();
|
||||
PRUnichar ch5=theString.Last();
|
||||
ch=theString.First();
|
||||
ch=theString.Last();
|
||||
}
|
||||
|
||||
//**********************************************
|
||||
@@ -1826,7 +1855,6 @@ void nsString2::SelfTest(void) {
|
||||
temp1.Right(temp2,4);
|
||||
}
|
||||
|
||||
|
||||
//**********************************************
|
||||
//Now let's test the INSERTION methods...
|
||||
//**********************************************
|
||||
@@ -1973,6 +2001,15 @@ void nsString2::SelfTest(void) {
|
||||
pos=find1.BinarySearch('i');
|
||||
pos=find1.BinarySearch('z');
|
||||
}
|
||||
|
||||
{
|
||||
//now let's try a memory allocation test...
|
||||
nsString2 temp;
|
||||
for(int i=0;i<100;i++){
|
||||
temp+="hello ";
|
||||
}
|
||||
int x=5;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1981,14 +2018,6 @@ void nsString2::SelfTest(void) {
|
||||
IMPLEMENTATION NOTES: AUTOSTRING...
|
||||
***********************************************************************/
|
||||
|
||||
void InitAutoStr(nsAutoString2& aDest,nsBufDescriptor& aBufDescriptor){
|
||||
aDest.mAgent=0;
|
||||
aDest.mStr=aBufDescriptor.mStr;
|
||||
aDest.mMultibyte=aBufDescriptor.mMultibyte;
|
||||
aDest.mCapacity=(sizeof(aDest.mBuffer)>>aDest.mMultibyte)-1;
|
||||
aDest.mOwnsBuffer=aBufDescriptor.mOwnsBuffer;
|
||||
AddNullTerminator(aDest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Special case constructor, that allows the consumer to provide
|
||||
@@ -1998,8 +2027,9 @@ void InitAutoStr(nsAutoString2& aDest,nsBufDescriptor& aBufDescriptor){
|
||||
* @param aCurrentLength tells us the current length of the buffer
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(eCharSize aCharSize) : nsString2(aCharSize){
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
mAgent=0;
|
||||
AddNullTerminator(*this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2007,8 +2037,10 @@ nsAutoString2::nsAutoString2(eCharSize aCharSize) : nsString2(aCharSize){
|
||||
* @param anExtBuffer describes an external buffer
|
||||
* @param aCString is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(nsBufDescriptor& aBufDescriptor,const char* aCString) : nsString2(aBufDescriptor.mMultibyte) {
|
||||
InitAutoStr(*this,aBufDescriptor);
|
||||
nsAutoString2::nsAutoString2(nsStr& aStr,const char* aCString) : nsString2(aStr.mMultibyte) {
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aStr.mMultibyte)-1,0,aStr.mMultibyte,PR_FALSE);
|
||||
mAgent=0;
|
||||
AddNullTerminator(*this);
|
||||
Assign(aCString);
|
||||
}
|
||||
|
||||
@@ -2017,8 +2049,9 @@ nsAutoString2::nsAutoString2(nsBufDescriptor& aBufDescriptor,const char* aCStrin
|
||||
* @param aCString is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const char* aCString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
mAgent=0;
|
||||
AddNullTerminator(*this);
|
||||
Assign(aCString);
|
||||
}
|
||||
|
||||
@@ -2026,15 +2059,15 @@ nsAutoString2::nsAutoString2(const char* aCString,eCharSize aCharSize) : nsStrin
|
||||
* Copy construct from ascii c-string
|
||||
* @param aCString is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(char* aCString,PRUint32 aLen,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
nsAutoString2::nsAutoString2(char* aCString,PRUint32 aCapacity,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
mAgent=0;
|
||||
if(assumeOwnership) {
|
||||
nsBufDescriptor theDescriptor(aCString,aLen,eOneByte,PR_TRUE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
nsStr::Initialize(*this,aCString,aCapacity,0,eOneByte,PR_TRUE);
|
||||
}
|
||||
else {
|
||||
nsBufDescriptor theDescriptor(mBuffer,aLen,aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
}
|
||||
AddNullTerminator(*this);
|
||||
Assign(aCString);
|
||||
}
|
||||
|
||||
@@ -2043,8 +2076,9 @@ nsAutoString2::nsAutoString2(char* aCString,PRUint32 aLen,eCharSize aCharSize,PR
|
||||
* @param aString is a ptr to a unistr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const PRUnichar* aString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
@@ -2052,15 +2086,15 @@ nsAutoString2::nsAutoString2(const PRUnichar* aString,eCharSize aCharSize) : nsS
|
||||
* Copy construct from uni-string
|
||||
* @param aString is a ptr to a unistr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(PRUnichar* aString,PRUint32 aLength,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
nsAutoString2::nsAutoString2(PRUnichar* aString,PRUint32 aCapacity,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
mAgent=0;
|
||||
if(assumeOwnership) {
|
||||
nsBufDescriptor theDescriptor((char*)aString,aLength,eTwoByte,PR_TRUE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
nsStr::Initialize(*this,(char*)aString,aCapacity,0,eTwoByte,PR_TRUE);
|
||||
}
|
||||
else {
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
}
|
||||
AddNullTerminator(*this);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
@@ -2070,8 +2104,9 @@ nsAutoString2::nsAutoString2(PRUnichar* aString,PRUint32 aLength,eCharSize aChar
|
||||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const nsStr& aString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
@@ -2080,8 +2115,9 @@ nsAutoString2::nsAutoString2(const nsStr& aString,eCharSize aCharSize) : nsStrin
|
||||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const nsAutoString2& aString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
@@ -2090,8 +2126,9 @@ nsAutoString2::nsAutoString2(const nsAutoString2& aString,eCharSize aCharSize) :
|
||||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const nsString2& aString,eCharSize aCharSize) : nsString2(aCharSize){
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
@@ -2101,11 +2138,22 @@ nsAutoString2::nsAutoString2(const nsString2& aString,eCharSize aCharSize) : nsS
|
||||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(PRUnichar aChar,eCharSize aCharSize) : nsString2(aCharSize){
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
Assign(aChar);
|
||||
}
|
||||
|
||||
/**
|
||||
* construct from a subsumeable string
|
||||
* @update gess 1/4/99
|
||||
* @param reference to a subsumeString
|
||||
*/
|
||||
nsAutoString2::nsAutoString2( nsSubsumeStr& aSubsumeStr) :nsString2(aSubsumeStr.mMultibyte) {
|
||||
mAgent=0;
|
||||
Subsume(*this,aSubsumeStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* deconstruct the autstring
|
||||
* @param
|
||||
@@ -2120,3 +2168,16 @@ void nsAutoString2::SizeOf(nsISizeOfHandler* aHandler) const {
|
||||
aHandler->Add(mCapacity << mMultibyte);
|
||||
}
|
||||
|
||||
nsSubsumeStr::nsSubsumeStr(nsString2& aString) : nsString2() {
|
||||
Subsume(*this,aString);
|
||||
}
|
||||
|
||||
nsSubsumeStr::nsSubsumeStr(nsStr& aString) : nsString2() {
|
||||
Subsume(*this,aString);
|
||||
}
|
||||
|
||||
nsSubsumeStr::nsSubsumeStr(const PRUnichar* aString) : nsString2(aString,eTwoByte) {
|
||||
}
|
||||
|
||||
nsSubsumeStr::nsSubsumeStr(const char* aString) : nsString2(aString,eOneByte) {
|
||||
}
|
||||
|
||||
@@ -20,18 +20,19 @@
|
||||
/***********************************************************************
|
||||
MODULE NOTES:
|
||||
|
||||
This class provides a 1-byte ASCII string implementation that shares
|
||||
a common API with all other strImpl derivatives.
|
||||
This version of the nsString class offers many improvements over the
|
||||
original version:
|
||||
1. Wide and narrow chars
|
||||
2. Allocators
|
||||
3. Much smarter autostrings
|
||||
4. Subsumable strings
|
||||
5. Memory pools and recycling
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef _nsString2
|
||||
#define _nsString2
|
||||
|
||||
//#define nsString2 nsString
|
||||
//#define nsAutoString2 nsAutoString
|
||||
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nscore.h"
|
||||
#include <iostream.h>
|
||||
@@ -46,6 +47,13 @@
|
||||
class nsISizeOfHandler;
|
||||
|
||||
|
||||
#ifdef USE_STRING2
|
||||
#define nsString2 nsString
|
||||
#define nsAutoString2 nsAutoString
|
||||
#endif
|
||||
|
||||
class NS_BASE nsSubsumeStr;
|
||||
|
||||
class NS_BASE nsString2 : public nsStr {
|
||||
|
||||
public:
|
||||
@@ -83,6 +91,12 @@ nsString2(const nsStr&,eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAg
|
||||
*/
|
||||
nsString2(const nsString2& aString);
|
||||
|
||||
/**
|
||||
* This constructor takes a subsumestr
|
||||
* @param reference to subsumestr
|
||||
*/
|
||||
nsString2(nsSubsumeStr& aSubsumeStr);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*
|
||||
@@ -139,16 +153,15 @@ PRBool IsOrdered(void) const;
|
||||
Accessor methods...
|
||||
*********************************************************************/
|
||||
|
||||
char* GetBuffer(void) const;
|
||||
PRUnichar* GetUnicode(void) const;
|
||||
operator PRUnichar*() const {return GetUnicode();}
|
||||
const char* GetBuffer(void) const;
|
||||
const PRUnichar* GetUnicode(void) const;
|
||||
|
||||
|
||||
/**
|
||||
* Get nth character.
|
||||
*/
|
||||
PRUnichar operator[](int anIndex) const;
|
||||
PRUnichar CharAt(int anIndex) const;
|
||||
PRUnichar operator[](PRUint32 anIndex) const;
|
||||
PRUnichar CharAt(PRUint32 anIndex) const;
|
||||
PRUnichar First(void) const;
|
||||
PRUnichar Last(void) const;
|
||||
|
||||
@@ -164,42 +177,42 @@ PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsString2 operator+(const nsStr& aString);
|
||||
nsSubsumeStr operator+(const nsStr& aString);
|
||||
|
||||
/**
|
||||
* Create a new string by appending given string to this
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsString2 operator+(const nsString2& aString);
|
||||
nsSubsumeStr operator+(const nsString2& aString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given buffer.
|
||||
* @param aCString is a ptr to cstring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 operator+(const char* aCString);
|
||||
nsSubsumeStr operator+(const char* aCString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given wide buffer.
|
||||
* @param aString is a ptr to UC-string to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 operator+(const PRUnichar* aString);
|
||||
nsSubsumeStr operator+(const PRUnichar* aString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given char.
|
||||
* @param aChar is a char to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 operator+(char aChar);
|
||||
nsSubsumeStr operator+(char aChar);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given char.
|
||||
* @param aChar is a unichar to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 operator+(PRUnichar aChar);
|
||||
nsSubsumeStr operator+(PRUnichar aChar);
|
||||
|
||||
/**********************************************************************
|
||||
Lexomorphic transforms...
|
||||
@@ -353,7 +366,6 @@ PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=10) const;
|
||||
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);}
|
||||
void Copy(nsString2& aString) const;
|
||||
|
||||
/**
|
||||
* assign given string to this string
|
||||
@@ -380,6 +392,7 @@ 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);}
|
||||
nsString2& operator=(nsSubsumeStr& aSubsumeString);
|
||||
|
||||
/**
|
||||
* Here's a bunch of append mehtods for varying types...
|
||||
@@ -402,8 +415,7 @@ nsString2& operator+=(PRUnichar aChar){return Append(aChar);}
|
||||
*/
|
||||
nsString2& Append(const nsStr& aString) {return Append(aString,aString.mLength);}
|
||||
nsString2& Append(const nsString2& aString) {return Append(aString,aString.mLength);}
|
||||
nsString2& Append(const char* aString) {if(aString) {Append(aString,nsCRT::strlen(aString));} return *this;}
|
||||
nsString2& Append(const PRUnichar* aString) {if(aString) {Append(aString,nsCRT::strlen(aString));} return *this;}
|
||||
|
||||
|
||||
/*
|
||||
* Appends n characters from given string to this,
|
||||
@@ -414,13 +426,13 @@ nsString2& Append(const PRUnichar* aString) {if(aString) {Append(aString,nsCRT::
|
||||
*/
|
||||
nsString2& Append(const nsStr& aString,PRInt32 aCount);
|
||||
nsString2& Append(const nsString2& aString,PRInt32 aCount);
|
||||
nsString2& Append(const char* aString,PRInt32 aCount);
|
||||
nsString2& Append(const PRUnichar* 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,
|
||||
* starting at the leftmost offset.
|
||||
@@ -464,7 +476,7 @@ PRUint32 Right(nsString2& aCopy,PRInt32 aCount) const;
|
||||
* @param aCount -- number of chars to be copied from aCopy
|
||||
* @return number of chars inserted into this.
|
||||
*/
|
||||
nsString2& Insert(nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
|
||||
nsString2& Insert(const nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
|
||||
|
||||
/**
|
||||
* Insert a given string into this string at
|
||||
@@ -519,6 +531,7 @@ PRInt32 BinarySearch(PRUnichar aChar) const;
|
||||
* @param aString is substring to be sought in this
|
||||
* @return offset 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;
|
||||
@@ -554,6 +567,7 @@ PRInt32 RFindCharInSet(const nsString2& aString,PRUint32 anOffset=0) const;
|
||||
* @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,PRBool aIgnoreCase=PR_FALSE,PRUint32 offset=0) const;
|
||||
@@ -675,10 +689,8 @@ static PRBool IsAlpha(PRUnichar ch);
|
||||
*/
|
||||
static PRBool IsDigit(PRUnichar ch);
|
||||
|
||||
#if 0
|
||||
static void Recycle(nsString2* aString);
|
||||
static nsString2* NewString(eCharSize aCharSize=eTwoByte);
|
||||
#endif
|
||||
|
||||
static void SelfTest();
|
||||
virtual void DebugDump(ostream& aStream) const;
|
||||
@@ -701,12 +713,11 @@ ostream& operator<<(ostream& os,nsString2& aString);
|
||||
If the buffer needs to grow, it gets reallocated on the heap.
|
||||
**************************************************************/
|
||||
|
||||
|
||||
class NS_BASE nsAutoString2 : public nsString2 {
|
||||
public:
|
||||
|
||||
nsAutoString2(eCharSize aCharSize=kDefaultCharSize);
|
||||
nsAutoString2(nsBufDescriptor& anExtBuffer,const char* aCString);
|
||||
nsAutoString2(nsStr& anExtBuffer,const char* aCString);
|
||||
|
||||
|
||||
nsAutoString2(const char* aCString,eCharSize aCharSize=kDefaultCharSize);
|
||||
@@ -717,6 +728,7 @@ public:
|
||||
nsAutoString2(const nsStr& aString,eCharSize aCharSize=kDefaultCharSize);
|
||||
nsAutoString2(const nsString2& aString,eCharSize aCharSize=kDefaultCharSize);
|
||||
nsAutoString2(const nsAutoString2& aString,eCharSize aCharSize=kDefaultCharSize);
|
||||
nsAutoString2(nsSubsumeStr& aSubsumeStr);
|
||||
nsAutoString2(PRUnichar aChar,eCharSize aCharSize=kDefaultCharSize);
|
||||
virtual ~nsAutoString2();
|
||||
|
||||
@@ -738,5 +750,28 @@ public:
|
||||
};
|
||||
|
||||
|
||||
/***************************************************************
|
||||
The subsumestr class is very unusual.
|
||||
It differs from a normal string in that it doesn't use normal
|
||||
copy semantics when another string is assign to this.
|
||||
Instead, it "steals" the contents of the source string.
|
||||
|
||||
This is very handy for returning nsString classes as part of
|
||||
an operator+(...) for example, in that it cuts down the number
|
||||
of copy operations that must occur.
|
||||
|
||||
You should probably not use this class unless you really know
|
||||
what you're doing.
|
||||
***************************************************************/
|
||||
class NS_BASE nsSubsumeStr : public nsString2 {
|
||||
public:
|
||||
nsSubsumeStr(nsString2& aString);
|
||||
nsSubsumeStr(nsStr& aString);
|
||||
nsSubsumeStr(const PRUnichar* aString);
|
||||
nsSubsumeStr(const char* aString);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -31,7 +31,12 @@
|
||||
|
||||
#include "nsCRT.h"
|
||||
|
||||
static const PRInt32 kNotFound=-1;
|
||||
#ifndef RICKG_TESTBED
|
||||
#include "nsUnicharUtilCIID.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsICaseConversion.h"
|
||||
#endif
|
||||
|
||||
|
||||
inline PRUnichar GetUnicharAt(const char* aString,PRUint32 anIndex) {
|
||||
return ((PRUnichar*)aString)[anIndex];
|
||||
@@ -57,7 +62,7 @@ inline PRUnichar GetCharAt(const char* aString,PRUint32 anIndex) {
|
||||
*/
|
||||
void ShiftCharsLeft(char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUint32 aCount) {
|
||||
PRUint32 theMax=aLength-anOffset;
|
||||
// PRUint32 theLength=(theMax<aCount) ? theMax : aCount;
|
||||
PRUint32 theLength=(theMax<aCount) ? theMax : aCount;
|
||||
|
||||
char* first= aDest+anOffset+aCount;
|
||||
char* last = aDest+aLength;
|
||||
@@ -102,7 +107,7 @@ void ShiftCharsRight(char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUint32 aCo
|
||||
*/
|
||||
void ShiftDoubleCharsLeft(char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUint32 aCount) {
|
||||
PRUint32 theMax=aLength-anOffset;
|
||||
// PRUint32 theLength=(theMax<aCount) ? theMax : aCount;
|
||||
PRUint32 theLength=(theMax<aCount) ? theMax : aCount;
|
||||
|
||||
PRUnichar* theBuf=(PRUnichar*)aDest;
|
||||
PRUnichar* first= theBuf+anOffset+aCount;
|
||||
@@ -279,7 +284,7 @@ CopyChars gCopyChars[2][2]={
|
||||
* @param aIgnorecase tells us whether to use a case sensitive search
|
||||
* @return index of pos if found, else -1 (kNotFound)
|
||||
*/
|
||||
inline PRInt32 FindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
inline PRInt32 FindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
PRUnichar theCmpChar=(aIgnoreCase ? nsCRT::ToUpper(aChar) : aChar);
|
||||
PRUint32 theIndex=0;
|
||||
for(theIndex=0;theIndex<aLength;theIndex++){
|
||||
@@ -303,7 +308,7 @@ inline PRInt32 FindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,PR
|
||||
* @param aIgnorecase tells us whether to use a case sensitive search
|
||||
* @return index of pos if found, else -1 (kNotFound)
|
||||
*/
|
||||
inline PRInt32 FindChar2(const char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
inline PRInt32 FindChar2(const char* aDest,PRUint32 aLength,PRUint32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
PRUnichar theCmpChar=(aIgnoreCase ? nsCRT::ToUpper(aChar) : aChar);
|
||||
PRUint32 theIndex=0;
|
||||
for(theIndex=0;theIndex<aLength;theIndex++){
|
||||
@@ -329,7 +334,7 @@ inline PRInt32 FindChar2(const char* aDest,PRUint32 aLength,PRUint32 anOffset,PR
|
||||
* @param aIgnorecase tells us whether to use a case sensitive search
|
||||
* @return index of pos if found, else -1 (kNotFound)
|
||||
*/
|
||||
inline PRInt32 RFindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
inline PRInt32 RFindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
PRUnichar theCmpChar=(aIgnoreCase ? nsCRT::ToUpper(aChar) : aChar);
|
||||
PRUint32 theIndex=0;
|
||||
for(theIndex=aLength-1;theIndex>=0;theIndex--){
|
||||
@@ -355,7 +360,7 @@ inline PRInt32 RFindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,P
|
||||
* @param aIgnorecase tells us whether to use a case sensitive search
|
||||
* @return index of pos if found, else -1 (kNotFound)
|
||||
*/
|
||||
inline PRInt32 RFindChar2(const char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
inline PRInt32 RFindChar2(const char* aDest,PRUint32 aLength,PRUint32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
PRUnichar theCmpChar=(aIgnoreCase ? nsCRT::ToUpper(aChar) : aChar);
|
||||
PRUint32 theIndex=0;
|
||||
for(theIndex=aLength-1;theIndex>=0;theIndex--){
|
||||
@@ -368,7 +373,7 @@ inline PRInt32 RFindChar2(const char* aDest,PRUint32 aLength,PRUint32 anOffset,P
|
||||
return kNotFound;
|
||||
}
|
||||
|
||||
typedef PRInt32 (*FindChars)(const char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUnichar aChar,PRBool aIgnoreCase);
|
||||
typedef PRInt32 (*FindChars)(const char* aDest,PRUint32 aLength,PRUint32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase);
|
||||
FindChars gFindChars[]={&FindChar1,&FindChar2};
|
||||
FindChars gRFindChars[]={&RFindChar1,&RFindChar2};
|
||||
|
||||
@@ -496,6 +501,53 @@ PRInt32 ConvertCase1(char* aString,PRUint32 aCount,PRBool aToUpper){
|
||||
return result;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef RICKG_TESTBED
|
||||
class HandleCaseConversionShutdown3 : public nsIShutdownListener {
|
||||
public :
|
||||
NS_IMETHOD OnShutdown(const nsCID& cid, nsISupports* service);
|
||||
HandleCaseConversionShutdown3(void) { NS_INIT_REFCNT(); }
|
||||
virtual ~HandleCaseConversionShutdown3(void) {}
|
||||
NS_DECL_ISUPPORTS
|
||||
};
|
||||
|
||||
static NS_DEFINE_CID(kUnicharUtilCID, NS_UNICHARUTIL_CID);
|
||||
static NS_DEFINE_IID(kICaseConversionIID, NS_ICASECONVERSION_IID);
|
||||
static NS_DEFINE_IID(kIShutdownListenerIID, NS_ISHUTDOWNLISTENER_IID);
|
||||
static nsICaseConversion * gCaseConv = 0;
|
||||
|
||||
NS_IMPL_ISUPPORTS(HandleCaseConversionShutdown3, kIShutdownListenerIID);
|
||||
|
||||
nsresult HandleCaseConversionShutdown3::OnShutdown(const nsCID& cid, nsISupports* service) {
|
||||
if (cid.Equals(kUnicharUtilCID)) {
|
||||
NS_ASSERTION(service == gCaseConv, "wrong service!");
|
||||
if(gCaseConv){
|
||||
gCaseConv->Release();
|
||||
gCaseConv = 0;
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
class CCaseConversionServiceInitializer {
|
||||
public:
|
||||
CCaseConversionServiceInitializer(){
|
||||
mListener = new HandleCaseConversionShutdown3();
|
||||
if(mListener){
|
||||
mListener->AddRef();
|
||||
nsresult result=nsServiceManager::GetService(kUnicharUtilCID, kICaseConversionIID,(nsISupports**) &gCaseConv, mListener);
|
||||
}
|
||||
}
|
||||
protected:
|
||||
HandleCaseConversionShutdown3* mListener;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* This method performs a case conversion the data in the given buffer
|
||||
*
|
||||
@@ -506,14 +558,25 @@ PRInt32 ConvertCase1(char* aString,PRUint32 aCount,PRBool aToUpper){
|
||||
* @return 0
|
||||
*/
|
||||
PRInt32 ConvertCase2(char* aString,PRUint32 aCount,PRBool aToUpper){
|
||||
PRUnichar* cp = (PRUnichar*)aString;
|
||||
PRUnichar* end = cp + aCount-1;
|
||||
PRInt32 result=0;
|
||||
|
||||
typedef PRUnichar chartype;
|
||||
chartype* cp = (chartype*)aString;
|
||||
chartype* end = cp + aCount-1;
|
||||
#ifndef RICKG_TESTBED
|
||||
static CCaseConversionServiceInitializer gCaseConversionServiceInitializer;
|
||||
|
||||
// I18N code begin
|
||||
if(gCaseConv) {
|
||||
nsresult err=(aToUpper) ? gCaseConv->ToUpper(cp, cp, aCount) : gCaseConv->ToLower(cp, cp, aCount);
|
||||
if(NS_SUCCEEDED(err))
|
||||
return 0;
|
||||
}
|
||||
// I18N code end
|
||||
#endif
|
||||
|
||||
|
||||
while (cp <= end) {
|
||||
chartype ch = *cp;
|
||||
PRUnichar ch = *cp;
|
||||
if(aToUpper) {
|
||||
if ((ch >= 'a') && (ch <= 'z')) {
|
||||
*cp = 'A' + (ch - 'a');
|
||||
@@ -549,7 +612,7 @@ CaseConverters gCaseConverters[]={&ConvertCase1,&ConvertCase2};
|
||||
* @return the new length of the given buffer
|
||||
*/
|
||||
PRInt32 StripChars1(char* aString,PRUint32 anOffset,PRUint32 aCount,const char* aSet){
|
||||
// PRInt32 result=0;
|
||||
PRInt32 result=0;
|
||||
|
||||
typedef char chartype;
|
||||
chartype* from = (chartype*)&aString[anOffset];
|
||||
@@ -581,7 +644,7 @@ PRInt32 StripChars1(char* aString,PRUint32 anOffset,PRUint32 aCount,const char*
|
||||
* @return the new length of the given buffer
|
||||
*/
|
||||
PRInt32 StripChars2(char* aString,PRUint32 anOffset,PRUint32 aCount,const char* aSet){
|
||||
// PRInt32 result=0;
|
||||
PRInt32 result=0;
|
||||
|
||||
typedef PRUnichar chartype;
|
||||
chartype* from = (chartype*)&aString[anOffset];
|
||||
@@ -622,7 +685,7 @@ StripChars gStripChars[]={&StripChars1,&StripChars2};
|
||||
* @return the new length of the given buffer
|
||||
*/
|
||||
PRInt32 TrimChars1(char* aString,PRUint32 aLength,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
||||
// PRInt32 result=0;
|
||||
PRInt32 result=0;
|
||||
|
||||
typedef char chartype;
|
||||
chartype* from = (chartype*)aString;
|
||||
@@ -745,7 +808,7 @@ TrimChars gTrimChars[]={&TrimChars1,&TrimChars2};
|
||||
* @return the new length of the given buffer
|
||||
*/
|
||||
PRInt32 CompressChars1(char* aString,PRUint32 aLength,const char* aSet,PRUint32 aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
||||
// PRInt32 result=0;
|
||||
PRInt32 result=0;
|
||||
|
||||
TrimChars1(aString,aLength,aSet,aEliminateLeading,aEliminateTrailing);
|
||||
|
||||
@@ -791,7 +854,7 @@ PRInt32 CompressChars1(char* aString,PRUint32 aLength,const char* aSet,PRUint32
|
||||
* @return the new length of the given buffer
|
||||
*/
|
||||
PRInt32 CompressChars2(char* aString,PRUint32 aLength,const char* aSet,PRUint32 aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
||||
// PRInt32 result=0;
|
||||
PRInt32 result=0;
|
||||
|
||||
TrimChars2(aString,aLength,aSet,aEliminateLeading,aEliminateTrailing);
|
||||
|
||||
|
||||
@@ -31,11 +31,103 @@
|
||||
#include "nsStr.h"
|
||||
#include "bufferRoutines.h"
|
||||
#include "stdio.h" //only used for printf
|
||||
#include "nsDeque.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
|
||||
static const char* kFoolMsg = "Error: Some fool overwrote the shared buffer.";
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// The following is a memory agent who knows how to recycled (pool) freed memory...
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
/**************************************************************
|
||||
Define the char* (pooled) deallocator class...
|
||||
**************************************************************/
|
||||
class nsBufferDeallocator: public nsDequeFunctor{
|
||||
public:
|
||||
virtual void* operator()(void* anObject) {
|
||||
char* aCString= (char*)anObject;
|
||||
delete [] aCString;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess10/30/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
class nsPoolingMemoryAgent : public nsMemoryAgent{
|
||||
public:
|
||||
nsPoolingMemoryAgent() {
|
||||
memset(mPools,0,sizeof(mPools));
|
||||
}
|
||||
|
||||
~nsPoolingMemoryAgent() {
|
||||
nsBufferDeallocator theDeallocator;
|
||||
int i=0;
|
||||
for(i=0;i<10;i++){
|
||||
if(mPools[i]){
|
||||
mPools[i]->ForEach(theDeallocator); //now delete the buffers
|
||||
}
|
||||
delete mPools[i];
|
||||
mPools[i]=0;
|
||||
}
|
||||
}
|
||||
|
||||
virtual PRBool Alloc(nsStr& aDest,PRInt32 aCount) {
|
||||
|
||||
//we're given the acount value in charunits; we have to scale up by the charsize.
|
||||
int theShift=4;
|
||||
PRInt32 theNewCapacity=eDefaultSize;
|
||||
while(theNewCapacity<aCount){
|
||||
theNewCapacity<<=1;
|
||||
theShift++;
|
||||
}
|
||||
|
||||
aDest.mCapacity=theNewCapacity++;
|
||||
theShift=(theShift<<aDest.mMultibyte)-4;
|
||||
if((theShift<12) && (mPools[theShift])){
|
||||
aDest.mStr=(char*)mPools[theShift]->Pop();
|
||||
}
|
||||
if(!aDest.mStr) {
|
||||
//we're given the acount value in charunits; we have to scale up by the charsize.
|
||||
size_t theSize=(theNewCapacity<<aDest.mMultibyte);
|
||||
aDest.mStr=new char[theSize];
|
||||
}
|
||||
aDest.mOwnsBuffer=1;
|
||||
return PR_TRUE;
|
||||
|
||||
}
|
||||
|
||||
virtual PRBool Free(nsStr& aDest){
|
||||
if(aDest.mStr){
|
||||
if(aDest.mOwnsBuffer){
|
||||
int theShift=1;
|
||||
unsigned int theValue=1;
|
||||
while((theValue<<=1)<aDest.mCapacity){
|
||||
theShift++;
|
||||
}
|
||||
theShift-=4;
|
||||
if(theShift<12){
|
||||
if(!mPools[theShift]){
|
||||
mPools[theShift]=new nsDeque(0);
|
||||
}
|
||||
mPools[theShift]->Push(aDest.mStr);
|
||||
}
|
||||
else delete [] aDest.mStr; //it's too big. Just delete it.
|
||||
}
|
||||
aDest.mStr=0;
|
||||
aDest.mOwnsBuffer=0;
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
nsDeque* mPools[16];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -71,6 +163,7 @@ void nsStr::Initialize(nsStr& aDest,eCharSize aCharSize) {
|
||||
aDest.mCapacity=0;
|
||||
aDest.mMultibyte=aCharSize;
|
||||
aDest.mOwnsBuffer=0;
|
||||
aDest.mUnused=0;
|
||||
NS_ASSERTION(aDest.mStr[0]==0,kFoolMsg);
|
||||
}
|
||||
|
||||
@@ -80,14 +173,25 @@ void nsStr::Initialize(nsStr& aDest,eCharSize aCharSize) {
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsIMemoryAgent* GetDefaultAgent(void){
|
||||
static nsIMemoryAgent* gDefaultAgent=0;
|
||||
if(!gDefaultAgent)
|
||||
gDefaultAgent=new nsMemoryAgent();
|
||||
|
||||
NS_ASSERTION(gDefaultAgent,"You MUST always have an allocator!");
|
||||
void nsStr::Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 aLength,eCharSize aCharSize,PRBool aOwnsBuffer){
|
||||
aDest.mStr=(aCString) ? aCString : GetSharedEmptyBuffer();
|
||||
aDest.mLength=aLength;
|
||||
aDest.mCapacity=aCapacity;
|
||||
aDest.mMultibyte=aCharSize;
|
||||
aDest.mOwnsBuffer=aOwnsBuffer;
|
||||
aDest.mUnused=0;
|
||||
}
|
||||
|
||||
return gDefaultAgent;
|
||||
/**
|
||||
*
|
||||
* @update gess10/30/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsIMemoryAgent* GetDefaultAgent(void){
|
||||
// static nsPoolingMemoryAgent gDefaultAgent;
|
||||
static nsMemoryAgent gDefaultAgent;
|
||||
return (nsIMemoryAgent*)&gDefaultAgent;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,20 +214,6 @@ void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess11/12/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRUnichar nsStr::GetCharAt(const nsStr& aDest,PRUint32 anIndex) {
|
||||
PRUnichar result=0;
|
||||
if((anIndex>=0) && (anIndex<aDest.mLength)) {
|
||||
result=(eTwoByte==aDest.mMultibyte) ? aDest.mUStr[anIndex] : aDest.mStr[anIndex];
|
||||
}//if
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method gets called when the internal buffer needs
|
||||
@@ -155,8 +245,8 @@ void nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAgen
|
||||
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
|
||||
EnsureCapacity(theTempStr,aNewLength,theAgent);
|
||||
|
||||
if(0<aDest.mLength) {
|
||||
Append(theTempStr,aDest,0,aDest.mLength,anAgent);
|
||||
if(aDest.mLength) {
|
||||
Append(theTempStr,aDest,0,aDest.mLength,theAgent);
|
||||
}
|
||||
theAgent->Free(aDest);
|
||||
aDest.mStr = theTempStr.mStr;
|
||||
@@ -182,13 +272,12 @@ void nsStr::Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 a
|
||||
/**
|
||||
* This method appends the given nsStr to this one. Note that we have to
|
||||
* pay attention to the underlying char-size of both structs.
|
||||
* @update gess 04/04/99
|
||||
* @update gess10/30/98
|
||||
* @param aDest is the nsStr to be manipulated
|
||||
* @param aSource is where char are copied from
|
||||
* @aCount is the number of bytes to be copied
|
||||
*/
|
||||
void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){
|
||||
|
||||
if(anOffset<aSource.mLength){
|
||||
PRUint32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
|
||||
PRUint32 theLength=(anOffset+theRealLen<aSource.mLength) ? theRealLen : (aSource.mLength-anOffset);
|
||||
@@ -221,30 +310,30 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin
|
||||
// 1. You're inserting chars into an empty string (assign)
|
||||
// 2. You're inserting onto the end of a string (append)
|
||||
// 3. You're inserting onto the 1..n-1 pos of a string (the hard case).
|
||||
if((0<aSource.mLength) && (aDestOffset<aDest.mLength-1)){
|
||||
if(0<aSource.mLength){
|
||||
ToRange(aDestOffset,0,aDest.mLength);
|
||||
if(aDest.mLength){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
if(aSrcOffset<aSource.mLength-1) {
|
||||
PRInt32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
|
||||
PRInt32 theLength=(aSrcOffset+theRealLen<aSource.mLength) ? theRealLen : (aSource.mLength-aSrcOffset);
|
||||
//ToRange(aSrcOffset,0,aSource.mLength-1);
|
||||
PRInt32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
|
||||
PRInt32 theLength=(aSrcOffset+theRealLen<aSource.mLength) ? theRealLen : (aSource.mLength-aSrcOffset);
|
||||
|
||||
if(aSrcOffset<aSource.mLength) {
|
||||
//here's the only new case we have to handle.
|
||||
//chars are really being inserted into our buffer...
|
||||
GrowCapacity(aDest,aDest.mLength+theLength,anAgent);
|
||||
if(aSrcOffset<aSource.mLength) {
|
||||
//here's the only new case we have to handle.
|
||||
//chars are really being inserted into our buffer...
|
||||
GrowCapacity(aDest,aDest.mLength+theLength,anAgent);
|
||||
|
||||
//shift the chars right by theDelta...
|
||||
(*gShiftChars[aDest.mMultibyte][PR_TRUE])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
|
||||
//shift the chars right by theDelta...
|
||||
(*gShiftChars[aDest.mMultibyte][PR_TRUE])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
|
||||
|
||||
//now insert new chars, starting at offset
|
||||
(*gCopyChars[aSource.mMultibyte][aDest.mMultibyte])(aDest.mStr,aDestOffset,aSource.mStr,aSrcOffset,theLength);
|
||||
//now insert new chars, starting at offset
|
||||
(*gCopyChars[aSource.mMultibyte][aDest.mMultibyte])(aDest.mStr,aDestOffset,aSource.mStr,aSrcOffset,theLength);
|
||||
|
||||
//finally, make sure to update the string length...
|
||||
aDest.mLength+=theLength;
|
||||
//finally, make sure to update the string length...
|
||||
aDest.mLength+=theLength;
|
||||
|
||||
}//if
|
||||
//else nothing to do!
|
||||
}
|
||||
}//if
|
||||
//else nothing to do!
|
||||
}
|
||||
else Append(aDest,aSource,0,aCount,anAgent);
|
||||
}
|
||||
@@ -260,22 +349,20 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin
|
||||
* @param aDestOffset is where in aDest deletion is to occur
|
||||
* @param aCount is the number of chars to be deleted in aDest
|
||||
*/
|
||||
void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){
|
||||
if(0<aCount){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAgent* anAgent){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
|
||||
PRInt32 theDelta=aDest.mLength-aDestOffset;
|
||||
PRInt32 theLength=(theDelta<aCount) ? theDelta : aCount;
|
||||
PRUint32 theDelta=aDest.mLength-aDestOffset;
|
||||
PRUint32 theLength=(theDelta<aCount) ? theDelta : aCount;
|
||||
|
||||
if(aDestOffset+theLength<aDest.mLength) {
|
||||
if(aDestOffset+theLength<aDest.mLength) {
|
||||
|
||||
//if you're here, it means we're cutting chars out of the middle of the string...
|
||||
//so shift the chars left by theLength...
|
||||
(*gShiftChars[aDest.mMultibyte][PR_FALSE])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
|
||||
aDest.mLength-=theLength;
|
||||
}
|
||||
else Truncate(aDest,aDestOffset,anAgent);
|
||||
}//if
|
||||
//if you're here, it means we're cutting chars out of the middle of the string...
|
||||
//so shift the chars left by theLength...
|
||||
(*gShiftChars[aDest.mMultibyte][PR_FALSE])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
|
||||
aDest.mLength-=theLength;
|
||||
}
|
||||
else Truncate(aDest,aDestOffset,anAgent);
|
||||
}//if
|
||||
}
|
||||
|
||||
@@ -343,28 +430,28 @@ void nsStr::CompressSet(nsStr& aDest,const char* aSet,PRUint32 aChar,PRBool aEli
|
||||
**************************************************************/
|
||||
|
||||
|
||||
PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool /*aIgnoreCase*/,PRUint32 anOffset) {
|
||||
PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 index=anOffset-1;
|
||||
PRInt32 theMax=aDest.mLength-aTarget.mLength;
|
||||
if((aDest.mLength>0) && (aTarget.mLength>0)){
|
||||
PRInt32 theNewStartPos=-1;
|
||||
PRUnichar theFirstTargetChar=nsStr::GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=nsStr::GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRUnichar theFirstTargetChar=GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRInt32 theTargetMax=aTarget.mLength;
|
||||
while(++index<=theMax) {
|
||||
PRInt32 theSubIndex=-1;
|
||||
PRBool matches=PR_TRUE;
|
||||
while((++theSubIndex<theTargetMax) && (matches)){
|
||||
PRUnichar theChar=nsStr::GetCharAt(aDest,index+theSubIndex);
|
||||
PRUnichar theChar=GetCharAt(aDest,index+theSubIndex);
|
||||
if(theSubIndex>0) {
|
||||
if(theFirstTargetChar==theChar){
|
||||
PRUnichar theDestJumpChar=nsStr::GetCharAt(aDest,index+theTargetMax);
|
||||
PRUnichar theDestJumpChar=GetCharAt(aDest,index+theTargetMax);
|
||||
if(theDestJumpChar==theLastTargetChar) {
|
||||
theNewStartPos=index; //this lets us jump ahead during our search where possible.
|
||||
}//if
|
||||
}//if
|
||||
}//if
|
||||
PRUnichar theTargetChar=nsStr::GetCharAt(aTarget,theSubIndex);
|
||||
PRUnichar theTargetChar=GetCharAt(aTarget,theSubIndex);
|
||||
matches=PRBool(theChar==theTargetChar);
|
||||
}
|
||||
if(matches)
|
||||
@@ -384,8 +471,8 @@ PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool /*aIgn
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsStr::FindChar(const nsStr& aDest, PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase);
|
||||
PRInt32 nsStr::FindChar(const nsStr& aDest,const PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,0,aChar,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -415,12 +502,12 @@ PRInt32 nsStr::FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnore
|
||||
**************************************************************/
|
||||
|
||||
|
||||
PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool /*aIgnoreCase*/,PRUint32 anOffset) {
|
||||
PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 index=(anOffset ? anOffset : aDest.mLength-aTarget.mLength+1);
|
||||
if((aDest.mLength>0) && (aTarget.mLength>0)){
|
||||
PRInt32 theNewStartPos=-1;
|
||||
PRUnichar theFirstTargetChar=nsStr::GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=nsStr::GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRUnichar theFirstTargetChar=GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRInt32 theTargetMax=aTarget.mLength;
|
||||
|
||||
while(index--) {
|
||||
@@ -429,16 +516,16 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool /*aIg
|
||||
|
||||
if(anOffset+aTarget.mLength<=aDest.mLength) {
|
||||
while((++theSubIndex<theTargetMax) && (matches)){
|
||||
PRUnichar theChar=nsStr::GetCharAt(aDest,index+theSubIndex);
|
||||
PRUnichar theChar=GetCharAt(aDest,index+theSubIndex);
|
||||
if(theSubIndex>0) {
|
||||
if(theFirstTargetChar==theChar){
|
||||
PRUnichar theDestJumpChar=nsStr::GetCharAt(aDest,index+theTargetMax);
|
||||
PRUnichar theDestJumpChar=GetCharAt(aDest,index+theTargetMax);
|
||||
if(theDestJumpChar==theLastTargetChar) {
|
||||
theNewStartPos=index; //this lets us jump ahead during our search where possible.
|
||||
}//if
|
||||
}//if
|
||||
}//if
|
||||
PRUnichar theTargetChar=nsStr::GetCharAt(aTarget,theSubIndex);
|
||||
PRUnichar theTargetChar=GetCharAt(aTarget,theSubIndex);
|
||||
matches=PRBool(theChar==theTargetChar);
|
||||
} //while
|
||||
} //if
|
||||
@@ -459,8 +546,8 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool /*aIg
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsStr::RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gRFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase);
|
||||
PRInt32 nsStr::RFindChar(const nsStr& aDest,const PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gRFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,0,aChar,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -472,11 +559,11 @@ PRInt32 nsStr::RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,
|
||||
* @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) {
|
||||
PRUnichar theChar=GetCharAt(aDest,PRUint32(offset));
|
||||
PRUnichar theChar=GetCharAt(aDest,offset);
|
||||
thePos=gRFindChars[aSet.mMultibyte](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase);
|
||||
if(kNotFound!=thePos)
|
||||
return offset;
|
||||
@@ -491,7 +578,7 @@ PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnor
|
||||
* @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 nsStr::Compare(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) {
|
||||
int minlen=(aSource.mLength<aDest.mLength) ? aSource.mLength : aDest.mLength;
|
||||
|
||||
if(0==minlen) {
|
||||
|
||||
@@ -27,8 +27,6 @@
|
||||
We chose the option B for performance reasons.
|
||||
|
||||
2 Our internal buffer always holds capacity+1 bytes.
|
||||
3. Note that our internal format for this class makes our memory
|
||||
layout compatible with BStrings.
|
||||
|
||||
The nsStr struct is a simple structure (no methods) that contains
|
||||
the necessary info to be described as a string. This simple struct
|
||||
@@ -44,41 +42,13 @@
|
||||
#ifndef _nsStr
|
||||
#define _nsStr
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nscore.h"
|
||||
#include "nsCore.h"
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
enum eCharSize {eOneByte=0,eTwoByte=1};
|
||||
#define kDefaultCharSize eTwoByte
|
||||
|
||||
|
||||
union UStrPtr {
|
||||
char* mCharBuf;
|
||||
PRUnichar* mUnicharBuf;
|
||||
};
|
||||
|
||||
/**************************************************************************
|
||||
Here comes the nsBufDescriptor class which describes buffer properties.
|
||||
**************************************************************************/
|
||||
|
||||
struct nsBufDescriptor {
|
||||
nsBufDescriptor(char* aBuffer,PRUint32 aBufferSize,eCharSize aCharSize,PRBool aOwnsBuffer) {
|
||||
mStr=aBuffer;
|
||||
mMultibyte=aCharSize;
|
||||
mCapacity=(aBufferSize>>mMultibyte)-1;
|
||||
mOwnsBuffer=aOwnsBuffer;
|
||||
}
|
||||
|
||||
PRUint32 mCapacity;
|
||||
PRBool mOwnsBuffer;
|
||||
eCharSize mMultibyte;
|
||||
// UStrPtr mStr;
|
||||
union {
|
||||
char* mStr;
|
||||
PRUnichar* mUStr;
|
||||
};
|
||||
};
|
||||
const PRInt32 kNotFound = -1;
|
||||
|
||||
|
||||
class nsIMemoryAgent;
|
||||
@@ -97,6 +67,15 @@ struct nsStr {
|
||||
*/
|
||||
static void Initialize(nsStr& aDest,eCharSize aCharSize);
|
||||
|
||||
/**
|
||||
* This method initializes an nsStr for use
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aString is the nsStr to be initialized
|
||||
* @param aCharSize tells us the requested char size (1 or 2 bytes)
|
||||
*/
|
||||
static void Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 aLength,eCharSize aCharSize,PRBool aOwnsBuffer);
|
||||
|
||||
/**
|
||||
* This method destroys the given nsStr, and *MAY*
|
||||
* deallocate it's memory depending on the setting
|
||||
@@ -166,7 +145,7 @@ struct nsStr {
|
||||
* @param aCount tells us the (max) # of chars to delete
|
||||
* @param anAgent is the allocator to be used for alloc/free operations
|
||||
*/
|
||||
static void Delete(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0);
|
||||
static void Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAgent* anAgent=0);
|
||||
|
||||
/**
|
||||
* This method is used to truncate the given string.
|
||||
@@ -254,21 +233,20 @@ struct nsStr {
|
||||
static PRInt32 RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset);
|
||||
static PRInt32 RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRUint32 anOffset);
|
||||
|
||||
/**
|
||||
* This method is used to access a given char in the given string
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the nsStr to be appended to
|
||||
* @param anIndex tells us where in dest to get the char from
|
||||
* @return the given char, or 0 if anIndex is out of range
|
||||
*/
|
||||
static PRUnichar GetCharAt(const nsStr& aDest,PRUint32 anIndex);
|
||||
|
||||
PRUint32 mLength : 30;
|
||||
eCharSize mMultibyte : 2;
|
||||
#ifdef NS_DEBUG
|
||||
PRUint32 mLength;
|
||||
eCharSize mMultibyte;
|
||||
PRUint32 mCapacity;
|
||||
PRUint32 mOwnsBuffer;
|
||||
PRUint32 mUnused;
|
||||
#else
|
||||
PRUint32 mLength: 30;
|
||||
eCharSize mMultibyte: 2;
|
||||
PRUint32 mCapacity: 30;
|
||||
PRUint32 mOwnsBuffer: 1;
|
||||
PRUint32 mUnused: 1;
|
||||
PRUint32 mOwnsBuffer: 1;
|
||||
PRUint32 mUnused: 1;
|
||||
#endif
|
||||
union {
|
||||
char* mStr;
|
||||
PRUnichar* mUStr;
|
||||
@@ -307,6 +285,21 @@ inline void AddNullTerminator(nsStr& aDest) {
|
||||
else aDest.mStr[aDest.mLength]=0;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to access a given char in the given string
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the nsStr to be appended to
|
||||
* @param anIndex tells us where in dest to get the char from
|
||||
* @return the given char, or 0 if anIndex is out of range
|
||||
*/
|
||||
inline PRUnichar GetCharAt(const nsStr& aDest,PRUint32 anIndex){
|
||||
if(anIndex<aDest.mLength) {
|
||||
return (eTwoByte==aDest.mMultibyte) ? aDest.mUStr[anIndex] : aDest.mStr[anIndex];
|
||||
}//if
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
class nsIMemoryAgent {
|
||||
@@ -317,25 +310,18 @@ public:
|
||||
};
|
||||
|
||||
class nsMemoryAgent : public nsIMemoryAgent {
|
||||
enum eDelta{eGrowthDelta=8};
|
||||
protected:
|
||||
enum eDelta{eDefaultSize=16};
|
||||
public:
|
||||
|
||||
virtual PRBool Alloc(nsStr& aDest,PRInt32 aCount) {
|
||||
|
||||
//we're given the acount value in charunits; we have to scale up by the charsize.
|
||||
|
||||
PRInt32 theNewCapacity;
|
||||
if (aDest.mCapacity > 64) {
|
||||
// When the string starts getting large, double the capacity as we grow.
|
||||
theNewCapacity = aDest.mCapacity * 2;
|
||||
if (theNewCapacity < aCount) {
|
||||
theNewCapacity = aDest.mCapacity + aCount;
|
||||
}
|
||||
} else {
|
||||
// When the string is small, keep it's capacity a multiple of kGrowthDelta
|
||||
PRInt32 unitDelta=(aCount/eGrowthDelta)+1;
|
||||
theNewCapacity=unitDelta*eGrowthDelta;
|
||||
//we're given the acount value in charunits; now scale up to next multiple.
|
||||
PRInt32 theNewCapacity=eDefaultSize;
|
||||
while(theNewCapacity<aCount){
|
||||
theNewCapacity<<=1;
|
||||
}
|
||||
|
||||
|
||||
aDest.mCapacity=theNewCapacity++;
|
||||
size_t theSize=(theNewCapacity<<aDest.mMultibyte);
|
||||
aDest.mStr=new char[theSize];
|
||||
@@ -362,6 +348,5 @@ public:
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -30,8 +30,8 @@
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef _NSSTRING
|
||||
#define _NSSTRING
|
||||
#ifndef _nsString1
|
||||
#define _nsString1
|
||||
|
||||
|
||||
#include "prtypes.h"
|
||||
@@ -39,9 +39,18 @@
|
||||
#include "nsIAtom.h"
|
||||
#include <iostream.h>
|
||||
#include <stdio.h>
|
||||
#include "nsStr.h"
|
||||
|
||||
#ifndef USE_STRING2
|
||||
#define nsString1 nsString
|
||||
#define nsAutoString1 nsAutoString
|
||||
#else
|
||||
#include "nsString2.h" //get new string class
|
||||
#endif
|
||||
|
||||
class nsISizeOfHandler;
|
||||
|
||||
class NS_BASE nsString {
|
||||
class NS_BASE nsString1 {
|
||||
public:
|
||||
|
||||
/**
|
||||
@@ -50,30 +59,30 @@ class NS_BASE nsString {
|
||||
* was to allow developers direct access to the underlying buffer for
|
||||
* performance reasons.
|
||||
*/
|
||||
nsString();
|
||||
nsString1();
|
||||
|
||||
/**
|
||||
* This constructor accepts an isolatin string
|
||||
* @param an ascii is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsString(const char* aCString);
|
||||
nsString1(const char* aCString);
|
||||
|
||||
/**
|
||||
* This is our copy constructor
|
||||
* @param reference to another nsString
|
||||
* @param reference to another nsString1
|
||||
*/
|
||||
nsString(const nsString&);
|
||||
nsString1(const nsString1&);
|
||||
|
||||
/**
|
||||
* Constructor from a unicode string
|
||||
* @param anicodestr pts to a unicode string
|
||||
*/
|
||||
nsString(const PRUnichar* aUnicode);
|
||||
nsString1(const PRUnichar* aUnicode);
|
||||
|
||||
/**
|
||||
* Virtual Destructor
|
||||
*/
|
||||
virtual ~nsString();
|
||||
virtual ~nsString1();
|
||||
|
||||
|
||||
/**
|
||||
@@ -136,14 +145,14 @@ const PRUnichar* GetUnicode(void) const;
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
operator const PRUnichar*() const;
|
||||
//operator const PRUnichar*() const;
|
||||
|
||||
/**
|
||||
* Retrieve unicode char at given index
|
||||
* @param offset into string
|
||||
* @return PRUnichar* to internal string
|
||||
*/
|
||||
PRUnichar operator()(PRInt32 anIndex) const;
|
||||
//PRUnichar operator()(PRInt32 anIndex) const;
|
||||
|
||||
/**
|
||||
* Retrieve reference to unicode char at given index
|
||||
@@ -183,35 +192,35 @@ PRBool SetCharAt(PRUnichar aChar,PRInt32 anIndex);
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsString operator+(const nsString& aString);
|
||||
nsString1 operator+(const nsString1& aString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given buffer.
|
||||
* @param aCString is a ptr to cstring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString operator+(const char* aCString);
|
||||
nsString1 operator+(const char* aCString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given char.
|
||||
* @param aChar is a char to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString operator+(char aChar);
|
||||
nsString1 operator+(char aChar);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given buffer.
|
||||
* @param aStr unichar buffer to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString operator+(const PRUnichar* aBuffer);
|
||||
nsString1 operator+(const PRUnichar* aBuffer);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given char.
|
||||
* @param aChar is a unichar to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString operator+(PRUnichar aChar);
|
||||
nsString1 operator+(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* Converts all chars in internal string to lower
|
||||
@@ -221,7 +230,7 @@ void ToLowerCase();
|
||||
/**
|
||||
* Converts all chars in given string to lower
|
||||
*/
|
||||
void ToLowerCase(nsString& aString) const;
|
||||
void ToLowerCase(nsString1& aString) const;
|
||||
|
||||
/**
|
||||
* Converts all chars in given string to upper
|
||||
@@ -237,13 +246,13 @@ void ToUCS2(PRInt32 aStartOffset);
|
||||
/**
|
||||
* Converts all chars in internal string to upper
|
||||
*/
|
||||
void ToUpperCase(nsString& aString) const;
|
||||
void ToUpperCase(nsString1& aString) const;
|
||||
|
||||
/**
|
||||
* Creates a duplicate clone (ptr) of this string.
|
||||
* @return ptr to clone of this string
|
||||
*/
|
||||
nsString* ToNewString() const;
|
||||
nsString1* ToNewString() const;
|
||||
|
||||
/**
|
||||
* Creates an ascii clone of this string
|
||||
@@ -265,7 +274,7 @@ char* ToCString(char* aBuf,PRInt32 aBufLength) const;
|
||||
* @param aString to hold copy of this
|
||||
* @return nada.
|
||||
*/
|
||||
void Copy(nsString& aString) const;
|
||||
void Copy(nsString1& aString) const;
|
||||
|
||||
/**
|
||||
* Creates an unichar clone of this string
|
||||
@@ -298,79 +307,72 @@ PRInt32 ToInteger(PRInt32* aErrorCode,PRInt32 aRadix=10) const;
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString& SetString(const PRUnichar* aStr,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* assign given char* to this string
|
||||
* @param aCString: buffer to be assigned to this
|
||||
* @param alength is the length of the given str (or -1)
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString& SetString(const char* aCString,PRInt32 aLength=-1);
|
||||
nsString1& SetString(const PRUnichar* aStr,PRInt32 aLength=-1);
|
||||
nsString1& SetString(const char* aCString,PRInt32 aLength=-1);
|
||||
nsString1& SetString(const nsString1& aString);
|
||||
|
||||
/**
|
||||
* assign given string to this one
|
||||
* @param aString: string to be added to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator=(const nsString& aString);
|
||||
nsString1& operator=(const nsString1& aString);
|
||||
|
||||
/**
|
||||
* assign given char* to this string
|
||||
* @param aCString: buffer to be assigned to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator=(const char* aCString);
|
||||
nsString1& operator=(const char* aCString);
|
||||
|
||||
/**
|
||||
* assign given char to this string
|
||||
* @param aChar: char to be assignd to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator=(char aChar);
|
||||
nsString1& operator=(char aChar);
|
||||
|
||||
/**
|
||||
* assign given unichar* to this string
|
||||
* @param aBuffer: unichar buffer to be assigned to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator=(const PRUnichar* aBuffer);
|
||||
nsString1& operator=(const PRUnichar* aBuffer);
|
||||
|
||||
/**
|
||||
* assign given char to this string
|
||||
* @param aChar: char to be assignd to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator=(PRUnichar aChar);
|
||||
nsString1& operator=(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @param aString : string to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator+=(const nsString& aString);
|
||||
nsString1& operator+=(const nsString1& aString);
|
||||
|
||||
/**
|
||||
* append given buffer to this string
|
||||
* @param aCString: buffer to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator+=(const char* aCString);
|
||||
nsString1& operator+=(const char* aCString);
|
||||
|
||||
/**
|
||||
* append given buffer to this string
|
||||
* @param aBuffer: buffer to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator+=(const PRUnichar* aBuffer);
|
||||
nsString1& operator+=(const PRUnichar* aBuffer);
|
||||
|
||||
/**
|
||||
* append given char to this string
|
||||
* @param aChar: char to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator+=(PRUnichar aChar);
|
||||
nsString1& operator+=(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
@@ -379,7 +381,7 @@ nsString& operator+=(PRUnichar aChar);
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(const nsString& aString,PRInt32 aLength=-1);
|
||||
nsString1& Append(const nsString1& aString,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
@@ -388,14 +390,14 @@ nsString& Append(const nsString& aString,PRInt32 aLength=-1);
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(const char* aCString,PRInt32 aLength=-1);
|
||||
nsString1& Append(const char* aCString,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @param aString : string to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(char aChar);
|
||||
nsString1& Append(char aChar);
|
||||
|
||||
/**
|
||||
* append given unichar buffer to this string
|
||||
@@ -404,14 +406,14 @@ nsString& Append(char aChar);
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(const PRUnichar* aBuffer,PRInt32 aLength=-1);
|
||||
nsString1& Append(const PRUnichar* aBuffer,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* append given unichar character to this string
|
||||
* @param aChar is the char to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(PRUnichar aChar);
|
||||
nsString1& Append(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* Append an integer onto this string
|
||||
@@ -419,14 +421,14 @@ nsString& Append(PRUnichar aChar);
|
||||
* @param aRadix specifies 8,10,16
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(PRInt32 aInteger,PRInt32 aRadix); //radix=8,10 or 16
|
||||
nsString1& Append(PRInt32 aInteger,PRInt32 aRadix); //radix=8,10 or 16
|
||||
|
||||
/**
|
||||
* Append a float value onto this string
|
||||
* @param aFloat is the float to be appended
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(float aFloat);
|
||||
nsString1& Append(float aFloat);
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
@@ -437,7 +439,7 @@ nsString& Append(float aFloat);
|
||||
* @param aCount -- number of chars to copy
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Left(nsString& aCopy,PRInt32 aCount) const;
|
||||
PRInt32 Left(nsString1& aCopy,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
@@ -449,7 +451,7 @@ PRInt32 Left(nsString& aCopy,PRInt32 aCount) const;
|
||||
* @param anOffset -- position where copying begins
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Mid(nsString& aCopy,PRInt32 anOffset,PRInt32 aCount) const;
|
||||
PRInt32 Mid(nsString1& aCopy,PRInt32 anOffset,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
@@ -460,7 +462,7 @@ PRInt32 Mid(nsString& aCopy,PRInt32 anOffset,PRInt32 aCount) const;
|
||||
* @param aCount -- number of chars to copy
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Right(nsString& aCopy,PRInt32 aCount) const;
|
||||
PRInt32 Right(nsString1& aCopy,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* This method inserts n chars from given string into this
|
||||
@@ -471,7 +473,7 @@ PRInt32 Right(nsString& aCopy,PRInt32 aCount) const;
|
||||
* @param aCount -- number of chars to be copied from aCopy
|
||||
* @return number of chars inserted into this.
|
||||
*/
|
||||
PRInt32 Insert(const nsString& aCopy,PRInt32 anOffset,PRInt32 aCount=-1);
|
||||
PRInt32 Insert(const nsString1& aCopy,PRInt32 anOffset,PRInt32 aCount=-1);
|
||||
|
||||
/**
|
||||
* Insert a single unicode char into this string at
|
||||
@@ -491,7 +493,7 @@ PRInt32 Insert(PRUnichar aChar,PRInt32 anOffset);
|
||||
* @param aCount -- number of chars to be cut
|
||||
* @return *this
|
||||
*/
|
||||
nsString& Cut(PRInt32 anOffset,PRInt32 aCount);
|
||||
nsString1& Cut(PRInt32 anOffset,PRInt32 aCount);
|
||||
|
||||
/**
|
||||
* This method is used to remove all occurances of the
|
||||
@@ -500,7 +502,7 @@ nsString& Cut(PRInt32 anOffset,PRInt32 aCount);
|
||||
* @param aSet -- characters to be cut from this
|
||||
* @return *this
|
||||
*/
|
||||
nsString& StripChars(const char* aSet);
|
||||
nsString1& StripChars(const char* aSet);
|
||||
|
||||
/**
|
||||
* This method is used to replace all occurances of the
|
||||
@@ -509,14 +511,14 @@ nsString& StripChars(const char* aSet);
|
||||
* @param
|
||||
* @return *this
|
||||
*/
|
||||
nsString& ReplaceChar(PRUnichar aSourceChar, PRUnichar aDestChar);
|
||||
nsString1& ReplaceChar(PRUnichar aSourceChar, PRUnichar aDestChar);
|
||||
|
||||
/**
|
||||
* This method strips whitespace throughout the string
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
nsString& StripWhitespace();
|
||||
nsString1& StripWhitespace();
|
||||
|
||||
/**
|
||||
* This method trims characters found in aTrimSet from
|
||||
@@ -526,7 +528,7 @@ nsString& StripWhitespace();
|
||||
* both ends
|
||||
* @return this
|
||||
*/
|
||||
nsString& Trim(const char* aSet,
|
||||
nsString1& Trim(const char* aSet,
|
||||
PRBool aEliminateLeading=PR_TRUE,
|
||||
PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
@@ -539,7 +541,7 @@ nsString& Trim(const char* aSet,
|
||||
* @param aEliminateTrailing controls stripping of trailing ws
|
||||
* @return this
|
||||
*/
|
||||
nsString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,
|
||||
nsString1& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,
|
||||
PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
/**
|
||||
@@ -588,7 +590,7 @@ PRInt32 BinarySearch(PRUnichar aChar) const;
|
||||
*/
|
||||
PRInt32 Find(const char* aString) const;
|
||||
PRInt32 Find(const PRUnichar* aString) const;
|
||||
PRInt32 Find(const nsString& aString) const;
|
||||
PRInt32 Find(const nsString1& aString) const;
|
||||
|
||||
/**
|
||||
* Search for given char within this string
|
||||
@@ -606,7 +608,7 @@ PRInt32 Find(PRUnichar aChar,PRInt32 offset=0) const;
|
||||
* @return -1 if not found, else the offset in this
|
||||
*/
|
||||
PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 FindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 FindCharInSet(nsString1& aString,PRInt32 anOffset=0) const;
|
||||
|
||||
/**
|
||||
* This method searches this string for the last character
|
||||
@@ -616,7 +618,7 @@ PRInt32 FindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
||||
* @return -1 if not found, else the offset in this
|
||||
*/
|
||||
PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 RFindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 RFindCharInSet(nsString1& aString,PRInt32 anOffset=0) const;
|
||||
|
||||
|
||||
/**
|
||||
@@ -627,7 +629,7 @@ PRInt32 RFindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
||||
*/
|
||||
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFind(const nsString1& aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
|
||||
/**
|
||||
* This methods scans the string backwards, looking for the given char
|
||||
@@ -648,7 +650,7 @@ PRInt32 RFind(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
* @param aIgnoreCase tells us how to treat case
|
||||
* @return -1,0,1
|
||||
*/
|
||||
virtual PRInt32 Compare(const nsString &aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
virtual PRInt32 Compare(const nsString1 &aString,PRBool aIgnoreCase=PR_FALSE) 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;
|
||||
|
||||
@@ -657,7 +659,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 nsString1 &aString) const;
|
||||
PRBool operator==(const char *aString) const;
|
||||
PRBool operator==(const PRUnichar* aString) const;
|
||||
PRBool operator==(PRUnichar* aString) const;
|
||||
@@ -667,7 +669,7 @@ PRBool operator==(PRUnichar* aString) const;
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE
|
||||
*/
|
||||
PRBool operator!=(const nsString &aString) const;
|
||||
PRBool operator!=(const nsString1 &aString) const;
|
||||
PRBool operator!=(const char *aString) const;
|
||||
PRBool operator!=(const PRUnichar* aString) const;
|
||||
|
||||
@@ -676,7 +678,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 nsString1 &aString) const;
|
||||
PRBool operator<(const char *aString) const;
|
||||
PRBool operator<(const PRUnichar* aString) const;
|
||||
|
||||
@@ -685,7 +687,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 &S) const;
|
||||
PRBool operator>(const nsString1 &S) const;
|
||||
PRBool operator>(const char *aCString) const;
|
||||
PRBool operator>(const PRUnichar* aString) const;
|
||||
|
||||
@@ -694,7 +696,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 &S) const;
|
||||
PRBool operator<=(const nsString1 &S) const;
|
||||
PRBool operator<=(const char *aCString) const;
|
||||
PRBool operator<=(const PRUnichar* aString) const;
|
||||
|
||||
@@ -703,7 +705,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 &S) const;
|
||||
PRBool operator>=(const nsString1 &S) const;
|
||||
PRBool operator>=(const char* aCString) const;
|
||||
PRBool operator>=(const PRUnichar* aString) const;
|
||||
|
||||
@@ -717,7 +719,7 @@ PRBool operator>=(const PRUnichar* aString) const;
|
||||
* @param aLength -- optional length of given string.
|
||||
* @return TRUE if equal
|
||||
*/
|
||||
PRBool Equals(const nsString& aString) const;
|
||||
PRBool Equals(const nsString1& aString) const;
|
||||
PRBool Equals(const char* aString,PRInt32 aLength=-1) const;
|
||||
PRBool Equals(const nsIAtom *aAtom) const;
|
||||
|
||||
@@ -740,7 +742,7 @@ PRBool Equals(const PRUnichar* s1, const PRUnichar* s2) const;
|
||||
* @param aLength -- optional length of given string.
|
||||
* @return TRUE if equal
|
||||
*/
|
||||
PRBool EqualsIgnoreCase(const nsString& aString) const;
|
||||
PRBool EqualsIgnoreCase(const nsString1& aString) const;
|
||||
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aLength=-1) const;
|
||||
PRBool EqualsIgnoreCase(const nsIAtom *aAtom) const;
|
||||
|
||||
@@ -768,34 +770,34 @@ typedef PRUnichar chartype;
|
||||
#endif
|
||||
};
|
||||
|
||||
ostream& operator<<(ostream& os,nsString& aString);
|
||||
extern NS_BASE int fputs(const nsString& aString, FILE* out);
|
||||
ostream& operator<<(ostream& os,nsString1& aString);
|
||||
extern NS_BASE int fputs(const nsString1& aString, FILE* out);
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* A version of nsString which is designed to be used as an automatic
|
||||
* A version of nsString1 which is designed to be used as an automatic
|
||||
* variable. It attempts to operate out of a fixed size internal
|
||||
* buffer until too much data is added; then a dynamic buffer is
|
||||
* allocated and grown as necessary.
|
||||
*/
|
||||
// XXX template this with a parameter for the size of the buffer?
|
||||
class NS_BASE nsAutoString : public nsString {
|
||||
class NS_BASE nsAutoString1 : public nsString1 {
|
||||
public:
|
||||
nsAutoString();
|
||||
nsAutoString(const nsString& other);
|
||||
nsAutoString(const nsAutoString& other);
|
||||
nsAutoString(PRUnichar aChar);
|
||||
nsAutoString(const char* aCString);
|
||||
nsAutoString(const PRUnichar* us, PRInt32 uslen = -1);
|
||||
virtual ~nsAutoString();
|
||||
nsAutoString1();
|
||||
nsAutoString1(const nsString1& other);
|
||||
nsAutoString1(const nsAutoString1& other);
|
||||
nsAutoString1(PRUnichar aChar);
|
||||
nsAutoString1(const char* aCString);
|
||||
nsAutoString1(const PRUnichar* us, PRInt32 uslen = -1);
|
||||
virtual ~nsAutoString1();
|
||||
|
||||
nsAutoString& operator=(const nsString& aString) {nsString::operator=(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;}
|
||||
nsAutoString1& operator=(const nsString1& aString) {nsString1::operator=(aString); return *this;}
|
||||
nsAutoString1& operator=(const nsAutoString1& aString) {nsString1::operator=(aString); return *this;}
|
||||
nsAutoString1& operator=(const char* aCString) {nsString1::operator=(aCString); return *this;}
|
||||
nsAutoString1& operator=(char aChar) {nsString1::operator=(aChar); return *this;}
|
||||
nsAutoString1& operator=(const PRUnichar* aBuffer) {nsString1::operator=(aBuffer); return *this;}
|
||||
nsAutoString1& operator=(PRUnichar aChar) {nsString1::operator=(aChar); return *this;}
|
||||
|
||||
virtual void SizeOf(nsISizeOfHandler* aHandler) const;
|
||||
|
||||
@@ -807,7 +809,7 @@ protected:
|
||||
chartype mBuf[32];
|
||||
};
|
||||
|
||||
ostream& operator<<(ostream& os,nsAutoString& aString);
|
||||
ostream& operator<<(ostream& os,nsAutoString1& aString);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -25,18 +25,15 @@
|
||||
#include "nsDebug.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsISizeOfHandler.h"
|
||||
#include "prprf.h"
|
||||
#include "prdtoa.h"
|
||||
#include "nsDeque.h"
|
||||
|
||||
#include "nsUnicharUtilCIID.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsICaseConversion.h"
|
||||
#ifndef RICKG_TESTBED
|
||||
#include "prdtoa.h"
|
||||
#include "nsISizeOfHandler.h"
|
||||
#endif
|
||||
|
||||
static const char* kNullPointerError = "Error: unexpected null ptr";
|
||||
static const char* kWhitespace="\b\t\r\n ";
|
||||
static const PRInt32 kNotFound=-1;
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
PRBool nsString2::mSelfTested = PR_FALSE;
|
||||
@@ -97,58 +94,7 @@ public:
|
||||
}
|
||||
}
|
||||
};
|
||||
static CTableConstructor gTableConstructor;
|
||||
|
||||
//---- XPCOM code to connect with UnicharUtil
|
||||
|
||||
class HandleCaseConversionShutdown3 : public nsIShutdownListener {
|
||||
public :
|
||||
NS_IMETHOD OnShutdown(const nsCID& cid, nsISupports* service);
|
||||
HandleCaseConversionShutdown3(void) { NS_INIT_REFCNT(); }
|
||||
virtual ~HandleCaseConversionShutdown3(void) {}
|
||||
NS_DECL_ISUPPORTS
|
||||
};
|
||||
static NS_DEFINE_CID(kUnicharUtilCID, NS_UNICHARUTIL_CID);
|
||||
static NS_DEFINE_IID(kICaseConversionIID, NS_ICASECONVERSION_IID);
|
||||
|
||||
static nsICaseConversion * gCaseConv = NULL;
|
||||
|
||||
static NS_DEFINE_IID(kIShutdownListenerIID, NS_ISHUTDOWNLISTENER_IID);
|
||||
NS_IMPL_ISUPPORTS(HandleCaseConversionShutdown3, kIShutdownListenerIID);
|
||||
|
||||
nsresult
|
||||
HandleCaseConversionShutdown3::OnShutdown(const nsCID& cid, nsISupports* service)
|
||||
{
|
||||
if (cid.Equals(kUnicharUtilCID)) {
|
||||
NS_ASSERTION(service == gCaseConv, "wrong service!");
|
||||
gCaseConv->Release();
|
||||
gCaseConv = NULL;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static HandleCaseConversionShutdown3* gListener = NULL;
|
||||
|
||||
static void StartUpCaseConversion()
|
||||
{
|
||||
nsresult err;
|
||||
|
||||
if ( NULL == gListener )
|
||||
{
|
||||
gListener = new HandleCaseConversionShutdown3();
|
||||
gListener->AddRef();
|
||||
}
|
||||
err = nsServiceManager::GetService(kUnicharUtilCID, kICaseConversionIID,
|
||||
(nsISupports**) &gCaseConv, gListener);
|
||||
}
|
||||
static void CheckCaseConversion()
|
||||
{
|
||||
if(NULL == gCaseConv )
|
||||
StartUpCaseConversion();
|
||||
|
||||
// NS_ASSERTION( gCaseConv != NULL , "cannot obtain UnicharUtil");
|
||||
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
IMPLEMENTATION NOTES:
|
||||
@@ -158,6 +104,15 @@ static void CheckCaseConversion()
|
||||
that no poor soul would ever have to do this again. Sigh.
|
||||
***********************************************************************/
|
||||
|
||||
void Subsume(nsStr& aDest,nsStr& aSource){
|
||||
aDest.mStr=aSource.mStr;
|
||||
aDest.mLength=aSource.mLength;
|
||||
aDest.mMultibyte=aSource.mMultibyte;
|
||||
aDest.mCapacity=aSource.mCapacity;
|
||||
aDest.mOwnsBuffer=aSource.mOwnsBuffer;
|
||||
aSource.mOwnsBuffer=PR_FALSE;
|
||||
aSource.mStr=0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor. Note that we actually allocate a small buffer
|
||||
@@ -216,6 +171,15 @@ nsString2::nsString2(const nsString2& aString) :mAgent(aString.mAgent) {
|
||||
nsStr::Assign(*this,aString,0,aString.mLength,mAgent);
|
||||
}
|
||||
|
||||
/**
|
||||
* construct off a subsumeable string
|
||||
* @update gess 1/4/99
|
||||
* @param reference to a subsumeString
|
||||
*/
|
||||
nsString2::nsString2(nsSubsumeStr& aSubsumeStr) :mAgent(0) {
|
||||
Subsume(*this,aSubsumeStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
* Make sure we call nsStr::Destroy.
|
||||
@@ -293,7 +257,7 @@ void nsString2::SetCapacity(PRUint32 aLength) {
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
char* nsString2::GetBuffer(void) const {
|
||||
const char* nsString2::GetBuffer(void) const {
|
||||
if(!mMultibyte)
|
||||
return mStr;
|
||||
return 0;
|
||||
@@ -305,7 +269,7 @@ char* nsString2::GetBuffer(void) const {
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRUnichar* nsString2::GetUnicode(void) const {
|
||||
const PRUnichar* nsString2::GetUnicode(void) const {
|
||||
if(mMultibyte)
|
||||
return (PRUnichar*)mUStr;
|
||||
return 0;
|
||||
@@ -314,11 +278,11 @@ PRUnichar* nsString2::GetUnicode(void) const {
|
||||
/**
|
||||
* Get nth character.
|
||||
*/
|
||||
PRUnichar nsString2::operator[](int anIndex) const {
|
||||
PRUnichar nsString2::operator[](PRUint32 anIndex) const {
|
||||
return GetCharAt(*this,anIndex);
|
||||
}
|
||||
|
||||
PRUnichar nsString2::CharAt(int anIndex) const {
|
||||
PRUnichar nsString2::CharAt(PRUint32 anIndex) const {
|
||||
return GetCharAt(*this,anIndex);
|
||||
}
|
||||
|
||||
@@ -352,10 +316,10 @@ PRBool nsString2::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsString2 nsString2::operator+(const nsStr& aString){
|
||||
nsSubsumeStr nsString2::operator+(const nsStr& aString){
|
||||
nsString2 temp(*this); //make a temp string the same size as this...
|
||||
nsStr::Append(temp,aString,0,aString.mLength,mAgent);
|
||||
return temp;
|
||||
return nsSubsumeStr(temp);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -364,10 +328,10 @@ nsString2 nsString2::operator+(const nsStr& aString){
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsString2 nsString2::operator+(const nsString2& aString){
|
||||
nsSubsumeStr nsString2::operator+(const nsString2& aString){
|
||||
nsString2 temp(*this); //make a temp string the same size as this...
|
||||
nsStr::Append(temp,aString,0,aString.mLength,mAgent);
|
||||
return temp;
|
||||
return nsSubsumeStr(temp);
|
||||
}
|
||||
|
||||
|
||||
@@ -377,10 +341,10 @@ nsString2 nsString2::operator+(const nsString2& aString){
|
||||
* @param aCString is a ptr to cstring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 nsString2::operator+(const char* aCString) {
|
||||
nsSubsumeStr nsString2::operator+(const char* aCString) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(aCString);
|
||||
return temp;
|
||||
return nsSubsumeStr(temp);
|
||||
}
|
||||
|
||||
|
||||
@@ -390,10 +354,10 @@ nsString2 nsString2::operator+(const char* aCString) {
|
||||
* @param aChar is a char to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 nsString2::operator+(char aChar) {
|
||||
nsSubsumeStr nsString2::operator+(char aChar) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(char(aChar));
|
||||
return temp;
|
||||
return nsSubsumeStr(temp);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -402,10 +366,10 @@ nsString2 nsString2::operator+(char aChar) {
|
||||
* @param aString is a ptr to unistring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 nsString2::operator+(const PRUnichar* aString) {
|
||||
nsSubsumeStr nsString2::operator+(const PRUnichar* aString) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(aString);
|
||||
return temp;
|
||||
return nsSubsumeStr(temp);
|
||||
}
|
||||
|
||||
|
||||
@@ -415,10 +379,10 @@ nsString2 nsString2::operator+(const PRUnichar* aString) {
|
||||
* @param aChar is a unichar to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 nsString2::operator+(PRUnichar aChar) {
|
||||
nsSubsumeStr nsString2::operator+(PRUnichar aChar) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(char(aChar));
|
||||
return temp;
|
||||
return nsSubsumeStr(temp);
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
@@ -429,6 +393,7 @@ nsString2 nsString2::operator+(PRUnichar aChar) {
|
||||
* Converts all chars in given string to UCS2
|
||||
*/
|
||||
void nsString2::ToUCS2(PRUint32 aStartOffset){
|
||||
static CTableConstructor gTableConstructor;
|
||||
if(aStartOffset<mLength){
|
||||
if(mMultibyte) {
|
||||
PRUint32 theIndex=0;
|
||||
@@ -621,11 +586,11 @@ PRUnichar* nsString2::ToNewUnicode() const {
|
||||
*/
|
||||
char* nsString2::ToCString(char* aBuf, PRUint32 aBufLength) const{
|
||||
if(aBuf) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mStr=aBuf;
|
||||
theTempStr.mCapacity=aBufLength;
|
||||
nsStr::Assign(theTempStr,*this,0,mLength,mAgent);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mStr=aBuf;
|
||||
temp.mCapacity=aBufLength;
|
||||
nsStr::Assign(temp,*this,0,mLength,mAgent);
|
||||
}
|
||||
return aBuf;
|
||||
}
|
||||
@@ -800,15 +765,19 @@ nsString2& nsString2::Assign(PRUnichar aChar) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies contents of this onto given string.
|
||||
* @update gess 7/27/98
|
||||
* @param aString to hold copy of this
|
||||
* @return nada.
|
||||
* WARNING! THIS IS A VERY SPECIAL METHOD.
|
||||
* This method "steals" the contents of aSource and hands it to aDest.
|
||||
* Ordinarily a copy is made, but not in this version.
|
||||
* @update gess10/30/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void nsString2::Copy(nsString2& aString) const{
|
||||
aString.SetString(*this);
|
||||
nsString2& nsString2::operator=(nsSubsumeStr& aSubsumeString) {
|
||||
Subsume(*this,aSubsumeString);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @update gess 01/04/99
|
||||
@@ -843,12 +812,12 @@ nsString2& nsString2::Append(const nsString2& aString,PRInt32 aCount) {
|
||||
*/
|
||||
nsString2& nsString2::Append(const char* aCString,PRInt32 aCount) {
|
||||
if(aCString){
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eOneByte);
|
||||
theTemp.mStr=(char*)aCString;
|
||||
theTemp.mLength=nsCRT::strlen(aCString);
|
||||
if(-1==aCount) aCount=theTemp.mLength;
|
||||
nsStr::Append(*this,theTemp,0,aCount,mAgent);
|
||||
nsStr temp;
|
||||
Initialize(temp,eOneByte);
|
||||
temp.mStr=(char*)aCString;
|
||||
temp.mLength=nsCRT::strlen(aCString);
|
||||
if(-1==aCount) aCount=temp.mLength;
|
||||
nsStr::Append(*this,temp,0,aCount,mAgent);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -862,12 +831,12 @@ nsString2& nsString2::Append(const char* aCString,PRInt32 aCount) {
|
||||
*/
|
||||
nsString2& nsString2::Append(const PRUnichar* aString,PRInt32 aCount) {
|
||||
if(aString){
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eTwoByte);
|
||||
theTemp.mUStr=(PRUnichar*)aString;
|
||||
theTemp.mLength=nsCRT::strlen(aString);
|
||||
if(-1==aCount) aCount=theTemp.mLength;
|
||||
nsStr::Append(*this,theTemp,0,aCount,mAgent);
|
||||
nsStr temp;
|
||||
Initialize(temp,eTwoByte);
|
||||
temp.mUStr=(PRUnichar*)aString;
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
if(-1==aCount) aCount=temp.mLength;
|
||||
nsStr::Append(*this,temp,0,aCount,mAgent);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -882,11 +851,11 @@ nsString2& nsString2::Append(char aChar) {
|
||||
char buf[2]={0,0};
|
||||
buf[0]=aChar;
|
||||
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eOneByte);
|
||||
theTemp.mStr=buf;
|
||||
theTemp.mLength=1;
|
||||
nsStr::Append(*this,theTemp,0,1,mAgent);
|
||||
nsStr temp;
|
||||
Initialize(temp,eOneByte);
|
||||
temp.mStr=buf;
|
||||
temp.mLength=1;
|
||||
nsStr::Append(*this,temp,0,1,mAgent);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -900,11 +869,11 @@ nsString2& nsString2::Append(PRUnichar aChar) {
|
||||
PRUnichar buf[2]={0,0};
|
||||
buf[0]=aChar;
|
||||
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eTwoByte);
|
||||
theTemp.mUStr=buf;
|
||||
theTemp.mLength=1;
|
||||
nsStr::Append(*this,theTemp,0,1,mAgent);
|
||||
nsStr temp;
|
||||
Initialize(temp,eTwoByte);
|
||||
temp.mUStr=buf;
|
||||
temp.mLength=1;
|
||||
nsStr::Append(*this,temp,0,1,mAgent);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -1001,7 +970,7 @@ PRUint32 nsString2::Right(nsString2& aCopy,PRInt32 aCount) const{
|
||||
* @param aCount -- number of chars to be copied from aCopy
|
||||
* @return number of chars inserted into this.
|
||||
*/
|
||||
nsString2& nsString2::Insert(nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount) {
|
||||
nsString2& nsString2::Insert(const nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount) {
|
||||
nsStr::Insert(*this,anOffset,aCopy,0,aCount,mAgent);
|
||||
return *this;
|
||||
}
|
||||
@@ -1018,12 +987,12 @@ nsString2& nsString2::Insert(nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount)
|
||||
nsString2& nsString2::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCount){
|
||||
if(aCString){
|
||||
if(0<aCount) {
|
||||
nsStr theTemp;
|
||||
nsStr::Initialize(theTemp,eOneByte);
|
||||
theTemp.mStr=(char*)aCString;
|
||||
theTemp.mLength=nsCRT::strlen(aCString);
|
||||
if(theTemp.mLength){
|
||||
nsStr::Insert(*this,anOffset,theTemp,0,aCount,0);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mStr=(char*)aCString;
|
||||
temp.mLength=nsCRT::strlen(aCString);
|
||||
if(temp.mLength){
|
||||
nsStr::Insert(*this,anOffset,temp,0,aCount,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1044,11 +1013,11 @@ nsString2& nsString2::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCou
|
||||
nsString2& nsString2::Insert(char aChar,PRUint32 anOffset){
|
||||
char theBuffer[2]={0,0};
|
||||
theBuffer[0]=aChar;
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mStr=(char*)theBuffer;
|
||||
theTempStr.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,theTempStr,0,1,0);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mStr=(char*)theBuffer;
|
||||
temp.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,temp,0,1,0);
|
||||
return *this;
|
||||
}
|
||||
*/
|
||||
@@ -1065,12 +1034,12 @@ nsString2& nsString2::Insert(char aChar,PRUint32 anOffset){
|
||||
nsString2& nsString2::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32 aCount){
|
||||
if(aString){
|
||||
if(0<aCount) {
|
||||
nsStr theTemp;
|
||||
nsStr::Initialize(theTemp,eTwoByte);
|
||||
theTemp.mUStr=(PRUnichar*)aString;
|
||||
theTemp.mLength=nsCRT::strlen(aString);
|
||||
if(theTemp.mLength){
|
||||
nsStr::Insert(*this,anOffset,theTemp,0,aCount,0);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eTwoByte);
|
||||
temp.mUStr=(PRUnichar*)aString;
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
if(temp.mLength){
|
||||
nsStr::Insert(*this,anOffset,temp,0,aCount,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1090,11 +1059,11 @@ nsString2& nsString2::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32
|
||||
nsString2& nsString2::Insert(PRUnichar aChar,PRUint32 anOffset){
|
||||
PRUnichar theBuffer[2]={0,0};
|
||||
theBuffer[0]=aChar;
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mUStr=theBuffer;
|
||||
theTempStr.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,theTempStr,0,1,0);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eTwoByte);
|
||||
temp.mUStr=theBuffer;
|
||||
temp.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,temp,0,1,0);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -1153,11 +1122,11 @@ PRInt32 nsString2::Find(const char* aCString,PRBool aIgnoreCase) const{
|
||||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aCString) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCString);
|
||||
theTempStr.mStr=(char*)aCString;
|
||||
result=nsStr::FindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCString);
|
||||
temp.mStr=(char*)aCString;
|
||||
result=nsStr::FindSubstr(*this,temp,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1174,11 +1143,11 @@ PRInt32 nsString2::Find(const PRUnichar* aString,PRBool aIgnoreCase) const{
|
||||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aString) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mUStr=(PRUnichar*)aString;
|
||||
result=nsStr::FindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eTwoByte);
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
temp.mUStr=(PRUnichar*)aString;
|
||||
result=nsStr::FindSubstr(*this,temp,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1195,6 +1164,18 @@ PRInt32 nsString2::Find(const nsStr& aString,PRBool aIgnoreCase) const{
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for given buffer within this string
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param nsString2 -- buffer to be found
|
||||
* @return offset in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 nsString2::Find(const nsString2& aString,PRBool aIgnoreCase) const{
|
||||
PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,0);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for a given char, starting at given offset
|
||||
*
|
||||
@@ -1219,11 +1200,11 @@ PRInt32 nsString2::FindCharInSet(const char* aCStringSet,PRUint32 anOffset) cons
|
||||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aCStringSet) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCStringSet);
|
||||
theTempStr.mStr=(char*)aCStringSet;
|
||||
result=nsStr::FindCharInSet(*this,theTempStr,PR_FALSE,anOffset);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCStringSet);
|
||||
temp.mStr=(char*)aCStringSet;
|
||||
result=nsStr::FindCharInSet(*this,temp,PR_FALSE,anOffset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1252,11 +1233,11 @@ PRInt32 nsString2::RFindCharInSet(const char* aCStringSet,PRUint32 anOffset) con
|
||||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aCStringSet) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCStringSet);
|
||||
theTempStr.mStr=(char*)aCStringSet;
|
||||
result=nsStr::RFindCharInSet(*this,theTempStr,PR_FALSE,anOffset);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCStringSet);
|
||||
temp.mStr=(char*)aCStringSet;
|
||||
result=nsStr::RFindCharInSet(*this,temp,PR_FALSE,anOffset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1285,6 +1266,18 @@ PRInt32 nsString2::RFind(const nsStr& aString,PRBool aIgnoreCase) const{
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsString2::RFind(const nsString2& aString,PRBool aIgnoreCase) const{
|
||||
PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,0);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
@@ -1297,11 +1290,11 @@ PRInt32 nsString2::RFind(const char* aString,PRBool aIgnoreCase) const{
|
||||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aString) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mStr=(char*)aString;
|
||||
result=nsStr::RFindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
temp.mStr=(char*)aString;
|
||||
result=nsStr::RFindSubstr(*this,temp,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1334,11 +1327,11 @@ PRInt32 nsString2::Compare(const char *aCString,PRBool aIgnoreCase,PRInt32 aLeng
|
||||
NS_ASSERTION(0!=aCString,kNullPointerError);
|
||||
|
||||
if(aCString) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCString);
|
||||
theTempStr.mStr=(char*)aCString;
|
||||
return nsStr::Compare(*this,theTempStr,aLength,aIgnoreCase);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCString);
|
||||
temp.mStr=(char*)aCString;
|
||||
return nsStr::Compare(*this,temp,aLength,aIgnoreCase);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1354,11 +1347,11 @@ PRInt32 nsString2::Compare(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 a
|
||||
NS_ASSERTION(0!=aString,kNullPointerError);
|
||||
|
||||
if(aString) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mUStr=(PRUnichar*)aString;
|
||||
return nsStr::Compare(*this,theTempStr,aLength,aIgnoreCase);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eTwoByte);
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
temp.mUStr=(PRUnichar*)aString;
|
||||
return nsStr::Compare(*this,temp,aLength,aIgnoreCase);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1568,16 +1561,37 @@ PRBool nsString2::IsDigit(PRUnichar aChar) {
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Define the string deallocator class...
|
||||
**************************************************************/
|
||||
class nsStringDeallocator: public nsDequeFunctor{
|
||||
public:
|
||||
virtual void* operator()(void* anObject) {
|
||||
static nsMemoryAgent theAgent;
|
||||
nsString2* aString= (nsString2*)anObject;
|
||||
if(aString){
|
||||
aString->mAgent=&theAgent;
|
||||
delete aString;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* This class, appropriately enough, creates and recycles nsString2 objects..
|
||||
****************************************************************************/
|
||||
|
||||
#if 0
|
||||
|
||||
class nsStringRecycler {
|
||||
public:
|
||||
nsStringRecycler() : mDeque(0) {
|
||||
}
|
||||
|
||||
~nsStringRecycler() {
|
||||
nsStringDeallocator theDeallocator;
|
||||
mDeque.ForEach(theDeallocator); //now delete the strings
|
||||
}
|
||||
|
||||
void Recycle(nsString2* aString) {
|
||||
mDeque.Push(aString);
|
||||
}
|
||||
@@ -1623,7 +1637,6 @@ void nsString2::Recycle(nsString2* aString){
|
||||
GetRecycler().Recycle(aString);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -1690,14 +1703,12 @@ NS_BASE int fputs(const nsString2& aString, FILE* out)
|
||||
*/
|
||||
void nsString2::SelfTest(void) {
|
||||
|
||||
#if 0
|
||||
#ifdef NS_DEBUG
|
||||
static const char* kConstructorError = kConstructorError;
|
||||
static const char* kComparisonError = "Comparision error!";
|
||||
static const char* kEqualsError = "Equals error!";
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
mSelfTested=PR_TRUE;
|
||||
#endif
|
||||
|
||||
eCharSize theSize=eOneByte;
|
||||
|
||||
@@ -1705,8 +1716,18 @@ void nsString2::SelfTest(void) {
|
||||
{
|
||||
{
|
||||
nsString2 theString0("foo",theSize); //watch it construct and destruct
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
nsString2 theString("hello");
|
||||
nsString2 temp1=theString+" there!";
|
||||
nsString2 temp2=theString+'!';
|
||||
nsSubsumeStr temp3=theString+'?';
|
||||
nsString2 temp4(temp3);
|
||||
temp1=temp3;
|
||||
nsSubsumeStr temp5("hello");
|
||||
}
|
||||
|
||||
nsString2 theString1(theSize);
|
||||
nsString2 theString("hello",theSize);
|
||||
nsString2 theString3(theString,theSize);
|
||||
@@ -1721,6 +1742,8 @@ void nsString2::SelfTest(void) {
|
||||
//while we're here, let's try truncation and setting the length.
|
||||
theString3.Truncate(3);
|
||||
theLen=theString3.Length();
|
||||
|
||||
|
||||
theString.SetCapacity(3);
|
||||
const char* theBuffer=theString.GetBuffer();
|
||||
const char* theOther=theBuffer;
|
||||
@@ -1736,12 +1759,17 @@ void nsString2::SelfTest(void) {
|
||||
theString5.StripWhitespace();
|
||||
|
||||
nsString2* theString6=theString5.ToNewString();
|
||||
nsString2::Recycle(theString6);
|
||||
|
||||
char* str=theString5.ToNewCString();
|
||||
delete [] str;
|
||||
|
||||
char buffer[100];
|
||||
theString5.ToCString(buffer,sizeof(buffer)-1);
|
||||
theOther=theString5.GetBuffer();
|
||||
}
|
||||
//try a few numeric conversion routines...
|
||||
|
||||
//try a few numeric conversion routines...
|
||||
{
|
||||
nsString2 str1("10000",theSize);
|
||||
PRInt32 err;
|
||||
@@ -1753,11 +1781,12 @@ void nsString2::SelfTest(void) {
|
||||
{
|
||||
nsString2 theString("hello",theSize);
|
||||
PRUint32 len=theString.Length();
|
||||
PRUnichar ch;
|
||||
for(PRUint32 i=0;i<len;i++) {
|
||||
PRUnichar ch3=theString.CharAt(i);
|
||||
ch=theString.CharAt(i);
|
||||
}
|
||||
PRUnichar ch4=theString.First();
|
||||
PRUnichar ch5=theString.Last();
|
||||
ch=theString.First();
|
||||
ch=theString.Last();
|
||||
}
|
||||
|
||||
//**********************************************
|
||||
@@ -1826,7 +1855,6 @@ void nsString2::SelfTest(void) {
|
||||
temp1.Right(temp2,4);
|
||||
}
|
||||
|
||||
|
||||
//**********************************************
|
||||
//Now let's test the INSERTION methods...
|
||||
//**********************************************
|
||||
@@ -1973,6 +2001,15 @@ void nsString2::SelfTest(void) {
|
||||
pos=find1.BinarySearch('i');
|
||||
pos=find1.BinarySearch('z');
|
||||
}
|
||||
|
||||
{
|
||||
//now let's try a memory allocation test...
|
||||
nsString2 temp;
|
||||
for(int i=0;i<100;i++){
|
||||
temp+="hello ";
|
||||
}
|
||||
int x=5;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1981,14 +2018,6 @@ void nsString2::SelfTest(void) {
|
||||
IMPLEMENTATION NOTES: AUTOSTRING...
|
||||
***********************************************************************/
|
||||
|
||||
void InitAutoStr(nsAutoString2& aDest,nsBufDescriptor& aBufDescriptor){
|
||||
aDest.mAgent=0;
|
||||
aDest.mStr=aBufDescriptor.mStr;
|
||||
aDest.mMultibyte=aBufDescriptor.mMultibyte;
|
||||
aDest.mCapacity=(sizeof(aDest.mBuffer)>>aDest.mMultibyte)-1;
|
||||
aDest.mOwnsBuffer=aBufDescriptor.mOwnsBuffer;
|
||||
AddNullTerminator(aDest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Special case constructor, that allows the consumer to provide
|
||||
@@ -1998,8 +2027,9 @@ void InitAutoStr(nsAutoString2& aDest,nsBufDescriptor& aBufDescriptor){
|
||||
* @param aCurrentLength tells us the current length of the buffer
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(eCharSize aCharSize) : nsString2(aCharSize){
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
mAgent=0;
|
||||
AddNullTerminator(*this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2007,8 +2037,10 @@ nsAutoString2::nsAutoString2(eCharSize aCharSize) : nsString2(aCharSize){
|
||||
* @param anExtBuffer describes an external buffer
|
||||
* @param aCString is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(nsBufDescriptor& aBufDescriptor,const char* aCString) : nsString2(aBufDescriptor.mMultibyte) {
|
||||
InitAutoStr(*this,aBufDescriptor);
|
||||
nsAutoString2::nsAutoString2(nsStr& aStr,const char* aCString) : nsString2(aStr.mMultibyte) {
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aStr.mMultibyte)-1,0,aStr.mMultibyte,PR_FALSE);
|
||||
mAgent=0;
|
||||
AddNullTerminator(*this);
|
||||
Assign(aCString);
|
||||
}
|
||||
|
||||
@@ -2017,8 +2049,9 @@ nsAutoString2::nsAutoString2(nsBufDescriptor& aBufDescriptor,const char* aCStrin
|
||||
* @param aCString is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const char* aCString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
mAgent=0;
|
||||
AddNullTerminator(*this);
|
||||
Assign(aCString);
|
||||
}
|
||||
|
||||
@@ -2026,15 +2059,15 @@ nsAutoString2::nsAutoString2(const char* aCString,eCharSize aCharSize) : nsStrin
|
||||
* Copy construct from ascii c-string
|
||||
* @param aCString is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(char* aCString,PRUint32 aLen,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
nsAutoString2::nsAutoString2(char* aCString,PRUint32 aCapacity,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
mAgent=0;
|
||||
if(assumeOwnership) {
|
||||
nsBufDescriptor theDescriptor(aCString,aLen,eOneByte,PR_TRUE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
nsStr::Initialize(*this,aCString,aCapacity,0,eOneByte,PR_TRUE);
|
||||
}
|
||||
else {
|
||||
nsBufDescriptor theDescriptor(mBuffer,aLen,aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
}
|
||||
AddNullTerminator(*this);
|
||||
Assign(aCString);
|
||||
}
|
||||
|
||||
@@ -2043,8 +2076,9 @@ nsAutoString2::nsAutoString2(char* aCString,PRUint32 aLen,eCharSize aCharSize,PR
|
||||
* @param aString is a ptr to a unistr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const PRUnichar* aString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
@@ -2052,15 +2086,15 @@ nsAutoString2::nsAutoString2(const PRUnichar* aString,eCharSize aCharSize) : nsS
|
||||
* Copy construct from uni-string
|
||||
* @param aString is a ptr to a unistr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(PRUnichar* aString,PRUint32 aLength,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
nsAutoString2::nsAutoString2(PRUnichar* aString,PRUint32 aCapacity,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
mAgent=0;
|
||||
if(assumeOwnership) {
|
||||
nsBufDescriptor theDescriptor((char*)aString,aLength,eTwoByte,PR_TRUE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
nsStr::Initialize(*this,(char*)aString,aCapacity,0,eTwoByte,PR_TRUE);
|
||||
}
|
||||
else {
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
}
|
||||
AddNullTerminator(*this);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
@@ -2070,8 +2104,9 @@ nsAutoString2::nsAutoString2(PRUnichar* aString,PRUint32 aLength,eCharSize aChar
|
||||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const nsStr& aString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
@@ -2080,8 +2115,9 @@ nsAutoString2::nsAutoString2(const nsStr& aString,eCharSize aCharSize) : nsStrin
|
||||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const nsAutoString2& aString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
@@ -2090,8 +2126,9 @@ nsAutoString2::nsAutoString2(const nsAutoString2& aString,eCharSize aCharSize) :
|
||||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const nsString2& aString,eCharSize aCharSize) : nsString2(aCharSize){
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
@@ -2101,11 +2138,22 @@ nsAutoString2::nsAutoString2(const nsString2& aString,eCharSize aCharSize) : nsS
|
||||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(PRUnichar aChar,eCharSize aCharSize) : nsString2(aCharSize){
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
Assign(aChar);
|
||||
}
|
||||
|
||||
/**
|
||||
* construct from a subsumeable string
|
||||
* @update gess 1/4/99
|
||||
* @param reference to a subsumeString
|
||||
*/
|
||||
nsAutoString2::nsAutoString2( nsSubsumeStr& aSubsumeStr) :nsString2(aSubsumeStr.mMultibyte) {
|
||||
mAgent=0;
|
||||
Subsume(*this,aSubsumeStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* deconstruct the autstring
|
||||
* @param
|
||||
@@ -2120,3 +2168,16 @@ void nsAutoString2::SizeOf(nsISizeOfHandler* aHandler) const {
|
||||
aHandler->Add(mCapacity << mMultibyte);
|
||||
}
|
||||
|
||||
nsSubsumeStr::nsSubsumeStr(nsString2& aString) : nsString2() {
|
||||
Subsume(*this,aString);
|
||||
}
|
||||
|
||||
nsSubsumeStr::nsSubsumeStr(nsStr& aString) : nsString2() {
|
||||
Subsume(*this,aString);
|
||||
}
|
||||
|
||||
nsSubsumeStr::nsSubsumeStr(const PRUnichar* aString) : nsString2(aString,eTwoByte) {
|
||||
}
|
||||
|
||||
nsSubsumeStr::nsSubsumeStr(const char* aString) : nsString2(aString,eOneByte) {
|
||||
}
|
||||
|
||||
@@ -20,18 +20,19 @@
|
||||
/***********************************************************************
|
||||
MODULE NOTES:
|
||||
|
||||
This class provides a 1-byte ASCII string implementation that shares
|
||||
a common API with all other strImpl derivatives.
|
||||
This version of the nsString class offers many improvements over the
|
||||
original version:
|
||||
1. Wide and narrow chars
|
||||
2. Allocators
|
||||
3. Much smarter autostrings
|
||||
4. Subsumable strings
|
||||
5. Memory pools and recycling
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef _nsString2
|
||||
#define _nsString2
|
||||
|
||||
//#define nsString2 nsString
|
||||
//#define nsAutoString2 nsAutoString
|
||||
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nscore.h"
|
||||
#include <iostream.h>
|
||||
@@ -46,6 +47,13 @@
|
||||
class nsISizeOfHandler;
|
||||
|
||||
|
||||
#ifdef USE_STRING2
|
||||
#define nsString2 nsString
|
||||
#define nsAutoString2 nsAutoString
|
||||
#endif
|
||||
|
||||
class NS_BASE nsSubsumeStr;
|
||||
|
||||
class NS_BASE nsString2 : public nsStr {
|
||||
|
||||
public:
|
||||
@@ -83,6 +91,12 @@ nsString2(const nsStr&,eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAg
|
||||
*/
|
||||
nsString2(const nsString2& aString);
|
||||
|
||||
/**
|
||||
* This constructor takes a subsumestr
|
||||
* @param reference to subsumestr
|
||||
*/
|
||||
nsString2(nsSubsumeStr& aSubsumeStr);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*
|
||||
@@ -139,16 +153,15 @@ PRBool IsOrdered(void) const;
|
||||
Accessor methods...
|
||||
*********************************************************************/
|
||||
|
||||
char* GetBuffer(void) const;
|
||||
PRUnichar* GetUnicode(void) const;
|
||||
operator PRUnichar*() const {return GetUnicode();}
|
||||
const char* GetBuffer(void) const;
|
||||
const PRUnichar* GetUnicode(void) const;
|
||||
|
||||
|
||||
/**
|
||||
* Get nth character.
|
||||
*/
|
||||
PRUnichar operator[](int anIndex) const;
|
||||
PRUnichar CharAt(int anIndex) const;
|
||||
PRUnichar operator[](PRUint32 anIndex) const;
|
||||
PRUnichar CharAt(PRUint32 anIndex) const;
|
||||
PRUnichar First(void) const;
|
||||
PRUnichar Last(void) const;
|
||||
|
||||
@@ -164,42 +177,42 @@ PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsString2 operator+(const nsStr& aString);
|
||||
nsSubsumeStr operator+(const nsStr& aString);
|
||||
|
||||
/**
|
||||
* Create a new string by appending given string to this
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsString2 operator+(const nsString2& aString);
|
||||
nsSubsumeStr operator+(const nsString2& aString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given buffer.
|
||||
* @param aCString is a ptr to cstring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 operator+(const char* aCString);
|
||||
nsSubsumeStr operator+(const char* aCString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given wide buffer.
|
||||
* @param aString is a ptr to UC-string to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 operator+(const PRUnichar* aString);
|
||||
nsSubsumeStr operator+(const PRUnichar* aString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given char.
|
||||
* @param aChar is a char to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 operator+(char aChar);
|
||||
nsSubsumeStr operator+(char aChar);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given char.
|
||||
* @param aChar is a unichar to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 operator+(PRUnichar aChar);
|
||||
nsSubsumeStr operator+(PRUnichar aChar);
|
||||
|
||||
/**********************************************************************
|
||||
Lexomorphic transforms...
|
||||
@@ -353,7 +366,6 @@ PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=10) const;
|
||||
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);}
|
||||
void Copy(nsString2& aString) const;
|
||||
|
||||
/**
|
||||
* assign given string to this string
|
||||
@@ -380,6 +392,7 @@ 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);}
|
||||
nsString2& operator=(nsSubsumeStr& aSubsumeString);
|
||||
|
||||
/**
|
||||
* Here's a bunch of append mehtods for varying types...
|
||||
@@ -402,8 +415,7 @@ nsString2& operator+=(PRUnichar aChar){return Append(aChar);}
|
||||
*/
|
||||
nsString2& Append(const nsStr& aString) {return Append(aString,aString.mLength);}
|
||||
nsString2& Append(const nsString2& aString) {return Append(aString,aString.mLength);}
|
||||
nsString2& Append(const char* aString) {if(aString) {Append(aString,nsCRT::strlen(aString));} return *this;}
|
||||
nsString2& Append(const PRUnichar* aString) {if(aString) {Append(aString,nsCRT::strlen(aString));} return *this;}
|
||||
|
||||
|
||||
/*
|
||||
* Appends n characters from given string to this,
|
||||
@@ -414,13 +426,13 @@ nsString2& Append(const PRUnichar* aString) {if(aString) {Append(aString,nsCRT::
|
||||
*/
|
||||
nsString2& Append(const nsStr& aString,PRInt32 aCount);
|
||||
nsString2& Append(const nsString2& aString,PRInt32 aCount);
|
||||
nsString2& Append(const char* aString,PRInt32 aCount);
|
||||
nsString2& Append(const PRUnichar* 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,
|
||||
* starting at the leftmost offset.
|
||||
@@ -464,7 +476,7 @@ PRUint32 Right(nsString2& aCopy,PRInt32 aCount) const;
|
||||
* @param aCount -- number of chars to be copied from aCopy
|
||||
* @return number of chars inserted into this.
|
||||
*/
|
||||
nsString2& Insert(nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
|
||||
nsString2& Insert(const nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
|
||||
|
||||
/**
|
||||
* Insert a given string into this string at
|
||||
@@ -519,6 +531,7 @@ PRInt32 BinarySearch(PRUnichar aChar) const;
|
||||
* @param aString is substring to be sought in this
|
||||
* @return offset 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;
|
||||
@@ -554,6 +567,7 @@ PRInt32 RFindCharInSet(const nsString2& aString,PRUint32 anOffset=0) const;
|
||||
* @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,PRBool aIgnoreCase=PR_FALSE,PRUint32 offset=0) const;
|
||||
@@ -675,10 +689,8 @@ static PRBool IsAlpha(PRUnichar ch);
|
||||
*/
|
||||
static PRBool IsDigit(PRUnichar ch);
|
||||
|
||||
#if 0
|
||||
static void Recycle(nsString2* aString);
|
||||
static nsString2* NewString(eCharSize aCharSize=eTwoByte);
|
||||
#endif
|
||||
|
||||
static void SelfTest();
|
||||
virtual void DebugDump(ostream& aStream) const;
|
||||
@@ -701,12 +713,11 @@ ostream& operator<<(ostream& os,nsString2& aString);
|
||||
If the buffer needs to grow, it gets reallocated on the heap.
|
||||
**************************************************************/
|
||||
|
||||
|
||||
class NS_BASE nsAutoString2 : public nsString2 {
|
||||
public:
|
||||
|
||||
nsAutoString2(eCharSize aCharSize=kDefaultCharSize);
|
||||
nsAutoString2(nsBufDescriptor& anExtBuffer,const char* aCString);
|
||||
nsAutoString2(nsStr& anExtBuffer,const char* aCString);
|
||||
|
||||
|
||||
nsAutoString2(const char* aCString,eCharSize aCharSize=kDefaultCharSize);
|
||||
@@ -717,6 +728,7 @@ public:
|
||||
nsAutoString2(const nsStr& aString,eCharSize aCharSize=kDefaultCharSize);
|
||||
nsAutoString2(const nsString2& aString,eCharSize aCharSize=kDefaultCharSize);
|
||||
nsAutoString2(const nsAutoString2& aString,eCharSize aCharSize=kDefaultCharSize);
|
||||
nsAutoString2(nsSubsumeStr& aSubsumeStr);
|
||||
nsAutoString2(PRUnichar aChar,eCharSize aCharSize=kDefaultCharSize);
|
||||
virtual ~nsAutoString2();
|
||||
|
||||
@@ -738,5 +750,28 @@ public:
|
||||
};
|
||||
|
||||
|
||||
/***************************************************************
|
||||
The subsumestr class is very unusual.
|
||||
It differs from a normal string in that it doesn't use normal
|
||||
copy semantics when another string is assign to this.
|
||||
Instead, it "steals" the contents of the source string.
|
||||
|
||||
This is very handy for returning nsString classes as part of
|
||||
an operator+(...) for example, in that it cuts down the number
|
||||
of copy operations that must occur.
|
||||
|
||||
You should probably not use this class unless you really know
|
||||
what you're doing.
|
||||
***************************************************************/
|
||||
class NS_BASE nsSubsumeStr : public nsString2 {
|
||||
public:
|
||||
nsSubsumeStr(nsString2& aString);
|
||||
nsSubsumeStr(nsStr& aString);
|
||||
nsSubsumeStr(const PRUnichar* aString);
|
||||
nsSubsumeStr(const char* aString);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -31,11 +31,103 @@
|
||||
#include "nsStr.h"
|
||||
#include "bufferRoutines.h"
|
||||
#include "stdio.h" //only used for printf
|
||||
#include "nsDeque.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
|
||||
static const char* kFoolMsg = "Error: Some fool overwrote the shared buffer.";
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// The following is a memory agent who knows how to recycled (pool) freed memory...
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
/**************************************************************
|
||||
Define the char* (pooled) deallocator class...
|
||||
**************************************************************/
|
||||
class nsBufferDeallocator: public nsDequeFunctor{
|
||||
public:
|
||||
virtual void* operator()(void* anObject) {
|
||||
char* aCString= (char*)anObject;
|
||||
delete [] aCString;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess10/30/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
class nsPoolingMemoryAgent : public nsMemoryAgent{
|
||||
public:
|
||||
nsPoolingMemoryAgent() {
|
||||
memset(mPools,0,sizeof(mPools));
|
||||
}
|
||||
|
||||
~nsPoolingMemoryAgent() {
|
||||
nsBufferDeallocator theDeallocator;
|
||||
int i=0;
|
||||
for(i=0;i<10;i++){
|
||||
if(mPools[i]){
|
||||
mPools[i]->ForEach(theDeallocator); //now delete the buffers
|
||||
}
|
||||
delete mPools[i];
|
||||
mPools[i]=0;
|
||||
}
|
||||
}
|
||||
|
||||
virtual PRBool Alloc(nsStr& aDest,PRInt32 aCount) {
|
||||
|
||||
//we're given the acount value in charunits; we have to scale up by the charsize.
|
||||
int theShift=4;
|
||||
PRInt32 theNewCapacity=eDefaultSize;
|
||||
while(theNewCapacity<aCount){
|
||||
theNewCapacity<<=1;
|
||||
theShift++;
|
||||
}
|
||||
|
||||
aDest.mCapacity=theNewCapacity++;
|
||||
theShift=(theShift<<aDest.mMultibyte)-4;
|
||||
if((theShift<12) && (mPools[theShift])){
|
||||
aDest.mStr=(char*)mPools[theShift]->Pop();
|
||||
}
|
||||
if(!aDest.mStr) {
|
||||
//we're given the acount value in charunits; we have to scale up by the charsize.
|
||||
size_t theSize=(theNewCapacity<<aDest.mMultibyte);
|
||||
aDest.mStr=new char[theSize];
|
||||
}
|
||||
aDest.mOwnsBuffer=1;
|
||||
return PR_TRUE;
|
||||
|
||||
}
|
||||
|
||||
virtual PRBool Free(nsStr& aDest){
|
||||
if(aDest.mStr){
|
||||
if(aDest.mOwnsBuffer){
|
||||
int theShift=1;
|
||||
unsigned int theValue=1;
|
||||
while((theValue<<=1)<aDest.mCapacity){
|
||||
theShift++;
|
||||
}
|
||||
theShift-=4;
|
||||
if(theShift<12){
|
||||
if(!mPools[theShift]){
|
||||
mPools[theShift]=new nsDeque(0);
|
||||
}
|
||||
mPools[theShift]->Push(aDest.mStr);
|
||||
}
|
||||
else delete [] aDest.mStr; //it's too big. Just delete it.
|
||||
}
|
||||
aDest.mStr=0;
|
||||
aDest.mOwnsBuffer=0;
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
nsDeque* mPools[16];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -71,6 +163,7 @@ void nsStr::Initialize(nsStr& aDest,eCharSize aCharSize) {
|
||||
aDest.mCapacity=0;
|
||||
aDest.mMultibyte=aCharSize;
|
||||
aDest.mOwnsBuffer=0;
|
||||
aDest.mUnused=0;
|
||||
NS_ASSERTION(aDest.mStr[0]==0,kFoolMsg);
|
||||
}
|
||||
|
||||
@@ -80,14 +173,25 @@ void nsStr::Initialize(nsStr& aDest,eCharSize aCharSize) {
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsIMemoryAgent* GetDefaultAgent(void){
|
||||
static nsIMemoryAgent* gDefaultAgent=0;
|
||||
if(!gDefaultAgent)
|
||||
gDefaultAgent=new nsMemoryAgent();
|
||||
|
||||
NS_ASSERTION(gDefaultAgent,"You MUST always have an allocator!");
|
||||
void nsStr::Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 aLength,eCharSize aCharSize,PRBool aOwnsBuffer){
|
||||
aDest.mStr=(aCString) ? aCString : GetSharedEmptyBuffer();
|
||||
aDest.mLength=aLength;
|
||||
aDest.mCapacity=aCapacity;
|
||||
aDest.mMultibyte=aCharSize;
|
||||
aDest.mOwnsBuffer=aOwnsBuffer;
|
||||
aDest.mUnused=0;
|
||||
}
|
||||
|
||||
return gDefaultAgent;
|
||||
/**
|
||||
*
|
||||
* @update gess10/30/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsIMemoryAgent* GetDefaultAgent(void){
|
||||
// static nsPoolingMemoryAgent gDefaultAgent;
|
||||
static nsMemoryAgent gDefaultAgent;
|
||||
return (nsIMemoryAgent*)&gDefaultAgent;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,20 +214,6 @@ void nsStr::Destroy(nsStr& aDest,nsIMemoryAgent* anAgent) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess11/12/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRUnichar nsStr::GetCharAt(const nsStr& aDest,PRUint32 anIndex) {
|
||||
PRUnichar result=0;
|
||||
if((anIndex>=0) && (anIndex<aDest.mLength)) {
|
||||
result=(eTwoByte==aDest.mMultibyte) ? aDest.mUStr[anIndex] : aDest.mStr[anIndex];
|
||||
}//if
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method gets called when the internal buffer needs
|
||||
@@ -155,8 +245,8 @@ void nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAgen
|
||||
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
|
||||
EnsureCapacity(theTempStr,aNewLength,theAgent);
|
||||
|
||||
if(0<aDest.mLength) {
|
||||
Append(theTempStr,aDest,0,aDest.mLength,anAgent);
|
||||
if(aDest.mLength) {
|
||||
Append(theTempStr,aDest,0,aDest.mLength,theAgent);
|
||||
}
|
||||
theAgent->Free(aDest);
|
||||
aDest.mStr = theTempStr.mStr;
|
||||
@@ -182,13 +272,12 @@ void nsStr::Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 a
|
||||
/**
|
||||
* This method appends the given nsStr to this one. Note that we have to
|
||||
* pay attention to the underlying char-size of both structs.
|
||||
* @update gess 04/04/99
|
||||
* @update gess10/30/98
|
||||
* @param aDest is the nsStr to be manipulated
|
||||
* @param aSource is where char are copied from
|
||||
* @aCount is the number of bytes to be copied
|
||||
*/
|
||||
void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){
|
||||
|
||||
if(anOffset<aSource.mLength){
|
||||
PRUint32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
|
||||
PRUint32 theLength=(anOffset+theRealLen<aSource.mLength) ? theRealLen : (aSource.mLength-anOffset);
|
||||
@@ -221,30 +310,30 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin
|
||||
// 1. You're inserting chars into an empty string (assign)
|
||||
// 2. You're inserting onto the end of a string (append)
|
||||
// 3. You're inserting onto the 1..n-1 pos of a string (the hard case).
|
||||
if((0<aSource.mLength) && (aDestOffset<aDest.mLength-1)){
|
||||
if(0<aSource.mLength){
|
||||
ToRange(aDestOffset,0,aDest.mLength);
|
||||
if(aDest.mLength){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
if(aSrcOffset<aSource.mLength-1) {
|
||||
PRInt32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
|
||||
PRInt32 theLength=(aSrcOffset+theRealLen<aSource.mLength) ? theRealLen : (aSource.mLength-aSrcOffset);
|
||||
//ToRange(aSrcOffset,0,aSource.mLength-1);
|
||||
PRInt32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
|
||||
PRInt32 theLength=(aSrcOffset+theRealLen<aSource.mLength) ? theRealLen : (aSource.mLength-aSrcOffset);
|
||||
|
||||
if(aSrcOffset<aSource.mLength) {
|
||||
//here's the only new case we have to handle.
|
||||
//chars are really being inserted into our buffer...
|
||||
GrowCapacity(aDest,aDest.mLength+theLength,anAgent);
|
||||
if(aSrcOffset<aSource.mLength) {
|
||||
//here's the only new case we have to handle.
|
||||
//chars are really being inserted into our buffer...
|
||||
GrowCapacity(aDest,aDest.mLength+theLength,anAgent);
|
||||
|
||||
//shift the chars right by theDelta...
|
||||
(*gShiftChars[aDest.mMultibyte][PR_TRUE])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
|
||||
//shift the chars right by theDelta...
|
||||
(*gShiftChars[aDest.mMultibyte][PR_TRUE])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
|
||||
|
||||
//now insert new chars, starting at offset
|
||||
(*gCopyChars[aSource.mMultibyte][aDest.mMultibyte])(aDest.mStr,aDestOffset,aSource.mStr,aSrcOffset,theLength);
|
||||
//now insert new chars, starting at offset
|
||||
(*gCopyChars[aSource.mMultibyte][aDest.mMultibyte])(aDest.mStr,aDestOffset,aSource.mStr,aSrcOffset,theLength);
|
||||
|
||||
//finally, make sure to update the string length...
|
||||
aDest.mLength+=theLength;
|
||||
//finally, make sure to update the string length...
|
||||
aDest.mLength+=theLength;
|
||||
|
||||
}//if
|
||||
//else nothing to do!
|
||||
}
|
||||
}//if
|
||||
//else nothing to do!
|
||||
}
|
||||
else Append(aDest,aSource,0,aCount,anAgent);
|
||||
}
|
||||
@@ -260,22 +349,20 @@ void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUin
|
||||
* @param aDestOffset is where in aDest deletion is to occur
|
||||
* @param aCount is the number of chars to be deleted in aDest
|
||||
*/
|
||||
void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){
|
||||
if(0<aCount){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAgent* anAgent){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
|
||||
PRInt32 theDelta=aDest.mLength-aDestOffset;
|
||||
PRInt32 theLength=(theDelta<aCount) ? theDelta : aCount;
|
||||
PRUint32 theDelta=aDest.mLength-aDestOffset;
|
||||
PRUint32 theLength=(theDelta<aCount) ? theDelta : aCount;
|
||||
|
||||
if(aDestOffset+theLength<aDest.mLength) {
|
||||
if(aDestOffset+theLength<aDest.mLength) {
|
||||
|
||||
//if you're here, it means we're cutting chars out of the middle of the string...
|
||||
//so shift the chars left by theLength...
|
||||
(*gShiftChars[aDest.mMultibyte][PR_FALSE])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
|
||||
aDest.mLength-=theLength;
|
||||
}
|
||||
else Truncate(aDest,aDestOffset,anAgent);
|
||||
}//if
|
||||
//if you're here, it means we're cutting chars out of the middle of the string...
|
||||
//so shift the chars left by theLength...
|
||||
(*gShiftChars[aDest.mMultibyte][PR_FALSE])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
|
||||
aDest.mLength-=theLength;
|
||||
}
|
||||
else Truncate(aDest,aDestOffset,anAgent);
|
||||
}//if
|
||||
}
|
||||
|
||||
@@ -343,28 +430,28 @@ void nsStr::CompressSet(nsStr& aDest,const char* aSet,PRUint32 aChar,PRBool aEli
|
||||
**************************************************************/
|
||||
|
||||
|
||||
PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool /*aIgnoreCase*/,PRUint32 anOffset) {
|
||||
PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 index=anOffset-1;
|
||||
PRInt32 theMax=aDest.mLength-aTarget.mLength;
|
||||
if((aDest.mLength>0) && (aTarget.mLength>0)){
|
||||
PRInt32 theNewStartPos=-1;
|
||||
PRUnichar theFirstTargetChar=nsStr::GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=nsStr::GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRUnichar theFirstTargetChar=GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRInt32 theTargetMax=aTarget.mLength;
|
||||
while(++index<=theMax) {
|
||||
PRInt32 theSubIndex=-1;
|
||||
PRBool matches=PR_TRUE;
|
||||
while((++theSubIndex<theTargetMax) && (matches)){
|
||||
PRUnichar theChar=nsStr::GetCharAt(aDest,index+theSubIndex);
|
||||
PRUnichar theChar=GetCharAt(aDest,index+theSubIndex);
|
||||
if(theSubIndex>0) {
|
||||
if(theFirstTargetChar==theChar){
|
||||
PRUnichar theDestJumpChar=nsStr::GetCharAt(aDest,index+theTargetMax);
|
||||
PRUnichar theDestJumpChar=GetCharAt(aDest,index+theTargetMax);
|
||||
if(theDestJumpChar==theLastTargetChar) {
|
||||
theNewStartPos=index; //this lets us jump ahead during our search where possible.
|
||||
}//if
|
||||
}//if
|
||||
}//if
|
||||
PRUnichar theTargetChar=nsStr::GetCharAt(aTarget,theSubIndex);
|
||||
PRUnichar theTargetChar=GetCharAt(aTarget,theSubIndex);
|
||||
matches=PRBool(theChar==theTargetChar);
|
||||
}
|
||||
if(matches)
|
||||
@@ -384,8 +471,8 @@ PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool /*aIgn
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsStr::FindChar(const nsStr& aDest, PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase);
|
||||
PRInt32 nsStr::FindChar(const nsStr& aDest,const PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,0,aChar,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -415,12 +502,12 @@ PRInt32 nsStr::FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnore
|
||||
**************************************************************/
|
||||
|
||||
|
||||
PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool /*aIgnoreCase*/,PRUint32 anOffset) {
|
||||
PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 index=(anOffset ? anOffset : aDest.mLength-aTarget.mLength+1);
|
||||
if((aDest.mLength>0) && (aTarget.mLength>0)){
|
||||
PRInt32 theNewStartPos=-1;
|
||||
PRUnichar theFirstTargetChar=nsStr::GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=nsStr::GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRUnichar theFirstTargetChar=GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRInt32 theTargetMax=aTarget.mLength;
|
||||
|
||||
while(index--) {
|
||||
@@ -429,16 +516,16 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool /*aIg
|
||||
|
||||
if(anOffset+aTarget.mLength<=aDest.mLength) {
|
||||
while((++theSubIndex<theTargetMax) && (matches)){
|
||||
PRUnichar theChar=nsStr::GetCharAt(aDest,index+theSubIndex);
|
||||
PRUnichar theChar=GetCharAt(aDest,index+theSubIndex);
|
||||
if(theSubIndex>0) {
|
||||
if(theFirstTargetChar==theChar){
|
||||
PRUnichar theDestJumpChar=nsStr::GetCharAt(aDest,index+theTargetMax);
|
||||
PRUnichar theDestJumpChar=GetCharAt(aDest,index+theTargetMax);
|
||||
if(theDestJumpChar==theLastTargetChar) {
|
||||
theNewStartPos=index; //this lets us jump ahead during our search where possible.
|
||||
}//if
|
||||
}//if
|
||||
}//if
|
||||
PRUnichar theTargetChar=nsStr::GetCharAt(aTarget,theSubIndex);
|
||||
PRUnichar theTargetChar=GetCharAt(aTarget,theSubIndex);
|
||||
matches=PRBool(theChar==theTargetChar);
|
||||
} //while
|
||||
} //if
|
||||
@@ -459,8 +546,8 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool /*aIg
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsStr::RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gRFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase);
|
||||
PRInt32 nsStr::RFindChar(const nsStr& aDest,const PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gRFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,0,aChar,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -472,11 +559,11 @@ PRInt32 nsStr::RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,
|
||||
* @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) {
|
||||
PRUnichar theChar=GetCharAt(aDest,PRUint32(offset));
|
||||
PRUnichar theChar=GetCharAt(aDest,offset);
|
||||
thePos=gRFindChars[aSet.mMultibyte](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase);
|
||||
if(kNotFound!=thePos)
|
||||
return offset;
|
||||
@@ -491,7 +578,7 @@ PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnor
|
||||
* @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 nsStr::Compare(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) {
|
||||
int minlen=(aSource.mLength<aDest.mLength) ? aSource.mLength : aDest.mLength;
|
||||
|
||||
if(0==minlen) {
|
||||
|
||||
@@ -27,8 +27,6 @@
|
||||
We chose the option B for performance reasons.
|
||||
|
||||
2 Our internal buffer always holds capacity+1 bytes.
|
||||
3. Note that our internal format for this class makes our memory
|
||||
layout compatible with BStrings.
|
||||
|
||||
The nsStr struct is a simple structure (no methods) that contains
|
||||
the necessary info to be described as a string. This simple struct
|
||||
@@ -44,41 +42,13 @@
|
||||
#ifndef _nsStr
|
||||
#define _nsStr
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nscore.h"
|
||||
#include "nsCore.h"
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
enum eCharSize {eOneByte=0,eTwoByte=1};
|
||||
#define kDefaultCharSize eTwoByte
|
||||
|
||||
|
||||
union UStrPtr {
|
||||
char* mCharBuf;
|
||||
PRUnichar* mUnicharBuf;
|
||||
};
|
||||
|
||||
/**************************************************************************
|
||||
Here comes the nsBufDescriptor class which describes buffer properties.
|
||||
**************************************************************************/
|
||||
|
||||
struct nsBufDescriptor {
|
||||
nsBufDescriptor(char* aBuffer,PRUint32 aBufferSize,eCharSize aCharSize,PRBool aOwnsBuffer) {
|
||||
mStr=aBuffer;
|
||||
mMultibyte=aCharSize;
|
||||
mCapacity=(aBufferSize>>mMultibyte)-1;
|
||||
mOwnsBuffer=aOwnsBuffer;
|
||||
}
|
||||
|
||||
PRUint32 mCapacity;
|
||||
PRBool mOwnsBuffer;
|
||||
eCharSize mMultibyte;
|
||||
// UStrPtr mStr;
|
||||
union {
|
||||
char* mStr;
|
||||
PRUnichar* mUStr;
|
||||
};
|
||||
};
|
||||
const PRInt32 kNotFound = -1;
|
||||
|
||||
|
||||
class nsIMemoryAgent;
|
||||
@@ -97,6 +67,15 @@ struct nsStr {
|
||||
*/
|
||||
static void Initialize(nsStr& aDest,eCharSize aCharSize);
|
||||
|
||||
/**
|
||||
* This method initializes an nsStr for use
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aString is the nsStr to be initialized
|
||||
* @param aCharSize tells us the requested char size (1 or 2 bytes)
|
||||
*/
|
||||
static void Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 aLength,eCharSize aCharSize,PRBool aOwnsBuffer);
|
||||
|
||||
/**
|
||||
* This method destroys the given nsStr, and *MAY*
|
||||
* deallocate it's memory depending on the setting
|
||||
@@ -166,7 +145,7 @@ struct nsStr {
|
||||
* @param aCount tells us the (max) # of chars to delete
|
||||
* @param anAgent is the allocator to be used for alloc/free operations
|
||||
*/
|
||||
static void Delete(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0);
|
||||
static void Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount,nsIMemoryAgent* anAgent=0);
|
||||
|
||||
/**
|
||||
* This method is used to truncate the given string.
|
||||
@@ -254,21 +233,20 @@ struct nsStr {
|
||||
static PRInt32 RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset);
|
||||
static PRInt32 RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRUint32 anOffset);
|
||||
|
||||
/**
|
||||
* This method is used to access a given char in the given string
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the nsStr to be appended to
|
||||
* @param anIndex tells us where in dest to get the char from
|
||||
* @return the given char, or 0 if anIndex is out of range
|
||||
*/
|
||||
static PRUnichar GetCharAt(const nsStr& aDest,PRUint32 anIndex);
|
||||
|
||||
PRUint32 mLength : 30;
|
||||
eCharSize mMultibyte : 2;
|
||||
#ifdef NS_DEBUG
|
||||
PRUint32 mLength;
|
||||
eCharSize mMultibyte;
|
||||
PRUint32 mCapacity;
|
||||
PRUint32 mOwnsBuffer;
|
||||
PRUint32 mUnused;
|
||||
#else
|
||||
PRUint32 mLength: 30;
|
||||
eCharSize mMultibyte: 2;
|
||||
PRUint32 mCapacity: 30;
|
||||
PRUint32 mOwnsBuffer: 1;
|
||||
PRUint32 mUnused: 1;
|
||||
PRUint32 mOwnsBuffer: 1;
|
||||
PRUint32 mUnused: 1;
|
||||
#endif
|
||||
union {
|
||||
char* mStr;
|
||||
PRUnichar* mUStr;
|
||||
@@ -307,6 +285,21 @@ inline void AddNullTerminator(nsStr& aDest) {
|
||||
else aDest.mStr[aDest.mLength]=0;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to access a given char in the given string
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the nsStr to be appended to
|
||||
* @param anIndex tells us where in dest to get the char from
|
||||
* @return the given char, or 0 if anIndex is out of range
|
||||
*/
|
||||
inline PRUnichar GetCharAt(const nsStr& aDest,PRUint32 anIndex){
|
||||
if(anIndex<aDest.mLength) {
|
||||
return (eTwoByte==aDest.mMultibyte) ? aDest.mUStr[anIndex] : aDest.mStr[anIndex];
|
||||
}//if
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
class nsIMemoryAgent {
|
||||
@@ -317,25 +310,18 @@ public:
|
||||
};
|
||||
|
||||
class nsMemoryAgent : public nsIMemoryAgent {
|
||||
enum eDelta{eGrowthDelta=8};
|
||||
protected:
|
||||
enum eDelta{eDefaultSize=16};
|
||||
public:
|
||||
|
||||
virtual PRBool Alloc(nsStr& aDest,PRInt32 aCount) {
|
||||
|
||||
//we're given the acount value in charunits; we have to scale up by the charsize.
|
||||
|
||||
PRInt32 theNewCapacity;
|
||||
if (aDest.mCapacity > 64) {
|
||||
// When the string starts getting large, double the capacity as we grow.
|
||||
theNewCapacity = aDest.mCapacity * 2;
|
||||
if (theNewCapacity < aCount) {
|
||||
theNewCapacity = aDest.mCapacity + aCount;
|
||||
}
|
||||
} else {
|
||||
// When the string is small, keep it's capacity a multiple of kGrowthDelta
|
||||
PRInt32 unitDelta=(aCount/eGrowthDelta)+1;
|
||||
theNewCapacity=unitDelta*eGrowthDelta;
|
||||
//we're given the acount value in charunits; now scale up to next multiple.
|
||||
PRInt32 theNewCapacity=eDefaultSize;
|
||||
while(theNewCapacity<aCount){
|
||||
theNewCapacity<<=1;
|
||||
}
|
||||
|
||||
|
||||
aDest.mCapacity=theNewCapacity++;
|
||||
size_t theSize=(theNewCapacity<<aDest.mMultibyte);
|
||||
aDest.mStr=new char[theSize];
|
||||
@@ -362,6 +348,5 @@ public:
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -30,8 +30,8 @@
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef _NSSTRING
|
||||
#define _NSSTRING
|
||||
#ifndef _nsString1
|
||||
#define _nsString1
|
||||
|
||||
|
||||
#include "prtypes.h"
|
||||
@@ -39,9 +39,18 @@
|
||||
#include "nsIAtom.h"
|
||||
#include <iostream.h>
|
||||
#include <stdio.h>
|
||||
#include "nsStr.h"
|
||||
|
||||
#ifndef USE_STRING2
|
||||
#define nsString1 nsString
|
||||
#define nsAutoString1 nsAutoString
|
||||
#else
|
||||
#include "nsString2.h" //get new string class
|
||||
#endif
|
||||
|
||||
class nsISizeOfHandler;
|
||||
|
||||
class NS_BASE nsString {
|
||||
class NS_BASE nsString1 {
|
||||
public:
|
||||
|
||||
/**
|
||||
@@ -50,30 +59,30 @@ class NS_BASE nsString {
|
||||
* was to allow developers direct access to the underlying buffer for
|
||||
* performance reasons.
|
||||
*/
|
||||
nsString();
|
||||
nsString1();
|
||||
|
||||
/**
|
||||
* This constructor accepts an isolatin string
|
||||
* @param an ascii is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsString(const char* aCString);
|
||||
nsString1(const char* aCString);
|
||||
|
||||
/**
|
||||
* This is our copy constructor
|
||||
* @param reference to another nsString
|
||||
* @param reference to another nsString1
|
||||
*/
|
||||
nsString(const nsString&);
|
||||
nsString1(const nsString1&);
|
||||
|
||||
/**
|
||||
* Constructor from a unicode string
|
||||
* @param anicodestr pts to a unicode string
|
||||
*/
|
||||
nsString(const PRUnichar* aUnicode);
|
||||
nsString1(const PRUnichar* aUnicode);
|
||||
|
||||
/**
|
||||
* Virtual Destructor
|
||||
*/
|
||||
virtual ~nsString();
|
||||
virtual ~nsString1();
|
||||
|
||||
|
||||
/**
|
||||
@@ -136,14 +145,14 @@ const PRUnichar* GetUnicode(void) const;
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
operator const PRUnichar*() const;
|
||||
//operator const PRUnichar*() const;
|
||||
|
||||
/**
|
||||
* Retrieve unicode char at given index
|
||||
* @param offset into string
|
||||
* @return PRUnichar* to internal string
|
||||
*/
|
||||
PRUnichar operator()(PRInt32 anIndex) const;
|
||||
//PRUnichar operator()(PRInt32 anIndex) const;
|
||||
|
||||
/**
|
||||
* Retrieve reference to unicode char at given index
|
||||
@@ -183,35 +192,35 @@ PRBool SetCharAt(PRUnichar aChar,PRInt32 anIndex);
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsString operator+(const nsString& aString);
|
||||
nsString1 operator+(const nsString1& aString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given buffer.
|
||||
* @param aCString is a ptr to cstring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString operator+(const char* aCString);
|
||||
nsString1 operator+(const char* aCString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given char.
|
||||
* @param aChar is a char to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString operator+(char aChar);
|
||||
nsString1 operator+(char aChar);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given buffer.
|
||||
* @param aStr unichar buffer to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString operator+(const PRUnichar* aBuffer);
|
||||
nsString1 operator+(const PRUnichar* aBuffer);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given char.
|
||||
* @param aChar is a unichar to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString operator+(PRUnichar aChar);
|
||||
nsString1 operator+(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* Converts all chars in internal string to lower
|
||||
@@ -221,7 +230,7 @@ void ToLowerCase();
|
||||
/**
|
||||
* Converts all chars in given string to lower
|
||||
*/
|
||||
void ToLowerCase(nsString& aString) const;
|
||||
void ToLowerCase(nsString1& aString) const;
|
||||
|
||||
/**
|
||||
* Converts all chars in given string to upper
|
||||
@@ -237,13 +246,13 @@ void ToUCS2(PRInt32 aStartOffset);
|
||||
/**
|
||||
* Converts all chars in internal string to upper
|
||||
*/
|
||||
void ToUpperCase(nsString& aString) const;
|
||||
void ToUpperCase(nsString1& aString) const;
|
||||
|
||||
/**
|
||||
* Creates a duplicate clone (ptr) of this string.
|
||||
* @return ptr to clone of this string
|
||||
*/
|
||||
nsString* ToNewString() const;
|
||||
nsString1* ToNewString() const;
|
||||
|
||||
/**
|
||||
* Creates an ascii clone of this string
|
||||
@@ -265,7 +274,7 @@ char* ToCString(char* aBuf,PRInt32 aBufLength) const;
|
||||
* @param aString to hold copy of this
|
||||
* @return nada.
|
||||
*/
|
||||
void Copy(nsString& aString) const;
|
||||
void Copy(nsString1& aString) const;
|
||||
|
||||
/**
|
||||
* Creates an unichar clone of this string
|
||||
@@ -298,79 +307,72 @@ PRInt32 ToInteger(PRInt32* aErrorCode,PRInt32 aRadix=10) const;
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString& SetString(const PRUnichar* aStr,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* assign given char* to this string
|
||||
* @param aCString: buffer to be assigned to this
|
||||
* @param alength is the length of the given str (or -1)
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString& SetString(const char* aCString,PRInt32 aLength=-1);
|
||||
nsString1& SetString(const PRUnichar* aStr,PRInt32 aLength=-1);
|
||||
nsString1& SetString(const char* aCString,PRInt32 aLength=-1);
|
||||
nsString1& SetString(const nsString1& aString);
|
||||
|
||||
/**
|
||||
* assign given string to this one
|
||||
* @param aString: string to be added to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator=(const nsString& aString);
|
||||
nsString1& operator=(const nsString1& aString);
|
||||
|
||||
/**
|
||||
* assign given char* to this string
|
||||
* @param aCString: buffer to be assigned to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator=(const char* aCString);
|
||||
nsString1& operator=(const char* aCString);
|
||||
|
||||
/**
|
||||
* assign given char to this string
|
||||
* @param aChar: char to be assignd to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator=(char aChar);
|
||||
nsString1& operator=(char aChar);
|
||||
|
||||
/**
|
||||
* assign given unichar* to this string
|
||||
* @param aBuffer: unichar buffer to be assigned to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator=(const PRUnichar* aBuffer);
|
||||
nsString1& operator=(const PRUnichar* aBuffer);
|
||||
|
||||
/**
|
||||
* assign given char to this string
|
||||
* @param aChar: char to be assignd to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator=(PRUnichar aChar);
|
||||
nsString1& operator=(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @param aString : string to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator+=(const nsString& aString);
|
||||
nsString1& operator+=(const nsString1& aString);
|
||||
|
||||
/**
|
||||
* append given buffer to this string
|
||||
* @param aCString: buffer to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator+=(const char* aCString);
|
||||
nsString1& operator+=(const char* aCString);
|
||||
|
||||
/**
|
||||
* append given buffer to this string
|
||||
* @param aBuffer: buffer to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator+=(const PRUnichar* aBuffer);
|
||||
nsString1& operator+=(const PRUnichar* aBuffer);
|
||||
|
||||
/**
|
||||
* append given char to this string
|
||||
* @param aChar: char to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator+=(PRUnichar aChar);
|
||||
nsString1& operator+=(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
@@ -379,7 +381,7 @@ nsString& operator+=(PRUnichar aChar);
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(const nsString& aString,PRInt32 aLength=-1);
|
||||
nsString1& Append(const nsString1& aString,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
@@ -388,14 +390,14 @@ nsString& Append(const nsString& aString,PRInt32 aLength=-1);
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(const char* aCString,PRInt32 aLength=-1);
|
||||
nsString1& Append(const char* aCString,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @param aString : string to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(char aChar);
|
||||
nsString1& Append(char aChar);
|
||||
|
||||
/**
|
||||
* append given unichar buffer to this string
|
||||
@@ -404,14 +406,14 @@ nsString& Append(char aChar);
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(const PRUnichar* aBuffer,PRInt32 aLength=-1);
|
||||
nsString1& Append(const PRUnichar* aBuffer,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* append given unichar character to this string
|
||||
* @param aChar is the char to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(PRUnichar aChar);
|
||||
nsString1& Append(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* Append an integer onto this string
|
||||
@@ -419,14 +421,14 @@ nsString& Append(PRUnichar aChar);
|
||||
* @param aRadix specifies 8,10,16
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(PRInt32 aInteger,PRInt32 aRadix); //radix=8,10 or 16
|
||||
nsString1& Append(PRInt32 aInteger,PRInt32 aRadix); //radix=8,10 or 16
|
||||
|
||||
/**
|
||||
* Append a float value onto this string
|
||||
* @param aFloat is the float to be appended
|
||||
* @return this
|
||||
*/
|
||||
nsString& Append(float aFloat);
|
||||
nsString1& Append(float aFloat);
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
@@ -437,7 +439,7 @@ nsString& Append(float aFloat);
|
||||
* @param aCount -- number of chars to copy
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Left(nsString& aCopy,PRInt32 aCount) const;
|
||||
PRInt32 Left(nsString1& aCopy,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
@@ -449,7 +451,7 @@ PRInt32 Left(nsString& aCopy,PRInt32 aCount) const;
|
||||
* @param anOffset -- position where copying begins
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Mid(nsString& aCopy,PRInt32 anOffset,PRInt32 aCount) const;
|
||||
PRInt32 Mid(nsString1& aCopy,PRInt32 anOffset,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
@@ -460,7 +462,7 @@ PRInt32 Mid(nsString& aCopy,PRInt32 anOffset,PRInt32 aCount) const;
|
||||
* @param aCount -- number of chars to copy
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Right(nsString& aCopy,PRInt32 aCount) const;
|
||||
PRInt32 Right(nsString1& aCopy,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* This method inserts n chars from given string into this
|
||||
@@ -471,7 +473,7 @@ PRInt32 Right(nsString& aCopy,PRInt32 aCount) const;
|
||||
* @param aCount -- number of chars to be copied from aCopy
|
||||
* @return number of chars inserted into this.
|
||||
*/
|
||||
PRInt32 Insert(const nsString& aCopy,PRInt32 anOffset,PRInt32 aCount=-1);
|
||||
PRInt32 Insert(const nsString1& aCopy,PRInt32 anOffset,PRInt32 aCount=-1);
|
||||
|
||||
/**
|
||||
* Insert a single unicode char into this string at
|
||||
@@ -491,7 +493,7 @@ PRInt32 Insert(PRUnichar aChar,PRInt32 anOffset);
|
||||
* @param aCount -- number of chars to be cut
|
||||
* @return *this
|
||||
*/
|
||||
nsString& Cut(PRInt32 anOffset,PRInt32 aCount);
|
||||
nsString1& Cut(PRInt32 anOffset,PRInt32 aCount);
|
||||
|
||||
/**
|
||||
* This method is used to remove all occurances of the
|
||||
@@ -500,7 +502,7 @@ nsString& Cut(PRInt32 anOffset,PRInt32 aCount);
|
||||
* @param aSet -- characters to be cut from this
|
||||
* @return *this
|
||||
*/
|
||||
nsString& StripChars(const char* aSet);
|
||||
nsString1& StripChars(const char* aSet);
|
||||
|
||||
/**
|
||||
* This method is used to replace all occurances of the
|
||||
@@ -509,14 +511,14 @@ nsString& StripChars(const char* aSet);
|
||||
* @param
|
||||
* @return *this
|
||||
*/
|
||||
nsString& ReplaceChar(PRUnichar aSourceChar, PRUnichar aDestChar);
|
||||
nsString1& ReplaceChar(PRUnichar aSourceChar, PRUnichar aDestChar);
|
||||
|
||||
/**
|
||||
* This method strips whitespace throughout the string
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
nsString& StripWhitespace();
|
||||
nsString1& StripWhitespace();
|
||||
|
||||
/**
|
||||
* This method trims characters found in aTrimSet from
|
||||
@@ -526,7 +528,7 @@ nsString& StripWhitespace();
|
||||
* both ends
|
||||
* @return this
|
||||
*/
|
||||
nsString& Trim(const char* aSet,
|
||||
nsString1& Trim(const char* aSet,
|
||||
PRBool aEliminateLeading=PR_TRUE,
|
||||
PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
@@ -539,7 +541,7 @@ nsString& Trim(const char* aSet,
|
||||
* @param aEliminateTrailing controls stripping of trailing ws
|
||||
* @return this
|
||||
*/
|
||||
nsString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,
|
||||
nsString1& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,
|
||||
PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
/**
|
||||
@@ -588,7 +590,7 @@ PRInt32 BinarySearch(PRUnichar aChar) const;
|
||||
*/
|
||||
PRInt32 Find(const char* aString) const;
|
||||
PRInt32 Find(const PRUnichar* aString) const;
|
||||
PRInt32 Find(const nsString& aString) const;
|
||||
PRInt32 Find(const nsString1& aString) const;
|
||||
|
||||
/**
|
||||
* Search for given char within this string
|
||||
@@ -606,7 +608,7 @@ PRInt32 Find(PRUnichar aChar,PRInt32 offset=0) const;
|
||||
* @return -1 if not found, else the offset in this
|
||||
*/
|
||||
PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 FindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 FindCharInSet(nsString1& aString,PRInt32 anOffset=0) const;
|
||||
|
||||
/**
|
||||
* This method searches this string for the last character
|
||||
@@ -616,7 +618,7 @@ PRInt32 FindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
||||
* @return -1 if not found, else the offset in this
|
||||
*/
|
||||
PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 RFindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 RFindCharInSet(nsString1& aString,PRInt32 anOffset=0) const;
|
||||
|
||||
|
||||
/**
|
||||
@@ -627,7 +629,7 @@ PRInt32 RFindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
||||
*/
|
||||
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFind(const nsString1& aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
|
||||
/**
|
||||
* This methods scans the string backwards, looking for the given char
|
||||
@@ -648,7 +650,7 @@ PRInt32 RFind(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
* @param aIgnoreCase tells us how to treat case
|
||||
* @return -1,0,1
|
||||
*/
|
||||
virtual PRInt32 Compare(const nsString &aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
virtual PRInt32 Compare(const nsString1 &aString,PRBool aIgnoreCase=PR_FALSE) 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;
|
||||
|
||||
@@ -657,7 +659,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 nsString1 &aString) const;
|
||||
PRBool operator==(const char *aString) const;
|
||||
PRBool operator==(const PRUnichar* aString) const;
|
||||
PRBool operator==(PRUnichar* aString) const;
|
||||
@@ -667,7 +669,7 @@ PRBool operator==(PRUnichar* aString) const;
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE
|
||||
*/
|
||||
PRBool operator!=(const nsString &aString) const;
|
||||
PRBool operator!=(const nsString1 &aString) const;
|
||||
PRBool operator!=(const char *aString) const;
|
||||
PRBool operator!=(const PRUnichar* aString) const;
|
||||
|
||||
@@ -676,7 +678,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 nsString1 &aString) const;
|
||||
PRBool operator<(const char *aString) const;
|
||||
PRBool operator<(const PRUnichar* aString) const;
|
||||
|
||||
@@ -685,7 +687,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 &S) const;
|
||||
PRBool operator>(const nsString1 &S) const;
|
||||
PRBool operator>(const char *aCString) const;
|
||||
PRBool operator>(const PRUnichar* aString) const;
|
||||
|
||||
@@ -694,7 +696,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 &S) const;
|
||||
PRBool operator<=(const nsString1 &S) const;
|
||||
PRBool operator<=(const char *aCString) const;
|
||||
PRBool operator<=(const PRUnichar* aString) const;
|
||||
|
||||
@@ -703,7 +705,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 &S) const;
|
||||
PRBool operator>=(const nsString1 &S) const;
|
||||
PRBool operator>=(const char* aCString) const;
|
||||
PRBool operator>=(const PRUnichar* aString) const;
|
||||
|
||||
@@ -717,7 +719,7 @@ PRBool operator>=(const PRUnichar* aString) const;
|
||||
* @param aLength -- optional length of given string.
|
||||
* @return TRUE if equal
|
||||
*/
|
||||
PRBool Equals(const nsString& aString) const;
|
||||
PRBool Equals(const nsString1& aString) const;
|
||||
PRBool Equals(const char* aString,PRInt32 aLength=-1) const;
|
||||
PRBool Equals(const nsIAtom *aAtom) const;
|
||||
|
||||
@@ -740,7 +742,7 @@ PRBool Equals(const PRUnichar* s1, const PRUnichar* s2) const;
|
||||
* @param aLength -- optional length of given string.
|
||||
* @return TRUE if equal
|
||||
*/
|
||||
PRBool EqualsIgnoreCase(const nsString& aString) const;
|
||||
PRBool EqualsIgnoreCase(const nsString1& aString) const;
|
||||
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aLength=-1) const;
|
||||
PRBool EqualsIgnoreCase(const nsIAtom *aAtom) const;
|
||||
|
||||
@@ -768,34 +770,34 @@ typedef PRUnichar chartype;
|
||||
#endif
|
||||
};
|
||||
|
||||
ostream& operator<<(ostream& os,nsString& aString);
|
||||
extern NS_BASE int fputs(const nsString& aString, FILE* out);
|
||||
ostream& operator<<(ostream& os,nsString1& aString);
|
||||
extern NS_BASE int fputs(const nsString1& aString, FILE* out);
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* A version of nsString which is designed to be used as an automatic
|
||||
* A version of nsString1 which is designed to be used as an automatic
|
||||
* variable. It attempts to operate out of a fixed size internal
|
||||
* buffer until too much data is added; then a dynamic buffer is
|
||||
* allocated and grown as necessary.
|
||||
*/
|
||||
// XXX template this with a parameter for the size of the buffer?
|
||||
class NS_BASE nsAutoString : public nsString {
|
||||
class NS_BASE nsAutoString1 : public nsString1 {
|
||||
public:
|
||||
nsAutoString();
|
||||
nsAutoString(const nsString& other);
|
||||
nsAutoString(const nsAutoString& other);
|
||||
nsAutoString(PRUnichar aChar);
|
||||
nsAutoString(const char* aCString);
|
||||
nsAutoString(const PRUnichar* us, PRInt32 uslen = -1);
|
||||
virtual ~nsAutoString();
|
||||
nsAutoString1();
|
||||
nsAutoString1(const nsString1& other);
|
||||
nsAutoString1(const nsAutoString1& other);
|
||||
nsAutoString1(PRUnichar aChar);
|
||||
nsAutoString1(const char* aCString);
|
||||
nsAutoString1(const PRUnichar* us, PRInt32 uslen = -1);
|
||||
virtual ~nsAutoString1();
|
||||
|
||||
nsAutoString& operator=(const nsString& aString) {nsString::operator=(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;}
|
||||
nsAutoString1& operator=(const nsString1& aString) {nsString1::operator=(aString); return *this;}
|
||||
nsAutoString1& operator=(const nsAutoString1& aString) {nsString1::operator=(aString); return *this;}
|
||||
nsAutoString1& operator=(const char* aCString) {nsString1::operator=(aCString); return *this;}
|
||||
nsAutoString1& operator=(char aChar) {nsString1::operator=(aChar); return *this;}
|
||||
nsAutoString1& operator=(const PRUnichar* aBuffer) {nsString1::operator=(aBuffer); return *this;}
|
||||
nsAutoString1& operator=(PRUnichar aChar) {nsString1::operator=(aChar); return *this;}
|
||||
|
||||
virtual void SizeOf(nsISizeOfHandler* aHandler) const;
|
||||
|
||||
@@ -807,7 +809,7 @@ protected:
|
||||
chartype mBuf[32];
|
||||
};
|
||||
|
||||
ostream& operator<<(ostream& os,nsAutoString& aString);
|
||||
ostream& operator<<(ostream& os,nsAutoString1& aString);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -25,18 +25,15 @@
|
||||
#include "nsDebug.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsISizeOfHandler.h"
|
||||
#include "prprf.h"
|
||||
#include "prdtoa.h"
|
||||
#include "nsDeque.h"
|
||||
|
||||
#include "nsUnicharUtilCIID.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsICaseConversion.h"
|
||||
#ifndef RICKG_TESTBED
|
||||
#include "prdtoa.h"
|
||||
#include "nsISizeOfHandler.h"
|
||||
#endif
|
||||
|
||||
static const char* kNullPointerError = "Error: unexpected null ptr";
|
||||
static const char* kWhitespace="\b\t\r\n ";
|
||||
static const PRInt32 kNotFound=-1;
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
PRBool nsString2::mSelfTested = PR_FALSE;
|
||||
@@ -97,58 +94,7 @@ public:
|
||||
}
|
||||
}
|
||||
};
|
||||
static CTableConstructor gTableConstructor;
|
||||
|
||||
//---- XPCOM code to connect with UnicharUtil
|
||||
|
||||
class HandleCaseConversionShutdown3 : public nsIShutdownListener {
|
||||
public :
|
||||
NS_IMETHOD OnShutdown(const nsCID& cid, nsISupports* service);
|
||||
HandleCaseConversionShutdown3(void) { NS_INIT_REFCNT(); }
|
||||
virtual ~HandleCaseConversionShutdown3(void) {}
|
||||
NS_DECL_ISUPPORTS
|
||||
};
|
||||
static NS_DEFINE_CID(kUnicharUtilCID, NS_UNICHARUTIL_CID);
|
||||
static NS_DEFINE_IID(kICaseConversionIID, NS_ICASECONVERSION_IID);
|
||||
|
||||
static nsICaseConversion * gCaseConv = NULL;
|
||||
|
||||
static NS_DEFINE_IID(kIShutdownListenerIID, NS_ISHUTDOWNLISTENER_IID);
|
||||
NS_IMPL_ISUPPORTS(HandleCaseConversionShutdown3, kIShutdownListenerIID);
|
||||
|
||||
nsresult
|
||||
HandleCaseConversionShutdown3::OnShutdown(const nsCID& cid, nsISupports* service)
|
||||
{
|
||||
if (cid.Equals(kUnicharUtilCID)) {
|
||||
NS_ASSERTION(service == gCaseConv, "wrong service!");
|
||||
gCaseConv->Release();
|
||||
gCaseConv = NULL;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static HandleCaseConversionShutdown3* gListener = NULL;
|
||||
|
||||
static void StartUpCaseConversion()
|
||||
{
|
||||
nsresult err;
|
||||
|
||||
if ( NULL == gListener )
|
||||
{
|
||||
gListener = new HandleCaseConversionShutdown3();
|
||||
gListener->AddRef();
|
||||
}
|
||||
err = nsServiceManager::GetService(kUnicharUtilCID, kICaseConversionIID,
|
||||
(nsISupports**) &gCaseConv, gListener);
|
||||
}
|
||||
static void CheckCaseConversion()
|
||||
{
|
||||
if(NULL == gCaseConv )
|
||||
StartUpCaseConversion();
|
||||
|
||||
// NS_ASSERTION( gCaseConv != NULL , "cannot obtain UnicharUtil");
|
||||
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
IMPLEMENTATION NOTES:
|
||||
@@ -158,6 +104,15 @@ static void CheckCaseConversion()
|
||||
that no poor soul would ever have to do this again. Sigh.
|
||||
***********************************************************************/
|
||||
|
||||
void Subsume(nsStr& aDest,nsStr& aSource){
|
||||
aDest.mStr=aSource.mStr;
|
||||
aDest.mLength=aSource.mLength;
|
||||
aDest.mMultibyte=aSource.mMultibyte;
|
||||
aDest.mCapacity=aSource.mCapacity;
|
||||
aDest.mOwnsBuffer=aSource.mOwnsBuffer;
|
||||
aSource.mOwnsBuffer=PR_FALSE;
|
||||
aSource.mStr=0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor. Note that we actually allocate a small buffer
|
||||
@@ -216,6 +171,15 @@ nsString2::nsString2(const nsString2& aString) :mAgent(aString.mAgent) {
|
||||
nsStr::Assign(*this,aString,0,aString.mLength,mAgent);
|
||||
}
|
||||
|
||||
/**
|
||||
* construct off a subsumeable string
|
||||
* @update gess 1/4/99
|
||||
* @param reference to a subsumeString
|
||||
*/
|
||||
nsString2::nsString2(nsSubsumeStr& aSubsumeStr) :mAgent(0) {
|
||||
Subsume(*this,aSubsumeStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
* Make sure we call nsStr::Destroy.
|
||||
@@ -293,7 +257,7 @@ void nsString2::SetCapacity(PRUint32 aLength) {
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
char* nsString2::GetBuffer(void) const {
|
||||
const char* nsString2::GetBuffer(void) const {
|
||||
if(!mMultibyte)
|
||||
return mStr;
|
||||
return 0;
|
||||
@@ -305,7 +269,7 @@ char* nsString2::GetBuffer(void) const {
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRUnichar* nsString2::GetUnicode(void) const {
|
||||
const PRUnichar* nsString2::GetUnicode(void) const {
|
||||
if(mMultibyte)
|
||||
return (PRUnichar*)mUStr;
|
||||
return 0;
|
||||
@@ -314,11 +278,11 @@ PRUnichar* nsString2::GetUnicode(void) const {
|
||||
/**
|
||||
* Get nth character.
|
||||
*/
|
||||
PRUnichar nsString2::operator[](int anIndex) const {
|
||||
PRUnichar nsString2::operator[](PRUint32 anIndex) const {
|
||||
return GetCharAt(*this,anIndex);
|
||||
}
|
||||
|
||||
PRUnichar nsString2::CharAt(int anIndex) const {
|
||||
PRUnichar nsString2::CharAt(PRUint32 anIndex) const {
|
||||
return GetCharAt(*this,anIndex);
|
||||
}
|
||||
|
||||
@@ -352,10 +316,10 @@ PRBool nsString2::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsString2 nsString2::operator+(const nsStr& aString){
|
||||
nsSubsumeStr nsString2::operator+(const nsStr& aString){
|
||||
nsString2 temp(*this); //make a temp string the same size as this...
|
||||
nsStr::Append(temp,aString,0,aString.mLength,mAgent);
|
||||
return temp;
|
||||
return nsSubsumeStr(temp);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -364,10 +328,10 @@ nsString2 nsString2::operator+(const nsStr& aString){
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsString2 nsString2::operator+(const nsString2& aString){
|
||||
nsSubsumeStr nsString2::operator+(const nsString2& aString){
|
||||
nsString2 temp(*this); //make a temp string the same size as this...
|
||||
nsStr::Append(temp,aString,0,aString.mLength,mAgent);
|
||||
return temp;
|
||||
return nsSubsumeStr(temp);
|
||||
}
|
||||
|
||||
|
||||
@@ -377,10 +341,10 @@ nsString2 nsString2::operator+(const nsString2& aString){
|
||||
* @param aCString is a ptr to cstring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 nsString2::operator+(const char* aCString) {
|
||||
nsSubsumeStr nsString2::operator+(const char* aCString) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(aCString);
|
||||
return temp;
|
||||
return nsSubsumeStr(temp);
|
||||
}
|
||||
|
||||
|
||||
@@ -390,10 +354,10 @@ nsString2 nsString2::operator+(const char* aCString) {
|
||||
* @param aChar is a char to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 nsString2::operator+(char aChar) {
|
||||
nsSubsumeStr nsString2::operator+(char aChar) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(char(aChar));
|
||||
return temp;
|
||||
return nsSubsumeStr(temp);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -402,10 +366,10 @@ nsString2 nsString2::operator+(char aChar) {
|
||||
* @param aString is a ptr to unistring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 nsString2::operator+(const PRUnichar* aString) {
|
||||
nsSubsumeStr nsString2::operator+(const PRUnichar* aString) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(aString);
|
||||
return temp;
|
||||
return nsSubsumeStr(temp);
|
||||
}
|
||||
|
||||
|
||||
@@ -415,10 +379,10 @@ nsString2 nsString2::operator+(const PRUnichar* aString) {
|
||||
* @param aChar is a unichar to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 nsString2::operator+(PRUnichar aChar) {
|
||||
nsSubsumeStr nsString2::operator+(PRUnichar aChar) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(char(aChar));
|
||||
return temp;
|
||||
return nsSubsumeStr(temp);
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
@@ -429,6 +393,7 @@ nsString2 nsString2::operator+(PRUnichar aChar) {
|
||||
* Converts all chars in given string to UCS2
|
||||
*/
|
||||
void nsString2::ToUCS2(PRUint32 aStartOffset){
|
||||
static CTableConstructor gTableConstructor;
|
||||
if(aStartOffset<mLength){
|
||||
if(mMultibyte) {
|
||||
PRUint32 theIndex=0;
|
||||
@@ -621,11 +586,11 @@ PRUnichar* nsString2::ToNewUnicode() const {
|
||||
*/
|
||||
char* nsString2::ToCString(char* aBuf, PRUint32 aBufLength) const{
|
||||
if(aBuf) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mStr=aBuf;
|
||||
theTempStr.mCapacity=aBufLength;
|
||||
nsStr::Assign(theTempStr,*this,0,mLength,mAgent);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mStr=aBuf;
|
||||
temp.mCapacity=aBufLength;
|
||||
nsStr::Assign(temp,*this,0,mLength,mAgent);
|
||||
}
|
||||
return aBuf;
|
||||
}
|
||||
@@ -800,15 +765,19 @@ nsString2& nsString2::Assign(PRUnichar aChar) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies contents of this onto given string.
|
||||
* @update gess 7/27/98
|
||||
* @param aString to hold copy of this
|
||||
* @return nada.
|
||||
* WARNING! THIS IS A VERY SPECIAL METHOD.
|
||||
* This method "steals" the contents of aSource and hands it to aDest.
|
||||
* Ordinarily a copy is made, but not in this version.
|
||||
* @update gess10/30/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void nsString2::Copy(nsString2& aString) const{
|
||||
aString.SetString(*this);
|
||||
nsString2& nsString2::operator=(nsSubsumeStr& aSubsumeString) {
|
||||
Subsume(*this,aSubsumeString);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @update gess 01/04/99
|
||||
@@ -843,12 +812,12 @@ nsString2& nsString2::Append(const nsString2& aString,PRInt32 aCount) {
|
||||
*/
|
||||
nsString2& nsString2::Append(const char* aCString,PRInt32 aCount) {
|
||||
if(aCString){
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eOneByte);
|
||||
theTemp.mStr=(char*)aCString;
|
||||
theTemp.mLength=nsCRT::strlen(aCString);
|
||||
if(-1==aCount) aCount=theTemp.mLength;
|
||||
nsStr::Append(*this,theTemp,0,aCount,mAgent);
|
||||
nsStr temp;
|
||||
Initialize(temp,eOneByte);
|
||||
temp.mStr=(char*)aCString;
|
||||
temp.mLength=nsCRT::strlen(aCString);
|
||||
if(-1==aCount) aCount=temp.mLength;
|
||||
nsStr::Append(*this,temp,0,aCount,mAgent);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -862,12 +831,12 @@ nsString2& nsString2::Append(const char* aCString,PRInt32 aCount) {
|
||||
*/
|
||||
nsString2& nsString2::Append(const PRUnichar* aString,PRInt32 aCount) {
|
||||
if(aString){
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eTwoByte);
|
||||
theTemp.mUStr=(PRUnichar*)aString;
|
||||
theTemp.mLength=nsCRT::strlen(aString);
|
||||
if(-1==aCount) aCount=theTemp.mLength;
|
||||
nsStr::Append(*this,theTemp,0,aCount,mAgent);
|
||||
nsStr temp;
|
||||
Initialize(temp,eTwoByte);
|
||||
temp.mUStr=(PRUnichar*)aString;
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
if(-1==aCount) aCount=temp.mLength;
|
||||
nsStr::Append(*this,temp,0,aCount,mAgent);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -882,11 +851,11 @@ nsString2& nsString2::Append(char aChar) {
|
||||
char buf[2]={0,0};
|
||||
buf[0]=aChar;
|
||||
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eOneByte);
|
||||
theTemp.mStr=buf;
|
||||
theTemp.mLength=1;
|
||||
nsStr::Append(*this,theTemp,0,1,mAgent);
|
||||
nsStr temp;
|
||||
Initialize(temp,eOneByte);
|
||||
temp.mStr=buf;
|
||||
temp.mLength=1;
|
||||
nsStr::Append(*this,temp,0,1,mAgent);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -900,11 +869,11 @@ nsString2& nsString2::Append(PRUnichar aChar) {
|
||||
PRUnichar buf[2]={0,0};
|
||||
buf[0]=aChar;
|
||||
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eTwoByte);
|
||||
theTemp.mUStr=buf;
|
||||
theTemp.mLength=1;
|
||||
nsStr::Append(*this,theTemp,0,1,mAgent);
|
||||
nsStr temp;
|
||||
Initialize(temp,eTwoByte);
|
||||
temp.mUStr=buf;
|
||||
temp.mLength=1;
|
||||
nsStr::Append(*this,temp,0,1,mAgent);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -1001,7 +970,7 @@ PRUint32 nsString2::Right(nsString2& aCopy,PRInt32 aCount) const{
|
||||
* @param aCount -- number of chars to be copied from aCopy
|
||||
* @return number of chars inserted into this.
|
||||
*/
|
||||
nsString2& nsString2::Insert(nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount) {
|
||||
nsString2& nsString2::Insert(const nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount) {
|
||||
nsStr::Insert(*this,anOffset,aCopy,0,aCount,mAgent);
|
||||
return *this;
|
||||
}
|
||||
@@ -1018,12 +987,12 @@ nsString2& nsString2::Insert(nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount)
|
||||
nsString2& nsString2::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCount){
|
||||
if(aCString){
|
||||
if(0<aCount) {
|
||||
nsStr theTemp;
|
||||
nsStr::Initialize(theTemp,eOneByte);
|
||||
theTemp.mStr=(char*)aCString;
|
||||
theTemp.mLength=nsCRT::strlen(aCString);
|
||||
if(theTemp.mLength){
|
||||
nsStr::Insert(*this,anOffset,theTemp,0,aCount,0);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mStr=(char*)aCString;
|
||||
temp.mLength=nsCRT::strlen(aCString);
|
||||
if(temp.mLength){
|
||||
nsStr::Insert(*this,anOffset,temp,0,aCount,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1044,11 +1013,11 @@ nsString2& nsString2::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCou
|
||||
nsString2& nsString2::Insert(char aChar,PRUint32 anOffset){
|
||||
char theBuffer[2]={0,0};
|
||||
theBuffer[0]=aChar;
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mStr=(char*)theBuffer;
|
||||
theTempStr.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,theTempStr,0,1,0);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mStr=(char*)theBuffer;
|
||||
temp.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,temp,0,1,0);
|
||||
return *this;
|
||||
}
|
||||
*/
|
||||
@@ -1065,12 +1034,12 @@ nsString2& nsString2::Insert(char aChar,PRUint32 anOffset){
|
||||
nsString2& nsString2::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32 aCount){
|
||||
if(aString){
|
||||
if(0<aCount) {
|
||||
nsStr theTemp;
|
||||
nsStr::Initialize(theTemp,eTwoByte);
|
||||
theTemp.mUStr=(PRUnichar*)aString;
|
||||
theTemp.mLength=nsCRT::strlen(aString);
|
||||
if(theTemp.mLength){
|
||||
nsStr::Insert(*this,anOffset,theTemp,0,aCount,0);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eTwoByte);
|
||||
temp.mUStr=(PRUnichar*)aString;
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
if(temp.mLength){
|
||||
nsStr::Insert(*this,anOffset,temp,0,aCount,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1090,11 +1059,11 @@ nsString2& nsString2::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32
|
||||
nsString2& nsString2::Insert(PRUnichar aChar,PRUint32 anOffset){
|
||||
PRUnichar theBuffer[2]={0,0};
|
||||
theBuffer[0]=aChar;
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mUStr=theBuffer;
|
||||
theTempStr.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,theTempStr,0,1,0);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eTwoByte);
|
||||
temp.mUStr=theBuffer;
|
||||
temp.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,temp,0,1,0);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -1153,11 +1122,11 @@ PRInt32 nsString2::Find(const char* aCString,PRBool aIgnoreCase) const{
|
||||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aCString) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCString);
|
||||
theTempStr.mStr=(char*)aCString;
|
||||
result=nsStr::FindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCString);
|
||||
temp.mStr=(char*)aCString;
|
||||
result=nsStr::FindSubstr(*this,temp,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1174,11 +1143,11 @@ PRInt32 nsString2::Find(const PRUnichar* aString,PRBool aIgnoreCase) const{
|
||||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aString) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mUStr=(PRUnichar*)aString;
|
||||
result=nsStr::FindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eTwoByte);
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
temp.mUStr=(PRUnichar*)aString;
|
||||
result=nsStr::FindSubstr(*this,temp,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1195,6 +1164,18 @@ PRInt32 nsString2::Find(const nsStr& aString,PRBool aIgnoreCase) const{
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for given buffer within this string
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param nsString2 -- buffer to be found
|
||||
* @return offset in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 nsString2::Find(const nsString2& aString,PRBool aIgnoreCase) const{
|
||||
PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,0);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for a given char, starting at given offset
|
||||
*
|
||||
@@ -1219,11 +1200,11 @@ PRInt32 nsString2::FindCharInSet(const char* aCStringSet,PRUint32 anOffset) cons
|
||||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aCStringSet) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCStringSet);
|
||||
theTempStr.mStr=(char*)aCStringSet;
|
||||
result=nsStr::FindCharInSet(*this,theTempStr,PR_FALSE,anOffset);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCStringSet);
|
||||
temp.mStr=(char*)aCStringSet;
|
||||
result=nsStr::FindCharInSet(*this,temp,PR_FALSE,anOffset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1252,11 +1233,11 @@ PRInt32 nsString2::RFindCharInSet(const char* aCStringSet,PRUint32 anOffset) con
|
||||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aCStringSet) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCStringSet);
|
||||
theTempStr.mStr=(char*)aCStringSet;
|
||||
result=nsStr::RFindCharInSet(*this,theTempStr,PR_FALSE,anOffset);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCStringSet);
|
||||
temp.mStr=(char*)aCStringSet;
|
||||
result=nsStr::RFindCharInSet(*this,temp,PR_FALSE,anOffset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1285,6 +1266,18 @@ PRInt32 nsString2::RFind(const nsStr& aString,PRBool aIgnoreCase) const{
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsString2::RFind(const nsString2& aString,PRBool aIgnoreCase) const{
|
||||
PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,0);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
@@ -1297,11 +1290,11 @@ PRInt32 nsString2::RFind(const char* aString,PRBool aIgnoreCase) const{
|
||||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aString) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mStr=(char*)aString;
|
||||
result=nsStr::RFindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
temp.mStr=(char*)aString;
|
||||
result=nsStr::RFindSubstr(*this,temp,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1334,11 +1327,11 @@ PRInt32 nsString2::Compare(const char *aCString,PRBool aIgnoreCase,PRInt32 aLeng
|
||||
NS_ASSERTION(0!=aCString,kNullPointerError);
|
||||
|
||||
if(aCString) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCString);
|
||||
theTempStr.mStr=(char*)aCString;
|
||||
return nsStr::Compare(*this,theTempStr,aLength,aIgnoreCase);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCString);
|
||||
temp.mStr=(char*)aCString;
|
||||
return nsStr::Compare(*this,temp,aLength,aIgnoreCase);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1354,11 +1347,11 @@ PRInt32 nsString2::Compare(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 a
|
||||
NS_ASSERTION(0!=aString,kNullPointerError);
|
||||
|
||||
if(aString) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mUStr=(PRUnichar*)aString;
|
||||
return nsStr::Compare(*this,theTempStr,aLength,aIgnoreCase);
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eTwoByte);
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
temp.mUStr=(PRUnichar*)aString;
|
||||
return nsStr::Compare(*this,temp,aLength,aIgnoreCase);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1568,16 +1561,37 @@ PRBool nsString2::IsDigit(PRUnichar aChar) {
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Define the string deallocator class...
|
||||
**************************************************************/
|
||||
class nsStringDeallocator: public nsDequeFunctor{
|
||||
public:
|
||||
virtual void* operator()(void* anObject) {
|
||||
static nsMemoryAgent theAgent;
|
||||
nsString2* aString= (nsString2*)anObject;
|
||||
if(aString){
|
||||
aString->mAgent=&theAgent;
|
||||
delete aString;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* This class, appropriately enough, creates and recycles nsString2 objects..
|
||||
****************************************************************************/
|
||||
|
||||
#if 0
|
||||
|
||||
class nsStringRecycler {
|
||||
public:
|
||||
nsStringRecycler() : mDeque(0) {
|
||||
}
|
||||
|
||||
~nsStringRecycler() {
|
||||
nsStringDeallocator theDeallocator;
|
||||
mDeque.ForEach(theDeallocator); //now delete the strings
|
||||
}
|
||||
|
||||
void Recycle(nsString2* aString) {
|
||||
mDeque.Push(aString);
|
||||
}
|
||||
@@ -1623,7 +1637,6 @@ void nsString2::Recycle(nsString2* aString){
|
||||
GetRecycler().Recycle(aString);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -1690,14 +1703,12 @@ NS_BASE int fputs(const nsString2& aString, FILE* out)
|
||||
*/
|
||||
void nsString2::SelfTest(void) {
|
||||
|
||||
#if 0
|
||||
#ifdef NS_DEBUG
|
||||
static const char* kConstructorError = kConstructorError;
|
||||
static const char* kComparisonError = "Comparision error!";
|
||||
static const char* kEqualsError = "Equals error!";
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
mSelfTested=PR_TRUE;
|
||||
#endif
|
||||
|
||||
eCharSize theSize=eOneByte;
|
||||
|
||||
@@ -1705,8 +1716,18 @@ void nsString2::SelfTest(void) {
|
||||
{
|
||||
{
|
||||
nsString2 theString0("foo",theSize); //watch it construct and destruct
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
nsString2 theString("hello");
|
||||
nsString2 temp1=theString+" there!";
|
||||
nsString2 temp2=theString+'!';
|
||||
nsSubsumeStr temp3=theString+'?';
|
||||
nsString2 temp4(temp3);
|
||||
temp1=temp3;
|
||||
nsSubsumeStr temp5("hello");
|
||||
}
|
||||
|
||||
nsString2 theString1(theSize);
|
||||
nsString2 theString("hello",theSize);
|
||||
nsString2 theString3(theString,theSize);
|
||||
@@ -1721,6 +1742,8 @@ void nsString2::SelfTest(void) {
|
||||
//while we're here, let's try truncation and setting the length.
|
||||
theString3.Truncate(3);
|
||||
theLen=theString3.Length();
|
||||
|
||||
|
||||
theString.SetCapacity(3);
|
||||
const char* theBuffer=theString.GetBuffer();
|
||||
const char* theOther=theBuffer;
|
||||
@@ -1736,12 +1759,17 @@ void nsString2::SelfTest(void) {
|
||||
theString5.StripWhitespace();
|
||||
|
||||
nsString2* theString6=theString5.ToNewString();
|
||||
nsString2::Recycle(theString6);
|
||||
|
||||
char* str=theString5.ToNewCString();
|
||||
delete [] str;
|
||||
|
||||
char buffer[100];
|
||||
theString5.ToCString(buffer,sizeof(buffer)-1);
|
||||
theOther=theString5.GetBuffer();
|
||||
}
|
||||
//try a few numeric conversion routines...
|
||||
|
||||
//try a few numeric conversion routines...
|
||||
{
|
||||
nsString2 str1("10000",theSize);
|
||||
PRInt32 err;
|
||||
@@ -1753,11 +1781,12 @@ void nsString2::SelfTest(void) {
|
||||
{
|
||||
nsString2 theString("hello",theSize);
|
||||
PRUint32 len=theString.Length();
|
||||
PRUnichar ch;
|
||||
for(PRUint32 i=0;i<len;i++) {
|
||||
PRUnichar ch3=theString.CharAt(i);
|
||||
ch=theString.CharAt(i);
|
||||
}
|
||||
PRUnichar ch4=theString.First();
|
||||
PRUnichar ch5=theString.Last();
|
||||
ch=theString.First();
|
||||
ch=theString.Last();
|
||||
}
|
||||
|
||||
//**********************************************
|
||||
@@ -1826,7 +1855,6 @@ void nsString2::SelfTest(void) {
|
||||
temp1.Right(temp2,4);
|
||||
}
|
||||
|
||||
|
||||
//**********************************************
|
||||
//Now let's test the INSERTION methods...
|
||||
//**********************************************
|
||||
@@ -1973,6 +2001,15 @@ void nsString2::SelfTest(void) {
|
||||
pos=find1.BinarySearch('i');
|
||||
pos=find1.BinarySearch('z');
|
||||
}
|
||||
|
||||
{
|
||||
//now let's try a memory allocation test...
|
||||
nsString2 temp;
|
||||
for(int i=0;i<100;i++){
|
||||
temp+="hello ";
|
||||
}
|
||||
int x=5;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1981,14 +2018,6 @@ void nsString2::SelfTest(void) {
|
||||
IMPLEMENTATION NOTES: AUTOSTRING...
|
||||
***********************************************************************/
|
||||
|
||||
void InitAutoStr(nsAutoString2& aDest,nsBufDescriptor& aBufDescriptor){
|
||||
aDest.mAgent=0;
|
||||
aDest.mStr=aBufDescriptor.mStr;
|
||||
aDest.mMultibyte=aBufDescriptor.mMultibyte;
|
||||
aDest.mCapacity=(sizeof(aDest.mBuffer)>>aDest.mMultibyte)-1;
|
||||
aDest.mOwnsBuffer=aBufDescriptor.mOwnsBuffer;
|
||||
AddNullTerminator(aDest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Special case constructor, that allows the consumer to provide
|
||||
@@ -1998,8 +2027,9 @@ void InitAutoStr(nsAutoString2& aDest,nsBufDescriptor& aBufDescriptor){
|
||||
* @param aCurrentLength tells us the current length of the buffer
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(eCharSize aCharSize) : nsString2(aCharSize){
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
mAgent=0;
|
||||
AddNullTerminator(*this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2007,8 +2037,10 @@ nsAutoString2::nsAutoString2(eCharSize aCharSize) : nsString2(aCharSize){
|
||||
* @param anExtBuffer describes an external buffer
|
||||
* @param aCString is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(nsBufDescriptor& aBufDescriptor,const char* aCString) : nsString2(aBufDescriptor.mMultibyte) {
|
||||
InitAutoStr(*this,aBufDescriptor);
|
||||
nsAutoString2::nsAutoString2(nsStr& aStr,const char* aCString) : nsString2(aStr.mMultibyte) {
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aStr.mMultibyte)-1,0,aStr.mMultibyte,PR_FALSE);
|
||||
mAgent=0;
|
||||
AddNullTerminator(*this);
|
||||
Assign(aCString);
|
||||
}
|
||||
|
||||
@@ -2017,8 +2049,9 @@ nsAutoString2::nsAutoString2(nsBufDescriptor& aBufDescriptor,const char* aCStrin
|
||||
* @param aCString is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const char* aCString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
mAgent=0;
|
||||
AddNullTerminator(*this);
|
||||
Assign(aCString);
|
||||
}
|
||||
|
||||
@@ -2026,15 +2059,15 @@ nsAutoString2::nsAutoString2(const char* aCString,eCharSize aCharSize) : nsStrin
|
||||
* Copy construct from ascii c-string
|
||||
* @param aCString is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(char* aCString,PRUint32 aLen,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
nsAutoString2::nsAutoString2(char* aCString,PRUint32 aCapacity,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
mAgent=0;
|
||||
if(assumeOwnership) {
|
||||
nsBufDescriptor theDescriptor(aCString,aLen,eOneByte,PR_TRUE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
nsStr::Initialize(*this,aCString,aCapacity,0,eOneByte,PR_TRUE);
|
||||
}
|
||||
else {
|
||||
nsBufDescriptor theDescriptor(mBuffer,aLen,aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
}
|
||||
AddNullTerminator(*this);
|
||||
Assign(aCString);
|
||||
}
|
||||
|
||||
@@ -2043,8 +2076,9 @@ nsAutoString2::nsAutoString2(char* aCString,PRUint32 aLen,eCharSize aCharSize,PR
|
||||
* @param aString is a ptr to a unistr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const PRUnichar* aString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
@@ -2052,15 +2086,15 @@ nsAutoString2::nsAutoString2(const PRUnichar* aString,eCharSize aCharSize) : nsS
|
||||
* Copy construct from uni-string
|
||||
* @param aString is a ptr to a unistr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(PRUnichar* aString,PRUint32 aLength,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
nsAutoString2::nsAutoString2(PRUnichar* aString,PRUint32 aCapacity,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
mAgent=0;
|
||||
if(assumeOwnership) {
|
||||
nsBufDescriptor theDescriptor((char*)aString,aLength,eTwoByte,PR_TRUE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
nsStr::Initialize(*this,(char*)aString,aCapacity,0,eTwoByte,PR_TRUE);
|
||||
}
|
||||
else {
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
}
|
||||
AddNullTerminator(*this);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
@@ -2070,8 +2104,9 @@ nsAutoString2::nsAutoString2(PRUnichar* aString,PRUint32 aLength,eCharSize aChar
|
||||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const nsStr& aString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
@@ -2080,8 +2115,9 @@ nsAutoString2::nsAutoString2(const nsStr& aString,eCharSize aCharSize) : nsStrin
|
||||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const nsAutoString2& aString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
@@ -2090,8 +2126,9 @@ nsAutoString2::nsAutoString2(const nsAutoString2& aString,eCharSize aCharSize) :
|
||||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const nsString2& aString,eCharSize aCharSize) : nsString2(aCharSize){
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
@@ -2101,11 +2138,22 @@ nsAutoString2::nsAutoString2(const nsString2& aString,eCharSize aCharSize) : nsS
|
||||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(PRUnichar aChar,eCharSize aCharSize) : nsString2(aCharSize){
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
Assign(aChar);
|
||||
}
|
||||
|
||||
/**
|
||||
* construct from a subsumeable string
|
||||
* @update gess 1/4/99
|
||||
* @param reference to a subsumeString
|
||||
*/
|
||||
nsAutoString2::nsAutoString2( nsSubsumeStr& aSubsumeStr) :nsString2(aSubsumeStr.mMultibyte) {
|
||||
mAgent=0;
|
||||
Subsume(*this,aSubsumeStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* deconstruct the autstring
|
||||
* @param
|
||||
@@ -2120,3 +2168,16 @@ void nsAutoString2::SizeOf(nsISizeOfHandler* aHandler) const {
|
||||
aHandler->Add(mCapacity << mMultibyte);
|
||||
}
|
||||
|
||||
nsSubsumeStr::nsSubsumeStr(nsString2& aString) : nsString2() {
|
||||
Subsume(*this,aString);
|
||||
}
|
||||
|
||||
nsSubsumeStr::nsSubsumeStr(nsStr& aString) : nsString2() {
|
||||
Subsume(*this,aString);
|
||||
}
|
||||
|
||||
nsSubsumeStr::nsSubsumeStr(const PRUnichar* aString) : nsString2(aString,eTwoByte) {
|
||||
}
|
||||
|
||||
nsSubsumeStr::nsSubsumeStr(const char* aString) : nsString2(aString,eOneByte) {
|
||||
}
|
||||
|
||||
@@ -20,18 +20,19 @@
|
||||
/***********************************************************************
|
||||
MODULE NOTES:
|
||||
|
||||
This class provides a 1-byte ASCII string implementation that shares
|
||||
a common API with all other strImpl derivatives.
|
||||
This version of the nsString class offers many improvements over the
|
||||
original version:
|
||||
1. Wide and narrow chars
|
||||
2. Allocators
|
||||
3. Much smarter autostrings
|
||||
4. Subsumable strings
|
||||
5. Memory pools and recycling
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef _nsString2
|
||||
#define _nsString2
|
||||
|
||||
//#define nsString2 nsString
|
||||
//#define nsAutoString2 nsAutoString
|
||||
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nscore.h"
|
||||
#include <iostream.h>
|
||||
@@ -46,6 +47,13 @@
|
||||
class nsISizeOfHandler;
|
||||
|
||||
|
||||
#ifdef USE_STRING2
|
||||
#define nsString2 nsString
|
||||
#define nsAutoString2 nsAutoString
|
||||
#endif
|
||||
|
||||
class NS_BASE nsSubsumeStr;
|
||||
|
||||
class NS_BASE nsString2 : public nsStr {
|
||||
|
||||
public:
|
||||
@@ -83,6 +91,12 @@ nsString2(const nsStr&,eCharSize aCharSize=kDefaultCharSize,nsIMemoryAgent* anAg
|
||||
*/
|
||||
nsString2(const nsString2& aString);
|
||||
|
||||
/**
|
||||
* This constructor takes a subsumestr
|
||||
* @param reference to subsumestr
|
||||
*/
|
||||
nsString2(nsSubsumeStr& aSubsumeStr);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*
|
||||
@@ -139,16 +153,15 @@ PRBool IsOrdered(void) const;
|
||||
Accessor methods...
|
||||
*********************************************************************/
|
||||
|
||||
char* GetBuffer(void) const;
|
||||
PRUnichar* GetUnicode(void) const;
|
||||
operator PRUnichar*() const {return GetUnicode();}
|
||||
const char* GetBuffer(void) const;
|
||||
const PRUnichar* GetUnicode(void) const;
|
||||
|
||||
|
||||
/**
|
||||
* Get nth character.
|
||||
*/
|
||||
PRUnichar operator[](int anIndex) const;
|
||||
PRUnichar CharAt(int anIndex) const;
|
||||
PRUnichar operator[](PRUint32 anIndex) const;
|
||||
PRUnichar CharAt(PRUint32 anIndex) const;
|
||||
PRUnichar First(void) const;
|
||||
PRUnichar Last(void) const;
|
||||
|
||||
@@ -164,42 +177,42 @@ PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsString2 operator+(const nsStr& aString);
|
||||
nsSubsumeStr operator+(const nsStr& aString);
|
||||
|
||||
/**
|
||||
* Create a new string by appending given string to this
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsString2 operator+(const nsString2& aString);
|
||||
nsSubsumeStr operator+(const nsString2& aString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given buffer.
|
||||
* @param aCString is a ptr to cstring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 operator+(const char* aCString);
|
||||
nsSubsumeStr operator+(const char* aCString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given wide buffer.
|
||||
* @param aString is a ptr to UC-string to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 operator+(const PRUnichar* aString);
|
||||
nsSubsumeStr operator+(const PRUnichar* aString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given char.
|
||||
* @param aChar is a char to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 operator+(char aChar);
|
||||
nsSubsumeStr operator+(char aChar);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given char.
|
||||
* @param aChar is a unichar to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsString2 operator+(PRUnichar aChar);
|
||||
nsSubsumeStr operator+(PRUnichar aChar);
|
||||
|
||||
/**********************************************************************
|
||||
Lexomorphic transforms...
|
||||
@@ -353,7 +366,6 @@ PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=10) const;
|
||||
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);}
|
||||
void Copy(nsString2& aString) const;
|
||||
|
||||
/**
|
||||
* assign given string to this string
|
||||
@@ -380,6 +392,7 @@ 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);}
|
||||
nsString2& operator=(nsSubsumeStr& aSubsumeString);
|
||||
|
||||
/**
|
||||
* Here's a bunch of append mehtods for varying types...
|
||||
@@ -402,8 +415,7 @@ nsString2& operator+=(PRUnichar aChar){return Append(aChar);}
|
||||
*/
|
||||
nsString2& Append(const nsStr& aString) {return Append(aString,aString.mLength);}
|
||||
nsString2& Append(const nsString2& aString) {return Append(aString,aString.mLength);}
|
||||
nsString2& Append(const char* aString) {if(aString) {Append(aString,nsCRT::strlen(aString));} return *this;}
|
||||
nsString2& Append(const PRUnichar* aString) {if(aString) {Append(aString,nsCRT::strlen(aString));} return *this;}
|
||||
|
||||
|
||||
/*
|
||||
* Appends n characters from given string to this,
|
||||
@@ -414,13 +426,13 @@ nsString2& Append(const PRUnichar* aString) {if(aString) {Append(aString,nsCRT::
|
||||
*/
|
||||
nsString2& Append(const nsStr& aString,PRInt32 aCount);
|
||||
nsString2& Append(const nsString2& aString,PRInt32 aCount);
|
||||
nsString2& Append(const char* aString,PRInt32 aCount);
|
||||
nsString2& Append(const PRUnichar* 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,
|
||||
* starting at the leftmost offset.
|
||||
@@ -464,7 +476,7 @@ PRUint32 Right(nsString2& aCopy,PRInt32 aCount) const;
|
||||
* @param aCount -- number of chars to be copied from aCopy
|
||||
* @return number of chars inserted into this.
|
||||
*/
|
||||
nsString2& Insert(nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
|
||||
nsString2& Insert(const nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
|
||||
|
||||
/**
|
||||
* Insert a given string into this string at
|
||||
@@ -519,6 +531,7 @@ PRInt32 BinarySearch(PRUnichar aChar) const;
|
||||
* @param aString is substring to be sought in this
|
||||
* @return offset 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;
|
||||
@@ -554,6 +567,7 @@ PRInt32 RFindCharInSet(const nsString2& aString,PRUint32 anOffset=0) const;
|
||||
* @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,PRBool aIgnoreCase=PR_FALSE,PRUint32 offset=0) const;
|
||||
@@ -675,10 +689,8 @@ static PRBool IsAlpha(PRUnichar ch);
|
||||
*/
|
||||
static PRBool IsDigit(PRUnichar ch);
|
||||
|
||||
#if 0
|
||||
static void Recycle(nsString2* aString);
|
||||
static nsString2* NewString(eCharSize aCharSize=eTwoByte);
|
||||
#endif
|
||||
|
||||
static void SelfTest();
|
||||
virtual void DebugDump(ostream& aStream) const;
|
||||
@@ -701,12 +713,11 @@ ostream& operator<<(ostream& os,nsString2& aString);
|
||||
If the buffer needs to grow, it gets reallocated on the heap.
|
||||
**************************************************************/
|
||||
|
||||
|
||||
class NS_BASE nsAutoString2 : public nsString2 {
|
||||
public:
|
||||
|
||||
nsAutoString2(eCharSize aCharSize=kDefaultCharSize);
|
||||
nsAutoString2(nsBufDescriptor& anExtBuffer,const char* aCString);
|
||||
nsAutoString2(nsStr& anExtBuffer,const char* aCString);
|
||||
|
||||
|
||||
nsAutoString2(const char* aCString,eCharSize aCharSize=kDefaultCharSize);
|
||||
@@ -717,6 +728,7 @@ public:
|
||||
nsAutoString2(const nsStr& aString,eCharSize aCharSize=kDefaultCharSize);
|
||||
nsAutoString2(const nsString2& aString,eCharSize aCharSize=kDefaultCharSize);
|
||||
nsAutoString2(const nsAutoString2& aString,eCharSize aCharSize=kDefaultCharSize);
|
||||
nsAutoString2(nsSubsumeStr& aSubsumeStr);
|
||||
nsAutoString2(PRUnichar aChar,eCharSize aCharSize=kDefaultCharSize);
|
||||
virtual ~nsAutoString2();
|
||||
|
||||
@@ -738,5 +750,28 @@ public:
|
||||
};
|
||||
|
||||
|
||||
/***************************************************************
|
||||
The subsumestr class is very unusual.
|
||||
It differs from a normal string in that it doesn't use normal
|
||||
copy semantics when another string is assign to this.
|
||||
Instead, it "steals" the contents of the source string.
|
||||
|
||||
This is very handy for returning nsString classes as part of
|
||||
an operator+(...) for example, in that it cuts down the number
|
||||
of copy operations that must occur.
|
||||
|
||||
You should probably not use this class unless you really know
|
||||
what you're doing.
|
||||
***************************************************************/
|
||||
class NS_BASE nsSubsumeStr : public nsString2 {
|
||||
public:
|
||||
nsSubsumeStr(nsString2& aString);
|
||||
nsSubsumeStr(nsStr& aString);
|
||||
nsSubsumeStr(const PRUnichar* aString);
|
||||
nsSubsumeStr(const char* aString);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user