diff --git a/mozilla/string/obsolete/nsStr.cpp b/mozilla/string/obsolete/nsStr.cpp index 27b8715df4d..4acc9ab610d 100644 --- a/mozilla/string/obsolete/nsStr.cpp +++ b/mozilla/string/obsolete/nsStr.cpp @@ -37,7 +37,6 @@ * * ***** END LICENSE BLOCK ***** */ -#include "nsStrPrivate.h" #include "nsStr.h" #include "bufferRoutines.h" #include //only used for printf @@ -72,7 +71,7 @@ static PRBool gStringAcquiredMemory = PR_TRUE; * @param * @return */ -void nsStrPrivate::Initialize(nsStr& aDest,eCharSize aCharSize) { +void nsStr::Initialize(nsStr& aDest,eCharSize aCharSize) { aDest.mStr=(char*)gCommonEmptyBuffer; aDest.mLength=0; aDest.SetInternalCapacity(0); @@ -86,7 +85,7 @@ void nsStrPrivate::Initialize(nsStr& aDest,eCharSize aCharSize) { * @param * @return */ -void nsStrPrivate::Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 aLength,eCharSize aCharSize,PRBool aOwnsBuffer){ +void nsStr::Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 aLength,eCharSize aCharSize,PRBool aOwnsBuffer){ aDest.mStr=(aCString) ? aCString : (char*)gCommonEmptyBuffer; aDest.mLength=aLength; aDest.SetInternalCapacity(aCapacity); @@ -100,7 +99,7 @@ void nsStrPrivate::Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRU * @param * @return */ -void nsStrPrivate::Destroy(nsStr& aDest) { +void nsStr::Destroy(nsStr& aDest) { if((aDest.mStr) && (aDest.mStr!=(char*)gCommonEmptyBuffer)) { Free(aDest); } @@ -114,7 +113,7 @@ void nsStrPrivate::Destroy(nsStr& aDest) { * @param aNewLength -- new capacity of string in charSize units * @return void */ -PRBool nsStrPrivate::EnsureCapacity(nsStr& aString,PRUint32 aNewLength) { +PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength) { PRBool result=PR_TRUE; if(aNewLength>aString.GetCapacity()) { result=Realloc(aString,aNewLength); @@ -131,11 +130,11 @@ PRBool nsStrPrivate::EnsureCapacity(nsStr& aString,PRUint32 aNewLength) { * @param aNewLength -- new capacity of string in charSize units * @return void */ -PRBool nsStrPrivate::GrowCapacity(nsStr& aDest,PRUint32 aNewLength) { +PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength) { PRBool result=PR_TRUE; if(aNewLength>aDest.GetCapacity()) { nsStr theTempStr; - nsStrPrivate::Initialize(theTempStr,eCharSize(aDest.GetCharSize())); + nsStr::Initialize(theTempStr,eCharSize(aDest.GetCharSize())); // the new strategy is, allocate exact size, double on grows if ( aDest.GetCapacity() ) { @@ -168,7 +167,7 @@ PRBool nsStrPrivate::GrowCapacity(nsStr& aDest,PRUint32 aNewLength) { * @param aSource is where chars are copied from * @param aCount is the number of chars copied from aSource */ -void nsStrPrivate::StrAssign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount){ +void nsStr::StrAssign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount){ if(&aDest!=&aSource){ StrTruncate(aDest,0); StrAppend(aDest,aSource,anOffset,aCount); @@ -183,7 +182,7 @@ void nsStrPrivate::StrAssign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset * @param aSource is where char are copied from * @aCount is the number of bytes to be copied */ -void nsStrPrivate::StrAppend(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount){ +void nsStr::StrAppend(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount){ if(anOffset0) && aSet){ PRInt32 theIndex=-1; @@ -543,7 +542,7 @@ void nsStrPrivate::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,P * @param * @return */ -void nsStrPrivate::CompressSet1(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){ +void nsStr::CompressSet1(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){ NS_ASSERTION(aDest.GetCharSize() == eOneByte, "Must be 1 byte"); Trim(aDest,aSet,aEliminateLeading,aEliminateTrailing); @@ -552,7 +551,7 @@ void nsStrPrivate::CompressSet1(nsStr& aDest,const char* aSet,PRBool aEliminateL NSSTR_SEEN(aDest); } -void nsStrPrivate::CompressSet2(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){ +void nsStr::CompressSet2(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){ NS_ASSERTION(aDest.GetCharSize() == eTwoByte, "Must be 2 bytes"); Trim(aDest,aSet,aEliminateLeading,aEliminateTrailing); @@ -568,7 +567,7 @@ void nsStrPrivate::CompressSet2(nsStr& aDest,const char* aSet,PRBool aEliminateL * @param * @return */ -void nsStrPrivate::StripChars1(nsStr& aDest,const char* aSet){ +void nsStr::StripChars1(nsStr& aDest,const char* aSet){ NS_ASSERTION(aDest.GetCharSize() == eOneByte, "Must be 1 byte"); if((0aSource=1 */ -PRInt32 nsStrPrivate::StrCompare1To1(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) { +PRInt32 nsStr::StrCompare1To1(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) { NS_ASSERTION(aDest.GetCharSize() == eOneByte, "Must be 1 byte"); NS_ASSERTION(aSource.GetCharSize() == eOneByte, "Must be 1 byte"); if (aCount) { @@ -1152,7 +1151,7 @@ PRInt32 nsStrPrivate::StrCompare1To1(const nsStr& aDest,const nsStr& aSource,PRI return 0; } -PRInt32 nsStrPrivate::StrCompare1To2(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) { +PRInt32 nsStr::StrCompare1To2(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) { NS_ASSERTION(aDest.GetCharSize() == eOneByte, "Must be 1 byte"); NS_ASSERTION(aSource.GetCharSize() == eTwoByte, "Must be 2 byte"); @@ -1166,7 +1165,7 @@ PRInt32 nsStrPrivate::StrCompare1To2(const nsStr& aDest,const nsStr& aSource,PRI return 0; } -PRInt32 nsStrPrivate::StrCompare2To1(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) { +PRInt32 nsStr::StrCompare2To1(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) { NS_ASSERTION(aDest.GetCharSize() == eTwoByte, "Must be 2 byte"); NS_ASSERTION(aSource.GetCharSize() == eOneByte, "Must be 1 byte"); @@ -1180,7 +1179,7 @@ PRInt32 nsStrPrivate::StrCompare2To1(const nsStr& aDest,const nsStr& aSource,PRI return 0; } -PRInt32 nsStrPrivate::StrCompare2To2(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) { +PRInt32 nsStr::StrCompare2To2(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) { NS_ASSERTION(aDest.GetCharSize() == eTwoByte, "Must be 2 byte"); NS_ASSERTION(aSource.GetCharSize() == eTwoByte, "Must be 2 byte"); @@ -1202,7 +1201,7 @@ PRInt32 nsStrPrivate::StrCompare2To2(const nsStr& aDest,const nsStr& aSource,PRI * @param aDestOffset is the offset within aDest where source should be copied * @return error code */ -void nsStrPrivate::Overwrite(nsStr& aDest,const nsStr& aSource,PRInt32 aDestOffset) { +void nsStr::Overwrite(nsStr& aDest,const nsStr& aSource,PRInt32 aDestOffset) { if(aDest.mLength && aSource.mLength) { if((aDest.mLength-aDestOffset)>=aSource.mLength) { //if you're here, then both dest and source have valid lengths @@ -1214,7 +1213,7 @@ void nsStrPrivate::Overwrite(nsStr& aDest,const nsStr& aSource,PRInt32 aDestOffs //---------------------------------------------------------------------------------------- // allocate the given bytes, not including the null terminator -PRBool nsStrPrivate::Alloc(nsStr& aDest,PRUint32 aCount) { +PRBool nsStr::Alloc(nsStr& aDest,PRUint32 aCount) { // the new strategy is, allocate exact size, double on grows aDest.SetInternalCapacity(aCount); @@ -1230,7 +1229,7 @@ PRBool nsStrPrivate::Alloc(nsStr& aDest,PRUint32 aCount) { return (aDest.mStr != nsnull); } -PRBool nsStrPrivate::Free(nsStr& aDest){ +PRBool nsStr::Free(nsStr& aDest){ if(aDest.mStr){ if(aDest.GetOwnsBuffer()){ nsMemory::Free(aDest.mStr); @@ -1242,7 +1241,7 @@ PRBool nsStrPrivate::Free(nsStr& aDest){ return PR_FALSE; } -PRBool nsStrPrivate::Realloc(nsStr& aDest,PRUint32 aCount){ +PRBool nsStr::Realloc(nsStr& aDest,PRUint32 aCount){ nsStr temp; memcpy(&temp,&aDest,sizeof(aDest)); @@ -1264,7 +1263,7 @@ PRBool nsStrPrivate::Realloc(nsStr& aDest,PRUint32 aCount){ * @update gess 10/11/99 * @return memory error (usually returns PR_TRUE) */ -PRBool nsStrPrivate::DidAcquireMemory(void) { +PRBool nsStr::DidAcquireMemory(void) { return gStringAcquiredMemory; } #endif @@ -1331,7 +1330,7 @@ CBufDescriptor::CBufDescriptor(const PRUnichar* aString,PRBool aStackBased,PRUin //---------------------------------------------------------------------------------------- PRUint32 -nsStrPrivate::HashCode(const nsStr& aDest) +nsStr::HashCode(const nsStr& aDest) { if (aDest.GetCharSize() == eTwoByte) return nsCRT::HashCode(aDest.mUStr); @@ -1348,7 +1347,7 @@ nsStrPrivate::HashCode(const nsStr& aDest) #endif void -nsStrPrivate::Print(const nsStr& aDest, FILE* out, PRBool truncate) +nsStr::Print(const nsStr& aDest, FILE* out, PRBool truncate) { PRInt32 printLen = (PRInt32)aDest.mLength; @@ -1379,9 +1378,9 @@ PRBool gNoStringInfo = PR_FALSE; nsStringInfo::nsStringInfo(nsStr& str) : mCount(0) { - nsStrPrivate::Initialize(mStr, str.GetCharSize()); - nsStrPrivate::StrAssign(mStr, str, 0, -1); -// nsStrPrivate::Print(mStr, stdout); + nsStr::Initialize(mStr, str.GetCharSize()); + nsStr::StrAssign(mStr, str, 0, -1); +// nsStr::Print(mStr, stdout); // fputc('\n', stdout); } @@ -1389,7 +1388,7 @@ PR_EXTERN(PRHashNumber) nsStr_Hash(const void* key) { nsStr* str = (nsStr*)key; - return nsStrPrivate::HashCode(*str); + return nsStr::HashCode(*str); } nsStringInfo* @@ -1447,7 +1446,7 @@ nsStringInfo::ReportEntry(PLHashEntry *he, PRIntn i, void *arg) FILE* out = (FILE*)arg; fprintf(out, "%d ==> (%d) ", entry->mCount, entry->mStr.mLength); - nsStrPrivate::Print(entry->mStr, out, PR_TRUE); + nsStr::Print(entry->mStr, out, PR_TRUE); fputc('\n', out); return HT_ENUMERATE_NEXT; } diff --git a/mozilla/string/obsolete/nsStr.h b/mozilla/string/obsolete/nsStr.h index 8d9adf44ea7..968d6e80f3f 100644 --- a/mozilla/string/obsolete/nsStr.h +++ b/mozilla/string/obsolete/nsStr.h @@ -267,6 +267,225 @@ protected: MOZ_COUNT_DTOR(nsStr); } + /** + * This method initializes an nsStr for use + * + * @update gess 01/04/99 + * @param aString is the nsStr to be initialized + * @param aCharSize tells us the requested char size (1 or 2 bytes) + */ + static void Initialize(nsStr& aDest,eCharSize aCharSize); + + /** + * This method initializes an nsStr for use + * + * @update gess 01/04/99 + * @param aString is the nsStr to be initialized + * @param aCharSize tells us the requested char size (1 or 2 bytes) + */ + static void Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 aLength,eCharSize aCharSize,PRBool aOwnsBuffer); + /** + * This method destroys the given nsStr, and *MAY* + * deallocate it's memory depending on the setting + * of the internal mOwnsBUffer flag. + * + * @update gess 01/04/99 + * @param aString is the nsStr to be manipulated + */ + static void Destroy(nsStr& aDest); + + /** + * These methods are where memory allocation/reallocation occur. + * + * @update gess 01/04/99 + * @param aString is the nsStr to be manipulated + * @return + */ + static PRBool EnsureCapacity(nsStr& aString,PRUint32 aNewLength); + static PRBool GrowCapacity(nsStr& aString,PRUint32 aNewLength); + + /** + * These methods are used to append content to the given nsStr + * + * @update gess 01/04/99 + * @param aDest is the nsStr to be appended to + * @param aSource is the buffer to be copied from + * @param anOffset tells us where in source to start copying + * @param aCount tells us the (max) # of chars to copy + */ + static void StrAppend(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount); + + /** + * These methods are used to assign contents of a source string to dest string + * + * @update gess 01/04/99 + * @param aDest is the nsStr to be appended to + * @param aSource is the buffer to be copied from + * @param anOffset tells us where in source to start copying + * @param aCount tells us the (max) # of chars to copy + */ + static void StrAssign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount); + + /** + * These methods are used to insert content from source string to the dest nsStr + * + * @update gess 01/04/99 + * @param aDest is the nsStr to be appended to + * @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 + */ + static void StrInsert1into1( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount); + static void StrInsert1into2( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount); + static void StrInsert2into1( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount); + static void StrInsert2into2( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount); + + + /** + * Helper routines for StrInsert1into1, etc + */ + static PRInt32 GetSegmentLength(const nsStr& aSource, + PRUint32 aSrcOffset, PRInt32 aCount); + static void AppendForInsert(nsStr& aDest, PRUint32 aDestOffset, const nsStr& aSource, PRUint32 aSrcOffset, PRInt32 theLength); + + /** + * This method deletes chars from the given str. + * The given allocator may choose to resize the str as well. + * + * @update gess 01/04/99 + * @param aDest is the nsStr to be deleted from + * @param aDestOffset tells us where in dest to start deleting + * @param aCount tells us the (max) # of chars to delete + */ + static void Delete1(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount); + static void Delete2(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount); + + /** + * helper routines for Delete1, Delete2 + */ + static PRInt32 GetDeleteLength(const nsStr& aDest, PRUint32 aDestOffset, PRUint32 aCount); + + /** + * This method is used to truncate the given string. + * The given allocator may choose to resize the str as well (but it's not likely). + * + * @update gess 01/04/99 + * @param aDest is the nsStr to be appended to + * @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 + */ + static void StrTruncate(nsStr& aDest,PRUint32 aDestOffset); + + /** + * This method trims chars (given in aSet) from the edges of given buffer + * + * @update gess 01/04/99 + * @param aDest is the buffer to be manipulated + * @param aSet tells us which chars to remove from given buffer + * @param aEliminateLeading tells us whether to strip chars from the start of the buffer + * @param aEliminateTrailing tells us whether to strip chars from the start of the buffer + */ + static void Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing); + + /** + * This method compresses duplicate runs of a given char from the given buffer + * + * @update gess 01/04/99 + * @param aDest is the buffer to be manipulated + * @param aSet tells us which chars to compress from given buffer + * @param aChar is the replacement char + * @param aEliminateLeading tells us whether to strip chars from the start of the buffer + * @param aEliminateTrailing tells us whether to strip chars from the start of the buffer + */ + static void CompressSet1(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing); + static void CompressSet2(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing); + + /** + * This method removes all occurances of chars in given set from aDest + * + * @update gess 01/04/99 + * @param aDest is the buffer to be manipulated + * @param aSet tells us which chars to compress from given buffer + * @param aChar is the replacement char + * @param aEliminateLeading tells us whether to strip chars from the start of the buffer + * @param aEliminateTrailing tells us whether to strip chars from the start of the buffer + */ + static void StripChars1(nsStr& aDest,const char* aSet); + static void StripChars2(nsStr& aDest,const char* aSet); + + /** + * This method compares the data bewteen two nsStr's + * + * @update gess 01/04/99 + * @param aStr1 is the first buffer to be compared + * @param aStr2 is the 2nd buffer to be compared + * @param aCount is the number of chars to compare + * @param aIgnorecase tells us whether to use a case-sensitive comparison + * @return -1,0,1 depending on <,==,> + */ + static PRInt32 StrCompare1To1(const nsStr& aDest,const nsStr& aSource, + PRInt32 aCount,PRBool aIgnoreCase); + static PRInt32 StrCompare1To2(const nsStr& aDest, const nsStr& aSource, + PRInt32 aCount, PRBool aIgnoreCase); + static PRInt32 StrCompare2To1(const nsStr& aDest, const nsStr& aSource, + PRInt32 aCount, PRBool aIgnoreCase); + static PRInt32 StrCompare2To2(const nsStr& aDest, const nsStr& aSource, + PRInt32 aCount, PRBool aIgnoreCase); + + /** + * These methods scan the given string for 1 or more chars in a given direction + * + * @update gess 01/04/99 + * @param aDest is the nsStr to be searched to + * @param aSource (or aChar) is the substr we're looking to find + * @param aIgnoreCase tells us whether to search in a case-sensitive manner + * @param anOffset tells us where in the dest string to start searching + * @return the index of the source (substr) in dest, or -1 (kNotFound) if not found. + */ + static PRInt32 FindSubstr1in1(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount); + static PRInt32 FindSubstr1in2(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount); + static PRInt32 FindSubstr2in1(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount); + static PRInt32 FindSubstr2in2(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount); + + static PRInt32 FindChar1(const nsStr& aDest,PRUnichar aChar, PRInt32 anOffset,PRInt32 aCount); + static PRInt32 FindChar2(const nsStr& aDest,PRUnichar aChar, PRInt32 anOffset,PRInt32 aCount); + + static PRInt32 FindCharInSet1(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset); + static PRInt32 FindCharInSet2(const nsStr& aDest,const nsStr& aSet,PRInt32 anOffset); + + static PRInt32 RFindSubstr1in1(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount); + static PRInt32 RFindSubstr2in1(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount); + static PRInt32 RFindSubstr1in2(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount); + static PRInt32 RFindSubstr2in2(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount); + + static PRInt32 RFindChar1(const nsStr& aDest,PRUnichar aChar, PRInt32 anOffset,PRInt32 aCount); + static PRInt32 RFindChar2(const nsStr& aDest,PRUnichar aChar, PRInt32 anOffset,PRInt32 aCount); + + static PRInt32 RFindCharInSet1(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset); + static PRInt32 RFindCharInSet2(const nsStr& aDest,const nsStr& aSet,PRInt32 anOffset); + + static void Overwrite(nsStr& aDest,const nsStr& aSource,PRInt32 anOffset); + +#ifdef NS_STR_STATS + static PRBool DidAcquireMemory(void); +#endif + + /** + * Returns a hash code for the string for use in a PLHashTable. + */ + static PRUint32 HashCode(const nsStr& aDest); + +#ifdef NS_STR_STATS + /** + * Prints an nsStr. If truncate is true, the string is only printed up to + * the first newline. (Note: The current implementation doesn't handle + * non-ascii unicode characters.) + */ + static void Print(const nsStr& aDest, FILE* out, PRBool truncate = PR_FALSE); +#endif + protected: union { char* mStr; @@ -309,13 +528,16 @@ private: (aOwnsBuffer ? 1 : 0) << NSSTR_OWNSBUFFER_BIT); } + static PRBool Alloc(nsStr& aString,PRUint32 aCount); + static PRBool Realloc(nsStr& aString,PRUint32 aCount); + static PRBool Free(nsStr& aString); + public: friend NS_COM char* ToNewUTF8String( const nsAString& aSource ); friend inline void AddNullTerminator(nsStr& aDest); friend inline PRUnichar GetCharAt(const nsStr& aDest,PRUint32 anIndex); - friend class nsStrPrivate; friend class nsString; friend class nsCString; }; diff --git a/mozilla/string/obsolete/nsString.cpp b/mozilla/string/obsolete/nsString.cpp index bab9e69e501..1be4da8c3fd 100644 --- a/mozilla/string/obsolete/nsString.cpp +++ b/mozilla/string/obsolete/nsString.cpp @@ -41,7 +41,6 @@ #include #include #include -#include "nsStrPrivate.h" #include "nsString.h" #include "nsReadableUtils.h" #include "nsDebug.h" @@ -67,11 +66,11 @@ nsCString::GetFlatBufferHandle() const * Default constructor. */ nsCString::nsCString() { - nsStrPrivate::Initialize(*this,eOneByte); + Initialize(*this,eOneByte); } nsCString::nsCString(const char* aCString) { - nsStrPrivate::Initialize(*this,eOneByte); + Initialize(*this,eOneByte); Assign(aCString); } @@ -82,7 +81,7 @@ nsCString::nsCString(const char* aCString) { * @param aLength tells us how many chars to copy from given CString */ nsCString::nsCString(const char* aCString,PRInt32 aLength) { - nsStrPrivate::Initialize(*this,eOneByte); + Initialize(*this,eOneByte); Assign(aCString,aLength); } @@ -92,15 +91,15 @@ nsCString::nsCString(const char* aCString,PRInt32 aLength) { * @param reference to another nsCString */ nsCString::nsCString(const nsCString& aString) { - nsStrPrivate::Initialize(*this,aString.GetCharSize()); - nsStrPrivate::StrAssign(*this,aString,0,aString.mLength); + Initialize(*this,aString.GetCharSize()); + StrAssign(*this,aString,0,aString.mLength); } /** * Destructor */ nsCString::~nsCString() { - nsStrPrivate::Destroy(*this); + Destroy(*this); } const char* nsCString::GetReadableFragment( nsReadableFragment& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset ) const { @@ -134,7 +133,7 @@ char* nsCString::GetWritableFragment( nsWritableFragment& aFragment, nsFra } nsCString::nsCString( const nsACString& aReadable ) { - nsStrPrivate::Initialize(*this,eOneByte); + Initialize(*this,eOneByte); Assign(aReadable); } @@ -159,7 +158,7 @@ void nsCString::SetLength(PRUint32 anIndex) { // |SetCapacity| normally doesn't guarantee the use we are putting it to here (see its interface comment in nsAWritableString.h), // we can only use it since our local implementation, |nsCString::SetCapacity|, is known to do what we want - nsStrPrivate::StrTruncate(*this,anIndex); + nsStr::StrTruncate(*this,anIndex); } @@ -175,13 +174,13 @@ nsCString::SetCapacity( PRUint32 aNewCapacity ) if ( aNewCapacity ) { if( aNewCapacity > GetCapacity() ) - nsStrPrivate::GrowCapacity(*this,aNewCapacity); + GrowCapacity(*this,aNewCapacity); AddNullTerminator(*this); } else { - nsStrPrivate::Destroy(*this); - nsStrPrivate::Initialize(*this, eOneByte); + nsStr::Destroy(*this); + nsStr::Initialize(*this, eOneByte); } } @@ -249,7 +248,7 @@ nsCString::StripChar(PRUnichar aChar,PRInt32 anOffset){ */ void nsCString::StripChars(const char* aSet){ - nsStrPrivate::StripChars1(*this,aSet); + nsStr::StripChars1(*this,aSet); } @@ -354,19 +353,19 @@ nsCString::ReplaceSubstring(const nsCString& aTarget,const nsCString& aNewValue) } else { PRInt32 theIndex=0; - while(kNotFound!=(theIndex=nsStrPrivate::FindSubstr1in1(*this,aTarget,PR_FALSE,theIndex,mLength))) { + while(kNotFound!=(theIndex=nsStr::FindSubstr1in1(*this,aTarget,PR_FALSE,theIndex,mLength))) { if(aNewValue.mLength 0 ) { temp.mLength = aLength; - nsStrPrivate::StrAppend(*this, temp, 0, aLength); + StrAppend(*this, temp, 0, aLength); } } @@ -789,7 +788,7 @@ void nsCString::AppendWithConversion(const nsString& aString,PRInt32 aCount) { else aCount=MinInt(aCount,aString.mLength); if(0::length(aPtr); // We don't know the capacity, so we'll just have to assume // capacity = length. - nsStrPrivate::Initialize(*this, aPtr, aLength, aLength, eOneByte, PR_TRUE); + nsStr::Initialize(*this, aPtr, aLength, aLength, eOneByte, PR_TRUE); } /********************************************************************** @@ -841,10 +840,10 @@ PRInt32 nsCString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset PRInt32 result=kNotFound; if(aCString) { nsStr temp; - nsStrPrivate::Initialize(temp,eOneByte); + nsStr::Initialize(temp,eOneByte); temp.mLength = nsCRT::strlen(aCString); temp.mStr=(char*)aCString; - result=nsStrPrivate::FindSubstr1in1(*this,temp,aIgnoreCase,anOffset,aCount); + result=nsStr::FindSubstr1in1(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } @@ -865,10 +864,10 @@ PRInt32 nsCString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOf PRInt32 result=kNotFound; if(aString) { nsStr temp; - nsStrPrivate::Initialize(temp,eTwoByte); + nsStr::Initialize(temp,eTwoByte); temp.mLength = nsCRT::strlen(aString); temp.mUStr=(PRUnichar*)aString; - result=nsStrPrivate::FindSubstr2in1(*this,temp,aIgnoreCase,anOffset,aCount); + result=nsStr::FindSubstr2in1(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } @@ -884,12 +883,12 @@ PRInt32 nsCString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOf * @return offset in string, or -1 (kNotFound) */ PRInt32 nsCString::Find(const nsCString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ - PRInt32 result=nsStrPrivate::FindSubstr1in1(*this,aString,aIgnoreCase,anOffset,aCount); + PRInt32 result=nsStr::FindSubstr1in1(*this,aString,aIgnoreCase,anOffset,aCount); return result; } PRInt32 nsCString::Find(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ - PRInt32 result=nsStrPrivate::FindSubstr1in2(*this,aString,aIgnoreCase,anOffset,aCount); + PRInt32 result=nsStr::FindSubstr1in2(*this,aString,aIgnoreCase,anOffset,aCount); return result; } @@ -905,7 +904,7 @@ PRInt32 nsCString::Find(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOff * @return index in aDest where member of aSet occurs, or -1 if not found */ PRInt32 nsCString::FindChar(PRUnichar aChar,PRInt32 anOffset,PRInt32 aCount) const{ - PRInt32 result=nsStrPrivate::FindChar1(*this,aChar,anOffset,aCount); + PRInt32 result=nsStr::FindChar1(*this,aChar,anOffset,aCount); return result; } @@ -924,10 +923,10 @@ PRInt32 nsCString::FindCharInSet(const char* aCStringSet,PRInt32 anOffset) const PRInt32 result=kNotFound; if(aCStringSet) { nsStr temp; - nsStrPrivate::Initialize(temp,eOneByte); + nsStr::Initialize(temp,eOneByte); temp.mLength=nsCRT::strlen(aCStringSet); temp.mStr=(char*)aCStringSet; - result=nsStrPrivate::FindCharInSet1(*this,temp,PR_FALSE,anOffset); + result=nsStr::FindCharInSet1(*this,temp,PR_FALSE,anOffset); } return result; } @@ -947,10 +946,10 @@ PRInt32 nsCString::FindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) c PRInt32 result=kNotFound; if(aStringSet) { nsStr temp; - nsStrPrivate::Initialize(temp,eTwoByte); + nsStr::Initialize(temp,eTwoByte); temp.mLength=nsCRT::strlen(aStringSet); temp.mStr=(char*)aStringSet; - result=nsStrPrivate::FindCharInSet2(*this,temp,anOffset); + result=nsStr::FindCharInSet2(*this,temp,anOffset); } return result; } @@ -965,12 +964,12 @@ PRInt32 nsCString::FindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) c * @return */ PRInt32 nsCString::FindCharInSet(const nsCString& aSet,PRInt32 anOffset) const{ - PRInt32 result=nsStrPrivate::FindCharInSet1(*this,aSet,PR_FALSE,anOffset); + PRInt32 result=nsStr::FindCharInSet1(*this,aSet,PR_FALSE,anOffset); return result; } PRInt32 nsCString::FindCharInSet(const nsString& aSet,PRInt32 anOffset) const{ - PRInt32 result=nsStrPrivate::FindCharInSet2(*this,aSet,anOffset); + PRInt32 result=nsStr::FindCharInSet2(*this,aSet,anOffset); return result; } @@ -985,12 +984,12 @@ PRInt32 nsCString::FindCharInSet(const nsString& aSet,PRInt32 anOffset) const{ * @return offset in string, or -1 (kNotFound) */ PRInt32 nsCString::RFind(const nsCString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ - PRInt32 result=nsStrPrivate::RFindSubstr1in1(*this,aString,aIgnoreCase,anOffset,aCount); + PRInt32 result=nsStr::RFindSubstr1in1(*this,aString,aIgnoreCase,anOffset,aCount); return result; } PRInt32 nsCString::RFind(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ - PRInt32 result=nsStrPrivate::RFindSubstr2in1(*this,aString,aIgnoreCase,anOffset,aCount); + PRInt32 result=nsStr::RFindSubstr2in1(*this,aString,aIgnoreCase,anOffset,aCount); return result; } @@ -1011,10 +1010,10 @@ PRInt32 nsCString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset PRInt32 result=kNotFound; if(aString) { nsStr temp; - nsStrPrivate::Initialize(temp,eOneByte); + nsStr::Initialize(temp,eOneByte); temp.mLength=nsCRT::strlen(aString); temp.mStr=(char*)aString; - result=nsStrPrivate::RFindSubstr1in1(*this,temp,aIgnoreCase,anOffset,aCount); + result=nsStr::RFindSubstr1in1(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } @@ -1030,7 +1029,7 @@ PRInt32 nsCString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset * @return index in aDest where member of aSet occurs, or -1 if not found */ PRInt32 nsCString::RFindChar(PRUnichar aChar,PRInt32 anOffset,PRInt32 aCount) const{ - PRInt32 result=nsStrPrivate::RFindChar1(*this,aChar,anOffset,aCount); + PRInt32 result=nsStr::RFindChar1(*this,aChar,anOffset,aCount); return result; } @@ -1048,10 +1047,10 @@ PRInt32 nsCString::RFindCharInSet(const char* aCStringSet,PRInt32 anOffset) cons PRInt32 result=kNotFound; if(aCStringSet) { nsStr temp; - nsStrPrivate::Initialize(temp,eOneByte); + nsStr::Initialize(temp,eOneByte); temp.mLength=nsCRT::strlen(aCStringSet); temp.mStr=(char*)aCStringSet; - result=nsStrPrivate::RFindCharInSet1(*this,temp,PR_FALSE,anOffset); + result=nsStr::RFindCharInSet1(*this,temp,PR_FALSE,anOffset); } return result; } @@ -1070,10 +1069,10 @@ PRInt32 nsCString::RFindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) PRInt32 result=kNotFound; if(aStringSet) { nsStr temp; - nsStrPrivate::Initialize(temp,eTwoByte); + nsStr::Initialize(temp,eTwoByte); temp.mLength=nsCRT::strlen(aStringSet); temp.mUStr=(PRUnichar*)aStringSet; - result=nsStrPrivate::RFindCharInSet2(*this,temp,anOffset); + result=nsStr::RFindCharInSet2(*this,temp,anOffset); } return result; } @@ -1088,12 +1087,12 @@ PRInt32 nsCString::RFindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) * @return offset of found char, or -1 (kNotFound) */ PRInt32 nsCString::RFindCharInSet(const nsCString& aSet,PRInt32 anOffset) const{ - PRInt32 result=nsStrPrivate::RFindCharInSet1(*this,aSet,PR_FALSE,anOffset); + PRInt32 result=nsStr::RFindCharInSet1(*this,aSet,PR_FALSE,anOffset); return result; } PRInt32 nsCString::RFindCharInSet(const nsString& aSet,PRInt32 anOffset) const{ - PRInt32 result=nsStrPrivate::RFindCharInSet2(*this,aSet,anOffset); + PRInt32 result=nsStr::RFindCharInSet2(*this,aSet,anOffset); return result; } @@ -1116,10 +1115,10 @@ PRInt32 nsCString::CompareWithConversion(const PRUnichar* aString,PRBool aIgnore if(aString) { nsStr temp; - nsStrPrivate::Initialize(temp,eTwoByte); + nsStr::Initialize(temp,eTwoByte); temp.mLength=nsCRT::strlen(aString); temp.mUStr=(PRUnichar*)aString; - return nsStrPrivate::StrCompare1To2(*this,temp,aCount,aIgnoreCase); + return nsStr::StrCompare1To2(*this,temp,aCount,aIgnoreCase); } return 0; } @@ -1137,10 +1136,10 @@ PRInt32 nsCString::CompareWithConversion(const char *aCString,PRBool aIgnoreCase if(aCString) { nsStr temp; - nsStrPrivate::Initialize(temp,eOneByte); + nsStr::Initialize(temp,eOneByte); temp.mLength=nsCRT::strlen(aCString); temp.mStr=(char*)aCString; - return nsStrPrivate::StrCompare1To1(*this,temp,aCount,aIgnoreCase); + return nsStr::StrCompare1To1(*this,temp,aCount,aIgnoreCase); } return 0; } @@ -1316,25 +1315,25 @@ NS_LossyConvertUCS2toASCII::NS_LossyConvertUCS2toASCII( const nsAString& aString * */ nsCAutoString::nsCAutoString() : nsCString(){ - nsStrPrivate::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); + Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); AddNullTerminator(*this); } nsCAutoString::nsCAutoString( const nsCString& aString ) : nsCString(){ - nsStrPrivate::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); + Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); AddNullTerminator(*this); Append(aString); } nsCAutoString::nsCAutoString( const nsACString& aString ) : nsCString(){ - nsStrPrivate::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); + Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); AddNullTerminator(*this); Append(aString); } nsCAutoString::nsCAutoString(const char* aCString) : nsCString() { - nsStrPrivate::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); + Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); AddNullTerminator(*this); Append(aCString); } @@ -1344,7 +1343,7 @@ nsCAutoString::nsCAutoString(const char* aCString) : nsCString() { * @param aCString is a ptr to a 1-byte cstr */ nsCAutoString::nsCAutoString(const char* aCString,PRInt32 aLength) : nsCString() { - nsStrPrivate::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); + Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); AddNullTerminator(*this); Append(aCString,aLength); } @@ -1355,10 +1354,10 @@ nsCAutoString::nsCAutoString(const char* aCString,PRInt32 aLength) : nsCString() */ nsCAutoString::nsCAutoString(const CBufDescriptor& aBuffer) : nsCString() { if(!aBuffer.mBuffer) { - nsStrPrivate::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); + Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); } else { - nsStrPrivate::Initialize(*this,aBuffer.mBuffer,aBuffer.mCapacity,aBuffer.mLength,aBuffer.mCharSize,!aBuffer.mStackBased); + Initialize(*this,aBuffer.mBuffer,aBuffer.mCapacity,aBuffer.mLength,aBuffer.mCharSize,!aBuffer.mStackBased); } if(!aBuffer.mIsConst) AddNullTerminator(*this); //this isn't really needed, but it guarantees that folks don't pass string constants. diff --git a/mozilla/string/obsolete/nsString2.cpp b/mozilla/string/obsolete/nsString2.cpp index f9d0a9a3f67..10ef2e510b5 100644 --- a/mozilla/string/obsolete/nsString2.cpp +++ b/mozilla/string/obsolete/nsString2.cpp @@ -40,7 +40,6 @@ #include #include #include -#include "nsStrPrivate.h" #include "nsString.h" #include "nsReadableUtils.h" #include "nsDebug.h" @@ -66,11 +65,11 @@ nsString::GetFlatBufferHandle() const * Default constructor. */ nsString::nsString() { - nsStrPrivate::Initialize(*this,eTwoByte); + Initialize(*this,eTwoByte); } nsString::nsString(const PRUnichar* aString) { - nsStrPrivate::Initialize(*this,eTwoByte); + Initialize(*this,eTwoByte); Assign(aString); } @@ -81,7 +80,7 @@ nsString::nsString(const PRUnichar* aString) { * @param aLength tells us how many chars to copy from given aString */ nsString::nsString(const PRUnichar* aString,PRInt32 aCount) { - nsStrPrivate::Initialize(*this,eTwoByte); + Initialize(*this,eTwoByte); Assign(aString,aCount); } @@ -91,16 +90,16 @@ nsString::nsString(const PRUnichar* aString,PRInt32 aCount) { * @param reference to another nsString */ nsString::nsString(const nsString& aString) { - nsStrPrivate::Initialize(*this,eTwoByte); - nsStrPrivate::StrAssign(*this,aString,0,aString.mLength); + Initialize(*this,eTwoByte); + StrAssign(*this,aString,0,aString.mLength); } /** * Destructor - * Make sure we call nsStrPrivate::Destroy. + * Make sure we call nsStr::Destroy. */ nsString::~nsString() { - nsStrPrivate::Destroy(*this); + nsStr::Destroy(*this); } const PRUnichar* nsString::GetReadableFragment( nsReadableFragment& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset ) const { @@ -141,15 +140,15 @@ nsString::do_AppendFromElement( PRUnichar inChar ) buf[0] = inChar; nsStr temp; - nsStrPrivate::Initialize(temp, eTwoByte); + nsStr::Initialize(temp, eTwoByte); temp.mUStr = buf; temp.mLength = 1; - nsStrPrivate::StrAppend(*this, temp, 0, 1); + StrAppend(*this, temp, 0, 1); } nsString::nsString( const nsAString& aReadable ) { - nsStrPrivate::Initialize(*this,eTwoByte); + Initialize(*this,eTwoByte); Assign(aReadable); } @@ -173,7 +172,7 @@ void nsString::SetLength(PRUint32 anIndex) { SetCapacity(anIndex); // |SetCapacity| normally doesn't guarantee the use we are putting it to here (see its interface comment in nsAWritableString.h), // we can only use it since our local implementation, |nsString::SetCapacity|, is known to do what we want - nsStrPrivate::StrTruncate(*this,anIndex); + nsStr::StrTruncate(*this,anIndex); } @@ -189,13 +188,13 @@ nsString::SetCapacity( PRUint32 aNewCapacity ) if ( aNewCapacity ) { if( aNewCapacity > GetCapacity() ) - nsStrPrivate::GrowCapacity(*this, aNewCapacity); + GrowCapacity(*this, aNewCapacity); AddNullTerminator(*this); } else { - nsStrPrivate::Destroy(*this); - nsStrPrivate::Initialize(*this, eTwoByte); + nsStr::Destroy(*this); + nsStr::Initialize(*this, eTwoByte); } } @@ -300,7 +299,7 @@ nsString::StripChar(PRUnichar aChar,PRInt32 anOffset){ */ void nsString::StripChars(const char* aSet){ - nsStrPrivate::StripChars2(*this,aSet); + nsStr::StripChars2(*this,aSet); } @@ -410,19 +409,19 @@ nsString::ReplaceSubstring(const nsString& aTarget,const nsString& aNewValue){ } else { PRInt32 theIndex=0; - while(kNotFound!=(theIndex=nsStrPrivate::FindSubstr2in2(*this,aTarget,PR_FALSE,theIndex,mLength))) { + while(kNotFound!=(theIndex=nsStr::FindSubstr2in2(*this,aTarget,PR_FALSE,theIndex,mLength))) { if(aNewValue.mLength::length(aPtr); // We don't know the capacity, so we'll just have to assume // capacity = length. - nsStrPrivate::Initialize(*this, (char*)aPtr, aLength, aLength, eTwoByte, PR_TRUE); + nsStr::Initialize(*this, (char*)aPtr, aLength, aLength, eTwoByte, PR_TRUE); } @@ -884,10 +883,10 @@ PRInt32 nsString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset, PRInt32 result=kNotFound; if(aCString) { nsStr temp; - nsStrPrivate::Initialize(temp,eOneByte); + nsStr::Initialize(temp,eOneByte); temp.mLength=nsCRT::strlen(aCString); temp.mStr=(char*)aCString; - result=nsStrPrivate::FindSubstr1in2(*this,temp,aIgnoreCase,anOffset,aCount); + result=nsStr::FindSubstr1in2(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } @@ -908,10 +907,10 @@ PRInt32 nsString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOff PRInt32 result=kNotFound; if(aString) { nsStr temp; - nsStrPrivate::Initialize(temp,eTwoByte); + nsStr::Initialize(temp,eTwoByte); temp.mLength=nsCRT::strlen(aString); temp.mUStr=(PRUnichar*)aString; - result=nsStrPrivate::FindSubstr2in2(*this,temp,aIgnoreCase,anOffset,aCount); + result=nsStr::FindSubstr2in2(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } @@ -927,7 +926,7 @@ PRInt32 nsString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOff * @return offset in string, or -1 (kNotFound) */ PRInt32 nsString::Find(const nsCString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ - PRInt32 result=nsStrPrivate::FindSubstr1in2(*this,aString,aIgnoreCase,anOffset,aCount); + PRInt32 result=nsStr::FindSubstr1in2(*this,aString,aIgnoreCase,anOffset,aCount); return result; } @@ -942,7 +941,7 @@ PRInt32 nsString::Find(const nsCString& aString,PRBool aIgnoreCase,PRInt32 anOff * @return offset in string, or -1 (kNotFound) */ PRInt32 nsString::Find(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ - PRInt32 result=nsStrPrivate::FindSubstr2in2(*this,aString,aIgnoreCase,anOffset,aCount); + PRInt32 result=nsStr::FindSubstr2in2(*this,aString,aIgnoreCase,anOffset,aCount); return result; } @@ -961,10 +960,10 @@ PRInt32 nsString::FindCharInSet(const char* aCStringSet,PRInt32 anOffset) const{ PRInt32 result=kNotFound; if(aCStringSet) { nsStr temp; - nsStrPrivate::Initialize(temp,eOneByte); + nsStr::Initialize(temp,eOneByte); temp.mLength=nsCRT::strlen(aCStringSet); temp.mStr=(char*)aCStringSet; - result=nsStrPrivate::FindCharInSet1(*this,temp,PR_FALSE,anOffset); + result=nsStr::FindCharInSet1(*this,temp,PR_FALSE,anOffset); } return result; } @@ -984,10 +983,10 @@ PRInt32 nsString::FindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) co PRInt32 result=kNotFound; if(aStringSet) { nsStr temp; - nsStrPrivate::Initialize(temp,eTwoByte); + nsStr::Initialize(temp,eTwoByte); temp.mLength=nsCRT::strlen(aStringSet); temp.mStr=(char*)aStringSet; - result=nsStrPrivate::FindCharInSet2(*this,temp,anOffset); + result=nsStr::FindCharInSet2(*this,temp,anOffset); } return result; } @@ -1002,12 +1001,12 @@ PRInt32 nsString::FindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) co * @return */ PRInt32 nsString::FindCharInSet(const nsString& aSet,PRInt32 anOffset) const{ - PRInt32 result=nsStrPrivate::FindCharInSet2(*this,aSet,anOffset); + PRInt32 result=nsStr::FindCharInSet2(*this,aSet,anOffset); return result; } PRInt32 nsString::FindCharInSet(const nsCString& aSet,PRInt32 anOffset) const{ - PRInt32 result=nsStrPrivate::FindCharInSet1(*this,aSet,PR_FALSE,anOffset); + PRInt32 result=nsStr::FindCharInSet1(*this,aSet,PR_FALSE,anOffset); return result; } @@ -1023,7 +1022,7 @@ PRInt32 nsString::FindCharInSet(const nsCString& aSet,PRInt32 anOffset) const{ * @return offset in string, or -1 (kNotFound) */ PRInt32 nsString::RFind(const nsCString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ - PRInt32 result=nsStrPrivate::RFindSubstr1in2(*this,aString,aIgnoreCase,anOffset,aCount); + PRInt32 result=nsStr::RFindSubstr1in2(*this,aString,aIgnoreCase,anOffset,aCount); return result; } @@ -1038,7 +1037,7 @@ PRInt32 nsString::RFind(const nsCString& aString,PRBool aIgnoreCase,PRInt32 anOf * @return offset in string, or -1 (kNotFound) */ PRInt32 nsString::RFind(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ - PRInt32 result=nsStrPrivate::RFindSubstr2in2(*this,aString,aIgnoreCase,anOffset,aCount); + PRInt32 result=nsStr::RFindSubstr2in2(*this,aString,aIgnoreCase,anOffset,aCount); return result; } @@ -1058,10 +1057,10 @@ PRInt32 nsString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset, PRInt32 result=kNotFound; if(aString) { nsStr temp; - nsStrPrivate::Initialize(temp,eOneByte); + nsStr::Initialize(temp,eOneByte); temp.mLength=nsCRT::strlen(aString); temp.mStr=(char*)aString; - result=nsStrPrivate::RFindSubstr1in2(*this,temp,aIgnoreCase,anOffset,aCount); + result=nsStr::RFindSubstr1in2(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } @@ -1076,7 +1075,7 @@ PRInt32 nsString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset, * @return offset of found char, or -1 (kNotFound) */ PRInt32 nsString::RFindChar(PRUnichar aChar,PRInt32 anOffset,PRInt32 aCount) const{ - PRInt32 result=nsStrPrivate::RFindChar2(*this,aChar,anOffset,aCount); + PRInt32 result=nsStr::RFindChar2(*this,aChar,anOffset,aCount); return result; } @@ -1094,10 +1093,10 @@ PRInt32 nsString::RFindCharInSet(const char* aCStringSet,PRInt32 anOffset) const PRInt32 result=kNotFound; if(aCStringSet) { nsStr temp; - nsStrPrivate::Initialize(temp,eOneByte); + nsStr::Initialize(temp,eOneByte); temp.mLength=nsCRT::strlen(aCStringSet); temp.mStr=(char*)aCStringSet; - result=nsStrPrivate::RFindCharInSet1(*this,temp,PR_FALSE,anOffset); + result=nsStr::RFindCharInSet1(*this,temp,PR_FALSE,anOffset); } return result; } @@ -1113,12 +1112,12 @@ PRInt32 nsString::RFindCharInSet(const char* aCStringSet,PRInt32 anOffset) const * @return offset of found char, or -1 (kNotFound) */ PRInt32 nsString::RFindCharInSet(const nsString& aSet,PRInt32 anOffset) const{ - PRInt32 result=nsStrPrivate::RFindCharInSet2(*this,aSet,anOffset); + PRInt32 result=nsStr::RFindCharInSet2(*this,aSet,anOffset); return result; } PRInt32 nsString::RFindCharInSet(const nsCString& aSet,PRInt32 anOffset) const{ - PRInt32 result=nsStrPrivate::RFindCharInSet1(*this,aSet,PR_FALSE,anOffset); + PRInt32 result=nsStr::RFindCharInSet1(*this,aSet,PR_FALSE,anOffset); return result; } @@ -1138,10 +1137,10 @@ PRInt32 nsString::RFindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) c PRInt32 result=kNotFound; if(aStringSet) { nsStr temp; - nsStrPrivate::Initialize(temp,eTwoByte); + nsStr::Initialize(temp,eTwoByte); temp.mLength=nsCRT::strlen(aStringSet); temp.mUStr=(PRUnichar*)aStringSet; - result=nsStrPrivate::RFindCharInSet2(*this,temp,anOffset); + result=nsStr::RFindCharInSet2(*this,temp,anOffset); } return result; } @@ -1164,12 +1163,12 @@ PRInt32 nsString::CompareWithConversion(const char *aCString,PRBool aIgnoreCase, if(aCString) { nsStr temp; - nsStrPrivate::Initialize(temp,eOneByte); + nsStr::Initialize(temp,eOneByte); temp.mLength= (0>eTwoByte)-1,0,eTwoByte,PR_FALSE); + Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); AddNullTerminator(*this); } nsAutoString::nsAutoString(const PRUnichar* aString) : nsString() { - nsStrPrivate::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); + Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); AddNullTerminator(*this); Append(aString); } @@ -1398,7 +1397,7 @@ nsAutoString::nsAutoString(const PRUnichar* aString) : nsString() { * @param aLength tells us how many chars to copy from aString */ nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString() { - nsStrPrivate::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); + Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); AddNullTerminator(*this); Append(aString,aLength); } @@ -1406,7 +1405,7 @@ nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString( nsAutoString::nsAutoString( const nsString& aString ) : nsString() { - nsStrPrivate::Initialize(*this, mBuffer, (sizeof(mBuffer)>>eTwoByte)-1, 0, eTwoByte, PR_FALSE); + Initialize(*this, mBuffer, (sizeof(mBuffer)>>eTwoByte)-1, 0, eTwoByte, PR_FALSE); AddNullTerminator(*this); Append(aString); } @@ -1414,7 +1413,7 @@ nsAutoString::nsAutoString( const nsString& aString ) nsAutoString::nsAutoString( const nsAString& aString ) : nsString() { - nsStrPrivate::Initialize(*this, mBuffer, (sizeof(mBuffer)>>eTwoByte)-1, 0, eTwoByte, PR_FALSE); + Initialize(*this, mBuffer, (sizeof(mBuffer)>>eTwoByte)-1, 0, eTwoByte, PR_FALSE); AddNullTerminator(*this); Append(aString); } @@ -1427,10 +1426,10 @@ nsAutoString::nsAutoString( const nsAString& aString ) */ nsAutoString::nsAutoString(const CBufDescriptor& aBuffer) : nsString() { if(!aBuffer.mBuffer) { - nsStrPrivate::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); + Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); } else { - nsStrPrivate::Initialize(*this,aBuffer.mBuffer,aBuffer.mCapacity,aBuffer.mLength,aBuffer.mCharSize,!aBuffer.mStackBased); + Initialize(*this,aBuffer.mBuffer,aBuffer.mCapacity,aBuffer.mLength,aBuffer.mCharSize,!aBuffer.mStackBased); } if(!aBuffer.mIsConst) AddNullTerminator(*this); @@ -1545,7 +1544,7 @@ NS_ConvertUTF8toUCS2::Init( const nsACString& aCString ) * Default copy constructor */ nsAutoString::nsAutoString(const nsAutoString& aString) : nsString() { - nsStrPrivate::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); + Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); AddNullTerminator(*this); Append(aString); } @@ -1556,7 +1555,7 @@ nsAutoString::nsAutoString(const nsAutoString& aString) : nsString() { * @param */ nsAutoString::nsAutoString(PRUnichar aChar) : nsString(){ - nsStrPrivate::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); + Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); AddNullTerminator(*this); Append(aChar); } diff --git a/mozilla/xpcom/string/obsolete/nsStr.cpp b/mozilla/xpcom/string/obsolete/nsStr.cpp index 27b8715df4d..4acc9ab610d 100644 --- a/mozilla/xpcom/string/obsolete/nsStr.cpp +++ b/mozilla/xpcom/string/obsolete/nsStr.cpp @@ -37,7 +37,6 @@ * * ***** END LICENSE BLOCK ***** */ -#include "nsStrPrivate.h" #include "nsStr.h" #include "bufferRoutines.h" #include //only used for printf @@ -72,7 +71,7 @@ static PRBool gStringAcquiredMemory = PR_TRUE; * @param * @return */ -void nsStrPrivate::Initialize(nsStr& aDest,eCharSize aCharSize) { +void nsStr::Initialize(nsStr& aDest,eCharSize aCharSize) { aDest.mStr=(char*)gCommonEmptyBuffer; aDest.mLength=0; aDest.SetInternalCapacity(0); @@ -86,7 +85,7 @@ void nsStrPrivate::Initialize(nsStr& aDest,eCharSize aCharSize) { * @param * @return */ -void nsStrPrivate::Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 aLength,eCharSize aCharSize,PRBool aOwnsBuffer){ +void nsStr::Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 aLength,eCharSize aCharSize,PRBool aOwnsBuffer){ aDest.mStr=(aCString) ? aCString : (char*)gCommonEmptyBuffer; aDest.mLength=aLength; aDest.SetInternalCapacity(aCapacity); @@ -100,7 +99,7 @@ void nsStrPrivate::Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRU * @param * @return */ -void nsStrPrivate::Destroy(nsStr& aDest) { +void nsStr::Destroy(nsStr& aDest) { if((aDest.mStr) && (aDest.mStr!=(char*)gCommonEmptyBuffer)) { Free(aDest); } @@ -114,7 +113,7 @@ void nsStrPrivate::Destroy(nsStr& aDest) { * @param aNewLength -- new capacity of string in charSize units * @return void */ -PRBool nsStrPrivate::EnsureCapacity(nsStr& aString,PRUint32 aNewLength) { +PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength) { PRBool result=PR_TRUE; if(aNewLength>aString.GetCapacity()) { result=Realloc(aString,aNewLength); @@ -131,11 +130,11 @@ PRBool nsStrPrivate::EnsureCapacity(nsStr& aString,PRUint32 aNewLength) { * @param aNewLength -- new capacity of string in charSize units * @return void */ -PRBool nsStrPrivate::GrowCapacity(nsStr& aDest,PRUint32 aNewLength) { +PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength) { PRBool result=PR_TRUE; if(aNewLength>aDest.GetCapacity()) { nsStr theTempStr; - nsStrPrivate::Initialize(theTempStr,eCharSize(aDest.GetCharSize())); + nsStr::Initialize(theTempStr,eCharSize(aDest.GetCharSize())); // the new strategy is, allocate exact size, double on grows if ( aDest.GetCapacity() ) { @@ -168,7 +167,7 @@ PRBool nsStrPrivate::GrowCapacity(nsStr& aDest,PRUint32 aNewLength) { * @param aSource is where chars are copied from * @param aCount is the number of chars copied from aSource */ -void nsStrPrivate::StrAssign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount){ +void nsStr::StrAssign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount){ if(&aDest!=&aSource){ StrTruncate(aDest,0); StrAppend(aDest,aSource,anOffset,aCount); @@ -183,7 +182,7 @@ void nsStrPrivate::StrAssign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset * @param aSource is where char are copied from * @aCount is the number of bytes to be copied */ -void nsStrPrivate::StrAppend(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount){ +void nsStr::StrAppend(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount){ if(anOffset0) && aSet){ PRInt32 theIndex=-1; @@ -543,7 +542,7 @@ void nsStrPrivate::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,P * @param * @return */ -void nsStrPrivate::CompressSet1(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){ +void nsStr::CompressSet1(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){ NS_ASSERTION(aDest.GetCharSize() == eOneByte, "Must be 1 byte"); Trim(aDest,aSet,aEliminateLeading,aEliminateTrailing); @@ -552,7 +551,7 @@ void nsStrPrivate::CompressSet1(nsStr& aDest,const char* aSet,PRBool aEliminateL NSSTR_SEEN(aDest); } -void nsStrPrivate::CompressSet2(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){ +void nsStr::CompressSet2(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){ NS_ASSERTION(aDest.GetCharSize() == eTwoByte, "Must be 2 bytes"); Trim(aDest,aSet,aEliminateLeading,aEliminateTrailing); @@ -568,7 +567,7 @@ void nsStrPrivate::CompressSet2(nsStr& aDest,const char* aSet,PRBool aEliminateL * @param * @return */ -void nsStrPrivate::StripChars1(nsStr& aDest,const char* aSet){ +void nsStr::StripChars1(nsStr& aDest,const char* aSet){ NS_ASSERTION(aDest.GetCharSize() == eOneByte, "Must be 1 byte"); if((0aSource=1 */ -PRInt32 nsStrPrivate::StrCompare1To1(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) { +PRInt32 nsStr::StrCompare1To1(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) { NS_ASSERTION(aDest.GetCharSize() == eOneByte, "Must be 1 byte"); NS_ASSERTION(aSource.GetCharSize() == eOneByte, "Must be 1 byte"); if (aCount) { @@ -1152,7 +1151,7 @@ PRInt32 nsStrPrivate::StrCompare1To1(const nsStr& aDest,const nsStr& aSource,PRI return 0; } -PRInt32 nsStrPrivate::StrCompare1To2(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) { +PRInt32 nsStr::StrCompare1To2(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) { NS_ASSERTION(aDest.GetCharSize() == eOneByte, "Must be 1 byte"); NS_ASSERTION(aSource.GetCharSize() == eTwoByte, "Must be 2 byte"); @@ -1166,7 +1165,7 @@ PRInt32 nsStrPrivate::StrCompare1To2(const nsStr& aDest,const nsStr& aSource,PRI return 0; } -PRInt32 nsStrPrivate::StrCompare2To1(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) { +PRInt32 nsStr::StrCompare2To1(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) { NS_ASSERTION(aDest.GetCharSize() == eTwoByte, "Must be 2 byte"); NS_ASSERTION(aSource.GetCharSize() == eOneByte, "Must be 1 byte"); @@ -1180,7 +1179,7 @@ PRInt32 nsStrPrivate::StrCompare2To1(const nsStr& aDest,const nsStr& aSource,PRI return 0; } -PRInt32 nsStrPrivate::StrCompare2To2(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) { +PRInt32 nsStr::StrCompare2To2(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) { NS_ASSERTION(aDest.GetCharSize() == eTwoByte, "Must be 2 byte"); NS_ASSERTION(aSource.GetCharSize() == eTwoByte, "Must be 2 byte"); @@ -1202,7 +1201,7 @@ PRInt32 nsStrPrivate::StrCompare2To2(const nsStr& aDest,const nsStr& aSource,PRI * @param aDestOffset is the offset within aDest where source should be copied * @return error code */ -void nsStrPrivate::Overwrite(nsStr& aDest,const nsStr& aSource,PRInt32 aDestOffset) { +void nsStr::Overwrite(nsStr& aDest,const nsStr& aSource,PRInt32 aDestOffset) { if(aDest.mLength && aSource.mLength) { if((aDest.mLength-aDestOffset)>=aSource.mLength) { //if you're here, then both dest and source have valid lengths @@ -1214,7 +1213,7 @@ void nsStrPrivate::Overwrite(nsStr& aDest,const nsStr& aSource,PRInt32 aDestOffs //---------------------------------------------------------------------------------------- // allocate the given bytes, not including the null terminator -PRBool nsStrPrivate::Alloc(nsStr& aDest,PRUint32 aCount) { +PRBool nsStr::Alloc(nsStr& aDest,PRUint32 aCount) { // the new strategy is, allocate exact size, double on grows aDest.SetInternalCapacity(aCount); @@ -1230,7 +1229,7 @@ PRBool nsStrPrivate::Alloc(nsStr& aDest,PRUint32 aCount) { return (aDest.mStr != nsnull); } -PRBool nsStrPrivate::Free(nsStr& aDest){ +PRBool nsStr::Free(nsStr& aDest){ if(aDest.mStr){ if(aDest.GetOwnsBuffer()){ nsMemory::Free(aDest.mStr); @@ -1242,7 +1241,7 @@ PRBool nsStrPrivate::Free(nsStr& aDest){ return PR_FALSE; } -PRBool nsStrPrivate::Realloc(nsStr& aDest,PRUint32 aCount){ +PRBool nsStr::Realloc(nsStr& aDest,PRUint32 aCount){ nsStr temp; memcpy(&temp,&aDest,sizeof(aDest)); @@ -1264,7 +1263,7 @@ PRBool nsStrPrivate::Realloc(nsStr& aDest,PRUint32 aCount){ * @update gess 10/11/99 * @return memory error (usually returns PR_TRUE) */ -PRBool nsStrPrivate::DidAcquireMemory(void) { +PRBool nsStr::DidAcquireMemory(void) { return gStringAcquiredMemory; } #endif @@ -1331,7 +1330,7 @@ CBufDescriptor::CBufDescriptor(const PRUnichar* aString,PRBool aStackBased,PRUin //---------------------------------------------------------------------------------------- PRUint32 -nsStrPrivate::HashCode(const nsStr& aDest) +nsStr::HashCode(const nsStr& aDest) { if (aDest.GetCharSize() == eTwoByte) return nsCRT::HashCode(aDest.mUStr); @@ -1348,7 +1347,7 @@ nsStrPrivate::HashCode(const nsStr& aDest) #endif void -nsStrPrivate::Print(const nsStr& aDest, FILE* out, PRBool truncate) +nsStr::Print(const nsStr& aDest, FILE* out, PRBool truncate) { PRInt32 printLen = (PRInt32)aDest.mLength; @@ -1379,9 +1378,9 @@ PRBool gNoStringInfo = PR_FALSE; nsStringInfo::nsStringInfo(nsStr& str) : mCount(0) { - nsStrPrivate::Initialize(mStr, str.GetCharSize()); - nsStrPrivate::StrAssign(mStr, str, 0, -1); -// nsStrPrivate::Print(mStr, stdout); + nsStr::Initialize(mStr, str.GetCharSize()); + nsStr::StrAssign(mStr, str, 0, -1); +// nsStr::Print(mStr, stdout); // fputc('\n', stdout); } @@ -1389,7 +1388,7 @@ PR_EXTERN(PRHashNumber) nsStr_Hash(const void* key) { nsStr* str = (nsStr*)key; - return nsStrPrivate::HashCode(*str); + return nsStr::HashCode(*str); } nsStringInfo* @@ -1447,7 +1446,7 @@ nsStringInfo::ReportEntry(PLHashEntry *he, PRIntn i, void *arg) FILE* out = (FILE*)arg; fprintf(out, "%d ==> (%d) ", entry->mCount, entry->mStr.mLength); - nsStrPrivate::Print(entry->mStr, out, PR_TRUE); + nsStr::Print(entry->mStr, out, PR_TRUE); fputc('\n', out); return HT_ENUMERATE_NEXT; } diff --git a/mozilla/xpcom/string/obsolete/nsStr.h b/mozilla/xpcom/string/obsolete/nsStr.h index 8d9adf44ea7..968d6e80f3f 100644 --- a/mozilla/xpcom/string/obsolete/nsStr.h +++ b/mozilla/xpcom/string/obsolete/nsStr.h @@ -267,6 +267,225 @@ protected: MOZ_COUNT_DTOR(nsStr); } + /** + * This method initializes an nsStr for use + * + * @update gess 01/04/99 + * @param aString is the nsStr to be initialized + * @param aCharSize tells us the requested char size (1 or 2 bytes) + */ + static void Initialize(nsStr& aDest,eCharSize aCharSize); + + /** + * This method initializes an nsStr for use + * + * @update gess 01/04/99 + * @param aString is the nsStr to be initialized + * @param aCharSize tells us the requested char size (1 or 2 bytes) + */ + static void Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 aLength,eCharSize aCharSize,PRBool aOwnsBuffer); + /** + * This method destroys the given nsStr, and *MAY* + * deallocate it's memory depending on the setting + * of the internal mOwnsBUffer flag. + * + * @update gess 01/04/99 + * @param aString is the nsStr to be manipulated + */ + static void Destroy(nsStr& aDest); + + /** + * These methods are where memory allocation/reallocation occur. + * + * @update gess 01/04/99 + * @param aString is the nsStr to be manipulated + * @return + */ + static PRBool EnsureCapacity(nsStr& aString,PRUint32 aNewLength); + static PRBool GrowCapacity(nsStr& aString,PRUint32 aNewLength); + + /** + * These methods are used to append content to the given nsStr + * + * @update gess 01/04/99 + * @param aDest is the nsStr to be appended to + * @param aSource is the buffer to be copied from + * @param anOffset tells us where in source to start copying + * @param aCount tells us the (max) # of chars to copy + */ + static void StrAppend(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount); + + /** + * These methods are used to assign contents of a source string to dest string + * + * @update gess 01/04/99 + * @param aDest is the nsStr to be appended to + * @param aSource is the buffer to be copied from + * @param anOffset tells us where in source to start copying + * @param aCount tells us the (max) # of chars to copy + */ + static void StrAssign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount); + + /** + * These methods are used to insert content from source string to the dest nsStr + * + * @update gess 01/04/99 + * @param aDest is the nsStr to be appended to + * @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 + */ + static void StrInsert1into1( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount); + static void StrInsert1into2( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount); + static void StrInsert2into1( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount); + static void StrInsert2into2( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount); + + + /** + * Helper routines for StrInsert1into1, etc + */ + static PRInt32 GetSegmentLength(const nsStr& aSource, + PRUint32 aSrcOffset, PRInt32 aCount); + static void AppendForInsert(nsStr& aDest, PRUint32 aDestOffset, const nsStr& aSource, PRUint32 aSrcOffset, PRInt32 theLength); + + /** + * This method deletes chars from the given str. + * The given allocator may choose to resize the str as well. + * + * @update gess 01/04/99 + * @param aDest is the nsStr to be deleted from + * @param aDestOffset tells us where in dest to start deleting + * @param aCount tells us the (max) # of chars to delete + */ + static void Delete1(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount); + static void Delete2(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount); + + /** + * helper routines for Delete1, Delete2 + */ + static PRInt32 GetDeleteLength(const nsStr& aDest, PRUint32 aDestOffset, PRUint32 aCount); + + /** + * This method is used to truncate the given string. + * The given allocator may choose to resize the str as well (but it's not likely). + * + * @update gess 01/04/99 + * @param aDest is the nsStr to be appended to + * @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 + */ + static void StrTruncate(nsStr& aDest,PRUint32 aDestOffset); + + /** + * This method trims chars (given in aSet) from the edges of given buffer + * + * @update gess 01/04/99 + * @param aDest is the buffer to be manipulated + * @param aSet tells us which chars to remove from given buffer + * @param aEliminateLeading tells us whether to strip chars from the start of the buffer + * @param aEliminateTrailing tells us whether to strip chars from the start of the buffer + */ + static void Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing); + + /** + * This method compresses duplicate runs of a given char from the given buffer + * + * @update gess 01/04/99 + * @param aDest is the buffer to be manipulated + * @param aSet tells us which chars to compress from given buffer + * @param aChar is the replacement char + * @param aEliminateLeading tells us whether to strip chars from the start of the buffer + * @param aEliminateTrailing tells us whether to strip chars from the start of the buffer + */ + static void CompressSet1(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing); + static void CompressSet2(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing); + + /** + * This method removes all occurances of chars in given set from aDest + * + * @update gess 01/04/99 + * @param aDest is the buffer to be manipulated + * @param aSet tells us which chars to compress from given buffer + * @param aChar is the replacement char + * @param aEliminateLeading tells us whether to strip chars from the start of the buffer + * @param aEliminateTrailing tells us whether to strip chars from the start of the buffer + */ + static void StripChars1(nsStr& aDest,const char* aSet); + static void StripChars2(nsStr& aDest,const char* aSet); + + /** + * This method compares the data bewteen two nsStr's + * + * @update gess 01/04/99 + * @param aStr1 is the first buffer to be compared + * @param aStr2 is the 2nd buffer to be compared + * @param aCount is the number of chars to compare + * @param aIgnorecase tells us whether to use a case-sensitive comparison + * @return -1,0,1 depending on <,==,> + */ + static PRInt32 StrCompare1To1(const nsStr& aDest,const nsStr& aSource, + PRInt32 aCount,PRBool aIgnoreCase); + static PRInt32 StrCompare1To2(const nsStr& aDest, const nsStr& aSource, + PRInt32 aCount, PRBool aIgnoreCase); + static PRInt32 StrCompare2To1(const nsStr& aDest, const nsStr& aSource, + PRInt32 aCount, PRBool aIgnoreCase); + static PRInt32 StrCompare2To2(const nsStr& aDest, const nsStr& aSource, + PRInt32 aCount, PRBool aIgnoreCase); + + /** + * These methods scan the given string for 1 or more chars in a given direction + * + * @update gess 01/04/99 + * @param aDest is the nsStr to be searched to + * @param aSource (or aChar) is the substr we're looking to find + * @param aIgnoreCase tells us whether to search in a case-sensitive manner + * @param anOffset tells us where in the dest string to start searching + * @return the index of the source (substr) in dest, or -1 (kNotFound) if not found. + */ + static PRInt32 FindSubstr1in1(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount); + static PRInt32 FindSubstr1in2(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount); + static PRInt32 FindSubstr2in1(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount); + static PRInt32 FindSubstr2in2(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount); + + static PRInt32 FindChar1(const nsStr& aDest,PRUnichar aChar, PRInt32 anOffset,PRInt32 aCount); + static PRInt32 FindChar2(const nsStr& aDest,PRUnichar aChar, PRInt32 anOffset,PRInt32 aCount); + + static PRInt32 FindCharInSet1(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset); + static PRInt32 FindCharInSet2(const nsStr& aDest,const nsStr& aSet,PRInt32 anOffset); + + static PRInt32 RFindSubstr1in1(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount); + static PRInt32 RFindSubstr2in1(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount); + static PRInt32 RFindSubstr1in2(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount); + static PRInt32 RFindSubstr2in2(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount); + + static PRInt32 RFindChar1(const nsStr& aDest,PRUnichar aChar, PRInt32 anOffset,PRInt32 aCount); + static PRInt32 RFindChar2(const nsStr& aDest,PRUnichar aChar, PRInt32 anOffset,PRInt32 aCount); + + static PRInt32 RFindCharInSet1(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset); + static PRInt32 RFindCharInSet2(const nsStr& aDest,const nsStr& aSet,PRInt32 anOffset); + + static void Overwrite(nsStr& aDest,const nsStr& aSource,PRInt32 anOffset); + +#ifdef NS_STR_STATS + static PRBool DidAcquireMemory(void); +#endif + + /** + * Returns a hash code for the string for use in a PLHashTable. + */ + static PRUint32 HashCode(const nsStr& aDest); + +#ifdef NS_STR_STATS + /** + * Prints an nsStr. If truncate is true, the string is only printed up to + * the first newline. (Note: The current implementation doesn't handle + * non-ascii unicode characters.) + */ + static void Print(const nsStr& aDest, FILE* out, PRBool truncate = PR_FALSE); +#endif + protected: union { char* mStr; @@ -309,13 +528,16 @@ private: (aOwnsBuffer ? 1 : 0) << NSSTR_OWNSBUFFER_BIT); } + static PRBool Alloc(nsStr& aString,PRUint32 aCount); + static PRBool Realloc(nsStr& aString,PRUint32 aCount); + static PRBool Free(nsStr& aString); + public: friend NS_COM char* ToNewUTF8String( const nsAString& aSource ); friend inline void AddNullTerminator(nsStr& aDest); friend inline PRUnichar GetCharAt(const nsStr& aDest,PRUint32 anIndex); - friend class nsStrPrivate; friend class nsString; friend class nsCString; }; diff --git a/mozilla/xpcom/string/obsolete/nsString.cpp b/mozilla/xpcom/string/obsolete/nsString.cpp index bab9e69e501..1be4da8c3fd 100644 --- a/mozilla/xpcom/string/obsolete/nsString.cpp +++ b/mozilla/xpcom/string/obsolete/nsString.cpp @@ -41,7 +41,6 @@ #include #include #include -#include "nsStrPrivate.h" #include "nsString.h" #include "nsReadableUtils.h" #include "nsDebug.h" @@ -67,11 +66,11 @@ nsCString::GetFlatBufferHandle() const * Default constructor. */ nsCString::nsCString() { - nsStrPrivate::Initialize(*this,eOneByte); + Initialize(*this,eOneByte); } nsCString::nsCString(const char* aCString) { - nsStrPrivate::Initialize(*this,eOneByte); + Initialize(*this,eOneByte); Assign(aCString); } @@ -82,7 +81,7 @@ nsCString::nsCString(const char* aCString) { * @param aLength tells us how many chars to copy from given CString */ nsCString::nsCString(const char* aCString,PRInt32 aLength) { - nsStrPrivate::Initialize(*this,eOneByte); + Initialize(*this,eOneByte); Assign(aCString,aLength); } @@ -92,15 +91,15 @@ nsCString::nsCString(const char* aCString,PRInt32 aLength) { * @param reference to another nsCString */ nsCString::nsCString(const nsCString& aString) { - nsStrPrivate::Initialize(*this,aString.GetCharSize()); - nsStrPrivate::StrAssign(*this,aString,0,aString.mLength); + Initialize(*this,aString.GetCharSize()); + StrAssign(*this,aString,0,aString.mLength); } /** * Destructor */ nsCString::~nsCString() { - nsStrPrivate::Destroy(*this); + Destroy(*this); } const char* nsCString::GetReadableFragment( nsReadableFragment& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset ) const { @@ -134,7 +133,7 @@ char* nsCString::GetWritableFragment( nsWritableFragment& aFragment, nsFra } nsCString::nsCString( const nsACString& aReadable ) { - nsStrPrivate::Initialize(*this,eOneByte); + Initialize(*this,eOneByte); Assign(aReadable); } @@ -159,7 +158,7 @@ void nsCString::SetLength(PRUint32 anIndex) { // |SetCapacity| normally doesn't guarantee the use we are putting it to here (see its interface comment in nsAWritableString.h), // we can only use it since our local implementation, |nsCString::SetCapacity|, is known to do what we want - nsStrPrivate::StrTruncate(*this,anIndex); + nsStr::StrTruncate(*this,anIndex); } @@ -175,13 +174,13 @@ nsCString::SetCapacity( PRUint32 aNewCapacity ) if ( aNewCapacity ) { if( aNewCapacity > GetCapacity() ) - nsStrPrivate::GrowCapacity(*this,aNewCapacity); + GrowCapacity(*this,aNewCapacity); AddNullTerminator(*this); } else { - nsStrPrivate::Destroy(*this); - nsStrPrivate::Initialize(*this, eOneByte); + nsStr::Destroy(*this); + nsStr::Initialize(*this, eOneByte); } } @@ -249,7 +248,7 @@ nsCString::StripChar(PRUnichar aChar,PRInt32 anOffset){ */ void nsCString::StripChars(const char* aSet){ - nsStrPrivate::StripChars1(*this,aSet); + nsStr::StripChars1(*this,aSet); } @@ -354,19 +353,19 @@ nsCString::ReplaceSubstring(const nsCString& aTarget,const nsCString& aNewValue) } else { PRInt32 theIndex=0; - while(kNotFound!=(theIndex=nsStrPrivate::FindSubstr1in1(*this,aTarget,PR_FALSE,theIndex,mLength))) { + while(kNotFound!=(theIndex=nsStr::FindSubstr1in1(*this,aTarget,PR_FALSE,theIndex,mLength))) { if(aNewValue.mLength 0 ) { temp.mLength = aLength; - nsStrPrivate::StrAppend(*this, temp, 0, aLength); + StrAppend(*this, temp, 0, aLength); } } @@ -789,7 +788,7 @@ void nsCString::AppendWithConversion(const nsString& aString,PRInt32 aCount) { else aCount=MinInt(aCount,aString.mLength); if(0::length(aPtr); // We don't know the capacity, so we'll just have to assume // capacity = length. - nsStrPrivate::Initialize(*this, aPtr, aLength, aLength, eOneByte, PR_TRUE); + nsStr::Initialize(*this, aPtr, aLength, aLength, eOneByte, PR_TRUE); } /********************************************************************** @@ -841,10 +840,10 @@ PRInt32 nsCString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset PRInt32 result=kNotFound; if(aCString) { nsStr temp; - nsStrPrivate::Initialize(temp,eOneByte); + nsStr::Initialize(temp,eOneByte); temp.mLength = nsCRT::strlen(aCString); temp.mStr=(char*)aCString; - result=nsStrPrivate::FindSubstr1in1(*this,temp,aIgnoreCase,anOffset,aCount); + result=nsStr::FindSubstr1in1(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } @@ -865,10 +864,10 @@ PRInt32 nsCString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOf PRInt32 result=kNotFound; if(aString) { nsStr temp; - nsStrPrivate::Initialize(temp,eTwoByte); + nsStr::Initialize(temp,eTwoByte); temp.mLength = nsCRT::strlen(aString); temp.mUStr=(PRUnichar*)aString; - result=nsStrPrivate::FindSubstr2in1(*this,temp,aIgnoreCase,anOffset,aCount); + result=nsStr::FindSubstr2in1(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } @@ -884,12 +883,12 @@ PRInt32 nsCString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOf * @return offset in string, or -1 (kNotFound) */ PRInt32 nsCString::Find(const nsCString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ - PRInt32 result=nsStrPrivate::FindSubstr1in1(*this,aString,aIgnoreCase,anOffset,aCount); + PRInt32 result=nsStr::FindSubstr1in1(*this,aString,aIgnoreCase,anOffset,aCount); return result; } PRInt32 nsCString::Find(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ - PRInt32 result=nsStrPrivate::FindSubstr1in2(*this,aString,aIgnoreCase,anOffset,aCount); + PRInt32 result=nsStr::FindSubstr1in2(*this,aString,aIgnoreCase,anOffset,aCount); return result; } @@ -905,7 +904,7 @@ PRInt32 nsCString::Find(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOff * @return index in aDest where member of aSet occurs, or -1 if not found */ PRInt32 nsCString::FindChar(PRUnichar aChar,PRInt32 anOffset,PRInt32 aCount) const{ - PRInt32 result=nsStrPrivate::FindChar1(*this,aChar,anOffset,aCount); + PRInt32 result=nsStr::FindChar1(*this,aChar,anOffset,aCount); return result; } @@ -924,10 +923,10 @@ PRInt32 nsCString::FindCharInSet(const char* aCStringSet,PRInt32 anOffset) const PRInt32 result=kNotFound; if(aCStringSet) { nsStr temp; - nsStrPrivate::Initialize(temp,eOneByte); + nsStr::Initialize(temp,eOneByte); temp.mLength=nsCRT::strlen(aCStringSet); temp.mStr=(char*)aCStringSet; - result=nsStrPrivate::FindCharInSet1(*this,temp,PR_FALSE,anOffset); + result=nsStr::FindCharInSet1(*this,temp,PR_FALSE,anOffset); } return result; } @@ -947,10 +946,10 @@ PRInt32 nsCString::FindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) c PRInt32 result=kNotFound; if(aStringSet) { nsStr temp; - nsStrPrivate::Initialize(temp,eTwoByte); + nsStr::Initialize(temp,eTwoByte); temp.mLength=nsCRT::strlen(aStringSet); temp.mStr=(char*)aStringSet; - result=nsStrPrivate::FindCharInSet2(*this,temp,anOffset); + result=nsStr::FindCharInSet2(*this,temp,anOffset); } return result; } @@ -965,12 +964,12 @@ PRInt32 nsCString::FindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) c * @return */ PRInt32 nsCString::FindCharInSet(const nsCString& aSet,PRInt32 anOffset) const{ - PRInt32 result=nsStrPrivate::FindCharInSet1(*this,aSet,PR_FALSE,anOffset); + PRInt32 result=nsStr::FindCharInSet1(*this,aSet,PR_FALSE,anOffset); return result; } PRInt32 nsCString::FindCharInSet(const nsString& aSet,PRInt32 anOffset) const{ - PRInt32 result=nsStrPrivate::FindCharInSet2(*this,aSet,anOffset); + PRInt32 result=nsStr::FindCharInSet2(*this,aSet,anOffset); return result; } @@ -985,12 +984,12 @@ PRInt32 nsCString::FindCharInSet(const nsString& aSet,PRInt32 anOffset) const{ * @return offset in string, or -1 (kNotFound) */ PRInt32 nsCString::RFind(const nsCString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ - PRInt32 result=nsStrPrivate::RFindSubstr1in1(*this,aString,aIgnoreCase,anOffset,aCount); + PRInt32 result=nsStr::RFindSubstr1in1(*this,aString,aIgnoreCase,anOffset,aCount); return result; } PRInt32 nsCString::RFind(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ - PRInt32 result=nsStrPrivate::RFindSubstr2in1(*this,aString,aIgnoreCase,anOffset,aCount); + PRInt32 result=nsStr::RFindSubstr2in1(*this,aString,aIgnoreCase,anOffset,aCount); return result; } @@ -1011,10 +1010,10 @@ PRInt32 nsCString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset PRInt32 result=kNotFound; if(aString) { nsStr temp; - nsStrPrivate::Initialize(temp,eOneByte); + nsStr::Initialize(temp,eOneByte); temp.mLength=nsCRT::strlen(aString); temp.mStr=(char*)aString; - result=nsStrPrivate::RFindSubstr1in1(*this,temp,aIgnoreCase,anOffset,aCount); + result=nsStr::RFindSubstr1in1(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } @@ -1030,7 +1029,7 @@ PRInt32 nsCString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset * @return index in aDest where member of aSet occurs, or -1 if not found */ PRInt32 nsCString::RFindChar(PRUnichar aChar,PRInt32 anOffset,PRInt32 aCount) const{ - PRInt32 result=nsStrPrivate::RFindChar1(*this,aChar,anOffset,aCount); + PRInt32 result=nsStr::RFindChar1(*this,aChar,anOffset,aCount); return result; } @@ -1048,10 +1047,10 @@ PRInt32 nsCString::RFindCharInSet(const char* aCStringSet,PRInt32 anOffset) cons PRInt32 result=kNotFound; if(aCStringSet) { nsStr temp; - nsStrPrivate::Initialize(temp,eOneByte); + nsStr::Initialize(temp,eOneByte); temp.mLength=nsCRT::strlen(aCStringSet); temp.mStr=(char*)aCStringSet; - result=nsStrPrivate::RFindCharInSet1(*this,temp,PR_FALSE,anOffset); + result=nsStr::RFindCharInSet1(*this,temp,PR_FALSE,anOffset); } return result; } @@ -1070,10 +1069,10 @@ PRInt32 nsCString::RFindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) PRInt32 result=kNotFound; if(aStringSet) { nsStr temp; - nsStrPrivate::Initialize(temp,eTwoByte); + nsStr::Initialize(temp,eTwoByte); temp.mLength=nsCRT::strlen(aStringSet); temp.mUStr=(PRUnichar*)aStringSet; - result=nsStrPrivate::RFindCharInSet2(*this,temp,anOffset); + result=nsStr::RFindCharInSet2(*this,temp,anOffset); } return result; } @@ -1088,12 +1087,12 @@ PRInt32 nsCString::RFindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) * @return offset of found char, or -1 (kNotFound) */ PRInt32 nsCString::RFindCharInSet(const nsCString& aSet,PRInt32 anOffset) const{ - PRInt32 result=nsStrPrivate::RFindCharInSet1(*this,aSet,PR_FALSE,anOffset); + PRInt32 result=nsStr::RFindCharInSet1(*this,aSet,PR_FALSE,anOffset); return result; } PRInt32 nsCString::RFindCharInSet(const nsString& aSet,PRInt32 anOffset) const{ - PRInt32 result=nsStrPrivate::RFindCharInSet2(*this,aSet,anOffset); + PRInt32 result=nsStr::RFindCharInSet2(*this,aSet,anOffset); return result; } @@ -1116,10 +1115,10 @@ PRInt32 nsCString::CompareWithConversion(const PRUnichar* aString,PRBool aIgnore if(aString) { nsStr temp; - nsStrPrivate::Initialize(temp,eTwoByte); + nsStr::Initialize(temp,eTwoByte); temp.mLength=nsCRT::strlen(aString); temp.mUStr=(PRUnichar*)aString; - return nsStrPrivate::StrCompare1To2(*this,temp,aCount,aIgnoreCase); + return nsStr::StrCompare1To2(*this,temp,aCount,aIgnoreCase); } return 0; } @@ -1137,10 +1136,10 @@ PRInt32 nsCString::CompareWithConversion(const char *aCString,PRBool aIgnoreCase if(aCString) { nsStr temp; - nsStrPrivate::Initialize(temp,eOneByte); + nsStr::Initialize(temp,eOneByte); temp.mLength=nsCRT::strlen(aCString); temp.mStr=(char*)aCString; - return nsStrPrivate::StrCompare1To1(*this,temp,aCount,aIgnoreCase); + return nsStr::StrCompare1To1(*this,temp,aCount,aIgnoreCase); } return 0; } @@ -1316,25 +1315,25 @@ NS_LossyConvertUCS2toASCII::NS_LossyConvertUCS2toASCII( const nsAString& aString * */ nsCAutoString::nsCAutoString() : nsCString(){ - nsStrPrivate::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); + Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); AddNullTerminator(*this); } nsCAutoString::nsCAutoString( const nsCString& aString ) : nsCString(){ - nsStrPrivate::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); + Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); AddNullTerminator(*this); Append(aString); } nsCAutoString::nsCAutoString( const nsACString& aString ) : nsCString(){ - nsStrPrivate::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); + Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); AddNullTerminator(*this); Append(aString); } nsCAutoString::nsCAutoString(const char* aCString) : nsCString() { - nsStrPrivate::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); + Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); AddNullTerminator(*this); Append(aCString); } @@ -1344,7 +1343,7 @@ nsCAutoString::nsCAutoString(const char* aCString) : nsCString() { * @param aCString is a ptr to a 1-byte cstr */ nsCAutoString::nsCAutoString(const char* aCString,PRInt32 aLength) : nsCString() { - nsStrPrivate::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); + Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); AddNullTerminator(*this); Append(aCString,aLength); } @@ -1355,10 +1354,10 @@ nsCAutoString::nsCAutoString(const char* aCString,PRInt32 aLength) : nsCString() */ nsCAutoString::nsCAutoString(const CBufDescriptor& aBuffer) : nsCString() { if(!aBuffer.mBuffer) { - nsStrPrivate::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); + Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE); } else { - nsStrPrivate::Initialize(*this,aBuffer.mBuffer,aBuffer.mCapacity,aBuffer.mLength,aBuffer.mCharSize,!aBuffer.mStackBased); + Initialize(*this,aBuffer.mBuffer,aBuffer.mCapacity,aBuffer.mLength,aBuffer.mCharSize,!aBuffer.mStackBased); } if(!aBuffer.mIsConst) AddNullTerminator(*this); //this isn't really needed, but it guarantees that folks don't pass string constants. diff --git a/mozilla/xpcom/string/obsolete/nsString2.cpp b/mozilla/xpcom/string/obsolete/nsString2.cpp index f9d0a9a3f67..10ef2e510b5 100644 --- a/mozilla/xpcom/string/obsolete/nsString2.cpp +++ b/mozilla/xpcom/string/obsolete/nsString2.cpp @@ -40,7 +40,6 @@ #include #include #include -#include "nsStrPrivate.h" #include "nsString.h" #include "nsReadableUtils.h" #include "nsDebug.h" @@ -66,11 +65,11 @@ nsString::GetFlatBufferHandle() const * Default constructor. */ nsString::nsString() { - nsStrPrivate::Initialize(*this,eTwoByte); + Initialize(*this,eTwoByte); } nsString::nsString(const PRUnichar* aString) { - nsStrPrivate::Initialize(*this,eTwoByte); + Initialize(*this,eTwoByte); Assign(aString); } @@ -81,7 +80,7 @@ nsString::nsString(const PRUnichar* aString) { * @param aLength tells us how many chars to copy from given aString */ nsString::nsString(const PRUnichar* aString,PRInt32 aCount) { - nsStrPrivate::Initialize(*this,eTwoByte); + Initialize(*this,eTwoByte); Assign(aString,aCount); } @@ -91,16 +90,16 @@ nsString::nsString(const PRUnichar* aString,PRInt32 aCount) { * @param reference to another nsString */ nsString::nsString(const nsString& aString) { - nsStrPrivate::Initialize(*this,eTwoByte); - nsStrPrivate::StrAssign(*this,aString,0,aString.mLength); + Initialize(*this,eTwoByte); + StrAssign(*this,aString,0,aString.mLength); } /** * Destructor - * Make sure we call nsStrPrivate::Destroy. + * Make sure we call nsStr::Destroy. */ nsString::~nsString() { - nsStrPrivate::Destroy(*this); + nsStr::Destroy(*this); } const PRUnichar* nsString::GetReadableFragment( nsReadableFragment& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset ) const { @@ -141,15 +140,15 @@ nsString::do_AppendFromElement( PRUnichar inChar ) buf[0] = inChar; nsStr temp; - nsStrPrivate::Initialize(temp, eTwoByte); + nsStr::Initialize(temp, eTwoByte); temp.mUStr = buf; temp.mLength = 1; - nsStrPrivate::StrAppend(*this, temp, 0, 1); + StrAppend(*this, temp, 0, 1); } nsString::nsString( const nsAString& aReadable ) { - nsStrPrivate::Initialize(*this,eTwoByte); + Initialize(*this,eTwoByte); Assign(aReadable); } @@ -173,7 +172,7 @@ void nsString::SetLength(PRUint32 anIndex) { SetCapacity(anIndex); // |SetCapacity| normally doesn't guarantee the use we are putting it to here (see its interface comment in nsAWritableString.h), // we can only use it since our local implementation, |nsString::SetCapacity|, is known to do what we want - nsStrPrivate::StrTruncate(*this,anIndex); + nsStr::StrTruncate(*this,anIndex); } @@ -189,13 +188,13 @@ nsString::SetCapacity( PRUint32 aNewCapacity ) if ( aNewCapacity ) { if( aNewCapacity > GetCapacity() ) - nsStrPrivate::GrowCapacity(*this, aNewCapacity); + GrowCapacity(*this, aNewCapacity); AddNullTerminator(*this); } else { - nsStrPrivate::Destroy(*this); - nsStrPrivate::Initialize(*this, eTwoByte); + nsStr::Destroy(*this); + nsStr::Initialize(*this, eTwoByte); } } @@ -300,7 +299,7 @@ nsString::StripChar(PRUnichar aChar,PRInt32 anOffset){ */ void nsString::StripChars(const char* aSet){ - nsStrPrivate::StripChars2(*this,aSet); + nsStr::StripChars2(*this,aSet); } @@ -410,19 +409,19 @@ nsString::ReplaceSubstring(const nsString& aTarget,const nsString& aNewValue){ } else { PRInt32 theIndex=0; - while(kNotFound!=(theIndex=nsStrPrivate::FindSubstr2in2(*this,aTarget,PR_FALSE,theIndex,mLength))) { + while(kNotFound!=(theIndex=nsStr::FindSubstr2in2(*this,aTarget,PR_FALSE,theIndex,mLength))) { if(aNewValue.mLength::length(aPtr); // We don't know the capacity, so we'll just have to assume // capacity = length. - nsStrPrivate::Initialize(*this, (char*)aPtr, aLength, aLength, eTwoByte, PR_TRUE); + nsStr::Initialize(*this, (char*)aPtr, aLength, aLength, eTwoByte, PR_TRUE); } @@ -884,10 +883,10 @@ PRInt32 nsString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset, PRInt32 result=kNotFound; if(aCString) { nsStr temp; - nsStrPrivate::Initialize(temp,eOneByte); + nsStr::Initialize(temp,eOneByte); temp.mLength=nsCRT::strlen(aCString); temp.mStr=(char*)aCString; - result=nsStrPrivate::FindSubstr1in2(*this,temp,aIgnoreCase,anOffset,aCount); + result=nsStr::FindSubstr1in2(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } @@ -908,10 +907,10 @@ PRInt32 nsString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOff PRInt32 result=kNotFound; if(aString) { nsStr temp; - nsStrPrivate::Initialize(temp,eTwoByte); + nsStr::Initialize(temp,eTwoByte); temp.mLength=nsCRT::strlen(aString); temp.mUStr=(PRUnichar*)aString; - result=nsStrPrivate::FindSubstr2in2(*this,temp,aIgnoreCase,anOffset,aCount); + result=nsStr::FindSubstr2in2(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } @@ -927,7 +926,7 @@ PRInt32 nsString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOff * @return offset in string, or -1 (kNotFound) */ PRInt32 nsString::Find(const nsCString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ - PRInt32 result=nsStrPrivate::FindSubstr1in2(*this,aString,aIgnoreCase,anOffset,aCount); + PRInt32 result=nsStr::FindSubstr1in2(*this,aString,aIgnoreCase,anOffset,aCount); return result; } @@ -942,7 +941,7 @@ PRInt32 nsString::Find(const nsCString& aString,PRBool aIgnoreCase,PRInt32 anOff * @return offset in string, or -1 (kNotFound) */ PRInt32 nsString::Find(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ - PRInt32 result=nsStrPrivate::FindSubstr2in2(*this,aString,aIgnoreCase,anOffset,aCount); + PRInt32 result=nsStr::FindSubstr2in2(*this,aString,aIgnoreCase,anOffset,aCount); return result; } @@ -961,10 +960,10 @@ PRInt32 nsString::FindCharInSet(const char* aCStringSet,PRInt32 anOffset) const{ PRInt32 result=kNotFound; if(aCStringSet) { nsStr temp; - nsStrPrivate::Initialize(temp,eOneByte); + nsStr::Initialize(temp,eOneByte); temp.mLength=nsCRT::strlen(aCStringSet); temp.mStr=(char*)aCStringSet; - result=nsStrPrivate::FindCharInSet1(*this,temp,PR_FALSE,anOffset); + result=nsStr::FindCharInSet1(*this,temp,PR_FALSE,anOffset); } return result; } @@ -984,10 +983,10 @@ PRInt32 nsString::FindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) co PRInt32 result=kNotFound; if(aStringSet) { nsStr temp; - nsStrPrivate::Initialize(temp,eTwoByte); + nsStr::Initialize(temp,eTwoByte); temp.mLength=nsCRT::strlen(aStringSet); temp.mStr=(char*)aStringSet; - result=nsStrPrivate::FindCharInSet2(*this,temp,anOffset); + result=nsStr::FindCharInSet2(*this,temp,anOffset); } return result; } @@ -1002,12 +1001,12 @@ PRInt32 nsString::FindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) co * @return */ PRInt32 nsString::FindCharInSet(const nsString& aSet,PRInt32 anOffset) const{ - PRInt32 result=nsStrPrivate::FindCharInSet2(*this,aSet,anOffset); + PRInt32 result=nsStr::FindCharInSet2(*this,aSet,anOffset); return result; } PRInt32 nsString::FindCharInSet(const nsCString& aSet,PRInt32 anOffset) const{ - PRInt32 result=nsStrPrivate::FindCharInSet1(*this,aSet,PR_FALSE,anOffset); + PRInt32 result=nsStr::FindCharInSet1(*this,aSet,PR_FALSE,anOffset); return result; } @@ -1023,7 +1022,7 @@ PRInt32 nsString::FindCharInSet(const nsCString& aSet,PRInt32 anOffset) const{ * @return offset in string, or -1 (kNotFound) */ PRInt32 nsString::RFind(const nsCString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ - PRInt32 result=nsStrPrivate::RFindSubstr1in2(*this,aString,aIgnoreCase,anOffset,aCount); + PRInt32 result=nsStr::RFindSubstr1in2(*this,aString,aIgnoreCase,anOffset,aCount); return result; } @@ -1038,7 +1037,7 @@ PRInt32 nsString::RFind(const nsCString& aString,PRBool aIgnoreCase,PRInt32 anOf * @return offset in string, or -1 (kNotFound) */ PRInt32 nsString::RFind(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ - PRInt32 result=nsStrPrivate::RFindSubstr2in2(*this,aString,aIgnoreCase,anOffset,aCount); + PRInt32 result=nsStr::RFindSubstr2in2(*this,aString,aIgnoreCase,anOffset,aCount); return result; } @@ -1058,10 +1057,10 @@ PRInt32 nsString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset, PRInt32 result=kNotFound; if(aString) { nsStr temp; - nsStrPrivate::Initialize(temp,eOneByte); + nsStr::Initialize(temp,eOneByte); temp.mLength=nsCRT::strlen(aString); temp.mStr=(char*)aString; - result=nsStrPrivate::RFindSubstr1in2(*this,temp,aIgnoreCase,anOffset,aCount); + result=nsStr::RFindSubstr1in2(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } @@ -1076,7 +1075,7 @@ PRInt32 nsString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset, * @return offset of found char, or -1 (kNotFound) */ PRInt32 nsString::RFindChar(PRUnichar aChar,PRInt32 anOffset,PRInt32 aCount) const{ - PRInt32 result=nsStrPrivate::RFindChar2(*this,aChar,anOffset,aCount); + PRInt32 result=nsStr::RFindChar2(*this,aChar,anOffset,aCount); return result; } @@ -1094,10 +1093,10 @@ PRInt32 nsString::RFindCharInSet(const char* aCStringSet,PRInt32 anOffset) const PRInt32 result=kNotFound; if(aCStringSet) { nsStr temp; - nsStrPrivate::Initialize(temp,eOneByte); + nsStr::Initialize(temp,eOneByte); temp.mLength=nsCRT::strlen(aCStringSet); temp.mStr=(char*)aCStringSet; - result=nsStrPrivate::RFindCharInSet1(*this,temp,PR_FALSE,anOffset); + result=nsStr::RFindCharInSet1(*this,temp,PR_FALSE,anOffset); } return result; } @@ -1113,12 +1112,12 @@ PRInt32 nsString::RFindCharInSet(const char* aCStringSet,PRInt32 anOffset) const * @return offset of found char, or -1 (kNotFound) */ PRInt32 nsString::RFindCharInSet(const nsString& aSet,PRInt32 anOffset) const{ - PRInt32 result=nsStrPrivate::RFindCharInSet2(*this,aSet,anOffset); + PRInt32 result=nsStr::RFindCharInSet2(*this,aSet,anOffset); return result; } PRInt32 nsString::RFindCharInSet(const nsCString& aSet,PRInt32 anOffset) const{ - PRInt32 result=nsStrPrivate::RFindCharInSet1(*this,aSet,PR_FALSE,anOffset); + PRInt32 result=nsStr::RFindCharInSet1(*this,aSet,PR_FALSE,anOffset); return result; } @@ -1138,10 +1137,10 @@ PRInt32 nsString::RFindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) c PRInt32 result=kNotFound; if(aStringSet) { nsStr temp; - nsStrPrivate::Initialize(temp,eTwoByte); + nsStr::Initialize(temp,eTwoByte); temp.mLength=nsCRT::strlen(aStringSet); temp.mUStr=(PRUnichar*)aStringSet; - result=nsStrPrivate::RFindCharInSet2(*this,temp,anOffset); + result=nsStr::RFindCharInSet2(*this,temp,anOffset); } return result; } @@ -1164,12 +1163,12 @@ PRInt32 nsString::CompareWithConversion(const char *aCString,PRBool aIgnoreCase, if(aCString) { nsStr temp; - nsStrPrivate::Initialize(temp,eOneByte); + nsStr::Initialize(temp,eOneByte); temp.mLength= (0>eTwoByte)-1,0,eTwoByte,PR_FALSE); + Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); AddNullTerminator(*this); } nsAutoString::nsAutoString(const PRUnichar* aString) : nsString() { - nsStrPrivate::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); + Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); AddNullTerminator(*this); Append(aString); } @@ -1398,7 +1397,7 @@ nsAutoString::nsAutoString(const PRUnichar* aString) : nsString() { * @param aLength tells us how many chars to copy from aString */ nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString() { - nsStrPrivate::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); + Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); AddNullTerminator(*this); Append(aString,aLength); } @@ -1406,7 +1405,7 @@ nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString( nsAutoString::nsAutoString( const nsString& aString ) : nsString() { - nsStrPrivate::Initialize(*this, mBuffer, (sizeof(mBuffer)>>eTwoByte)-1, 0, eTwoByte, PR_FALSE); + Initialize(*this, mBuffer, (sizeof(mBuffer)>>eTwoByte)-1, 0, eTwoByte, PR_FALSE); AddNullTerminator(*this); Append(aString); } @@ -1414,7 +1413,7 @@ nsAutoString::nsAutoString( const nsString& aString ) nsAutoString::nsAutoString( const nsAString& aString ) : nsString() { - nsStrPrivate::Initialize(*this, mBuffer, (sizeof(mBuffer)>>eTwoByte)-1, 0, eTwoByte, PR_FALSE); + Initialize(*this, mBuffer, (sizeof(mBuffer)>>eTwoByte)-1, 0, eTwoByte, PR_FALSE); AddNullTerminator(*this); Append(aString); } @@ -1427,10 +1426,10 @@ nsAutoString::nsAutoString( const nsAString& aString ) */ nsAutoString::nsAutoString(const CBufDescriptor& aBuffer) : nsString() { if(!aBuffer.mBuffer) { - nsStrPrivate::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); + Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); } else { - nsStrPrivate::Initialize(*this,aBuffer.mBuffer,aBuffer.mCapacity,aBuffer.mLength,aBuffer.mCharSize,!aBuffer.mStackBased); + Initialize(*this,aBuffer.mBuffer,aBuffer.mCapacity,aBuffer.mLength,aBuffer.mCharSize,!aBuffer.mStackBased); } if(!aBuffer.mIsConst) AddNullTerminator(*this); @@ -1545,7 +1544,7 @@ NS_ConvertUTF8toUCS2::Init( const nsACString& aCString ) * Default copy constructor */ nsAutoString::nsAutoString(const nsAutoString& aString) : nsString() { - nsStrPrivate::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); + Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); AddNullTerminator(*this); Append(aString); } @@ -1556,7 +1555,7 @@ nsAutoString::nsAutoString(const nsAutoString& aString) : nsString() { * @param */ nsAutoString::nsAutoString(PRUnichar aChar) : nsString(){ - nsStrPrivate::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); + Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE); AddNullTerminator(*this); Append(aChar); }