From 7ddf575be5cfb146d586ce30f7cc01a162a2e9c9 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Tue, 3 Dec 2002 18:23:17 +0000 Subject: Fixed to not get false positives when the token is shorter than the actual 2002-12-03 Jeffrey Stedfast * broken-date-parser.c (get_tzone): Fixed to not get false positives when the token is shorter than the actual timezone string (but matches the first little bit of it). (datetok): Modified to properly handle when the first char of a token is a special char (such as a '-') that is also used as a token delimiter. svn path=/trunk/; revision=18996 --- camel/ChangeLog | 9 +++++++++ camel/broken-date-parser.c | 37 +++++++++++++++++++++++++------------ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/camel/ChangeLog b/camel/ChangeLog index 78386adf70..e9524dad1b 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,12 @@ +2002-12-03 Jeffrey Stedfast + + * broken-date-parser.c (get_tzone): Fixed to not get false + positives when the token is shorter than the actual timezone + string (but matches the first little bit of it). + (datetok): Modified to properly handle when the first char of a + token is a special char (such as a '-') that is also used as a + token delimiter. + 2002-11-21 Jeffrey Stedfast * camel-tcp-stream-ssl.c (stream_read): Use the new diff --git a/camel/broken-date-parser.c b/camel/broken-date-parser.c index 238665cb93..f6e697896c 100644 --- a/camel/broken-date-parser.c +++ b/camel/broken-date-parser.c @@ -123,14 +123,18 @@ datetok (const char *date) start = date; while (*start) { /* kill leading whitespace */ - for ( ; *start && isspace ((int) *start); start++); + while (*start && isspace ((int) *start)) + start++; - mask = 0; + if (*start == '\0') + break; + + mask = datetok_table[*start]; /* find the end of this token */ - for (end = start; *end && !strchr ("-/,\t\r\n ", *end); end++) { - mask |= datetok_table[*end]; - } + end = start + 1; + while (*end && !strchr ("-/,\t\r\n ", *end)) + mask |= datetok_table[*end++]; if (end != start) { token = g_malloc (sizeof (struct _date_token)); @@ -277,22 +281,31 @@ get_time (const unsigned char *in, unsigned int inlen, int *hour, int *min, int static int get_tzone (struct _date_token **token) { - int i; + const unsigned char *inptr, *inend; + unsigned int inlen; + int i, t; for (i = 0; *token && i < 2; *token = (*token)->next, i++) { - const unsigned char *inptr = (*token)->start; - unsigned int inlen = (*token)->len; + inptr = (*token)->start; + inlen = (*token)->len; + inend = inptr + inlen; if (*inptr == '+' || *inptr == '-') { return decode_int (inptr, inlen); } else { - int t; - - if (*inptr == '(') + if (*inptr == '(') { inptr++; + if (*(inend - 1) == ')') + inlen -= 2; + else + inlen--; + } for (t = 0; t < 15; t++) { - unsigned int len = MIN (strlen (tz_offsets[t].name), inlen - 1); + unsigned int len = strlen (tz_offsets[t].name); + + if (len != inlen) + continue; if (!strncmp (inptr, tz_offsets[t].name, len)) return tz_offsets[t].offset; -- cgit v1.2.3