From 4209916b0d23fad5aa6b4307dc015fafb3f6f982 Mon Sep 17 00:00:00 2001 From: "rickg%netscape.com" Date: Fri, 11 Feb 2000 12:11:03 +0000 Subject: [PATCH] fixed25049; r=harishd git-svn-id: svn://10.0.0.236/trunk@60477 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/string/obsolete/nsStr.cpp | 163 +++++------ mozilla/string/obsolete/nsStr.h | 14 +- mozilla/string/obsolete/nsString.cpp | 277 +++++++++++++----- mozilla/string/obsolete/nsString.h | 24 +- mozilla/string/obsolete/nsString2.cpp | 309 +++++++++++++++----- mozilla/string/obsolete/nsString2.h | 34 ++- mozilla/xpcom/ds/bufferRoutines.h | 228 ++++++++++----- mozilla/xpcom/ds/nsStr.cpp | 163 +++++------ mozilla/xpcom/ds/nsStr.h | 14 +- mozilla/xpcom/ds/nsString.cpp | 277 +++++++++++++----- mozilla/xpcom/ds/nsString.h | 24 +- mozilla/xpcom/ds/nsString2.cpp | 309 +++++++++++++++----- mozilla/xpcom/ds/nsString2.h | 34 ++- mozilla/xpcom/string/obsolete/nsStr.cpp | 163 +++++------ mozilla/xpcom/string/obsolete/nsStr.h | 14 +- mozilla/xpcom/string/obsolete/nsString.cpp | 277 +++++++++++++----- mozilla/xpcom/string/obsolete/nsString.h | 24 +- mozilla/xpcom/string/obsolete/nsString2.cpp | 309 +++++++++++++++----- mozilla/xpcom/string/obsolete/nsString2.h | 34 ++- 19 files changed, 1856 insertions(+), 835 deletions(-) diff --git a/mozilla/string/obsolete/nsStr.cpp b/mozilla/string/obsolete/nsStr.cpp index e351f3c026b..bd40c1191c7 100644 --- a/mozilla/string/obsolete/nsStr.cpp +++ b/mozilla/string/obsolete/nsStr.cpp @@ -37,7 +37,6 @@ #include //only used for printf #include "nsCRT.h" #include "nsDeque.h" - //static const char* kCallFindChar = "For better performance, call FindChar() for targets whose length==1."; //static const char* kCallRFindChar = "For better performance, call RFindChar() for targets whose length==1."; @@ -327,7 +326,7 @@ void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool a if(aEliminateLeading) { while(++theIndex<=theMax) { PRUnichar theChar=GetCharAt(aDest,theIndex); - PRInt32 thePos=gFindChars[eOneByte](aSet,theSetLen,0,theChar,PR_FALSE); + PRInt32 thePos=gFindChars[eOneByte](aSet,theSetLen,0,theChar,PR_FALSE,theSetLen); if(kNotFound==thePos) break; } @@ -344,7 +343,7 @@ void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool a PRInt32 theNewLen=theIndex; while(--theIndex>0) { PRUnichar theChar=GetCharAt(aDest,theIndex); //read at end now... - PRInt32 thePos=gFindChars[eOneByte](aSet,theSetLen,0,theChar,PR_FALSE); + PRInt32 thePos=gFindChars[eOneByte](aSet,theSetLen,0,theChar,PR_FALSE,theSetLen); if(kNotFound=aTarget.mLength) && (aTarget.mLength>0) && (index>=0)){ - PRInt32 theTargetMax=aTarget.mLength; - while(index<=theMax) { - PRInt32 theSubIndex=-1; - PRBool matches=PR_TRUE; - while((++theSubIndex=aTarget.mLength) && (aTarget.mLength>0) && (index>=0)){ + const char* rightmost = root+(anOffset*aDelta); + const char* min = rightmost-((aCount-1)*aDelta); - nsStr theCopy; - nsStr::Initialize(theCopy,eOneByte); - nsStr::Assign(theCopy,aTarget,0,aTarget.mLength); - if(aIgnoreCase){ - nsStr::ChangeCase(theCopy,PR_FALSE); //force to lowercase - } - - PRInt32 theTargetMax=theCopy.mLength; - while(index>=0) { - PRInt32 theSubIndex=-1; - PRBool matches=PR_FALSE; - if(index+theCopy.mLength<=aDest.mLength) { - matches=PR_TRUE; - while((++theSubIndex=0) { PRUnichar theChar=GetCharAt(aDest,index); - thePos=gFindChars[aSet.mCharSize](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase); + thePos=gFindChars[aSet.mCharSize](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase,aSet.mLength); if(kNotFound!=thePos) return index; } //while diff --git a/mozilla/string/obsolete/nsStr.h b/mozilla/string/obsolete/nsStr.h index c6c7fdf11ad..7bcdd560338 100644 --- a/mozilla/string/obsolete/nsStr.h +++ b/mozilla/string/obsolete/nsStr.h @@ -223,8 +223,6 @@ public: struct NS_COM nsStr { -//---------------------------------------------------------------------------------------- - nsStr() { MOZ_COUNT_CTOR(nsStr); } @@ -402,12 +400,12 @@ struct NS_COM nsStr { * @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 FindSubstr(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset); - static PRInt32 FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset); + static PRInt32 FindSubstr(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount); + static PRInt32 FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount); static PRInt32 FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset); - static PRInt32 RFindSubstr(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset); - static PRInt32 RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset); + static PRInt32 RFindSubstr(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount); + static PRInt32 RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount); static PRInt32 RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset); static void Overwrite(nsStr& aDest,const nsStr& aSource,PRInt32 anOffset); @@ -445,6 +443,9 @@ private: }; + + + /************************************************************** A couple of tiny helper methods used in the string classes. **************************************************************/ @@ -485,6 +486,7 @@ inline PRUnichar GetCharAt(const nsStr& aDest,PRUint32 anIndex){ return 0; } + #ifdef NS_STR_STATS class nsStringInfo { diff --git a/mozilla/string/obsolete/nsString.cpp b/mozilla/string/obsolete/nsString.cpp index 80fc1b9dada..a32efac8f70 100644 --- a/mozilla/string/obsolete/nsString.cpp +++ b/mozilla/string/obsolete/nsString.cpp @@ -342,10 +342,10 @@ void nsCString::ToUpperCase(nsCString& aString) const { */ nsCString& nsCString::StripChar(PRUnichar aChar,PRInt32 anOffset){ - anOffset=nsStr::FindChar(*this,aChar,PR_FALSE,anOffset); + anOffset=nsStr::FindChar(*this,aChar,PR_FALSE,anOffset,mLength); while(kNotFound2)) { + theFirstChar=First(); + theLastChar=Last(); + if(theFirstChar==theLastChar) { + if(('\''==theFirstChar) || ('"'==theFirstChar)) { + Cut(0,1); + Truncate(mLength-1); + theQuotesAreNeeded=PR_TRUE; + } + else theFirstChar=0; + } + } + nsStr::Trim(*this,aTrimSet,aEliminateLeading,aEliminateTrailing); + + if(aIgnoreQuotes && theQuotesAreNeeded) { + Insert(theFirstChar,0); + Append(theLastChar); + } + } return *this; } @@ -644,7 +669,7 @@ float nsCString::ToFloat(PRInt32* aErrorCode) const { * @return int rep of string value */ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) { - + //copy chars to local buffer -- step down from 2 bytes to 1 if necessary... PRInt32 result=0; @@ -712,10 +737,11 @@ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) { */ static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) { - const char* cp=aString.GetBuffer(); + const char* cp=aString.mStr; PRInt32 result=NS_ERROR_ILLEGAL_VALUE; if(cp) { + aRadix = (kAutoDetect==aRadix) ? 10 : aRadix; //begin by skipping over leading chars that shouldn't be part of the number... @@ -725,16 +751,19 @@ static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) { while(!done){ switch(*cp) { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + aRadix=16; + done=PR_TRUE; + break; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': case '-': case '+': case '#': done=PR_TRUE; break; default: cp++; - done=cp='A') && (theChar<='F')) { + if(10==theRadix) { + if(kAutoDetect==aRadix){ + theRadix=16; + cp=first; //backup + result=0; + } + else { + *anErrorCode=NS_ERROR_ILLEGAL_VALUE; + result=0; + break; + } + } + else { + result = (theRadix * result) + ((theChar-'A')+10); + } + } + else if((theChar>='a') && (theChar<='f')) { + if(10==theRadix) { + if(kAutoDetect==aRadix){ + theRadix=16; + cp=first; //backup + result=0; + } + else { + *anErrorCode=NS_ERROR_ILLEGAL_VALUE; + result=0; + break; + } + } + else { + result = (theRadix * result) + ((theChar-'a')+10); + } + } + else if(('X'==theChar) || ('x'==theChar) || ('#'==theChar) || ('+'==theChar)) { + continue; + } + else { + //we've encountered a char that's not a legal number or sign + break; + } + } //while + if(negate) + result=-result; + } //if + } + return result; +#endif } /********************************************************************** @@ -894,7 +1028,7 @@ nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) { // If this assertion fires, the caller is probably lying about the length of // the passed-in string. File a bug on the caller. #ifdef NS_DEBUG - PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0); + PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength); NS_WARN_IF_FALSE(kNotFound==len,"possible embedded null in Assign(PRUnichar*)"); #endif @@ -1183,7 +1317,7 @@ nsCString& nsCString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCou // If this assertion fires, the caller is probably lying about the length of // the passed-in string. File a bug on the caller. #ifdef NS_DEBUG - PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0); + PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength); NS_WARN_IF_FALSE(kNotFound==len,"possible embedded null in Insert(char*)"); #endif @@ -1287,18 +1421,19 @@ PRInt32 nsCString::BinarySearch(PRUnichar aChar) const{ * * @update gess 3/25/98 * @param aCString - substr to be found - * @param aIgnoreCase - * @param anOffset + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsCString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset) const{ +PRInt32 nsCString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ PRInt32 result=kNotFound; if(aCString) { nsStr temp; nsStr::Initialize(temp,eOneByte); - temp.mLength=nsCRT::strlen(aCString); + temp.mLength = nsCRT::strlen(aCString); temp.mStr=(char*)aCString; - result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset); + result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } @@ -1307,21 +1442,22 @@ PRInt32 nsCString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset * Search for given buffer within this string * * @update gess 3/25/98 - * @param aString unichar* to be found - * @param aIgnoreCase - * @param anOffset + * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsCString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ +PRInt32 nsCString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ NS_ASSERTION(0!=aString,kNullPointerError); PRInt32 result=kNotFound; if(aString) { nsStr temp; nsStr::Initialize(temp,eTwoByte); - temp.mLength=nsCRT::strlen(aString); + temp.mLength = nsCRT::strlen(aString); temp.mUStr=(PRUnichar*)aString; - result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset); + result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } @@ -1330,28 +1466,30 @@ PRInt32 nsCString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOf * Search for given string within this string * * @update gess 3/25/98 - * @param aSTring -- buffer to be found - * @param aIgnoreCase - * @param anOffset + * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsCString::Find(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,anOffset); +PRInt32 nsCString::Find(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,anOffset,aCount); return result; } /** - * Search for a given char, starting at given offset + * This searches this string for a given character * - * @update gess 3/25/98 - * @param aChar the unichar to be sought - * @param aIgnoreCase - * @param anOffset - * @return offset of found char, or -1 (kNotFound) + * @update gess 2/04/00 + * @param char is the character you're trying to find. + * @param aIgnorecase indicates case sensitivity of search + * @param anOffset tells us where to start the search; -1 means start at 0. + * @param aCount tell us how many chars to search from offset; -1 means use full length. + * @return index in aDest where member of aSet occurs, or -1 if not found */ -PRInt32 nsCString::FindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::FindChar(*this,aChar,aIgnoreCase,anOffset); +PRInt32 nsCString::FindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::FindChar(*this,aChar,aIgnoreCase,anOffset,aCount); return result; } @@ -1416,30 +1554,32 @@ PRInt32 nsCString::FindCharInSet(const nsStr& aSet,PRInt32 anOffset) const{ } /** - * Reverse search for substring + * Reverse search for given string within this string * * @update gess 3/25/98 - * @param aString - * @param aIgnoreCase - * @param anOffset - tells us where to begin the search - * @return offset of substring or -1 + * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset + * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsCString::RFind(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,anOffset); +PRInt32 nsCString::RFind(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,anOffset,aCount); return result; } /** - * Reverse search for substring + * Reverse search for given string within this string * * @update gess 3/25/98 - * @param aString - * @param aIgnoreCase - * @param anOffset - tells us where to begin the search - * @return offset of substring or -1 + * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset + * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsCString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ +PRInt32 nsCString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ NS_ASSERTION(0!=aString,kNullPointerError); PRInt32 result=kNotFound; @@ -1448,22 +1588,23 @@ PRInt32 nsCString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset nsStr::Initialize(temp,eOneByte); temp.mLength=nsCRT::strlen(aString); temp.mStr=(char*)aString; - result=nsStr::RFindSubstr(*this,temp,aIgnoreCase,anOffset); + result=nsStr::RFindSubstr(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } /** - * Reverse search for char + * This reverse searches this string for a given character * - * @update gess 3/25/98 - * @param aChar - * @param aIgnoreCase - * @param anOffset - tells us where to begin the search - * @return offset of substring or -1 + * @update gess 2/04/00 + * @param char is the character you're trying to find. + * @param aIgnorecase indicates case sensitivity of search + * @param anOffset tells us where to start the search; -1 means start at 0. + * @param aCount tell us how many chars to search from offset; -1 means use full length. + * @return index in aDest where member of aSet occurs, or -1 if not found */ -PRInt32 nsCString::RFindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::RFindChar(*this,aChar,aIgnoreCase,anOffset); +PRInt32 nsCString::RFindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::RFindChar(*this,aChar,aIgnoreCase,anOffset,aCount); return result; } diff --git a/mozilla/string/obsolete/nsString.h b/mozilla/string/obsolete/nsString.h index 5edd943f280..6f1a91eb932 100644 --- a/mozilla/string/obsolete/nsString.h +++ b/mozilla/string/obsolete/nsString.h @@ -270,9 +270,12 @@ public: * * @param aTrimSet -- contains chars to be trimmed from * both ends + * @param aEliminateLeading + * @param aEliminateTrailing + * @param aIgnoreQuotes * @return this */ - nsCString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + nsCString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE,PRBool aIgnoreQuotes=PR_FALSE); /** * This method strips whitespace from string. @@ -533,11 +536,12 @@ public: * @param aString is substring to be sought in this * @param aIgnoreCase selects case sensitivity * @param anOffset tells us where in this strig to start searching + * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ - PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; /** * Search for given char within this string @@ -545,9 +549,10 @@ public: * @param aString is substring to be sought in this * @param anOffset tells us where in this strig to start searching * @param aIgnoreCase selects case sensitivity + * @param aCount tells us how many iterations to make starting at the given offset * @return find pos in string, or -1 (kNotFound) */ - PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; /** * This method searches this string for the first character @@ -565,11 +570,12 @@ public: * This methods scans the string backwards, looking for the given string * @param aString is substring to be sought in this * @param aIgnoreCase tells us whether or not to do caseless compare + * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ - PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; /** @@ -580,7 +586,7 @@ public: * @param aIgnoreCase selects case sensitivity * @return find pos in string, or -1 (kNotFound) */ - PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; /** * This method searches this string for the last character diff --git a/mozilla/string/obsolete/nsString2.cpp b/mozilla/string/obsolete/nsString2.cpp index 9afcd9bb706..257325996a9 100644 --- a/mozilla/string/obsolete/nsString2.cpp +++ b/mozilla/string/obsolete/nsString2.cpp @@ -403,10 +403,10 @@ void nsString::ToUpperCase(nsString& aString) const { */ nsString& nsString::StripChar(PRUnichar aChar,PRInt32 anOffset){ - anOffset=nsStr::FindChar(*this,aChar,PR_FALSE,anOffset); + anOffset=nsStr::FindChar(*this,aChar,PR_FALSE,anOffset,mLength); while(kNotFound2)) { + theFirstChar=First(); + theLastChar=Last(); + if(theFirstChar==theLastChar) { + if(('\''==theFirstChar) || ('"'==theFirstChar)) { + Cut(0,1); + Truncate(mLength-1); + theQuotesAreNeeded=PR_TRUE; + } + else theFirstChar=0; + } + } + + nsStr::Trim(*this,aTrimSet,aEliminateLeading,aEliminateTrailing); + + if(aIgnoreQuotes && theQuotesAreNeeded) { + Insert(theFirstChar,0); + Append(theLastChar); + } + + } return *this; } @@ -872,10 +896,11 @@ static PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadi */ static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) { - const char* cp=aString.GetBuffer(); + const char* cp=aString.mStr; PRInt32 result=NS_ERROR_ILLEGAL_VALUE; if(cp) { + aRadix = (kAutoDetect==aRadix) ? 10 : aRadix; //begin by skipping over leading chars that shouldn't be part of the number... @@ -885,16 +910,19 @@ static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) { while(!done){ switch(*cp) { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + aRadix=16; + done=PR_TRUE; + break; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': case '-': case '+': case '#': done=PR_TRUE; break; default: cp++; - done=cp='A') && (theChar<='F')) { + if(10==theRadix) { + if(kAutoDetect==aRadix){ + theRadix=16; + cp=first; //backup + result=0; + } + else { + *anErrorCode=NS_ERROR_ILLEGAL_VALUE; + result=0; + break; + } + } + else { + result = (theRadix * result) + ((theChar-'A')+10); + } + } + else if((theChar>='a') && (theChar<='f')) { + if(10==theRadix) { + if(kAutoDetect==aRadix){ + theRadix=16; + cp=first; //backup + result=0; + } + else { + *anErrorCode=NS_ERROR_ILLEGAL_VALUE; + result=0; + break; + } + } + else { + result = (theRadix * result) + ((theChar-'a')+10); + } + } + else if(('X'==theChar) || ('x'==theChar) || ('#'==theChar) || ('+'==theChar)) { + continue; + } + else { + //we've encountered a char that's not a legal number or sign + break; + } + } //while + if(negate) + result=-result; + } //if } return result; +#endif } /********************************************************************** @@ -1146,7 +1279,7 @@ nsString& nsString::Append(const char* aCString,PRInt32 aCount) { // the passed-in string. File a bug on the caller. #ifdef NS_DEBUG - PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0); + PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength); NS_WARN_IF_FALSE(kNotFound==len,"possible embedded null in append(char*)"); #endif @@ -1180,7 +1313,7 @@ nsString& nsString::Append(const PRUnichar* aString,PRInt32 aCount) { // If this assertion fires, the caller is probably lying about the length of // the passed-in string. File a bug on the caller. #ifdef NS_DEBUG - PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0); + PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength); NS_WARN_IF_FALSE(kNotFound==len,"possible embedded null in append(PRUnichar*)"); #endif @@ -1372,7 +1505,7 @@ nsString& nsString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCount // If this assertion fires, the caller is probably lying about the length of // the passed-in string. File a bug on the caller. #ifdef NS_DEBUG - PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0); + PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength); NS_WARN_IF_FALSE(kNotFound==len,"possible embedded null in Insert(char*)"); #endif @@ -1410,7 +1543,7 @@ nsString& nsString::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32 aC // If this assertion fires, the caller is probably lying about the length of // the passed-in string. File a bug on the caller. #ifdef NS_DEBUG - PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0); + PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength); NS_WARN_IF_FALSE(kNotFound==len,"possible embedded null in Insert(PRUnichar*)"); #endif @@ -1491,13 +1624,16 @@ PRInt32 nsString::BinarySearch(PRUnichar aChar) const{ } /** - * Search for given cstr within this string + * search for given string within this string * * @update gess 3/25/98 - * @param aCString - substr to be found + * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset) const{ +PRInt32 nsString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ NS_ASSERTION(0!=aCString,kNullPointerError); PRInt32 result=kNotFound; @@ -1506,19 +1642,22 @@ PRInt32 nsString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset) nsStr::Initialize(temp,eOneByte); temp.mLength=nsCRT::strlen(aCString); temp.mStr=(char*)aCString; - result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset); + result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } /** - * Search for given unichar* within this string + * search for given string within this string * * @update gess 3/25/98 * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ +PRInt32 nsString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ NS_ASSERTION(0!=aString,kNullPointerError); PRInt32 result=kNotFound; @@ -1527,32 +1666,38 @@ PRInt32 nsString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOff nsStr::Initialize(temp,eTwoByte); temp.mLength=nsCRT::strlen(aString); temp.mUStr=(PRUnichar*)aString; - result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset); + result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } -/** - * Search for given nsSTr within this string - * - * @update gess 3/25/98 - * @param aString - substr to be found - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 nsString::Find(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,anOffset); - return result; -} - /** * Search for given string within this string * * @update gess 3/25/98 * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsString::Find(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,anOffset); +PRInt32 nsString::Find(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,anOffset,aCount); + return result; +} + +/** + * search for given string within this string + * + * @update gess 3/25/98 + * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset + * @return offset in string, or -1 (kNotFound) + */ +PRInt32 nsString::Find(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,anOffset,aCount); return result; } @@ -1575,12 +1720,13 @@ PRInt32 nsString::Find(PRUnichar aChar,PRInt32 anOffset,PRBool aIgnoreCase) cons * * @update gess 3/25/98 * @param aChar is the unichar to be sought - * @param anOffset - * @param aIgnoreCase - * @return offset of found char, or -1 (kNotFound) + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset + * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsString::FindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::FindChar(*this,aChar,aIgnoreCase,anOffset); +PRInt32 nsString::FindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::FindChar(*this,aChar,aIgnoreCase,anOffset,aCount); return result; } @@ -1646,50 +1792,55 @@ PRInt32 nsString::FindCharInSet(const nsStr& aSet,PRInt32 anOffset) const{ /** - * + * Reverse search for given string within this string * * @update gess 3/25/98 - * @param - * @return + * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset + * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsString::RFind(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,anOffset); +PRInt32 nsString::RFind(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,anOffset,aCount); return result; } /** - * Reverse search for substring + * Reverse search for given string within this string * * @update gess 3/25/98 - * @param aString - * @param aIgnoreCase - * @param anOffset - tells us where to begin the search - * @return offset of substring or -1 + * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset + * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsString::RFind(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,anOffset); +PRInt32 nsString::RFind(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,anOffset,aCount); return result; } /** - * Reverse search for substring + * Reverse search for given string within this string * * @update gess 3/25/98 - * @param aString - * @param aIgnoreCase - * @param anOffset - tells us where to begin the search - * @return offset of substring or -1 + * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset + * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ +PRInt32 nsString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ NS_ASSERTION(0!=aString,kNullPointerError); - + PRInt32 result=kNotFound; if(aString) { nsStr temp; nsStr::Initialize(temp,eOneByte); temp.mLength=nsCRT::strlen(aString); temp.mStr=(char*)aString; - result=nsStr::RFindSubstr(*this,temp,aIgnoreCase,anOffset); + result=nsStr::RFindSubstr(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } @@ -1720,8 +1871,8 @@ PRInt32 nsString::RFind(PRUnichar aChar,PRInt32 anOffset,PRBool aIgnoreCase) con * @param anOffset * @return offset of found char, or -1 (kNotFound) */ -PRInt32 nsString::RFindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::RFindChar(*this,aChar,aIgnoreCase,anOffset); +PRInt32 nsString::RFindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::RFindChar(*this,aChar,aIgnoreCase,anOffset,aCount); return result; } @@ -2358,12 +2509,16 @@ void nsAutoString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const { } } +nsSubsumeStr::nsSubsumeStr() : nsString() { +} + nsSubsumeStr::nsSubsumeStr(nsStr& aString) : nsString() { - Subsume(*this,aString); + ::Subsume(*this,aString); } nsSubsumeStr::nsSubsumeStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength) : nsString() { mUStr=aString; + mCharSize=eTwoByte; mCapacity=mLength=(-1==aLength) ? nsCRT::strlen(aString) : aLength; mOwnsBuffer=assumeOwnership; } @@ -2375,3 +2530,9 @@ nsSubsumeStr::nsSubsumeStr(char* aString,PRBool assumeOwnership,PRInt32 aLength) mOwnsBuffer=assumeOwnership; } +nsSubsumeStr::Subsume(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength) { + mUStr=aString; + mCharSize=eTwoByte; + mCapacity=mLength=(-1==aLength) ? nsCRT::strlen(aString) : aLength; + mOwnsBuffer=assumeOwnership; +} diff --git a/mozilla/string/obsolete/nsString2.h b/mozilla/string/obsolete/nsString2.h index 90e48945009..04f25024050 100644 --- a/mozilla/string/obsolete/nsString2.h +++ b/mozilla/string/obsolete/nsString2.h @@ -310,9 +310,12 @@ public: * * @param aTrimSet -- contains chars to be trimmed from * both ends + * @param aEliminateLeading + * @param aEliminateTrailing + * @param aIgnoreQuotes * @return this */ - nsString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + nsString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE,PRBool aIgnoreQuotes=PR_FALSE); /** * This method strips whitespace from string. @@ -584,12 +587,13 @@ public: * @param aString is substring to be sought in this * @param aIgnoreCase selects case sensitivity * @param anOffset tells us where in this strig to start searching + * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ - PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; /** @@ -598,10 +602,11 @@ public: * @param aString is substring to be sought in this * @param anOffset tells us where in this strig to start searching * @param aIgnoreCase selects case sensitivity + * @param aCount tells us how many iterations to make starting at the given offset * @return find pos in string, or -1 (kNotFound) */ //PRInt32 Find(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const; - PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; /** * This method searches this string for the first character @@ -619,12 +624,14 @@ public: * This methods scans the string backwards, looking for the given string * @param aString is substring to be sought in this * @param aIgnoreCase tells us whether or not to do caseless compare - * @param anOffset tells us where in this strig to start searching (counting from left) + * @param anOffset tells us where in this strig to start searching (counting from left) + * @param aCount tells us how many iterations to make starting at the given offset + * @return offset in string, or -1 (kNotFound) */ - PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; /** @@ -633,10 +640,11 @@ public: * @param aString is substring to be sought in this * @param anOffset tells us where in this strig to start searching (counting from left) * @param aIgnoreCase selects case sensitivity + * @param aCount tells us how many iterations to make starting at the given offset * @return find pos in string, or -1 (kNotFound) */ //PRInt32 RFind(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const; - PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; /** * This method searches this string for the last character @@ -849,9 +857,11 @@ public: ***************************************************************/ class NS_COM nsSubsumeStr : public nsString { public: + nsSubsumeStr(); nsSubsumeStr(nsStr& aString); nsSubsumeStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1); nsSubsumeStr(char* aString,PRBool assumeOwnership,PRInt32 aLength=-1); + Subsume(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1); }; diff --git a/mozilla/xpcom/ds/bufferRoutines.h b/mozilla/xpcom/ds/bufferRoutines.h index 6dbd4dad7b8..6deb374e16c 100644 --- a/mozilla/xpcom/ds/bufferRoutines.h +++ b/mozilla/xpcom/ds/bufferRoutines.h @@ -247,64 +247,100 @@ CopyChars gCopyChars[2][2]={ * * @update gess 3/25/98 * @param aDest is the buffer to be searched - * @param aLength is the size (in char-units, not bytes) of the buffer + * @param aDestLength is the size (in char-units, not bytes) of the buffer * @param anOffset is the start pos to begin searching * @param aChar is the target character we're looking for * @param aIgnorecase tells us whether to use a case sensitive search + * @param aCount tells us how many characters to iterate through (which may be different than aLength); -1 means use full length. * @return index of pos if found, else -1 (kNotFound) */ -inline PRInt32 FindChar1(const char* aDest,PRUint32 aLength,PRUint32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase) { +inline PRInt32 FindChar1(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase,PRInt32 aCount) { - if(aChar<256) { - if(aIgnoreCase) { - char theChar=(char)nsCRT::ToUpper(aChar); - const char* ptr=aDest+(anOffset-1); - const char* last=aDest+aLength; - while(++ptr=0;theIndex--){ - if(nsCRT::ToUpper(aDest[theIndex])==theChar) - return theIndex; - } - } - else { - for(theIndex=(PRInt32)anOffset;theIndex>=0;theIndex--){ - if(aDest[theIndex]==aChar) - return theIndex; +inline PRInt32 RFindChar1(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase,PRInt32 aCount) { + + if(anOffset<0) + anOffset=(PRInt32)aDestLength-1; + + if(aCount<0) + aCount = aDestLength; + + if((0=0;theIndex--){ - if(nsCRT::ToUpper(theBuf[theIndex])==theChar) - return theIndex; - } - } - else { - for(theIndex=(PRInt32)anOffset;theIndex>=0;theIndex--){ - if(theBuf[theIndex]==aChar) - return theIndex; + if(aCount<0) + aCount = aDestLength; + + if((0 //only used for printf #include "nsCRT.h" #include "nsDeque.h" - //static const char* kCallFindChar = "For better performance, call FindChar() for targets whose length==1."; //static const char* kCallRFindChar = "For better performance, call RFindChar() for targets whose length==1."; @@ -327,7 +326,7 @@ void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool a if(aEliminateLeading) { while(++theIndex<=theMax) { PRUnichar theChar=GetCharAt(aDest,theIndex); - PRInt32 thePos=gFindChars[eOneByte](aSet,theSetLen,0,theChar,PR_FALSE); + PRInt32 thePos=gFindChars[eOneByte](aSet,theSetLen,0,theChar,PR_FALSE,theSetLen); if(kNotFound==thePos) break; } @@ -344,7 +343,7 @@ void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool a PRInt32 theNewLen=theIndex; while(--theIndex>0) { PRUnichar theChar=GetCharAt(aDest,theIndex); //read at end now... - PRInt32 thePos=gFindChars[eOneByte](aSet,theSetLen,0,theChar,PR_FALSE); + PRInt32 thePos=gFindChars[eOneByte](aSet,theSetLen,0,theChar,PR_FALSE,theSetLen); if(kNotFound=aTarget.mLength) && (aTarget.mLength>0) && (index>=0)){ - PRInt32 theTargetMax=aTarget.mLength; - while(index<=theMax) { - PRInt32 theSubIndex=-1; - PRBool matches=PR_TRUE; - while((++theSubIndex=aTarget.mLength) && (aTarget.mLength>0) && (index>=0)){ + const char* rightmost = root+(anOffset*aDelta); + const char* min = rightmost-((aCount-1)*aDelta); - nsStr theCopy; - nsStr::Initialize(theCopy,eOneByte); - nsStr::Assign(theCopy,aTarget,0,aTarget.mLength); - if(aIgnoreCase){ - nsStr::ChangeCase(theCopy,PR_FALSE); //force to lowercase - } - - PRInt32 theTargetMax=theCopy.mLength; - while(index>=0) { - PRInt32 theSubIndex=-1; - PRBool matches=PR_FALSE; - if(index+theCopy.mLength<=aDest.mLength) { - matches=PR_TRUE; - while((++theSubIndex=0) { PRUnichar theChar=GetCharAt(aDest,index); - thePos=gFindChars[aSet.mCharSize](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase); + thePos=gFindChars[aSet.mCharSize](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase,aSet.mLength); if(kNotFound!=thePos) return index; } //while diff --git a/mozilla/xpcom/ds/nsStr.h b/mozilla/xpcom/ds/nsStr.h index c6c7fdf11ad..7bcdd560338 100644 --- a/mozilla/xpcom/ds/nsStr.h +++ b/mozilla/xpcom/ds/nsStr.h @@ -223,8 +223,6 @@ public: struct NS_COM nsStr { -//---------------------------------------------------------------------------------------- - nsStr() { MOZ_COUNT_CTOR(nsStr); } @@ -402,12 +400,12 @@ struct NS_COM nsStr { * @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 FindSubstr(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset); - static PRInt32 FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset); + static PRInt32 FindSubstr(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount); + static PRInt32 FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount); static PRInt32 FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset); - static PRInt32 RFindSubstr(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset); - static PRInt32 RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset); + static PRInt32 RFindSubstr(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount); + static PRInt32 RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount); static PRInt32 RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset); static void Overwrite(nsStr& aDest,const nsStr& aSource,PRInt32 anOffset); @@ -445,6 +443,9 @@ private: }; + + + /************************************************************** A couple of tiny helper methods used in the string classes. **************************************************************/ @@ -485,6 +486,7 @@ inline PRUnichar GetCharAt(const nsStr& aDest,PRUint32 anIndex){ return 0; } + #ifdef NS_STR_STATS class nsStringInfo { diff --git a/mozilla/xpcom/ds/nsString.cpp b/mozilla/xpcom/ds/nsString.cpp index 80fc1b9dada..a32efac8f70 100644 --- a/mozilla/xpcom/ds/nsString.cpp +++ b/mozilla/xpcom/ds/nsString.cpp @@ -342,10 +342,10 @@ void nsCString::ToUpperCase(nsCString& aString) const { */ nsCString& nsCString::StripChar(PRUnichar aChar,PRInt32 anOffset){ - anOffset=nsStr::FindChar(*this,aChar,PR_FALSE,anOffset); + anOffset=nsStr::FindChar(*this,aChar,PR_FALSE,anOffset,mLength); while(kNotFound2)) { + theFirstChar=First(); + theLastChar=Last(); + if(theFirstChar==theLastChar) { + if(('\''==theFirstChar) || ('"'==theFirstChar)) { + Cut(0,1); + Truncate(mLength-1); + theQuotesAreNeeded=PR_TRUE; + } + else theFirstChar=0; + } + } + nsStr::Trim(*this,aTrimSet,aEliminateLeading,aEliminateTrailing); + + if(aIgnoreQuotes && theQuotesAreNeeded) { + Insert(theFirstChar,0); + Append(theLastChar); + } + } return *this; } @@ -644,7 +669,7 @@ float nsCString::ToFloat(PRInt32* aErrorCode) const { * @return int rep of string value */ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) { - + //copy chars to local buffer -- step down from 2 bytes to 1 if necessary... PRInt32 result=0; @@ -712,10 +737,11 @@ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) { */ static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) { - const char* cp=aString.GetBuffer(); + const char* cp=aString.mStr; PRInt32 result=NS_ERROR_ILLEGAL_VALUE; if(cp) { + aRadix = (kAutoDetect==aRadix) ? 10 : aRadix; //begin by skipping over leading chars that shouldn't be part of the number... @@ -725,16 +751,19 @@ static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) { while(!done){ switch(*cp) { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + aRadix=16; + done=PR_TRUE; + break; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': case '-': case '+': case '#': done=PR_TRUE; break; default: cp++; - done=cp='A') && (theChar<='F')) { + if(10==theRadix) { + if(kAutoDetect==aRadix){ + theRadix=16; + cp=first; //backup + result=0; + } + else { + *anErrorCode=NS_ERROR_ILLEGAL_VALUE; + result=0; + break; + } + } + else { + result = (theRadix * result) + ((theChar-'A')+10); + } + } + else if((theChar>='a') && (theChar<='f')) { + if(10==theRadix) { + if(kAutoDetect==aRadix){ + theRadix=16; + cp=first; //backup + result=0; + } + else { + *anErrorCode=NS_ERROR_ILLEGAL_VALUE; + result=0; + break; + } + } + else { + result = (theRadix * result) + ((theChar-'a')+10); + } + } + else if(('X'==theChar) || ('x'==theChar) || ('#'==theChar) || ('+'==theChar)) { + continue; + } + else { + //we've encountered a char that's not a legal number or sign + break; + } + } //while + if(negate) + result=-result; + } //if + } + return result; +#endif } /********************************************************************** @@ -894,7 +1028,7 @@ nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) { // If this assertion fires, the caller is probably lying about the length of // the passed-in string. File a bug on the caller. #ifdef NS_DEBUG - PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0); + PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength); NS_WARN_IF_FALSE(kNotFound==len,"possible embedded null in Assign(PRUnichar*)"); #endif @@ -1183,7 +1317,7 @@ nsCString& nsCString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCou // If this assertion fires, the caller is probably lying about the length of // the passed-in string. File a bug on the caller. #ifdef NS_DEBUG - PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0); + PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength); NS_WARN_IF_FALSE(kNotFound==len,"possible embedded null in Insert(char*)"); #endif @@ -1287,18 +1421,19 @@ PRInt32 nsCString::BinarySearch(PRUnichar aChar) const{ * * @update gess 3/25/98 * @param aCString - substr to be found - * @param aIgnoreCase - * @param anOffset + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsCString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset) const{ +PRInt32 nsCString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ PRInt32 result=kNotFound; if(aCString) { nsStr temp; nsStr::Initialize(temp,eOneByte); - temp.mLength=nsCRT::strlen(aCString); + temp.mLength = nsCRT::strlen(aCString); temp.mStr=(char*)aCString; - result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset); + result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } @@ -1307,21 +1442,22 @@ PRInt32 nsCString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset * Search for given buffer within this string * * @update gess 3/25/98 - * @param aString unichar* to be found - * @param aIgnoreCase - * @param anOffset + * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsCString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ +PRInt32 nsCString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ NS_ASSERTION(0!=aString,kNullPointerError); PRInt32 result=kNotFound; if(aString) { nsStr temp; nsStr::Initialize(temp,eTwoByte); - temp.mLength=nsCRT::strlen(aString); + temp.mLength = nsCRT::strlen(aString); temp.mUStr=(PRUnichar*)aString; - result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset); + result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } @@ -1330,28 +1466,30 @@ PRInt32 nsCString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOf * Search for given string within this string * * @update gess 3/25/98 - * @param aSTring -- buffer to be found - * @param aIgnoreCase - * @param anOffset + * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsCString::Find(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,anOffset); +PRInt32 nsCString::Find(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,anOffset,aCount); return result; } /** - * Search for a given char, starting at given offset + * This searches this string for a given character * - * @update gess 3/25/98 - * @param aChar the unichar to be sought - * @param aIgnoreCase - * @param anOffset - * @return offset of found char, or -1 (kNotFound) + * @update gess 2/04/00 + * @param char is the character you're trying to find. + * @param aIgnorecase indicates case sensitivity of search + * @param anOffset tells us where to start the search; -1 means start at 0. + * @param aCount tell us how many chars to search from offset; -1 means use full length. + * @return index in aDest where member of aSet occurs, or -1 if not found */ -PRInt32 nsCString::FindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::FindChar(*this,aChar,aIgnoreCase,anOffset); +PRInt32 nsCString::FindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::FindChar(*this,aChar,aIgnoreCase,anOffset,aCount); return result; } @@ -1416,30 +1554,32 @@ PRInt32 nsCString::FindCharInSet(const nsStr& aSet,PRInt32 anOffset) const{ } /** - * Reverse search for substring + * Reverse search for given string within this string * * @update gess 3/25/98 - * @param aString - * @param aIgnoreCase - * @param anOffset - tells us where to begin the search - * @return offset of substring or -1 + * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset + * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsCString::RFind(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,anOffset); +PRInt32 nsCString::RFind(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,anOffset,aCount); return result; } /** - * Reverse search for substring + * Reverse search for given string within this string * * @update gess 3/25/98 - * @param aString - * @param aIgnoreCase - * @param anOffset - tells us where to begin the search - * @return offset of substring or -1 + * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset + * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsCString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ +PRInt32 nsCString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ NS_ASSERTION(0!=aString,kNullPointerError); PRInt32 result=kNotFound; @@ -1448,22 +1588,23 @@ PRInt32 nsCString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset nsStr::Initialize(temp,eOneByte); temp.mLength=nsCRT::strlen(aString); temp.mStr=(char*)aString; - result=nsStr::RFindSubstr(*this,temp,aIgnoreCase,anOffset); + result=nsStr::RFindSubstr(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } /** - * Reverse search for char + * This reverse searches this string for a given character * - * @update gess 3/25/98 - * @param aChar - * @param aIgnoreCase - * @param anOffset - tells us where to begin the search - * @return offset of substring or -1 + * @update gess 2/04/00 + * @param char is the character you're trying to find. + * @param aIgnorecase indicates case sensitivity of search + * @param anOffset tells us where to start the search; -1 means start at 0. + * @param aCount tell us how many chars to search from offset; -1 means use full length. + * @return index in aDest where member of aSet occurs, or -1 if not found */ -PRInt32 nsCString::RFindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::RFindChar(*this,aChar,aIgnoreCase,anOffset); +PRInt32 nsCString::RFindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::RFindChar(*this,aChar,aIgnoreCase,anOffset,aCount); return result; } diff --git a/mozilla/xpcom/ds/nsString.h b/mozilla/xpcom/ds/nsString.h index 5edd943f280..6f1a91eb932 100644 --- a/mozilla/xpcom/ds/nsString.h +++ b/mozilla/xpcom/ds/nsString.h @@ -270,9 +270,12 @@ public: * * @param aTrimSet -- contains chars to be trimmed from * both ends + * @param aEliminateLeading + * @param aEliminateTrailing + * @param aIgnoreQuotes * @return this */ - nsCString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + nsCString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE,PRBool aIgnoreQuotes=PR_FALSE); /** * This method strips whitespace from string. @@ -533,11 +536,12 @@ public: * @param aString is substring to be sought in this * @param aIgnoreCase selects case sensitivity * @param anOffset tells us where in this strig to start searching + * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ - PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; /** * Search for given char within this string @@ -545,9 +549,10 @@ public: * @param aString is substring to be sought in this * @param anOffset tells us where in this strig to start searching * @param aIgnoreCase selects case sensitivity + * @param aCount tells us how many iterations to make starting at the given offset * @return find pos in string, or -1 (kNotFound) */ - PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; /** * This method searches this string for the first character @@ -565,11 +570,12 @@ public: * This methods scans the string backwards, looking for the given string * @param aString is substring to be sought in this * @param aIgnoreCase tells us whether or not to do caseless compare + * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ - PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; /** @@ -580,7 +586,7 @@ public: * @param aIgnoreCase selects case sensitivity * @return find pos in string, or -1 (kNotFound) */ - PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; /** * This method searches this string for the last character diff --git a/mozilla/xpcom/ds/nsString2.cpp b/mozilla/xpcom/ds/nsString2.cpp index 9afcd9bb706..257325996a9 100644 --- a/mozilla/xpcom/ds/nsString2.cpp +++ b/mozilla/xpcom/ds/nsString2.cpp @@ -403,10 +403,10 @@ void nsString::ToUpperCase(nsString& aString) const { */ nsString& nsString::StripChar(PRUnichar aChar,PRInt32 anOffset){ - anOffset=nsStr::FindChar(*this,aChar,PR_FALSE,anOffset); + anOffset=nsStr::FindChar(*this,aChar,PR_FALSE,anOffset,mLength); while(kNotFound2)) { + theFirstChar=First(); + theLastChar=Last(); + if(theFirstChar==theLastChar) { + if(('\''==theFirstChar) || ('"'==theFirstChar)) { + Cut(0,1); + Truncate(mLength-1); + theQuotesAreNeeded=PR_TRUE; + } + else theFirstChar=0; + } + } + + nsStr::Trim(*this,aTrimSet,aEliminateLeading,aEliminateTrailing); + + if(aIgnoreQuotes && theQuotesAreNeeded) { + Insert(theFirstChar,0); + Append(theLastChar); + } + + } return *this; } @@ -872,10 +896,11 @@ static PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadi */ static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) { - const char* cp=aString.GetBuffer(); + const char* cp=aString.mStr; PRInt32 result=NS_ERROR_ILLEGAL_VALUE; if(cp) { + aRadix = (kAutoDetect==aRadix) ? 10 : aRadix; //begin by skipping over leading chars that shouldn't be part of the number... @@ -885,16 +910,19 @@ static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) { while(!done){ switch(*cp) { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + aRadix=16; + done=PR_TRUE; + break; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': case '-': case '+': case '#': done=PR_TRUE; break; default: cp++; - done=cp='A') && (theChar<='F')) { + if(10==theRadix) { + if(kAutoDetect==aRadix){ + theRadix=16; + cp=first; //backup + result=0; + } + else { + *anErrorCode=NS_ERROR_ILLEGAL_VALUE; + result=0; + break; + } + } + else { + result = (theRadix * result) + ((theChar-'A')+10); + } + } + else if((theChar>='a') && (theChar<='f')) { + if(10==theRadix) { + if(kAutoDetect==aRadix){ + theRadix=16; + cp=first; //backup + result=0; + } + else { + *anErrorCode=NS_ERROR_ILLEGAL_VALUE; + result=0; + break; + } + } + else { + result = (theRadix * result) + ((theChar-'a')+10); + } + } + else if(('X'==theChar) || ('x'==theChar) || ('#'==theChar) || ('+'==theChar)) { + continue; + } + else { + //we've encountered a char that's not a legal number or sign + break; + } + } //while + if(negate) + result=-result; + } //if } return result; +#endif } /********************************************************************** @@ -1146,7 +1279,7 @@ nsString& nsString::Append(const char* aCString,PRInt32 aCount) { // the passed-in string. File a bug on the caller. #ifdef NS_DEBUG - PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0); + PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength); NS_WARN_IF_FALSE(kNotFound==len,"possible embedded null in append(char*)"); #endif @@ -1180,7 +1313,7 @@ nsString& nsString::Append(const PRUnichar* aString,PRInt32 aCount) { // If this assertion fires, the caller is probably lying about the length of // the passed-in string. File a bug on the caller. #ifdef NS_DEBUG - PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0); + PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength); NS_WARN_IF_FALSE(kNotFound==len,"possible embedded null in append(PRUnichar*)"); #endif @@ -1372,7 +1505,7 @@ nsString& nsString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCount // If this assertion fires, the caller is probably lying about the length of // the passed-in string. File a bug on the caller. #ifdef NS_DEBUG - PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0); + PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength); NS_WARN_IF_FALSE(kNotFound==len,"possible embedded null in Insert(char*)"); #endif @@ -1410,7 +1543,7 @@ nsString& nsString::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32 aC // If this assertion fires, the caller is probably lying about the length of // the passed-in string. File a bug on the caller. #ifdef NS_DEBUG - PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0); + PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength); NS_WARN_IF_FALSE(kNotFound==len,"possible embedded null in Insert(PRUnichar*)"); #endif @@ -1491,13 +1624,16 @@ PRInt32 nsString::BinarySearch(PRUnichar aChar) const{ } /** - * Search for given cstr within this string + * search for given string within this string * * @update gess 3/25/98 - * @param aCString - substr to be found + * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset) const{ +PRInt32 nsString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ NS_ASSERTION(0!=aCString,kNullPointerError); PRInt32 result=kNotFound; @@ -1506,19 +1642,22 @@ PRInt32 nsString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset) nsStr::Initialize(temp,eOneByte); temp.mLength=nsCRT::strlen(aCString); temp.mStr=(char*)aCString; - result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset); + result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } /** - * Search for given unichar* within this string + * search for given string within this string * * @update gess 3/25/98 * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ +PRInt32 nsString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ NS_ASSERTION(0!=aString,kNullPointerError); PRInt32 result=kNotFound; @@ -1527,32 +1666,38 @@ PRInt32 nsString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOff nsStr::Initialize(temp,eTwoByte); temp.mLength=nsCRT::strlen(aString); temp.mUStr=(PRUnichar*)aString; - result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset); + result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } -/** - * Search for given nsSTr within this string - * - * @update gess 3/25/98 - * @param aString - substr to be found - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 nsString::Find(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,anOffset); - return result; -} - /** * Search for given string within this string * * @update gess 3/25/98 * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsString::Find(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,anOffset); +PRInt32 nsString::Find(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,anOffset,aCount); + return result; +} + +/** + * search for given string within this string + * + * @update gess 3/25/98 + * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset + * @return offset in string, or -1 (kNotFound) + */ +PRInt32 nsString::Find(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,anOffset,aCount); return result; } @@ -1575,12 +1720,13 @@ PRInt32 nsString::Find(PRUnichar aChar,PRInt32 anOffset,PRBool aIgnoreCase) cons * * @update gess 3/25/98 * @param aChar is the unichar to be sought - * @param anOffset - * @param aIgnoreCase - * @return offset of found char, or -1 (kNotFound) + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset + * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsString::FindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::FindChar(*this,aChar,aIgnoreCase,anOffset); +PRInt32 nsString::FindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::FindChar(*this,aChar,aIgnoreCase,anOffset,aCount); return result; } @@ -1646,50 +1792,55 @@ PRInt32 nsString::FindCharInSet(const nsStr& aSet,PRInt32 anOffset) const{ /** - * + * Reverse search for given string within this string * * @update gess 3/25/98 - * @param - * @return + * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset + * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsString::RFind(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,anOffset); +PRInt32 nsString::RFind(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,anOffset,aCount); return result; } /** - * Reverse search for substring + * Reverse search for given string within this string * * @update gess 3/25/98 - * @param aString - * @param aIgnoreCase - * @param anOffset - tells us where to begin the search - * @return offset of substring or -1 + * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset + * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsString::RFind(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,anOffset); +PRInt32 nsString::RFind(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,anOffset,aCount); return result; } /** - * Reverse search for substring + * Reverse search for given string within this string * * @update gess 3/25/98 - * @param aString - * @param aIgnoreCase - * @param anOffset - tells us where to begin the search - * @return offset of substring or -1 + * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset + * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ +PRInt32 nsString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ NS_ASSERTION(0!=aString,kNullPointerError); - + PRInt32 result=kNotFound; if(aString) { nsStr temp; nsStr::Initialize(temp,eOneByte); temp.mLength=nsCRT::strlen(aString); temp.mStr=(char*)aString; - result=nsStr::RFindSubstr(*this,temp,aIgnoreCase,anOffset); + result=nsStr::RFindSubstr(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } @@ -1720,8 +1871,8 @@ PRInt32 nsString::RFind(PRUnichar aChar,PRInt32 anOffset,PRBool aIgnoreCase) con * @param anOffset * @return offset of found char, or -1 (kNotFound) */ -PRInt32 nsString::RFindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::RFindChar(*this,aChar,aIgnoreCase,anOffset); +PRInt32 nsString::RFindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::RFindChar(*this,aChar,aIgnoreCase,anOffset,aCount); return result; } @@ -2358,12 +2509,16 @@ void nsAutoString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const { } } +nsSubsumeStr::nsSubsumeStr() : nsString() { +} + nsSubsumeStr::nsSubsumeStr(nsStr& aString) : nsString() { - Subsume(*this,aString); + ::Subsume(*this,aString); } nsSubsumeStr::nsSubsumeStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength) : nsString() { mUStr=aString; + mCharSize=eTwoByte; mCapacity=mLength=(-1==aLength) ? nsCRT::strlen(aString) : aLength; mOwnsBuffer=assumeOwnership; } @@ -2375,3 +2530,9 @@ nsSubsumeStr::nsSubsumeStr(char* aString,PRBool assumeOwnership,PRInt32 aLength) mOwnsBuffer=assumeOwnership; } +nsSubsumeStr::Subsume(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength) { + mUStr=aString; + mCharSize=eTwoByte; + mCapacity=mLength=(-1==aLength) ? nsCRT::strlen(aString) : aLength; + mOwnsBuffer=assumeOwnership; +} diff --git a/mozilla/xpcom/ds/nsString2.h b/mozilla/xpcom/ds/nsString2.h index 90e48945009..04f25024050 100644 --- a/mozilla/xpcom/ds/nsString2.h +++ b/mozilla/xpcom/ds/nsString2.h @@ -310,9 +310,12 @@ public: * * @param aTrimSet -- contains chars to be trimmed from * both ends + * @param aEliminateLeading + * @param aEliminateTrailing + * @param aIgnoreQuotes * @return this */ - nsString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + nsString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE,PRBool aIgnoreQuotes=PR_FALSE); /** * This method strips whitespace from string. @@ -584,12 +587,13 @@ public: * @param aString is substring to be sought in this * @param aIgnoreCase selects case sensitivity * @param anOffset tells us where in this strig to start searching + * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ - PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; /** @@ -598,10 +602,11 @@ public: * @param aString is substring to be sought in this * @param anOffset tells us where in this strig to start searching * @param aIgnoreCase selects case sensitivity + * @param aCount tells us how many iterations to make starting at the given offset * @return find pos in string, or -1 (kNotFound) */ //PRInt32 Find(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const; - PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; /** * This method searches this string for the first character @@ -619,12 +624,14 @@ public: * This methods scans the string backwards, looking for the given string * @param aString is substring to be sought in this * @param aIgnoreCase tells us whether or not to do caseless compare - * @param anOffset tells us where in this strig to start searching (counting from left) + * @param anOffset tells us where in this strig to start searching (counting from left) + * @param aCount tells us how many iterations to make starting at the given offset + * @return offset in string, or -1 (kNotFound) */ - PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; /** @@ -633,10 +640,11 @@ public: * @param aString is substring to be sought in this * @param anOffset tells us where in this strig to start searching (counting from left) * @param aIgnoreCase selects case sensitivity + * @param aCount tells us how many iterations to make starting at the given offset * @return find pos in string, or -1 (kNotFound) */ //PRInt32 RFind(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const; - PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; /** * This method searches this string for the last character @@ -849,9 +857,11 @@ public: ***************************************************************/ class NS_COM nsSubsumeStr : public nsString { public: + nsSubsumeStr(); nsSubsumeStr(nsStr& aString); nsSubsumeStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1); nsSubsumeStr(char* aString,PRBool assumeOwnership,PRInt32 aLength=-1); + Subsume(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1); }; diff --git a/mozilla/xpcom/string/obsolete/nsStr.cpp b/mozilla/xpcom/string/obsolete/nsStr.cpp index e351f3c026b..bd40c1191c7 100644 --- a/mozilla/xpcom/string/obsolete/nsStr.cpp +++ b/mozilla/xpcom/string/obsolete/nsStr.cpp @@ -37,7 +37,6 @@ #include //only used for printf #include "nsCRT.h" #include "nsDeque.h" - //static const char* kCallFindChar = "For better performance, call FindChar() for targets whose length==1."; //static const char* kCallRFindChar = "For better performance, call RFindChar() for targets whose length==1."; @@ -327,7 +326,7 @@ void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool a if(aEliminateLeading) { while(++theIndex<=theMax) { PRUnichar theChar=GetCharAt(aDest,theIndex); - PRInt32 thePos=gFindChars[eOneByte](aSet,theSetLen,0,theChar,PR_FALSE); + PRInt32 thePos=gFindChars[eOneByte](aSet,theSetLen,0,theChar,PR_FALSE,theSetLen); if(kNotFound==thePos) break; } @@ -344,7 +343,7 @@ void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool a PRInt32 theNewLen=theIndex; while(--theIndex>0) { PRUnichar theChar=GetCharAt(aDest,theIndex); //read at end now... - PRInt32 thePos=gFindChars[eOneByte](aSet,theSetLen,0,theChar,PR_FALSE); + PRInt32 thePos=gFindChars[eOneByte](aSet,theSetLen,0,theChar,PR_FALSE,theSetLen); if(kNotFound=aTarget.mLength) && (aTarget.mLength>0) && (index>=0)){ - PRInt32 theTargetMax=aTarget.mLength; - while(index<=theMax) { - PRInt32 theSubIndex=-1; - PRBool matches=PR_TRUE; - while((++theSubIndex=aTarget.mLength) && (aTarget.mLength>0) && (index>=0)){ + const char* rightmost = root+(anOffset*aDelta); + const char* min = rightmost-((aCount-1)*aDelta); - nsStr theCopy; - nsStr::Initialize(theCopy,eOneByte); - nsStr::Assign(theCopy,aTarget,0,aTarget.mLength); - if(aIgnoreCase){ - nsStr::ChangeCase(theCopy,PR_FALSE); //force to lowercase - } - - PRInt32 theTargetMax=theCopy.mLength; - while(index>=0) { - PRInt32 theSubIndex=-1; - PRBool matches=PR_FALSE; - if(index+theCopy.mLength<=aDest.mLength) { - matches=PR_TRUE; - while((++theSubIndex=0) { PRUnichar theChar=GetCharAt(aDest,index); - thePos=gFindChars[aSet.mCharSize](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase); + thePos=gFindChars[aSet.mCharSize](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase,aSet.mLength); if(kNotFound!=thePos) return index; } //while diff --git a/mozilla/xpcom/string/obsolete/nsStr.h b/mozilla/xpcom/string/obsolete/nsStr.h index c6c7fdf11ad..7bcdd560338 100644 --- a/mozilla/xpcom/string/obsolete/nsStr.h +++ b/mozilla/xpcom/string/obsolete/nsStr.h @@ -223,8 +223,6 @@ public: struct NS_COM nsStr { -//---------------------------------------------------------------------------------------- - nsStr() { MOZ_COUNT_CTOR(nsStr); } @@ -402,12 +400,12 @@ struct NS_COM nsStr { * @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 FindSubstr(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset); - static PRInt32 FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset); + static PRInt32 FindSubstr(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount); + static PRInt32 FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount); static PRInt32 FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset); - static PRInt32 RFindSubstr(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset); - static PRInt32 RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset); + static PRInt32 RFindSubstr(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount); + static PRInt32 RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount); static PRInt32 RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset); static void Overwrite(nsStr& aDest,const nsStr& aSource,PRInt32 anOffset); @@ -445,6 +443,9 @@ private: }; + + + /************************************************************** A couple of tiny helper methods used in the string classes. **************************************************************/ @@ -485,6 +486,7 @@ inline PRUnichar GetCharAt(const nsStr& aDest,PRUint32 anIndex){ return 0; } + #ifdef NS_STR_STATS class nsStringInfo { diff --git a/mozilla/xpcom/string/obsolete/nsString.cpp b/mozilla/xpcom/string/obsolete/nsString.cpp index 80fc1b9dada..a32efac8f70 100644 --- a/mozilla/xpcom/string/obsolete/nsString.cpp +++ b/mozilla/xpcom/string/obsolete/nsString.cpp @@ -342,10 +342,10 @@ void nsCString::ToUpperCase(nsCString& aString) const { */ nsCString& nsCString::StripChar(PRUnichar aChar,PRInt32 anOffset){ - anOffset=nsStr::FindChar(*this,aChar,PR_FALSE,anOffset); + anOffset=nsStr::FindChar(*this,aChar,PR_FALSE,anOffset,mLength); while(kNotFound2)) { + theFirstChar=First(); + theLastChar=Last(); + if(theFirstChar==theLastChar) { + if(('\''==theFirstChar) || ('"'==theFirstChar)) { + Cut(0,1); + Truncate(mLength-1); + theQuotesAreNeeded=PR_TRUE; + } + else theFirstChar=0; + } + } + nsStr::Trim(*this,aTrimSet,aEliminateLeading,aEliminateTrailing); + + if(aIgnoreQuotes && theQuotesAreNeeded) { + Insert(theFirstChar,0); + Append(theLastChar); + } + } return *this; } @@ -644,7 +669,7 @@ float nsCString::ToFloat(PRInt32* aErrorCode) const { * @return int rep of string value */ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) { - + //copy chars to local buffer -- step down from 2 bytes to 1 if necessary... PRInt32 result=0; @@ -712,10 +737,11 @@ PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) { */ static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) { - const char* cp=aString.GetBuffer(); + const char* cp=aString.mStr; PRInt32 result=NS_ERROR_ILLEGAL_VALUE; if(cp) { + aRadix = (kAutoDetect==aRadix) ? 10 : aRadix; //begin by skipping over leading chars that shouldn't be part of the number... @@ -725,16 +751,19 @@ static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) { while(!done){ switch(*cp) { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + aRadix=16; + done=PR_TRUE; + break; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': case '-': case '+': case '#': done=PR_TRUE; break; default: cp++; - done=cp='A') && (theChar<='F')) { + if(10==theRadix) { + if(kAutoDetect==aRadix){ + theRadix=16; + cp=first; //backup + result=0; + } + else { + *anErrorCode=NS_ERROR_ILLEGAL_VALUE; + result=0; + break; + } + } + else { + result = (theRadix * result) + ((theChar-'A')+10); + } + } + else if((theChar>='a') && (theChar<='f')) { + if(10==theRadix) { + if(kAutoDetect==aRadix){ + theRadix=16; + cp=first; //backup + result=0; + } + else { + *anErrorCode=NS_ERROR_ILLEGAL_VALUE; + result=0; + break; + } + } + else { + result = (theRadix * result) + ((theChar-'a')+10); + } + } + else if(('X'==theChar) || ('x'==theChar) || ('#'==theChar) || ('+'==theChar)) { + continue; + } + else { + //we've encountered a char that's not a legal number or sign + break; + } + } //while + if(negate) + result=-result; + } //if + } + return result; +#endif } /********************************************************************** @@ -894,7 +1028,7 @@ nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) { // If this assertion fires, the caller is probably lying about the length of // the passed-in string. File a bug on the caller. #ifdef NS_DEBUG - PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0); + PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength); NS_WARN_IF_FALSE(kNotFound==len,"possible embedded null in Assign(PRUnichar*)"); #endif @@ -1183,7 +1317,7 @@ nsCString& nsCString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCou // If this assertion fires, the caller is probably lying about the length of // the passed-in string. File a bug on the caller. #ifdef NS_DEBUG - PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0); + PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength); NS_WARN_IF_FALSE(kNotFound==len,"possible embedded null in Insert(char*)"); #endif @@ -1287,18 +1421,19 @@ PRInt32 nsCString::BinarySearch(PRUnichar aChar) const{ * * @update gess 3/25/98 * @param aCString - substr to be found - * @param aIgnoreCase - * @param anOffset + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsCString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset) const{ +PRInt32 nsCString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ PRInt32 result=kNotFound; if(aCString) { nsStr temp; nsStr::Initialize(temp,eOneByte); - temp.mLength=nsCRT::strlen(aCString); + temp.mLength = nsCRT::strlen(aCString); temp.mStr=(char*)aCString; - result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset); + result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } @@ -1307,21 +1442,22 @@ PRInt32 nsCString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset * Search for given buffer within this string * * @update gess 3/25/98 - * @param aString unichar* to be found - * @param aIgnoreCase - * @param anOffset + * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsCString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ +PRInt32 nsCString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ NS_ASSERTION(0!=aString,kNullPointerError); PRInt32 result=kNotFound; if(aString) { nsStr temp; nsStr::Initialize(temp,eTwoByte); - temp.mLength=nsCRT::strlen(aString); + temp.mLength = nsCRT::strlen(aString); temp.mUStr=(PRUnichar*)aString; - result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset); + result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } @@ -1330,28 +1466,30 @@ PRInt32 nsCString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOf * Search for given string within this string * * @update gess 3/25/98 - * @param aSTring -- buffer to be found - * @param aIgnoreCase - * @param anOffset + * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsCString::Find(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,anOffset); +PRInt32 nsCString::Find(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,anOffset,aCount); return result; } /** - * Search for a given char, starting at given offset + * This searches this string for a given character * - * @update gess 3/25/98 - * @param aChar the unichar to be sought - * @param aIgnoreCase - * @param anOffset - * @return offset of found char, or -1 (kNotFound) + * @update gess 2/04/00 + * @param char is the character you're trying to find. + * @param aIgnorecase indicates case sensitivity of search + * @param anOffset tells us where to start the search; -1 means start at 0. + * @param aCount tell us how many chars to search from offset; -1 means use full length. + * @return index in aDest where member of aSet occurs, or -1 if not found */ -PRInt32 nsCString::FindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::FindChar(*this,aChar,aIgnoreCase,anOffset); +PRInt32 nsCString::FindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::FindChar(*this,aChar,aIgnoreCase,anOffset,aCount); return result; } @@ -1416,30 +1554,32 @@ PRInt32 nsCString::FindCharInSet(const nsStr& aSet,PRInt32 anOffset) const{ } /** - * Reverse search for substring + * Reverse search for given string within this string * * @update gess 3/25/98 - * @param aString - * @param aIgnoreCase - * @param anOffset - tells us where to begin the search - * @return offset of substring or -1 + * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset + * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsCString::RFind(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,anOffset); +PRInt32 nsCString::RFind(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,anOffset,aCount); return result; } /** - * Reverse search for substring + * Reverse search for given string within this string * * @update gess 3/25/98 - * @param aString - * @param aIgnoreCase - * @param anOffset - tells us where to begin the search - * @return offset of substring or -1 + * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset + * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsCString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ +PRInt32 nsCString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ NS_ASSERTION(0!=aString,kNullPointerError); PRInt32 result=kNotFound; @@ -1448,22 +1588,23 @@ PRInt32 nsCString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset nsStr::Initialize(temp,eOneByte); temp.mLength=nsCRT::strlen(aString); temp.mStr=(char*)aString; - result=nsStr::RFindSubstr(*this,temp,aIgnoreCase,anOffset); + result=nsStr::RFindSubstr(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } /** - * Reverse search for char + * This reverse searches this string for a given character * - * @update gess 3/25/98 - * @param aChar - * @param aIgnoreCase - * @param anOffset - tells us where to begin the search - * @return offset of substring or -1 + * @update gess 2/04/00 + * @param char is the character you're trying to find. + * @param aIgnorecase indicates case sensitivity of search + * @param anOffset tells us where to start the search; -1 means start at 0. + * @param aCount tell us how many chars to search from offset; -1 means use full length. + * @return index in aDest where member of aSet occurs, or -1 if not found */ -PRInt32 nsCString::RFindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::RFindChar(*this,aChar,aIgnoreCase,anOffset); +PRInt32 nsCString::RFindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::RFindChar(*this,aChar,aIgnoreCase,anOffset,aCount); return result; } diff --git a/mozilla/xpcom/string/obsolete/nsString.h b/mozilla/xpcom/string/obsolete/nsString.h index 5edd943f280..6f1a91eb932 100644 --- a/mozilla/xpcom/string/obsolete/nsString.h +++ b/mozilla/xpcom/string/obsolete/nsString.h @@ -270,9 +270,12 @@ public: * * @param aTrimSet -- contains chars to be trimmed from * both ends + * @param aEliminateLeading + * @param aEliminateTrailing + * @param aIgnoreQuotes * @return this */ - nsCString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + nsCString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE,PRBool aIgnoreQuotes=PR_FALSE); /** * This method strips whitespace from string. @@ -533,11 +536,12 @@ public: * @param aString is substring to be sought in this * @param aIgnoreCase selects case sensitivity * @param anOffset tells us where in this strig to start searching + * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ - PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; /** * Search for given char within this string @@ -545,9 +549,10 @@ public: * @param aString is substring to be sought in this * @param anOffset tells us where in this strig to start searching * @param aIgnoreCase selects case sensitivity + * @param aCount tells us how many iterations to make starting at the given offset * @return find pos in string, or -1 (kNotFound) */ - PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; /** * This method searches this string for the first character @@ -565,11 +570,12 @@ public: * This methods scans the string backwards, looking for the given string * @param aString is substring to be sought in this * @param aIgnoreCase tells us whether or not to do caseless compare + * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ - PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; /** @@ -580,7 +586,7 @@ public: * @param aIgnoreCase selects case sensitivity * @return find pos in string, or -1 (kNotFound) */ - PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; /** * This method searches this string for the last character diff --git a/mozilla/xpcom/string/obsolete/nsString2.cpp b/mozilla/xpcom/string/obsolete/nsString2.cpp index 9afcd9bb706..257325996a9 100644 --- a/mozilla/xpcom/string/obsolete/nsString2.cpp +++ b/mozilla/xpcom/string/obsolete/nsString2.cpp @@ -403,10 +403,10 @@ void nsString::ToUpperCase(nsString& aString) const { */ nsString& nsString::StripChar(PRUnichar aChar,PRInt32 anOffset){ - anOffset=nsStr::FindChar(*this,aChar,PR_FALSE,anOffset); + anOffset=nsStr::FindChar(*this,aChar,PR_FALSE,anOffset,mLength); while(kNotFound2)) { + theFirstChar=First(); + theLastChar=Last(); + if(theFirstChar==theLastChar) { + if(('\''==theFirstChar) || ('"'==theFirstChar)) { + Cut(0,1); + Truncate(mLength-1); + theQuotesAreNeeded=PR_TRUE; + } + else theFirstChar=0; + } + } + + nsStr::Trim(*this,aTrimSet,aEliminateLeading,aEliminateTrailing); + + if(aIgnoreQuotes && theQuotesAreNeeded) { + Insert(theFirstChar,0); + Append(theLastChar); + } + + } return *this; } @@ -872,10 +896,11 @@ static PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadi */ static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) { - const char* cp=aString.GetBuffer(); + const char* cp=aString.mStr; PRInt32 result=NS_ERROR_ILLEGAL_VALUE; if(cp) { + aRadix = (kAutoDetect==aRadix) ? 10 : aRadix; //begin by skipping over leading chars that shouldn't be part of the number... @@ -885,16 +910,19 @@ static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) { while(!done){ switch(*cp) { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + aRadix=16; + done=PR_TRUE; + break; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': case '-': case '+': case '#': done=PR_TRUE; break; default: cp++; - done=cp='A') && (theChar<='F')) { + if(10==theRadix) { + if(kAutoDetect==aRadix){ + theRadix=16; + cp=first; //backup + result=0; + } + else { + *anErrorCode=NS_ERROR_ILLEGAL_VALUE; + result=0; + break; + } + } + else { + result = (theRadix * result) + ((theChar-'A')+10); + } + } + else if((theChar>='a') && (theChar<='f')) { + if(10==theRadix) { + if(kAutoDetect==aRadix){ + theRadix=16; + cp=first; //backup + result=0; + } + else { + *anErrorCode=NS_ERROR_ILLEGAL_VALUE; + result=0; + break; + } + } + else { + result = (theRadix * result) + ((theChar-'a')+10); + } + } + else if(('X'==theChar) || ('x'==theChar) || ('#'==theChar) || ('+'==theChar)) { + continue; + } + else { + //we've encountered a char that's not a legal number or sign + break; + } + } //while + if(negate) + result=-result; + } //if } return result; +#endif } /********************************************************************** @@ -1146,7 +1279,7 @@ nsString& nsString::Append(const char* aCString,PRInt32 aCount) { // the passed-in string. File a bug on the caller. #ifdef NS_DEBUG - PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0); + PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength); NS_WARN_IF_FALSE(kNotFound==len,"possible embedded null in append(char*)"); #endif @@ -1180,7 +1313,7 @@ nsString& nsString::Append(const PRUnichar* aString,PRInt32 aCount) { // If this assertion fires, the caller is probably lying about the length of // the passed-in string. File a bug on the caller. #ifdef NS_DEBUG - PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0); + PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength); NS_WARN_IF_FALSE(kNotFound==len,"possible embedded null in append(PRUnichar*)"); #endif @@ -1372,7 +1505,7 @@ nsString& nsString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCount // If this assertion fires, the caller is probably lying about the length of // the passed-in string. File a bug on the caller. #ifdef NS_DEBUG - PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0); + PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength); NS_WARN_IF_FALSE(kNotFound==len,"possible embedded null in Insert(char*)"); #endif @@ -1410,7 +1543,7 @@ nsString& nsString::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32 aC // If this assertion fires, the caller is probably lying about the length of // the passed-in string. File a bug on the caller. #ifdef NS_DEBUG - PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0); + PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength); NS_WARN_IF_FALSE(kNotFound==len,"possible embedded null in Insert(PRUnichar*)"); #endif @@ -1491,13 +1624,16 @@ PRInt32 nsString::BinarySearch(PRUnichar aChar) const{ } /** - * Search for given cstr within this string + * search for given string within this string * * @update gess 3/25/98 - * @param aCString - substr to be found + * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset) const{ +PRInt32 nsString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ NS_ASSERTION(0!=aCString,kNullPointerError); PRInt32 result=kNotFound; @@ -1506,19 +1642,22 @@ PRInt32 nsString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset) nsStr::Initialize(temp,eOneByte); temp.mLength=nsCRT::strlen(aCString); temp.mStr=(char*)aCString; - result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset); + result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } /** - * Search for given unichar* within this string + * search for given string within this string * * @update gess 3/25/98 * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ +PRInt32 nsString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ NS_ASSERTION(0!=aString,kNullPointerError); PRInt32 result=kNotFound; @@ -1527,32 +1666,38 @@ PRInt32 nsString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOff nsStr::Initialize(temp,eTwoByte); temp.mLength=nsCRT::strlen(aString); temp.mUStr=(PRUnichar*)aString; - result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset); + result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } -/** - * Search for given nsSTr within this string - * - * @update gess 3/25/98 - * @param aString - substr to be found - * @return offset in string, or -1 (kNotFound) - */ -PRInt32 nsString::Find(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,anOffset); - return result; -} - /** * Search for given string within this string * * @update gess 3/25/98 * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsString::Find(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,anOffset); +PRInt32 nsString::Find(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,anOffset,aCount); + return result; +} + +/** + * search for given string within this string + * + * @update gess 3/25/98 + * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset + * @return offset in string, or -1 (kNotFound) + */ +PRInt32 nsString::Find(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,anOffset,aCount); return result; } @@ -1575,12 +1720,13 @@ PRInt32 nsString::Find(PRUnichar aChar,PRInt32 anOffset,PRBool aIgnoreCase) cons * * @update gess 3/25/98 * @param aChar is the unichar to be sought - * @param anOffset - * @param aIgnoreCase - * @return offset of found char, or -1 (kNotFound) + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset + * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsString::FindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::FindChar(*this,aChar,aIgnoreCase,anOffset); +PRInt32 nsString::FindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::FindChar(*this,aChar,aIgnoreCase,anOffset,aCount); return result; } @@ -1646,50 +1792,55 @@ PRInt32 nsString::FindCharInSet(const nsStr& aSet,PRInt32 anOffset) const{ /** - * + * Reverse search for given string within this string * * @update gess 3/25/98 - * @param - * @return + * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset + * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsString::RFind(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,anOffset); +PRInt32 nsString::RFind(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,anOffset,aCount); return result; } /** - * Reverse search for substring + * Reverse search for given string within this string * * @update gess 3/25/98 - * @param aString - * @param aIgnoreCase - * @param anOffset - tells us where to begin the search - * @return offset of substring or -1 + * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset + * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsString::RFind(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,anOffset); +PRInt32 nsString::RFind(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,anOffset,aCount); return result; } /** - * Reverse search for substring + * Reverse search for given string within this string * * @update gess 3/25/98 - * @param aString - * @param aIgnoreCase - * @param anOffset - tells us where to begin the search - * @return offset of substring or -1 + * @param aString - substr to be found + * @param aIgnoreCase tells us whether or not to do caseless compare + * @param anOffset tells us where in this string to start searching + * @param aCount tells us how many iterations to make starting at the given offset + * @return offset in string, or -1 (kNotFound) */ -PRInt32 nsString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset) const{ +PRInt32 nsString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ NS_ASSERTION(0!=aString,kNullPointerError); - + PRInt32 result=kNotFound; if(aString) { nsStr temp; nsStr::Initialize(temp,eOneByte); temp.mLength=nsCRT::strlen(aString); temp.mStr=(char*)aString; - result=nsStr::RFindSubstr(*this,temp,aIgnoreCase,anOffset); + result=nsStr::RFindSubstr(*this,temp,aIgnoreCase,anOffset,aCount); } return result; } @@ -1720,8 +1871,8 @@ PRInt32 nsString::RFind(PRUnichar aChar,PRInt32 anOffset,PRBool aIgnoreCase) con * @param anOffset * @return offset of found char, or -1 (kNotFound) */ -PRInt32 nsString::RFindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset) const{ - PRInt32 result=nsStr::RFindChar(*this,aChar,aIgnoreCase,anOffset); +PRInt32 nsString::RFindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{ + PRInt32 result=nsStr::RFindChar(*this,aChar,aIgnoreCase,anOffset,aCount); return result; } @@ -2358,12 +2509,16 @@ void nsAutoString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const { } } +nsSubsumeStr::nsSubsumeStr() : nsString() { +} + nsSubsumeStr::nsSubsumeStr(nsStr& aString) : nsString() { - Subsume(*this,aString); + ::Subsume(*this,aString); } nsSubsumeStr::nsSubsumeStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength) : nsString() { mUStr=aString; + mCharSize=eTwoByte; mCapacity=mLength=(-1==aLength) ? nsCRT::strlen(aString) : aLength; mOwnsBuffer=assumeOwnership; } @@ -2375,3 +2530,9 @@ nsSubsumeStr::nsSubsumeStr(char* aString,PRBool assumeOwnership,PRInt32 aLength) mOwnsBuffer=assumeOwnership; } +nsSubsumeStr::Subsume(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength) { + mUStr=aString; + mCharSize=eTwoByte; + mCapacity=mLength=(-1==aLength) ? nsCRT::strlen(aString) : aLength; + mOwnsBuffer=assumeOwnership; +} diff --git a/mozilla/xpcom/string/obsolete/nsString2.h b/mozilla/xpcom/string/obsolete/nsString2.h index 90e48945009..04f25024050 100644 --- a/mozilla/xpcom/string/obsolete/nsString2.h +++ b/mozilla/xpcom/string/obsolete/nsString2.h @@ -310,9 +310,12 @@ public: * * @param aTrimSet -- contains chars to be trimmed from * both ends + * @param aEliminateLeading + * @param aEliminateTrailing + * @param aIgnoreQuotes * @return this */ - nsString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE); + nsString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE,PRBool aIgnoreQuotes=PR_FALSE); /** * This method strips whitespace from string. @@ -584,12 +587,13 @@ public: * @param aString is substring to be sought in this * @param aIgnoreCase selects case sensitivity * @param anOffset tells us where in this strig to start searching + * @param aCount tells us how many iterations to make starting at the given offset * @return offset in string, or -1 (kNotFound) */ - PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; /** @@ -598,10 +602,11 @@ public: * @param aString is substring to be sought in this * @param anOffset tells us where in this strig to start searching * @param aIgnoreCase selects case sensitivity + * @param aCount tells us how many iterations to make starting at the given offset * @return find pos in string, or -1 (kNotFound) */ //PRInt32 Find(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const; - PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; /** * This method searches this string for the first character @@ -619,12 +624,14 @@ public: * This methods scans the string backwards, looking for the given string * @param aString is substring to be sought in this * @param aIgnoreCase tells us whether or not to do caseless compare - * @param anOffset tells us where in this strig to start searching (counting from left) + * @param anOffset tells us where in this strig to start searching (counting from left) + * @param aCount tells us how many iterations to make starting at the given offset + * @return offset in string, or -1 (kNotFound) */ - PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; - PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; + PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; /** @@ -633,10 +640,11 @@ public: * @param aString is substring to be sought in this * @param anOffset tells us where in this strig to start searching (counting from left) * @param aIgnoreCase selects case sensitivity + * @param aCount tells us how many iterations to make starting at the given offset * @return find pos in string, or -1 (kNotFound) */ //PRInt32 RFind(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const; - PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const; + PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const; /** * This method searches this string for the last character @@ -849,9 +857,11 @@ public: ***************************************************************/ class NS_COM nsSubsumeStr : public nsString { public: + nsSubsumeStr(); nsSubsumeStr(nsStr& aString); nsSubsumeStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1); nsSubsumeStr(char* aString,PRBool assumeOwnership,PRInt32 aLength=-1); + Subsume(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1); };