changed ToInteger() so that it returns an error properly

This commit is contained in:
rickg%netscape.com 1998-11-24 02:38:21 +00:00
Родитель 056674d506
Коммит 7755d427f4
4 изменённых файлов: 20 добавлений и 8 удалений

Просмотреть файл

@ -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;
}