зеркало из https://github.com/mozilla/gecko-dev.git
backing out string changes until I can get it right
This commit is contained in:
Родитель
ac88c0c3d6
Коммит
5b3132ce88
|
@ -31,12 +31,7 @@
|
|||
|
||||
#include "nsCRT.h"
|
||||
|
||||
#ifndef RICKG_TESTBED
|
||||
#include "nsUnicharUtilCIID.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsICaseConversion.h"
|
||||
#endif
|
||||
|
||||
static const PRInt32 kNotFound=-1;
|
||||
|
||||
inline PRUnichar GetUnicharAt(const char* aString,PRUint32 anIndex) {
|
||||
return ((PRUnichar*)aString)[anIndex];
|
||||
|
@ -67,7 +62,7 @@ PRInt32 CompressChars2(char* aString,PRUint32 aLength,const char* aSet,PRUint32
|
|||
*/
|
||||
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;
|
||||
|
@ -112,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;
|
||||
|
@ -289,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,const PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
inline PRInt32 FindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
PRUnichar theCmpChar=(aIgnoreCase ? nsCRT::ToUpper(aChar) : aChar);
|
||||
PRUint32 theIndex=0;
|
||||
for(theIndex=0;theIndex<aLength;theIndex++){
|
||||
|
@ -313,7 +308,7 @@ inline PRInt32 FindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,co
|
|||
* @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,const PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
inline PRInt32 FindChar2(const char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
PRUnichar theCmpChar=(aIgnoreCase ? nsCRT::ToUpper(aChar) : aChar);
|
||||
PRUint32 theIndex=0;
|
||||
for(theIndex=0;theIndex<aLength;theIndex++){
|
||||
|
@ -339,7 +334,7 @@ inline PRInt32 FindChar2(const char* aDest,PRUint32 aLength,PRUint32 anOffset,co
|
|||
* @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,const PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
inline PRInt32 RFindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
PRUnichar theCmpChar=(aIgnoreCase ? nsCRT::ToUpper(aChar) : aChar);
|
||||
PRUint32 theIndex=0;
|
||||
for(theIndex=aLength-1;theIndex>=0;theIndex--){
|
||||
|
@ -365,7 +360,7 @@ inline PRInt32 RFindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,c
|
|||
* @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,const PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
inline PRInt32 RFindChar2(const char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
PRUnichar theCmpChar=(aIgnoreCase ? nsCRT::ToUpper(aChar) : aChar);
|
||||
PRUint32 theIndex=0;
|
||||
for(theIndex=aLength-1;theIndex>=0;theIndex--){
|
||||
|
@ -378,7 +373,7 @@ inline PRInt32 RFindChar2(const char* aDest,PRUint32 aLength,PRUint32 anOffset,c
|
|||
return kNotFound;
|
||||
}
|
||||
|
||||
typedef PRInt32 (*FindChars)(const char* aDest,PRUint32 aLength,PRUint32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase);
|
||||
typedef PRInt32 (*FindChars)(const char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUnichar aChar,PRBool aIgnoreCase);
|
||||
FindChars gFindChars[]={&FindChar1,&FindChar2};
|
||||
FindChars gRFindChars[]={&RFindChar1,&RFindChar2};
|
||||
|
||||
|
@ -506,53 +501,6 @@ 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
|
||||
*
|
||||
|
@ -563,25 +511,14 @@ protected:
|
|||
* @return 0
|
||||
*/
|
||||
PRInt32 ConvertCase2(char* aString,PRUint32 aCount,PRBool aToUpper){
|
||||
PRUnichar* cp = (PRUnichar*)aString;
|
||||
PRUnichar* end = cp + aCount-1;
|
||||
PRInt32 result=0;
|
||||
|
||||
#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
|
||||
|
||||
typedef PRUnichar chartype;
|
||||
chartype* cp = (chartype*)aString;
|
||||
chartype* end = cp + aCount-1;
|
||||
|
||||
while (cp <= end) {
|
||||
PRUnichar ch = *cp;
|
||||
chartype ch = *cp;
|
||||
if(aToUpper) {
|
||||
if ((ch >= 'a') && (ch <= 'z')) {
|
||||
*cp = 'A' + (ch - 'a');
|
||||
|
@ -617,7 +554,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];
|
||||
|
@ -649,7 +586,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];
|
||||
|
@ -690,7 +627,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;
|
||||
|
@ -813,7 +750,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);
|
||||
|
||||
|
@ -859,7 +796,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,103 +31,11 @@
|
|||
#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];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -163,25 +71,9 @@ 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);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess10/30/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess10/30/98
|
||||
|
@ -189,9 +81,13 @@ void nsStr::Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 a
|
|||
* @return
|
||||
*/
|
||||
nsIMemoryAgent* GetDefaultAgent(void){
|
||||
// static nsPoolingMemoryAgent gDefaultAgent;
|
||||
static nsMemoryAgent gDefaultAgent;
|
||||
return (nsIMemoryAgent*)&gDefaultAgent;
|
||||
static nsIMemoryAgent* gDefaultAgent=0;
|
||||
if(!gDefaultAgent)
|
||||
gDefaultAgent=new nsMemoryAgent();
|
||||
|
||||
NS_ASSERTION(gDefaultAgent,"You MUST always have an allocator!");
|
||||
|
||||
return gDefaultAgent;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -214,6 +110,20 @@ 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
|
||||
|
@ -245,8 +155,8 @@ void nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAgen
|
|||
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
|
||||
EnsureCapacity(theTempStr,aNewLength,theAgent);
|
||||
|
||||
if(aDest.mLength) {
|
||||
Append(theTempStr,aDest,0,aDest.mLength,theAgent);
|
||||
if(0<aDest.mLength) {
|
||||
Append(theTempStr,aDest,0,aDest.mLength,anAgent);
|
||||
}
|
||||
theAgent->Free(aDest);
|
||||
aDest.mStr = theTempStr.mStr;
|
||||
|
@ -272,12 +182,13 @@ 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 gess10/30/98
|
||||
* @update gess 04/04/99
|
||||
* @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);
|
||||
|
@ -310,30 +221,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){
|
||||
ToRange(aDestOffset,0,aDest.mLength);
|
||||
if((0<aSource.mLength) && (aDestOffset<aDest.mLength-1)){
|
||||
if(aDest.mLength){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
//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-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);
|
||||
}
|
||||
|
@ -349,20 +260,22 @@ 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,PRUint32 aCount,nsIMemoryAgent* anAgent){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){
|
||||
if(0<aCount){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
|
||||
PRUint32 theDelta=aDest.mLength-aDestOffset;
|
||||
PRUint32 theLength=(theDelta<aCount) ? theDelta : aCount;
|
||||
PRInt32 theDelta=aDest.mLength-aDestOffset;
|
||||
PRInt32 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 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
|
||||
}
|
||||
|
||||
|
@ -430,28 +343,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=GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRUnichar theFirstTargetChar=nsStr::GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=nsStr::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=GetCharAt(aDest,index+theSubIndex);
|
||||
PRUnichar theChar=nsStr::GetCharAt(aDest,index+theSubIndex);
|
||||
if(theSubIndex>0) {
|
||||
if(theFirstTargetChar==theChar){
|
||||
PRUnichar theDestJumpChar=GetCharAt(aDest,index+theTargetMax);
|
||||
PRUnichar theDestJumpChar=nsStr::GetCharAt(aDest,index+theTargetMax);
|
||||
if(theDestJumpChar==theLastTargetChar) {
|
||||
theNewStartPos=index; //this lets us jump ahead during our search where possible.
|
||||
}//if
|
||||
}//if
|
||||
}//if
|
||||
PRUnichar theTargetChar=GetCharAt(aTarget,theSubIndex);
|
||||
PRUnichar theTargetChar=nsStr::GetCharAt(aTarget,theSubIndex);
|
||||
matches=PRBool(theChar==theTargetChar);
|
||||
}
|
||||
if(matches)
|
||||
|
@ -471,8 +384,8 @@ PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnor
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
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);
|
||||
PRInt32 nsStr::FindChar(const nsStr& aDest, PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -502,12 +415,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=GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRUnichar theFirstTargetChar=nsStr::GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=nsStr::GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRInt32 theTargetMax=aTarget.mLength;
|
||||
|
||||
while(index--) {
|
||||
|
@ -516,16 +429,16 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgno
|
|||
|
||||
if(anOffset+aTarget.mLength<=aDest.mLength) {
|
||||
while((++theSubIndex<theTargetMax) && (matches)){
|
||||
PRUnichar theChar=GetCharAt(aDest,index+theSubIndex);
|
||||
PRUnichar theChar=nsStr::GetCharAt(aDest,index+theSubIndex);
|
||||
if(theSubIndex>0) {
|
||||
if(theFirstTargetChar==theChar){
|
||||
PRUnichar theDestJumpChar=GetCharAt(aDest,index+theTargetMax);
|
||||
PRUnichar theDestJumpChar=nsStr::GetCharAt(aDest,index+theTargetMax);
|
||||
if(theDestJumpChar==theLastTargetChar) {
|
||||
theNewStartPos=index; //this lets us jump ahead during our search where possible.
|
||||
}//if
|
||||
}//if
|
||||
}//if
|
||||
PRUnichar theTargetChar=GetCharAt(aTarget,theSubIndex);
|
||||
PRUnichar theTargetChar=nsStr::GetCharAt(aTarget,theSubIndex);
|
||||
matches=PRBool(theChar==theTargetChar);
|
||||
} //while
|
||||
} //if
|
||||
|
@ -546,8 +459,8 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgno
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
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);
|
||||
PRInt32 nsStr::RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gRFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -559,11 +472,11 @@ PRInt32 nsStr::RFindChar(const nsStr& aDest,const PRUnichar aChar, PRBool aIgnor
|
|||
* @return
|
||||
*/
|
||||
PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRUint32 offset=aDest.mLength-anOffset;
|
||||
PRInt32 offset=aDest.mLength-anOffset;
|
||||
PRInt32 thePos;
|
||||
|
||||
while(--offset>=0) {
|
||||
PRUnichar theChar=GetCharAt(aDest,offset);
|
||||
PRUnichar theChar=GetCharAt(aDest,PRUint32(offset));
|
||||
thePos=gRFindChars[aSet.mMultibyte](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase);
|
||||
if(kNotFound!=thePos)
|
||||
return offset;
|
||||
|
@ -578,7 +491,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) {
|
||||
|
|
111
base/src/nsStr.h
111
base/src/nsStr.h
|
@ -27,6 +27,8 @@
|
|||
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
|
||||
|
@ -42,13 +44,41 @@
|
|||
#ifndef _nsStr
|
||||
#define _nsStr
|
||||
|
||||
#include "nsCore.h"
|
||||
#include "prtypes.h"
|
||||
#include "nscore.h"
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
enum eCharSize {eOneByte=0,eTwoByte=1};
|
||||
#define kDefaultCharSize eTwoByte
|
||||
const PRInt32 kNotFound = -1;
|
||||
|
||||
|
||||
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;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
class nsIMemoryAgent;
|
||||
|
@ -67,15 +97,6 @@ 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
|
||||
|
@ -145,7 +166,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,PRUint32 aCount,nsIMemoryAgent* anAgent=0);
|
||||
static void Delete(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0);
|
||||
|
||||
/**
|
||||
* This method is used to truncate the given string.
|
||||
|
@ -233,20 +254,21 @@ 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);
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
PRUint32 mLength;
|
||||
eCharSize mMultibyte;
|
||||
PRUint32 mCapacity;
|
||||
PRUint32 mOwnsBuffer;
|
||||
PRUint32 mUnused;
|
||||
#else
|
||||
PRUint32 mLength: 30;
|
||||
eCharSize mMultibyte: 2;
|
||||
PRUint32 mLength : 30;
|
||||
eCharSize mMultibyte : 2;
|
||||
PRUint32 mCapacity: 30;
|
||||
PRUint32 mOwnsBuffer: 1;
|
||||
PRUint32 mUnused: 1;
|
||||
#endif
|
||||
PRUint32 mOwnsBuffer: 1;
|
||||
PRUint32 mUnused: 1;
|
||||
union {
|
||||
char* mStr;
|
||||
PRUnichar* mUStr;
|
||||
|
@ -285,21 +307,6 @@ 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 {
|
||||
|
@ -310,18 +317,25 @@ public:
|
|||
};
|
||||
|
||||
class nsMemoryAgent : public nsIMemoryAgent {
|
||||
protected:
|
||||
enum eDelta{eDefaultSize=16};
|
||||
enum eDelta{eGrowthDelta=8};
|
||||
public:
|
||||
|
||||
virtual PRBool Alloc(nsStr& aDest,PRInt32 aCount) {
|
||||
|
||||
//we're given the acount value in charunits; now scale up to next multiple.
|
||||
PRInt32 theNewCapacity=eDefaultSize;
|
||||
while(theNewCapacity<aCount){
|
||||
theNewCapacity<<=1;
|
||||
//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;
|
||||
}
|
||||
|
||||
|
||||
aDest.mCapacity=theNewCapacity++;
|
||||
size_t theSize=(theNewCapacity<<aDest.mMultibyte);
|
||||
aDest.mStr=new char[theSize];
|
||||
|
@ -348,8 +362,5 @@ public:
|
|||
|
||||
};
|
||||
|
||||
char* GetSharedEmptyBuffer();
|
||||
nsIMemoryAgent* GetDefaultAgent(void);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -30,8 +30,8 @@
|
|||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef _nsString1
|
||||
#define _nsString1
|
||||
#ifndef _NSSTRING
|
||||
#define _NSSTRING
|
||||
|
||||
|
||||
#include "prtypes.h"
|
||||
|
@ -39,18 +39,9 @@
|
|||
#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 nsString1 {
|
||||
class NS_BASE nsString {
|
||||
public:
|
||||
|
||||
/**
|
||||
|
@ -59,30 +50,30 @@ class NS_BASE nsString1 {
|
|||
* was to allow developers direct access to the underlying buffer for
|
||||
* performance reasons.
|
||||
*/
|
||||
nsString1();
|
||||
nsString();
|
||||
|
||||
/**
|
||||
* This constructor accepts an isolatin string
|
||||
* @param an ascii is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsString1(const char* aCString);
|
||||
nsString(const char* aCString);
|
||||
|
||||
/**
|
||||
* This is our copy constructor
|
||||
* @param reference to another nsString1
|
||||
* @param reference to another nsString
|
||||
*/
|
||||
nsString1(const nsString1&);
|
||||
nsString(const nsString&);
|
||||
|
||||
/**
|
||||
* Constructor from a unicode string
|
||||
* @param anicodestr pts to a unicode string
|
||||
*/
|
||||
nsString1(const PRUnichar* aUnicode);
|
||||
nsString(const PRUnichar* aUnicode);
|
||||
|
||||
/**
|
||||
* Virtual Destructor
|
||||
*/
|
||||
virtual ~nsString1();
|
||||
virtual ~nsString();
|
||||
|
||||
|
||||
/**
|
||||
|
@ -145,14 +136,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
|
||||
|
@ -192,35 +183,35 @@ PRBool SetCharAt(PRUnichar aChar,PRInt32 anIndex);
|
|||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsString1 operator+(const nsString1& aString);
|
||||
nsString operator+(const nsString& 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
|
||||
*/
|
||||
nsString1 operator+(const char* aCString);
|
||||
nsString 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
|
||||
*/
|
||||
nsString1 operator+(char aChar);
|
||||
nsString 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
|
||||
*/
|
||||
nsString1 operator+(const PRUnichar* aBuffer);
|
||||
nsString 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
|
||||
*/
|
||||
nsString1 operator+(PRUnichar aChar);
|
||||
nsString operator+(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* Converts all chars in internal string to lower
|
||||
|
@ -230,7 +221,7 @@ void ToLowerCase();
|
|||
/**
|
||||
* Converts all chars in given string to lower
|
||||
*/
|
||||
void ToLowerCase(nsString1& aString) const;
|
||||
void ToLowerCase(nsString& aString) const;
|
||||
|
||||
/**
|
||||
* Converts all chars in given string to upper
|
||||
|
@ -246,13 +237,13 @@ void ToUCS2(PRInt32 aStartOffset);
|
|||
/**
|
||||
* Converts all chars in internal string to upper
|
||||
*/
|
||||
void ToUpperCase(nsString1& aString) const;
|
||||
void ToUpperCase(nsString& aString) const;
|
||||
|
||||
/**
|
||||
* Creates a duplicate clone (ptr) of this string.
|
||||
* @return ptr to clone of this string
|
||||
*/
|
||||
nsString1* ToNewString() const;
|
||||
nsString* ToNewString() const;
|
||||
|
||||
/**
|
||||
* Creates an ascii clone of this string
|
||||
|
@ -274,7 +265,7 @@ char* ToCString(char* aBuf,PRInt32 aBufLength) const;
|
|||
* @param aString to hold copy of this
|
||||
* @return nada.
|
||||
*/
|
||||
void Copy(nsString1& aString) const;
|
||||
void Copy(nsString& aString) const;
|
||||
|
||||
/**
|
||||
* Creates an unichar clone of this string
|
||||
|
@ -307,72 +298,79 @@ PRInt32 ToInteger(PRInt32* aErrorCode,PRInt32 aRadix=10) const;
|
|||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString1& SetString(const PRUnichar* aStr,PRInt32 aLength=-1);
|
||||
nsString1& SetString(const char* aCString,PRInt32 aLength=-1);
|
||||
nsString1& SetString(const nsString1& aString);
|
||||
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);
|
||||
|
||||
/**
|
||||
* assign given string to this one
|
||||
* @param aString: string to be added to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator=(const nsString1& aString);
|
||||
nsString& operator=(const nsString& aString);
|
||||
|
||||
/**
|
||||
* assign given char* to this string
|
||||
* @param aCString: buffer to be assigned to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator=(const char* aCString);
|
||||
nsString& operator=(const char* aCString);
|
||||
|
||||
/**
|
||||
* assign given char to this string
|
||||
* @param aChar: char to be assignd to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator=(char aChar);
|
||||
nsString& operator=(char aChar);
|
||||
|
||||
/**
|
||||
* assign given unichar* to this string
|
||||
* @param aBuffer: unichar buffer to be assigned to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator=(const PRUnichar* aBuffer);
|
||||
nsString& operator=(const PRUnichar* aBuffer);
|
||||
|
||||
/**
|
||||
* assign given char to this string
|
||||
* @param aChar: char to be assignd to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator=(PRUnichar aChar);
|
||||
nsString& operator=(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @param aString : string to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator+=(const nsString1& aString);
|
||||
nsString& operator+=(const nsString& aString);
|
||||
|
||||
/**
|
||||
* append given buffer to this string
|
||||
* @param aCString: buffer to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator+=(const char* aCString);
|
||||
nsString& operator+=(const char* aCString);
|
||||
|
||||
/**
|
||||
* append given buffer to this string
|
||||
* @param aBuffer: buffer to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator+=(const PRUnichar* aBuffer);
|
||||
nsString& operator+=(const PRUnichar* aBuffer);
|
||||
|
||||
/**
|
||||
* append given char to this string
|
||||
* @param aChar: char to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator+=(PRUnichar aChar);
|
||||
nsString& operator+=(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
|
@ -381,7 +379,7 @@ nsString1& operator+=(PRUnichar aChar);
|
|||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Append(const nsString1& aString,PRInt32 aLength=-1);
|
||||
nsString& Append(const nsString& aString,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
|
@ -390,14 +388,14 @@ nsString1& Append(const nsString1& aString,PRInt32 aLength=-1);
|
|||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Append(const char* aCString,PRInt32 aLength=-1);
|
||||
nsString& Append(const char* aCString,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @param aString : string to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Append(char aChar);
|
||||
nsString& Append(char aChar);
|
||||
|
||||
/**
|
||||
* append given unichar buffer to this string
|
||||
|
@ -406,14 +404,14 @@ nsString1& Append(char aChar);
|
|||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Append(const PRUnichar* aBuffer,PRInt32 aLength=-1);
|
||||
nsString& 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
|
||||
*/
|
||||
nsString1& Append(PRUnichar aChar);
|
||||
nsString& Append(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* Append an integer onto this string
|
||||
|
@ -421,14 +419,14 @@ nsString1& Append(PRUnichar aChar);
|
|||
* @param aRadix specifies 8,10,16
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Append(PRInt32 aInteger,PRInt32 aRadix); //radix=8,10 or 16
|
||||
nsString& 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
|
||||
*/
|
||||
nsString1& Append(float aFloat);
|
||||
nsString& Append(float aFloat);
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
|
@ -439,7 +437,7 @@ nsString1& Append(float aFloat);
|
|||
* @param aCount -- number of chars to copy
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Left(nsString1& aCopy,PRInt32 aCount) const;
|
||||
PRInt32 Left(nsString& aCopy,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
|
@ -451,7 +449,7 @@ PRInt32 Left(nsString1& aCopy,PRInt32 aCount) const;
|
|||
* @param anOffset -- position where copying begins
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Mid(nsString1& aCopy,PRInt32 anOffset,PRInt32 aCount) const;
|
||||
PRInt32 Mid(nsString& aCopy,PRInt32 anOffset,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
|
@ -462,7 +460,7 @@ PRInt32 Mid(nsString1& aCopy,PRInt32 anOffset,PRInt32 aCount) const;
|
|||
* @param aCount -- number of chars to copy
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Right(nsString1& aCopy,PRInt32 aCount) const;
|
||||
PRInt32 Right(nsString& aCopy,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* This method inserts n chars from given string into this
|
||||
|
@ -473,7 +471,7 @@ PRInt32 Right(nsString1& aCopy,PRInt32 aCount) const;
|
|||
* @param aCount -- number of chars to be copied from aCopy
|
||||
* @return number of chars inserted into this.
|
||||
*/
|
||||
PRInt32 Insert(const nsString1& aCopy,PRInt32 anOffset,PRInt32 aCount=-1);
|
||||
PRInt32 Insert(const nsString& aCopy,PRInt32 anOffset,PRInt32 aCount=-1);
|
||||
|
||||
/**
|
||||
* Insert a single unicode char into this string at
|
||||
|
@ -493,7 +491,7 @@ PRInt32 Insert(PRUnichar aChar,PRInt32 anOffset);
|
|||
* @param aCount -- number of chars to be cut
|
||||
* @return *this
|
||||
*/
|
||||
nsString1& Cut(PRInt32 anOffset,PRInt32 aCount);
|
||||
nsString& Cut(PRInt32 anOffset,PRInt32 aCount);
|
||||
|
||||
/**
|
||||
* This method is used to remove all occurances of the
|
||||
|
@ -502,7 +500,7 @@ nsString1& Cut(PRInt32 anOffset,PRInt32 aCount);
|
|||
* @param aSet -- characters to be cut from this
|
||||
* @return *this
|
||||
*/
|
||||
nsString1& StripChars(const char* aSet);
|
||||
nsString& StripChars(const char* aSet);
|
||||
|
||||
/**
|
||||
* This method is used to replace all occurances of the
|
||||
|
@ -511,14 +509,14 @@ nsString1& StripChars(const char* aSet);
|
|||
* @param
|
||||
* @return *this
|
||||
*/
|
||||
nsString1& ReplaceChar(PRUnichar aSourceChar, PRUnichar aDestChar);
|
||||
nsString& ReplaceChar(PRUnichar aSourceChar, PRUnichar aDestChar);
|
||||
|
||||
/**
|
||||
* This method strips whitespace throughout the string
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
nsString1& StripWhitespace();
|
||||
nsString& StripWhitespace();
|
||||
|
||||
/**
|
||||
* This method trims characters found in aTrimSet from
|
||||
|
@ -528,7 +526,7 @@ nsString1& StripWhitespace();
|
|||
* both ends
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Trim(const char* aSet,
|
||||
nsString& Trim(const char* aSet,
|
||||
PRBool aEliminateLeading=PR_TRUE,
|
||||
PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
|
@ -541,7 +539,7 @@ nsString1& Trim(const char* aSet,
|
|||
* @param aEliminateTrailing controls stripping of trailing ws
|
||||
* @return this
|
||||
*/
|
||||
nsString1& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,
|
||||
nsString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,
|
||||
PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
/**
|
||||
|
@ -590,7 +588,7 @@ PRInt32 BinarySearch(PRUnichar aChar) const;
|
|||
*/
|
||||
PRInt32 Find(const char* aString) const;
|
||||
PRInt32 Find(const PRUnichar* aString) const;
|
||||
PRInt32 Find(const nsString1& aString) const;
|
||||
PRInt32 Find(const nsString& aString) const;
|
||||
|
||||
/**
|
||||
* Search for given char within this string
|
||||
|
@ -608,7 +606,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(nsString1& aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 FindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
||||
|
||||
/**
|
||||
* This method searches this string for the last character
|
||||
|
@ -618,7 +616,7 @@ PRInt32 FindCharInSet(nsString1& 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(nsString1& aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 RFindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -629,7 +627,7 @@ PRInt32 RFindCharInSet(nsString1& 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 nsString1& aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
|
||||
/**
|
||||
* This methods scans the string backwards, looking for the given char
|
||||
|
@ -650,7 +648,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 nsString1 &aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
virtual PRInt32 Compare(const nsString &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;
|
||||
|
||||
|
@ -659,7 +657,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 nsString1 &aString) const;
|
||||
PRBool operator==(const nsString &aString) const;
|
||||
PRBool operator==(const char *aString) const;
|
||||
PRBool operator==(const PRUnichar* aString) const;
|
||||
PRBool operator==(PRUnichar* aString) const;
|
||||
|
@ -669,7 +667,7 @@ PRBool operator==(PRUnichar* aString) const;
|
|||
* @param aString is the string to be compared to this
|
||||
* @return TRUE
|
||||
*/
|
||||
PRBool operator!=(const nsString1 &aString) const;
|
||||
PRBool operator!=(const nsString &aString) const;
|
||||
PRBool operator!=(const char *aString) const;
|
||||
PRBool operator!=(const PRUnichar* aString) const;
|
||||
|
||||
|
@ -678,7 +676,7 @@ PRBool operator!=(const PRUnichar* aString) const;
|
|||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator<(const nsString1 &aString) const;
|
||||
PRBool operator<(const nsString &aString) const;
|
||||
PRBool operator<(const char *aString) const;
|
||||
PRBool operator<(const PRUnichar* aString) const;
|
||||
|
||||
|
@ -687,7 +685,7 @@ PRBool operator<(const PRUnichar* aString) const;
|
|||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator>(const nsString1 &S) const;
|
||||
PRBool operator>(const nsString &S) const;
|
||||
PRBool operator>(const char *aCString) const;
|
||||
PRBool operator>(const PRUnichar* aString) const;
|
||||
|
||||
|
@ -696,7 +694,7 @@ PRBool operator>(const PRUnichar* aString) const;
|
|||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator<=(const nsString1 &S) const;
|
||||
PRBool operator<=(const nsString &S) const;
|
||||
PRBool operator<=(const char *aCString) const;
|
||||
PRBool operator<=(const PRUnichar* aString) const;
|
||||
|
||||
|
@ -705,7 +703,7 @@ PRBool operator<=(const PRUnichar* aString) const;
|
|||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator>=(const nsString1 &S) const;
|
||||
PRBool operator>=(const nsString &S) const;
|
||||
PRBool operator>=(const char* aCString) const;
|
||||
PRBool operator>=(const PRUnichar* aString) const;
|
||||
|
||||
|
@ -719,7 +717,7 @@ PRBool operator>=(const PRUnichar* aString) const;
|
|||
* @param aLength -- optional length of given string.
|
||||
* @return TRUE if equal
|
||||
*/
|
||||
PRBool Equals(const nsString1& aString) const;
|
||||
PRBool Equals(const nsString& aString) const;
|
||||
PRBool Equals(const char* aString,PRInt32 aLength=-1) const;
|
||||
PRBool Equals(const nsIAtom *aAtom) const;
|
||||
|
||||
|
@ -742,7 +740,7 @@ PRBool Equals(const PRUnichar* s1, const PRUnichar* s2) const;
|
|||
* @param aLength -- optional length of given string.
|
||||
* @return TRUE if equal
|
||||
*/
|
||||
PRBool EqualsIgnoreCase(const nsString1& aString) const;
|
||||
PRBool EqualsIgnoreCase(const nsString& aString) const;
|
||||
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aLength=-1) const;
|
||||
PRBool EqualsIgnoreCase(const nsIAtom *aAtom) const;
|
||||
|
||||
|
@ -770,34 +768,34 @@ typedef PRUnichar chartype;
|
|||
#endif
|
||||
};
|
||||
|
||||
ostream& operator<<(ostream& os,nsString1& aString);
|
||||
extern NS_BASE int fputs(const nsString1& aString, FILE* out);
|
||||
ostream& operator<<(ostream& os,nsString& aString);
|
||||
extern NS_BASE int fputs(const nsString& aString, FILE* out);
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* A version of nsString1 which is designed to be used as an automatic
|
||||
* A version of nsString 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 nsAutoString1 : public nsString1 {
|
||||
class NS_BASE nsAutoString : public nsString {
|
||||
public:
|
||||
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();
|
||||
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& 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;}
|
||||
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;}
|
||||
|
||||
virtual void SizeOf(nsISizeOfHandler* aHandler) const;
|
||||
|
||||
|
@ -809,7 +807,7 @@ protected:
|
|||
chartype mBuf[32];
|
||||
};
|
||||
|
||||
ostream& operator<<(ostream& os,nsAutoString1& aString);
|
||||
ostream& operator<<(ostream& os,nsAutoString& aString);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -25,15 +25,18 @@
|
|||
#include "nsDebug.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsISizeOfHandler.h"
|
||||
#include "prprf.h"
|
||||
#include "prdtoa.h"
|
||||
#include "nsDeque.h"
|
||||
|
||||
#ifndef RICKG_TESTBED
|
||||
#include "prdtoa.h"
|
||||
#include "nsISizeOfHandler.h"
|
||||
#endif
|
||||
#include "nsUnicharUtilCIID.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsICaseConversion.h"
|
||||
|
||||
static const char* kNullPointerError = "Error: unexpected null ptr";
|
||||
static const char* kWhitespace="\b\t\r\n ";
|
||||
static const PRInt32 kNotFound=-1;
|
||||
|
||||
#ifdef RICKG_DEBUG
|
||||
PRBool nsString2::mSelfTested = PR_FALSE;
|
||||
|
@ -94,7 +97,58 @@ 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:
|
||||
|
@ -104,15 +158,6 @@ public:
|
|||
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
|
||||
|
@ -171,15 +216,6 @@ 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.
|
||||
|
@ -257,7 +293,7 @@ void nsString2::SetCapacity(PRUint32 aLength) {
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
const char* nsString2::GetBuffer(void) const {
|
||||
char* nsString2::GetBuffer(void) const {
|
||||
if(!mMultibyte)
|
||||
return mStr;
|
||||
return 0;
|
||||
|
@ -269,7 +305,7 @@ const char* nsString2::GetBuffer(void) const {
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
const PRUnichar* nsString2::GetUnicode(void) const {
|
||||
PRUnichar* nsString2::GetUnicode(void) const {
|
||||
if(mMultibyte)
|
||||
return (PRUnichar*)mUStr;
|
||||
return 0;
|
||||
|
@ -278,11 +314,11 @@ const PRUnichar* nsString2::GetUnicode(void) const {
|
|||
/**
|
||||
* Get nth character.
|
||||
*/
|
||||
PRUnichar nsString2::operator[](PRUint32 anIndex) const {
|
||||
PRUnichar nsString2::operator[](int anIndex) const {
|
||||
return GetCharAt(*this,anIndex);
|
||||
}
|
||||
|
||||
PRUnichar nsString2::CharAt(PRUint32 anIndex) const {
|
||||
PRUnichar nsString2::CharAt(int anIndex) const {
|
||||
return GetCharAt(*this,anIndex);
|
||||
}
|
||||
|
||||
|
@ -316,10 +352,10 @@ PRBool nsString2::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
|
|||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsSubsumeStr nsString2::operator+(const nsStr& aString){
|
||||
nsString2 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 nsSubsumeStr(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -328,10 +364,10 @@ nsSubsumeStr nsString2::operator+(const nsStr& aString){
|
|||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsSubsumeStr nsString2::operator+(const nsString2& aString){
|
||||
nsString2 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 nsSubsumeStr(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
|
@ -341,10 +377,10 @@ nsSubsumeStr nsString2::operator+(const nsString2& aString){
|
|||
* @param aCString is a ptr to cstring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsSubsumeStr nsString2::operator+(const char* aCString) {
|
||||
nsString2 nsString2::operator+(const char* aCString) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(aCString);
|
||||
return nsSubsumeStr(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
|
@ -354,10 +390,10 @@ nsSubsumeStr nsString2::operator+(const char* aCString) {
|
|||
* @param aChar is a char to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsSubsumeStr nsString2::operator+(char aChar) {
|
||||
nsString2 nsString2::operator+(char aChar) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(char(aChar));
|
||||
return nsSubsumeStr(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -366,10 +402,10 @@ nsSubsumeStr nsString2::operator+(char aChar) {
|
|||
* @param aString is a ptr to unistring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsSubsumeStr nsString2::operator+(const PRUnichar* aString) {
|
||||
nsString2 nsString2::operator+(const PRUnichar* aString) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(aString);
|
||||
return nsSubsumeStr(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
|
@ -379,10 +415,10 @@ nsSubsumeStr nsString2::operator+(const PRUnichar* aString) {
|
|||
* @param aChar is a unichar to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsSubsumeStr nsString2::operator+(PRUnichar aChar) {
|
||||
nsString2 nsString2::operator+(PRUnichar aChar) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(char(aChar));
|
||||
return nsSubsumeStr(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
|
@ -393,7 +429,6 @@ nsSubsumeStr 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;
|
||||
|
@ -586,11 +621,11 @@ PRUnichar* nsString2::ToNewUnicode() const {
|
|||
*/
|
||||
char* nsString2::ToCString(char* aBuf, PRUint32 aBufLength) const{
|
||||
if(aBuf) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mStr=aBuf;
|
||||
temp.mCapacity=aBufLength;
|
||||
nsStr::Assign(temp,*this,0,mLength,mAgent);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mStr=aBuf;
|
||||
theTempStr.mCapacity=aBufLength;
|
||||
nsStr::Assign(theTempStr,*this,0,mLength,mAgent);
|
||||
}
|
||||
return aBuf;
|
||||
}
|
||||
|
@ -765,19 +800,15 @@ nsString2& nsString2::Assign(PRUnichar aChar) {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* Copies contents of this onto given string.
|
||||
* @update gess 7/27/98
|
||||
* @param aString to hold copy of this
|
||||
* @return nada.
|
||||
*/
|
||||
nsString2& nsString2::operator=(nsSubsumeStr& aSubsumeString) {
|
||||
Subsume(*this,aSubsumeString);
|
||||
return *this;
|
||||
void nsString2::Copy(nsString2& aString) const{
|
||||
aString.SetString(*this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @update gess 01/04/99
|
||||
|
@ -812,12 +843,12 @@ nsString2& nsString2::Append(const nsString2& aString,PRInt32 aCount) {
|
|||
*/
|
||||
nsString2& nsString2::Append(const char* aCString,PRInt32 aCount) {
|
||||
if(aCString){
|
||||
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);
|
||||
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);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
@ -831,12 +862,12 @@ nsString2& nsString2::Append(const char* aCString,PRInt32 aCount) {
|
|||
*/
|
||||
nsString2& nsString2::Append(const PRUnichar* aString,PRInt32 aCount) {
|
||||
if(aString){
|
||||
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);
|
||||
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);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
@ -851,11 +882,11 @@ nsString2& nsString2::Append(char aChar) {
|
|||
char buf[2]={0,0};
|
||||
buf[0]=aChar;
|
||||
|
||||
nsStr temp;
|
||||
Initialize(temp,eOneByte);
|
||||
temp.mStr=buf;
|
||||
temp.mLength=1;
|
||||
nsStr::Append(*this,temp,0,1,mAgent);
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eOneByte);
|
||||
theTemp.mStr=buf;
|
||||
theTemp.mLength=1;
|
||||
nsStr::Append(*this,theTemp,0,1,mAgent);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -869,11 +900,11 @@ nsString2& nsString2::Append(PRUnichar aChar) {
|
|||
PRUnichar buf[2]={0,0};
|
||||
buf[0]=aChar;
|
||||
|
||||
nsStr temp;
|
||||
Initialize(temp,eTwoByte);
|
||||
temp.mUStr=buf;
|
||||
temp.mLength=1;
|
||||
nsStr::Append(*this,temp,0,1,mAgent);
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eTwoByte);
|
||||
theTemp.mUStr=buf;
|
||||
theTemp.mLength=1;
|
||||
nsStr::Append(*this,theTemp,0,1,mAgent);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -970,7 +1001,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(const nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount) {
|
||||
nsString2& nsString2::Insert(nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount) {
|
||||
nsStr::Insert(*this,anOffset,aCopy,0,aCount,mAgent);
|
||||
return *this;
|
||||
}
|
||||
|
@ -987,12 +1018,12 @@ nsString2& nsString2::Insert(const nsString2& aCopy,PRUint32 anOffset,PRInt32 aC
|
|||
nsString2& nsString2::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCount){
|
||||
if(aCString){
|
||||
if(0<aCount) {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1013,11 +1044,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 temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mStr=(char*)theBuffer;
|
||||
temp.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,temp,0,1,0);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mStr=(char*)theBuffer;
|
||||
theTempStr.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,theTempStr,0,1,0);
|
||||
return *this;
|
||||
}
|
||||
*/
|
||||
|
@ -1034,12 +1065,12 @@ nsString2& nsString2::Insert(char aChar,PRUint32 anOffset){
|
|||
nsString2& nsString2::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32 aCount){
|
||||
if(aString){
|
||||
if(0<aCount) {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1059,11 +1090,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 temp;
|
||||
nsStr::Initialize(temp,eTwoByte);
|
||||
temp.mUStr=theBuffer;
|
||||
temp.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,temp,0,1,0);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mUStr=theBuffer;
|
||||
theTempStr.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,theTempStr,0,1,0);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -1122,11 +1153,11 @@ PRInt32 nsString2::Find(const char* aCString,PRBool aIgnoreCase) const{
|
|||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aCString) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCString);
|
||||
temp.mStr=(char*)aCString;
|
||||
result=nsStr::FindSubstr(*this,temp,aIgnoreCase,0);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCString);
|
||||
theTempStr.mStr=(char*)aCString;
|
||||
result=nsStr::FindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -1143,11 +1174,11 @@ PRInt32 nsString2::Find(const PRUnichar* aString,PRBool aIgnoreCase) const{
|
|||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aString) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eTwoByte);
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
temp.mUStr=(PRUnichar*)aString;
|
||||
result=nsStr::FindSubstr(*this,temp,aIgnoreCase,0);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mUStr=(PRUnichar*)aString;
|
||||
result=nsStr::FindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -1164,18 +1195,6 @@ 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
|
||||
*
|
||||
|
@ -1200,11 +1219,11 @@ PRInt32 nsString2::FindCharInSet(const char* aCStringSet,PRUint32 anOffset) cons
|
|||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aCStringSet) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCStringSet);
|
||||
temp.mStr=(char*)aCStringSet;
|
||||
result=nsStr::FindCharInSet(*this,temp,PR_FALSE,anOffset);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCStringSet);
|
||||
theTempStr.mStr=(char*)aCStringSet;
|
||||
result=nsStr::FindCharInSet(*this,theTempStr,PR_FALSE,anOffset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -1233,11 +1252,11 @@ PRInt32 nsString2::RFindCharInSet(const char* aCStringSet,PRUint32 anOffset) con
|
|||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aCStringSet) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCStringSet);
|
||||
temp.mStr=(char*)aCStringSet;
|
||||
result=nsStr::RFindCharInSet(*this,temp,PR_FALSE,anOffset);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCStringSet);
|
||||
theTempStr.mStr=(char*)aCStringSet;
|
||||
result=nsStr::RFindCharInSet(*this,theTempStr,PR_FALSE,anOffset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -1266,18 +1285,6 @@ 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;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
|
@ -1290,11 +1297,11 @@ PRInt32 nsString2::RFind(const char* aString,PRBool aIgnoreCase) const{
|
|||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aString) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
temp.mStr=(char*)aString;
|
||||
result=nsStr::RFindSubstr(*this,temp,aIgnoreCase,0);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mStr=(char*)aString;
|
||||
result=nsStr::RFindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -1327,11 +1334,11 @@ PRInt32 nsString2::Compare(const char *aCString,PRBool aIgnoreCase,PRInt32 aLeng
|
|||
NS_ASSERTION(0!=aCString,kNullPointerError);
|
||||
|
||||
if(aCString) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCString);
|
||||
temp.mStr=(char*)aCString;
|
||||
return nsStr::Compare(*this,temp,aLength,aIgnoreCase);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCString);
|
||||
theTempStr.mStr=(char*)aCString;
|
||||
return nsStr::Compare(*this,theTempStr,aLength,aIgnoreCase);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1347,11 +1354,11 @@ PRInt32 nsString2::Compare(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 a
|
|||
NS_ASSERTION(0!=aString,kNullPointerError);
|
||||
|
||||
if(aString) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eTwoByte);
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
temp.mUStr=(PRUnichar*)aString;
|
||||
return nsStr::Compare(*this,temp,aLength,aIgnoreCase);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mUStr=(PRUnichar*)aString;
|
||||
return nsStr::Compare(*this,theTempStr,aLength,aIgnoreCase);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1561,37 +1568,16 @@ 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);
|
||||
}
|
||||
|
@ -1641,6 +1627,7 @@ void nsString2::Recycle(nsString2* aString){
|
|||
GetRecycler().Recycle(aString);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -1713,7 +1700,6 @@ void nsString2::SelfTest(void) {
|
|||
static const char* kConstructorError = kConstructorError;
|
||||
static const char* kComparisonError = "Comparision error!";
|
||||
static const char* kEqualsError = "Equals error!";
|
||||
|
||||
mSelfTested=PR_TRUE;
|
||||
|
||||
eCharSize theSize=eOneByte;
|
||||
|
@ -1722,18 +1708,8 @@ 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);
|
||||
|
@ -1748,8 +1724,6 @@ 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;
|
||||
|
@ -1765,17 +1739,12 @@ 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;
|
||||
|
@ -1787,12 +1756,11 @@ void nsString2::SelfTest(void) {
|
|||
{
|
||||
nsString2 theString("hello",theSize);
|
||||
PRUint32 len=theString.Length();
|
||||
PRUnichar ch;
|
||||
for(PRUint32 i=0;i<len;i++) {
|
||||
ch=theString.CharAt(i);
|
||||
PRUnichar ch3=theString.CharAt(i);
|
||||
}
|
||||
ch=theString.First();
|
||||
ch=theString.Last();
|
||||
PRUnichar ch4=theString.First();
|
||||
PRUnichar ch5=theString.Last();
|
||||
}
|
||||
|
||||
//**********************************************
|
||||
|
@ -1861,6 +1829,7 @@ void nsString2::SelfTest(void) {
|
|||
temp1.Right(temp2,4);
|
||||
}
|
||||
|
||||
|
||||
//**********************************************
|
||||
//Now let's test the INSERTION methods...
|
||||
//**********************************************
|
||||
|
@ -2007,15 +1976,6 @@ 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
|
||||
}
|
||||
|
||||
|
@ -2024,6 +1984,14 @@ 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
|
||||
|
@ -2033,9 +2001,8 @@ void nsString2::SelfTest(void) {
|
|||
* @param aCurrentLength tells us the current length of the buffer
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(eCharSize aCharSize) : nsString2(aCharSize){
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
mAgent=0;
|
||||
AddNullTerminator(*this);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2043,11 +2010,8 @@ nsAutoString2::nsAutoString2(eCharSize aCharSize) : nsString2(aCharSize){
|
|||
* @param anExtBuffer describes an external buffer
|
||||
* @param aCString is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(nsStr& aStr,const char* aCString) : nsString2((eCharSize)aStr.mMultibyte) {
|
||||
eCharSize theSize=(eCharSize)aStr.mMultibyte;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>theSize)-1,0,theSize,PR_FALSE);
|
||||
mAgent=0;
|
||||
AddNullTerminator(*this);
|
||||
nsAutoString2::nsAutoString2(nsBufDescriptor& aBufDescriptor,const char* aCString) : nsString2(aBufDescriptor.mMultibyte) {
|
||||
InitAutoStr(*this,aBufDescriptor);
|
||||
Assign(aCString);
|
||||
}
|
||||
|
||||
|
@ -2056,9 +2020,8 @@ nsAutoString2::nsAutoString2(nsStr& aStr,const char* aCString) : nsString2((eCha
|
|||
* @param aCString is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const char* aCString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
mAgent=0;
|
||||
AddNullTerminator(*this);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
Assign(aCString);
|
||||
}
|
||||
|
||||
|
@ -2066,15 +2029,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 aCapacity,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
mAgent=0;
|
||||
nsAutoString2::nsAutoString2(char* aCString,PRUint32 aLen,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
if(assumeOwnership) {
|
||||
nsStr::Initialize(*this,aCString,aCapacity,0,eOneByte,PR_TRUE);
|
||||
nsBufDescriptor theDescriptor(aCString,aLen,eOneByte,PR_TRUE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
}
|
||||
else {
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
nsBufDescriptor theDescriptor(mBuffer,aLen,aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
}
|
||||
AddNullTerminator(*this);
|
||||
Assign(aCString);
|
||||
}
|
||||
|
||||
|
@ -2083,9 +2046,8 @@ nsAutoString2::nsAutoString2(char* aCString,PRUint32 aCapacity,eCharSize aCharSi
|
|||
* @param aString is a ptr to a unistr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const PRUnichar* aString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
|
@ -2093,15 +2055,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 aCapacity,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
mAgent=0;
|
||||
nsAutoString2::nsAutoString2(PRUnichar* aString,PRUint32 aLength,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
if(assumeOwnership) {
|
||||
nsStr::Initialize(*this,(char*)aString,aCapacity,0,eTwoByte,PR_TRUE);
|
||||
nsBufDescriptor theDescriptor((char*)aString,aLength,eTwoByte,PR_TRUE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
}
|
||||
else {
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
}
|
||||
AddNullTerminator(*this);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
|
@ -2111,9 +2073,8 @@ nsAutoString2::nsAutoString2(PRUnichar* aString,PRUint32 aCapacity,eCharSize aCh
|
|||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const nsStr& aString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
|
@ -2122,9 +2083,8 @@ nsAutoString2::nsAutoString2(const nsStr& aString,eCharSize aCharSize) : nsStrin
|
|||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const nsAutoString2& aString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
|
@ -2133,9 +2093,8 @@ nsAutoString2::nsAutoString2(const nsAutoString2& aString,eCharSize aCharSize) :
|
|||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const nsString2& aString,eCharSize aCharSize) : nsString2(aCharSize){
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
|
@ -2145,22 +2104,11 @@ nsAutoString2::nsAutoString2(const nsString2& aString,eCharSize aCharSize) : nsS
|
|||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(PRUnichar aChar,eCharSize aCharSize) : nsString2(aCharSize){
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
Assign(aChar);
|
||||
}
|
||||
|
||||
/**
|
||||
* construct from a subsumeable string
|
||||
* @update gess 1/4/99
|
||||
* @param reference to a subsumeString
|
||||
*/
|
||||
nsAutoString2::nsAutoString2( nsSubsumeStr& aSubsumeStr) :nsString2((eCharSize)aSubsumeStr.mMultibyte) {
|
||||
mAgent=0;
|
||||
Subsume(*this,aSubsumeStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* deconstruct the autstring
|
||||
* @param
|
||||
|
@ -2175,16 +2123,3 @@ 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,19 +20,18 @@
|
|||
/***********************************************************************
|
||||
MODULE NOTES:
|
||||
|
||||
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
|
||||
This class provides a 1-byte ASCII string implementation that shares
|
||||
a common API with all other strImpl derivatives.
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef _nsString2
|
||||
#define _nsString2
|
||||
|
||||
//#define nsString2 nsString
|
||||
//#define nsAutoString2 nsAutoString
|
||||
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nscore.h"
|
||||
#include <iostream.h>
|
||||
|
@ -47,13 +46,6 @@
|
|||
class nsISizeOfHandler;
|
||||
|
||||
|
||||
#ifdef USE_STRING2
|
||||
#define nsString2 nsString
|
||||
#define nsAutoString2 nsAutoString
|
||||
#endif
|
||||
|
||||
class NS_BASE nsSubsumeStr;
|
||||
|
||||
class NS_BASE nsString2 : public nsStr {
|
||||
|
||||
public:
|
||||
|
@ -91,12 +83,6 @@ 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
|
||||
*
|
||||
|
@ -153,15 +139,16 @@ PRBool IsOrdered(void) const;
|
|||
Accessor methods...
|
||||
*********************************************************************/
|
||||
|
||||
const char* GetBuffer(void) const;
|
||||
const PRUnichar* GetUnicode(void) const;
|
||||
char* GetBuffer(void) const;
|
||||
PRUnichar* GetUnicode(void) const;
|
||||
operator PRUnichar*() const {return GetUnicode();}
|
||||
|
||||
|
||||
/**
|
||||
* Get nth character.
|
||||
*/
|
||||
PRUnichar operator[](PRUint32 anIndex) const;
|
||||
PRUnichar CharAt(PRUint32 anIndex) const;
|
||||
PRUnichar operator[](int anIndex) const;
|
||||
PRUnichar CharAt(int anIndex) const;
|
||||
PRUnichar First(void) const;
|
||||
PRUnichar Last(void) const;
|
||||
|
||||
|
@ -177,42 +164,42 @@ PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
|
|||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsSubsumeStr operator+(const nsStr& aString);
|
||||
nsString2 operator+(const nsStr& aString);
|
||||
|
||||
/**
|
||||
* Create a new string by appending given string to this
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsSubsumeStr operator+(const nsString2& aString);
|
||||
nsString2 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
|
||||
*/
|
||||
nsSubsumeStr operator+(const char* aCString);
|
||||
nsString2 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
|
||||
*/
|
||||
nsSubsumeStr operator+(const PRUnichar* aString);
|
||||
nsString2 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
|
||||
*/
|
||||
nsSubsumeStr operator+(char aChar);
|
||||
nsString2 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
|
||||
*/
|
||||
nsSubsumeStr operator+(PRUnichar aChar);
|
||||
nsString2 operator+(PRUnichar aChar);
|
||||
|
||||
/**********************************************************************
|
||||
Lexomorphic transforms...
|
||||
|
@ -366,6 +353,7 @@ 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
|
||||
|
@ -392,7 +380,6 @@ 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...
|
||||
|
@ -415,7 +402,8 @@ 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,
|
||||
|
@ -426,13 +414,13 @@ nsString2& Append(const nsString2& aString) {return Append(aString,aString.mLeng
|
|||
*/
|
||||
nsString2& Append(const nsStr& aString,PRInt32 aCount);
|
||||
nsString2& Append(const nsString2& aString,PRInt32 aCount);
|
||||
nsString2& Append(const char* aString,PRInt32 aCount=-1);
|
||||
nsString2& Append(const PRUnichar* aString,PRInt32 aCount=-1);
|
||||
nsString2& Append(const char* aString,PRInt32 aCount);
|
||||
nsString2& Append(const PRUnichar* aString,PRInt32 aCount);
|
||||
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.
|
||||
|
@ -476,7 +464,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(const nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
|
||||
nsString2& Insert(nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
|
||||
|
||||
/**
|
||||
* Insert a given string into this string at
|
||||
|
@ -531,7 +519,6 @@ 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;
|
||||
|
@ -567,7 +554,6 @@ 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;
|
||||
|
@ -689,8 +675,10 @@ 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;
|
||||
|
@ -713,11 +701,12 @@ 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(nsStr& anExtBuffer,const char* aCString);
|
||||
nsAutoString2(nsBufDescriptor& anExtBuffer,const char* aCString);
|
||||
|
||||
|
||||
nsAutoString2(const char* aCString,eCharSize aCharSize=kDefaultCharSize);
|
||||
|
@ -728,7 +717,6 @@ 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();
|
||||
|
||||
|
@ -750,28 +738,5 @@ 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,103 +31,11 @@
|
|||
#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];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -163,25 +71,9 @@ 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);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess10/30/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess10/30/98
|
||||
|
@ -189,9 +81,13 @@ void nsStr::Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 a
|
|||
* @return
|
||||
*/
|
||||
nsIMemoryAgent* GetDefaultAgent(void){
|
||||
// static nsPoolingMemoryAgent gDefaultAgent;
|
||||
static nsMemoryAgent gDefaultAgent;
|
||||
return (nsIMemoryAgent*)&gDefaultAgent;
|
||||
static nsIMemoryAgent* gDefaultAgent=0;
|
||||
if(!gDefaultAgent)
|
||||
gDefaultAgent=new nsMemoryAgent();
|
||||
|
||||
NS_ASSERTION(gDefaultAgent,"You MUST always have an allocator!");
|
||||
|
||||
return gDefaultAgent;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -214,6 +110,20 @@ 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
|
||||
|
@ -245,8 +155,8 @@ void nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAgen
|
|||
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
|
||||
EnsureCapacity(theTempStr,aNewLength,theAgent);
|
||||
|
||||
if(aDest.mLength) {
|
||||
Append(theTempStr,aDest,0,aDest.mLength,theAgent);
|
||||
if(0<aDest.mLength) {
|
||||
Append(theTempStr,aDest,0,aDest.mLength,anAgent);
|
||||
}
|
||||
theAgent->Free(aDest);
|
||||
aDest.mStr = theTempStr.mStr;
|
||||
|
@ -272,12 +182,13 @@ 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 gess10/30/98
|
||||
* @update gess 04/04/99
|
||||
* @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);
|
||||
|
@ -310,30 +221,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){
|
||||
ToRange(aDestOffset,0,aDest.mLength);
|
||||
if((0<aSource.mLength) && (aDestOffset<aDest.mLength-1)){
|
||||
if(aDest.mLength){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
//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-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);
|
||||
}
|
||||
|
@ -349,20 +260,22 @@ 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,PRUint32 aCount,nsIMemoryAgent* anAgent){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){
|
||||
if(0<aCount){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
|
||||
PRUint32 theDelta=aDest.mLength-aDestOffset;
|
||||
PRUint32 theLength=(theDelta<aCount) ? theDelta : aCount;
|
||||
PRInt32 theDelta=aDest.mLength-aDestOffset;
|
||||
PRInt32 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 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
|
||||
}
|
||||
|
||||
|
@ -430,28 +343,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=GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRUnichar theFirstTargetChar=nsStr::GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=nsStr::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=GetCharAt(aDest,index+theSubIndex);
|
||||
PRUnichar theChar=nsStr::GetCharAt(aDest,index+theSubIndex);
|
||||
if(theSubIndex>0) {
|
||||
if(theFirstTargetChar==theChar){
|
||||
PRUnichar theDestJumpChar=GetCharAt(aDest,index+theTargetMax);
|
||||
PRUnichar theDestJumpChar=nsStr::GetCharAt(aDest,index+theTargetMax);
|
||||
if(theDestJumpChar==theLastTargetChar) {
|
||||
theNewStartPos=index; //this lets us jump ahead during our search where possible.
|
||||
}//if
|
||||
}//if
|
||||
}//if
|
||||
PRUnichar theTargetChar=GetCharAt(aTarget,theSubIndex);
|
||||
PRUnichar theTargetChar=nsStr::GetCharAt(aTarget,theSubIndex);
|
||||
matches=PRBool(theChar==theTargetChar);
|
||||
}
|
||||
if(matches)
|
||||
|
@ -471,8 +384,8 @@ PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnor
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
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);
|
||||
PRInt32 nsStr::FindChar(const nsStr& aDest, PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -502,12 +415,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=GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRUnichar theFirstTargetChar=nsStr::GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=nsStr::GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRInt32 theTargetMax=aTarget.mLength;
|
||||
|
||||
while(index--) {
|
||||
|
@ -516,16 +429,16 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgno
|
|||
|
||||
if(anOffset+aTarget.mLength<=aDest.mLength) {
|
||||
while((++theSubIndex<theTargetMax) && (matches)){
|
||||
PRUnichar theChar=GetCharAt(aDest,index+theSubIndex);
|
||||
PRUnichar theChar=nsStr::GetCharAt(aDest,index+theSubIndex);
|
||||
if(theSubIndex>0) {
|
||||
if(theFirstTargetChar==theChar){
|
||||
PRUnichar theDestJumpChar=GetCharAt(aDest,index+theTargetMax);
|
||||
PRUnichar theDestJumpChar=nsStr::GetCharAt(aDest,index+theTargetMax);
|
||||
if(theDestJumpChar==theLastTargetChar) {
|
||||
theNewStartPos=index; //this lets us jump ahead during our search where possible.
|
||||
}//if
|
||||
}//if
|
||||
}//if
|
||||
PRUnichar theTargetChar=GetCharAt(aTarget,theSubIndex);
|
||||
PRUnichar theTargetChar=nsStr::GetCharAt(aTarget,theSubIndex);
|
||||
matches=PRBool(theChar==theTargetChar);
|
||||
} //while
|
||||
} //if
|
||||
|
@ -546,8 +459,8 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgno
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
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);
|
||||
PRInt32 nsStr::RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gRFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -559,11 +472,11 @@ PRInt32 nsStr::RFindChar(const nsStr& aDest,const PRUnichar aChar, PRBool aIgnor
|
|||
* @return
|
||||
*/
|
||||
PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRUint32 offset=aDest.mLength-anOffset;
|
||||
PRInt32 offset=aDest.mLength-anOffset;
|
||||
PRInt32 thePos;
|
||||
|
||||
while(--offset>=0) {
|
||||
PRUnichar theChar=GetCharAt(aDest,offset);
|
||||
PRUnichar theChar=GetCharAt(aDest,PRUint32(offset));
|
||||
thePos=gRFindChars[aSet.mMultibyte](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase);
|
||||
if(kNotFound!=thePos)
|
||||
return offset;
|
||||
|
@ -578,7 +491,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,6 +27,8 @@
|
|||
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
|
||||
|
@ -42,13 +44,41 @@
|
|||
#ifndef _nsStr
|
||||
#define _nsStr
|
||||
|
||||
#include "nsCore.h"
|
||||
#include "prtypes.h"
|
||||
#include "nscore.h"
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
enum eCharSize {eOneByte=0,eTwoByte=1};
|
||||
#define kDefaultCharSize eTwoByte
|
||||
const PRInt32 kNotFound = -1;
|
||||
|
||||
|
||||
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;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
class nsIMemoryAgent;
|
||||
|
@ -67,15 +97,6 @@ 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
|
||||
|
@ -145,7 +166,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,PRUint32 aCount,nsIMemoryAgent* anAgent=0);
|
||||
static void Delete(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0);
|
||||
|
||||
/**
|
||||
* This method is used to truncate the given string.
|
||||
|
@ -233,20 +254,21 @@ 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);
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
PRUint32 mLength;
|
||||
eCharSize mMultibyte;
|
||||
PRUint32 mCapacity;
|
||||
PRUint32 mOwnsBuffer;
|
||||
PRUint32 mUnused;
|
||||
#else
|
||||
PRUint32 mLength: 30;
|
||||
eCharSize mMultibyte: 2;
|
||||
PRUint32 mLength : 30;
|
||||
eCharSize mMultibyte : 2;
|
||||
PRUint32 mCapacity: 30;
|
||||
PRUint32 mOwnsBuffer: 1;
|
||||
PRUint32 mUnused: 1;
|
||||
#endif
|
||||
PRUint32 mOwnsBuffer: 1;
|
||||
PRUint32 mUnused: 1;
|
||||
union {
|
||||
char* mStr;
|
||||
PRUnichar* mUStr;
|
||||
|
@ -285,21 +307,6 @@ 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 {
|
||||
|
@ -310,18 +317,25 @@ public:
|
|||
};
|
||||
|
||||
class nsMemoryAgent : public nsIMemoryAgent {
|
||||
protected:
|
||||
enum eDelta{eDefaultSize=16};
|
||||
enum eDelta{eGrowthDelta=8};
|
||||
public:
|
||||
|
||||
virtual PRBool Alloc(nsStr& aDest,PRInt32 aCount) {
|
||||
|
||||
//we're given the acount value in charunits; now scale up to next multiple.
|
||||
PRInt32 theNewCapacity=eDefaultSize;
|
||||
while(theNewCapacity<aCount){
|
||||
theNewCapacity<<=1;
|
||||
//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;
|
||||
}
|
||||
|
||||
|
||||
aDest.mCapacity=theNewCapacity++;
|
||||
size_t theSize=(theNewCapacity<<aDest.mMultibyte);
|
||||
aDest.mStr=new char[theSize];
|
||||
|
@ -348,8 +362,5 @@ public:
|
|||
|
||||
};
|
||||
|
||||
char* GetSharedEmptyBuffer();
|
||||
nsIMemoryAgent* GetDefaultAgent(void);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -30,8 +30,8 @@
|
|||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef _nsString1
|
||||
#define _nsString1
|
||||
#ifndef _NSSTRING
|
||||
#define _NSSTRING
|
||||
|
||||
|
||||
#include "prtypes.h"
|
||||
|
@ -39,18 +39,9 @@
|
|||
#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 nsString1 {
|
||||
class NS_BASE nsString {
|
||||
public:
|
||||
|
||||
/**
|
||||
|
@ -59,30 +50,30 @@ class NS_BASE nsString1 {
|
|||
* was to allow developers direct access to the underlying buffer for
|
||||
* performance reasons.
|
||||
*/
|
||||
nsString1();
|
||||
nsString();
|
||||
|
||||
/**
|
||||
* This constructor accepts an isolatin string
|
||||
* @param an ascii is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsString1(const char* aCString);
|
||||
nsString(const char* aCString);
|
||||
|
||||
/**
|
||||
* This is our copy constructor
|
||||
* @param reference to another nsString1
|
||||
* @param reference to another nsString
|
||||
*/
|
||||
nsString1(const nsString1&);
|
||||
nsString(const nsString&);
|
||||
|
||||
/**
|
||||
* Constructor from a unicode string
|
||||
* @param anicodestr pts to a unicode string
|
||||
*/
|
||||
nsString1(const PRUnichar* aUnicode);
|
||||
nsString(const PRUnichar* aUnicode);
|
||||
|
||||
/**
|
||||
* Virtual Destructor
|
||||
*/
|
||||
virtual ~nsString1();
|
||||
virtual ~nsString();
|
||||
|
||||
|
||||
/**
|
||||
|
@ -145,14 +136,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
|
||||
|
@ -192,35 +183,35 @@ PRBool SetCharAt(PRUnichar aChar,PRInt32 anIndex);
|
|||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsString1 operator+(const nsString1& aString);
|
||||
nsString operator+(const nsString& 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
|
||||
*/
|
||||
nsString1 operator+(const char* aCString);
|
||||
nsString 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
|
||||
*/
|
||||
nsString1 operator+(char aChar);
|
||||
nsString 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
|
||||
*/
|
||||
nsString1 operator+(const PRUnichar* aBuffer);
|
||||
nsString 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
|
||||
*/
|
||||
nsString1 operator+(PRUnichar aChar);
|
||||
nsString operator+(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* Converts all chars in internal string to lower
|
||||
|
@ -230,7 +221,7 @@ void ToLowerCase();
|
|||
/**
|
||||
* Converts all chars in given string to lower
|
||||
*/
|
||||
void ToLowerCase(nsString1& aString) const;
|
||||
void ToLowerCase(nsString& aString) const;
|
||||
|
||||
/**
|
||||
* Converts all chars in given string to upper
|
||||
|
@ -246,13 +237,13 @@ void ToUCS2(PRInt32 aStartOffset);
|
|||
/**
|
||||
* Converts all chars in internal string to upper
|
||||
*/
|
||||
void ToUpperCase(nsString1& aString) const;
|
||||
void ToUpperCase(nsString& aString) const;
|
||||
|
||||
/**
|
||||
* Creates a duplicate clone (ptr) of this string.
|
||||
* @return ptr to clone of this string
|
||||
*/
|
||||
nsString1* ToNewString() const;
|
||||
nsString* ToNewString() const;
|
||||
|
||||
/**
|
||||
* Creates an ascii clone of this string
|
||||
|
@ -274,7 +265,7 @@ char* ToCString(char* aBuf,PRInt32 aBufLength) const;
|
|||
* @param aString to hold copy of this
|
||||
* @return nada.
|
||||
*/
|
||||
void Copy(nsString1& aString) const;
|
||||
void Copy(nsString& aString) const;
|
||||
|
||||
/**
|
||||
* Creates an unichar clone of this string
|
||||
|
@ -307,72 +298,79 @@ PRInt32 ToInteger(PRInt32* aErrorCode,PRInt32 aRadix=10) const;
|
|||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString1& SetString(const PRUnichar* aStr,PRInt32 aLength=-1);
|
||||
nsString1& SetString(const char* aCString,PRInt32 aLength=-1);
|
||||
nsString1& SetString(const nsString1& aString);
|
||||
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);
|
||||
|
||||
/**
|
||||
* assign given string to this one
|
||||
* @param aString: string to be added to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator=(const nsString1& aString);
|
||||
nsString& operator=(const nsString& aString);
|
||||
|
||||
/**
|
||||
* assign given char* to this string
|
||||
* @param aCString: buffer to be assigned to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator=(const char* aCString);
|
||||
nsString& operator=(const char* aCString);
|
||||
|
||||
/**
|
||||
* assign given char to this string
|
||||
* @param aChar: char to be assignd to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator=(char aChar);
|
||||
nsString& operator=(char aChar);
|
||||
|
||||
/**
|
||||
* assign given unichar* to this string
|
||||
* @param aBuffer: unichar buffer to be assigned to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator=(const PRUnichar* aBuffer);
|
||||
nsString& operator=(const PRUnichar* aBuffer);
|
||||
|
||||
/**
|
||||
* assign given char to this string
|
||||
* @param aChar: char to be assignd to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator=(PRUnichar aChar);
|
||||
nsString& operator=(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @param aString : string to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator+=(const nsString1& aString);
|
||||
nsString& operator+=(const nsString& aString);
|
||||
|
||||
/**
|
||||
* append given buffer to this string
|
||||
* @param aCString: buffer to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator+=(const char* aCString);
|
||||
nsString& operator+=(const char* aCString);
|
||||
|
||||
/**
|
||||
* append given buffer to this string
|
||||
* @param aBuffer: buffer to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator+=(const PRUnichar* aBuffer);
|
||||
nsString& operator+=(const PRUnichar* aBuffer);
|
||||
|
||||
/**
|
||||
* append given char to this string
|
||||
* @param aChar: char to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator+=(PRUnichar aChar);
|
||||
nsString& operator+=(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
|
@ -381,7 +379,7 @@ nsString1& operator+=(PRUnichar aChar);
|
|||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Append(const nsString1& aString,PRInt32 aLength=-1);
|
||||
nsString& Append(const nsString& aString,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
|
@ -390,14 +388,14 @@ nsString1& Append(const nsString1& aString,PRInt32 aLength=-1);
|
|||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Append(const char* aCString,PRInt32 aLength=-1);
|
||||
nsString& Append(const char* aCString,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @param aString : string to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Append(char aChar);
|
||||
nsString& Append(char aChar);
|
||||
|
||||
/**
|
||||
* append given unichar buffer to this string
|
||||
|
@ -406,14 +404,14 @@ nsString1& Append(char aChar);
|
|||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Append(const PRUnichar* aBuffer,PRInt32 aLength=-1);
|
||||
nsString& 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
|
||||
*/
|
||||
nsString1& Append(PRUnichar aChar);
|
||||
nsString& Append(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* Append an integer onto this string
|
||||
|
@ -421,14 +419,14 @@ nsString1& Append(PRUnichar aChar);
|
|||
* @param aRadix specifies 8,10,16
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Append(PRInt32 aInteger,PRInt32 aRadix); //radix=8,10 or 16
|
||||
nsString& 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
|
||||
*/
|
||||
nsString1& Append(float aFloat);
|
||||
nsString& Append(float aFloat);
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
|
@ -439,7 +437,7 @@ nsString1& Append(float aFloat);
|
|||
* @param aCount -- number of chars to copy
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Left(nsString1& aCopy,PRInt32 aCount) const;
|
||||
PRInt32 Left(nsString& aCopy,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
|
@ -451,7 +449,7 @@ PRInt32 Left(nsString1& aCopy,PRInt32 aCount) const;
|
|||
* @param anOffset -- position where copying begins
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Mid(nsString1& aCopy,PRInt32 anOffset,PRInt32 aCount) const;
|
||||
PRInt32 Mid(nsString& aCopy,PRInt32 anOffset,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
|
@ -462,7 +460,7 @@ PRInt32 Mid(nsString1& aCopy,PRInt32 anOffset,PRInt32 aCount) const;
|
|||
* @param aCount -- number of chars to copy
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Right(nsString1& aCopy,PRInt32 aCount) const;
|
||||
PRInt32 Right(nsString& aCopy,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* This method inserts n chars from given string into this
|
||||
|
@ -473,7 +471,7 @@ PRInt32 Right(nsString1& aCopy,PRInt32 aCount) const;
|
|||
* @param aCount -- number of chars to be copied from aCopy
|
||||
* @return number of chars inserted into this.
|
||||
*/
|
||||
PRInt32 Insert(const nsString1& aCopy,PRInt32 anOffset,PRInt32 aCount=-1);
|
||||
PRInt32 Insert(const nsString& aCopy,PRInt32 anOffset,PRInt32 aCount=-1);
|
||||
|
||||
/**
|
||||
* Insert a single unicode char into this string at
|
||||
|
@ -493,7 +491,7 @@ PRInt32 Insert(PRUnichar aChar,PRInt32 anOffset);
|
|||
* @param aCount -- number of chars to be cut
|
||||
* @return *this
|
||||
*/
|
||||
nsString1& Cut(PRInt32 anOffset,PRInt32 aCount);
|
||||
nsString& Cut(PRInt32 anOffset,PRInt32 aCount);
|
||||
|
||||
/**
|
||||
* This method is used to remove all occurances of the
|
||||
|
@ -502,7 +500,7 @@ nsString1& Cut(PRInt32 anOffset,PRInt32 aCount);
|
|||
* @param aSet -- characters to be cut from this
|
||||
* @return *this
|
||||
*/
|
||||
nsString1& StripChars(const char* aSet);
|
||||
nsString& StripChars(const char* aSet);
|
||||
|
||||
/**
|
||||
* This method is used to replace all occurances of the
|
||||
|
@ -511,14 +509,14 @@ nsString1& StripChars(const char* aSet);
|
|||
* @param
|
||||
* @return *this
|
||||
*/
|
||||
nsString1& ReplaceChar(PRUnichar aSourceChar, PRUnichar aDestChar);
|
||||
nsString& ReplaceChar(PRUnichar aSourceChar, PRUnichar aDestChar);
|
||||
|
||||
/**
|
||||
* This method strips whitespace throughout the string
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
nsString1& StripWhitespace();
|
||||
nsString& StripWhitespace();
|
||||
|
||||
/**
|
||||
* This method trims characters found in aTrimSet from
|
||||
|
@ -528,7 +526,7 @@ nsString1& StripWhitespace();
|
|||
* both ends
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Trim(const char* aSet,
|
||||
nsString& Trim(const char* aSet,
|
||||
PRBool aEliminateLeading=PR_TRUE,
|
||||
PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
|
@ -541,7 +539,7 @@ nsString1& Trim(const char* aSet,
|
|||
* @param aEliminateTrailing controls stripping of trailing ws
|
||||
* @return this
|
||||
*/
|
||||
nsString1& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,
|
||||
nsString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,
|
||||
PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
/**
|
||||
|
@ -590,7 +588,7 @@ PRInt32 BinarySearch(PRUnichar aChar) const;
|
|||
*/
|
||||
PRInt32 Find(const char* aString) const;
|
||||
PRInt32 Find(const PRUnichar* aString) const;
|
||||
PRInt32 Find(const nsString1& aString) const;
|
||||
PRInt32 Find(const nsString& aString) const;
|
||||
|
||||
/**
|
||||
* Search for given char within this string
|
||||
|
@ -608,7 +606,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(nsString1& aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 FindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
||||
|
||||
/**
|
||||
* This method searches this string for the last character
|
||||
|
@ -618,7 +616,7 @@ PRInt32 FindCharInSet(nsString1& 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(nsString1& aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 RFindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -629,7 +627,7 @@ PRInt32 RFindCharInSet(nsString1& 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 nsString1& aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
|
||||
/**
|
||||
* This methods scans the string backwards, looking for the given char
|
||||
|
@ -650,7 +648,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 nsString1 &aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
virtual PRInt32 Compare(const nsString &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;
|
||||
|
||||
|
@ -659,7 +657,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 nsString1 &aString) const;
|
||||
PRBool operator==(const nsString &aString) const;
|
||||
PRBool operator==(const char *aString) const;
|
||||
PRBool operator==(const PRUnichar* aString) const;
|
||||
PRBool operator==(PRUnichar* aString) const;
|
||||
|
@ -669,7 +667,7 @@ PRBool operator==(PRUnichar* aString) const;
|
|||
* @param aString is the string to be compared to this
|
||||
* @return TRUE
|
||||
*/
|
||||
PRBool operator!=(const nsString1 &aString) const;
|
||||
PRBool operator!=(const nsString &aString) const;
|
||||
PRBool operator!=(const char *aString) const;
|
||||
PRBool operator!=(const PRUnichar* aString) const;
|
||||
|
||||
|
@ -678,7 +676,7 @@ PRBool operator!=(const PRUnichar* aString) const;
|
|||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator<(const nsString1 &aString) const;
|
||||
PRBool operator<(const nsString &aString) const;
|
||||
PRBool operator<(const char *aString) const;
|
||||
PRBool operator<(const PRUnichar* aString) const;
|
||||
|
||||
|
@ -687,7 +685,7 @@ PRBool operator<(const PRUnichar* aString) const;
|
|||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator>(const nsString1 &S) const;
|
||||
PRBool operator>(const nsString &S) const;
|
||||
PRBool operator>(const char *aCString) const;
|
||||
PRBool operator>(const PRUnichar* aString) const;
|
||||
|
||||
|
@ -696,7 +694,7 @@ PRBool operator>(const PRUnichar* aString) const;
|
|||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator<=(const nsString1 &S) const;
|
||||
PRBool operator<=(const nsString &S) const;
|
||||
PRBool operator<=(const char *aCString) const;
|
||||
PRBool operator<=(const PRUnichar* aString) const;
|
||||
|
||||
|
@ -705,7 +703,7 @@ PRBool operator<=(const PRUnichar* aString) const;
|
|||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator>=(const nsString1 &S) const;
|
||||
PRBool operator>=(const nsString &S) const;
|
||||
PRBool operator>=(const char* aCString) const;
|
||||
PRBool operator>=(const PRUnichar* aString) const;
|
||||
|
||||
|
@ -719,7 +717,7 @@ PRBool operator>=(const PRUnichar* aString) const;
|
|||
* @param aLength -- optional length of given string.
|
||||
* @return TRUE if equal
|
||||
*/
|
||||
PRBool Equals(const nsString1& aString) const;
|
||||
PRBool Equals(const nsString& aString) const;
|
||||
PRBool Equals(const char* aString,PRInt32 aLength=-1) const;
|
||||
PRBool Equals(const nsIAtom *aAtom) const;
|
||||
|
||||
|
@ -742,7 +740,7 @@ PRBool Equals(const PRUnichar* s1, const PRUnichar* s2) const;
|
|||
* @param aLength -- optional length of given string.
|
||||
* @return TRUE if equal
|
||||
*/
|
||||
PRBool EqualsIgnoreCase(const nsString1& aString) const;
|
||||
PRBool EqualsIgnoreCase(const nsString& aString) const;
|
||||
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aLength=-1) const;
|
||||
PRBool EqualsIgnoreCase(const nsIAtom *aAtom) const;
|
||||
|
||||
|
@ -770,34 +768,34 @@ typedef PRUnichar chartype;
|
|||
#endif
|
||||
};
|
||||
|
||||
ostream& operator<<(ostream& os,nsString1& aString);
|
||||
extern NS_BASE int fputs(const nsString1& aString, FILE* out);
|
||||
ostream& operator<<(ostream& os,nsString& aString);
|
||||
extern NS_BASE int fputs(const nsString& aString, FILE* out);
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* A version of nsString1 which is designed to be used as an automatic
|
||||
* A version of nsString 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 nsAutoString1 : public nsString1 {
|
||||
class NS_BASE nsAutoString : public nsString {
|
||||
public:
|
||||
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();
|
||||
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& 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;}
|
||||
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;}
|
||||
|
||||
virtual void SizeOf(nsISizeOfHandler* aHandler) const;
|
||||
|
||||
|
@ -809,7 +807,7 @@ protected:
|
|||
chartype mBuf[32];
|
||||
};
|
||||
|
||||
ostream& operator<<(ostream& os,nsAutoString1& aString);
|
||||
ostream& operator<<(ostream& os,nsAutoString& aString);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -25,15 +25,18 @@
|
|||
#include "nsDebug.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsISizeOfHandler.h"
|
||||
#include "prprf.h"
|
||||
#include "prdtoa.h"
|
||||
#include "nsDeque.h"
|
||||
|
||||
#ifndef RICKG_TESTBED
|
||||
#include "prdtoa.h"
|
||||
#include "nsISizeOfHandler.h"
|
||||
#endif
|
||||
#include "nsUnicharUtilCIID.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsICaseConversion.h"
|
||||
|
||||
static const char* kNullPointerError = "Error: unexpected null ptr";
|
||||
static const char* kWhitespace="\b\t\r\n ";
|
||||
static const PRInt32 kNotFound=-1;
|
||||
|
||||
#ifdef RICKG_DEBUG
|
||||
PRBool nsString2::mSelfTested = PR_FALSE;
|
||||
|
@ -94,7 +97,58 @@ 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:
|
||||
|
@ -104,15 +158,6 @@ public:
|
|||
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
|
||||
|
@ -171,15 +216,6 @@ 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.
|
||||
|
@ -257,7 +293,7 @@ void nsString2::SetCapacity(PRUint32 aLength) {
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
const char* nsString2::GetBuffer(void) const {
|
||||
char* nsString2::GetBuffer(void) const {
|
||||
if(!mMultibyte)
|
||||
return mStr;
|
||||
return 0;
|
||||
|
@ -269,7 +305,7 @@ const char* nsString2::GetBuffer(void) const {
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
const PRUnichar* nsString2::GetUnicode(void) const {
|
||||
PRUnichar* nsString2::GetUnicode(void) const {
|
||||
if(mMultibyte)
|
||||
return (PRUnichar*)mUStr;
|
||||
return 0;
|
||||
|
@ -278,11 +314,11 @@ const PRUnichar* nsString2::GetUnicode(void) const {
|
|||
/**
|
||||
* Get nth character.
|
||||
*/
|
||||
PRUnichar nsString2::operator[](PRUint32 anIndex) const {
|
||||
PRUnichar nsString2::operator[](int anIndex) const {
|
||||
return GetCharAt(*this,anIndex);
|
||||
}
|
||||
|
||||
PRUnichar nsString2::CharAt(PRUint32 anIndex) const {
|
||||
PRUnichar nsString2::CharAt(int anIndex) const {
|
||||
return GetCharAt(*this,anIndex);
|
||||
}
|
||||
|
||||
|
@ -316,10 +352,10 @@ PRBool nsString2::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
|
|||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsSubsumeStr nsString2::operator+(const nsStr& aString){
|
||||
nsString2 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 nsSubsumeStr(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -328,10 +364,10 @@ nsSubsumeStr nsString2::operator+(const nsStr& aString){
|
|||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsSubsumeStr nsString2::operator+(const nsString2& aString){
|
||||
nsString2 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 nsSubsumeStr(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
|
@ -341,10 +377,10 @@ nsSubsumeStr nsString2::operator+(const nsString2& aString){
|
|||
* @param aCString is a ptr to cstring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsSubsumeStr nsString2::operator+(const char* aCString) {
|
||||
nsString2 nsString2::operator+(const char* aCString) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(aCString);
|
||||
return nsSubsumeStr(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
|
@ -354,10 +390,10 @@ nsSubsumeStr nsString2::operator+(const char* aCString) {
|
|||
* @param aChar is a char to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsSubsumeStr nsString2::operator+(char aChar) {
|
||||
nsString2 nsString2::operator+(char aChar) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(char(aChar));
|
||||
return nsSubsumeStr(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -366,10 +402,10 @@ nsSubsumeStr nsString2::operator+(char aChar) {
|
|||
* @param aString is a ptr to unistring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsSubsumeStr nsString2::operator+(const PRUnichar* aString) {
|
||||
nsString2 nsString2::operator+(const PRUnichar* aString) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(aString);
|
||||
return nsSubsumeStr(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
|
@ -379,10 +415,10 @@ nsSubsumeStr nsString2::operator+(const PRUnichar* aString) {
|
|||
* @param aChar is a unichar to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsSubsumeStr nsString2::operator+(PRUnichar aChar) {
|
||||
nsString2 nsString2::operator+(PRUnichar aChar) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(char(aChar));
|
||||
return nsSubsumeStr(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
|
@ -393,7 +429,6 @@ nsSubsumeStr 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;
|
||||
|
@ -586,11 +621,11 @@ PRUnichar* nsString2::ToNewUnicode() const {
|
|||
*/
|
||||
char* nsString2::ToCString(char* aBuf, PRUint32 aBufLength) const{
|
||||
if(aBuf) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mStr=aBuf;
|
||||
temp.mCapacity=aBufLength;
|
||||
nsStr::Assign(temp,*this,0,mLength,mAgent);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mStr=aBuf;
|
||||
theTempStr.mCapacity=aBufLength;
|
||||
nsStr::Assign(theTempStr,*this,0,mLength,mAgent);
|
||||
}
|
||||
return aBuf;
|
||||
}
|
||||
|
@ -765,19 +800,15 @@ nsString2& nsString2::Assign(PRUnichar aChar) {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* Copies contents of this onto given string.
|
||||
* @update gess 7/27/98
|
||||
* @param aString to hold copy of this
|
||||
* @return nada.
|
||||
*/
|
||||
nsString2& nsString2::operator=(nsSubsumeStr& aSubsumeString) {
|
||||
Subsume(*this,aSubsumeString);
|
||||
return *this;
|
||||
void nsString2::Copy(nsString2& aString) const{
|
||||
aString.SetString(*this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @update gess 01/04/99
|
||||
|
@ -812,12 +843,12 @@ nsString2& nsString2::Append(const nsString2& aString,PRInt32 aCount) {
|
|||
*/
|
||||
nsString2& nsString2::Append(const char* aCString,PRInt32 aCount) {
|
||||
if(aCString){
|
||||
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);
|
||||
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);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
@ -831,12 +862,12 @@ nsString2& nsString2::Append(const char* aCString,PRInt32 aCount) {
|
|||
*/
|
||||
nsString2& nsString2::Append(const PRUnichar* aString,PRInt32 aCount) {
|
||||
if(aString){
|
||||
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);
|
||||
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);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
@ -851,11 +882,11 @@ nsString2& nsString2::Append(char aChar) {
|
|||
char buf[2]={0,0};
|
||||
buf[0]=aChar;
|
||||
|
||||
nsStr temp;
|
||||
Initialize(temp,eOneByte);
|
||||
temp.mStr=buf;
|
||||
temp.mLength=1;
|
||||
nsStr::Append(*this,temp,0,1,mAgent);
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eOneByte);
|
||||
theTemp.mStr=buf;
|
||||
theTemp.mLength=1;
|
||||
nsStr::Append(*this,theTemp,0,1,mAgent);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -869,11 +900,11 @@ nsString2& nsString2::Append(PRUnichar aChar) {
|
|||
PRUnichar buf[2]={0,0};
|
||||
buf[0]=aChar;
|
||||
|
||||
nsStr temp;
|
||||
Initialize(temp,eTwoByte);
|
||||
temp.mUStr=buf;
|
||||
temp.mLength=1;
|
||||
nsStr::Append(*this,temp,0,1,mAgent);
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eTwoByte);
|
||||
theTemp.mUStr=buf;
|
||||
theTemp.mLength=1;
|
||||
nsStr::Append(*this,theTemp,0,1,mAgent);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -970,7 +1001,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(const nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount) {
|
||||
nsString2& nsString2::Insert(nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount) {
|
||||
nsStr::Insert(*this,anOffset,aCopy,0,aCount,mAgent);
|
||||
return *this;
|
||||
}
|
||||
|
@ -987,12 +1018,12 @@ nsString2& nsString2::Insert(const nsString2& aCopy,PRUint32 anOffset,PRInt32 aC
|
|||
nsString2& nsString2::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCount){
|
||||
if(aCString){
|
||||
if(0<aCount) {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1013,11 +1044,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 temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mStr=(char*)theBuffer;
|
||||
temp.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,temp,0,1,0);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mStr=(char*)theBuffer;
|
||||
theTempStr.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,theTempStr,0,1,0);
|
||||
return *this;
|
||||
}
|
||||
*/
|
||||
|
@ -1034,12 +1065,12 @@ nsString2& nsString2::Insert(char aChar,PRUint32 anOffset){
|
|||
nsString2& nsString2::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32 aCount){
|
||||
if(aString){
|
||||
if(0<aCount) {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1059,11 +1090,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 temp;
|
||||
nsStr::Initialize(temp,eTwoByte);
|
||||
temp.mUStr=theBuffer;
|
||||
temp.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,temp,0,1,0);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mUStr=theBuffer;
|
||||
theTempStr.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,theTempStr,0,1,0);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -1122,11 +1153,11 @@ PRInt32 nsString2::Find(const char* aCString,PRBool aIgnoreCase) const{
|
|||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aCString) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCString);
|
||||
temp.mStr=(char*)aCString;
|
||||
result=nsStr::FindSubstr(*this,temp,aIgnoreCase,0);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCString);
|
||||
theTempStr.mStr=(char*)aCString;
|
||||
result=nsStr::FindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -1143,11 +1174,11 @@ PRInt32 nsString2::Find(const PRUnichar* aString,PRBool aIgnoreCase) const{
|
|||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aString) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eTwoByte);
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
temp.mUStr=(PRUnichar*)aString;
|
||||
result=nsStr::FindSubstr(*this,temp,aIgnoreCase,0);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mUStr=(PRUnichar*)aString;
|
||||
result=nsStr::FindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -1164,18 +1195,6 @@ 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
|
||||
*
|
||||
|
@ -1200,11 +1219,11 @@ PRInt32 nsString2::FindCharInSet(const char* aCStringSet,PRUint32 anOffset) cons
|
|||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aCStringSet) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCStringSet);
|
||||
temp.mStr=(char*)aCStringSet;
|
||||
result=nsStr::FindCharInSet(*this,temp,PR_FALSE,anOffset);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCStringSet);
|
||||
theTempStr.mStr=(char*)aCStringSet;
|
||||
result=nsStr::FindCharInSet(*this,theTempStr,PR_FALSE,anOffset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -1233,11 +1252,11 @@ PRInt32 nsString2::RFindCharInSet(const char* aCStringSet,PRUint32 anOffset) con
|
|||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aCStringSet) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCStringSet);
|
||||
temp.mStr=(char*)aCStringSet;
|
||||
result=nsStr::RFindCharInSet(*this,temp,PR_FALSE,anOffset);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCStringSet);
|
||||
theTempStr.mStr=(char*)aCStringSet;
|
||||
result=nsStr::RFindCharInSet(*this,theTempStr,PR_FALSE,anOffset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -1266,18 +1285,6 @@ 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;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
|
@ -1290,11 +1297,11 @@ PRInt32 nsString2::RFind(const char* aString,PRBool aIgnoreCase) const{
|
|||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aString) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
temp.mStr=(char*)aString;
|
||||
result=nsStr::RFindSubstr(*this,temp,aIgnoreCase,0);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mStr=(char*)aString;
|
||||
result=nsStr::RFindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -1327,11 +1334,11 @@ PRInt32 nsString2::Compare(const char *aCString,PRBool aIgnoreCase,PRInt32 aLeng
|
|||
NS_ASSERTION(0!=aCString,kNullPointerError);
|
||||
|
||||
if(aCString) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCString);
|
||||
temp.mStr=(char*)aCString;
|
||||
return nsStr::Compare(*this,temp,aLength,aIgnoreCase);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCString);
|
||||
theTempStr.mStr=(char*)aCString;
|
||||
return nsStr::Compare(*this,theTempStr,aLength,aIgnoreCase);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1347,11 +1354,11 @@ PRInt32 nsString2::Compare(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 a
|
|||
NS_ASSERTION(0!=aString,kNullPointerError);
|
||||
|
||||
if(aString) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eTwoByte);
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
temp.mUStr=(PRUnichar*)aString;
|
||||
return nsStr::Compare(*this,temp,aLength,aIgnoreCase);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mUStr=(PRUnichar*)aString;
|
||||
return nsStr::Compare(*this,theTempStr,aLength,aIgnoreCase);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1561,37 +1568,16 @@ 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);
|
||||
}
|
||||
|
@ -1641,6 +1627,7 @@ void nsString2::Recycle(nsString2* aString){
|
|||
GetRecycler().Recycle(aString);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -1713,7 +1700,6 @@ void nsString2::SelfTest(void) {
|
|||
static const char* kConstructorError = kConstructorError;
|
||||
static const char* kComparisonError = "Comparision error!";
|
||||
static const char* kEqualsError = "Equals error!";
|
||||
|
||||
mSelfTested=PR_TRUE;
|
||||
|
||||
eCharSize theSize=eOneByte;
|
||||
|
@ -1722,18 +1708,8 @@ 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);
|
||||
|
@ -1748,8 +1724,6 @@ 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;
|
||||
|
@ -1765,17 +1739,12 @@ 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;
|
||||
|
@ -1787,12 +1756,11 @@ void nsString2::SelfTest(void) {
|
|||
{
|
||||
nsString2 theString("hello",theSize);
|
||||
PRUint32 len=theString.Length();
|
||||
PRUnichar ch;
|
||||
for(PRUint32 i=0;i<len;i++) {
|
||||
ch=theString.CharAt(i);
|
||||
PRUnichar ch3=theString.CharAt(i);
|
||||
}
|
||||
ch=theString.First();
|
||||
ch=theString.Last();
|
||||
PRUnichar ch4=theString.First();
|
||||
PRUnichar ch5=theString.Last();
|
||||
}
|
||||
|
||||
//**********************************************
|
||||
|
@ -1861,6 +1829,7 @@ void nsString2::SelfTest(void) {
|
|||
temp1.Right(temp2,4);
|
||||
}
|
||||
|
||||
|
||||
//**********************************************
|
||||
//Now let's test the INSERTION methods...
|
||||
//**********************************************
|
||||
|
@ -2007,15 +1976,6 @@ 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
|
||||
}
|
||||
|
||||
|
@ -2024,6 +1984,14 @@ 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
|
||||
|
@ -2033,9 +2001,8 @@ void nsString2::SelfTest(void) {
|
|||
* @param aCurrentLength tells us the current length of the buffer
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(eCharSize aCharSize) : nsString2(aCharSize){
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
mAgent=0;
|
||||
AddNullTerminator(*this);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2043,11 +2010,8 @@ nsAutoString2::nsAutoString2(eCharSize aCharSize) : nsString2(aCharSize){
|
|||
* @param anExtBuffer describes an external buffer
|
||||
* @param aCString is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(nsStr& aStr,const char* aCString) : nsString2((eCharSize)aStr.mMultibyte) {
|
||||
eCharSize theSize=(eCharSize)aStr.mMultibyte;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>theSize)-1,0,theSize,PR_FALSE);
|
||||
mAgent=0;
|
||||
AddNullTerminator(*this);
|
||||
nsAutoString2::nsAutoString2(nsBufDescriptor& aBufDescriptor,const char* aCString) : nsString2(aBufDescriptor.mMultibyte) {
|
||||
InitAutoStr(*this,aBufDescriptor);
|
||||
Assign(aCString);
|
||||
}
|
||||
|
||||
|
@ -2056,9 +2020,8 @@ nsAutoString2::nsAutoString2(nsStr& aStr,const char* aCString) : nsString2((eCha
|
|||
* @param aCString is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const char* aCString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
mAgent=0;
|
||||
AddNullTerminator(*this);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
Assign(aCString);
|
||||
}
|
||||
|
||||
|
@ -2066,15 +2029,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 aCapacity,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
mAgent=0;
|
||||
nsAutoString2::nsAutoString2(char* aCString,PRUint32 aLen,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
if(assumeOwnership) {
|
||||
nsStr::Initialize(*this,aCString,aCapacity,0,eOneByte,PR_TRUE);
|
||||
nsBufDescriptor theDescriptor(aCString,aLen,eOneByte,PR_TRUE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
}
|
||||
else {
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
nsBufDescriptor theDescriptor(mBuffer,aLen,aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
}
|
||||
AddNullTerminator(*this);
|
||||
Assign(aCString);
|
||||
}
|
||||
|
||||
|
@ -2083,9 +2046,8 @@ nsAutoString2::nsAutoString2(char* aCString,PRUint32 aCapacity,eCharSize aCharSi
|
|||
* @param aString is a ptr to a unistr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const PRUnichar* aString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
|
@ -2093,15 +2055,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 aCapacity,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
mAgent=0;
|
||||
nsAutoString2::nsAutoString2(PRUnichar* aString,PRUint32 aLength,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
if(assumeOwnership) {
|
||||
nsStr::Initialize(*this,(char*)aString,aCapacity,0,eTwoByte,PR_TRUE);
|
||||
nsBufDescriptor theDescriptor((char*)aString,aLength,eTwoByte,PR_TRUE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
}
|
||||
else {
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
}
|
||||
AddNullTerminator(*this);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
|
@ -2111,9 +2073,8 @@ nsAutoString2::nsAutoString2(PRUnichar* aString,PRUint32 aCapacity,eCharSize aCh
|
|||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const nsStr& aString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
|
@ -2122,9 +2083,8 @@ nsAutoString2::nsAutoString2(const nsStr& aString,eCharSize aCharSize) : nsStrin
|
|||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const nsAutoString2& aString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
|
@ -2133,9 +2093,8 @@ nsAutoString2::nsAutoString2(const nsAutoString2& aString,eCharSize aCharSize) :
|
|||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const nsString2& aString,eCharSize aCharSize) : nsString2(aCharSize){
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
|
@ -2145,22 +2104,11 @@ nsAutoString2::nsAutoString2(const nsString2& aString,eCharSize aCharSize) : nsS
|
|||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(PRUnichar aChar,eCharSize aCharSize) : nsString2(aCharSize){
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
Assign(aChar);
|
||||
}
|
||||
|
||||
/**
|
||||
* construct from a subsumeable string
|
||||
* @update gess 1/4/99
|
||||
* @param reference to a subsumeString
|
||||
*/
|
||||
nsAutoString2::nsAutoString2( nsSubsumeStr& aSubsumeStr) :nsString2((eCharSize)aSubsumeStr.mMultibyte) {
|
||||
mAgent=0;
|
||||
Subsume(*this,aSubsumeStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* deconstruct the autstring
|
||||
* @param
|
||||
|
@ -2175,16 +2123,3 @@ 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,19 +20,18 @@
|
|||
/***********************************************************************
|
||||
MODULE NOTES:
|
||||
|
||||
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
|
||||
This class provides a 1-byte ASCII string implementation that shares
|
||||
a common API with all other strImpl derivatives.
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef _nsString2
|
||||
#define _nsString2
|
||||
|
||||
//#define nsString2 nsString
|
||||
//#define nsAutoString2 nsAutoString
|
||||
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nscore.h"
|
||||
#include <iostream.h>
|
||||
|
@ -47,13 +46,6 @@
|
|||
class nsISizeOfHandler;
|
||||
|
||||
|
||||
#ifdef USE_STRING2
|
||||
#define nsString2 nsString
|
||||
#define nsAutoString2 nsAutoString
|
||||
#endif
|
||||
|
||||
class NS_BASE nsSubsumeStr;
|
||||
|
||||
class NS_BASE nsString2 : public nsStr {
|
||||
|
||||
public:
|
||||
|
@ -91,12 +83,6 @@ 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
|
||||
*
|
||||
|
@ -153,15 +139,16 @@ PRBool IsOrdered(void) const;
|
|||
Accessor methods...
|
||||
*********************************************************************/
|
||||
|
||||
const char* GetBuffer(void) const;
|
||||
const PRUnichar* GetUnicode(void) const;
|
||||
char* GetBuffer(void) const;
|
||||
PRUnichar* GetUnicode(void) const;
|
||||
operator PRUnichar*() const {return GetUnicode();}
|
||||
|
||||
|
||||
/**
|
||||
* Get nth character.
|
||||
*/
|
||||
PRUnichar operator[](PRUint32 anIndex) const;
|
||||
PRUnichar CharAt(PRUint32 anIndex) const;
|
||||
PRUnichar operator[](int anIndex) const;
|
||||
PRUnichar CharAt(int anIndex) const;
|
||||
PRUnichar First(void) const;
|
||||
PRUnichar Last(void) const;
|
||||
|
||||
|
@ -177,42 +164,42 @@ PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
|
|||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsSubsumeStr operator+(const nsStr& aString);
|
||||
nsString2 operator+(const nsStr& aString);
|
||||
|
||||
/**
|
||||
* Create a new string by appending given string to this
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsSubsumeStr operator+(const nsString2& aString);
|
||||
nsString2 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
|
||||
*/
|
||||
nsSubsumeStr operator+(const char* aCString);
|
||||
nsString2 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
|
||||
*/
|
||||
nsSubsumeStr operator+(const PRUnichar* aString);
|
||||
nsString2 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
|
||||
*/
|
||||
nsSubsumeStr operator+(char aChar);
|
||||
nsString2 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
|
||||
*/
|
||||
nsSubsumeStr operator+(PRUnichar aChar);
|
||||
nsString2 operator+(PRUnichar aChar);
|
||||
|
||||
/**********************************************************************
|
||||
Lexomorphic transforms...
|
||||
|
@ -366,6 +353,7 @@ 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
|
||||
|
@ -392,7 +380,6 @@ 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...
|
||||
|
@ -415,7 +402,8 @@ 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,
|
||||
|
@ -426,13 +414,13 @@ nsString2& Append(const nsString2& aString) {return Append(aString,aString.mLeng
|
|||
*/
|
||||
nsString2& Append(const nsStr& aString,PRInt32 aCount);
|
||||
nsString2& Append(const nsString2& aString,PRInt32 aCount);
|
||||
nsString2& Append(const char* aString,PRInt32 aCount=-1);
|
||||
nsString2& Append(const PRUnichar* aString,PRInt32 aCount=-1);
|
||||
nsString2& Append(const char* aString,PRInt32 aCount);
|
||||
nsString2& Append(const PRUnichar* aString,PRInt32 aCount);
|
||||
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.
|
||||
|
@ -476,7 +464,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(const nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
|
||||
nsString2& Insert(nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
|
||||
|
||||
/**
|
||||
* Insert a given string into this string at
|
||||
|
@ -531,7 +519,6 @@ 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;
|
||||
|
@ -567,7 +554,6 @@ 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;
|
||||
|
@ -689,8 +675,10 @@ 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;
|
||||
|
@ -713,11 +701,12 @@ 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(nsStr& anExtBuffer,const char* aCString);
|
||||
nsAutoString2(nsBufDescriptor& anExtBuffer,const char* aCString);
|
||||
|
||||
|
||||
nsAutoString2(const char* aCString,eCharSize aCharSize=kDefaultCharSize);
|
||||
|
@ -728,7 +717,6 @@ 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();
|
||||
|
||||
|
@ -750,28 +738,5 @@ 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,12 +31,7 @@
|
|||
|
||||
#include "nsCRT.h"
|
||||
|
||||
#ifndef RICKG_TESTBED
|
||||
#include "nsUnicharUtilCIID.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsICaseConversion.h"
|
||||
#endif
|
||||
|
||||
static const PRInt32 kNotFound=-1;
|
||||
|
||||
inline PRUnichar GetUnicharAt(const char* aString,PRUint32 anIndex) {
|
||||
return ((PRUnichar*)aString)[anIndex];
|
||||
|
@ -67,7 +62,7 @@ PRInt32 CompressChars2(char* aString,PRUint32 aLength,const char* aSet,PRUint32
|
|||
*/
|
||||
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;
|
||||
|
@ -112,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;
|
||||
|
@ -289,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,const PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
inline PRInt32 FindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
PRUnichar theCmpChar=(aIgnoreCase ? nsCRT::ToUpper(aChar) : aChar);
|
||||
PRUint32 theIndex=0;
|
||||
for(theIndex=0;theIndex<aLength;theIndex++){
|
||||
|
@ -313,7 +308,7 @@ inline PRInt32 FindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,co
|
|||
* @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,const PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
inline PRInt32 FindChar2(const char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
PRUnichar theCmpChar=(aIgnoreCase ? nsCRT::ToUpper(aChar) : aChar);
|
||||
PRUint32 theIndex=0;
|
||||
for(theIndex=0;theIndex<aLength;theIndex++){
|
||||
|
@ -339,7 +334,7 @@ inline PRInt32 FindChar2(const char* aDest,PRUint32 aLength,PRUint32 anOffset,co
|
|||
* @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,const PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
inline PRInt32 RFindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
PRUnichar theCmpChar=(aIgnoreCase ? nsCRT::ToUpper(aChar) : aChar);
|
||||
PRUint32 theIndex=0;
|
||||
for(theIndex=aLength-1;theIndex>=0;theIndex--){
|
||||
|
@ -365,7 +360,7 @@ inline PRInt32 RFindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,c
|
|||
* @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,const PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
inline PRInt32 RFindChar2(const char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUnichar aChar,PRBool aIgnoreCase) {
|
||||
PRUnichar theCmpChar=(aIgnoreCase ? nsCRT::ToUpper(aChar) : aChar);
|
||||
PRUint32 theIndex=0;
|
||||
for(theIndex=aLength-1;theIndex>=0;theIndex--){
|
||||
|
@ -378,7 +373,7 @@ inline PRInt32 RFindChar2(const char* aDest,PRUint32 aLength,PRUint32 anOffset,c
|
|||
return kNotFound;
|
||||
}
|
||||
|
||||
typedef PRInt32 (*FindChars)(const char* aDest,PRUint32 aLength,PRUint32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase);
|
||||
typedef PRInt32 (*FindChars)(const char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUnichar aChar,PRBool aIgnoreCase);
|
||||
FindChars gFindChars[]={&FindChar1,&FindChar2};
|
||||
FindChars gRFindChars[]={&RFindChar1,&RFindChar2};
|
||||
|
||||
|
@ -506,53 +501,6 @@ 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
|
||||
*
|
||||
|
@ -563,25 +511,14 @@ protected:
|
|||
* @return 0
|
||||
*/
|
||||
PRInt32 ConvertCase2(char* aString,PRUint32 aCount,PRBool aToUpper){
|
||||
PRUnichar* cp = (PRUnichar*)aString;
|
||||
PRUnichar* end = cp + aCount-1;
|
||||
PRInt32 result=0;
|
||||
|
||||
#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
|
||||
|
||||
typedef PRUnichar chartype;
|
||||
chartype* cp = (chartype*)aString;
|
||||
chartype* end = cp + aCount-1;
|
||||
|
||||
while (cp <= end) {
|
||||
PRUnichar ch = *cp;
|
||||
chartype ch = *cp;
|
||||
if(aToUpper) {
|
||||
if ((ch >= 'a') && (ch <= 'z')) {
|
||||
*cp = 'A' + (ch - 'a');
|
||||
|
@ -617,7 +554,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];
|
||||
|
@ -649,7 +586,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];
|
||||
|
@ -690,7 +627,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;
|
||||
|
@ -813,7 +750,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);
|
||||
|
||||
|
@ -859,7 +796,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,103 +31,11 @@
|
|||
#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];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -163,25 +71,9 @@ 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);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess10/30/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess10/30/98
|
||||
|
@ -189,9 +81,13 @@ void nsStr::Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 a
|
|||
* @return
|
||||
*/
|
||||
nsIMemoryAgent* GetDefaultAgent(void){
|
||||
// static nsPoolingMemoryAgent gDefaultAgent;
|
||||
static nsMemoryAgent gDefaultAgent;
|
||||
return (nsIMemoryAgent*)&gDefaultAgent;
|
||||
static nsIMemoryAgent* gDefaultAgent=0;
|
||||
if(!gDefaultAgent)
|
||||
gDefaultAgent=new nsMemoryAgent();
|
||||
|
||||
NS_ASSERTION(gDefaultAgent,"You MUST always have an allocator!");
|
||||
|
||||
return gDefaultAgent;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -214,6 +110,20 @@ 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
|
||||
|
@ -245,8 +155,8 @@ void nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAgen
|
|||
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
|
||||
EnsureCapacity(theTempStr,aNewLength,theAgent);
|
||||
|
||||
if(aDest.mLength) {
|
||||
Append(theTempStr,aDest,0,aDest.mLength,theAgent);
|
||||
if(0<aDest.mLength) {
|
||||
Append(theTempStr,aDest,0,aDest.mLength,anAgent);
|
||||
}
|
||||
theAgent->Free(aDest);
|
||||
aDest.mStr = theTempStr.mStr;
|
||||
|
@ -272,12 +182,13 @@ 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 gess10/30/98
|
||||
* @update gess 04/04/99
|
||||
* @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);
|
||||
|
@ -310,30 +221,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){
|
||||
ToRange(aDestOffset,0,aDest.mLength);
|
||||
if((0<aSource.mLength) && (aDestOffset<aDest.mLength-1)){
|
||||
if(aDest.mLength){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
//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-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);
|
||||
}
|
||||
|
@ -349,20 +260,22 @@ 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,PRUint32 aCount,nsIMemoryAgent* anAgent){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){
|
||||
if(0<aCount){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
|
||||
PRUint32 theDelta=aDest.mLength-aDestOffset;
|
||||
PRUint32 theLength=(theDelta<aCount) ? theDelta : aCount;
|
||||
PRInt32 theDelta=aDest.mLength-aDestOffset;
|
||||
PRInt32 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 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
|
||||
}
|
||||
|
||||
|
@ -430,28 +343,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=GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRUnichar theFirstTargetChar=nsStr::GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=nsStr::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=GetCharAt(aDest,index+theSubIndex);
|
||||
PRUnichar theChar=nsStr::GetCharAt(aDest,index+theSubIndex);
|
||||
if(theSubIndex>0) {
|
||||
if(theFirstTargetChar==theChar){
|
||||
PRUnichar theDestJumpChar=GetCharAt(aDest,index+theTargetMax);
|
||||
PRUnichar theDestJumpChar=nsStr::GetCharAt(aDest,index+theTargetMax);
|
||||
if(theDestJumpChar==theLastTargetChar) {
|
||||
theNewStartPos=index; //this lets us jump ahead during our search where possible.
|
||||
}//if
|
||||
}//if
|
||||
}//if
|
||||
PRUnichar theTargetChar=GetCharAt(aTarget,theSubIndex);
|
||||
PRUnichar theTargetChar=nsStr::GetCharAt(aTarget,theSubIndex);
|
||||
matches=PRBool(theChar==theTargetChar);
|
||||
}
|
||||
if(matches)
|
||||
|
@ -471,8 +384,8 @@ PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnor
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
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);
|
||||
PRInt32 nsStr::FindChar(const nsStr& aDest, PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -502,12 +415,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=GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRUnichar theFirstTargetChar=nsStr::GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=nsStr::GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRInt32 theTargetMax=aTarget.mLength;
|
||||
|
||||
while(index--) {
|
||||
|
@ -516,16 +429,16 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgno
|
|||
|
||||
if(anOffset+aTarget.mLength<=aDest.mLength) {
|
||||
while((++theSubIndex<theTargetMax) && (matches)){
|
||||
PRUnichar theChar=GetCharAt(aDest,index+theSubIndex);
|
||||
PRUnichar theChar=nsStr::GetCharAt(aDest,index+theSubIndex);
|
||||
if(theSubIndex>0) {
|
||||
if(theFirstTargetChar==theChar){
|
||||
PRUnichar theDestJumpChar=GetCharAt(aDest,index+theTargetMax);
|
||||
PRUnichar theDestJumpChar=nsStr::GetCharAt(aDest,index+theTargetMax);
|
||||
if(theDestJumpChar==theLastTargetChar) {
|
||||
theNewStartPos=index; //this lets us jump ahead during our search where possible.
|
||||
}//if
|
||||
}//if
|
||||
}//if
|
||||
PRUnichar theTargetChar=GetCharAt(aTarget,theSubIndex);
|
||||
PRUnichar theTargetChar=nsStr::GetCharAt(aTarget,theSubIndex);
|
||||
matches=PRBool(theChar==theTargetChar);
|
||||
} //while
|
||||
} //if
|
||||
|
@ -546,8 +459,8 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgno
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
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);
|
||||
PRInt32 nsStr::RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gRFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -559,11 +472,11 @@ PRInt32 nsStr::RFindChar(const nsStr& aDest,const PRUnichar aChar, PRBool aIgnor
|
|||
* @return
|
||||
*/
|
||||
PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRUint32 offset=aDest.mLength-anOffset;
|
||||
PRInt32 offset=aDest.mLength-anOffset;
|
||||
PRInt32 thePos;
|
||||
|
||||
while(--offset>=0) {
|
||||
PRUnichar theChar=GetCharAt(aDest,offset);
|
||||
PRUnichar theChar=GetCharAt(aDest,PRUint32(offset));
|
||||
thePos=gRFindChars[aSet.mMultibyte](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase);
|
||||
if(kNotFound!=thePos)
|
||||
return offset;
|
||||
|
@ -578,7 +491,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) {
|
||||
|
|
111
xpcom/ds/nsStr.h
111
xpcom/ds/nsStr.h
|
@ -27,6 +27,8 @@
|
|||
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
|
||||
|
@ -42,13 +44,41 @@
|
|||
#ifndef _nsStr
|
||||
#define _nsStr
|
||||
|
||||
#include "nsCore.h"
|
||||
#include "prtypes.h"
|
||||
#include "nscore.h"
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
enum eCharSize {eOneByte=0,eTwoByte=1};
|
||||
#define kDefaultCharSize eTwoByte
|
||||
const PRInt32 kNotFound = -1;
|
||||
|
||||
|
||||
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;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
class nsIMemoryAgent;
|
||||
|
@ -67,15 +97,6 @@ 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
|
||||
|
@ -145,7 +166,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,PRUint32 aCount,nsIMemoryAgent* anAgent=0);
|
||||
static void Delete(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0);
|
||||
|
||||
/**
|
||||
* This method is used to truncate the given string.
|
||||
|
@ -233,20 +254,21 @@ 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);
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
PRUint32 mLength;
|
||||
eCharSize mMultibyte;
|
||||
PRUint32 mCapacity;
|
||||
PRUint32 mOwnsBuffer;
|
||||
PRUint32 mUnused;
|
||||
#else
|
||||
PRUint32 mLength: 30;
|
||||
eCharSize mMultibyte: 2;
|
||||
PRUint32 mLength : 30;
|
||||
eCharSize mMultibyte : 2;
|
||||
PRUint32 mCapacity: 30;
|
||||
PRUint32 mOwnsBuffer: 1;
|
||||
PRUint32 mUnused: 1;
|
||||
#endif
|
||||
PRUint32 mOwnsBuffer: 1;
|
||||
PRUint32 mUnused: 1;
|
||||
union {
|
||||
char* mStr;
|
||||
PRUnichar* mUStr;
|
||||
|
@ -285,21 +307,6 @@ 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 {
|
||||
|
@ -310,18 +317,25 @@ public:
|
|||
};
|
||||
|
||||
class nsMemoryAgent : public nsIMemoryAgent {
|
||||
protected:
|
||||
enum eDelta{eDefaultSize=16};
|
||||
enum eDelta{eGrowthDelta=8};
|
||||
public:
|
||||
|
||||
virtual PRBool Alloc(nsStr& aDest,PRInt32 aCount) {
|
||||
|
||||
//we're given the acount value in charunits; now scale up to next multiple.
|
||||
PRInt32 theNewCapacity=eDefaultSize;
|
||||
while(theNewCapacity<aCount){
|
||||
theNewCapacity<<=1;
|
||||
//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;
|
||||
}
|
||||
|
||||
|
||||
aDest.mCapacity=theNewCapacity++;
|
||||
size_t theSize=(theNewCapacity<<aDest.mMultibyte);
|
||||
aDest.mStr=new char[theSize];
|
||||
|
@ -348,8 +362,5 @@ public:
|
|||
|
||||
};
|
||||
|
||||
char* GetSharedEmptyBuffer();
|
||||
nsIMemoryAgent* GetDefaultAgent(void);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -30,8 +30,8 @@
|
|||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef _nsString1
|
||||
#define _nsString1
|
||||
#ifndef _NSSTRING
|
||||
#define _NSSTRING
|
||||
|
||||
|
||||
#include "prtypes.h"
|
||||
|
@ -39,18 +39,9 @@
|
|||
#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 nsString1 {
|
||||
class NS_BASE nsString {
|
||||
public:
|
||||
|
||||
/**
|
||||
|
@ -59,30 +50,30 @@ class NS_BASE nsString1 {
|
|||
* was to allow developers direct access to the underlying buffer for
|
||||
* performance reasons.
|
||||
*/
|
||||
nsString1();
|
||||
nsString();
|
||||
|
||||
/**
|
||||
* This constructor accepts an isolatin string
|
||||
* @param an ascii is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsString1(const char* aCString);
|
||||
nsString(const char* aCString);
|
||||
|
||||
/**
|
||||
* This is our copy constructor
|
||||
* @param reference to another nsString1
|
||||
* @param reference to another nsString
|
||||
*/
|
||||
nsString1(const nsString1&);
|
||||
nsString(const nsString&);
|
||||
|
||||
/**
|
||||
* Constructor from a unicode string
|
||||
* @param anicodestr pts to a unicode string
|
||||
*/
|
||||
nsString1(const PRUnichar* aUnicode);
|
||||
nsString(const PRUnichar* aUnicode);
|
||||
|
||||
/**
|
||||
* Virtual Destructor
|
||||
*/
|
||||
virtual ~nsString1();
|
||||
virtual ~nsString();
|
||||
|
||||
|
||||
/**
|
||||
|
@ -145,14 +136,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
|
||||
|
@ -192,35 +183,35 @@ PRBool SetCharAt(PRUnichar aChar,PRInt32 anIndex);
|
|||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsString1 operator+(const nsString1& aString);
|
||||
nsString operator+(const nsString& 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
|
||||
*/
|
||||
nsString1 operator+(const char* aCString);
|
||||
nsString 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
|
||||
*/
|
||||
nsString1 operator+(char aChar);
|
||||
nsString 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
|
||||
*/
|
||||
nsString1 operator+(const PRUnichar* aBuffer);
|
||||
nsString 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
|
||||
*/
|
||||
nsString1 operator+(PRUnichar aChar);
|
||||
nsString operator+(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* Converts all chars in internal string to lower
|
||||
|
@ -230,7 +221,7 @@ void ToLowerCase();
|
|||
/**
|
||||
* Converts all chars in given string to lower
|
||||
*/
|
||||
void ToLowerCase(nsString1& aString) const;
|
||||
void ToLowerCase(nsString& aString) const;
|
||||
|
||||
/**
|
||||
* Converts all chars in given string to upper
|
||||
|
@ -246,13 +237,13 @@ void ToUCS2(PRInt32 aStartOffset);
|
|||
/**
|
||||
* Converts all chars in internal string to upper
|
||||
*/
|
||||
void ToUpperCase(nsString1& aString) const;
|
||||
void ToUpperCase(nsString& aString) const;
|
||||
|
||||
/**
|
||||
* Creates a duplicate clone (ptr) of this string.
|
||||
* @return ptr to clone of this string
|
||||
*/
|
||||
nsString1* ToNewString() const;
|
||||
nsString* ToNewString() const;
|
||||
|
||||
/**
|
||||
* Creates an ascii clone of this string
|
||||
|
@ -274,7 +265,7 @@ char* ToCString(char* aBuf,PRInt32 aBufLength) const;
|
|||
* @param aString to hold copy of this
|
||||
* @return nada.
|
||||
*/
|
||||
void Copy(nsString1& aString) const;
|
||||
void Copy(nsString& aString) const;
|
||||
|
||||
/**
|
||||
* Creates an unichar clone of this string
|
||||
|
@ -307,72 +298,79 @@ PRInt32 ToInteger(PRInt32* aErrorCode,PRInt32 aRadix=10) const;
|
|||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString1& SetString(const PRUnichar* aStr,PRInt32 aLength=-1);
|
||||
nsString1& SetString(const char* aCString,PRInt32 aLength=-1);
|
||||
nsString1& SetString(const nsString1& aString);
|
||||
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);
|
||||
|
||||
/**
|
||||
* assign given string to this one
|
||||
* @param aString: string to be added to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator=(const nsString1& aString);
|
||||
nsString& operator=(const nsString& aString);
|
||||
|
||||
/**
|
||||
* assign given char* to this string
|
||||
* @param aCString: buffer to be assigned to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator=(const char* aCString);
|
||||
nsString& operator=(const char* aCString);
|
||||
|
||||
/**
|
||||
* assign given char to this string
|
||||
* @param aChar: char to be assignd to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator=(char aChar);
|
||||
nsString& operator=(char aChar);
|
||||
|
||||
/**
|
||||
* assign given unichar* to this string
|
||||
* @param aBuffer: unichar buffer to be assigned to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator=(const PRUnichar* aBuffer);
|
||||
nsString& operator=(const PRUnichar* aBuffer);
|
||||
|
||||
/**
|
||||
* assign given char to this string
|
||||
* @param aChar: char to be assignd to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator=(PRUnichar aChar);
|
||||
nsString& operator=(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @param aString : string to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator+=(const nsString1& aString);
|
||||
nsString& operator+=(const nsString& aString);
|
||||
|
||||
/**
|
||||
* append given buffer to this string
|
||||
* @param aCString: buffer to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator+=(const char* aCString);
|
||||
nsString& operator+=(const char* aCString);
|
||||
|
||||
/**
|
||||
* append given buffer to this string
|
||||
* @param aBuffer: buffer to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator+=(const PRUnichar* aBuffer);
|
||||
nsString& operator+=(const PRUnichar* aBuffer);
|
||||
|
||||
/**
|
||||
* append given char to this string
|
||||
* @param aChar: char to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator+=(PRUnichar aChar);
|
||||
nsString& operator+=(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
|
@ -381,7 +379,7 @@ nsString1& operator+=(PRUnichar aChar);
|
|||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Append(const nsString1& aString,PRInt32 aLength=-1);
|
||||
nsString& Append(const nsString& aString,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
|
@ -390,14 +388,14 @@ nsString1& Append(const nsString1& aString,PRInt32 aLength=-1);
|
|||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Append(const char* aCString,PRInt32 aLength=-1);
|
||||
nsString& Append(const char* aCString,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @param aString : string to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Append(char aChar);
|
||||
nsString& Append(char aChar);
|
||||
|
||||
/**
|
||||
* append given unichar buffer to this string
|
||||
|
@ -406,14 +404,14 @@ nsString1& Append(char aChar);
|
|||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Append(const PRUnichar* aBuffer,PRInt32 aLength=-1);
|
||||
nsString& 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
|
||||
*/
|
||||
nsString1& Append(PRUnichar aChar);
|
||||
nsString& Append(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* Append an integer onto this string
|
||||
|
@ -421,14 +419,14 @@ nsString1& Append(PRUnichar aChar);
|
|||
* @param aRadix specifies 8,10,16
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Append(PRInt32 aInteger,PRInt32 aRadix); //radix=8,10 or 16
|
||||
nsString& 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
|
||||
*/
|
||||
nsString1& Append(float aFloat);
|
||||
nsString& Append(float aFloat);
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
|
@ -439,7 +437,7 @@ nsString1& Append(float aFloat);
|
|||
* @param aCount -- number of chars to copy
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Left(nsString1& aCopy,PRInt32 aCount) const;
|
||||
PRInt32 Left(nsString& aCopy,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
|
@ -451,7 +449,7 @@ PRInt32 Left(nsString1& aCopy,PRInt32 aCount) const;
|
|||
* @param anOffset -- position where copying begins
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Mid(nsString1& aCopy,PRInt32 anOffset,PRInt32 aCount) const;
|
||||
PRInt32 Mid(nsString& aCopy,PRInt32 anOffset,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
|
@ -462,7 +460,7 @@ PRInt32 Mid(nsString1& aCopy,PRInt32 anOffset,PRInt32 aCount) const;
|
|||
* @param aCount -- number of chars to copy
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Right(nsString1& aCopy,PRInt32 aCount) const;
|
||||
PRInt32 Right(nsString& aCopy,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* This method inserts n chars from given string into this
|
||||
|
@ -473,7 +471,7 @@ PRInt32 Right(nsString1& aCopy,PRInt32 aCount) const;
|
|||
* @param aCount -- number of chars to be copied from aCopy
|
||||
* @return number of chars inserted into this.
|
||||
*/
|
||||
PRInt32 Insert(const nsString1& aCopy,PRInt32 anOffset,PRInt32 aCount=-1);
|
||||
PRInt32 Insert(const nsString& aCopy,PRInt32 anOffset,PRInt32 aCount=-1);
|
||||
|
||||
/**
|
||||
* Insert a single unicode char into this string at
|
||||
|
@ -493,7 +491,7 @@ PRInt32 Insert(PRUnichar aChar,PRInt32 anOffset);
|
|||
* @param aCount -- number of chars to be cut
|
||||
* @return *this
|
||||
*/
|
||||
nsString1& Cut(PRInt32 anOffset,PRInt32 aCount);
|
||||
nsString& Cut(PRInt32 anOffset,PRInt32 aCount);
|
||||
|
||||
/**
|
||||
* This method is used to remove all occurances of the
|
||||
|
@ -502,7 +500,7 @@ nsString1& Cut(PRInt32 anOffset,PRInt32 aCount);
|
|||
* @param aSet -- characters to be cut from this
|
||||
* @return *this
|
||||
*/
|
||||
nsString1& StripChars(const char* aSet);
|
||||
nsString& StripChars(const char* aSet);
|
||||
|
||||
/**
|
||||
* This method is used to replace all occurances of the
|
||||
|
@ -511,14 +509,14 @@ nsString1& StripChars(const char* aSet);
|
|||
* @param
|
||||
* @return *this
|
||||
*/
|
||||
nsString1& ReplaceChar(PRUnichar aSourceChar, PRUnichar aDestChar);
|
||||
nsString& ReplaceChar(PRUnichar aSourceChar, PRUnichar aDestChar);
|
||||
|
||||
/**
|
||||
* This method strips whitespace throughout the string
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
nsString1& StripWhitespace();
|
||||
nsString& StripWhitespace();
|
||||
|
||||
/**
|
||||
* This method trims characters found in aTrimSet from
|
||||
|
@ -528,7 +526,7 @@ nsString1& StripWhitespace();
|
|||
* both ends
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Trim(const char* aSet,
|
||||
nsString& Trim(const char* aSet,
|
||||
PRBool aEliminateLeading=PR_TRUE,
|
||||
PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
|
@ -541,7 +539,7 @@ nsString1& Trim(const char* aSet,
|
|||
* @param aEliminateTrailing controls stripping of trailing ws
|
||||
* @return this
|
||||
*/
|
||||
nsString1& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,
|
||||
nsString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,
|
||||
PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
/**
|
||||
|
@ -590,7 +588,7 @@ PRInt32 BinarySearch(PRUnichar aChar) const;
|
|||
*/
|
||||
PRInt32 Find(const char* aString) const;
|
||||
PRInt32 Find(const PRUnichar* aString) const;
|
||||
PRInt32 Find(const nsString1& aString) const;
|
||||
PRInt32 Find(const nsString& aString) const;
|
||||
|
||||
/**
|
||||
* Search for given char within this string
|
||||
|
@ -608,7 +606,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(nsString1& aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 FindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
||||
|
||||
/**
|
||||
* This method searches this string for the last character
|
||||
|
@ -618,7 +616,7 @@ PRInt32 FindCharInSet(nsString1& 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(nsString1& aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 RFindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -629,7 +627,7 @@ PRInt32 RFindCharInSet(nsString1& 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 nsString1& aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
|
||||
/**
|
||||
* This methods scans the string backwards, looking for the given char
|
||||
|
@ -650,7 +648,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 nsString1 &aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
virtual PRInt32 Compare(const nsString &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;
|
||||
|
||||
|
@ -659,7 +657,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 nsString1 &aString) const;
|
||||
PRBool operator==(const nsString &aString) const;
|
||||
PRBool operator==(const char *aString) const;
|
||||
PRBool operator==(const PRUnichar* aString) const;
|
||||
PRBool operator==(PRUnichar* aString) const;
|
||||
|
@ -669,7 +667,7 @@ PRBool operator==(PRUnichar* aString) const;
|
|||
* @param aString is the string to be compared to this
|
||||
* @return TRUE
|
||||
*/
|
||||
PRBool operator!=(const nsString1 &aString) const;
|
||||
PRBool operator!=(const nsString &aString) const;
|
||||
PRBool operator!=(const char *aString) const;
|
||||
PRBool operator!=(const PRUnichar* aString) const;
|
||||
|
||||
|
@ -678,7 +676,7 @@ PRBool operator!=(const PRUnichar* aString) const;
|
|||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator<(const nsString1 &aString) const;
|
||||
PRBool operator<(const nsString &aString) const;
|
||||
PRBool operator<(const char *aString) const;
|
||||
PRBool operator<(const PRUnichar* aString) const;
|
||||
|
||||
|
@ -687,7 +685,7 @@ PRBool operator<(const PRUnichar* aString) const;
|
|||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator>(const nsString1 &S) const;
|
||||
PRBool operator>(const nsString &S) const;
|
||||
PRBool operator>(const char *aCString) const;
|
||||
PRBool operator>(const PRUnichar* aString) const;
|
||||
|
||||
|
@ -696,7 +694,7 @@ PRBool operator>(const PRUnichar* aString) const;
|
|||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator<=(const nsString1 &S) const;
|
||||
PRBool operator<=(const nsString &S) const;
|
||||
PRBool operator<=(const char *aCString) const;
|
||||
PRBool operator<=(const PRUnichar* aString) const;
|
||||
|
||||
|
@ -705,7 +703,7 @@ PRBool operator<=(const PRUnichar* aString) const;
|
|||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator>=(const nsString1 &S) const;
|
||||
PRBool operator>=(const nsString &S) const;
|
||||
PRBool operator>=(const char* aCString) const;
|
||||
PRBool operator>=(const PRUnichar* aString) const;
|
||||
|
||||
|
@ -719,7 +717,7 @@ PRBool operator>=(const PRUnichar* aString) const;
|
|||
* @param aLength -- optional length of given string.
|
||||
* @return TRUE if equal
|
||||
*/
|
||||
PRBool Equals(const nsString1& aString) const;
|
||||
PRBool Equals(const nsString& aString) const;
|
||||
PRBool Equals(const char* aString,PRInt32 aLength=-1) const;
|
||||
PRBool Equals(const nsIAtom *aAtom) const;
|
||||
|
||||
|
@ -742,7 +740,7 @@ PRBool Equals(const PRUnichar* s1, const PRUnichar* s2) const;
|
|||
* @param aLength -- optional length of given string.
|
||||
* @return TRUE if equal
|
||||
*/
|
||||
PRBool EqualsIgnoreCase(const nsString1& aString) const;
|
||||
PRBool EqualsIgnoreCase(const nsString& aString) const;
|
||||
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aLength=-1) const;
|
||||
PRBool EqualsIgnoreCase(const nsIAtom *aAtom) const;
|
||||
|
||||
|
@ -770,34 +768,34 @@ typedef PRUnichar chartype;
|
|||
#endif
|
||||
};
|
||||
|
||||
ostream& operator<<(ostream& os,nsString1& aString);
|
||||
extern NS_BASE int fputs(const nsString1& aString, FILE* out);
|
||||
ostream& operator<<(ostream& os,nsString& aString);
|
||||
extern NS_BASE int fputs(const nsString& aString, FILE* out);
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* A version of nsString1 which is designed to be used as an automatic
|
||||
* A version of nsString 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 nsAutoString1 : public nsString1 {
|
||||
class NS_BASE nsAutoString : public nsString {
|
||||
public:
|
||||
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();
|
||||
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& 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;}
|
||||
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;}
|
||||
|
||||
virtual void SizeOf(nsISizeOfHandler* aHandler) const;
|
||||
|
||||
|
@ -809,7 +807,7 @@ protected:
|
|||
chartype mBuf[32];
|
||||
};
|
||||
|
||||
ostream& operator<<(ostream& os,nsAutoString1& aString);
|
||||
ostream& operator<<(ostream& os,nsAutoString& aString);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -25,15 +25,18 @@
|
|||
#include "nsDebug.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsISizeOfHandler.h"
|
||||
#include "prprf.h"
|
||||
#include "prdtoa.h"
|
||||
#include "nsDeque.h"
|
||||
|
||||
#ifndef RICKG_TESTBED
|
||||
#include "prdtoa.h"
|
||||
#include "nsISizeOfHandler.h"
|
||||
#endif
|
||||
#include "nsUnicharUtilCIID.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsICaseConversion.h"
|
||||
|
||||
static const char* kNullPointerError = "Error: unexpected null ptr";
|
||||
static const char* kWhitespace="\b\t\r\n ";
|
||||
static const PRInt32 kNotFound=-1;
|
||||
|
||||
#ifdef RICKG_DEBUG
|
||||
PRBool nsString2::mSelfTested = PR_FALSE;
|
||||
|
@ -94,7 +97,58 @@ 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:
|
||||
|
@ -104,15 +158,6 @@ public:
|
|||
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
|
||||
|
@ -171,15 +216,6 @@ 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.
|
||||
|
@ -257,7 +293,7 @@ void nsString2::SetCapacity(PRUint32 aLength) {
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
const char* nsString2::GetBuffer(void) const {
|
||||
char* nsString2::GetBuffer(void) const {
|
||||
if(!mMultibyte)
|
||||
return mStr;
|
||||
return 0;
|
||||
|
@ -269,7 +305,7 @@ const char* nsString2::GetBuffer(void) const {
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
const PRUnichar* nsString2::GetUnicode(void) const {
|
||||
PRUnichar* nsString2::GetUnicode(void) const {
|
||||
if(mMultibyte)
|
||||
return (PRUnichar*)mUStr;
|
||||
return 0;
|
||||
|
@ -278,11 +314,11 @@ const PRUnichar* nsString2::GetUnicode(void) const {
|
|||
/**
|
||||
* Get nth character.
|
||||
*/
|
||||
PRUnichar nsString2::operator[](PRUint32 anIndex) const {
|
||||
PRUnichar nsString2::operator[](int anIndex) const {
|
||||
return GetCharAt(*this,anIndex);
|
||||
}
|
||||
|
||||
PRUnichar nsString2::CharAt(PRUint32 anIndex) const {
|
||||
PRUnichar nsString2::CharAt(int anIndex) const {
|
||||
return GetCharAt(*this,anIndex);
|
||||
}
|
||||
|
||||
|
@ -316,10 +352,10 @@ PRBool nsString2::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
|
|||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsSubsumeStr nsString2::operator+(const nsStr& aString){
|
||||
nsString2 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 nsSubsumeStr(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -328,10 +364,10 @@ nsSubsumeStr nsString2::operator+(const nsStr& aString){
|
|||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsSubsumeStr nsString2::operator+(const nsString2& aString){
|
||||
nsString2 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 nsSubsumeStr(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
|
@ -341,10 +377,10 @@ nsSubsumeStr nsString2::operator+(const nsString2& aString){
|
|||
* @param aCString is a ptr to cstring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsSubsumeStr nsString2::operator+(const char* aCString) {
|
||||
nsString2 nsString2::operator+(const char* aCString) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(aCString);
|
||||
return nsSubsumeStr(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
|
@ -354,10 +390,10 @@ nsSubsumeStr nsString2::operator+(const char* aCString) {
|
|||
* @param aChar is a char to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsSubsumeStr nsString2::operator+(char aChar) {
|
||||
nsString2 nsString2::operator+(char aChar) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(char(aChar));
|
||||
return nsSubsumeStr(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -366,10 +402,10 @@ nsSubsumeStr nsString2::operator+(char aChar) {
|
|||
* @param aString is a ptr to unistring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsSubsumeStr nsString2::operator+(const PRUnichar* aString) {
|
||||
nsString2 nsString2::operator+(const PRUnichar* aString) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(aString);
|
||||
return nsSubsumeStr(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
|
@ -379,10 +415,10 @@ nsSubsumeStr nsString2::operator+(const PRUnichar* aString) {
|
|||
* @param aChar is a unichar to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsSubsumeStr nsString2::operator+(PRUnichar aChar) {
|
||||
nsString2 nsString2::operator+(PRUnichar aChar) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(char(aChar));
|
||||
return nsSubsumeStr(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
|
@ -393,7 +429,6 @@ nsSubsumeStr 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;
|
||||
|
@ -586,11 +621,11 @@ PRUnichar* nsString2::ToNewUnicode() const {
|
|||
*/
|
||||
char* nsString2::ToCString(char* aBuf, PRUint32 aBufLength) const{
|
||||
if(aBuf) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mStr=aBuf;
|
||||
temp.mCapacity=aBufLength;
|
||||
nsStr::Assign(temp,*this,0,mLength,mAgent);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mStr=aBuf;
|
||||
theTempStr.mCapacity=aBufLength;
|
||||
nsStr::Assign(theTempStr,*this,0,mLength,mAgent);
|
||||
}
|
||||
return aBuf;
|
||||
}
|
||||
|
@ -765,19 +800,15 @@ nsString2& nsString2::Assign(PRUnichar aChar) {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* Copies contents of this onto given string.
|
||||
* @update gess 7/27/98
|
||||
* @param aString to hold copy of this
|
||||
* @return nada.
|
||||
*/
|
||||
nsString2& nsString2::operator=(nsSubsumeStr& aSubsumeString) {
|
||||
Subsume(*this,aSubsumeString);
|
||||
return *this;
|
||||
void nsString2::Copy(nsString2& aString) const{
|
||||
aString.SetString(*this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @update gess 01/04/99
|
||||
|
@ -812,12 +843,12 @@ nsString2& nsString2::Append(const nsString2& aString,PRInt32 aCount) {
|
|||
*/
|
||||
nsString2& nsString2::Append(const char* aCString,PRInt32 aCount) {
|
||||
if(aCString){
|
||||
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);
|
||||
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);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
@ -831,12 +862,12 @@ nsString2& nsString2::Append(const char* aCString,PRInt32 aCount) {
|
|||
*/
|
||||
nsString2& nsString2::Append(const PRUnichar* aString,PRInt32 aCount) {
|
||||
if(aString){
|
||||
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);
|
||||
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);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
@ -851,11 +882,11 @@ nsString2& nsString2::Append(char aChar) {
|
|||
char buf[2]={0,0};
|
||||
buf[0]=aChar;
|
||||
|
||||
nsStr temp;
|
||||
Initialize(temp,eOneByte);
|
||||
temp.mStr=buf;
|
||||
temp.mLength=1;
|
||||
nsStr::Append(*this,temp,0,1,mAgent);
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eOneByte);
|
||||
theTemp.mStr=buf;
|
||||
theTemp.mLength=1;
|
||||
nsStr::Append(*this,theTemp,0,1,mAgent);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -869,11 +900,11 @@ nsString2& nsString2::Append(PRUnichar aChar) {
|
|||
PRUnichar buf[2]={0,0};
|
||||
buf[0]=aChar;
|
||||
|
||||
nsStr temp;
|
||||
Initialize(temp,eTwoByte);
|
||||
temp.mUStr=buf;
|
||||
temp.mLength=1;
|
||||
nsStr::Append(*this,temp,0,1,mAgent);
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eTwoByte);
|
||||
theTemp.mUStr=buf;
|
||||
theTemp.mLength=1;
|
||||
nsStr::Append(*this,theTemp,0,1,mAgent);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -970,7 +1001,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(const nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount) {
|
||||
nsString2& nsString2::Insert(nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount) {
|
||||
nsStr::Insert(*this,anOffset,aCopy,0,aCount,mAgent);
|
||||
return *this;
|
||||
}
|
||||
|
@ -987,12 +1018,12 @@ nsString2& nsString2::Insert(const nsString2& aCopy,PRUint32 anOffset,PRInt32 aC
|
|||
nsString2& nsString2::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCount){
|
||||
if(aCString){
|
||||
if(0<aCount) {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1013,11 +1044,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 temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mStr=(char*)theBuffer;
|
||||
temp.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,temp,0,1,0);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mStr=(char*)theBuffer;
|
||||
theTempStr.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,theTempStr,0,1,0);
|
||||
return *this;
|
||||
}
|
||||
*/
|
||||
|
@ -1034,12 +1065,12 @@ nsString2& nsString2::Insert(char aChar,PRUint32 anOffset){
|
|||
nsString2& nsString2::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32 aCount){
|
||||
if(aString){
|
||||
if(0<aCount) {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1059,11 +1090,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 temp;
|
||||
nsStr::Initialize(temp,eTwoByte);
|
||||
temp.mUStr=theBuffer;
|
||||
temp.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,temp,0,1,0);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mUStr=theBuffer;
|
||||
theTempStr.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,theTempStr,0,1,0);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -1122,11 +1153,11 @@ PRInt32 nsString2::Find(const char* aCString,PRBool aIgnoreCase) const{
|
|||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aCString) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCString);
|
||||
temp.mStr=(char*)aCString;
|
||||
result=nsStr::FindSubstr(*this,temp,aIgnoreCase,0);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCString);
|
||||
theTempStr.mStr=(char*)aCString;
|
||||
result=nsStr::FindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -1143,11 +1174,11 @@ PRInt32 nsString2::Find(const PRUnichar* aString,PRBool aIgnoreCase) const{
|
|||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aString) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eTwoByte);
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
temp.mUStr=(PRUnichar*)aString;
|
||||
result=nsStr::FindSubstr(*this,temp,aIgnoreCase,0);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mUStr=(PRUnichar*)aString;
|
||||
result=nsStr::FindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -1164,18 +1195,6 @@ 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
|
||||
*
|
||||
|
@ -1200,11 +1219,11 @@ PRInt32 nsString2::FindCharInSet(const char* aCStringSet,PRUint32 anOffset) cons
|
|||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aCStringSet) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCStringSet);
|
||||
temp.mStr=(char*)aCStringSet;
|
||||
result=nsStr::FindCharInSet(*this,temp,PR_FALSE,anOffset);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCStringSet);
|
||||
theTempStr.mStr=(char*)aCStringSet;
|
||||
result=nsStr::FindCharInSet(*this,theTempStr,PR_FALSE,anOffset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -1233,11 +1252,11 @@ PRInt32 nsString2::RFindCharInSet(const char* aCStringSet,PRUint32 anOffset) con
|
|||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aCStringSet) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCStringSet);
|
||||
temp.mStr=(char*)aCStringSet;
|
||||
result=nsStr::RFindCharInSet(*this,temp,PR_FALSE,anOffset);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCStringSet);
|
||||
theTempStr.mStr=(char*)aCStringSet;
|
||||
result=nsStr::RFindCharInSet(*this,theTempStr,PR_FALSE,anOffset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -1266,18 +1285,6 @@ 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;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
|
@ -1290,11 +1297,11 @@ PRInt32 nsString2::RFind(const char* aString,PRBool aIgnoreCase) const{
|
|||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aString) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
temp.mStr=(char*)aString;
|
||||
result=nsStr::RFindSubstr(*this,temp,aIgnoreCase,0);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mStr=(char*)aString;
|
||||
result=nsStr::RFindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -1327,11 +1334,11 @@ PRInt32 nsString2::Compare(const char *aCString,PRBool aIgnoreCase,PRInt32 aLeng
|
|||
NS_ASSERTION(0!=aCString,kNullPointerError);
|
||||
|
||||
if(aCString) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCString);
|
||||
temp.mStr=(char*)aCString;
|
||||
return nsStr::Compare(*this,temp,aLength,aIgnoreCase);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCString);
|
||||
theTempStr.mStr=(char*)aCString;
|
||||
return nsStr::Compare(*this,theTempStr,aLength,aIgnoreCase);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1347,11 +1354,11 @@ PRInt32 nsString2::Compare(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 a
|
|||
NS_ASSERTION(0!=aString,kNullPointerError);
|
||||
|
||||
if(aString) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eTwoByte);
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
temp.mUStr=(PRUnichar*)aString;
|
||||
return nsStr::Compare(*this,temp,aLength,aIgnoreCase);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mUStr=(PRUnichar*)aString;
|
||||
return nsStr::Compare(*this,theTempStr,aLength,aIgnoreCase);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1561,37 +1568,16 @@ 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);
|
||||
}
|
||||
|
@ -1641,6 +1627,7 @@ void nsString2::Recycle(nsString2* aString){
|
|||
GetRecycler().Recycle(aString);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -1713,7 +1700,6 @@ void nsString2::SelfTest(void) {
|
|||
static const char* kConstructorError = kConstructorError;
|
||||
static const char* kComparisonError = "Comparision error!";
|
||||
static const char* kEqualsError = "Equals error!";
|
||||
|
||||
mSelfTested=PR_TRUE;
|
||||
|
||||
eCharSize theSize=eOneByte;
|
||||
|
@ -1722,18 +1708,8 @@ 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);
|
||||
|
@ -1748,8 +1724,6 @@ 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;
|
||||
|
@ -1765,17 +1739,12 @@ 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;
|
||||
|
@ -1787,12 +1756,11 @@ void nsString2::SelfTest(void) {
|
|||
{
|
||||
nsString2 theString("hello",theSize);
|
||||
PRUint32 len=theString.Length();
|
||||
PRUnichar ch;
|
||||
for(PRUint32 i=0;i<len;i++) {
|
||||
ch=theString.CharAt(i);
|
||||
PRUnichar ch3=theString.CharAt(i);
|
||||
}
|
||||
ch=theString.First();
|
||||
ch=theString.Last();
|
||||
PRUnichar ch4=theString.First();
|
||||
PRUnichar ch5=theString.Last();
|
||||
}
|
||||
|
||||
//**********************************************
|
||||
|
@ -1861,6 +1829,7 @@ void nsString2::SelfTest(void) {
|
|||
temp1.Right(temp2,4);
|
||||
}
|
||||
|
||||
|
||||
//**********************************************
|
||||
//Now let's test the INSERTION methods...
|
||||
//**********************************************
|
||||
|
@ -2007,15 +1976,6 @@ 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
|
||||
}
|
||||
|
||||
|
@ -2024,6 +1984,14 @@ 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
|
||||
|
@ -2033,9 +2001,8 @@ void nsString2::SelfTest(void) {
|
|||
* @param aCurrentLength tells us the current length of the buffer
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(eCharSize aCharSize) : nsString2(aCharSize){
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
mAgent=0;
|
||||
AddNullTerminator(*this);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2043,11 +2010,8 @@ nsAutoString2::nsAutoString2(eCharSize aCharSize) : nsString2(aCharSize){
|
|||
* @param anExtBuffer describes an external buffer
|
||||
* @param aCString is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(nsStr& aStr,const char* aCString) : nsString2((eCharSize)aStr.mMultibyte) {
|
||||
eCharSize theSize=(eCharSize)aStr.mMultibyte;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>theSize)-1,0,theSize,PR_FALSE);
|
||||
mAgent=0;
|
||||
AddNullTerminator(*this);
|
||||
nsAutoString2::nsAutoString2(nsBufDescriptor& aBufDescriptor,const char* aCString) : nsString2(aBufDescriptor.mMultibyte) {
|
||||
InitAutoStr(*this,aBufDescriptor);
|
||||
Assign(aCString);
|
||||
}
|
||||
|
||||
|
@ -2056,9 +2020,8 @@ nsAutoString2::nsAutoString2(nsStr& aStr,const char* aCString) : nsString2((eCha
|
|||
* @param aCString is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const char* aCString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
mAgent=0;
|
||||
AddNullTerminator(*this);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
Assign(aCString);
|
||||
}
|
||||
|
||||
|
@ -2066,15 +2029,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 aCapacity,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
mAgent=0;
|
||||
nsAutoString2::nsAutoString2(char* aCString,PRUint32 aLen,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
if(assumeOwnership) {
|
||||
nsStr::Initialize(*this,aCString,aCapacity,0,eOneByte,PR_TRUE);
|
||||
nsBufDescriptor theDescriptor(aCString,aLen,eOneByte,PR_TRUE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
}
|
||||
else {
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
nsBufDescriptor theDescriptor(mBuffer,aLen,aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
}
|
||||
AddNullTerminator(*this);
|
||||
Assign(aCString);
|
||||
}
|
||||
|
||||
|
@ -2083,9 +2046,8 @@ nsAutoString2::nsAutoString2(char* aCString,PRUint32 aCapacity,eCharSize aCharSi
|
|||
* @param aString is a ptr to a unistr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const PRUnichar* aString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
|
@ -2093,15 +2055,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 aCapacity,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
mAgent=0;
|
||||
nsAutoString2::nsAutoString2(PRUnichar* aString,PRUint32 aLength,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
if(assumeOwnership) {
|
||||
nsStr::Initialize(*this,(char*)aString,aCapacity,0,eTwoByte,PR_TRUE);
|
||||
nsBufDescriptor theDescriptor((char*)aString,aLength,eTwoByte,PR_TRUE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
}
|
||||
else {
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
}
|
||||
AddNullTerminator(*this);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
|
@ -2111,9 +2073,8 @@ nsAutoString2::nsAutoString2(PRUnichar* aString,PRUint32 aCapacity,eCharSize aCh
|
|||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const nsStr& aString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
|
@ -2122,9 +2083,8 @@ nsAutoString2::nsAutoString2(const nsStr& aString,eCharSize aCharSize) : nsStrin
|
|||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const nsAutoString2& aString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
|
@ -2133,9 +2093,8 @@ nsAutoString2::nsAutoString2(const nsAutoString2& aString,eCharSize aCharSize) :
|
|||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const nsString2& aString,eCharSize aCharSize) : nsString2(aCharSize){
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
|
@ -2145,22 +2104,11 @@ nsAutoString2::nsAutoString2(const nsString2& aString,eCharSize aCharSize) : nsS
|
|||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(PRUnichar aChar,eCharSize aCharSize) : nsString2(aCharSize){
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
Assign(aChar);
|
||||
}
|
||||
|
||||
/**
|
||||
* construct from a subsumeable string
|
||||
* @update gess 1/4/99
|
||||
* @param reference to a subsumeString
|
||||
*/
|
||||
nsAutoString2::nsAutoString2( nsSubsumeStr& aSubsumeStr) :nsString2((eCharSize)aSubsumeStr.mMultibyte) {
|
||||
mAgent=0;
|
||||
Subsume(*this,aSubsumeStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* deconstruct the autstring
|
||||
* @param
|
||||
|
@ -2175,16 +2123,3 @@ 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,19 +20,18 @@
|
|||
/***********************************************************************
|
||||
MODULE NOTES:
|
||||
|
||||
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
|
||||
This class provides a 1-byte ASCII string implementation that shares
|
||||
a common API with all other strImpl derivatives.
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef _nsString2
|
||||
#define _nsString2
|
||||
|
||||
//#define nsString2 nsString
|
||||
//#define nsAutoString2 nsAutoString
|
||||
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nscore.h"
|
||||
#include <iostream.h>
|
||||
|
@ -47,13 +46,6 @@
|
|||
class nsISizeOfHandler;
|
||||
|
||||
|
||||
#ifdef USE_STRING2
|
||||
#define nsString2 nsString
|
||||
#define nsAutoString2 nsAutoString
|
||||
#endif
|
||||
|
||||
class NS_BASE nsSubsumeStr;
|
||||
|
||||
class NS_BASE nsString2 : public nsStr {
|
||||
|
||||
public:
|
||||
|
@ -91,12 +83,6 @@ 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
|
||||
*
|
||||
|
@ -153,15 +139,16 @@ PRBool IsOrdered(void) const;
|
|||
Accessor methods...
|
||||
*********************************************************************/
|
||||
|
||||
const char* GetBuffer(void) const;
|
||||
const PRUnichar* GetUnicode(void) const;
|
||||
char* GetBuffer(void) const;
|
||||
PRUnichar* GetUnicode(void) const;
|
||||
operator PRUnichar*() const {return GetUnicode();}
|
||||
|
||||
|
||||
/**
|
||||
* Get nth character.
|
||||
*/
|
||||
PRUnichar operator[](PRUint32 anIndex) const;
|
||||
PRUnichar CharAt(PRUint32 anIndex) const;
|
||||
PRUnichar operator[](int anIndex) const;
|
||||
PRUnichar CharAt(int anIndex) const;
|
||||
PRUnichar First(void) const;
|
||||
PRUnichar Last(void) const;
|
||||
|
||||
|
@ -177,42 +164,42 @@ PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
|
|||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsSubsumeStr operator+(const nsStr& aString);
|
||||
nsString2 operator+(const nsStr& aString);
|
||||
|
||||
/**
|
||||
* Create a new string by appending given string to this
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsSubsumeStr operator+(const nsString2& aString);
|
||||
nsString2 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
|
||||
*/
|
||||
nsSubsumeStr operator+(const char* aCString);
|
||||
nsString2 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
|
||||
*/
|
||||
nsSubsumeStr operator+(const PRUnichar* aString);
|
||||
nsString2 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
|
||||
*/
|
||||
nsSubsumeStr operator+(char aChar);
|
||||
nsString2 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
|
||||
*/
|
||||
nsSubsumeStr operator+(PRUnichar aChar);
|
||||
nsString2 operator+(PRUnichar aChar);
|
||||
|
||||
/**********************************************************************
|
||||
Lexomorphic transforms...
|
||||
|
@ -366,6 +353,7 @@ 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
|
||||
|
@ -392,7 +380,6 @@ 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...
|
||||
|
@ -415,7 +402,8 @@ 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,
|
||||
|
@ -426,13 +414,13 @@ nsString2& Append(const nsString2& aString) {return Append(aString,aString.mLeng
|
|||
*/
|
||||
nsString2& Append(const nsStr& aString,PRInt32 aCount);
|
||||
nsString2& Append(const nsString2& aString,PRInt32 aCount);
|
||||
nsString2& Append(const char* aString,PRInt32 aCount=-1);
|
||||
nsString2& Append(const PRUnichar* aString,PRInt32 aCount=-1);
|
||||
nsString2& Append(const char* aString,PRInt32 aCount);
|
||||
nsString2& Append(const PRUnichar* aString,PRInt32 aCount);
|
||||
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.
|
||||
|
@ -476,7 +464,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(const nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
|
||||
nsString2& Insert(nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
|
||||
|
||||
/**
|
||||
* Insert a given string into this string at
|
||||
|
@ -531,7 +519,6 @@ 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;
|
||||
|
@ -567,7 +554,6 @@ 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;
|
||||
|
@ -689,8 +675,10 @@ 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;
|
||||
|
@ -713,11 +701,12 @@ 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(nsStr& anExtBuffer,const char* aCString);
|
||||
nsAutoString2(nsBufDescriptor& anExtBuffer,const char* aCString);
|
||||
|
||||
|
||||
nsAutoString2(const char* aCString,eCharSize aCharSize=kDefaultCharSize);
|
||||
|
@ -728,7 +717,6 @@ 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();
|
||||
|
||||
|
@ -750,28 +738,5 @@ 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,103 +31,11 @@
|
|||
#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];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -163,25 +71,9 @@ 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);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess10/30/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess10/30/98
|
||||
|
@ -189,9 +81,13 @@ void nsStr::Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 a
|
|||
* @return
|
||||
*/
|
||||
nsIMemoryAgent* GetDefaultAgent(void){
|
||||
// static nsPoolingMemoryAgent gDefaultAgent;
|
||||
static nsMemoryAgent gDefaultAgent;
|
||||
return (nsIMemoryAgent*)&gDefaultAgent;
|
||||
static nsIMemoryAgent* gDefaultAgent=0;
|
||||
if(!gDefaultAgent)
|
||||
gDefaultAgent=new nsMemoryAgent();
|
||||
|
||||
NS_ASSERTION(gDefaultAgent,"You MUST always have an allocator!");
|
||||
|
||||
return gDefaultAgent;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -214,6 +110,20 @@ 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
|
||||
|
@ -245,8 +155,8 @@ void nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength,nsIMemoryAgent* anAgen
|
|||
nsIMemoryAgent* theAgent=(anAgent) ? anAgent : GetDefaultAgent();
|
||||
EnsureCapacity(theTempStr,aNewLength,theAgent);
|
||||
|
||||
if(aDest.mLength) {
|
||||
Append(theTempStr,aDest,0,aDest.mLength,theAgent);
|
||||
if(0<aDest.mLength) {
|
||||
Append(theTempStr,aDest,0,aDest.mLength,anAgent);
|
||||
}
|
||||
theAgent->Free(aDest);
|
||||
aDest.mStr = theTempStr.mStr;
|
||||
|
@ -272,12 +182,13 @@ 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 gess10/30/98
|
||||
* @update gess 04/04/99
|
||||
* @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);
|
||||
|
@ -310,30 +221,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){
|
||||
ToRange(aDestOffset,0,aDest.mLength);
|
||||
if((0<aSource.mLength) && (aDestOffset<aDest.mLength-1)){
|
||||
if(aDest.mLength){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
//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-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);
|
||||
}
|
||||
|
@ -349,20 +260,22 @@ 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,PRUint32 aCount,nsIMemoryAgent* anAgent){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,nsIMemoryAgent* anAgent){
|
||||
if(0<aCount){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
|
||||
PRUint32 theDelta=aDest.mLength-aDestOffset;
|
||||
PRUint32 theLength=(theDelta<aCount) ? theDelta : aCount;
|
||||
PRInt32 theDelta=aDest.mLength-aDestOffset;
|
||||
PRInt32 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 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
|
||||
}
|
||||
|
||||
|
@ -430,28 +343,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=GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRUnichar theFirstTargetChar=nsStr::GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=nsStr::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=GetCharAt(aDest,index+theSubIndex);
|
||||
PRUnichar theChar=nsStr::GetCharAt(aDest,index+theSubIndex);
|
||||
if(theSubIndex>0) {
|
||||
if(theFirstTargetChar==theChar){
|
||||
PRUnichar theDestJumpChar=GetCharAt(aDest,index+theTargetMax);
|
||||
PRUnichar theDestJumpChar=nsStr::GetCharAt(aDest,index+theTargetMax);
|
||||
if(theDestJumpChar==theLastTargetChar) {
|
||||
theNewStartPos=index; //this lets us jump ahead during our search where possible.
|
||||
}//if
|
||||
}//if
|
||||
}//if
|
||||
PRUnichar theTargetChar=GetCharAt(aTarget,theSubIndex);
|
||||
PRUnichar theTargetChar=nsStr::GetCharAt(aTarget,theSubIndex);
|
||||
matches=PRBool(theChar==theTargetChar);
|
||||
}
|
||||
if(matches)
|
||||
|
@ -471,8 +384,8 @@ PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnor
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
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);
|
||||
PRInt32 nsStr::FindChar(const nsStr& aDest, PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -502,12 +415,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=GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRUnichar theFirstTargetChar=nsStr::GetCharAt(aTarget,0);
|
||||
PRUnichar theLastTargetChar=nsStr::GetCharAt(aTarget,aTarget.mLength-1);
|
||||
PRInt32 theTargetMax=aTarget.mLength;
|
||||
|
||||
while(index--) {
|
||||
|
@ -516,16 +429,16 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgno
|
|||
|
||||
if(anOffset+aTarget.mLength<=aDest.mLength) {
|
||||
while((++theSubIndex<theTargetMax) && (matches)){
|
||||
PRUnichar theChar=GetCharAt(aDest,index+theSubIndex);
|
||||
PRUnichar theChar=nsStr::GetCharAt(aDest,index+theSubIndex);
|
||||
if(theSubIndex>0) {
|
||||
if(theFirstTargetChar==theChar){
|
||||
PRUnichar theDestJumpChar=GetCharAt(aDest,index+theTargetMax);
|
||||
PRUnichar theDestJumpChar=nsStr::GetCharAt(aDest,index+theTargetMax);
|
||||
if(theDestJumpChar==theLastTargetChar) {
|
||||
theNewStartPos=index; //this lets us jump ahead during our search where possible.
|
||||
}//if
|
||||
}//if
|
||||
}//if
|
||||
PRUnichar theTargetChar=GetCharAt(aTarget,theSubIndex);
|
||||
PRUnichar theTargetChar=nsStr::GetCharAt(aTarget,theSubIndex);
|
||||
matches=PRBool(theChar==theTargetChar);
|
||||
} //while
|
||||
} //if
|
||||
|
@ -546,8 +459,8 @@ PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgno
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
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);
|
||||
PRInt32 nsStr::RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRInt32 result=gRFindChars[aDest.mMultibyte](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -559,11 +472,11 @@ PRInt32 nsStr::RFindChar(const nsStr& aDest,const PRUnichar aChar, PRBool aIgnor
|
|||
* @return
|
||||
*/
|
||||
PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRUint32 anOffset) {
|
||||
PRUint32 offset=aDest.mLength-anOffset;
|
||||
PRInt32 offset=aDest.mLength-anOffset;
|
||||
PRInt32 thePos;
|
||||
|
||||
while(--offset>=0) {
|
||||
PRUnichar theChar=GetCharAt(aDest,offset);
|
||||
PRUnichar theChar=GetCharAt(aDest,PRUint32(offset));
|
||||
thePos=gRFindChars[aSet.mMultibyte](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase);
|
||||
if(kNotFound!=thePos)
|
||||
return offset;
|
||||
|
@ -578,7 +491,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,6 +27,8 @@
|
|||
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
|
||||
|
@ -42,13 +44,41 @@
|
|||
#ifndef _nsStr
|
||||
#define _nsStr
|
||||
|
||||
#include "nsCore.h"
|
||||
#include "prtypes.h"
|
||||
#include "nscore.h"
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
enum eCharSize {eOneByte=0,eTwoByte=1};
|
||||
#define kDefaultCharSize eTwoByte
|
||||
const PRInt32 kNotFound = -1;
|
||||
|
||||
|
||||
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;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
class nsIMemoryAgent;
|
||||
|
@ -67,15 +97,6 @@ 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
|
||||
|
@ -145,7 +166,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,PRUint32 aCount,nsIMemoryAgent* anAgent=0);
|
||||
static void Delete(nsStr& aDest,PRUint32 aDestOffset,PRInt32 aCount,nsIMemoryAgent* anAgent=0);
|
||||
|
||||
/**
|
||||
* This method is used to truncate the given string.
|
||||
|
@ -233,20 +254,21 @@ 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);
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
PRUint32 mLength;
|
||||
eCharSize mMultibyte;
|
||||
PRUint32 mCapacity;
|
||||
PRUint32 mOwnsBuffer;
|
||||
PRUint32 mUnused;
|
||||
#else
|
||||
PRUint32 mLength: 30;
|
||||
eCharSize mMultibyte: 2;
|
||||
PRUint32 mLength : 30;
|
||||
eCharSize mMultibyte : 2;
|
||||
PRUint32 mCapacity: 30;
|
||||
PRUint32 mOwnsBuffer: 1;
|
||||
PRUint32 mUnused: 1;
|
||||
#endif
|
||||
PRUint32 mOwnsBuffer: 1;
|
||||
PRUint32 mUnused: 1;
|
||||
union {
|
||||
char* mStr;
|
||||
PRUnichar* mUStr;
|
||||
|
@ -285,21 +307,6 @@ 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 {
|
||||
|
@ -310,18 +317,25 @@ public:
|
|||
};
|
||||
|
||||
class nsMemoryAgent : public nsIMemoryAgent {
|
||||
protected:
|
||||
enum eDelta{eDefaultSize=16};
|
||||
enum eDelta{eGrowthDelta=8};
|
||||
public:
|
||||
|
||||
virtual PRBool Alloc(nsStr& aDest,PRInt32 aCount) {
|
||||
|
||||
//we're given the acount value in charunits; now scale up to next multiple.
|
||||
PRInt32 theNewCapacity=eDefaultSize;
|
||||
while(theNewCapacity<aCount){
|
||||
theNewCapacity<<=1;
|
||||
//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;
|
||||
}
|
||||
|
||||
|
||||
aDest.mCapacity=theNewCapacity++;
|
||||
size_t theSize=(theNewCapacity<<aDest.mMultibyte);
|
||||
aDest.mStr=new char[theSize];
|
||||
|
@ -348,8 +362,5 @@ public:
|
|||
|
||||
};
|
||||
|
||||
char* GetSharedEmptyBuffer();
|
||||
nsIMemoryAgent* GetDefaultAgent(void);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -30,8 +30,8 @@
|
|||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef _nsString1
|
||||
#define _nsString1
|
||||
#ifndef _NSSTRING
|
||||
#define _NSSTRING
|
||||
|
||||
|
||||
#include "prtypes.h"
|
||||
|
@ -39,18 +39,9 @@
|
|||
#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 nsString1 {
|
||||
class NS_BASE nsString {
|
||||
public:
|
||||
|
||||
/**
|
||||
|
@ -59,30 +50,30 @@ class NS_BASE nsString1 {
|
|||
* was to allow developers direct access to the underlying buffer for
|
||||
* performance reasons.
|
||||
*/
|
||||
nsString1();
|
||||
nsString();
|
||||
|
||||
/**
|
||||
* This constructor accepts an isolatin string
|
||||
* @param an ascii is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsString1(const char* aCString);
|
||||
nsString(const char* aCString);
|
||||
|
||||
/**
|
||||
* This is our copy constructor
|
||||
* @param reference to another nsString1
|
||||
* @param reference to another nsString
|
||||
*/
|
||||
nsString1(const nsString1&);
|
||||
nsString(const nsString&);
|
||||
|
||||
/**
|
||||
* Constructor from a unicode string
|
||||
* @param anicodestr pts to a unicode string
|
||||
*/
|
||||
nsString1(const PRUnichar* aUnicode);
|
||||
nsString(const PRUnichar* aUnicode);
|
||||
|
||||
/**
|
||||
* Virtual Destructor
|
||||
*/
|
||||
virtual ~nsString1();
|
||||
virtual ~nsString();
|
||||
|
||||
|
||||
/**
|
||||
|
@ -145,14 +136,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
|
||||
|
@ -192,35 +183,35 @@ PRBool SetCharAt(PRUnichar aChar,PRInt32 anIndex);
|
|||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsString1 operator+(const nsString1& aString);
|
||||
nsString operator+(const nsString& 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
|
||||
*/
|
||||
nsString1 operator+(const char* aCString);
|
||||
nsString 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
|
||||
*/
|
||||
nsString1 operator+(char aChar);
|
||||
nsString 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
|
||||
*/
|
||||
nsString1 operator+(const PRUnichar* aBuffer);
|
||||
nsString 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
|
||||
*/
|
||||
nsString1 operator+(PRUnichar aChar);
|
||||
nsString operator+(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* Converts all chars in internal string to lower
|
||||
|
@ -230,7 +221,7 @@ void ToLowerCase();
|
|||
/**
|
||||
* Converts all chars in given string to lower
|
||||
*/
|
||||
void ToLowerCase(nsString1& aString) const;
|
||||
void ToLowerCase(nsString& aString) const;
|
||||
|
||||
/**
|
||||
* Converts all chars in given string to upper
|
||||
|
@ -246,13 +237,13 @@ void ToUCS2(PRInt32 aStartOffset);
|
|||
/**
|
||||
* Converts all chars in internal string to upper
|
||||
*/
|
||||
void ToUpperCase(nsString1& aString) const;
|
||||
void ToUpperCase(nsString& aString) const;
|
||||
|
||||
/**
|
||||
* Creates a duplicate clone (ptr) of this string.
|
||||
* @return ptr to clone of this string
|
||||
*/
|
||||
nsString1* ToNewString() const;
|
||||
nsString* ToNewString() const;
|
||||
|
||||
/**
|
||||
* Creates an ascii clone of this string
|
||||
|
@ -274,7 +265,7 @@ char* ToCString(char* aBuf,PRInt32 aBufLength) const;
|
|||
* @param aString to hold copy of this
|
||||
* @return nada.
|
||||
*/
|
||||
void Copy(nsString1& aString) const;
|
||||
void Copy(nsString& aString) const;
|
||||
|
||||
/**
|
||||
* Creates an unichar clone of this string
|
||||
|
@ -307,72 +298,79 @@ PRInt32 ToInteger(PRInt32* aErrorCode,PRInt32 aRadix=10) const;
|
|||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString1& SetString(const PRUnichar* aStr,PRInt32 aLength=-1);
|
||||
nsString1& SetString(const char* aCString,PRInt32 aLength=-1);
|
||||
nsString1& SetString(const nsString1& aString);
|
||||
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);
|
||||
|
||||
/**
|
||||
* assign given string to this one
|
||||
* @param aString: string to be added to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator=(const nsString1& aString);
|
||||
nsString& operator=(const nsString& aString);
|
||||
|
||||
/**
|
||||
* assign given char* to this string
|
||||
* @param aCString: buffer to be assigned to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator=(const char* aCString);
|
||||
nsString& operator=(const char* aCString);
|
||||
|
||||
/**
|
||||
* assign given char to this string
|
||||
* @param aChar: char to be assignd to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator=(char aChar);
|
||||
nsString& operator=(char aChar);
|
||||
|
||||
/**
|
||||
* assign given unichar* to this string
|
||||
* @param aBuffer: unichar buffer to be assigned to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator=(const PRUnichar* aBuffer);
|
||||
nsString& operator=(const PRUnichar* aBuffer);
|
||||
|
||||
/**
|
||||
* assign given char to this string
|
||||
* @param aChar: char to be assignd to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator=(PRUnichar aChar);
|
||||
nsString& operator=(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @param aString : string to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator+=(const nsString1& aString);
|
||||
nsString& operator+=(const nsString& aString);
|
||||
|
||||
/**
|
||||
* append given buffer to this string
|
||||
* @param aCString: buffer to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator+=(const char* aCString);
|
||||
nsString& operator+=(const char* aCString);
|
||||
|
||||
/**
|
||||
* append given buffer to this string
|
||||
* @param aBuffer: buffer to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator+=(const PRUnichar* aBuffer);
|
||||
nsString& operator+=(const PRUnichar* aBuffer);
|
||||
|
||||
/**
|
||||
* append given char to this string
|
||||
* @param aChar: char to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& operator+=(PRUnichar aChar);
|
||||
nsString& operator+=(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
|
@ -381,7 +379,7 @@ nsString1& operator+=(PRUnichar aChar);
|
|||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Append(const nsString1& aString,PRInt32 aLength=-1);
|
||||
nsString& Append(const nsString& aString,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
|
@ -390,14 +388,14 @@ nsString1& Append(const nsString1& aString,PRInt32 aLength=-1);
|
|||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Append(const char* aCString,PRInt32 aLength=-1);
|
||||
nsString& Append(const char* aCString,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @param aString : string to be appended to this
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Append(char aChar);
|
||||
nsString& Append(char aChar);
|
||||
|
||||
/**
|
||||
* append given unichar buffer to this string
|
||||
|
@ -406,14 +404,14 @@ nsString1& Append(char aChar);
|
|||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Append(const PRUnichar* aBuffer,PRInt32 aLength=-1);
|
||||
nsString& 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
|
||||
*/
|
||||
nsString1& Append(PRUnichar aChar);
|
||||
nsString& Append(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* Append an integer onto this string
|
||||
|
@ -421,14 +419,14 @@ nsString1& Append(PRUnichar aChar);
|
|||
* @param aRadix specifies 8,10,16
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Append(PRInt32 aInteger,PRInt32 aRadix); //radix=8,10 or 16
|
||||
nsString& 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
|
||||
*/
|
||||
nsString1& Append(float aFloat);
|
||||
nsString& Append(float aFloat);
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
|
@ -439,7 +437,7 @@ nsString1& Append(float aFloat);
|
|||
* @param aCount -- number of chars to copy
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Left(nsString1& aCopy,PRInt32 aCount) const;
|
||||
PRInt32 Left(nsString& aCopy,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
|
@ -451,7 +449,7 @@ PRInt32 Left(nsString1& aCopy,PRInt32 aCount) const;
|
|||
* @param anOffset -- position where copying begins
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Mid(nsString1& aCopy,PRInt32 anOffset,PRInt32 aCount) const;
|
||||
PRInt32 Mid(nsString& aCopy,PRInt32 anOffset,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
|
@ -462,7 +460,7 @@ PRInt32 Mid(nsString1& aCopy,PRInt32 anOffset,PRInt32 aCount) const;
|
|||
* @param aCount -- number of chars to copy
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRInt32 Right(nsString1& aCopy,PRInt32 aCount) const;
|
||||
PRInt32 Right(nsString& aCopy,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* This method inserts n chars from given string into this
|
||||
|
@ -473,7 +471,7 @@ PRInt32 Right(nsString1& aCopy,PRInt32 aCount) const;
|
|||
* @param aCount -- number of chars to be copied from aCopy
|
||||
* @return number of chars inserted into this.
|
||||
*/
|
||||
PRInt32 Insert(const nsString1& aCopy,PRInt32 anOffset,PRInt32 aCount=-1);
|
||||
PRInt32 Insert(const nsString& aCopy,PRInt32 anOffset,PRInt32 aCount=-1);
|
||||
|
||||
/**
|
||||
* Insert a single unicode char into this string at
|
||||
|
@ -493,7 +491,7 @@ PRInt32 Insert(PRUnichar aChar,PRInt32 anOffset);
|
|||
* @param aCount -- number of chars to be cut
|
||||
* @return *this
|
||||
*/
|
||||
nsString1& Cut(PRInt32 anOffset,PRInt32 aCount);
|
||||
nsString& Cut(PRInt32 anOffset,PRInt32 aCount);
|
||||
|
||||
/**
|
||||
* This method is used to remove all occurances of the
|
||||
|
@ -502,7 +500,7 @@ nsString1& Cut(PRInt32 anOffset,PRInt32 aCount);
|
|||
* @param aSet -- characters to be cut from this
|
||||
* @return *this
|
||||
*/
|
||||
nsString1& StripChars(const char* aSet);
|
||||
nsString& StripChars(const char* aSet);
|
||||
|
||||
/**
|
||||
* This method is used to replace all occurances of the
|
||||
|
@ -511,14 +509,14 @@ nsString1& StripChars(const char* aSet);
|
|||
* @param
|
||||
* @return *this
|
||||
*/
|
||||
nsString1& ReplaceChar(PRUnichar aSourceChar, PRUnichar aDestChar);
|
||||
nsString& ReplaceChar(PRUnichar aSourceChar, PRUnichar aDestChar);
|
||||
|
||||
/**
|
||||
* This method strips whitespace throughout the string
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
nsString1& StripWhitespace();
|
||||
nsString& StripWhitespace();
|
||||
|
||||
/**
|
||||
* This method trims characters found in aTrimSet from
|
||||
|
@ -528,7 +526,7 @@ nsString1& StripWhitespace();
|
|||
* both ends
|
||||
* @return this
|
||||
*/
|
||||
nsString1& Trim(const char* aSet,
|
||||
nsString& Trim(const char* aSet,
|
||||
PRBool aEliminateLeading=PR_TRUE,
|
||||
PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
|
@ -541,7 +539,7 @@ nsString1& Trim(const char* aSet,
|
|||
* @param aEliminateTrailing controls stripping of trailing ws
|
||||
* @return this
|
||||
*/
|
||||
nsString1& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,
|
||||
nsString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,
|
||||
PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
/**
|
||||
|
@ -590,7 +588,7 @@ PRInt32 BinarySearch(PRUnichar aChar) const;
|
|||
*/
|
||||
PRInt32 Find(const char* aString) const;
|
||||
PRInt32 Find(const PRUnichar* aString) const;
|
||||
PRInt32 Find(const nsString1& aString) const;
|
||||
PRInt32 Find(const nsString& aString) const;
|
||||
|
||||
/**
|
||||
* Search for given char within this string
|
||||
|
@ -608,7 +606,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(nsString1& aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 FindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
||||
|
||||
/**
|
||||
* This method searches this string for the last character
|
||||
|
@ -618,7 +616,7 @@ PRInt32 FindCharInSet(nsString1& 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(nsString1& aString,PRInt32 anOffset=0) const;
|
||||
PRInt32 RFindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -629,7 +627,7 @@ PRInt32 RFindCharInSet(nsString1& 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 nsString1& aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
|
||||
/**
|
||||
* This methods scans the string backwards, looking for the given char
|
||||
|
@ -650,7 +648,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 nsString1 &aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
virtual PRInt32 Compare(const nsString &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;
|
||||
|
||||
|
@ -659,7 +657,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 nsString1 &aString) const;
|
||||
PRBool operator==(const nsString &aString) const;
|
||||
PRBool operator==(const char *aString) const;
|
||||
PRBool operator==(const PRUnichar* aString) const;
|
||||
PRBool operator==(PRUnichar* aString) const;
|
||||
|
@ -669,7 +667,7 @@ PRBool operator==(PRUnichar* aString) const;
|
|||
* @param aString is the string to be compared to this
|
||||
* @return TRUE
|
||||
*/
|
||||
PRBool operator!=(const nsString1 &aString) const;
|
||||
PRBool operator!=(const nsString &aString) const;
|
||||
PRBool operator!=(const char *aString) const;
|
||||
PRBool operator!=(const PRUnichar* aString) const;
|
||||
|
||||
|
@ -678,7 +676,7 @@ PRBool operator!=(const PRUnichar* aString) const;
|
|||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator<(const nsString1 &aString) const;
|
||||
PRBool operator<(const nsString &aString) const;
|
||||
PRBool operator<(const char *aString) const;
|
||||
PRBool operator<(const PRUnichar* aString) const;
|
||||
|
||||
|
@ -687,7 +685,7 @@ PRBool operator<(const PRUnichar* aString) const;
|
|||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator>(const nsString1 &S) const;
|
||||
PRBool operator>(const nsString &S) const;
|
||||
PRBool operator>(const char *aCString) const;
|
||||
PRBool operator>(const PRUnichar* aString) const;
|
||||
|
||||
|
@ -696,7 +694,7 @@ PRBool operator>(const PRUnichar* aString) const;
|
|||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator<=(const nsString1 &S) const;
|
||||
PRBool operator<=(const nsString &S) const;
|
||||
PRBool operator<=(const char *aCString) const;
|
||||
PRBool operator<=(const PRUnichar* aString) const;
|
||||
|
||||
|
@ -705,7 +703,7 @@ PRBool operator<=(const PRUnichar* aString) const;
|
|||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator>=(const nsString1 &S) const;
|
||||
PRBool operator>=(const nsString &S) const;
|
||||
PRBool operator>=(const char* aCString) const;
|
||||
PRBool operator>=(const PRUnichar* aString) const;
|
||||
|
||||
|
@ -719,7 +717,7 @@ PRBool operator>=(const PRUnichar* aString) const;
|
|||
* @param aLength -- optional length of given string.
|
||||
* @return TRUE if equal
|
||||
*/
|
||||
PRBool Equals(const nsString1& aString) const;
|
||||
PRBool Equals(const nsString& aString) const;
|
||||
PRBool Equals(const char* aString,PRInt32 aLength=-1) const;
|
||||
PRBool Equals(const nsIAtom *aAtom) const;
|
||||
|
||||
|
@ -742,7 +740,7 @@ PRBool Equals(const PRUnichar* s1, const PRUnichar* s2) const;
|
|||
* @param aLength -- optional length of given string.
|
||||
* @return TRUE if equal
|
||||
*/
|
||||
PRBool EqualsIgnoreCase(const nsString1& aString) const;
|
||||
PRBool EqualsIgnoreCase(const nsString& aString) const;
|
||||
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aLength=-1) const;
|
||||
PRBool EqualsIgnoreCase(const nsIAtom *aAtom) const;
|
||||
|
||||
|
@ -770,34 +768,34 @@ typedef PRUnichar chartype;
|
|||
#endif
|
||||
};
|
||||
|
||||
ostream& operator<<(ostream& os,nsString1& aString);
|
||||
extern NS_BASE int fputs(const nsString1& aString, FILE* out);
|
||||
ostream& operator<<(ostream& os,nsString& aString);
|
||||
extern NS_BASE int fputs(const nsString& aString, FILE* out);
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* A version of nsString1 which is designed to be used as an automatic
|
||||
* A version of nsString 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 nsAutoString1 : public nsString1 {
|
||||
class NS_BASE nsAutoString : public nsString {
|
||||
public:
|
||||
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();
|
||||
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& 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;}
|
||||
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;}
|
||||
|
||||
virtual void SizeOf(nsISizeOfHandler* aHandler) const;
|
||||
|
||||
|
@ -809,7 +807,7 @@ protected:
|
|||
chartype mBuf[32];
|
||||
};
|
||||
|
||||
ostream& operator<<(ostream& os,nsAutoString1& aString);
|
||||
ostream& operator<<(ostream& os,nsAutoString& aString);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -25,15 +25,18 @@
|
|||
#include "nsDebug.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsISizeOfHandler.h"
|
||||
#include "prprf.h"
|
||||
#include "prdtoa.h"
|
||||
#include "nsDeque.h"
|
||||
|
||||
#ifndef RICKG_TESTBED
|
||||
#include "prdtoa.h"
|
||||
#include "nsISizeOfHandler.h"
|
||||
#endif
|
||||
#include "nsUnicharUtilCIID.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsICaseConversion.h"
|
||||
|
||||
static const char* kNullPointerError = "Error: unexpected null ptr";
|
||||
static const char* kWhitespace="\b\t\r\n ";
|
||||
static const PRInt32 kNotFound=-1;
|
||||
|
||||
#ifdef RICKG_DEBUG
|
||||
PRBool nsString2::mSelfTested = PR_FALSE;
|
||||
|
@ -94,7 +97,58 @@ 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:
|
||||
|
@ -104,15 +158,6 @@ public:
|
|||
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
|
||||
|
@ -171,15 +216,6 @@ 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.
|
||||
|
@ -257,7 +293,7 @@ void nsString2::SetCapacity(PRUint32 aLength) {
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
const char* nsString2::GetBuffer(void) const {
|
||||
char* nsString2::GetBuffer(void) const {
|
||||
if(!mMultibyte)
|
||||
return mStr;
|
||||
return 0;
|
||||
|
@ -269,7 +305,7 @@ const char* nsString2::GetBuffer(void) const {
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
const PRUnichar* nsString2::GetUnicode(void) const {
|
||||
PRUnichar* nsString2::GetUnicode(void) const {
|
||||
if(mMultibyte)
|
||||
return (PRUnichar*)mUStr;
|
||||
return 0;
|
||||
|
@ -278,11 +314,11 @@ const PRUnichar* nsString2::GetUnicode(void) const {
|
|||
/**
|
||||
* Get nth character.
|
||||
*/
|
||||
PRUnichar nsString2::operator[](PRUint32 anIndex) const {
|
||||
PRUnichar nsString2::operator[](int anIndex) const {
|
||||
return GetCharAt(*this,anIndex);
|
||||
}
|
||||
|
||||
PRUnichar nsString2::CharAt(PRUint32 anIndex) const {
|
||||
PRUnichar nsString2::CharAt(int anIndex) const {
|
||||
return GetCharAt(*this,anIndex);
|
||||
}
|
||||
|
||||
|
@ -316,10 +352,10 @@ PRBool nsString2::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
|
|||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsSubsumeStr nsString2::operator+(const nsStr& aString){
|
||||
nsString2 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 nsSubsumeStr(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -328,10 +364,10 @@ nsSubsumeStr nsString2::operator+(const nsStr& aString){
|
|||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsSubsumeStr nsString2::operator+(const nsString2& aString){
|
||||
nsString2 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 nsSubsumeStr(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
|
@ -341,10 +377,10 @@ nsSubsumeStr nsString2::operator+(const nsString2& aString){
|
|||
* @param aCString is a ptr to cstring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsSubsumeStr nsString2::operator+(const char* aCString) {
|
||||
nsString2 nsString2::operator+(const char* aCString) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(aCString);
|
||||
return nsSubsumeStr(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
|
@ -354,10 +390,10 @@ nsSubsumeStr nsString2::operator+(const char* aCString) {
|
|||
* @param aChar is a char to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsSubsumeStr nsString2::operator+(char aChar) {
|
||||
nsString2 nsString2::operator+(char aChar) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(char(aChar));
|
||||
return nsSubsumeStr(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -366,10 +402,10 @@ nsSubsumeStr nsString2::operator+(char aChar) {
|
|||
* @param aString is a ptr to unistring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsSubsumeStr nsString2::operator+(const PRUnichar* aString) {
|
||||
nsString2 nsString2::operator+(const PRUnichar* aString) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(aString);
|
||||
return nsSubsumeStr(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
|
@ -379,10 +415,10 @@ nsSubsumeStr nsString2::operator+(const PRUnichar* aString) {
|
|||
* @param aChar is a unichar to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsSubsumeStr nsString2::operator+(PRUnichar aChar) {
|
||||
nsString2 nsString2::operator+(PRUnichar aChar) {
|
||||
nsString2 temp(*this);
|
||||
temp.Append(char(aChar));
|
||||
return nsSubsumeStr(temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
|
@ -393,7 +429,6 @@ nsSubsumeStr 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;
|
||||
|
@ -586,11 +621,11 @@ PRUnichar* nsString2::ToNewUnicode() const {
|
|||
*/
|
||||
char* nsString2::ToCString(char* aBuf, PRUint32 aBufLength) const{
|
||||
if(aBuf) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mStr=aBuf;
|
||||
temp.mCapacity=aBufLength;
|
||||
nsStr::Assign(temp,*this,0,mLength,mAgent);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mStr=aBuf;
|
||||
theTempStr.mCapacity=aBufLength;
|
||||
nsStr::Assign(theTempStr,*this,0,mLength,mAgent);
|
||||
}
|
||||
return aBuf;
|
||||
}
|
||||
|
@ -765,19 +800,15 @@ nsString2& nsString2::Assign(PRUnichar aChar) {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* Copies contents of this onto given string.
|
||||
* @update gess 7/27/98
|
||||
* @param aString to hold copy of this
|
||||
* @return nada.
|
||||
*/
|
||||
nsString2& nsString2::operator=(nsSubsumeStr& aSubsumeString) {
|
||||
Subsume(*this,aSubsumeString);
|
||||
return *this;
|
||||
void nsString2::Copy(nsString2& aString) const{
|
||||
aString.SetString(*this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* append given string to this string
|
||||
* @update gess 01/04/99
|
||||
|
@ -812,12 +843,12 @@ nsString2& nsString2::Append(const nsString2& aString,PRInt32 aCount) {
|
|||
*/
|
||||
nsString2& nsString2::Append(const char* aCString,PRInt32 aCount) {
|
||||
if(aCString){
|
||||
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);
|
||||
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);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
@ -831,12 +862,12 @@ nsString2& nsString2::Append(const char* aCString,PRInt32 aCount) {
|
|||
*/
|
||||
nsString2& nsString2::Append(const PRUnichar* aString,PRInt32 aCount) {
|
||||
if(aString){
|
||||
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);
|
||||
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);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
@ -851,11 +882,11 @@ nsString2& nsString2::Append(char aChar) {
|
|||
char buf[2]={0,0};
|
||||
buf[0]=aChar;
|
||||
|
||||
nsStr temp;
|
||||
Initialize(temp,eOneByte);
|
||||
temp.mStr=buf;
|
||||
temp.mLength=1;
|
||||
nsStr::Append(*this,temp,0,1,mAgent);
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eOneByte);
|
||||
theTemp.mStr=buf;
|
||||
theTemp.mLength=1;
|
||||
nsStr::Append(*this,theTemp,0,1,mAgent);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -869,11 +900,11 @@ nsString2& nsString2::Append(PRUnichar aChar) {
|
|||
PRUnichar buf[2]={0,0};
|
||||
buf[0]=aChar;
|
||||
|
||||
nsStr temp;
|
||||
Initialize(temp,eTwoByte);
|
||||
temp.mUStr=buf;
|
||||
temp.mLength=1;
|
||||
nsStr::Append(*this,temp,0,1,mAgent);
|
||||
nsStr theTemp;
|
||||
Initialize(theTemp,eTwoByte);
|
||||
theTemp.mUStr=buf;
|
||||
theTemp.mLength=1;
|
||||
nsStr::Append(*this,theTemp,0,1,mAgent);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -970,7 +1001,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(const nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount) {
|
||||
nsString2& nsString2::Insert(nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount) {
|
||||
nsStr::Insert(*this,anOffset,aCopy,0,aCount,mAgent);
|
||||
return *this;
|
||||
}
|
||||
|
@ -987,12 +1018,12 @@ nsString2& nsString2::Insert(const nsString2& aCopy,PRUint32 anOffset,PRInt32 aC
|
|||
nsString2& nsString2::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCount){
|
||||
if(aCString){
|
||||
if(0<aCount) {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1013,11 +1044,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 temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mStr=(char*)theBuffer;
|
||||
temp.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,temp,0,1,0);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mStr=(char*)theBuffer;
|
||||
theTempStr.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,theTempStr,0,1,0);
|
||||
return *this;
|
||||
}
|
||||
*/
|
||||
|
@ -1034,12 +1065,12 @@ nsString2& nsString2::Insert(char aChar,PRUint32 anOffset){
|
|||
nsString2& nsString2::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32 aCount){
|
||||
if(aString){
|
||||
if(0<aCount) {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1059,11 +1090,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 temp;
|
||||
nsStr::Initialize(temp,eTwoByte);
|
||||
temp.mUStr=theBuffer;
|
||||
temp.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,temp,0,1,0);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mUStr=theBuffer;
|
||||
theTempStr.mLength=1;
|
||||
nsStr::Insert(*this,anOffset,theTempStr,0,1,0);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -1122,11 +1153,11 @@ PRInt32 nsString2::Find(const char* aCString,PRBool aIgnoreCase) const{
|
|||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aCString) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCString);
|
||||
temp.mStr=(char*)aCString;
|
||||
result=nsStr::FindSubstr(*this,temp,aIgnoreCase,0);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCString);
|
||||
theTempStr.mStr=(char*)aCString;
|
||||
result=nsStr::FindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -1143,11 +1174,11 @@ PRInt32 nsString2::Find(const PRUnichar* aString,PRBool aIgnoreCase) const{
|
|||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aString) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eTwoByte);
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
temp.mUStr=(PRUnichar*)aString;
|
||||
result=nsStr::FindSubstr(*this,temp,aIgnoreCase,0);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mUStr=(PRUnichar*)aString;
|
||||
result=nsStr::FindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -1164,18 +1195,6 @@ 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
|
||||
*
|
||||
|
@ -1200,11 +1219,11 @@ PRInt32 nsString2::FindCharInSet(const char* aCStringSet,PRUint32 anOffset) cons
|
|||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aCStringSet) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCStringSet);
|
||||
temp.mStr=(char*)aCStringSet;
|
||||
result=nsStr::FindCharInSet(*this,temp,PR_FALSE,anOffset);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCStringSet);
|
||||
theTempStr.mStr=(char*)aCStringSet;
|
||||
result=nsStr::FindCharInSet(*this,theTempStr,PR_FALSE,anOffset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -1233,11 +1252,11 @@ PRInt32 nsString2::RFindCharInSet(const char* aCStringSet,PRUint32 anOffset) con
|
|||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aCStringSet) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCStringSet);
|
||||
temp.mStr=(char*)aCStringSet;
|
||||
result=nsStr::RFindCharInSet(*this,temp,PR_FALSE,anOffset);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCStringSet);
|
||||
theTempStr.mStr=(char*)aCStringSet;
|
||||
result=nsStr::RFindCharInSet(*this,theTempStr,PR_FALSE,anOffset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -1266,18 +1285,6 @@ 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;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
|
@ -1290,11 +1297,11 @@ PRInt32 nsString2::RFind(const char* aString,PRBool aIgnoreCase) const{
|
|||
|
||||
PRInt32 result=kNotFound;
|
||||
if(aString) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
temp.mStr=(char*)aString;
|
||||
result=nsStr::RFindSubstr(*this,temp,aIgnoreCase,0);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mStr=(char*)aString;
|
||||
result=nsStr::RFindSubstr(*this,theTempStr,aIgnoreCase,0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -1327,11 +1334,11 @@ PRInt32 nsString2::Compare(const char *aCString,PRBool aIgnoreCase,PRInt32 aLeng
|
|||
NS_ASSERTION(0!=aCString,kNullPointerError);
|
||||
|
||||
if(aCString) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eOneByte);
|
||||
temp.mLength=nsCRT::strlen(aCString);
|
||||
temp.mStr=(char*)aCString;
|
||||
return nsStr::Compare(*this,temp,aLength,aIgnoreCase);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eOneByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aCString);
|
||||
theTempStr.mStr=(char*)aCString;
|
||||
return nsStr::Compare(*this,theTempStr,aLength,aIgnoreCase);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1347,11 +1354,11 @@ PRInt32 nsString2::Compare(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 a
|
|||
NS_ASSERTION(0!=aString,kNullPointerError);
|
||||
|
||||
if(aString) {
|
||||
nsStr temp;
|
||||
nsStr::Initialize(temp,eTwoByte);
|
||||
temp.mLength=nsCRT::strlen(aString);
|
||||
temp.mUStr=(PRUnichar*)aString;
|
||||
return nsStr::Compare(*this,temp,aLength,aIgnoreCase);
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,eTwoByte);
|
||||
theTempStr.mLength=nsCRT::strlen(aString);
|
||||
theTempStr.mUStr=(PRUnichar*)aString;
|
||||
return nsStr::Compare(*this,theTempStr,aLength,aIgnoreCase);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1561,37 +1568,16 @@ 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);
|
||||
}
|
||||
|
@ -1641,6 +1627,7 @@ void nsString2::Recycle(nsString2* aString){
|
|||
GetRecycler().Recycle(aString);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -1713,7 +1700,6 @@ void nsString2::SelfTest(void) {
|
|||
static const char* kConstructorError = kConstructorError;
|
||||
static const char* kComparisonError = "Comparision error!";
|
||||
static const char* kEqualsError = "Equals error!";
|
||||
|
||||
mSelfTested=PR_TRUE;
|
||||
|
||||
eCharSize theSize=eOneByte;
|
||||
|
@ -1722,18 +1708,8 @@ 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);
|
||||
|
@ -1748,8 +1724,6 @@ 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;
|
||||
|
@ -1765,17 +1739,12 @@ 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;
|
||||
|
@ -1787,12 +1756,11 @@ void nsString2::SelfTest(void) {
|
|||
{
|
||||
nsString2 theString("hello",theSize);
|
||||
PRUint32 len=theString.Length();
|
||||
PRUnichar ch;
|
||||
for(PRUint32 i=0;i<len;i++) {
|
||||
ch=theString.CharAt(i);
|
||||
PRUnichar ch3=theString.CharAt(i);
|
||||
}
|
||||
ch=theString.First();
|
||||
ch=theString.Last();
|
||||
PRUnichar ch4=theString.First();
|
||||
PRUnichar ch5=theString.Last();
|
||||
}
|
||||
|
||||
//**********************************************
|
||||
|
@ -1861,6 +1829,7 @@ void nsString2::SelfTest(void) {
|
|||
temp1.Right(temp2,4);
|
||||
}
|
||||
|
||||
|
||||
//**********************************************
|
||||
//Now let's test the INSERTION methods...
|
||||
//**********************************************
|
||||
|
@ -2007,15 +1976,6 @@ 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
|
||||
}
|
||||
|
||||
|
@ -2024,6 +1984,14 @@ 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
|
||||
|
@ -2033,9 +2001,8 @@ void nsString2::SelfTest(void) {
|
|||
* @param aCurrentLength tells us the current length of the buffer
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(eCharSize aCharSize) : nsString2(aCharSize){
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
mAgent=0;
|
||||
AddNullTerminator(*this);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2043,11 +2010,8 @@ nsAutoString2::nsAutoString2(eCharSize aCharSize) : nsString2(aCharSize){
|
|||
* @param anExtBuffer describes an external buffer
|
||||
* @param aCString is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(nsStr& aStr,const char* aCString) : nsString2((eCharSize)aStr.mMultibyte) {
|
||||
eCharSize theSize=(eCharSize)aStr.mMultibyte;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>theSize)-1,0,theSize,PR_FALSE);
|
||||
mAgent=0;
|
||||
AddNullTerminator(*this);
|
||||
nsAutoString2::nsAutoString2(nsBufDescriptor& aBufDescriptor,const char* aCString) : nsString2(aBufDescriptor.mMultibyte) {
|
||||
InitAutoStr(*this,aBufDescriptor);
|
||||
Assign(aCString);
|
||||
}
|
||||
|
||||
|
@ -2056,9 +2020,8 @@ nsAutoString2::nsAutoString2(nsStr& aStr,const char* aCString) : nsString2((eCha
|
|||
* @param aCString is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const char* aCString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
mAgent=0;
|
||||
AddNullTerminator(*this);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
Assign(aCString);
|
||||
}
|
||||
|
||||
|
@ -2066,15 +2029,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 aCapacity,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
mAgent=0;
|
||||
nsAutoString2::nsAutoString2(char* aCString,PRUint32 aLen,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
if(assumeOwnership) {
|
||||
nsStr::Initialize(*this,aCString,aCapacity,0,eOneByte,PR_TRUE);
|
||||
nsBufDescriptor theDescriptor(aCString,aLen,eOneByte,PR_TRUE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
}
|
||||
else {
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
nsBufDescriptor theDescriptor(mBuffer,aLen,aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
}
|
||||
AddNullTerminator(*this);
|
||||
Assign(aCString);
|
||||
}
|
||||
|
||||
|
@ -2083,9 +2046,8 @@ nsAutoString2::nsAutoString2(char* aCString,PRUint32 aCapacity,eCharSize aCharSi
|
|||
* @param aString is a ptr to a unistr
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const PRUnichar* aString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
|
@ -2093,15 +2055,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 aCapacity,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
mAgent=0;
|
||||
nsAutoString2::nsAutoString2(PRUnichar* aString,PRUint32 aLength,eCharSize aCharSize,PRBool assumeOwnership) : nsString2(aCharSize) {
|
||||
if(assumeOwnership) {
|
||||
nsStr::Initialize(*this,(char*)aString,aCapacity,0,eTwoByte,PR_TRUE);
|
||||
nsBufDescriptor theDescriptor((char*)aString,aLength,eTwoByte,PR_TRUE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
}
|
||||
else {
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
}
|
||||
AddNullTerminator(*this);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
|
@ -2111,9 +2073,8 @@ nsAutoString2::nsAutoString2(PRUnichar* aString,PRUint32 aCapacity,eCharSize aCh
|
|||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const nsStr& aString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
|
@ -2122,9 +2083,8 @@ nsAutoString2::nsAutoString2(const nsStr& aString,eCharSize aCharSize) : nsStrin
|
|||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const nsAutoString2& aString,eCharSize aCharSize) : nsString2(aCharSize) {
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
|
@ -2133,9 +2093,8 @@ nsAutoString2::nsAutoString2(const nsAutoString2& aString,eCharSize aCharSize) :
|
|||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(const nsString2& aString,eCharSize aCharSize) : nsString2(aCharSize){
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
|
@ -2145,22 +2104,11 @@ nsAutoString2::nsAutoString2(const nsString2& aString,eCharSize aCharSize) : nsS
|
|||
* @param
|
||||
*/
|
||||
nsAutoString2::nsAutoString2(PRUnichar aChar,eCharSize aCharSize) : nsString2(aCharSize){
|
||||
mAgent=0;
|
||||
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>aCharSize)-1,0,aCharSize,PR_FALSE);
|
||||
AddNullTerminator(*this);
|
||||
nsBufDescriptor theDescriptor(mBuffer,sizeof(mBuffer),aCharSize,PR_FALSE);
|
||||
InitAutoStr(*this,theDescriptor);
|
||||
Assign(aChar);
|
||||
}
|
||||
|
||||
/**
|
||||
* construct from a subsumeable string
|
||||
* @update gess 1/4/99
|
||||
* @param reference to a subsumeString
|
||||
*/
|
||||
nsAutoString2::nsAutoString2( nsSubsumeStr& aSubsumeStr) :nsString2((eCharSize)aSubsumeStr.mMultibyte) {
|
||||
mAgent=0;
|
||||
Subsume(*this,aSubsumeStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* deconstruct the autstring
|
||||
* @param
|
||||
|
@ -2175,16 +2123,3 @@ 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,19 +20,18 @@
|
|||
/***********************************************************************
|
||||
MODULE NOTES:
|
||||
|
||||
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
|
||||
This class provides a 1-byte ASCII string implementation that shares
|
||||
a common API with all other strImpl derivatives.
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef _nsString2
|
||||
#define _nsString2
|
||||
|
||||
//#define nsString2 nsString
|
||||
//#define nsAutoString2 nsAutoString
|
||||
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nscore.h"
|
||||
#include <iostream.h>
|
||||
|
@ -47,13 +46,6 @@
|
|||
class nsISizeOfHandler;
|
||||
|
||||
|
||||
#ifdef USE_STRING2
|
||||
#define nsString2 nsString
|
||||
#define nsAutoString2 nsAutoString
|
||||
#endif
|
||||
|
||||
class NS_BASE nsSubsumeStr;
|
||||
|
||||
class NS_BASE nsString2 : public nsStr {
|
||||
|
||||
public:
|
||||
|
@ -91,12 +83,6 @@ 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
|
||||
*
|
||||
|
@ -153,15 +139,16 @@ PRBool IsOrdered(void) const;
|
|||
Accessor methods...
|
||||
*********************************************************************/
|
||||
|
||||
const char* GetBuffer(void) const;
|
||||
const PRUnichar* GetUnicode(void) const;
|
||||
char* GetBuffer(void) const;
|
||||
PRUnichar* GetUnicode(void) const;
|
||||
operator PRUnichar*() const {return GetUnicode();}
|
||||
|
||||
|
||||
/**
|
||||
* Get nth character.
|
||||
*/
|
||||
PRUnichar operator[](PRUint32 anIndex) const;
|
||||
PRUnichar CharAt(PRUint32 anIndex) const;
|
||||
PRUnichar operator[](int anIndex) const;
|
||||
PRUnichar CharAt(int anIndex) const;
|
||||
PRUnichar First(void) const;
|
||||
PRUnichar Last(void) const;
|
||||
|
||||
|
@ -177,42 +164,42 @@ PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
|
|||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsSubsumeStr operator+(const nsStr& aString);
|
||||
nsString2 operator+(const nsStr& aString);
|
||||
|
||||
/**
|
||||
* Create a new string by appending given string to this
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsSubsumeStr operator+(const nsString2& aString);
|
||||
nsString2 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
|
||||
*/
|
||||
nsSubsumeStr operator+(const char* aCString);
|
||||
nsString2 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
|
||||
*/
|
||||
nsSubsumeStr operator+(const PRUnichar* aString);
|
||||
nsString2 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
|
||||
*/
|
||||
nsSubsumeStr operator+(char aChar);
|
||||
nsString2 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
|
||||
*/
|
||||
nsSubsumeStr operator+(PRUnichar aChar);
|
||||
nsString2 operator+(PRUnichar aChar);
|
||||
|
||||
/**********************************************************************
|
||||
Lexomorphic transforms...
|
||||
|
@ -366,6 +353,7 @@ 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
|
||||
|
@ -392,7 +380,6 @@ 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...
|
||||
|
@ -415,7 +402,8 @@ 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,
|
||||
|
@ -426,13 +414,13 @@ nsString2& Append(const nsString2& aString) {return Append(aString,aString.mLeng
|
|||
*/
|
||||
nsString2& Append(const nsStr& aString,PRInt32 aCount);
|
||||
nsString2& Append(const nsString2& aString,PRInt32 aCount);
|
||||
nsString2& Append(const char* aString,PRInt32 aCount=-1);
|
||||
nsString2& Append(const PRUnichar* aString,PRInt32 aCount=-1);
|
||||
nsString2& Append(const char* aString,PRInt32 aCount);
|
||||
nsString2& Append(const PRUnichar* aString,PRInt32 aCount);
|
||||
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.
|
||||
|
@ -476,7 +464,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(const nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
|
||||
nsString2& Insert(nsString2& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
|
||||
|
||||
/**
|
||||
* Insert a given string into this string at
|
||||
|
@ -531,7 +519,6 @@ 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;
|
||||
|
@ -567,7 +554,6 @@ 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;
|
||||
|
@ -689,8 +675,10 @@ 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;
|
||||
|
@ -713,11 +701,12 @@ 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(nsStr& anExtBuffer,const char* aCString);
|
||||
nsAutoString2(nsBufDescriptor& anExtBuffer,const char* aCString);
|
||||
|
||||
|
||||
nsAutoString2(const char* aCString,eCharSize aCharSize=kDefaultCharSize);
|
||||
|
@ -728,7 +717,6 @@ 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();
|
||||
|
||||
|
@ -750,28 +738,5 @@ 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
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче