Changeset: efe8110bd1d2 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/efe8110bd1d2
Modified Files:
        gdk/gdk_atoms.c
        gdk/gdk_time.c
Branch: default
Log Message:

Ignore spaces around values converted from strings.
This already happened for the "old" built-in types, now do it also for
date/time, uuid, blob.


diffs (139 lines):

diff --git a/gdk/gdk_atoms.c b/gdk/gdk_atoms.c
--- a/gdk/gdk_atoms.c
+++ b/gdk/gdk_atoms.c
@@ -1320,6 +1320,8 @@ UUIDfromString(const char *svalue, size_
                **retval = uuid_nil;
                return 1;
        }
+       while (GDKisspace(*s))
+               s++;
        /* we don't use uuid_parse since we accept UUIDs without hyphens */
        uuid u;
        for (int i = 0, j = 0; i < UUID_SIZE; i++) {
@@ -1350,6 +1352,8 @@ UUIDfromString(const char *svalue, size_
                s++;
                j++;
        }
+       while (GDKisspace(*s))
+               s++;
        if (*s != 0)
                goto bailout;
        **retval = u;
@@ -1601,12 +1605,7 @@ BLOBfromstr(const char *instr, size_t *l
        for (i = nitems = 0; instr[i]; i++) {
                if (xdigit[(unsigned char) instr[i]])
                        nitems++;
-               else if (instr[i] != ' ' &&
-                                instr[i] != '\n' &&
-                                instr[i] != '\t' &&
-                                instr[i] != '\r' &&
-                                instr[i] != '\f' &&
-                                instr[i] != '\v') {
+               else if (!GDKisspace(instr[i])) {
                        GDKerror("Illegal char in blob\n");
                        return -1;
                }
@@ -1642,7 +1641,7 @@ BLOBfromstr(const char *instr, size_t *l
                        } else if (*s >= 'a' && *s <= 'f') {
                                res = 10 + *s - 'a';
                        } else {
-                               assert(isspace((unsigned char) *s));
+                               assert(GDKisspace(*s));
                                s++;
                                continue;
                        }
@@ -1658,7 +1657,7 @@ BLOBfromstr(const char *instr, size_t *l
                        } else if (*s >= 'a' && *s <= 'f') {
                                res += 10 + *s - 'a';
                        } else {
-                               assert(isspace((unsigned char) *s));
+                               assert(GDKisspace(*s));
                                s++;
                                continue;
                        }
@@ -1668,6 +1667,8 @@ BLOBfromstr(const char *instr, size_t *l
 
                result->data[i] = res;
        }
+       while (GDKisspace(*s))
+               s++;
 
        return (ssize_t) (s - instr);
 }
diff --git a/gdk/gdk_time.c b/gdk/gdk_time.c
--- a/gdk/gdk_time.c
+++ b/gdk/gdk_time.c
@@ -652,7 +652,16 @@ date_fromstr(const char *buf, size_t *le
                if( *d == NULL)
                        return -1;
        }
-       return parse_date(buf, *d, external);
+       ssize_t n = 0;
+       while (buf[n] && GDKisspace(buf[n]))
+               n++;
+       ssize_t l = parse_date(buf + n, *d, external);
+       if (l < 0)
+               return l;
+       n += l;
+       while (buf[n] && GDKisspace(buf[n]))
+               n++;
+       return n;
 }
 
 static ssize_t
@@ -775,7 +784,16 @@ daytime_fromstr(const char *buf, size_t 
                if (*ret == NULL)
                        return -1;
        }
-       return parse_daytime(buf, *ret, external);
+       ssize_t n = 0;
+       while (buf[n] && GDKisspace(buf[n]))
+               n++;
+       ssize_t l = parse_daytime(buf + n, *ret, external);
+       if (l < 0)
+               return l;
+       n += l;
+       while (buf[n] && GDKisspace(buf[n]))
+               n++;
+       return n;
 }
 
 ssize_t
@@ -815,6 +833,8 @@ daytime_tz_fromstr(const char *buf, size
                val -= DAY_USEC;
        /* and return */
        **ret = val;
+       while (*s && GDKisspace(*s))
+               s++;
        return (ssize_t) (s - buf);
 }
 
@@ -900,7 +920,9 @@ timestamp_fromstr(const char *buf, size_
                if (*ret == NULL)
                        return -1;
        }
-       pos = parse_date(buf, &dt, external);
+       while (*s && GDKisspace(*s))
+               s++;
+       pos = parse_date(s, &dt, external);
        if (pos < 0)
                return pos;
        if (is_date_nil(dt)) {
@@ -947,6 +969,8 @@ timestamp_fromstr(const char *buf, size_
                }
                **ret = timestamp_add_usec(**ret, offset);
        }
+       while (*s && GDKisspace(*s))
+               s++;
        return (ssize_t) (s - buf);
 }
 
@@ -978,6 +1002,8 @@ timestamp_tz_fromstr(const char *buf, si
                s += pos;
        }
        **ret = timestamp_add_usec(**ret, offset);
+       while (*s && GDKisspace(*s))
+               s++;
        return (ssize_t) (s - buf);
 }
 
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to