From: Derick Rethans Date: Mon, 25 Feb 2008 18:26:33 +0000 (+0000) Subject: - MFH: Added a few new separation specifiers. X-Git-Tag: BEFORE_NEW_PARAMETER_PARSE~745 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b8883b65b83bbd90c3ba27d8f87e9a983d664dce;p=php - MFH: Added a few new separation specifiers. - MFH: Added specifiers that can reset or default the y/m/d/h/i/s/tz values. - MFH: Fixed a problem with parsing timezones as part of a format. --- diff --git a/ext/date/lib/parse_date.c b/ext/date/lib/parse_date.c index d46a37f956..bd13182f3c 100644 --- a/ext/date/lib/parse_date.c +++ b/ext/date/lib/parse_date.c @@ -1,4 +1,4 @@ -/* Generated by re2c 0.12.1 on Sun Feb 17 19:15:32 2008 */ +/* Generated by re2c 0.12.1 on Sun Feb 24 19:24:27 2008 */ #line 1 "ext/date/lib/parse_date.re" /* +----------------------------------------------------------------------+ @@ -728,7 +728,7 @@ static long timelib_lookup_zone(char **ptr, int *dst, char **tz_abbr, int *found long value = 0; const timelib_tz_lookup_table *tp; - while (**ptr != '\0' && **ptr != ')') { + while (**ptr != '\0' && **ptr != ')' && **ptr != ' ') { ++*ptr; } end = *ptr; @@ -23095,6 +23095,39 @@ timelib_time *timelib_parse_from_format(char *format, char *string, int len, tim } break; + case ';': + case ':': + case '/': + case '.': + case ',': + case '-': + if (*ptr == *fptr) { + ++ptr; + } else { + add_pbf_error(s, "The separation symbol could not be found", string, begin); + } + break; + + case '!': // reset all fields to default + s->time->y = 1970; + s->time->m = 1; + s->time->d = 1; + s->time->h = s->time->i = s->time->s = 0; + s->time->f = 0.0; + s->time->tz_info = NULL; + break; // break intentionally not missing + + case '|': // reset all fields to default when not set + if (s->time->y == TIMELIB_UNSET ) s->time->y = 1970; + if (s->time->m == TIMELIB_UNSET ) s->time->m = 1; + if (s->time->d == TIMELIB_UNSET ) s->time->d = 1; + if (s->time->h == TIMELIB_UNSET ) s->time->h = 0; + if (s->time->i == TIMELIB_UNSET ) s->time->i = 0; + if (s->time->s == TIMELIB_UNSET ) s->time->s = 0; + if (s->time->f == TIMELIB_UNSET ) s->time->f = 0.0; + + break; // break intentionally not missing + case '?': // random char ++ptr; break; @@ -23118,6 +23151,20 @@ timelib_time *timelib_parse_from_format(char *format, char *string, int len, tim add_pbf_error(s, "Data missing", string, ptr); } + // clean up a bit + if (s->time->h != TIMELIB_UNSET || s->time->i != TIMELIB_UNSET || s->time->s != TIMELIB_UNSET) { + if (s->time->h == TIMELIB_UNSET ) { + s->time->h = 0; + } + if (s->time->i == TIMELIB_UNSET ) { + s->time->i = 0; + } + if (s->time->s == TIMELIB_UNSET ) { + s->time->s = 0; + } + } + + if (errors) { *errors = in.errors; } else { diff --git a/ext/date/lib/parse_date.re b/ext/date/lib/parse_date.re index 21f4fa9516..ccc8df6322 100644 --- a/ext/date/lib/parse_date.re +++ b/ext/date/lib/parse_date.re @@ -726,7 +726,7 @@ static long timelib_lookup_zone(char **ptr, int *dst, char **tz_abbr, int *found long value = 0; const timelib_tz_lookup_table *tp; - while (**ptr != '\0' && **ptr != ')') { + while (**ptr != '\0' && **ptr != ')' && **ptr != ' ') { ++*ptr; } end = *ptr; @@ -1867,6 +1867,39 @@ timelib_time *timelib_parse_from_format(char *format, char *string, int len, tim } break; + case ';': + case ':': + case '/': + case '.': + case ',': + case '-': + if (*ptr == *fptr) { + ++ptr; + } else { + add_pbf_error(s, "The separation symbol could not be found", string, begin); + } + break; + + case '!': // reset all fields to default + s->time->y = 1970; + s->time->m = 1; + s->time->d = 1; + s->time->h = s->time->i = s->time->s = 0; + s->time->f = 0.0; + s->time->tz_info = NULL; + break; // break intentionally not missing + + case '|': // reset all fields to default when not set + if (s->time->y == TIMELIB_UNSET ) s->time->y = 1970; + if (s->time->m == TIMELIB_UNSET ) s->time->m = 1; + if (s->time->d == TIMELIB_UNSET ) s->time->d = 1; + if (s->time->h == TIMELIB_UNSET ) s->time->h = 0; + if (s->time->i == TIMELIB_UNSET ) s->time->i = 0; + if (s->time->s == TIMELIB_UNSET ) s->time->s = 0; + if (s->time->f == TIMELIB_UNSET ) s->time->f = 0.0; + + break; // break intentionally not missing + case '?': // random char ++ptr; break; @@ -1890,6 +1923,20 @@ timelib_time *timelib_parse_from_format(char *format, char *string, int len, tim add_pbf_error(s, "Data missing", string, ptr); } + // clean up a bit + if (s->time->h != TIMELIB_UNSET || s->time->i != TIMELIB_UNSET || s->time->s != TIMELIB_UNSET) { + if (s->time->h == TIMELIB_UNSET ) { + s->time->h = 0; + } + if (s->time->i == TIMELIB_UNSET ) { + s->time->i = 0; + } + if (s->time->s == TIMELIB_UNSET ) { + s->time->s = 0; + } + } + + if (errors) { *errors = in.errors; } else {