From 5ef8811e3657ef63bfcb36397d5dc9fbaf9231e4 Mon Sep 17 00:00:00 2001 From: "scc%mozilla.org" Date: Mon, 19 Feb 2001 01:34:34 +0000 Subject: [PATCH] bug #69315: r=dbaron, a=ben. Remove unused experimental string files that have never been part of the build --- xpcom/ds/nsAutoStringImpl.h | 88 -- xpcom/ds/nsBufferManager.h | 1555 ---------------------------------- xpcom/ds/nsImmutableString.h | 145 ---- xpcom/ds/nsString2x.cpp | 1251 --------------------------- xpcom/ds/nsString2x.h | 576 ------------- xpcom/ds/nsStringImpl.h | 515 ----------- xpcom/ds/nsStringValue.h | 211 ----- xpcom/ds/nsStringx.cpp | 1127 ------------------------ xpcom/ds/nsStringx.h | 525 ------------ 9 files changed, 5993 deletions(-) delete mode 100644 xpcom/ds/nsAutoStringImpl.h delete mode 100644 xpcom/ds/nsBufferManager.h delete mode 100644 xpcom/ds/nsImmutableString.h delete mode 100644 xpcom/ds/nsString2x.cpp delete mode 100644 xpcom/ds/nsString2x.h delete mode 100644 xpcom/ds/nsStringImpl.h delete mode 100644 xpcom/ds/nsStringValue.h delete mode 100644 xpcom/ds/nsStringx.cpp delete mode 100644 xpcom/ds/nsStringx.h diff --git a/xpcom/ds/nsAutoStringImpl.h b/xpcom/ds/nsAutoStringImpl.h deleted file mode 100644 index 7dcae0e4c6ea..000000000000 --- a/xpcom/ds/nsAutoStringImpl.h +++ /dev/null @@ -1,88 +0,0 @@ -/************************************************************************************* - * - * DEVELOPMENT NOTES: - * - * 1. See nsStringImpl.h - * - * 2. I've used the uncommon template style of including a base type. - * The purpose is to allow callers to vary the underlying size of - * the buffer as a local optimization. It may turn out to be a - * bad idea, but for now I'm more focused on getting a workable - * autostring. Please be patient. - * - * FILE NOTES: - * - * 02.29.2000: Original files (rickg) - * 03.02.2000: Flesh out the interface to be compatible with old library (rickg) - * - *************************************************************************************/ - -#ifndef NS_AUTOSTRING_ -#define NS_AUTOSTRING_ - -#include "nsStringImpl.h" - -/******************************************************************** - * - * This template provides the basic implementation for nsAutoString, - * nsAutoCString and so on. Note the typedefs at the bottom of this file. - * - ********************************************************************/ - -template -class nsAutoStringImpl : public nsStringImpl { -public: - - //default constructor - nsAutoStringImpl() : nsStringImpl () { - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); - mStringValue.mCapacity=DefaultBufferSize; - mStringValue.mBuffer=mInternalBuffer; - } - - //copy constructor - nsAutoStringImpl(const nsAutoStringImpl& aCopy,PRInt32 aLength=-1) : nsStringImpl() { - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); - mStringValue.mCapacity=DefaultBufferSize; - mStringValue.mBuffer=mInternalBuffer; - Assign(aCopy); - } - - //call this version for all ABT versions of readable strings - nsAutoStringImpl(const nsReadableString &aCopy,PRInt32 aLength=-1) : nsStringImpl () { - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); - mStringValue.mCapacity=DefaultBufferSize; - mStringValue.mBuffer=mInternalBuffer; - Assign(aCopy); - } - - //call this version for ptrs to char-strings that match the internal char type - nsAutoStringImpl(const CharType* theString, PRInt32 aLength=-1) : nsStringImpl () { - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); - mStringValue.mCapacity=DefaultBufferSize; - mStringValue.mBuffer=mInternalBuffer; - Assign(theString,aLength); - } - - virtual ~nsAutoStringImpl() { } - - nsAutoStringImpl& operator=(const nsAutoStringImpl& aCopy) { - if(aCopy.mStringValue.mBuffer!=mStringValue.mBuffer) { - Assign(aCopy); - } - return *this; - } - - nsAutoStringImpl& operator=(const CharType* aString) { - if(aCopy.mStringValue.mBuffer!=aString) { - Assign(aCopy); - } - return *this; - } - -protected: - CharType mInternalBuffer[DefaultBufferSize]; -}; - - -#endif diff --git a/xpcom/ds/nsBufferManager.h b/xpcom/ds/nsBufferManager.h deleted file mode 100644 index 7f42c2c28d95..000000000000 --- a/xpcom/ds/nsBufferManager.h +++ /dev/null @@ -1,1555 +0,0 @@ -/************************************************************************************* - * - * MODULES NOTES: - * - * 1. See nsStringImpl.h - * - * Contributor(s): - * Rick Gessner - * - * History: - * - * 02.29.2000: Original files (rickg) - * 03.02.2000: Flesh out the interface to be compatible with old library (rickg) - * 03.03.2000: Finished mapping original nsStr functionality to template form (rickg) - * 03.10.2000: Fixed off-by-1 error in StripChar() (rickg) - * 03.20.2000: Ran regressions by comparing operations against original nsString (rickg) - * - * To Do: - * - * 1. Use shared buffer for empty strings - * 2. Test refcounting - * 3. Implement copy semantics between autostring and nsCSubsumeString to ensure - * that actual character copying occurs if necessary. - * - *************************************************************************************/ - -#ifndef NS_BUFFERMANAGER_ -#define NS_BUFFERMANAGER_ - - -#include "nsStringValue.h" - - -#define NS_MEMORY_ERROR 1000 - - -// uncomment the following line to caught nsString char* casting problem -//#define DEBUG_ILLEGAL_CAST_UP -//#define DEBUG_ILLEGAL_CAST_DOWN - -#if defined(DEBUG_ILLEGAL_CAST_UP) || defined(DEBUG_ILLEGAL_CAST_DOWN) - -static PRBool track_illegal = PR_TRUE; -static PRBool track_latin1 = PR_TRUE; - -#ifdef XP_UNIX -#include "nsTraceRefcnt.h" -class CTraceFile { -public: - CTraceFile() { - mFile = fopen("nsStringTrace.txt" , "a+"); - } - ~CTraceFile() { - fflush(mFile); - fclose(mFile); - } - void ReportCastUp(const char* data, const char* msg) - { - if(mFile) { - fprintf(mFile, "ERRORTEXT= %s\n", msg); - fprintf(mFile, "BEGINDATA\n"); - const char* s=data; - while(*s) { - if(*s & 0x80) { - fprintf(mFile, "[%2X]", (char)*s); - } else { - fprintf(mFile, "%c", *s); - } - s++; - } - fprintf(mFile, "\n"); - fprintf(mFile, "ENDDATA\n"); - fprintf(mFile, "BEGINSTACK\n"); - nsTraceRefcnt::WalkTheStack(mFile); - fprintf(mFile, "\n"); - fprintf(mFile, "ENDSTACK\n"); - fflush(mFile); - } - } - void ReportCastDown(const PRUnichar* data, const char* msg) - { - if(mFile) { - fprintf(mFile, "ERRORTEXT=%s\n", msg); - fprintf(mFile, "BEGINDATA\n"); - const PRUnichar* s=data; - while(*s) { - if(*s & 0xFF80) { - fprintf(mFile, "\\u%X", *s); - } else { - fprintf(mFile, "%c", *s); - } - s++; - } - fprintf(mFile, "\n"); - fprintf(mFile, "ENDDATA\n"); - fprintf(mFile, "BEGINSTACK\n"); - nsTraceRefcnt::WalkTheStack(mFile); - fprintf(mFile, "\n"); - fprintf(mFile, "ENDSTACK\n"); - fflush(mFile); - } - } -private: - FILE* mFile; -}; -static CTraceFile gTrace; -#define TRACE_ILLEGAL_CAST_UP(c, s, m) if(!(c)) gTrace.ReportCastUp(s,m); -#define TRACE_ILLEGAL_CAST_DOWN(c, s, m) if(!(c)) gTrace.ReportCastDown(s,m); - -#else // XP_UNIX - -#define TRACE_ILLEGAL_CAST_UP(c, s, m) NS_ASSERTION((c), (m)) -#define TRACE_ILLEGAL_CAST_DOWN(c, s, m) NS_ASSERTION((c), (m)) - -#endif //XP_UNIX - -#endif - - -/************************************************************************************* - * - * These methods offer the low level buffer manipulation routines used throughout - * the string hierarchy. T1 and T2 will be types of stringvalues. (rickg) - * - *************************************************************************************/ - - -template -inline void SVAddNullTerminator( nsStringValueImpl& aDest) { - if(aDest.mBuffer) { - aDest.mBuffer[aDest.mLength]=0; - } -} - -template -inline CharType ToLower(CharType aChar) { - if((aChar>='A') && (aChar<='Z')) - aChar+=32; - return aChar; -} - -static const PRUnichar gCommonEmptyBuffer[1] = {0}; -static nsresult gStringAcquiredMemory = NS_OK; - - - -template -inline nsresult SVAlloc( nsStringValueImpl& aDest, PRUint32 aCount) { - - nsresult result=NS_OK; - - - //we're given the acount value in charunits; now scale up to next multiple. - aDest.mCapacity=kDefaultStringSize; - while(aDest.mCapacity -inline nsresult SVFree( nsStringValueImpl& aDest){ - aDest.mRefCount--; - - if((aDest.mBuffer) && (!aDest.mRefCount)){ - delete [] aDest.mBuffer; // nsMemory::Free(aDest.mBuffer); - aDest.mBuffer=0; - } - - return NS_OK; -} - - -/** - * Realloc memory from given stringvalueimpl - * - * @update rickg 03.02.2000 - * @return memory error (usually returns NS_OK) - */ -template -inline nsresult SVRealloc(nsStringValueImpl&aDest,PRUint32 aCount){ - - nsStringValueImpl temp(aDest); - nsresult result=SVAlloc(temp,aCount); - if(NS_SUCCEEDED(result)) { - - if(aDest.mBuffer) { - if(0255) { - NS_ASSERTION( (aSource[i] < 256), "data in U+0100-U+FFFF will be lost"); - if(track_illegal) { - if(track_latin1) { - if(aSource[i] & 0xFF80) - illegal = PR_TRUE; - } else { - if(aSource[i] & 0xFF00) - illegal = PR_TRUE; - } // track_latin1 - } // track_illegal - break; - } - - } -#endif - - while(aSource -inline nsresult SVDelete( nsStringValueImpl& aDest,PRUint32 anOffset,PRInt32 aCount=-1){ - nsresult result=NS_OK; - - PRInt32 theLength =(aCount<0) ? aDest.mLength : aCount; - - CharType* root_cp = aDest.mBuffer; - CharType* null_cp = root_cp+aDest.mLength; - CharType* offset_cp = root_cp+anOffset; //dst1 - - if(offset_cp -inline void SVTruncate( nsStringValueImpl& aDest,PRUint32 anOffset=0) { - if(anOffset -inline nsresult SVAppend( nsStringValueImpl& aDest,const nsStringValueImpl& aSource,PRInt32 aCount=-1,PRUint32 aSrcOffset=0){ - - nsresult result=NS_OK; - - if(aSrcOffset aDest.mCapacity) { - result=SVRealloc(aDest,aDest.mLength+theLength); - } - - if(NS_SUCCEEDED(result)) { - - //now append new chars, starting at offset - - CharType1 *to_cp = aDest.mBuffer+aDest.mLength; - const CharType2 *from_cp = aSource.mBuffer+aSrcOffset; - - SVCopyBuffer_(to_cp,from_cp,theLength); - - aDest.mLength+=theLength; - aDest.mBuffer[aDest.mLength]=0; - } - - } - } - return result; -} - -/** - * This method is used to append content to the given stringvalue from an nsAReadableString - * - * @update rickg 03.01.2000 - * @param aDest is the stringvalue to be modified - * @param aSource is the readablestring to be copied from - * @param anOffset tells us where in source to start copying - * @param aCount tells us the (max) # of chars to copy - */ -template -inline nsresult SVAppendReadable( nsStringValueImpl& aDest,const nsAReadableString& aSource,PRInt32 aCount,PRUint32 anSrcOffset){ - nsresult result=NS_OK; - /* - //I expect a pattern similar to this that could work on any readable string - - nsAReadableStringIterator theFirst=aSource.First(); - nsAReadableStringIterator theLast=aSource.Last(); - CharType1 *theDest=aDest.mBuffer; - while(theFirst -inline nsresult SVAssign(nsStringValueImpl& aDest,const nsStringValueImpl& aSource,PRInt32 aCount=-1,PRUint32 aSrcOffset=0) { - nsresult result=NS_OK; - if((void*)aDest.mBuffer!=(void*)aSource.mBuffer){ - SVTruncate(aDest,0); - SVAppend(aDest,aSource,aCount,aSrcOffset); - } - return result; -} - - - -/** - * These methods are used to insert content from source string to the dest stringvalue - * - * @update rickg 03.01.2000 - * @param aDest is the stringvalue to be modified - * @param aDestOffset tells us where in dest to start insertion - * @param aSource is the buffer to be copied from - * @param aSrcOffset tells us where in source to start copying - * @param aCount tells us the (max) # of chars to insert - */ -template -inline nsresult SVInsert( nsStringValueImpl& aDest,PRUint32 aDestOffset,const nsStringValueImpl& aSource,PRInt32 aCount=-1,PRUint32 aSrcOffset=0) { - nsresult result=NS_OK; - - //there are a few cases for insert: - // 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 aDest.mCapacity) { - - nsStringValueImpl theTempStr; - result=SVAlloc(theTempStr,aDest.mLength+theLength); - - if(NS_SUCCEEDED(result)) { - - CharType1 *to_cp=theTempStr.mBuffer; - - memcpy(to_cp,aDest.mBuffer,aDestOffset*sizeof(CharType1)); //copy front of existing string... - - to_cp+=aDestOffset; - SVCopyBuffer_(to_cp,from_src,theLength); //now insert the new data... - - PRUint32 theRemains=aDest.mLength-aDestOffset; - if(theRemains) { - CharType1 *from_dst=to_cp; - to_cp+=theLength; - memcpy(to_cp,from_dst,theRemains*sizeof(CharType1)); - } - - SVFree(aDest); - aDest=theTempStr; - theTempStr.mBuffer=0; //make sure to null this out so that you don't lose the buffer you just stole... - } - - } - - else { - //if you're here, it's because we have enough room to insert the new chars into the buffer - //that we already possess. - - CharType1* root_cp = aDest.mBuffer; - CharType1* end_cp = root_cp+aDest.mLength; - CharType1* offset_cp= root_cp+aDestOffset; - CharType1* max_cp = offset_cp+aCount; - - memmove(max_cp,offset_cp,sizeof(CharType1)*(end_cp-offset_cp)); - - SVCopyBuffer_(offset_cp,from_src,theLength); - - //finally, make sure to update the string length... - aDest.mLength+=theLength; - aDest.mBuffer[aDest.mLength]=0; - } - }//if - //else nothing to do! - } - else { - SVAppend(aDest,aSource,aCount,0); - } - } - else { - SVAppend(aDest,aSource,aCount,0); - } - } - return result; -} - - -/** - * This method compares characters strings of two types, and ignores case - * - * @update rickg 03.01.2000 - * @param aLeft - * @param anEnd - * @param aTarget - * @return aDestaSource=1 - */ -template -inline PRInt32 SVCompareCase_(const CharType1* aLeft,const CharType1* anEnd,const CharType2* aTarget){ - - while(aLeftaSource=1 - */ -inline PRInt32 SVCompare_(const char* aLeft,const char* anEnd,const char* aTarget){ - size_t theCount=anEnd-aLeft; - return memcmp(aLeft,aTarget,theCount); -} - -/** - * This method compares characters strings of two types (case sensitive) - * - * @update rickg 03.01.2000 - * @param aLeft - * @param anEnd - * @param aTarget - * @return aDestaSource=1 - */ -template -inline PRInt32 SVCompare_(const CharType1* aLeft,const CharType1* anEnd,const CharType2* aTarget){ - - while(aLeftaSource=1 - */ -template -inline PRInt32 SVCompare(const nsStringValueImpl& aDest,const nsStringValueImpl& aSource,PRBool aIgnoreCase, PRUint32 aCount){ - - PRInt32 result=0; - - if((void*)aDest.mBuffer!=(void*)aSource.mBuffer) { - if(aCount) { - PRUint32 minlen=(aSource.mLength -inline PRInt32 SVCompareChars(const nsStringValueImpl& aLHS,const nsStringValueImpl& aRHS,PRBool aIgnoreCase,PRInt32 aCount) { - - PRInt32 result=0; - - if(aLHS.mBuffer!=aRHS.mBuffer) { - if(!aIgnoreCase) { - PRInt32 aMax = (aLHS.mLength -inline PRInt32 SVFindOrig(const nsStringValueImpl& aDest,const nsStringValueImpl& aTarget,PRBool aIgnoreCase,PRInt32 aCount=-1,PRUint32 aSrcOffset=0) { - - PRUint32 minlen=(aTarget.mLength -inline PRInt32 SVFind(const nsStringValueImpl& aDest,const nsStringValueImpl& aTarget,PRBool aIgnoreCase,PRInt32 aCount=-1,PRUint32 aSrcOffset=0) { - - PRUint32 minlen=(aTarget.mLength -PRInt32 SVFindChar(const nsStringValueImpl& aDest,PRUnichar aChar,PRBool aIgnoreCase,PRInt32 aCount=-1,PRUint32 aSrcOffset=0) { - - if(aSrcOffset<0) - aSrcOffset=0; - - if(aCount<0) - aCount = (PRInt32)aDest.mLength; - - size_t theCharSize=sizeof(CharType); - if((2==theCharSize) || (aChar<256)) { - if((0 -inline PRInt32 SVFindCharInSet(const nsStringValueImpl& aDest,const nsStringValueImpl& aSet,PRBool aIgnoreCase,PRInt32 aCount,PRInt32 anOffset) { - - if(anOffset<0) - anOffset=0; - - if(aCount<0) - aCount = (PRInt32)aDest.mLength; - - if((0 -inline PRInt32 SVRFind(const nsStringValueImpl& aDest,const nsStringValueImpl& aTarget,PRBool aIgnoreCase,PRInt32 aCount,PRInt32 aSrcOffset) { - - if(aSrcOffset<0) - aSrcOffset=(PRInt32)aDest.mLength-1; - - if(aCount<0) - aCount = aSrcOffset; - - size_t theCharSize=sizeof(CharType1); - if((0 -PRInt32 SVRFindChar(const nsStringValueImpl& aDest,PRUnichar aChar,PRBool aIgnoreCase,PRInt32 aCount,PRInt32 aSrcOffset) { - - if(aSrcOffset<0) - aSrcOffset=(PRInt32)aDest.mLength-1; - - if(aCount<0) - aCount = aSrcOffset; - - size_t theCharSize=sizeof(CharType); - if((2==theCharSize) || (aChar<256)) { - if((0 -inline PRInt32 SVRFindCharInSet(const nsStringValueImpl& aDest,const nsStringValueImpl& aSet,PRBool aIgnoreCase,PRInt32 aCount,PRInt32 aSrcOffset) { - - if(aSrcOffset<0) - aSrcOffset=(PRInt32)aDest.mLength-1; - - if(aCount<0) - aCount = aSrcOffset; - - if((0 -nsresult SVTrim(nsStringValueImpl& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){ - - nsresult result=NS_OK; - - if(0 theSet((char*)aSet); - - - if(aEliminateTrailing) { - - while(root_cp -nsresult SVStripCharsInSet(nsStringValueImpl& aDest,const char* aSet,PRInt32 aCount,PRInt32 anOffset) { - - if((0 theSet((char*)aSet); - - while(left_cp -nsresult SVStripChar( nsStringValueImpl& aDest, CharType aChar,PRInt32 aCount,PRInt32 anOffset) { - - nsresult result=NS_OK; - - if(anOffset<(PRInt32)aDest.mLength){ - - CharType *root_cp=aDest.mBuffer; - CharType *theCP=root_cp+anOffset; - CharType *end_cp=root_cp+aDest.mLength; - CharType *theWriteCP=theCP; - - while(theCP -nsresult SVReplace( nsStringValueImpl &aDest, - const nsStringValueImpl &aTarget, - const nsStringValueImpl &aNewValue, - PRInt32 aRepCount, - PRUint32 anOffset) { - - nsresult result=NS_OK; - - if((aTarget.mLength) && (aNewValue.mLength)) { - - nsStringValueImpl theTempString; - PRUint32 thePrevOffset=0; - PRInt32 thePos=SVFind(aDest,aTarget,PR_FALSE,aDest.mLength,thePrevOffset); - - while(kNotFound -nsresult SVReplaceCharsInSet(nsStringValueImpl& aDest,const char* aSet,PRUnichar aNewChar,PRInt32 aCount,PRUint32 anOffset) { - - if((0 theSet((char*)aSet); - while(offset_cp -nsresult SVCompressSet(nsStringValueImpl& aDest,const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE){ - - nsresult result=NS_OK; - - if(0 theSet((char*)aSet); - - //this code converts /n, /t, /r into normal space ' '; - //it also compresses runs of whitespace down to a single char... - PRUint32 aSetLen=strlen(aSet); - if(aSetLen) { - - while (root_cp < end_cp) { - CharType theChar = *root_cp++; - - *to_cp++=theChar; //always copy this char - if((theChar<256) && (kNotFound -void SVToLowerCase(nsStringValueImpl &aString) { - - CharType *theCP=aString.mBuffer; - CharType *end_cp=theCP+aString.mLength; - - while(theCP= 'A') && (theChar <= 'Z')) { - *theCP = 'a' + (theChar - 'A'); - } - theCP++; - } - -} - -template -void SVToUpperCase(nsStringValueImpl &aString) { - CharType *theCP=aString.mBuffer; - CharType *end_cp=theCP+aString.mLength; - - while(theCP= 'a') && (theChar<= 'z')) { - *theCP= 'A' + (theChar - 'a'); - } - theCP++; - } - -} - -template -PRInt32 SVCountChar(const nsStringValueImpl &aString,PRUnichar aChar) { - PRInt32 result=0; - - const CharType* cp=aString.mBuffer; - const CharType* end_cp=cp+aString.mLength; - - while(cp -void SVDebugDump(const nsStringValueImpl &aString) { - - - CharType* cp=aString.mBuffer; - CharType* end_cp=cp+aString.mLength; - - char theBuffer[256]={0}; - char* outp=theBuffer; - char* outendp=&theBuffer[255]; - - while(cp -PRInt32 SVToInteger(const nsStringValueImpl &aString,PRInt32* anErrorCode,PRUint32 aRadix=kAutoDetect) { - - CharType* cp=aString.mBuffer; - PRInt32 theRadix = (kAutoDetect==aRadix) ? 10 : aRadix; - PRInt32 result=0; - PRBool negate=PR_FALSE; - PRUnichar theChar=0; - - *anErrorCode=NS_ERROR_ILLEGAL_VALUE; - - if(cp) { - - //begin by skipping over leading chars that shouldn't be part of the number... - - CharType* endcp=cp+aString.mLength; - PRBool done=PR_FALSE; - - while((cp='A') && (theChar<='F')) { - if(10==theRadix) { - if(kAutoDetect==aRadix){ - theRadix=16; - cp=first; //backup - result=0; - } - else { - *anErrorCode=NS_ERROR_ILLEGAL_VALUE; - result=0; - break; - } - } - else { - result = (theRadix * result) + ((theChar-'A')+10); - } - } - else if((theChar>='a') && (theChar<='f')) { - if(10==theRadix) { - if(kAutoDetect==aRadix){ - theRadix=16; - cp=first; //backup - result=0; - } - else { - *anErrorCode=NS_ERROR_ILLEGAL_VALUE; - result=0; - break; - } - } - else { - result = (theRadix * result) + ((theChar-'a')+10); - } - } - else if(('X'==theChar) || ('x'==theChar) || ('#'==theChar) || ('+'==theChar)) { - continue; - } - else { - //we've encountered a char that's not a legal number or sign - break; - } - } //while - if(negate) - result=-result; - } - return result; -} - -#endif - - diff --git a/xpcom/ds/nsImmutableString.h b/xpcom/ds/nsImmutableString.h deleted file mode 100644 index 53693166ef81..000000000000 --- a/xpcom/ds/nsImmutableString.h +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************************** - * - * MODULES NOTES: - * - * 1. See nsStringImpl.h - * 2. I've included an mBuffer in this class data member as a fast-up implementation. - * I'll get rid of this shortly, reducing the members to only the mLength member. (rickg) - * - * FILE NOTES: - * - * 02.29.2000: Original files (rickg) - * 03.02.2000: Flesh out the interface to be compatible with old library (rickg) - * - ********************************************************************************************/ - - -#ifndef NS_IMMUTABLESTRING_ -#define NS_IMMUTABLESTRING_ - -#include "nsStringImpl.h" - - -/** - * Immutable strings are intesting because their buffers get allocated - * at the same time as the actual string is allocated. (rickg) - * - **/ -template -class nsImmutableImpl : public nsReadableString { -public: - - //construct from ptr to char* of internal type - static nsImmutableImpl* Create(const CharType1* aBuffer) { - size_t theBufSize=(aBuffer) ? stringlen(aBuffer) : 0; - nsImmutableImpl *result= new(theBufSize) nsImmutableImpl(aBuffer,theBufSize); - return result; - } - - //copy construct - static nsImmutableImpl* Create(const nsImmutableImpl& aCopy) { - return 0; - } - - //construct for all other ABT versions of readable strings - static nsImmutableImpl* Create(const nsReadableString& aCopy) { - return 0; - } - - ~nsImmutableImpl() { - } - - //****************************************** - // From the stringbasics interface... - //****************************************** - - virtual void* GetBuffer() {return mValue.mBuffer;} - virtual PRUint32 Length() {return mValue.mLength;} - virtual size_t GetCharSize() {return sizeof(CharType1);} - - //****************************************** - // Here are the accessor methods... - //****************************************** - - virtual nsReadableStringIterator* First() {return new nsReadableStringIterator(); } - virtual nsReadableStringIterator* Last() {return new nsReadableStringIterator(); } - - virtual PRUnichar operator[](PRUint32 aOffset) { - return 0; //(*mBuffer)[aOffset]; - } - - /*********************************** - These come from stringsearcher - ***********************************/ - - virtual PRInt32 Find(const char* aTarget) { - return -1; - } - - virtual PRInt32 FindChar(PRUnichar aChar) { - return -1; - } - - //overloaded in order to free the object and the - //extra bytes for data that we allocated in new() - void operator delete(void *p, size_t aSize) { - if(p) { - nsImmutableImpl* theImmutable=static_cast(p); - size_t theBufLen=theImmutable->mValue.mLength+1; - ::delete [] p; - } - } - -protected: - - /** - * Overloaded in order to get extra bytes for data. - * This needs to use our standard nsMemory (rickg) - * - **/ - void* operator new(size_t aSize,size_t additionalBytes) { - CharType1* theBuf = ::new CharType1[aSize+additionalBytes+1]; - memset(theBuf,0xff,aSize+additionalBytes+1); - return theBuf; - } - -private: - - nsImmutableImpl() { - } - - //construct for ptr to internal char* - nsImmutableImpl(const CharType1* aBuffer,size_t aSize) { - mValue.mLength=aSize; - mValue.mBuffer=(CharType1*)this+sizeof(nsImmutableString); - strncopy(mValue.mBuffer,aBuffer,mValue.mLength+1); - } - - - //copy construct - nsImmutableImpl(const nsImmutableImpl& aString) { - } - - //construct from reference to another (generic) readableString - //We can't assume very much about the readableString implementation, - //and should rely upon generics (like iterators) to do the work - nsImmutableImpl(const nsReadableString& aString) { - } - - struct nsImmutableStringValue { - PRUint32 mLength; //data should follow - CharType1* mBuffer; //points to first char in data section of this object; this will soon go away - } - mValue; -}; - - - /*********************************** - Define the concrete immutables... - ***********************************/ -typedef nsImmutableImpl nsImmutableString; -typedef nsImmutableImpl nsImmutableCString; - - - -#endif diff --git a/xpcom/ds/nsString2x.cpp b/xpcom/ds/nsString2x.cpp deleted file mode 100644 index a49a21659ba7..000000000000 --- a/xpcom/ds/nsString2x.cpp +++ /dev/null @@ -1,1251 +0,0 @@ - -#include "nsString.h" -#include "nsBufferManager.h" -#include -#include -#include "nsMemory.h" - -static const char* kNullPointerError = "Unexpected null pointer"; -static const char* kWhitespace="\b\t\r\n "; - - //****************************************** - // Ctor's - //****************************************** - -void Subsume(nsStringValueImpl &aDest,nsStringValueImpl &aSource){ - if(aSource.mBuffer && aSource.mLength) { -#if 0 - if(aSource.mOwnsBuffer){ - nsStr::Destroy(aDest); - aDest.mStr=aSource.mStr; - aDest.mLength=aSource.mLength; - aDest.mCapacity=aSource.mCapacity; - aDest.mOwnsBuffer=aSource.mOwnsBuffer; - aSource.mOwnsBuffer=PR_FALSE; - aSource.mStr=0; - } - else{ - nsStr::StrAssign(aDest,aSource,0,aSource.mLength); - } -#endif - } - else SVTruncate(aDest,0); -} - - -nsString::nsString() : mStringValue() { -} - - //call this version for nsString,nsString and the autostrings -nsString::nsString(const nsString& aString,PRInt32 aLength) : mStringValue() { - SVAppend(mStringValue,aString.mStringValue,aLength,0); -} - - //call this version with nsCString -nsString::nsString(const nsCString &aString,PRInt32 aLength) : mStringValue() { - SVAppend(mStringValue,aString.mStringValue,aLength,0); -} - - //call this version for a single char of type char... -nsString::nsString(nsSubsumeStr &aSubsumeString) : mStringValue() { - mStringValue=aSubsumeString.mStringValue; - memset(&aSubsumeString.mStringValue,0,sizeof(mStringValue)); -} - - //call this version for char*'s.... -nsString::nsString(const PRUnichar* aString,PRInt32 aLength) : mStringValue() { - Append(aString,aLength,0); -} - - //call this version for a single char of type char... -nsString::nsString(const char aChar) : mStringValue() { - Append(aChar); -} - - - //call this version for PRUnichar*'s.... -nsString::nsString(const char* aString,PRInt32 aLength) : mStringValue() { - nsStringValueImpl theString(NS_CONST_CAST(char*,aString),aLength); - SVAppend(mStringValue,theString,theString.mLength,0); -} - - //call this version for all other ABT versions of readable strings -nsString::nsString(const nsAReadableString &aString) : mStringValue() { - Assign(aString); -} - -nsString::~nsString() { - SVFree(mStringValue); -} - -void nsString::Reinitialize(PRUnichar* aBuffer,PRUint32 aCapacity,PRInt32 aLength) { - mStringValue.mBuffer=aBuffer; - mStringValue.mCapacity=aCapacity; - mStringValue.mLength=aLength; - mStringValue.mRefCount=1; -} - - //****************************************** - // Assigment operators - //****************************************** - -nsString& nsString::operator=(const nsString& aString) { - if(aString.mStringValue.mBuffer!=mStringValue.mBuffer) { - Assign(aString); - } - return *this; -} - -nsString& nsString::operator=(const nsCString &aString) { - Assign(aString); - return *this; -} - -nsString& nsString::operator=(const nsSubsumeStr &aSubsumeString) { - mStringValue=aSubsumeString.mStringValue; - memset((void*)&aSubsumeString.mStringValue,0,sizeof(mStringValue)); - return *this; -} - - -nsString& nsString::operator=(const PRUnichar *aString) { - if(mStringValue.mBuffer!=aString) { - nsStringValueImpl theStringValue(NS_CONST_CAST(PRUnichar*,aString)); - Assign(aString); - } - return *this; -} - -nsString& nsString::operator=(const char *aString) { - nsStringValueImpl theStringValue(NS_CONST_CAST(char*,aString)); - SVAssign(mStringValue,theStringValue,theStringValue.mLength,0); - return *this; -} - -nsString& nsString::operator=(const char aChar) { - Assign(aChar); - return *this; -} - -nsString& nsString::operator=(const PRUnichar aChar) { - Assign(aChar); - return *this; -} - - //****************************************** - // Here are the accessor methods... - //****************************************** - - -nsresult nsString::SetCapacity(PRUint32 aCapacity) { - if(aCapacity>mStringValue.mCapacity) { - SVRealloc(mStringValue,aCapacity); - } - return NS_OK; -} - - -PRBool nsString::SetCharAt(PRUnichar aChar,PRUint32 anIndex) { - PRBool result=PR_FALSE; - if(anIndex theStringValue(NS_CONST_CAST(char*,aString),aLength); - result=SVAppend(mStringValue,theStringValue,aLength,aSrcOffset); - } - return result; -} - - //append from alternative type string pointer -nsresult nsString::Append(const char aChar) { - - if(mStringValue.mLength==mStringValue.mCapacity) { - SVRealloc(mStringValue,mStringValue.mCapacity+5); - } - - if(mStringValue.mLength theStringValue(NS_CONST_CAST(PRUnichar*,aString),aLength); - result=SVAppend (mStringValue,theStringValue,aLength,aSrcOffset); - } - return result; -} - - //append from an nsCString -nsresult nsString::Append(const nsCString &aString,PRInt32 aLength,PRUint32 aSrcOffset) { - aLength = (aLength<0) ? aString.mStringValue.mLength : (aLength<(PRInt32)aString.mStringValue.mLength) ? aLength: aString.mStringValue.mLength; - return SVAppend (mStringValue,aString.mStringValue,aLength,aSrcOffset); -} - - //append from an nsAReadableString (the ABT) -nsresult nsString::Append(const nsAReadableString &aString,PRInt32 aLength,PRUint32 aSrcOffset) { - aLength = (aLength<0) ? aString.Length() : MinInt(aLength,aString.Length()); - return SVAppendReadable(mStringValue,aString,aLength,aSrcOffset); -} - - //append an integer -nsresult nsString::Append(PRInt32 anInteger,PRInt32 aRadix) { - nsresult result=NS_OK; - - PRUint32 theInt=(PRUint32)anInteger; - - char buf[]={'0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; - - PRInt32 radices[] = {1000000000,268435456}; - PRInt32 mask1=radices[16==aRadix]; - - PRInt32 charpos=0; - if(anInteger<0) { - theInt*=-1; - if(10==aRadix) { - buf[charpos++]='-'; - } - else theInt=(int)~(theInt-1); - } - - PRBool isfirst=PR_TRUE; - while(mask1>=1) { - PRInt32 theDiv=theInt/mask1; - if((theDiv) || (!isfirst)) { - buf[charpos++]="0123456789abcdef"[theDiv]; - isfirst=PR_FALSE; - } - theInt-=theDiv*mask1; - mask1/=aRadix; - } - return Append(buf); - - return result; -} - - //Append a float -nsresult nsString::Append(float aFloat) { - nsresult result=NS_OK; - char buf[40]; - sprintf(buf,"%g",aFloat); - - nsStringValueImpl theStringValue(buf); - Append(theStringValue); - - return result; -} - - - //*************************************** - // Here come a few deletion methods... - //*************************************** - -nsresult nsString::Cut(PRUint32 anOffset,PRInt32 aCount) { - return (0 theStringValue(NS_CONST_CAST(char*,aString),aLength); - - if(0 theStringValue(NS_CONST_CAST(PRUnichar*,aString),aLength); - - if(0 theStringValue(theBuffer,1); - - return SVInsert(mStringValue,anOffset,theStringValue,1,0); -} - - - //******************************************* - // Here come inplace replacement methods... - //******************************************* - -/** - * swaps occurence of 1 char for another - * - * @return this - */ -nsresult nsString::ReplaceChar(char anOldChar,char aNewChar){ - PRUnichar *root_cp=mStringValue.mBuffer; - PRUnichar *null_cp=root_cp+mStringValue.mLength; - - while(root_cp theTarget(NS_CONST_CAST(char*,aTarget)); - const nsStringValueImpl theNewValue(NS_CONST_CAST(char*,aNewValue)); - - return SVReplace(mStringValue,theTarget,theNewValue,mStringValue.mLength,0); -} - - //******************************************* - // Here come the stripchar methods... - //******************************************* - -/** - * This method is used to remove all occurances of the - * given character from this string. - * - * @update rickg 03.01.2000 - * @param aChar -- char to be stripped - * @param anOffset -- where in this string to start stripping chars - * @return *this - */ -nsresult nsString::StripChar(PRUnichar aChar,PRUint32 anOffset){ - return SVStripChar(mStringValue,aChar,mStringValue.mLength,anOffset); -} - -/** - * This method is used to remove all occurances of the - * given character from this string. - * - * @update rickg 03.01.2000 - * @param aChar -- char to be stripped - * @param anOffset -- where in this string to start stripping chars - * @return *this - */ -nsresult nsString::StripChar(PRInt32 anInt,PRUint32 anOffset){ - return SVStripChar(mStringValue,(PRUnichar)anInt,mStringValue.mLength,anOffset); -} - -/** - * This method is used to remove all occurances of the - * characters found in aSet from this string. - * - * @update rickg 03.01.2000 - * @param aSet -- characters to be cut from this - * @return *this - */ -nsresult nsString::StripChars(const char* aSet,PRInt32 aLength){ - nsStringValueImpl theSet(NS_CONST_CAST(char*,aSet),aLength); - return SVStripCharsInSet(mStringValue,aSet,mStringValue.mLength,0); -} - -/** - * This method strips whitespace throughout the string - * - * @update rickg 03.01.2000 - * @return this - */ -nsresult nsString::StripWhitespace() { - static const char* kWhitespace="\b\t\r\n "; - return StripChars(kWhitespace); -} - - //************************************************** - // Here are some methods that extract substrings... - //************************************************** - -nsresult nsString::Left(nsString& aCopy,PRInt32 aCount) const { - aCount = (aCount<0) ? mStringValue.mLength : (aCount<(PRInt32)mStringValue.mLength) ? aCount : mStringValue.mLength; - return aCopy.Assign(*this,aCount,0); -} - -nsresult nsString::Mid(nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) const { - aCount = (aCount<0) ? mStringValue.mLength : (aCount<(PRInt32)mStringValue.mLength) ? aCount : mStringValue.mLength; - return aCopy.Assign(*this,aCount,anOffset); -} - -nsresult nsString::Right(nsString& aCopy,PRInt32 aCount) const { - PRUint32 theLen=mStringValue.mLength-aCount; - PRInt32 offset=(theLen<0) ? 0 : theLen; - return Mid(aCopy,offset,aCount); -} - - //****************************************** - // Concatenation operators - //****************************************** - -nsSubsumeStr nsString::operator+(const nsString &aString) { - nsString theString(*this); - SVAppend(theString.mStringValue,aString.mStringValue); - return nsSubsumeStr(theString); -} - -nsSubsumeStr nsString::operator+(const PRUnichar* aString) { - nsString theTempString(*this); - nsStringValueImpl theTempStrValue(NS_CONST_CAST(PRUnichar*,aString)); - SVAppend(theTempString.mStringValue,theTempStrValue); - return nsSubsumeStr(theTempString); -} - -nsSubsumeStr nsString::operator+(const char* aString) { - nsString theTempString(*this); - nsStringValueImpl theTempStrValue(NS_CONST_CAST(char*,aString)); - SVAppend(theTempString.mStringValue,theTempStrValue); - return nsSubsumeStr(theTempString); -} - -nsSubsumeStr nsString::operator+(PRUnichar aChar) { - nsString theTempString(*this); - theTempString.Append(aChar); - return nsSubsumeStr(theTempString); -} - //******************************************* - // Here come the operator+=() methods... - //******************************************* - -nsString& nsString::operator+=(const nsString& aString){ - SVAppend(mStringValue,aString.mStringValue,aString.mStringValue.mLength,0); - return *this; -} - -nsString& nsString::operator+=(const char* aString) { - Append(aString); - return *this; -} - -nsString& nsString::operator+=(const PRUnichar* aString) { - Append(aString); - return *this; -} - -nsString& nsString::operator+=(const char aChar) { - char theBuffer[]={aChar,0}; - Append(theBuffer,1); - return *this; -} - -nsString& nsString::operator+=(const PRUnichar aChar) { - PRUnichar theBuffer[]={aChar,0}; - Append(theBuffer,1); - return *this; -} - -nsString& nsString::operator+=(const int anInt){ - Append(anInt,10); - return *this; -} - -void nsString::ToLowerCase() { - SVToLowerCase(mStringValue); -} - -void nsString::ToLowerCase(nsString &aString) const { - aString=*this; - aString.ToLowerCase(); -} - -void nsString::ToUpperCase() { - SVToUpperCase(mStringValue); -} - -void nsString::ToUpperCase(nsString &aString) const { - aString=*this; - aString.ToUpperCase(); -} - - -PRInt32 nsString::Compare(const nsString &aString,PRBool aIgnoreCase,PRInt32 aCount) const { - return SVCompareChars(mStringValue,aString.mStringValue,aIgnoreCase,aCount); -} - -PRInt32 nsString::Compare(const nsCString &aString,PRBool aIgnoreCase,PRInt32 aCount) const { - return SVCompare(mStringValue,aString.mStringValue,aIgnoreCase,aCount); -} - -PRInt32 nsString::Compare(const char* aString,PRBool aIgnoreCase,PRInt32 aCount) const { - nsStringValueImpl theStringValue(NS_CONST_CAST(char*,aString),aCount); - return SVCompare(mStringValue,theStringValue,aIgnoreCase,aCount); -} - -PRInt32 nsString::Compare(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 aCount) const { - nsStringValueImpl theStringValue(NS_CONST_CAST(PRUnichar*,aString),aCount); - return SVCompareChars(mStringValue,theStringValue,aIgnoreCase,aCount); -} - -PRBool nsString::Equals(const nsString &aString,PRBool aIgnoreCase,PRInt32 aCount) const { - return PRBool(0==SVCompare(mStringValue,aString.mStringValue,aIgnoreCase,aCount)); -} - -PRBool nsString::Equals(const nsCString &aString,PRBool aIgnoreCase,PRInt32 aCount) const { - return PRBool(0==SVCompare(mStringValue,aString.mStringValue,aIgnoreCase,aCount)); -} - -PRBool nsString::Equals(const char* aString,PRBool aIgnoreCase,PRInt32 aCount) const { - nsStringValueImpl theStringValue(NS_CONST_CAST(char*,aString),aCount); - return PRBool(0==SVCompare(mStringValue,theStringValue,aIgnoreCase,aCount)); -} - - -PRBool nsString::Equals(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 aCount) const { - nsStringValueImpl theStringValue(NS_CONST_CAST(PRUnichar*,aString),aCount); - return PRBool(0==SVCompareChars(mStringValue,theStringValue,aIgnoreCase,aCount)); -} - -PRBool nsString::Equals(const PRUnichar* aLHS,const PRUnichar* aRHS,PRBool aIgnoreCase) const { - NS_ASSERTION(0!=aLHS,kNullPointerError); - NS_ASSERTION(0!=aRHS,kNullPointerError); - PRBool result=PR_FALSE; - if((aLHS) && (aRHS)){ - - -// PRInt32 cmp=(aIgnoreCase) ? nsCRT::strcasecmp(aLHS,aRHS) : nsCRT::strcmp(aLHS,aRHS); -// result=PRBool(0==cmp); - - - } - - return result; -} - -PRBool nsString::Equals(/*FIX: const */nsIAtom* aAtom,PRBool aIgnoreCase) const{ - NS_ASSERTION(0!=aAtom,kNullPointerError); - PRBool result=PR_FALSE; - -#if 0 - - if(aAtom){ - PRInt32 cmp=0; - const PRUnichar* unicode; - if (aAtom->GetUnicode(&unicode) != NS_OK || unicode == nsnull) - return PR_FALSE; - if (aIgnoreCase) - cmp=nsCRT::strcasecmp(mUStr,unicode); - else - cmp=nsCRT::strcmp(mUStr,unicode); - result=PRBool(0==cmp); - } -#endif - return result; -} - - -/*************************************** - These are string searching methods... - ***************************************/ - -/** - * search for given string within this string - * - * @update rickg 03.01.2000 - * @param aString - substr to be found - * @param aIgnoreCase tells us whether or not to do caseless compare - * @param anOffset tells us where in this string to start searching - * @param aRepCount tells us how many iterations to make starting at the given offset - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 nsString::Find(const nsString& aTarget,PRBool aIgnoreCase,PRUint32 anOffset,PRInt32 aRepCount) const { - return SVFind(mStringValue,aTarget.mStringValue,aIgnoreCase,aRepCount,anOffset); -} - -/** - * search for given string within this string - * - * @update rickg 03.01.2000 - * @param aString - substr to be found - * @param aIgnoreCase tells us whether or not to do caseless compare - * @param anOffset tells us where in this string to start searching - * @param aRepCount tells us how many iterations to make starting at the given offset - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 nsString::Find(const nsCString &aString,PRBool aIgnoreCase,PRUint32 anOffset,PRInt32 aRepCount) const { - return SVFind(mStringValue,aString.mStringValue,aIgnoreCase,aRepCount,anOffset); -} - -/** - * search for given string within this char* string - * - * @update rickg 03.01.2000 - * @param aString - substr to be found - * @param aIgnoreCase tells us whether or not to do caseless compare - * @param anOffset tells us where in this string to start searching - * @param aRepCount tells us how many iterations to make starting at the given offset - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 nsString::Find(const char* aString,PRBool aIgnoreCase,PRUint32 anOffset,PRInt32 aRepCount) const { - nsStringValueImpl theString(NS_CONST_CAST(char*,aString)); - return SVFind(mStringValue,theString,aIgnoreCase,aRepCount,anOffset); -} - -/** - * search for given string within this PRUnichar* string - * - * @update rickg 03.01.2000 - * @param aString - substr to be found - * @param aIgnoreCase tells us whether or not to do caseless compare - * @param anOffset tells us where in this string to start searching - * @param aRepCount tells us how many iterations to make starting at the given offset - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 nsString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRUint32 anOffset,PRInt32 aRepCount) const { - - nsStringValueImpl theString(NS_CONST_CAST(PRUnichar*,aString)); - return SVFind(mStringValue,theString,aIgnoreCase,aRepCount,anOffset); -} - -/** - * This method finds the offset of the first char in this string that is - * a member of the given charset, starting the search at anOffset - * - * @update rickg 03.01.2000 - * @param aString contains set of chars to be found - * @param anOffset -- where in this string to start searching - * @return - */ -PRInt32 nsString::FindCharInSet(const nsString& aString,PRUint32 anOffset) const{ - return SVFindCharInSet(mStringValue,aString.mStringValue,PR_FALSE,mStringValue.mLength,anOffset); -} - - -/** - * This method finds the offset of the first char in this string that is - * a member of the given charset, starting the search at anOffset - * - * @update rickg 03.01.2000 - * @param aString contains set of chars to be found - * @param anOffset -- where in this string to start searching - * @return - */ -PRInt32 nsString::FindCharInSet(const char *aString,PRUint32 anOffset) const{ - - nsStringValueImpl theStringValue(NS_CONST_CAST(char*,aString)); - return SVFindCharInSet(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset); -} - -/** - * This method finds the offset of the first char in this string that is - * a member of the given altcharset, starting the search at anOffset - * - * @update rickg 03.01.2000 - * @param aString contains set of chars to be found - * @param anOffset -- where in this string to start searching - * @return - */ -PRInt32 nsString::FindCharInSet(const PRUnichar *aString,PRUint32 anOffset) const{ - - nsStringValueImpl theStringValue(NS_CONST_CAST(PRUnichar*,aString)); - return SVFindCharInSet(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset); -} - -/** - * Search for a given char, starting at given offset - * - * @update rickg 03.01.2000 - * @param aChar is the unichar to be sought - * @param aIgnoreCase tells us whether or not to do caseless compare - * @param anOffset tells us where in this string to start searching - * @param aCount tells us how many iterations to make starting at the given offset - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 nsString::FindChar(char aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const { - return SVFindChar(mStringValue,aChar,aIgnoreCase,aCount,anOffset); -} - -/** - * Reverse search for given char within this string - * - * @update gess 3/25/98 - * @param aChar - char to be found - * @param aIgnoreCase tells us whether or not to do caseless compare - * @param anOffset tells us where in this string to start searching (-1 means start at end) - * @param aRepCount tells us how many iterations to make starting at the given offset - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 nsString::RFindChar(char aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aRepCount) const{ - return SVRFindChar(mStringValue,aChar,aIgnoreCase,aRepCount,anOffset); -} - -/** - * Reverse search for given string within this string - * - * @update gess 3/25/98 - * @param aString - substr to be found - * @param aIgnoreCase tells us whether or not to do caseless compare - * @param anOffset tells us where in this string to start searching - * @param aRepCount tells us how many iterations to make starting at the given offset - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 nsString::RFind(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aRepCount) const{ - PRInt32 theMaxPos = mStringValue.mLength-aString.mStringValue.mLength; //this is the last pos that is feasible for starting the search, with given lengths... - PRInt32 result=kNotFound; - - if(0<=theMaxPos) { - result=SVRFind(mStringValue,aString.mStringValue,aIgnoreCase,aRepCount,anOffset); - } - return result; -} - -PRInt32 nsString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aRepCount) const{ - nsStringValueImpl theStringValue(NS_CONST_CAST(char*,aString)); - return SVRFind(mStringValue,theStringValue,aIgnoreCase,aRepCount,anOffset); -} - - -PRInt32 nsString::RFind(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aRepCount) const{ - nsStringValueImpl theStringValue(NS_CONST_CAST(PRUnichar*,aString)); - return SVRFind(mStringValue,theStringValue,aIgnoreCase,aRepCount,anOffset); -} -/** - * This method finds (in reverse) the offset of the first char in this string that is - * a member of the given charset, starting the search at anOffset - * - * @update rickg 03.01.2000 - * @param aString contains set of chars to be found - * @param anOffset -- where in this string to start searching - * @return - */ -PRInt32 nsString::RFindCharInSet(const nsString& aString,PRInt32 anOffset) const { - return SVRFindCharInSet(mStringValue,aString.mStringValue,PR_FALSE,mStringValue.mLength,anOffset); -} - -/** - * This method finds (in reverse) the offset of the first char in this string that is - * a member of the given charset, starting the search at anOffset - * - * @update rickg 03.01.2000 - * @param aString contains set of chars to be found - * @param anOffset -- where in this string to start searching - * @return - */ -PRInt32 nsString::RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset) const{ - nsStringValueImpl theStringValue(NS_CONST_CAST(PRUnichar*,aString)); - return SVRFindCharInSet(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset); -} - -/** - * This method finds (in reverse) the offset of the first char in this string that is - * a member of the given charset, starting the search at anOffset - * - * @update rickg 03.01.2000 - * @param aString contains set of chars to be found - * @param anOffset -- where in this string to start searching - * @return - */ -PRInt32 nsString::RFindCharInSet(const char* aString,PRInt32 anOffset) const{ - nsStringValueImpl theStringValue(NS_CONST_CAST(char*,aString)); - return SVRFindCharInSet(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset); -} - -/*************************************** - These convert to a different type - ***************************************/ - -void nsString::Recycle(nsString* aString) { - //NOT IMPLEMENTED -} - -nsString* nsString::CreateString(void) { - return 0; //NOT IMPLEMENTED -} - -/** - * This method constructs a new nsString is a clone of this string. - */ -nsString* nsString::ToNewString() const { - return 0; //NOT IMPLEMENTED -} - - -char* nsString::ToNewCString() const { - return 0; //NOT IMPLEMENTED -} - -char* nsString::ToNewUTF8String() const { - return 0; //NOT IMPLEMENTED -} - -PRUnichar* nsString::ToNewUnicode() const { - return 0; //NOT IMPLEMENTED -} - -char* nsString::ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset) const { - int len=(mStringValue.mLength PRInt32(sizeof(buf)-1)) { - *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; - return 0.0f; - } - char* cp = ToCString(buf, sizeof(buf)); - float f = (float) strtod(cp, &cp); - if (*cp != 0) { - *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; - } - *aErrorCode = (PRInt32) NS_OK; - return f; -} - -/** - * Perform string to int conversion. - * @param aErrorCode will contain error if one occurs - * @param aRadix tells us which radix to assume; kAutoDetect tells us to determine the radix for you. - * @return int rep of string value, and possible (out) error code - */ -PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const{ - return SVToInteger(mStringValue,anErrorCode,aRadix); -} - -nsresult nsString::Append(const nsStringValueImpl &aString,PRInt32 aLength,PRUint32 aSrcOffset) { - aLength = (aLength<0) ? aString.mLength : (aLength<(PRInt32)aString.mLength) ? aLength: aString.mLength; - return SVAppend(mStringValue,aString,aLength,aSrcOffset); -} - -/***************************************************************** - Now we define the nsSubsumeStr class - *****************************************************************/ - -nsSubsumeStr::nsSubsumeStr(nsString& aString) : nsString() { - Subsume(mStringValue,aString.mStringValue); -} - -nsSubsumeStr::nsSubsumeStr(PRUnichar * aString,PRBool assumeOwnership,PRInt32 aLength) : nsString() { -// mStringValue.mBuffer=aString; -// mStringValue.mCapacity=mStringValue.mLength=(-1==aLength) ? strlen(aString) : aLength; -// mOwnsBuffer=assumeOwnership; -} - -/** - * - * @update gess 01/04/99 - * @param - * @return - */ -NS_COM int fputs(const nsString& aString, FILE* out) -{ - char buf[100]; - char* cp = buf; - PRInt32 len = aString.Length(); - if (len >= PRInt32(sizeof(buf))) { - cp = aString.ToNewCString(); - } else { - aString.ToCString(cp, len + 1); - } - if(len>0) - ::fwrite(cp, 1, len, out); - if (cp != buf) { - delete[] cp; - } - return (int) len; -} - -PRUint32 HashCode(const nsString& aDest) { - PRUint32 h = 0; - PRUint32 n = aDest.Length(); - PRUint32 m; - const PRUnichar* c=aDest.GetUnicode(); - - if (n < 16) { /* Hash every char in a short string. */ - for(; n; c++, n--) - h = (h >> 28) ^ (h << 4) ^ *c; - } - else { /* Sample a la java.lang.String.hash(). */ - for(m = n / 8; n >= m; c += m, n -= m) - h = (h >> 28) ^ (h << 4) ^ *c; - } - return h; -} - -void Recycle( PRUnichar* aBuffer) { - nsMemory::Free(aBuffer); -} - - -/***************************************************************** - Now we declare the nsAutoString class - *****************************************************************/ - - -nsAutoString::nsAutoString() : nsString() { - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - mStringValue.mRefCount=2; -} - - //call this version nsAutoString derivatives... -nsAutoString::nsAutoString(const nsAutoString& aString,PRInt32 aLength) : nsString() { - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - mStringValue.mRefCount=2; - nsString::Assign(aString,aLength,0); -} - - -//call this version for nsString and the autostrings -nsAutoString::nsAutoString(const nsString& aString,PRInt32 aLength) : nsString() { - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - mStringValue.mRefCount=2; - nsString::Assign(aString,aLength,0); -} - - - //call this version with nsCString -nsAutoString::nsAutoString(const nsCString& aString) : nsString() { - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - mStringValue.mRefCount=2; - nsString::Assign(aString); -} - - //call this version for char*'s.... -nsAutoString::nsAutoString(const char* aString,PRInt32 aLength) : nsString() { - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - mStringValue.mRefCount=2;; //so we don't try to delete our internal buffer - nsString::Assign(aString,aLength,0); -} - - //call this version for a single char of type char... -nsAutoString::nsAutoString(char aChar) : nsString() { - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - mStringValue.mRefCount=2; //so we don't try to delete our internal buffer - nsString::Assign(aChar); -} - - //call this version for a single char of type char... -nsAutoString::nsAutoString(PRUnichar aChar) : nsString() { - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - mStringValue.mRefCount=2; //so we don't try to delete our internal buffer - nsString::Assign(aChar); -} - - - //call this version for PRUnichar*'s.... -nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString() { - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - mStringValue.mRefCount=2; //so we don't try to delete our internal buffer - nsString::Assign(aString,aLength,0); -} - - - //call this version for all other ABT versions of readable strings -nsAutoString::nsAutoString(const nsAReadableString &aString) : nsString() { - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - mStringValue.mRefCount=2; //so we don't try to delete our internal buffer - nsString::Assign(aString); -} - -nsAutoString::nsAutoString(const UBufDescriptor &aBuffer) : nsString() { - mStringValue.mBuffer=aBuffer.mBuffer; - mStringValue.mCapacity=aBuffer.mCapacity; - mStringValue.mLength=aBuffer.mLength; - mStringValue.mRefCount=(aBuffer.mOwnsBuffer) ? 1 : 2; - memset(mInternalBuffer,0,sizeof(mInternalBuffer)); -} - - -nsAutoString::nsAutoString(const nsSubsumeStr& aSubsumeStringX) : nsString() { -} - - -nsAutoString::~nsAutoString() { } - - -nsAutoString& nsAutoString::operator=(const nsAutoString& aString) { - nsString::operator=(aString); - return *this; -} - -nsAutoString& nsAutoString::operator=(const nsString& aString) { - nsString::operator=(aString); - return *this; -} - -nsAutoString& nsAutoString::operator=(const nsCString& aString) { - nsString::operator=(aString); - return *this; -} - -nsAutoString& nsAutoString::operator=(const PRUnichar* aString) { - nsString::operator=(aString); - return *this; -} - -nsAutoString& nsAutoString::operator=(const char* aString) { - nsString::operator=(aString); - return *this; -} - -nsAutoString& nsAutoString::operator=(const PRUnichar aChar) { - nsString::operator=(aChar); - return *this; -} - - -nsAutoString& nsAutoString::operator=(const nsSubsumeStr &aSubsumeString) { - nsString::operator=(aSubsumeString); - return *this; -} - diff --git a/xpcom/ds/nsString2x.h b/xpcom/ds/nsString2x.h deleted file mode 100644 index 8506f7c8a121..000000000000 --- a/xpcom/ds/nsString2x.h +++ /dev/null @@ -1,576 +0,0 @@ -/***************************************************************************************************************** - * - * This template provides the basic implementation for nsString. - * - * Contributor(s): - * Rick Gessner - * - * History: - * - * 02.29.2000: Original files (rickg) - * 03.02.2000: Expand the API's to be a bit more realistic (rickg): - * 1. Flesh out the interface to be compatible with old library - * 2. Enable both nsString-based interfaces and nsAReadableString interfaces - * 3. Build enough infrastructure to test nsString(s) and nsImmutableString constructions. - * 03.03.2000: Finished mapping original nsString functionality to template form (rickg) - * - *****************************************************************************************************************/ - - -#ifndef _NS_STRING_ -#define _NS_STRING_ - -#include "nsStringValue.h" - - -class NS_COM nsCString; -class NS_COM nsSubsumeStr; - - -/*************************************************************************** - * - * This is the templatized base class from which stringvalues are derived. (rickg) - * - ***************************************************************************/ -struct UBufDescriptor { - UBufDescriptor(PRUnichar *aBuffer,PRUint32 aLength,PRUint32 aCapacity,PRBool aOwnsBuffer) { - mBuffer=aBuffer; - mLength=aLength; - mCapacity=aCapacity-1; - mOwnsBuffer=aOwnsBuffer; - } - PRUnichar* mBuffer; - PRUint32 mLength; - PRUint32 mCapacity; - PRBool mOwnsBuffer; -}; - - -class NS_COM nsString { -public: - - //****************************************** - // Ctor's - //****************************************** - - nsString(); - - //copy constructor - nsString(const nsString& aString,PRInt32 aLength=-1); - - //call this version for nsCString - nsString(const nsCString& aString,PRInt32 aLength=-1); - - //call this version for prunichar*'s.... - nsString(const PRUnichar* aString,PRInt32 aLength=-1) ; - - //call this version for a single char of type char... - nsString(const char aChar); - - //call this version for a single char of type prunichar... - nsString(const PRUnichar aChar); - - //call this version for stack-based string buffers... - nsString(const nsSubsumeStr &aSubsumeString); - - //call this version for stack-based string buffers... - nsString(nsSubsumeStr &aSubsumeString); - - //call this version for char's.... - nsString(const char* aString,PRInt32 aLength=-1) ; - - //call this version for all other ABT versions of readable strings - nsString(const nsAReadableString &aString) ; - - - virtual ~nsString(); - - void Reinitialize(PRUnichar* aBuffer,PRUint32 aCapacity,PRInt32 aLength=-1); - - //****************************************** - // Concat operators - //****************************************** - - nsSubsumeStr operator+(const nsString &aString); - nsSubsumeStr operator+(const PRUnichar* aString); - nsSubsumeStr operator+(const char* aString); - nsSubsumeStr operator+(PRUnichar aChar); - - - //****************************************** - // Assigment operators - //****************************************** - - - nsString& operator=(const nsString& aString); - nsString& operator=(const nsCString& aString); - nsString& operator=(const nsSubsumeStr &aSubsumeString); - nsString& operator=(const PRUnichar* aString); - nsString& operator=(const char* aString); - nsString& operator=(const char aChar); - nsString& operator=(const PRUnichar aChar); - - - //****************************************** - // Here are the simple accessor methods... - //****************************************** - - virtual nsresult SetLength(PRUint32 aLength) { - if(aLength>mStringValue.mLength) - SetCapacity(aLength); - Truncate(aLength); - return NS_OK; - } - - virtual nsresult SetCapacity(PRUint32 aCapacity); - - PRUnichar* GetUnicode() const { return mStringValue.mBuffer;} - - PRUnichar operator[](PRUint32 aOffset) const {return CharAt(aOffset);} - -// operator const char* const() {return mStringValue.mBuffer;} - - PRUint32 Length() const {return mStringValue.mLength;} - - PRUint32 Capacity() const {return mStringValue.mCapacity;} - - size_t GetCharSize() const {return sizeof(char);} - PRBool IsUnicode() const {return PRBool(sizeof(PRUnichar)==sizeof(char));} - - PRBool IsEmpty(void) const {return PRBool(mStringValue.mLength==0);} - - PRUnichar CharAt(PRUint32 anIndex) const { - return (anIndex(const nsString& aString) const {return PRBool(Compare(aString)>0);} - PRBool operator>(const nsCString& aString) const {return PRBool(Compare(aString)>0);} - PRBool operator>(const char* aString) const {return PRBool(Compare(aString)>0);} - PRBool operator>(const PRUnichar* aString) const {return PRBool(Compare(aString)>0);} - - PRBool operator<=(const nsString& aString) const {return PRBool(Compare(aString)<=0);} - PRBool operator<=(const nsCString& aString) const {return PRBool(Compare(aString)<=0);} - PRBool operator<=(const char* aString) const {return PRBool(Compare(aString)<=0);} - PRBool operator<=(const PRUnichar* aString) const {return PRBool(Compare(aString)<=0);} - - PRBool operator>=(const nsString& aString) const {return PRBool(Compare(aString)>=0);} - PRBool operator>=(const nsCString& aString) const {return PRBool(Compare(aString)>=0);} - PRBool operator>=(const char* aString) const {return PRBool(Compare(aString)>=0);} - PRBool operator>=(const PRUnichar* aString) const {return PRBool(Compare(aString)>=0);} - - - PRInt32 Compare(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; - PRInt32 Compare(const nsCString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; - PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; - PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const ; - - PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; - PRBool Equals(const nsCString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; - PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; - PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; - PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const; - PRBool Equals(const PRUnichar* aLHS,const PRUnichar* aRHS,PRBool aIgnoreCase=PR_FALSE) const; - - PRBool EqualsIgnoreCase(const nsString &aString) const {return Equals(aString,PR_TRUE);} - PRBool EqualsIgnoreCase(const nsCString &aString) const {return Equals(aString,PR_TRUE);} - PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const {return Equals(aString,PR_TRUE,aCount);} - PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const {return Equals(aString,PR_TRUE,aCount);} - PRBool EqualsIgnoreCase(const PRUnichar* aLHS, const PRUnichar* aRHS) const {return Equals(aLHS,aRHS,PR_TRUE);} - PRBool EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const {return Equals(aAtom,PR_TRUE);} - - - /*************************************** - These are string searching methods... - ***************************************/ - - /** - * search for given string within this string - * - * @update rickg 03.01.2000 - * @param aString - substr to be found - * @param aIgnoreCase tells us whether or not to do caseless compare - * @param anOffset tells us where in this string to start searching - * @param aRepCount tells us how many iterations to make starting at the given offset - * @return offset in string, or -1 (kNotFound) - */ - PRInt32 Find(const nsString& aTarget,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0,PRInt32 aRepCount=-1) const; - PRInt32 Find(const nsCString &aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0,PRInt32 aRepCount=-1) const; - PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0,PRInt32 aRepCount=-1) const; - PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0,PRInt32 aRepCount=-1) const; - PRInt32 FindChar(char aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aRepCount=-1) const ; - - PRInt32 FindCharInSet(const nsString& aString,PRUint32 anOffset=0) const; - PRInt32 FindCharInSet(const char *aString,PRUint32 anOffset=0) const; - PRInt32 FindCharInSet(const PRUnichar *aString,PRUint32 anOffset=0) const; - - PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aRepCount=-1) const; - PRInt32 RFind(const nsCString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aRepCount=-1) const; - PRInt32 RFind(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aRepCount=-1) const; - PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aRepCount=-1) const; - PRInt32 RFindChar(char aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aRepCount=-1) const; - - PRInt32 RFindCharInSet(const nsString& aString,PRInt32 anOffset=-1) const ; - PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const; - PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const; - - /*************************************** - These convert to a different type - ***************************************/ - - static void Recycle(nsString* aString); - - static nsString* CreateString(void); - - nsString* ToNewString() const; - - char* ToNewCString() const; - - char* ToNewUTF8String() const; - - PRUnichar* ToNewUnicode() const; - - char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const; - - - //****************************************** - // Utility methods - //****************************************** - - PRInt32 CountChar(PRUnichar aChar); - - //This will not work correctly for any unicode set other than ascii - void DebugDump(void) const; - - /** - * Perform string to float conversion. - * @param aErrorCode will contain error if one occurs - * @return float rep of string value - */ - float ToFloat(PRInt32* aErrorCode) const; - - /** - * Perform string to int conversion. - * @param aErrorCode will contain error if one occurs - * @param aRadix tells us which radix to assume; kAutoDetect tells us to determine the radix for you. - * @return int rep of string value, and possible (out) error code - */ - PRInt32 ToInteger(PRInt32* anErrorCode,PRUint32 aRadix=kAutoDetect) const; - - void ToLowerCase(); - - void ToLowerCase(nsString &aString) const; - - void ToUpperCase(); - - void ToUpperCase(nsString &aString) const; - - -protected: - - nsresult Append(const nsStringValueImpl &aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0); - - nsStringValueImpl mStringValue; - - friend class nsCString; - friend class nsSubsumeStr; -}; - - - -class NS_COM nsSubsumeStr : public nsString { -public: - nsSubsumeStr(nsString& aString); - nsSubsumeStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1); - - PRBool mOwnsBuffer; -}; - - -/***************************************************************** - Now we declare the nsAutoString class - *****************************************************************/ - - -class NS_COM nsAutoString : public nsString { -public: - - nsAutoString(); - - //call this version nsAutoString derivatives... - nsAutoString(const nsAutoString& aString,PRInt32 aLength=-1); - - //call this version for nsString and the autostrings - nsAutoString(const nsString& aString,PRInt32 aLength=-1); - - //call this version with nsCString (start of COW) - nsAutoString(const nsCString& aString); - - //call this version for char*'s.... - nsAutoString(const char* aString,PRInt32 aLength=-1); - - //call this version for a single char of type char... - nsAutoString(PRUnichar aChar); - nsAutoString(char aChar); - - //call this version for PRUnichar*'s.... - nsAutoString(const PRUnichar* aString,PRInt32 aLength=-1); - - //call this version for all other ABT versions of readable strings - nsAutoString(const nsAReadableString &aString); - - nsAutoString(const UBufDescriptor &aBuffer) ; - - nsAutoString(const nsSubsumeStr& aSubsumeStringX) ; - - virtual ~nsAutoString(); - - - nsAutoString& operator=(const nsAutoString& aCopy); - nsAutoString& operator=(const nsString& aString); - nsAutoString& operator=(const nsCString& aString); - nsAutoString& operator=(const PRUnichar* aString); - nsAutoString& operator=(const char* aString) ; - nsAutoString& operator=(const PRUnichar aChar); - nsAutoString& operator=(const nsSubsumeStr &aSubsumeString); - - -protected: - PRUnichar mInternalBuffer[kDefaultStringSize+1]; - -}; - -extern NS_COM int fputs(const nsString& aString, FILE* out); - -extern PRUint32 HashCode(const nsString& aDest); - -extern NS_COM void Recycle( PRUnichar* aBuffer); - - -#endif diff --git a/xpcom/ds/nsStringImpl.h b/xpcom/ds/nsStringImpl.h deleted file mode 100644 index dd96a5f6a19b..000000000000 --- a/xpcom/ds/nsStringImpl.h +++ /dev/null @@ -1,515 +0,0 @@ -/***************************************************************************************************************** - * - * This template provides the basic implementation for all the original - * nsString classes (nsString, nsCString) and serve as the basis for - * thier autostring forms. - * - * DEVELOPMENT NOTES: - * - * 0. Note that I've explictly created interfaces for both the nsString(s), - * and for the nsReadableString (ABT). This will allow the nsString - * form to be optimized (as in the original), while the nsReadable - * interfaces can use a new, more generic approach (including iterators). - * SEE Append() as an example. - * - * 1. Flesh out more of the nsReadableString and nsReadableStringIterator interfaces. - * Note the use of the readableStringIterator in the version of Append() that - * accepts an nsReadableString&. This is because the readableString may have - * almost any form (e.g. segmentString), and we can't rely upon a linear - * layout of buffer memory as we can with nsString class deriviates. - * - * I fully expect this pattern to get replaced with a legitimate form. - * - * - * 2. I don't really think it's necessary to go crazy with virtual methods - * but I've done so for now as a matter of consistency. Once this file - * gets further along, and I have a workable nsAutoString, then I'll start - * backing off from virtual methods whereever possible. Please be patient. - * - * 3. I'm being lazy for the time being, and NOT encoding the buffer-ownership - * flag into the high-order bit of the length field. This needs to be done - * "real soon" but it's not worth doing (today) while I'm still designing. - * - * 4. I explictly implemented the orthodox canonical form. - * - * 5. Before anyone get's too critical of this design, note that I'm using - * the dual-class template form to make interoperability between char* - * and prunichar* obvious. I recognize that it's better to switch to - * an nsReadableString interface, but I've done this for now ONLY to - * make the conversion from our existing nsString class easier. Once - * I get over a few hurdles there, I'll re-examine this approach. - * Once again: please be patient (I'm only 5 hours into this effort). - * - * 6. I've quickly hooked up some of the low level routines (in the - * file nsBufferManager.h). Don't expect it all to work just yet -- - * they're mostly placeholders. You CAN already construct and copy - * construct an nsString, nsCString and the autostring forms. - * - * 7. Note that the basic nsString interfaces (append, assign, etc) are not - * perfectly equivalent to the originals. All I tried to do was capture - * the gist of the originals to flesh out these interfaces. - * - * 8. Next Up: Mapping of more nsString functions (insert, delete, the - * boolean operators, the searching methods, etc. - * - * *** NOTE: I've begun to map the existing nsString functions -- - * most are empty covers, to be used as a placeholder. - * - * 9. After I'm done with #8, I'll split this implementation into 2 files. - * - * FILE NOTES: - * - * 02.29.2000: Original files (rickg) - * 03.02.2000: Expand the API's to be a bit more realistic (rickg): - * 1. Flesh out the interface to be compatible with old library - * 2. Enable both nsString-based interfaces and nsReadableString interfaces - * 3. Build enough infrastructure to test nsString(s) and nsImmutableString constructions. - * - *****************************************************************************************************************/ - - -#ifndef NS_STRINGIMPL_ -#define NS_STRINGIMPL_ - -#include "nsStringValue.h" -#include "nsBufferManager.h" - - -/*************************************************************************** - * - * The following is the basic interface nsString searching... - * - * We will merge this into nsReadableString very soon, but I've kept it - * seperate until I can map and factor the original nsString methods. - * - ***************************************************************************/ -class nsSearchableString { -public: - - //We need to decide how deep (and generic) this API can go... - -}; - -/*************************************************************************** - * - * This isn't intended as a real class, but only to illustrate that for - * nsReadableString, we want a common access pattern to get at the underlying - * buffer. Iterators make perfect sense, but it will take a real implementation. - * - * Note: This class is intended to replace direct calls to GetBuffer() - * in cases where iteration on an nsReadableString is taking place. - * - ***************************************************************************/ -class nsReadableStringIterator { -public: - nsReadableStringIterator() { } -}; - -/*************************************************************************** - * - * The following is the basic interface anyone who wants to be passed - * as a string should define. - * - ***************************************************************************/ -class nsReadableString : public nsSearchableString { -public: - virtual PRUint32 Length() =0; - virtual size_t GetCharSize() =0; - - virtual PRUnichar operator[](PRUint32) = 0; - - virtual nsReadableStringIterator* First() = 0; //These are here so that nsReadable strings can offer a standard mechanism for - virtual nsReadableStringIterator* Last() = 0; //callers to access underlying data. Feel free to replace with a better pattern. - -//by moving to iterators, we can support segmented content models... -//virtual nsStringIterator GetIterator() = 0; - -//virtual PRBool IsEmpty(void) = 0; - - //etc. -}; - - -/*************************************************************************** - * - * Now the basic nsStringImpl implementation, that becomes the functional - * base for genericized strings storing a given chartype.for nsString, - nsCStirng and the autoString pairs. - * - ***************************************************************************/ - -template -class nsStringImpl: public nsReadableString { -public: - - nsStringImpl() : mStringValue() { - } - - //call this version for nsString,nsCString and the autostrings - nsStringImpl(const nsStringImpl& aString,PRInt32 aLength=-1) : mStringValue() { - Assign(aString,aLength); - } - - //call this version for nsString,nsCString and the autostrings - nsStringImpl(const CharType* aString,PRInt32 aLength=-1) : mStringValue() { - Assign(aString,aLength); - } - - //call this version for all other ABT versions of readable strings - nsStringImpl(const nsReadableString &aString) : mStringValue() { - Assign(aString); - } - - virtual ~nsStringImpl() { } - - nsStringImpl& operator=(const nsStringImpl& aString) { - if(aString.mStringValue.mBuffer!=mStringValue.mBuffer) { - Assign(aString); - } - return *this; - } - - //****************************************** - // Here are the accessor methods... - //****************************************** - - virtual nsresult SetLength(PRUint32 aLength) { - return NS_OK; - } - - virtual nsresult SetCapacity(PRUint32 aCapacity) { - return NS_OK; - } - - operator CharType*() {return mStringValue.mBuffer;} - - PRUint32 Length() {return mStringValue.mLength;} - size_t GetCharSize() {return sizeof(CharType);} - PRBool IsEmpty(void) {return PRBool(mStringValue.mLength==0);} - PRUnichar operator[](PRUint32 aOffset) {return mStringValue[aOffset];} - PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex) {return PR_FALSE;} - - PRUnichar CharAt(PRUint32 anIndex) const {return mStringValue[aOffset];} - PRUnichar First(void) const {return mStringValue[0];} - PRUnichar Last(void) const {return mStringValue[mStringValue.mLength];} - - - //these aren't the real deal, but serve as a placeholder for us to implement iterators. - virtual nsReadableStringIterator* First() {return new nsReadableStringIterator(); } - virtual nsReadableStringIterator* Last() {return new nsReadableStringIterator(); } - - PRInt32 CountChar(PRUnichar aChar) { return 0; } - void DebugDump(void) const { } - - //****************************************** - // Here are the mutation methods... - //****************************************** - - virtual nsresult Truncate(PRUint32 offset=0) { - if(mStringValue) { - mStringValue[0]=0; - mStringValue.mLength=0; - } - return NS_OK; - } - - //assign from a stringimpl - nsresult Assign(const nsStringImpl& aString) { - nsresult result=NS_OK; - if(mStringValue.mBuffer!=aString.mStringValue.mBuffer){ - Truncate(); - result=Append(aString); - } - return result; - } - - //assign from a compatible string pointer - virtual nsresult Assign(const CharType* aString,PRInt32 aLength=-1) { - nsresult result=NS_OK; - if(mStringValue.mBuffer!=aString){ - Truncate(); - result=Append(aString,aLength); - } - return result; - } - - - //assign from an nsReadableString (the ABT) - virtual nsresult Assign(const nsReadableString &aString,PRInt32 aLength=-1) { - nsresult result=NS_OK; - Truncate(); - SVAppendReadable(mStringValue,aString,0,aLength); - return result; - } - - //append from a stringimpl - virtual nsresult Append(const nsStringImpl &aString,PRInt32 aLength=-1) { - SVAppend< CharType, CharType > (mStringValue,aString.mStringValue,0,aString.mStringValue.mLength); - return NS_OK; - } - - //append from a type compatible string pointer - virtual nsresult Append(const CharType* aString,PRInt32 aLength=-1) { - nsresult result=NS_OK; - if(aString) { - nsStringValueImpl theStringValue(const_cast(aString),aLength); - SVAppend< CharType, CharType > (mStringValue,theStringValue,0,aLength); - } - return result; - } - - //append from an nsReadableString (the ABT) - virtual nsresult Append(const nsReadableString &aString,PRInt32 aLength=-1) { - SVAppendReadable (mStringValue,aString,0,aLength); - return NS_OK; - } - - //append an integer - virtual nsresult Append(PRInt32 aInteger,PRInt32 aRadix=10) { - nsresult result=NS_OK; - return result; - } - - //Append a float - virtual nsresult Append(float aFloat) { - nsresult result=NS_OK; - return result; - } - - - //*************************************** - // Here come a few deletion methods... - //*************************************** - - nsStringImpl& Cut(PRUint32 anOffset,PRInt32 aCount) { - return *this; - } - - nsStringImpl& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE,PRBool aIgnoreQuotes=PR_FALSE) { - return *this; - } - - nsStringImpl& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE){ - return *this; - } - - nsStringImpl& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE){ - return *this; - } - - - //*************************************** - // Here come a wad of insert methods... - //*************************************** - - nsStringImpl& Insert(const nsStringImpl& aCopy,PRUint32 anOffset,PRInt32 aCount=-1) { - return *this; - } - - nsStringImpl& Insert(const CharType* aChar,PRUint32 anOffset,PRInt32 aCount=-1){ - return *this; - } - - nsStringImpl& Insert(CharType aChar,PRUint32 anOffset){ - return *this; - } - - - //******************************************* - // Here come inplace replacement methods... - //******************************************* - - nsStringImpl& ReplaceChar(PRUnichar anOldChar,PRUnichar aNewChar){ - return *this; - } - - nsStringImpl& ReplaceChar(const char* aSet,PRUnichar aNewChar){ - return *this; - } - - nsStringImpl& ReplaceSubstring( const nsStringImpl& aTarget, - const nsStringImpl& aNewValue){ - return *this; - } - - nsStringImpl& ReplaceSubstring(const CharType* aTarget,const CharType* aNewValue) { - return *this; - } - - //******************************************* - // Here come the stripchar methods... - //******************************************* - - nsStringImpl& StripChars(const char* aSet){ - return *this; - } - - nsStringImpl& StripChar(CharType aChar,PRInt32 anOffset=0){ - return *this; - } - - nsStringImpl& StripChar(PRInt32 anInt,PRInt32 anOffset=0) {return StripChar((PRUnichar)anInt,anOffset); } - - nsStringImpl& StripWhitespace() { - return *this; - } - - //************************************************** - // Here are some methods that extract substrings... - //************************************************** - - PRUint32 Left(nsStringImpl& aCopy,PRInt32 aCount) const { - } - - PRUint32 Mid(nsStringImpl& aCopy,PRUint32 anOffset,PRInt32 aCount) const { - } - - PRUint32 Right(nsStringImpl& aCopy,PRInt32 aCount) const { - } - - - //******************************************* - // Here come the operator+=() methods... - //******************************************* - - nsStringImpl& operator+=(const nsStringImpl& aString){ - Append(aString,aString.mStringValue.mLength); - return *this; - } - - nsStringImpl& operator+=(const CharType* aString) { - Append(aString); - return *this; - } - - nsStringImpl& operator+=(const CharType aChar) { - - return *this; - } - - - nsStringImpl& operator+=(const int anInt){ - Append(anInt,10); - return *this; - } - - void ToLowerCase() { - } - - void ToLowerCase(nsStringImpl &aString) const { - } - - void ToUpperCase() { - } - - void ToUpperCase(nsStringImpl &aString) const { - } - - /*********************************** - Comparison methods... - ***********************************/ - - PRBool operator==(const nsStringImpl& aString) const {return Equals(aString);} - PRBool operator==(const CharType* aString) const {return Equals(aString);} - - PRBool operator!=(const nsStringImpl& aString) const {return PRBool(Compare(aString)!=0);} - PRBool operator!=(const CharType* aString) const {return PRBool(Compare(aString)!=0);} - - PRBool operator<(const nsStringImpl& aString) const {return PRBool(Compare(aString)<0);} - PRBool operator<(const CharType* aString) const {return PRBool(Compare(aString)<0);} - - PRBool operator>(const nsStringImpl& aString) const {return PRBool(Compare(aString)>0);} - PRBool operator>(const CharType* aString) const {return PRBool(Compare(aString)>0);} - - PRBool operator<=(const nsStringImpl& aString) const {return PRBool(Compare(aString)<=0);} - PRBool operator<=(const CharType* aString) const {return PRBool(Compare(aString)<=0);} - - PRBool operator>=(const nsStringImpl& aString) const {return PRBool(Compare(aString)>=0);} - PRBool operator>=(const CharType* aString) const {return PRBool(Compare(aString)>=0);} - - - PRInt32 Compare(const nsStringImpl& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; - PRInt32 Compare(const CharType* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; - - PRBool Equals(const nsStringImpl &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; - PRBool Equals(const CharType* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; - // PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const; - - - /*************************************** - These are string searching methods... - ***************************************/ - - PRInt32 FindChar(PRUnichar aChar) { - return -1; - } - - PRInt32 Find(const nsStringImpl& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const { - return -1; - } - - PRInt32 Find(const CharType* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const { - return -1; - } - - - PRInt32 FindCharInSet(const nsStringImpl& aString,PRInt32 anOffset=-1) const{ - return -1; - } - - PRInt32 FindCharInSet(const CharType* aString,PRInt32 anOffset=-1) const{ - return -1; - } - - PRInt32 FindChar(CharType aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const { - return -1; - } - - PRInt32 RFindChar(CharType aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const{ - return -1; - } - - PRInt32 RFind(const nsStringImpl& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const{ - return -1; - } - - PRInt32 RFind(const CharType* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const{ - return -1; - } - - PRInt32 RFindCharInSet(const nsStringImpl& aString,PRInt32 anOffset=-1) const { - return -1; - } - - PRInt32 RFindCharInSet(const CharType* aString,PRInt32 anOffset=-1) const{ - return -1; - } - - /*************************************** - These convert to a different type - ***************************************/ - - char* ToNewCString() const { - } - - char* ToNewUTF8String() const { - } - - PRUnichar* ToNewUnicode() const { - } - - char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const { - } - - float ToFloat(PRInt32* aErrorCode) const { - } - - PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const{ - } - - nsStringValueImpl mStringValue; -}; - - - -#endif diff --git a/xpcom/ds/nsStringValue.h b/xpcom/ds/nsStringValue.h deleted file mode 100644 index 6fc9b648d33b..000000000000 --- a/xpcom/ds/nsStringValue.h +++ /dev/null @@ -1,211 +0,0 @@ -! -/************************************************************************************* - * - * MODULES NOTES: - * - * 1. See nsStringImpl.h - * 2. We still have the ownership flag (bool) as a seperate data member. This will - * get merged into the length or capacity field after things stabilize a bit. - * (Likely only a few more days). - * - * Contributor(s): - * Rick Gessner - * - * History: * - * 02.29.2000: Original files (rickg) - * 03.02.2000: Flesh out the interface to be compatible with old library (rickg) - * - *************************************************************************************/ - - -#ifndef NSSTRINGVALUE_ -#define NSSTRINGVALUE_ - -#include "nsIAtom.h" -#include "nscore.h" -#include "nsMemory.h" -#include - -#if 0 -typedef int PRInt32; -typedef unsigned int PRUint32; -typedef short int PRUnichar; -typedef int nsresult; -typedef char PRBool; - -#define NS_OK 0 -#define NS_MEMORY_ERROR 1000 -#define PR_TRUE 1 -#define PR_FALSE 0 -#define NS_SUCCEEDED(x) (NS_OK==x) - -#endif - - -typedef long int _RefCountType; - -static const int kRadix10=10; -static const int kRadix16=16; -static const int kAutoDetect=100; -static const int kRadixUnknown=kAutoDetect+1; - -static const int kDefaultStringSize=64; -static const int kNotFound=-1; -#define IGNORE_CASE (PR_TRUE) - -class nsAReadableString { -public: - virtual PRUint32 Length() const =0; - -}; - -#define MODERN_CPP //make this false for aix/solaris... - -#ifdef MODERN_CPP -#define CONST_CAST(type,arg) const_cast(arg) -#else -#define CONST_CAST(type,arg) (type)arg -#endif - - -/*************************************************************************** - * - * The following (hack) template functions will go away, but for now they - * provide basic string copying and appending for my prototype. (rickg) - * - ***************************************************************************/ - -template -inline PRInt32 MinInt(T1 anInt1,T2 anInt2){ - return (anInt1<(T1)anInt2) ? anInt1 : anInt2; -} - -template -inline PRInt32 MaxInt(T1 anInt1,T2 anInt2){ - return (anInt1<(T1)anInt2) ? anInt2 : anInt1; -} - -inline size_t stringlen(const PRUnichar* theString) { - const PRUnichar* theEnd=theString; - while(*theEnd++); //skip to end of aDest... - size_t result=theEnd-theString-1; - return result; -} - -inline size_t stringlen(const char* theString) { - return ::strlen(theString); -} - - - -//---------------------------------------------------------------------------------------- - - -/*************************************************************************** - * - * This is the templatized base class from which stringvalues are derived. (rickg) - * - ***************************************************************************/ -template -struct nsStackBuffer { - nsStackBuffer(CharType *aBuffer,PRUint32 aLength,PRUint32 aCapacity) { - mBuffer=aBuffer; - mLength=aLength; - mCapacity=aCapacity; - } - CharType* mBuffer; - PRUint32 mLength; - PRUint32 mCapacity; -}; - - -#if 0 -template -struct RCBuffer { - - void* operator new(size_t aSize) { - CharType* theBuf = ::new CharType[aSize+1+sizeof(_RefCountType)]; - memset(theBuf,0xff,aSize+additionalBytes+1); - return theBuf; - } - - void operator delete(void *p, size_t aSize) { - ::delete [] p; - } - - _RefCountType mRefCount; - CharType mBuffer[1]; - -}; -#endif - - -/*************************************************************************** - * - * This is the templatized base class from which stringvalues are derived. (rickg) - * - ***************************************************************************/ -template -struct nsStringValueImpl { - - nsStringValueImpl() { - mBuffer=(CharType*)gCommonEmptyBuffer; - mLength=mCapacity=0; - mRefCount=2; //so we don't ever try to free the shared buffer - } - - nsStringValueImpl(const nsStringValueImpl& aCopy) { - mBuffer=aCopy.mBuffer; - mLength=aCopy.mLength; - mCapacity=aCopy.mCapacity; - mRefCount=1; - } - - nsStringValueImpl(const nsStringValueImpl& aCopy,PRInt32 aLength){ - mBuffer=aCopy.mBuffer; - mLength=aLength; - mCapacity=aCopy.mCapacity; - mRefCount=1; - } - - nsStringValueImpl(CharType* theString,PRInt32 aLength=-1,PRUint32 aCapacity=0) { - if(theString) { - mLength = (-1==aLength) ? stringlen(theString) : aLength; - mCapacity=(0==aCapacity) ? mLength+1 : aCapacity; - mBuffer=theString; - } - else { - mBuffer=(CharType*)gCommonEmptyBuffer; - mLength=mCapacity=0; - } - mRefCount=1; - } - - nsStringValueImpl(const nsStackBuffer &aBuffer) { - mCapacity=aBuffer.mCapacity; - mLength=aBuffer.mLength; - mBuffer=aBuffer.mBuffer; - mRefCount=2; //set it to 2 so we don't try to free it. - } - - void operator=(const nsStringValueImpl& aCopy) { - mBuffer=aCopy.mBuffer; - mLength=aCopy.mLength; - mCapacity=aCopy.mCapacity; - mRefCount=aCopy.mRefCount; - } - - void* GetBuffer() {return mBuffer;} - PRUint32 GetLength() {return mLength;} - PRUint32 GetCapacity() {return mCapacity;} - size_t GetCharSize() {return sizeof(CharType);} - - CharType* mBuffer; - PRUint32 mLength; - PRUint32 mCapacity; - PRUint32 mRefCount; -}; - - - -#endif diff --git a/xpcom/ds/nsStringx.cpp b/xpcom/ds/nsStringx.cpp deleted file mode 100644 index 09333205b485..000000000000 --- a/xpcom/ds/nsStringx.cpp +++ /dev/null @@ -1,1127 +0,0 @@ - -#include "nsString.h" -#include "nsBufferManager.h" -#include -#include -#include "nsMemory.h" - -static const char* kWhitespace="\b\t\r\n "; - - -void Subsume(nsStringValueImpl &aDest,nsStringValueImpl &aSource){ - if(aSource.mBuffer && aSource.mLength) { -#if 0 - if(aSource.mOwnsBuffer){ - nsStr::Destroy(aDest); - aDest.mStr=aSource.mStr; - aDest.mLength=aSource.mLength; - aDest.mCapacity=aSource.mCapacity; - aDest.mOwnsBuffer=aSource.mOwnsBuffer; - aSource.mOwnsBuffer=PR_FALSE; - aSource.mStr=0; - } - else{ - nsStr::StrAssign(aDest,aSource,0,aSource.mLength); - } -#endif - } - else SVTruncate(aDest,0); -} - - - //****************************************** - // Ctor's - //****************************************** - -nsCString::nsCString() : mStringValue() { -} - - //call this to copy construct nsCString -nsCString::nsCString(const nsCString& aString,PRInt32 aLength) : mStringValue() { - SVAppend(mStringValue,aString.mStringValue,aLength,0); -} - - //call this to construct from nsString -nsCString::nsCString(const nsString& aString,PRInt32 aLength) : mStringValue() { - SVAppend(mStringValue,aString.mStringValue,aLength,0); -} - - //call this version for char*'s.... -nsCString::nsCString(const char* aString,PRInt32 aLength) : mStringValue() { - Append(aString,aLength); -} - - //call this version for PRUnichar*'s.... -nsCString::nsCString(const PRUnichar* aString,PRInt32 aLength) : mStringValue() { - Append(aString,aLength,0); -} - - //call this version for a single char of type char... -nsCString::nsCString(nsSubsumeCStr &aSubsumeString) : mStringValue() { - mStringValue=aSubsumeString.mStringValue; - memset(&aSubsumeString.mStringValue,0,sizeof(mStringValue)); -} - - - //call this version for a single char of type char... -nsCString::nsCString(const char aChar) : mStringValue() { - Append(aChar); -} - - //call this version for all other ABT versions of readable strings -nsCString::nsCString(const nsAReadableString &aString) : mStringValue() { - Assign(aString); -} - -nsCString::~nsCString() { - SVFree(mStringValue); -} - - -void nsCString::Reinitialize(char* aBuffer,PRUint32 aCapacity,PRInt32 aLength) { - mStringValue.mBuffer=aBuffer; - mStringValue.mCapacity=aCapacity; - mStringValue.mLength=aLength; - mStringValue.mRefCount=1; -} - - - //****************************************** - // Concatenation operators - //****************************************** - -nsSubsumeCStr nsCString::operator+(const nsCString &aCString) { - nsCString theString(*this); - SVAppend(theString.mStringValue,aCString.mStringValue); - return nsSubsumeCStr(theString); -} - -nsSubsumeCStr nsCString::operator+(const char* aString) { - nsCString theTempString(*this); - nsStringValueImpl theTempStrValue(NS_CONST_CAST(char*,aString)); - SVAppend(theTempString.mStringValue,theTempStrValue); - return nsSubsumeCStr(theTempString); -} - -nsSubsumeCStr nsCString::operator+(char aChar) { - nsCString theTempString(*this); - theTempString.Append(aChar); - return nsSubsumeCStr(theTempString); -} - - //****************************************** - // Assigment operators - //****************************************** - -nsCString& nsCString::operator=(const nsCString& aString) { - if(aString.mStringValue.mBuffer!=mStringValue.mBuffer) { - Assign(aString); - } - return *this; -} - -nsCString& nsCString::operator=(const nsString &aString) { - Assign(aString); - return *this; -} - -nsCString& nsCString::operator=(const char *aString) { - if(mStringValue.mBuffer!=aString) { - nsStringValueImpl theStringValue(NS_CONST_CAST(char*,aString)); - SVAssign(mStringValue,theStringValue,theStringValue.mLength,0); - } - return *this; -} - -nsCString& nsCString::operator=(const PRUnichar *aString) { - nsStringValueImpl theStringValue(NS_CONST_CAST(PRUnichar*,aString)); - Assign(aString); - return *this; -} - -nsCString& nsCString::operator=(const char aChar) { - Assign(aChar); - return *this; -} - -nsCString& nsCString::operator=(const nsSubsumeCStr &aSubsumeString) { - mStringValue=aSubsumeString.mStringValue; - memset((void*)&aSubsumeString.mStringValue,0,sizeof(mStringValue)); - return *this; -} - - - //****************************************** - // Here are the accessor methods... - //****************************************** - - -nsresult nsCString::SetCapacity(PRUint32 aCapacity) { - if(aCapacity>mStringValue.mCapacity) { - SVRealloc(mStringValue,aCapacity); - } - return NS_OK; -} - -// operator const char* const() {return mStringValue.mBuffer;} - - -PRBool nsCString::SetCharAt(char aChar,PRUint32 anIndex) { - PRBool result=PR_FALSE; - if(anIndex &aString,PRInt32 aLength,PRUint32 aSrcOffset) { - return NS_OK; -} - - -/* - * This method appends an nsCString - * - * @update rickg 03.01.2000 - * @param aString -- source String to be inserted into this - * @param aLength -- number of chars to be copied from aCopy - * @param aSrcOffset -- insertion position within this str - * @return this - */ -nsresult nsCString::Append(const nsCString &aString,PRInt32 aLength,PRUint32 aSrcOffset) { - return SVAppend (mStringValue,aString.mStringValue,aLength,aSrcOffset); -} - -/* - * This method appends an nsString - * - * @update rickg 03.01.2000 - * @param aString -- source String to be inserted into this - * @param aLength -- number of chars to be copied from aCopy - * @param aSrcOffset -- insertion position within this str - * @return this - */ -nsresult nsCString::Append(const nsString &aString,PRInt32 aLength,PRUint32 aSrcOffset) { - return SVAppend(mStringValue,aString.mStringValue,aString.mStringValue.mLength,aSrcOffset); -} - - //append from a char* -nsresult nsCString::Append(const char* aString,PRInt32 aLength,PRUint32 aSrcOffset) { - nsresult result=NS_OK; - if(aString) { - nsStringValueImpl theStringValue(NS_CONST_CAST(char*,aString),aLength); - result=SVAppend(mStringValue,theStringValue,aLength,aSrcOffset); - } - return result; -} - - //append from a char -nsresult nsCString::Append(const char aChar) { - - if(mStringValue.mLength==mStringValue.mCapacity) { - SVRealloc(mStringValue,mStringValue.mCapacity+5); - } - - if(mStringValue.mLength theStringValue(theBuffer,1); - return SVAppend(mStringValue,theStringValue,1,0); -} - - //append from a PRUnichar* -nsresult nsCString::Append(const PRUnichar* aString,PRInt32 aLength,PRUint32 aSrcOffset) { - nsresult result=NS_OK; - if(aString) { - nsStringValueImpl theStringValue(NS_CONST_CAST(PRUnichar*,aString),aLength); - result=SVAppend(mStringValue,theStringValue,aLength,aSrcOffset); - } - return result; -} - - //append from an nsAReadableString (the ABT) -nsresult nsCString::Append(const nsAReadableString &aString,PRInt32 aLength,PRUint32 aSrcOffset) { - return SVAppendReadable(mStringValue,aString,aLength,aSrcOffset); -} - - //append an integer -nsresult nsCString::Append(PRInt32 anInteger,PRInt32 aRadix) { - nsresult result=NS_OK; - - PRUint32 theInt=(PRUint32)anInteger; - - char buf[]={'0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; - - PRInt32 radices[] = {1000000000,268435456}; - PRInt32 mask1=radices[16==aRadix]; - - PRInt32 charpos=0; - if(anInteger<0) { - theInt*=-1; - if(10==aRadix) { - buf[charpos++]='-'; - } - else theInt=(int)~(theInt-1); - } - - PRBool isfirst=PR_TRUE; - while(mask1>=1) { - PRInt32 theDiv=theInt/mask1; - if((theDiv) || (!isfirst)) { - buf[charpos++]="0123456789abcdef"[theDiv]; - isfirst=PR_FALSE; - } - theInt-=theDiv*mask1; - mask1/=aRadix; - } - return Append(buf); - - return result; -} - - //Append a float -nsresult nsCString::Append(float aFloat) { - nsresult result=NS_OK; - char buf[40]; - sprintf(buf,"%g",aFloat); - - Append(buf); - - return result; -} - - - //*************************************** - // Here come a few deletion methods... - //*************************************** - -nsresult nsCString::Cut(PRUint32 anOffset,PRInt32 aCount) { - return (0 theStringValue(NS_CONST_CAST(char*,aString),aLength); - - if(0 theStringValue(theBuffer,1); - - return SVInsert(mStringValue,anOffset,theStringValue,1,0); -} - - - //******************************************* - // Here come inplace replacement methods... - //******************************************* - -/** - * swaps occurence of 1 char for another - * - * @return this - */ -nsresult nsCString::ReplaceChar(char anOldChar,char aNewChar){ - char *root_cp=mStringValue.mBuffer; - char *null_cp=root_cp+mStringValue.mLength; - - while(root_cp theTarget(NS_CONST_CAST(char*,aTarget)); - const nsStringValueImpl theNewValue(NS_CONST_CAST(char*,aNewValue)); - - return SVReplace(mStringValue,theTarget,theNewValue,mStringValue.mLength,0); -} - - //******************************************* - // Here come the stripchar methods... - //******************************************* - -/** - * This method is used to remove all occurances of the - * given character from this string. - * - * @update rickg 03.01.2000 - * @param aChar -- char to be stripped - * @param anOffset -- where in this string to start stripping chars - * @return *this - */ -nsresult nsCString::StripChar(char aChar,PRUint32 anOffset){ - return SVStripChar(mStringValue,aChar,mStringValue.mLength,anOffset); -} - -/** - * This method is used to remove all occurances of the - * given character from this string. - * - * @update rickg 03.01.2000 - * @param aChar -- char to be stripped - * @param anOffset -- where in this string to start stripping chars - * @return *this - */ -nsresult nsCString::StripChar(PRInt32 anInt,PRUint32 anOffset){ - return SVStripChar(mStringValue,(char)anInt,mStringValue.mLength,anOffset); -} - -/** - * This method is used to remove all occurances of the - * characters found in aSet from this string. - * - * @update rickg 03.01.2000 - * @param aSet -- characters to be cut from this - * @return *this - */ -nsresult nsCString::StripChars(const char* aSet,PRInt32 aLength){ - nsStringValueImpl theSet(NS_CONST_CAST(char*,aSet),aLength); - return SVStripCharsInSet(mStringValue,aSet,mStringValue.mLength,0); -} - -/** - * This method strips whitespace throughout the string - * - * @update rickg 03.01.2000 - * @return this - */ -nsresult nsCString::StripWhitespace() { - static const char* kWhitespace="\b\t\r\n "; - return StripChars(kWhitespace); -} - - //************************************************** - // Here are some methods that extract substrings... - //************************************************** - -nsresult nsCString::Left(nsCString& aCopy,PRInt32 aCount) const { - aCount = (aCount<0) ? mStringValue.mLength : (aCount<(PRInt32)mStringValue.mLength) ? aCount : mStringValue.mLength; - return aCopy.Assign(*this,aCount,0); -} - -nsresult nsCString::Mid(nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount) const { - aCount = (aCount<0) ? mStringValue.mLength : (aCount<(PRInt32)mStringValue.mLength) ? aCount : mStringValue.mLength; - return aCopy.Assign(*this,aCount,anOffset); -} - -nsresult nsCString::Right(nsCString& aCopy,PRInt32 aCount) const { - PRUint32 theLen=mStringValue.mLength-aCount; - PRInt32 offset=(theLen<0) ? 0 : theLen; - return Mid(aCopy,offset,aCount); -} - - - //******************************************* - // Here come the operator+=() methods... - //******************************************* - - -nsCString& nsCString::operator+=(const char* aString) { - Append(aString); - return *this; -} - -nsCString& nsCString::operator+=(const PRUnichar* aString) { - Append(aString); - return *this; -} - -nsCString& nsCString::operator+=(const nsCString& aCString) { - Append(aCString); - return *this; -} - -nsCString& nsCString::operator+=(const char aChar) { - char theBuffer[]={aChar,0}; - Append(theBuffer,1); - return *this; -} - -nsCString& nsCString::operator+=(const PRUnichar aChar) { - PRUnichar theBuffer[]={aChar,0}; - Append(theBuffer,1); - return *this; -} - -nsCString& nsCString::operator+=(const int anInt){ - Append(anInt,10); - return *this; -} - -void nsCString::ToLowerCase() { - SVToLowerCase(mStringValue); -} - -void nsCString::ToLowerCase(nsCString &aString) const { - aString=*this; - aString.ToLowerCase(); -} - -void nsCString::ToUpperCase() { - SVToUpperCase(mStringValue); -} - -void nsCString::ToUpperCase(nsCString &aString) const { - aString=*this; - aString.ToUpperCase(); -} - - -PRInt32 nsCString::Compare(const nsCString &aString,PRBool aIgnoreCase,PRInt32 aCount) const { - return SVCompareChars(mStringValue,aString.mStringValue,aIgnoreCase,aCount); -} - -PRInt32 nsCString::Compare(const char* aString,PRBool aIgnoreCase,PRInt32 aCount) const { - nsStringValueImpl theStringValue(NS_CONST_CAST(char*,aString),aCount); - return SVCompareChars(mStringValue,theStringValue,aIgnoreCase,aCount); -} - -PRInt32 nsCString::Compare(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 aCount) const { - nsStringValueImpl theStringValue(NS_CONST_CAST(PRUnichar*,aString),aCount); - return SVCompare(mStringValue,theStringValue,aIgnoreCase,aCount); -} - -PRBool nsCString::Equals(const nsString &aString,PRBool aIgnoreCase,PRInt32 aCount) const { - return PRBool(0==SVCompare(mStringValue,aString.mStringValue,aIgnoreCase,aCount)); -} - -PRBool nsCString::Equals(const nsCString &aString,PRBool aIgnoreCase,PRInt32 aCount) const { - PRInt32 result=SVCompareChars(mStringValue,aString.mStringValue,aIgnoreCase,aCount); - return PRBool(0==result); -} - -PRBool nsCString::Equals(const char* aString,PRBool aIgnoreCase,PRInt32 aCount) const { - nsStringValueImpl theStringValue(NS_CONST_CAST(char*,aString),aCount); - return PRBool(0==SVCompareChars(mStringValue,theStringValue,aIgnoreCase,aCount)); -} - - -PRBool nsCString::Equals(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 aCount) const { - nsStringValueImpl theStringValue(NS_CONST_CAST(PRUnichar*,aString),aCount); - return PRBool(0==SVCompare(mStringValue,theStringValue,aIgnoreCase,aCount)); -} - - -PRBool nsCString::Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const { - return PR_TRUE; -} - - -/*************************************** - These are string searching methods... - ***************************************/ - -/** - * search for given string within this string - * - * @update rickg 03.01.2000 - * @param aString - substr to be found - * @param aIgnoreCase tells us whether or not to do caseless compare - * @param anOffset tells us where in this string to start searching - * @param aRepCount tells us how many iterations to make starting at the given offset - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 nsCString::Find(const nsString& aTarget,PRBool aIgnoreCase,PRUint32 anOffset,PRInt32 aRepCount) const { - return SVFind(mStringValue,aTarget.mStringValue,aIgnoreCase,aRepCount,anOffset); -} - -/** - * search for given string within this string - * - * @update rickg 03.01.2000 - * @param aString - substr to be found - * @param aIgnoreCase tells us whether or not to do caseless compare - * @param anOffset tells us where in this string to start searching - * @param aRepCount tells us how many iterations to make starting at the given offset - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 nsCString::Find(const nsCString &aString,PRBool aIgnoreCase,PRUint32 anOffset,PRInt32 aRepCount) const { - return SVFind(mStringValue,aString.mStringValue,aIgnoreCase,aRepCount,anOffset); -} - -/** - * search for given string within this char* string - * - * @update rickg 03.01.2000 - * @param aString - substr to be found - * @param aIgnoreCase tells us whether or not to do caseless compare - * @param anOffset tells us where in this string to start searching - * @param aRepCount tells us how many iterations to make starting at the given offset - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 nsCString::Find(const char* aString,PRBool aIgnoreCase,PRUint32 anOffset,PRInt32 aRepCount) const { - nsStringValueImpl theString(NS_CONST_CAST(char*,aString)); - return SVFind(mStringValue,theString,aIgnoreCase,aRepCount,anOffset); -} - -/** - * search for given string within this PRUnichar* string - * - * @update rickg 03.01.2000 - * @param aString - substr to be found - * @param aIgnoreCase tells us whether or not to do caseless compare - * @param anOffset tells us where in this string to start searching - * @param aRepCount tells us how many iterations to make starting at the given offset - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 nsCString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRUint32 anOffset,PRInt32 aRepCount) const { - - nsStringValueImpl theString(NS_CONST_CAST(PRUnichar*,aString)); - return SVFind(mStringValue,theString,aIgnoreCase,aRepCount,anOffset); -} - -/** - * This method finds the offset of the first char in this string that is - * a member of the given charset, starting the search at anOffset - * - * @update rickg 03.01.2000 - * @param aString contains set of chars to be found - * @param anOffset -- where in this string to start searching - * @return - */ -PRInt32 nsCString::FindCharInSet(const nsCString& aString,PRUint32 anOffset) const{ - return SVFindCharInSet(mStringValue,aString.mStringValue,PR_FALSE,mStringValue.mLength,anOffset); -} - - -/** - * This method finds the offset of the first char in this string that is - * a member of the given charset, starting the search at anOffset - * - * @update rickg 03.01.2000 - * @param aString contains set of chars to be found - * @param anOffset -- where in this string to start searching - * @return - */ -PRInt32 nsCString::FindCharInSet(const char *aString,PRUint32 anOffset) const{ - - nsStringValueImpl theStringValue(NS_CONST_CAST(char*,aString)); - return SVFindCharInSet(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset); -} - -/** - * Search for a given char, starting at given offset - * - * @update rickg 03.01.2000 - * @param aChar is the unichar to be sought - * @param aIgnoreCase tells us whether or not to do caseless compare - * @param anOffset tells us where in this string to start searching - * @param aCount tells us how many iterations to make starting at the given offset - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 nsCString::FindChar(char aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const { - return SVFindChar(mStringValue,aChar,aIgnoreCase,aCount,anOffset); -} - -/** - * Reverse search for given char within this string - * - * @update gess 3/25/98 - * @param aChar - char to be found - * @param aIgnoreCase tells us whether or not to do caseless compare - * @param anOffset tells us where in this string to start searching (-1 means start at end) - * @param aRepCount tells us how many iterations to make starting at the given offset - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 nsCString::RFindChar(char aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aRepCount) const{ - return SVRFindChar(mStringValue,aChar,aIgnoreCase,aRepCount,anOffset); -} - - -PRInt32 nsCString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aRepCount) const{ - nsStringValueImpl theStringValue(NS_CONST_CAST(char*,aString)); - return SVRFind(mStringValue,theStringValue,aIgnoreCase,aRepCount,anOffset); -} - - -/** - * This method finds (in reverse) the offset of the first char in this string that is - * a member of the given charset, starting the search at anOffset - * - * @update rickg 03.01.2000 - * @param aString contains set of chars to be found - * @param anOffset -- where in this string to start searching - * @return - */ -PRInt32 nsCString::RFindCharInSet(const nsCString& aString,PRInt32 anOffset) const { - return SVRFindCharInSet(mStringValue,aString.mStringValue,PR_FALSE,mStringValue.mLength,anOffset); -} - - -/** - * This method finds (in reverse) the offset of the first char in this string that is - * a member of the given charset, starting the search at anOffset - * - * @update rickg 03.01.2000 - * @param aString contains set of chars to be found - * @param anOffset -- where in this string to start searching - * @return - */ -PRInt32 nsCString::RFindCharInSet(const char* aString,PRInt32 anOffset) const{ - nsStringValueImpl theStringValue(NS_CONST_CAST(char*,aString)); - return SVRFindCharInSet(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset); -} - -/*************************************** - These convert to a different type - ***************************************/ - -void nsCString::Recycle(nsCString* aString) { - //NOT IMPLEMENTED -} - -nsCString* nsCString::CreateString(void) { - return 0; //NOT IMPLEMENTED -} - -/** - * This method constructs a new nsString is a clone of this string. - */ -nsCString* nsCString::ToNewString() const { - return 0; //NOT IMPLEMENTED -} - - -char* nsCString::ToNewCString() const { - return 0; //NOT IMPLEMENTED -} - -char* nsCString::ToNewUTF8String() const { - return 0; //NOT IMPLEMENTED -} - -PRUnichar* nsCString::ToNewUnicode() const { - return 0; //NOT IMPLEMENTED -} - -char* nsCString::ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset) const { - int len=(mStringValue.mLength PRInt32(sizeof(buf)-1)) { - *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; - return 0.0f; - } - char* cp = ToCString(buf, sizeof(buf)); - float f = (float) strtod(cp, &cp); - if (*cp != 0) { - *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; - } - *aErrorCode = (PRInt32) NS_OK; - return f; -} - - -/** - * Perform string to int conversion. - * @param aErrorCode will contain error if one occurs - * @param aRadix tells us which radix to assume; kAutoDetect tells us to determine the radix for you. - * @return int rep of string value, and possible (out) error code - */ -PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const{ - return SVToInteger(mStringValue,anErrorCode,aRadix); -} - - - -/***************************************************************** - Now we define the nsSubsumeCStr class - *****************************************************************/ - -nsSubsumeCStr::nsSubsumeCStr(nsCString& aString) : nsCString() { - mStringValue=aString.mStringValue; - mOwnsBuffer=PR_TRUE; - aString.mStringValue.mBuffer=0; - aString.mStringValue.mRefCount=0; -} - -nsSubsumeCStr::nsSubsumeCStr(char* aString,PRBool assumeOwnership,PRInt32 aLength) : nsCString() { - mStringValue.mBuffer=aString; - mStringValue.mCapacity=mStringValue.mLength=(-1==aLength) ? stringlen(aString) : aLength; - mOwnsBuffer=assumeOwnership; -} - - -/** - * - * @update gess 01/04/99 - * @param - * @return - */ -NS_COM int fputs(const nsCString& aString, FILE* out) -{ - char buf[100]; - char* cp = buf; - PRInt32 len = aString.Length(); - if (len >= PRInt32(sizeof(buf))) { - cp = aString.ToNewCString(); - } else { - aString.ToCString(cp, len + 1); - } - if(len>0) - ::fwrite(cp, 1, len, out); - if (cp != buf) { - delete[] cp; - } - return (int) len; -} - -PRUint32 HashCode(const nsCString& aDest) { - PRUint32 result=0; -// return (PRUint32)PL_HashString((const void*) aDest.GetBuffer()); - return result; -} - -void Recycle( char* aBuffer) { - nsMemory::Free(aBuffer); -} - -/***************************************************************** - Now we declare the nsCAutoString class - *****************************************************************/ - - -nsCAutoString::nsCAutoString() : nsCString() { - mInternalBuffer[0]=0; - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - mStringValue.mRefCount=2; -} - - //call this version nsAutoString derivatives... -nsCAutoString::nsCAutoString(const nsCAutoString& aString,PRInt32 aLength) : nsCString() { - mInternalBuffer[0]=0; - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - mStringValue.mRefCount=2; - nsCString::Assign(aString,aLength,0); -} - -//call this version for nsCString,nsCString and the autostrings -nsCAutoString::nsCAutoString(const nsCString& aString,PRInt32 aLength) : nsCString() { - mInternalBuffer[0]=0; - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - mStringValue.mRefCount=2; - nsCString::Assign(aString,aLength,0); -} - - //call this version for char*'s.... -nsCAutoString::nsCAutoString(const char* aString,PRInt32 aLength) : nsCString() { - mInternalBuffer[0]=0; - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - mStringValue.mRefCount=2; - nsCString::Assign(aString,aLength,0); -} - - //call this version for a single char of type char... -nsCAutoString::nsCAutoString(const char aChar) : nsCString() { - mInternalBuffer[0]=0; - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - mStringValue.mRefCount=2; - nsCString::Assign(aChar); -} - - - //call this version for PRUnichar*'s.... -nsCAutoString::nsCAutoString(const PRUnichar* aString,PRInt32 aLength) : nsCString() { - mInternalBuffer[0]=0; - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - mStringValue.mRefCount=2; - nsCString::Assign(aString,aLength); -} - - - //call this version for all other ABT versions of readable strings -nsCAutoString::nsCAutoString(const nsAReadableString &aString) : nsCString() { - mInternalBuffer[0]=0; - mStringValue.mCapacity=kDefaultStringSize; - mStringValue.mBuffer=mInternalBuffer; - mStringValue.mRefCount=2; - nsCString::Assign(aString); -} - -nsCAutoString::nsCAutoString(const CBufDescriptor &aBuffer) : nsCString() { - mInternalBuffer[0]=0; - mStringValue.mBuffer=aBuffer.mBuffer; - mStringValue.mCapacity=aBuffer.mCapacity; - mStringValue.mLength=aBuffer.mLength; - mStringValue.mRefCount=(aBuffer.mOwnsBuffer) ? 1 : 2; -} - -nsCAutoString::nsCAutoString(const nsSubsumeCStr& aSubsumeString) : nsCString() { - mInternalBuffer[0]=0; - mStringValue=aSubsumeString.mStringValue; - memset((void*)&aSubsumeString.mStringValue,0,sizeof(mStringValue)); -} - -nsCAutoString::~nsCAutoString() { -} - - -nsCAutoString& nsCAutoString::operator=(const nsCAutoString& aString) { - nsCString::operator=(aString); - return *this; -} - -nsCAutoString& nsCAutoString::operator=(const nsCString& aString) { - nsCString::operator=(aString); - return *this; -} - -nsCAutoString& nsCAutoString::operator=(const char* aString) { - nsCString::operator=(aString); - return *this; -} - -nsCAutoString& nsCAutoString::operator=(const PRUnichar* aString) { - nsCString::operator=(aString); - return *this; -} - -nsCAutoString& nsCAutoString::operator=(const char aChar) { - nsCString::operator=(aChar); - return *this; -} - - -nsCAutoString& nsCAutoString::operator=(const nsSubsumeCStr &aSubsumeString) { - nsCString::operator=(aSubsumeString); - return *this; -} - diff --git a/xpcom/ds/nsStringx.h b/xpcom/ds/nsStringx.h deleted file mode 100644 index a89627163a33..000000000000 --- a/xpcom/ds/nsStringx.h +++ /dev/null @@ -1,525 +0,0 @@ -/***************************************************************************************************************** - * - * This template provides the basic implementation for nsCString. - * - * Contributor(s): - * Rick Gessner - * - * History: - * - * 02.29.2000: Original files (rickg) - * 03.02.2000: Expand the API's to be a bit more realistic (rickg): - * 1. Flesh out the interface to be compatible with old library - * 2. Enable both nsCString-based interfaces and nsAReadableString interfaces - * 3. Build enough infrastructure to test nsCString(s) and nsImmutableString constructions. - * 03.03.2000: Finished mapping original nsCString functionality to template form (rickg) - * - *****************************************************************************************************************/ - - -#ifndef _NS_CSTRING_ -#define _NS_CSTRING_ - -#include "nsStringValue.h" -#include "nsString2.h" -#include - - -class NS_COM nsSubsumeCStr; - -/*************************************************************************** - * - * This is the templatized base class from which stringvalues are derived. (rickg) - * - ***************************************************************************/ -struct CBufDescriptor { - CBufDescriptor(char *aBuffer,PRUint32 aLength,PRUint32 aCapacity,PRBool aOwnsBuffer) { - mBuffer=aBuffer; - mLength=aLength; - mCapacity=aCapacity-1; - mOwnsBuffer=aOwnsBuffer; - } - char* mBuffer; - PRUint32 mLength; - PRUint32 mCapacity; - PRBool mOwnsBuffer; -}; - - -class NS_COM nsCString { -public: - - //****************************************** - // Ctor's - //****************************************** - - nsCString(); - - //copy constructor - nsCString(const nsCString& aString,PRInt32 aLength=-1); - - //constructor from nsString - nsCString(const nsString& aString,PRInt32 aLength=-1); - - //call this version for char*'s.... - nsCString(const char* aString,PRInt32 aLength=-1) ; - - //call this version for a single char - nsCString(const char aChar); - - //call this version for PRUnichar*'s.... - nsCString(const PRUnichar* aString,PRInt32 aLength=-1) ; - - //call this version for stack-based string buffers... - nsCString(const nsSubsumeCStr &aSubsumeString); - - //call this version for stack-based string buffers... - nsCString(nsSubsumeCStr &aSubsumeString); - - //call this version for cbufdescriptor string buffers... - nsCString(const CBufDescriptor &aSubsumeString); - - //call this version for all other ABT versions of readable strings - nsCString(const nsAReadableString &aString) ; - - virtual ~nsCString(); - - void Reinitialize(char* aBuffer,PRUint32 aCapacity,PRInt32 aLength=-1); - - //****************************************** - // Concat operators - //****************************************** - - nsSubsumeCStr operator+(const nsCString &aCString); - nsSubsumeCStr operator+(const char* aCString); - nsSubsumeCStr operator+(char aChar); - - - //****************************************** - // Assigment operators - //****************************************** - - - nsCString& operator=(const nsCString& aString); - nsCString& operator=(const nsString& aString); - nsCString& operator=(const char* aString); - nsCString& operator=(const PRUnichar* aString); - nsCString& operator=(const char aChar); - nsCString& operator=(const nsSubsumeCStr &aBufDescriptor); - - //****************************************** - // Here are the accessor methods... - //****************************************** - - virtual nsresult SetLength(PRUint32 aLength) { - if(aLength>mStringValue.mLength) - SetCapacity(aLength); - Truncate(aLength); - return NS_OK; - } - - virtual nsresult SetCapacity(PRUint32 aCapacity); - - char* GetBuffer() const { return mStringValue.mBuffer;} - - char operator[](PRUint32 aOffset) const {return CharAt(aOffset);} - - operator const char*() const {return (const char*)mStringValue.mBuffer;} - operator char*() const {return mStringValue.mBuffer;} - - PRUint32 Length() const {return mStringValue.mLength;} - PRUint32 Capacity() const {return mStringValue.mCapacity;} - - size_t GetCharSize() const {return sizeof(mStringValue.mBuffer[0]);} - - PRBool IsUnicode() const {return PR_FALSE;} - - PRBool IsEmpty(void) const {return PRBool(mStringValue.mLength==0);} - - char CharAt(PRUint32 anIndex) const { - return (anIndex(const nsCString& aString) const {return PRBool(Compare(aString)>0);} - PRBool operator>(const PRUnichar* aString) const {return PRBool(Compare(aString)>0);} - PRBool operator>(const char* aString) const {return PRBool(Compare(aString)>0);} - - PRBool operator<=(const nsCString& aString) const {return PRBool(Compare(aString)<=0);} - PRBool operator<=(const PRUnichar* aString) const {return PRBool(Compare(aString)<=0);} - PRBool operator<=(const char* aString) const {return PRBool(Compare(aString)<=0);} - - PRBool operator>=(const nsCString& aString) const {return PRBool(Compare(aString)>=0);} - PRBool operator>=(const PRUnichar* aString) const {return PRBool(Compare(aString)>=0);} - PRBool operator>=(const char* aString) const {return PRBool(Compare(aString)>=0);} - - - PRInt32 Compare(const nsCString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; - PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; - PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const ; - - PRBool Equals(const nsCString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; - PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; - PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; - PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const; - PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const; - - PRBool EqualsIgnoreCase(const nsCString &aString) const {return Equals(aString,PR_TRUE);} - PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const {return Equals(aString,PR_TRUE);} - PRBool EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const; - - - /*************************************** - These are string searching methods... - ***************************************/ - - /** - * search for given string within this string - * - * @update rickg 03.01.2000 - * @param aString - substr to be found - * @param aIgnoreCase tells us whether or not to do caseless compare - * @param anOffset tells us where in this string to start searching - * @param aRepCount tells us how many iterations to make starting at the given offset - * @return offset in string, or -1 (kNotFound) - */ - PRInt32 Find(const nsCString& aTarget,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0,PRInt32 aRepCount=-1) const; - PRInt32 Find(const nsString& aTarget,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0,PRInt32 aRepCount=-1) const; - PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0,PRInt32 aRepCount=-1) const; - PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0,PRInt32 aRepCount=-1) const; - PRInt32 FindChar(char aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aRepCount=-1) const ; - - PRInt32 FindCharInSet(const nsCString& aString,PRUint32 anOffset=0) const; - PRInt32 FindCharInSet(const nsString& aString,PRUint32 anOffset=0) const; - PRInt32 FindCharInSet(const char *aString,PRUint32 anOffset=0) const; - - PRInt32 RFind(const nsCString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aRepCount=-1) const; - PRInt32 RFind(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aRepCount=-1) const; - PRInt32 RFindChar(char aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aRepCount=-1) const; - - PRInt32 RFindCharInSet(const nsCString& aString,PRInt32 anOffset=-1) const ; - PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const; - - /*************************************** - These convert to a different type - ***************************************/ - - static void Recycle(nsCString* aString); - - static nsCString* CreateString(void); - - nsCString* ToNewString() const; - - char* ToNewCString() const; - - char* ToNewUTF8String() const; - - PRUnichar* ToNewUnicode() const; - - char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const; - - - //****************************************** - // Utility methods - //****************************************** - - PRInt32 CountChar(char aChar); - - //This will not work correctly for any unicode set other than ascii - void DebugDump(void) const; - - /** - * Perform string to float conversion. - * @param aErrorCode will contain error if one occurs - * @return float rep of string value - */ - float ToFloat(PRInt32* aErrorCode) const; - - /** - * Perform string to int conversion. - * @param aErrorCode will contain error if one occurs - * @param aRadix tells us which radix to assume; kAutoDetect tells us to determine the radix for you. - * @return int rep of string value, and possible (out) error code - */ - PRInt32 ToInteger(PRInt32* anErrorCode,PRUint32 aRadix=kAutoDetect) const; - - void ToLowerCase(); - - void ToLowerCase(nsCString &aString) const; - - void ToUpperCase(); - - void ToUpperCase(nsCString &aString) const; - - -protected: - - nsStringValueImpl mStringValue; - - friend class nsString; - friend class nsSubsumeCStr; - friend class nsCAutoString; -}; - -/***************************************************************** - Now we declare the nsSubsumeCStr class - *****************************************************************/ - -class NS_COM nsSubsumeCStr : public nsCString { -public: - nsSubsumeCStr(nsCString& aString); - nsSubsumeCStr(char* aString,PRBool assumeOwnership,PRInt32 aLength=-1); - - PRBool mOwnsBuffer; -}; - - -/***************************************************************** - Now we declare the nsCAutoString class - *****************************************************************/ - - -class NS_COM nsCAutoString : public nsCString { -public: - - nsCAutoString() ; - - //call this version nsAutoString derivatives... - nsCAutoString(const nsCAutoString& aString,PRInt32 aLength=-1); - - //call this version for nsCString,nsCString and the autostrings - nsCAutoString(const nsCString& aString,PRInt32 aLength=-1) ; - //call this version for char*'s.... - nsCAutoString(const char* aString,PRInt32 aLength=-1); - - //call this version for a single char of type char... - nsCAutoString(const char aChar) ; - - //call this version for PRUnichar*'s.... - nsCAutoString(const PRUnichar* aString,PRInt32 aLength=-1) ; - - //call this version for all other ABT versions of readable strings - nsCAutoString(const nsAReadableString &aString); - - nsCAutoString(const CBufDescriptor&aBuffer) ; - - nsCAutoString(const nsSubsumeCStr& aSubsumeString) ; - - virtual ~nsCAutoString() ; - - - nsCAutoString& operator=(const nsCAutoString& aCopy) ; - - nsCAutoString& operator=(const nsCString& aString) ; - - nsCAutoString& operator=(const char* aString) ; - - nsCAutoString& operator=(const PRUnichar* aString) ; - - nsCAutoString& operator=(const char aChar) ; - - nsCAutoString& operator=(const nsSubsumeCStr &aSubsumeString); - -protected: - char mInternalBuffer[kDefaultStringSize+1]; -}; - -extern PRUint32 HashCode(const nsCString& aDest); -extern NS_COM int fputs(const nsCString& aString, FILE* out); -extern NS_COM void Recycle( char* aBuffer); - -#endif -