Reinstated backed-out changes.

This commit is contained in:
mccabe 1998-06-03 06:08:21 +00:00
Родитель 0250534026
Коммит ff3a76fcf6
1 изменённых файлов: 12 добавлений и 7 удалений

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

@ -97,7 +97,7 @@ num_parseFloat(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
return JS_TRUE; return JS_TRUE;
} }
/* See ECMA 15.1.2.2 */ /* See ECMA 15.1.2.2. */
static JSBool static JSBool
num_parseInt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) num_parseInt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{ {
@ -105,7 +105,8 @@ num_parseInt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
jsint radix; jsint radix;
const jschar *chars, *start; const jschar *chars, *start;
jsdouble sum; jsdouble sum;
intN negative, digit, newDigit; JSBool negative;
uintN digit, newDigit;
jschar c; jschar c;
jschar digitMax = '9'; jschar digitMax = '9';
jschar lowerCaseBound = 'a'; jschar lowerCaseBound = 'a';
@ -115,7 +116,12 @@ num_parseInt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
if (!str) if (!str)
return JS_FALSE; return JS_FALSE;
chars = str->chars; chars = str->chars;
while (JS_ISSPACE(*chars) && *chars != 0)
/* This assumes that the char strings are null-terminated - JS_ISSPACE will
* always evaluate to false at the end of a string containing only
* whitespace.
*/
while (JS_ISSPACE(*chars))
chars++; chars++;
if ((negative = (*chars == '-')) != 0 || *chars == '+') if ((negative = (*chars == '-')) != 0 || *chars == '+')
@ -143,10 +149,9 @@ num_parseInt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
/* No radix supplied, or some radix that evaluated to 0. */ /* No radix supplied, or some radix that evaluated to 0. */
if (*chars == '0') { if (*chars == '0') {
/* It's either hex or octal; only increment char if str isn't '0' */ /* It's either hex or octal; only increment char if str isn't '0' */
if ((*(chars + 1) != 0) && if (*(chars + 1) == 'X' || *(chars + 1) == 'x') /* Hex */
(*(++chars) == 'X' || *chars == 'x')) /* Hex */
{ {
chars++; chars += 2;
radix = 16; radix = 16;
} else { /* Octal */ } else { /* Octal */
radix = 8; radix = 8;
@ -176,7 +181,7 @@ num_parseInt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
} }
digit = 0; /* how many digits have we seen? (if radix == 10) */ digit = 0; /* how many digits have we seen? (if radix == 10) */
sum = 0; sum = 0;
while ((c = *chars) != 0) { while ((c = *chars) != 0) { /* 0 is never a valid character. */
if ('0' <= c && c <= digitMax) if ('0' <= c && c <= digitMax)
newDigit = c - '0'; newDigit = c - '0';
else if ('a' <= c && c < lowerCaseBound) else if ('a' <= c && c < lowerCaseBound)