diff options
author | Daniel Stenberg <daniel@haxx.se> | 2007-08-04 20:47:59 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2007-08-04 20:47:59 +0000 |
commit | 1926f4573d43f35f33b524d120e847ea819cc7c7 (patch) | |
tree | 9c19380b002d623c94747daee0edb941542451cc /lib/strtoofft.c | |
parent | 7fe65aaf5bda5f48eebcc3f694485b2bc6b49d6c (diff) | |
download | curl-1926f4573d43f35f33b524d120e847ea819cc7c7.tar.gz |
Patrick Monnerat fixed curl_easy_escape() and curlx_strtoll() to work on
non-ASCII systems.
Diffstat (limited to 'lib/strtoofft.c')
-rw-r--r-- | lib/strtoofft.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/strtoofft.c b/lib/strtoofft.c index 5314fa403..043ff4d9b 100644 --- a/lib/strtoofft.c +++ b/lib/strtoofft.c @@ -37,6 +37,18 @@ #include <ctype.h> #include <errno.h> +/* Range tests can be used for alphanum decoding if characters are consecutive, + like in ASCII. Else an array is scanned. Determine this condition now. */ + +#if ('9' - '0') != 9 || ('Z' - 'A') != 25 || ('z' - 'a') != 25 +#include <string.h> + +#define NO_RANGE_TEST + +static const char valchars[] = + "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; +#endif + static int get_char(char c, int base); /** @@ -145,6 +157,7 @@ curlx_strtoll(const char *nptr, char **endptr, int base) */ static int get_char(char c, int base) { +#ifndef NO_RANGE_TEST int value = -1; if (c <= '9' && c >= '0') { value = c - '0'; @@ -155,6 +168,20 @@ static int get_char(char c, int base) else if (c <= 'z' && c >= 'a') { value = c - 'a' + 10; } +#else + const char * cp; + int value; + + cp = memchr(valchars, c, 10 + 26 + 26); + + if (!cp) + return -1; + + value = cp - valchars; + + if (value >= 10 + 26) + value -= 26; /* Lowercase. */ +#endif if (value >= base) { value = -1; |