From a1de8e5158eca60690d488afeef04a639073eb31 Mon Sep 17 00:00:00 2001 From: "rickg%netscape.com" Date: Sun, 13 Feb 2000 17:46:15 +0000 Subject: [PATCH] major perf mods for bug 27524, and removed deprecated methods; r=harishd git-svn-id: svn://10.0.0.236/trunk@60648 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/string/obsolete/nsStr.cpp | 126 ++++++------ mozilla/string/obsolete/nsString.cpp | 206 +------------------- mozilla/string/obsolete/nsString.h | 8 +- mozilla/string/obsolete/nsString2.cpp | 193 +----------------- mozilla/string/obsolete/nsString2.h | 9 +- mozilla/xpcom/ds/nsStr.cpp | 126 ++++++------ mozilla/xpcom/ds/nsString.cpp | 206 +------------------- mozilla/xpcom/ds/nsString.h | 8 +- mozilla/xpcom/ds/nsString2.cpp | 193 +----------------- mozilla/xpcom/ds/nsString2.h | 9 +- mozilla/xpcom/string/obsolete/nsStr.cpp | 126 ++++++------ mozilla/xpcom/string/obsolete/nsString.cpp | 206 +------------------- mozilla/xpcom/string/obsolete/nsString.h | 8 +- mozilla/xpcom/string/obsolete/nsString2.cpp | 193 +----------------- mozilla/xpcom/string/obsolete/nsString2.h | 9 +- 15 files changed, 231 insertions(+), 1395 deletions(-) diff --git a/mozilla/string/obsolete/nsStr.cpp b/mozilla/string/obsolete/nsStr.cpp index a1b21c11225..f8698de6802 100644 --- a/mozilla/string/obsolete/nsStr.cpp +++ b/mozilla/string/obsolete/nsStr.cpp @@ -389,44 +389,53 @@ void nsStr::StripChars(nsStr& aDest,const char* aSet){ Searching methods... **************************************************************/ + /** * This searches aDest for a given substring * - * @update gess 3/25/98 + * @update gess 2/04/00: added aCount argument to restrict search * @param aDest string to search * @param aTarget is the substring you're trying to find. * @param aIgnorecase indicates case sensitivity of search * @param anOffset tells us where to start the search + * @param aCount tells us how many iterations to make from offset; -1 means the full length of the string * @return index in aDest where member of aSet occurs, or -1 if not found */ PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) { - // NS_PRECONDITION(aTarget.mLength!=1,kCallFindChar); + PRInt32 theMaxPos = aDest.mLength-aTarget.mLength; //this is the last pos that is feasible for starting the search, with given lengths... - PRInt32 result=kNotFound; - - if((0=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=aString.mStr){ - theChar=*cp; - if((theChar>='0') && (theChar<='9')){ - theDigit=theChar-'0'; - } - else if((theChar>='A') && (theChar<='F')) { - if(10==aRadix){ - *anErrorCode=NS_ERROR_ILLEGAL_VALUE; - result=0; - break; - } - theDigit=(theChar-'A')+10; - } - else if((theChar>='a') && (theChar<='f')) { - if(10==aRadix){ - *anErrorCode=NS_ERROR_ILLEGAL_VALUE; - result=0; - break; - } - theDigit=(theChar-'a')+10; - } - else if('-'==theChar) { - result=-result; - break; - } - else if(('+'==theChar) || (' '==theChar) || ('X'==theChar) || ('x'==theChar)) { //stop in a good state if you see this... - break; - } - else { - //we've encountered a char that's not a legal number or sign - *anErrorCode=NS_ERROR_ILLEGAL_VALUE; - result=0; - break; - } - - result+=theDigit*theMult; - theMult*=aRadix; - } - - return result; -} - - -/** - * Call this method to extract the rightmost numeric value from the given - * 1-byte input string, and simultaneously determine the radix. - * NOTE: This method mandates that the string is well formed. - * Leading and trailing gunk should be removed, and upper-cased. - * @update gess 10/01/98 - * @param anInputString contains orig string - * @param anOutString contains numeric portion copy of input string - * @param aRadix (an out parm) tells the caller what base we think the string is in. - * @return non-zero error code if this string is non-numeric - */ -static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) { - - 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... - - char* to=(char*)cp; - const char* endcp=cp+aString.mLength; - PRBool done=PR_FALSE; - - while(!done){ - switch(*cp) { - 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==endcp); - break; - } //switch - } - - while(cp=theChar) { - aRadix=16; - *to++=theChar; - } - else if('X'==theChar) { - if('-'==aString.mStr[0]) - to=&aString.mStr[1]; - else to=aString.mStr; - aRadix=16; - } - else if('a'<=theChar) { - if('f'>=theChar) { - aRadix=16; - *to++='A'+(theChar-'a'); - } - else if('x'==theChar) { - if('-'==aString.mStr[0]) - to=&aString.mStr[1]; - else to=aString.mStr; - aRadix=16; - } - } - else break; //bad char - } - else if((theChar>='0') && (theChar<='9')) { - *to++=theChar; - } - else if('-'==theChar) { - *to++=theChar; - } - else if(('#'!=theChar) && ('+'!=theChar)){ - break; //terminate on invalid char! - } - cp++; - } - - aString.Truncate(to-aString.mStr); - result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; - } - return result; -} - - -/** - * This method tries to autodetect that radix given a string - * @update gess 10/01/98 - * @return 10,16,or 0 (meaning I don't know) - */ -PRUint32 nsCString::DetermineRadix(void) { - PRUint32 result=kRadixUnknown; - if(0=aString.mStr){ - char theChar=*cp; - if((theChar>='0') && (theChar<='9')){ - theDigit=theChar-'0'; - } - else if((theChar>='A') && (theChar<='F')) { - if(10==aRadix){ - *anErrorCode=NS_ERROR_ILLEGAL_VALUE; - result=0; - break; - } - theDigit=(theChar-'A')+10; - } - else if('-'==theChar) { - result=-result; - break; - } - else if(('+'==theChar) || (' '==theChar)) { //stop in a good state if you see this... - break; - } - else { - //we've encountered a char that's not a legal number or sign - *anErrorCode=NS_ERROR_ILLEGAL_VALUE; - result=0; - break; - } - - result+=theDigit*theMult; - theMult*=aRadix; - } - return result; -} - -/** - * Call this method to extract the rightmost numeric value from the given - * 1-byte input string, and simultaneously determine the radix. - * NOTE: This method mandates that the string is well formed. - * Leading and trailing gunk should be removed, and the case upper. - * @update gess 10/01/98 - * @param anInputString contains orig string - * @param anOutString contains numeric portion copy of input string - * @param aRadix (an out parm) tells the caller what base we think the string is in. - * @return non-zero error code if this string is non-numeric - */ -static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) { - - 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... - - char* to=(char*)cp; - const char* endcp=cp+aString.mLength; - PRBool done=PR_FALSE; - - while(!done){ - switch(*cp) { - 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==endcp); - break; - } //switch - } - - while(cp=theChar) { - aRadix=16; - *to++=theChar; - } - else if('X'==theChar) { - if('-'==aString.mStr[0]) - to=&aString.mStr[1]; - else to=aString.mStr; - aRadix=16; - } - else if('a'<=theChar) { - if('f'>=theChar) { - aRadix=16; - *to++='A'+(theChar-'a'); - } - else if('x'==theChar) { - if('-'==aString.mStr[0]) - to=&aString.mStr[1]; - else to=aString.mStr; - aRadix=16; - } - } - else break; //bad char - } - else if((theChar>='0') && (theChar<='9')) { - *to++=theChar; - } - else if('-'==theChar) { - *to++=theChar; - } - else if(('#'!=theChar) && ('+'!=theChar)){ - break; //terminate on invalid char! - } - cp++; - } - - aString.Truncate(to-aString.mStr); - result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; - } - return result; -} - - -/** - * This method tries to autodetect that radix given a string - * @update gess 10/01/98 - * @return 10,16,or 0 (meaning I don't know) - */ -PRUint32 nsString::DetermineRadix(void) { - PRUint32 result=kRadixUnknown; - if(0=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=aString.mStr){ - theChar=*cp; - if((theChar>='0') && (theChar<='9')){ - theDigit=theChar-'0'; - } - else if((theChar>='A') && (theChar<='F')) { - if(10==aRadix){ - *anErrorCode=NS_ERROR_ILLEGAL_VALUE; - result=0; - break; - } - theDigit=(theChar-'A')+10; - } - else if((theChar>='a') && (theChar<='f')) { - if(10==aRadix){ - *anErrorCode=NS_ERROR_ILLEGAL_VALUE; - result=0; - break; - } - theDigit=(theChar-'a')+10; - } - else if('-'==theChar) { - result=-result; - break; - } - else if(('+'==theChar) || (' '==theChar) || ('X'==theChar) || ('x'==theChar)) { //stop in a good state if you see this... - break; - } - else { - //we've encountered a char that's not a legal number or sign - *anErrorCode=NS_ERROR_ILLEGAL_VALUE; - result=0; - break; - } - - result+=theDigit*theMult; - theMult*=aRadix; - } - - return result; -} - - -/** - * Call this method to extract the rightmost numeric value from the given - * 1-byte input string, and simultaneously determine the radix. - * NOTE: This method mandates that the string is well formed. - * Leading and trailing gunk should be removed, and upper-cased. - * @update gess 10/01/98 - * @param anInputString contains orig string - * @param anOutString contains numeric portion copy of input string - * @param aRadix (an out parm) tells the caller what base we think the string is in. - * @return non-zero error code if this string is non-numeric - */ -static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) { - - 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... - - char* to=(char*)cp; - const char* endcp=cp+aString.mLength; - PRBool done=PR_FALSE; - - while(!done){ - switch(*cp) { - 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==endcp); - break; - } //switch - } - - while(cp=theChar) { - aRadix=16; - *to++=theChar; - } - else if('X'==theChar) { - if('-'==aString.mStr[0]) - to=&aString.mStr[1]; - else to=aString.mStr; - aRadix=16; - } - else if('a'<=theChar) { - if('f'>=theChar) { - aRadix=16; - *to++='A'+(theChar-'a'); - } - else if('x'==theChar) { - if('-'==aString.mStr[0]) - to=&aString.mStr[1]; - else to=aString.mStr; - aRadix=16; - } - } - else break; //bad char - } - else if((theChar>='0') && (theChar<='9')) { - *to++=theChar; - } - else if('-'==theChar) { - *to++=theChar; - } - else if(('#'!=theChar) && ('+'!=theChar)){ - break; //terminate on invalid char! - } - cp++; - } - - aString.Truncate(to-aString.mStr); - result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; - } - return result; -} - - -/** - * This method tries to autodetect that radix given a string - * @update gess 10/01/98 - * @return 10,16,or 0 (meaning I don't know) - */ -PRUint32 nsCString::DetermineRadix(void) { - PRUint32 result=kRadixUnknown; - if(0=aString.mStr){ - char theChar=*cp; - if((theChar>='0') && (theChar<='9')){ - theDigit=theChar-'0'; - } - else if((theChar>='A') && (theChar<='F')) { - if(10==aRadix){ - *anErrorCode=NS_ERROR_ILLEGAL_VALUE; - result=0; - break; - } - theDigit=(theChar-'A')+10; - } - else if('-'==theChar) { - result=-result; - break; - } - else if(('+'==theChar) || (' '==theChar)) { //stop in a good state if you see this... - break; - } - else { - //we've encountered a char that's not a legal number or sign - *anErrorCode=NS_ERROR_ILLEGAL_VALUE; - result=0; - break; - } - - result+=theDigit*theMult; - theMult*=aRadix; - } - return result; -} - -/** - * Call this method to extract the rightmost numeric value from the given - * 1-byte input string, and simultaneously determine the radix. - * NOTE: This method mandates that the string is well formed. - * Leading and trailing gunk should be removed, and the case upper. - * @update gess 10/01/98 - * @param anInputString contains orig string - * @param anOutString contains numeric portion copy of input string - * @param aRadix (an out parm) tells the caller what base we think the string is in. - * @return non-zero error code if this string is non-numeric - */ -static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) { - - 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... - - char* to=(char*)cp; - const char* endcp=cp+aString.mLength; - PRBool done=PR_FALSE; - - while(!done){ - switch(*cp) { - 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==endcp); - break; - } //switch - } - - while(cp=theChar) { - aRadix=16; - *to++=theChar; - } - else if('X'==theChar) { - if('-'==aString.mStr[0]) - to=&aString.mStr[1]; - else to=aString.mStr; - aRadix=16; - } - else if('a'<=theChar) { - if('f'>=theChar) { - aRadix=16; - *to++='A'+(theChar-'a'); - } - else if('x'==theChar) { - if('-'==aString.mStr[0]) - to=&aString.mStr[1]; - else to=aString.mStr; - aRadix=16; - } - } - else break; //bad char - } - else if((theChar>='0') && (theChar<='9')) { - *to++=theChar; - } - else if('-'==theChar) { - *to++=theChar; - } - else if(('#'!=theChar) && ('+'!=theChar)){ - break; //terminate on invalid char! - } - cp++; - } - - aString.Truncate(to-aString.mStr); - result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; - } - return result; -} - - -/** - * This method tries to autodetect that radix given a string - * @update gess 10/01/98 - * @return 10,16,or 0 (meaning I don't know) - */ -PRUint32 nsString::DetermineRadix(void) { - PRUint32 result=kRadixUnknown; - if(0=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=aString.mStr){ - theChar=*cp; - if((theChar>='0') && (theChar<='9')){ - theDigit=theChar-'0'; - } - else if((theChar>='A') && (theChar<='F')) { - if(10==aRadix){ - *anErrorCode=NS_ERROR_ILLEGAL_VALUE; - result=0; - break; - } - theDigit=(theChar-'A')+10; - } - else if((theChar>='a') && (theChar<='f')) { - if(10==aRadix){ - *anErrorCode=NS_ERROR_ILLEGAL_VALUE; - result=0; - break; - } - theDigit=(theChar-'a')+10; - } - else if('-'==theChar) { - result=-result; - break; - } - else if(('+'==theChar) || (' '==theChar) || ('X'==theChar) || ('x'==theChar)) { //stop in a good state if you see this... - break; - } - else { - //we've encountered a char that's not a legal number or sign - *anErrorCode=NS_ERROR_ILLEGAL_VALUE; - result=0; - break; - } - - result+=theDigit*theMult; - theMult*=aRadix; - } - - return result; -} - - -/** - * Call this method to extract the rightmost numeric value from the given - * 1-byte input string, and simultaneously determine the radix. - * NOTE: This method mandates that the string is well formed. - * Leading and trailing gunk should be removed, and upper-cased. - * @update gess 10/01/98 - * @param anInputString contains orig string - * @param anOutString contains numeric portion copy of input string - * @param aRadix (an out parm) tells the caller what base we think the string is in. - * @return non-zero error code if this string is non-numeric - */ -static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) { - - 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... - - char* to=(char*)cp; - const char* endcp=cp+aString.mLength; - PRBool done=PR_FALSE; - - while(!done){ - switch(*cp) { - 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==endcp); - break; - } //switch - } - - while(cp=theChar) { - aRadix=16; - *to++=theChar; - } - else if('X'==theChar) { - if('-'==aString.mStr[0]) - to=&aString.mStr[1]; - else to=aString.mStr; - aRadix=16; - } - else if('a'<=theChar) { - if('f'>=theChar) { - aRadix=16; - *to++='A'+(theChar-'a'); - } - else if('x'==theChar) { - if('-'==aString.mStr[0]) - to=&aString.mStr[1]; - else to=aString.mStr; - aRadix=16; - } - } - else break; //bad char - } - else if((theChar>='0') && (theChar<='9')) { - *to++=theChar; - } - else if('-'==theChar) { - *to++=theChar; - } - else if(('#'!=theChar) && ('+'!=theChar)){ - break; //terminate on invalid char! - } - cp++; - } - - aString.Truncate(to-aString.mStr); - result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; - } - return result; -} - - -/** - * This method tries to autodetect that radix given a string - * @update gess 10/01/98 - * @return 10,16,or 0 (meaning I don't know) - */ -PRUint32 nsCString::DetermineRadix(void) { - PRUint32 result=kRadixUnknown; - if(0=aString.mStr){ - char theChar=*cp; - if((theChar>='0') && (theChar<='9')){ - theDigit=theChar-'0'; - } - else if((theChar>='A') && (theChar<='F')) { - if(10==aRadix){ - *anErrorCode=NS_ERROR_ILLEGAL_VALUE; - result=0; - break; - } - theDigit=(theChar-'A')+10; - } - else if('-'==theChar) { - result=-result; - break; - } - else if(('+'==theChar) || (' '==theChar)) { //stop in a good state if you see this... - break; - } - else { - //we've encountered a char that's not a legal number or sign - *anErrorCode=NS_ERROR_ILLEGAL_VALUE; - result=0; - break; - } - - result+=theDigit*theMult; - theMult*=aRadix; - } - return result; -} - -/** - * Call this method to extract the rightmost numeric value from the given - * 1-byte input string, and simultaneously determine the radix. - * NOTE: This method mandates that the string is well formed. - * Leading and trailing gunk should be removed, and the case upper. - * @update gess 10/01/98 - * @param anInputString contains orig string - * @param anOutString contains numeric portion copy of input string - * @param aRadix (an out parm) tells the caller what base we think the string is in. - * @return non-zero error code if this string is non-numeric - */ -static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) { - - 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... - - char* to=(char*)cp; - const char* endcp=cp+aString.mLength; - PRBool done=PR_FALSE; - - while(!done){ - switch(*cp) { - 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==endcp); - break; - } //switch - } - - while(cp=theChar) { - aRadix=16; - *to++=theChar; - } - else if('X'==theChar) { - if('-'==aString.mStr[0]) - to=&aString.mStr[1]; - else to=aString.mStr; - aRadix=16; - } - else if('a'<=theChar) { - if('f'>=theChar) { - aRadix=16; - *to++='A'+(theChar-'a'); - } - else if('x'==theChar) { - if('-'==aString.mStr[0]) - to=&aString.mStr[1]; - else to=aString.mStr; - aRadix=16; - } - } - else break; //bad char - } - else if((theChar>='0') && (theChar<='9')) { - *to++=theChar; - } - else if('-'==theChar) { - *to++=theChar; - } - else if(('#'!=theChar) && ('+'!=theChar)){ - break; //terminate on invalid char! - } - cp++; - } - - aString.Truncate(to-aString.mStr); - result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; - } - return result; -} - - -/** - * This method tries to autodetect that radix given a string - * @update gess 10/01/98 - * @return 10,16,or 0 (meaning I don't know) - */ -PRUint32 nsString::DetermineRadix(void) { - PRUint32 result=kRadixUnknown; - if(0