From 9cc8c710fd6d0424e672982c8df7ea2bfe5b2321 Mon Sep 17 00:00:00 2001 From: "rickg%netscape.com" Date: Thu, 17 Jun 1999 07:24:13 +0000 Subject: [PATCH] approved update git-svn-id: svn://10.0.0.236/trunk@35783 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/string/obsolete/nsString2.cpp | 57 +++++++-------------- mozilla/string/obsolete/nsString2.h | 14 ++++- mozilla/xpcom/ds/nsString2.cpp | 57 +++++++-------------- mozilla/xpcom/ds/nsString2.h | 14 ++++- mozilla/xpcom/string/obsolete/nsString2.cpp | 57 +++++++-------------- mozilla/xpcom/string/obsolete/nsString2.h | 14 ++++- 6 files changed, 90 insertions(+), 123 deletions(-) diff --git a/mozilla/string/obsolete/nsString2.cpp b/mozilla/string/obsolete/nsString2.cpp index 12fbce19122..7e75d055208 100644 --- a/mozilla/string/obsolete/nsString2.cpp +++ b/mozilla/string/obsolete/nsString2.cpp @@ -688,15 +688,6 @@ PRInt32 _ToInteger(nsString2& aString,PRInt32* anErrorCode,PRUint32 aRadix) { else if(('+'==theChar) || (' '==theChar)) { //stop in a good state if you see this... break; } -/* The following block can be replaced with the next block - else if(('X'==theChar) || ('#'==theChar)) { - if(10==aRadix) { - *anErrorCode=NS_ERROR_ILLEGAL_VALUE; - result=0; - } - break; - } ----cut above here...*/ else { //we've encountered a char that's not a legal number or sign *anErrorCode=NS_ERROR_ILLEGAL_VALUE; @@ -729,11 +720,13 @@ PRInt32 GetNumericSubstring(nsString2& aString,PRUint32& aRadix) { PRInt32 decPt=aString.FindChar(aString,'.',PR_TRUE,0); char* cp = (kNotFound==decPt) ? aString.mStr + aString.mLength-1 : aString.mStr+decPt-1; - aRadix=10; //assume for starters... + aRadix=kRadixUnknown; //assume for starters... // Skip trailing non-numeric... while (cp >= aString.mStr) { if((*cp>='0') && (*cp<='9')){ + if(kRadixUnknown==aRadix) + aRadix=kRadix10; break; } else if((*cp>='A') && (*cp<='F')) { @@ -761,7 +754,7 @@ PRInt32 GetNumericSubstring(nsString2& aString,PRUint32& aRadix) { } else { if(('#'==(*cp)) || ('X'==(*cp))) - aRadix=16; + aRadix=kRadix16; cp++; //move back by one break; } @@ -773,41 +766,23 @@ PRInt32 GetNumericSubstring(nsString2& aString,PRUint32& aRadix) { return result; } + /** - * Perform numeric string to int conversion with given radix. + * This method tries to autodetect that radix given a string * @update gess 10/01/98 - * @param aErrorCode will contain error if one occurs - * @param aRadix tells us what base to expect the string in. - * @return int rep of string value + * @return 10,16,or 0 (meaning I don't know) */ -PRInt32 nsString2::ToInteger(PRInt32* anErrorCode) const { - - /******************************************************************************** - If you called this version, it's because you don't know which radix your - string is stored in (hex, dec, etc.). - This method will attempt to figure that out for you, and then call - toInteger(err,radix). - NOTE: If you know your string is in a given radix, then it's better to - call toInteger(err,radix) directly, because there are cases where - this method cannot make the correct determination. For example, - a string that contains "123" can not be differentiated (hex vs. dec). - ********************************************************************************/ - - //copy chars to local buffer -- step down from 2 bytes to 1 if necessary... - PRInt32 result=0; +PRUint32 nsString2::DetermineRadix(void) { + PRUint32 result=kRadixUnknown; if(0= aString.mStr) { if((*cp>='0') && (*cp<='9')){ + if(kRadixUnknown==aRadix) + aRadix=kRadix10; break; } else if((*cp>='A') && (*cp<='F')) { @@ -761,7 +754,7 @@ PRInt32 GetNumericSubstring(nsString2& aString,PRUint32& aRadix) { } else { if(('#'==(*cp)) || ('X'==(*cp))) - aRadix=16; + aRadix=kRadix16; cp++; //move back by one break; } @@ -773,41 +766,23 @@ PRInt32 GetNumericSubstring(nsString2& aString,PRUint32& aRadix) { return result; } + /** - * Perform numeric string to int conversion with given radix. + * This method tries to autodetect that radix given a string * @update gess 10/01/98 - * @param aErrorCode will contain error if one occurs - * @param aRadix tells us what base to expect the string in. - * @return int rep of string value + * @return 10,16,or 0 (meaning I don't know) */ -PRInt32 nsString2::ToInteger(PRInt32* anErrorCode) const { - - /******************************************************************************** - If you called this version, it's because you don't know which radix your - string is stored in (hex, dec, etc.). - This method will attempt to figure that out for you, and then call - toInteger(err,radix). - NOTE: If you know your string is in a given radix, then it's better to - call toInteger(err,radix) directly, because there are cases where - this method cannot make the correct determination. For example, - a string that contains "123" can not be differentiated (hex vs. dec). - ********************************************************************************/ - - //copy chars to local buffer -- step down from 2 bytes to 1 if necessary... - PRInt32 result=0; +PRUint32 nsString2::DetermineRadix(void) { + PRUint32 result=kRadixUnknown; if(0= aString.mStr) { if((*cp>='0') && (*cp<='9')){ + if(kRadixUnknown==aRadix) + aRadix=kRadix10; break; } else if((*cp>='A') && (*cp<='F')) { @@ -761,7 +754,7 @@ PRInt32 GetNumericSubstring(nsString2& aString,PRUint32& aRadix) { } else { if(('#'==(*cp)) || ('X'==(*cp))) - aRadix=16; + aRadix=kRadix16; cp++; //move back by one break; } @@ -773,41 +766,23 @@ PRInt32 GetNumericSubstring(nsString2& aString,PRUint32& aRadix) { return result; } + /** - * Perform numeric string to int conversion with given radix. + * This method tries to autodetect that radix given a string * @update gess 10/01/98 - * @param aErrorCode will contain error if one occurs - * @param aRadix tells us what base to expect the string in. - * @return int rep of string value + * @return 10,16,or 0 (meaning I don't know) */ -PRInt32 nsString2::ToInteger(PRInt32* anErrorCode) const { - - /******************************************************************************** - If you called this version, it's because you don't know which radix your - string is stored in (hex, dec, etc.). - This method will attempt to figure that out for you, and then call - toInteger(err,radix). - NOTE: If you know your string is in a given radix, then it's better to - call toInteger(err,radix) directly, because there are cases where - this method cannot make the correct determination. For example, - a string that contains "123" can not be differentiated (hex vs. dec). - ********************************************************************************/ - - //copy chars to local buffer -- step down from 2 bytes to 1 if necessary... - PRInt32 result=0; +PRUint32 nsString2::DetermineRadix(void) { + PRUint32 result=kRadixUnknown; if(0