1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-18 10:35:55 +00:00

Make it works for non ASCII compatible encodings too.

The only assumption left is that 'A'..'Z' 'a'..'z' both are contiguous
This commit is contained in:
Andrey A. Chernov 2001-12-02 09:15:54 +00:00
parent 2985f5726b
commit 4bd71a3c89
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=87196
6 changed files with 42 additions and 42 deletions

View File

@ -58,7 +58,7 @@ strtoimax(nptr, endptr, base)
uintmax_t acc;
unsigned char c;
uintmax_t cutoff;
int neg, any, cutlim;
int neg, any, cutlim, n;
/*
* Skip white space and pick up leading +/- sign if any.
@ -113,19 +113,19 @@ strtoimax(nptr, endptr, base)
cutoff /= base;
for ( ; ; c = *s++) {
if (isxdigit(c))
c = digittoint(c);
else if (isascii(c) && isalpha(c))
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
n = digittoint(c);
else if (isalpha(c))
n = (char)c - (isupper(c) ? 'A' - 10 : 'a' - 10);
else
break;
if (c >= base)
if (n < 0 || n >= base)
break;
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
if (any < 0 || acc > cutoff || (acc == cutoff && n > cutlim))
any = -1;
else {
any = 1;
acc *= base;
acc += c;
acc += n;
}
}
if (any < 0) {

View File

@ -59,7 +59,7 @@ strtol(nptr, endptr, base)
unsigned long acc;
unsigned char c;
unsigned long cutoff;
int neg, any, cutlim;
int neg, any, cutlim, n;
/*
* Skip white space and pick up leading +/- sign if any.
@ -113,19 +113,19 @@ strtol(nptr, endptr, base)
cutoff /= base;
for ( ; ; c = *s++) {
if (isxdigit(c))
c = digittoint(c);
else if (isascii(c) && isalpha(c))
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
n = digittoint(c);
else if (isalpha(c))
n = (char)c - (isupper(c) ? 'A' - 10 : 'a' - 10);
else
break;
if (c >= base)
if (n < 0 || n >= base)
break;
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
if (any < 0 || acc > cutoff || (acc == cutoff && n > cutlim))
any = -1;
else {
any = 1;
acc *= base;
acc += c;
acc += n;
}
}
if (any < 0) {

View File

@ -58,7 +58,7 @@ strtoll(nptr, endptr, base)
unsigned long long acc;
unsigned char c;
unsigned long long cutoff;
int neg, any, cutlim;
int neg, any, cutlim, n;
/*
* Skip white space and pick up leading +/- sign if any.
@ -113,19 +113,19 @@ strtoll(nptr, endptr, base)
cutoff /= base;
for ( ; ; c = *s++) {
if (isxdigit(c))
c = digittoint(c);
else if (isascii(c) && isalpha(c))
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
n = digittoint(c);
else if (isalpha(c))
n = (char)c - (isupper(c) ? 'A' - 10 : 'a' - 10);
else
break;
if (c >= base)
if (n < 0 || n >= base)
break;
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
if (any < 0 || acc > cutoff || (acc == cutoff && n > cutlim))
any = -1;
else {
any = 1;
acc *= base;
acc += c;
acc += n;
}
}
if (any < 0) {

View File

@ -58,7 +58,7 @@ strtoul(nptr, endptr, base)
unsigned long acc;
unsigned char c;
unsigned long cutoff;
int neg, any, cutlim;
int neg, any, cutlim, n;
/*
* See strtol for comments as to the logic used.
@ -91,19 +91,19 @@ strtoul(nptr, endptr, base)
cutlim = ULONG_MAX % base;
for ( ; ; c = *s++) {
if (isxdigit(c))
c = digittoint(c);
else if (isascii(c) && isalpha(c))
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
n = digittoint(c);
else if (isalpha(c))
n = (char)c - (isupper(c) ? 'A' - 10 : 'a' - 10);
else
break;
if (c >= base)
if (n < 0 || n >= base)
break;
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
if (any < 0 || acc > cutoff || (acc == cutoff && n > cutlim))
any = -1;
else {
any = 1;
acc *= base;
acc += c;
acc += n;
}
}
if (any < 0) {

View File

@ -58,7 +58,7 @@ strtoull(nptr, endptr, base)
unsigned long long acc;
unsigned char c;
unsigned long long cutoff;
int neg, any, cutlim;
int neg, any, cutlim, n;
/*
* See strtoq for comments as to the logic used.
@ -91,19 +91,19 @@ strtoull(nptr, endptr, base)
cutlim = ULLONG_MAX % base;
for ( ; ; c = *s++) {
if (isxdigit(c))
c = digittoint(c);
else if (isascii(c) && isalpha(c))
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
n = digittoint(c);
else if (isalpha(c))
n = (char)c - (isupper(c) ? 'A' - 10 : 'a' - 10);
else
break;
if (c >= base)
if (n < 0 || n >= base)
break;
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
if (any < 0 || acc > cutoff || (acc == cutoff && n > cutlim))
any = -1;
else {
any = 1;
acc *= base;
acc += c;
acc += n;
}
}
if (any < 0) {

View File

@ -58,7 +58,7 @@ strtoumax(nptr, endptr, base)
uintmax_t acc;
unsigned char c;
uintmax_t cutoff;
int neg, any, cutlim;
int neg, any, cutlim, n;
/*
* See strtoimax for comments as to the logic used.
@ -91,19 +91,19 @@ strtoumax(nptr, endptr, base)
cutlim = UINTMAX_MAX % base;
for ( ; ; c = *s++) {
if (isxdigit(c))
c = digittoint(c);
else if (isascii(c) && isalpha(c))
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
n = digittoint(c);
else if (isalpha(c))
n = (char)c - (isupper(c) ? 'A' - 10 : 'a' - 10);
else
break;
if (c >= base)
if (n < 0 || n >= base)
break;
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
if (any < 0 || acc > cutoff || (acc == cutoff && n > cutlim))
any = -1;
else {
any = 1;
acc *= base;
acc += c;
acc += n;
}
}
if (any < 0) {