aboutsummaryrefslogtreecommitdiff
path: root/lib/strtoofft.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2007-08-04 20:47:59 +0000
committerDaniel Stenberg <daniel@haxx.se>2007-08-04 20:47:59 +0000
commit1926f4573d43f35f33b524d120e847ea819cc7c7 (patch)
tree9c19380b002d623c94747daee0edb941542451cc /lib/strtoofft.c
parent7fe65aaf5bda5f48eebcc3f694485b2bc6b49d6c (diff)
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.c27
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;