Changeset: 4b086f7cc399 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=4b086f7cc399
Modified Files:
clients/mapilib/mapi.c
clients/odbc/driver/ODBCConvert.c
common/utils/msabaoth.c
gdk/gdk_atoms.c
monetdb5/mal/mal_authorize.c
monetdb5/mal/mal_exception.c
monetdb5/mal/mal_parser.c
monetdb5/modules/atoms/blob.c
monetdb5/modules/atoms/color.c
monetdb5/modules/atoms/json.c
monetdb5/modules/atoms/url.c
monetdb5/modules/atoms/uuid.c
monetdb5/modules/mal/pcre.c
monetdb5/modules/mal/txtsim.c
sql/backends/monet5/sql_assert.c
sql/backends/monet5/sql_result.c
sql/server/sql_decimal.c
sql/server/sql_parser.y
tools/merovingian/utils/database.c
tools/merovingian/utils/properties.c
tools/merovingian/utils/utils.c
Branch: default
Log Message:
Use isdigit and isxdigit where we can.
Note these two functions are locale-independent.
diffs (truncated from 582 to 300 lines):
diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -1598,15 +1598,15 @@ add_error(struct MapiResultSet *result,
size_t size = result->errorstr ? strlen(result->errorstr) : 0;
if (strlen(error) > 6 && error[5] == '!' &&
- ((error[0] >= '0' && error[0] <= '9') ||
+ (isdigit((unsigned char) error[0]) ||
(error[0] >= 'A' && error[0] <= 'Z')) &&
- ((error[1] >= '0' && error[1] <= '9') ||
+ (isdigit((unsigned char) error[1]) ||
(error[1] >= 'A' && error[1] <= 'Z')) &&
- ((error[2] >= '0' && error[2] <= '9') ||
+ (isdigit((unsigned char) error[2]) ||
(error[2] >= 'A' && error[2] <= 'Z')) &&
- ((error[3] >= '0' && error[3] <= '9') ||
+ (isdigit((unsigned char) error[3]) ||
(error[3] >= 'A' && error[3] <= 'Z')) &&
- ((error[4] >= '0' && error[4] <= '9') ||
+ (isdigit((unsigned char) error[4]) ||
(error[4] >= 'A' && error[4] <= 'Z'))) {
if (result->errorstr == NULL) {
/* remeber SQLSTATE for first error */
diff --git a/clients/odbc/driver/ODBCConvert.c
b/clients/odbc/driver/ODBCConvert.c
--- a/clients/odbc/driver/ODBCConvert.c
+++ b/clients/odbc/driver/ODBCConvert.c
@@ -88,7 +88,7 @@ parseint(const char *data, bignum_t *nva
while (*data && *data != 'e' && *data != 'E' && !space(*data)) {
if (*data == '.')
fraction = 1;
- else if ('0' <= *data && *data <= '9') {
+ else if (isdigit((unsigned char) *data)) {
if (overflow ||
nval->val > MAXBIGNUM10 ||
(nval->val == MAXBIGNUM10 &&
@@ -273,7 +273,7 @@ parsetime(const char *data, TIME_STRUCT
data += n;
n = 1; /* tentative return value */
if (*data == '.') {
- while (*++data && '0' <= *data && *data <= '9')
+ while (*++data && isdigit((unsigned char) *data))
;
n = 2; /* indicate loss of precision */
}
@@ -324,7 +324,7 @@ parsetimestamp(const char *data, TIMESTA
data += n;
n = 1000000000;
if (*data == '.') {
- while (*++data && '0' <= *data && *data <= '9') {
+ while (*++data && isdigit((unsigned char) *data)) {
n /= 10;
tsval->fraction += (*data - '0') * n;
}
@@ -800,7 +800,7 @@ parsesecondintervalstring(char **svalp,
sval++;
slen--;
secondprecision = 0;
- while ('0' <= *sval && *sval <= '9') {
+ while (isdigit((unsigned char) *sval)) {
if (secondprecision < 9) {
secondprecision++;
ival->intval.day_second.fraction *= 10;
@@ -1309,7 +1309,7 @@ ODBCFetch(ODBCStmt *stmt,
return SQL_NO_DATA;
}
for (k = 0; k < datalen; k++) {
- if ('0' <= data[k] && data[k] <= '9')
+ if (isdigit((unsigned char) data[k]))
n = data[k] - '0';
else if ('A' <= data[k] && data[k] <= 'F')
n = data[k] - 'A' + 10;
@@ -2765,7 +2765,7 @@ ODBCFetch(ODBCStmt *stmt,
}
data++;
}
- if ('0' <= *data && *data <= '9')
+ if (isdigit((unsigned char) *data))
((unsigned char *) ptr)[i] = *data - '0';
else if ('a' <= *data && *data <= 'f')
((unsigned char *) ptr)[i] = *data - 'a' + 10;
@@ -2779,7 +2779,7 @@ ODBCFetch(ODBCStmt *stmt,
}
((unsigned char *) ptr)[i] <<= 4;
data++;
- if ('0' <= *data && *data <= '9')
+ if (isdigit((unsigned char) *data))
((unsigned char *) ptr)[i] |= *data - '0';
else if ('a' <= *data && *data <= 'f')
((unsigned char *) ptr)[i] |= *data - 'a' + 10;
diff --git a/common/utils/msabaoth.c b/common/utils/msabaoth.c
--- a/common/utils/msabaoth.c
+++ b/common/utils/msabaoth.c
@@ -28,6 +28,7 @@
#include <time.h>
#include <string.h> /* for getting error messages */
#include <stddef.h>
+#include <ctype.h>
#include "msabaoth.h"
#include "mutils.h"
@@ -106,7 +107,7 @@ msab_isuuid(const char *restrict s)
return 0;
/* only hexadecimals and hypens */
while (*s) {
- if (!('a' <= *s && *s <= 'f') && !('0' <= *s && *s <= '9')) {
+ if (!isxdigit((unsigned char) *s)) {
if (*s == '-')
hyphens++;
else
diff --git a/gdk/gdk_atoms.c b/gdk/gdk_atoms.c
--- a/gdk/gdk_atoms.c
+++ b/gdk/gdk_atoms.c
@@ -408,7 +408,7 @@ TYPE##ToStr(char **dst, size_t *len, con
#define num08(x) ((x) >= '0' && (x) <= '7')
#define num10(x) GDKisdigit(x)
-#define num16(x) (GDKisdigit(x) || ((x) >= 'a' && (x) <= 'f') || ((x)
>= 'A' && (x) <= 'F'))
+#define num16(x) isxdigit((unsigned char) (x))
#define base10(x) ((x) - '0')
#define base08(x) ((x) - '0')
#define base16(x) (((x) >= 'a' && (x) <= 'f') ? ((x) - 'a' + 10) : ((x)
>= 'A' && (x) <= 'F') ? ((x) - 'A' + 10) : (x) - '0')
diff --git a/monetdb5/mal/mal_authorize.c b/monetdb5/mal/mal_authorize.c
--- a/monetdb5/mal/mal_authorize.c
+++ b/monetdb5/mal/mal_authorize.c
@@ -951,7 +951,7 @@ AUTHverifyPassword(const char *passwd)
}
len++; // required in case all the checks above are false
while (*p != '\0') {
- if (!((*p >= 'a' && *p <= 'z') || (*p >= '0' && *p <= '9')))
+ if (!((*p >= 'a' && *p <= 'z') || isdigit((unsigned char) *p)))
throw(MAL, "verifyPassword",
"password does contain invalid
characters, is it a"
"lowercase hex representation of a
hash?");
diff --git a/monetdb5/mal/mal_exception.c b/monetdb5/mal/mal_exception.c
--- a/monetdb5/mal/mal_exception.c
+++ b/monetdb5/mal/mal_exception.c
@@ -361,15 +361,15 @@ getExceptionMessage(const char *exceptio
char *msg = getExceptionMessageAndState(exception);
if (strlen(msg) > 6 && msg[5] == '!' &&
- ((msg[0] >= '0' && msg[0] <= '9') ||
+ (isdigit((unsigned char) msg[0]) ||
(msg[0] >= 'A' && msg[0] <= 'Z')) &&
- ((msg[1] >= '0' && msg[1] <= '9') ||
+ (isdigit((unsigned char) msg[1]) ||
(msg[1] >= 'A' && msg[1] <= 'Z')) &&
- ((msg[2] >= '0' && msg[2] <= '9') ||
+ (isdigit((unsigned char) msg[2]) ||
(msg[2] >= 'A' && msg[2] <= 'Z')) &&
- ((msg[3] >= '0' && msg[3] <= '9') ||
+ (isdigit((unsigned char) msg[3]) ||
(msg[3] >= 'A' && msg[3] <= 'Z')) &&
- ((msg[4] >= '0' && msg[4] <= '9') ||
+ (isdigit((unsigned char) msg[4]) ||
(msg[4] >= 'A' && msg[4] <= 'Z')))
msg += 6;
return msg;
diff --git a/monetdb5/mal/mal_parser.c b/monetdb5/mal/mal_parser.c
--- a/monetdb5/mal/mal_parser.c
+++ b/monetdb5/mal/mal_parser.c
@@ -438,10 +438,7 @@ cstToken(Client cntxt, ValPtr cst)
case '1': case '2': case '3': case '4': case '5':
case '6': case '7': case '8': case '9':
if (hex) {
- while (isalnum((unsigned char) *s)) {
- if (!((tolower(*s) >= 'a' && tolower(*s) <= 'f')
- || isdigit((unsigned char) *s)))
- break;
+ while (isxdigit((unsigned char) *s)) {
i++;
s++;
}
diff --git a/monetdb5/modules/atoms/blob.c b/monetdb5/modules/atoms/blob.c
--- a/monetdb5/modules/atoms/blob.c
+++ b/monetdb5/modules/atoms/blob.c
@@ -312,7 +312,7 @@ BLOBfromstr(const char *instr, size_t *l
if (*s == ' ')
s++;
- if (*s >= '0' && *s <= '9') {
+ if (isdigit((unsigned char) *s)) {
res = *s - '0';
} else if (*s >= 'A' && *s <= 'F') {
res = 10 + *s - 'A';
@@ -323,7 +323,7 @@ BLOBfromstr(const char *instr, size_t *l
}
s++;
res <<= 4;
- if (*s >= '0' && *s <= '9') {
+ if (isdigit((unsigned char) *s)) {
res += *s - '0';
} else if (*s >= 'A' && *s <= 'F') {
res += 10 + *s - 'A';
@@ -470,7 +470,7 @@ SQLBLOBfromstr(const char *instr, size_t
for (i = 0; i < nitems; ++i) {
char res = 0;
- if (*s >= '0' && *s <= '9') {
+ if (isdigit((unsigned char) *s)) {
res = *s - '0';
} else if (*s >= 'A' && *s <= 'F') {
res = 10 + *s - 'A';
@@ -482,7 +482,7 @@ SQLBLOBfromstr(const char *instr, size_t
}
s++;
res <<= 4;
- if (*s >= '0' && *s <= '9') {
+ if (isdigit((unsigned char) *s)) {
res += *s - '0';
} else if (*s >= 'A' && *s <= 'F') {
res += 10 + *s - 'A';
diff --git a/monetdb5/modules/atoms/color.c b/monetdb5/modules/atoms/color.c
--- a/monetdb5/modules/atoms/color.c
+++ b/monetdb5/modules/atoms/color.c
@@ -45,13 +45,13 @@ CLRhextoint(char h, char l)
{
int r = 0;
- if (h >= '0' && h <= '9')
+ if (isdigit((unsigned char) h))
r = 16 * (int) (h - '0');
if (h >= 'a' && h <= 'f')
r = 16 * (int) (10 + h - 'a');
if (h >= 'A' && h <= 'F')
r = 16 * (int) (10 + h - 'A');
- if (l >= '0' && l <= '9')
+ if (isdigit((unsigned char) l))
r += (int) (l - '0');
if (l >= 'a' && l <= 'f')
r += (int) (10 + l - 'a');
diff --git a/monetdb5/modules/atoms/json.c b/monetdb5/modules/atoms/json.c
--- a/monetdb5/modules/atoms/json.c
+++ b/monetdb5/modules/atoms/json.c
@@ -30,9 +30,7 @@
#define hex(J)
\
do {
\
- if ((*(J) >='0' && *(J) <='9') ||
\
- (*(J) >='a' && *(J) <='f') ||
\
- (*(J) >='A' && *(J) <='F'))
\
+ if (isxdigit((unsigned char) *(J)))
\
(J)++;
\
else
\
throw(MAL, "json.parser", "illegal escape char");
\
@@ -462,7 +460,7 @@ JSONcompile(char *expr, pattern terms[])
s++;
skipblancs(s);
if (*s != '*') {
- if (*s >= '0' && *s <= '9') {
+ if (isdigit((unsigned char) *s)) {
terms[t].index = atoi(s);
terms[t].first = terms[t].last =
atoi(s);
} else
@@ -744,12 +742,12 @@ JSONnumberParser(const char *j, const ch
if (*j == '-')
j++;
skipblancs(j);
- if (*j < '0' || *j > '9') {
+ if (!isdigit((unsigned char) *j)) {
*next = j;
throw(MAL, "json.parser", "Number expected");
}
for (; *j; j++)
- if (*j < '0' || *j > '9')
+ if (!isdigit((unsigned char) *j))
break;
backup = j;
skipblancs(j);
@@ -757,7 +755,7 @@ JSONnumberParser(const char *j, const ch
j++;
skipblancs(j);
for (; *j; j++)
- if (*j < '0' || *j > '9')
+ if (!isdigit((unsigned char) *j))
break;
backup = j;
} else
@@ -770,7 +768,7 @@ JSONnumberParser(const char *j, const ch
j++;
skipblancs(j);
for (; *j; j++)
- if (*j < '0' || *j > '9')
+ if (!isdigit((unsigned char) *j))
break;
} else
j = backup;
@@ -939,7 +937,7 @@ JSONtoken(JSON *jt, const char *j, const
jt->error = createException(MAL, "json.parser", "JSON syntax
error: False expected");
return idx;
default:
- if (*j == '-' || (*j >= '0' && *j <= '9')) {
+ if (*j == '-' || isdigit((unsigned char) *j)) {
jt->elm[idx].value = j;
msg = JSONnumberParser(j, next);
if (msg)
diff --git a/monetdb5/modules/atoms/url.c b/monetdb5/modules/atoms/url.c
--- a/monetdb5/modules/atoms/url.c
+++ b/monetdb5/modules/atoms/url.c
@@ -60,7 +60,7 @@ skip_scheme(const char *uri)
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list