зеркало из https://github.com/mozilla/pjs.git
changed ToInteger() so that it returns an error properly
This commit is contained in:
Родитель
056674d506
Коммит
7755d427f4
|
@ -545,7 +545,7 @@ float nsString::ToFloat(PRInt32* aErrorCode) const
|
|||
* @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 int rep of string value; aErrorCode gets set too: NS_OK, NS_ERROR_ILLEGAL_VALUE
|
||||
*/
|
||||
PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const {
|
||||
PRInt32 result = 0;
|
||||
|
@ -555,6 +555,8 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const {
|
|||
PRInt32 theShift=0;
|
||||
PRInt32 theMult=1;
|
||||
|
||||
*aErrorCode = (0<mLength) ? NS_OK : NS_ERROR_ILLEGAL_VALUE;
|
||||
|
||||
// Skip trailing non-numeric...
|
||||
while (cp >= mStr) {
|
||||
theChar = *cp;
|
||||
|
@ -587,13 +589,14 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const {
|
|||
break;
|
||||
}
|
||||
else{
|
||||
*aErrorCode=NS_ERROR_ILLEGAL_VALUE;
|
||||
result=0;
|
||||
break;
|
||||
}
|
||||
result+=digit*theMult;
|
||||
theMult*=aRadix;
|
||||
}
|
||||
|
||||
*aErrorCode = NS_OK;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -545,7 +545,7 @@ float nsString::ToFloat(PRInt32* aErrorCode) const
|
|||
* @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 int rep of string value; aErrorCode gets set too: NS_OK, NS_ERROR_ILLEGAL_VALUE
|
||||
*/
|
||||
PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const {
|
||||
PRInt32 result = 0;
|
||||
|
@ -555,6 +555,8 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const {
|
|||
PRInt32 theShift=0;
|
||||
PRInt32 theMult=1;
|
||||
|
||||
*aErrorCode = (0<mLength) ? NS_OK : NS_ERROR_ILLEGAL_VALUE;
|
||||
|
||||
// Skip trailing non-numeric...
|
||||
while (cp >= mStr) {
|
||||
theChar = *cp;
|
||||
|
@ -587,13 +589,14 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const {
|
|||
break;
|
||||
}
|
||||
else{
|
||||
*aErrorCode=NS_ERROR_ILLEGAL_VALUE;
|
||||
result=0;
|
||||
break;
|
||||
}
|
||||
result+=digit*theMult;
|
||||
theMult*=aRadix;
|
||||
}
|
||||
|
||||
*aErrorCode = NS_OK;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -545,7 +545,7 @@ float nsString::ToFloat(PRInt32* aErrorCode) const
|
|||
* @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 int rep of string value; aErrorCode gets set too: NS_OK, NS_ERROR_ILLEGAL_VALUE
|
||||
*/
|
||||
PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const {
|
||||
PRInt32 result = 0;
|
||||
|
@ -555,6 +555,8 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const {
|
|||
PRInt32 theShift=0;
|
||||
PRInt32 theMult=1;
|
||||
|
||||
*aErrorCode = (0<mLength) ? NS_OK : NS_ERROR_ILLEGAL_VALUE;
|
||||
|
||||
// Skip trailing non-numeric...
|
||||
while (cp >= mStr) {
|
||||
theChar = *cp;
|
||||
|
@ -587,13 +589,14 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const {
|
|||
break;
|
||||
}
|
||||
else{
|
||||
*aErrorCode=NS_ERROR_ILLEGAL_VALUE;
|
||||
result=0;
|
||||
break;
|
||||
}
|
||||
result+=digit*theMult;
|
||||
theMult*=aRadix;
|
||||
}
|
||||
|
||||
*aErrorCode = NS_OK;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -545,7 +545,7 @@ float nsString::ToFloat(PRInt32* aErrorCode) const
|
|||
* @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 int rep of string value; aErrorCode gets set too: NS_OK, NS_ERROR_ILLEGAL_VALUE
|
||||
*/
|
||||
PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const {
|
||||
PRInt32 result = 0;
|
||||
|
@ -555,6 +555,8 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const {
|
|||
PRInt32 theShift=0;
|
||||
PRInt32 theMult=1;
|
||||
|
||||
*aErrorCode = (0<mLength) ? NS_OK : NS_ERROR_ILLEGAL_VALUE;
|
||||
|
||||
// Skip trailing non-numeric...
|
||||
while (cp >= mStr) {
|
||||
theChar = *cp;
|
||||
|
@ -587,13 +589,14 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const {
|
|||
break;
|
||||
}
|
||||
else{
|
||||
*aErrorCode=NS_ERROR_ILLEGAL_VALUE;
|
||||
result=0;
|
||||
break;
|
||||
}
|
||||
result+=digit*theMult;
|
||||
theMult*=aRadix;
|
||||
}
|
||||
|
||||
*aErrorCode = NS_OK;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче