Fixed to not get false positives when the token is shorter than the actual
authorJeffrey Stedfast <fejj@ximian.com>
Tue, 3 Dec 2002 18:23:17 +0000 (18:23 +0000)
committerJeffrey Stedfast <fejj@src.gnome.org>
Tue, 3 Dec 2002 18:23:17 +0000 (18:23 +0000)
2002-12-03  Jeffrey Stedfast  <fejj@ximian.com>

* 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.

camel/ChangeLog
camel/broken-date-parser.c

index 78386ad..e9524da 100644 (file)
@@ -1,3 +1,12 @@
+2002-12-03  Jeffrey Stedfast  <fejj@ximian.com>
+
+       * 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  <fejj@ximian.com>
 
        * camel-tcp-stream-ssl.c (stream_read): Use the new
index 238665c..f6e6978 100644 (file)
@@ -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;