📄 parse_date.re
字号:
++*ptr; } return timelib_lookup_month(ptr);}static void timelib_eat_spaces(char **ptr){ while (**ptr == ' ' || **ptr == '\t') { ++*ptr; }}static const timelib_relunit* timelib_lookup_relunit(char **ptr){ char *word; char *begin = *ptr, *end; const timelib_relunit *tp, *value = NULL; while (**ptr != '\0' && **ptr != ' ' && **ptr != '\t') { ++*ptr; } end = *ptr; word = calloc(1, end - begin + 1); memcpy(word, begin, end - begin); for (tp = timelib_relunit_lookup; tp->name; tp++) { if (strcasecmp(word, tp->name) == 0) { value = tp; break; } } free(word); return value;}static void timelib_set_relative(char **ptr, timelib_sll amount, int behavior, Scanner *s){ const timelib_relunit* relunit; relunit = timelib_lookup_relunit(ptr); switch (relunit->unit) { case TIMELIB_SECOND: s->time->relative.s += amount * relunit->multiplier; break; case TIMELIB_MINUTE: s->time->relative.i += amount * relunit->multiplier; break; case TIMELIB_HOUR: s->time->relative.h += amount * relunit->multiplier; break; case TIMELIB_DAY: s->time->relative.d += amount * relunit->multiplier; break; case TIMELIB_MONTH: s->time->relative.m += amount * relunit->multiplier; break; case TIMELIB_YEAR: s->time->relative.y += amount * relunit->multiplier; break; case TIMELIB_WEEKDAY: TIMELIB_HAVE_WEEKDAY_RELATIVE(); TIMELIB_UNHAVE_TIME(); s->time->relative.d += (amount > 0 ? amount - 1 : amount) * 7; s->time->relative.weekday = relunit->multiplier; s->time->relative.weekday_behavior = behavior; break; case TIMELIB_SPECIAL: TIMELIB_HAVE_SPECIAL_RELATIVE(); TIMELIB_UNHAVE_TIME(); s->time->special.type = relunit->multiplier; s->time->special.amount = amount; }}const static timelib_tz_lookup_table* zone_search(const char *word, long gmtoffset, int isdst){ int first_found = 0; const timelib_tz_lookup_table *tp, *first_found_elem = NULL; const timelib_tz_lookup_table *fmp; if (strcasecmp("utc", word) == 0 || strcasecmp("gmt", word) == 0) { return timelib_timezone_utc; } for (tp = timelib_timezone_lookup; tp->name; tp++) { if (strcasecmp(word, tp->name) == 0) { if (!first_found) { first_found = 1; first_found_elem = tp; if (gmtoffset == -1) { return tp; } } if (tp->gmtoffset == gmtoffset) { return tp; } } } if (first_found) { return first_found_elem; } /* Still didn't find anything, let's find the zone solely based on * offset/isdst then */ for (fmp = timelib_timezone_fallbackmap; fmp->name; fmp++) { if ((fmp->gmtoffset * 3600) == gmtoffset && fmp->type == isdst) { return fmp; } } return NULL;}static long timelib_lookup_zone(char **ptr, int *dst, char **tz_abbr, int *found){ char *word; char *begin = *ptr, *end; long value = 0; const timelib_tz_lookup_table *tp; while (**ptr != '\0' && **ptr != ')') { ++*ptr; } end = *ptr; word = calloc(1, end - begin + 1); memcpy(word, begin, end - begin); if ((tp = zone_search(word, -1, 0))) { value = -tp->gmtoffset / 60; *dst = tp->type; value += tp->type * 60; *found = 1; } else { *found = 0; } *tz_abbr = word; return value;}static long timelib_get_zone(char **ptr, int *dst, timelib_time *t, int *tz_not_found, const timelib_tzdb *tzdb){ timelib_tzinfo *res; long retval = 0; *tz_not_found = 0; while (**ptr == ' ' || **ptr == '\t' || **ptr == '(') { ++*ptr; } if (**ptr == '+') { ++*ptr; t->is_localtime = 1; t->zone_type = TIMELIB_ZONETYPE_OFFSET; *tz_not_found = 0; t->dst = 0; retval = -1 * timelib_parse_tz_cor(ptr); } else if (**ptr == '-') { ++*ptr; t->is_localtime = 1; t->zone_type = TIMELIB_ZONETYPE_OFFSET; *tz_not_found = 0; t->dst = 0; retval = timelib_parse_tz_cor(ptr); } else { int found = 0; long offset; char *tz_abbr; t->is_localtime = 1; offset = timelib_lookup_zone(ptr, dst, &tz_abbr, &found); if (found) { t->zone_type = TIMELIB_ZONETYPE_ABBR; }#if 0 /* If we found a TimeZone identifier, use it */ if (tz_name) { t->tz_info = timelib_parse_tzfile(tz_name); t->zone_type = TIMELIB_ZONETYPE_ID; }#endif /* If we have a TimeZone identifier to start with, use it */ if (strstr(tz_abbr, "/")) { if ((res = timelib_parse_tzfile(tz_abbr, tzdb)) != NULL) { t->tz_info = res; t->zone_type = TIMELIB_ZONETYPE_ID; found++; } } if (found && t->zone_type != TIMELIB_ZONETYPE_ID) { timelib_time_tz_abbr_update(t, tz_abbr); } free(tz_abbr); *tz_not_found = (found == 0); retval = offset; } while (**ptr == ')') { ++*ptr; } return retval;}#define timelib_split_free(arg) { \ int i; \ for (i = 0; i < arg.c; i++) { \ free(arg.v[i]); \ } \ if (arg.v) { \ free(arg.v); \ } \}static int scan(Scanner *s){ uchar *cursor = s->cur; char *str, *ptr = NULL; std: s->tok = cursor; s->len = 0;/*!re2cany = [\000-\377];space = [ \t]+;frac = "."[0-9]+;ago = 'ago';hour24 = [01]?[0-9] | "2"[0-3];hour24lz = [01][0-9] | "2"[0-3];hour12 = "0"?[1-9] | "1"[0-2];minute = [0-5]?[0-9];minutelz = [0-5][0-9];second = minute | "60";secondlz = minutelz | "60";meridian = ([AaPp] "."? [Mm] "."?) [\000\t ];tz = "("? [A-Za-z]{1,6} ")"? | [A-Z][a-z]+([_/][A-Z][a-z]+)+;tzcorrection = [+-] hour24 ":"? minute?;daysuf = "st" | "nd" | "rd" | "th";month = "0"? [0-9] | "1"[0-2];day = ([0-2]?[0-9] | "3"[01]) daysuf?;year = [0-9]{1,4};year2 = [0-9]{2};year4 = [0-9]{4};dayofyear = "00"[1-9] | "0"[1-9][0-9] | [1-2][0-9][0-9] | "3"[0-5][0-9] | "36"[0-6];weekofyear = "0"[1-9] | [1-4][0-9] | "5"[0-3];monthlz = "0" [1-9] | "1" [0-2];daylz = "0" [1-9] | [1-2][0-9] | "3" [01];dayfull = 'sunday' | 'monday' | 'tuesday' | 'wednesday' | 'thursday' | 'friday' | 'saturday';dayabbr = 'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat' | 'sun';dayspecial = 'weekday' | 'weekdays';daytext = dayfull | dayabbr | dayspecial;monthfull = 'january' | 'february' | 'march' | 'april' | 'may' | 'june' | 'july' | 'august' | 'september' | 'october' | 'november' | 'december';monthabbr = 'jan' | 'feb' | 'mar' | 'apr' | 'may' | 'jun' | 'jul' | 'aug' | 'sep' | 'sept' | 'oct' | 'nov' | 'dec';monthroman = "I" | "II" | "III" | "IV" | "V" | "VI" | "VII" | "VIII" | "IX" | "X" | "XI" | "XII";monthtext = monthfull | monthabbr | monthroman;/* Time formats */timetiny12 = hour12 space? meridian;timeshort12 = hour12[:.]minutelz space? meridian;timelong12 = hour12[:.]minute[:.]secondlz space? meridian;timeshort24 = 't'? hour24[:.]minute;timelong24 = 't'? hour24[:.]minute[:.]second;iso8601long = 't'? hour24 [:.] minute [:.] second frac;/* iso8601shorttz = hour24 [:] minutelz space? (tzcorrection | tz); */iso8601normtz = 't'? hour24 [:.] minute [:.] secondlz space? (tzcorrection | tz);/* iso8601longtz = hour24 [:] minute [:] secondlz frac space? (tzcorrection | tz); */gnunocolon = 't'? hour24lz minutelz;/* gnunocolontz = hour24lz minutelz space? (tzcorrection | tz); */iso8601nocolon = 't'? hour24lz minutelz secondlz; /* iso8601nocolontz = hour24lz minutelz secondlz space? (tzcorrection | tz); *//* Date formats */americanshort = month "/" day;american = month "/" day "/" year;iso8601dateslash = year4 "/" monthlz "/" daylz "/"?;dateslash = year4 "/" month "/" day;gnudateshorter = year4 "-" month;gnudateshort = year "-" month "-" day;iso8601date = year4 "-" monthlz "-" daylz;pointeddate = day [.\t-] month [.-] year;datefull = day ([ \t.-])* monthtext ([ \t.-])* year;datenoday = monthtext ([ .\t-])* year4;datenodayrev = year4 ([ .\t-])* monthtext;datetextual = monthtext ([ .\t-])* day [,.stndrh\t ]* year;datenoyear = monthtext ([ .\t-])* day [,.stndrh\t ]*;datenoyearrev = day ([ .\t-])* monthtext;datenocolon = year4 monthlz daylz;/* Special formats */soap = year4 "-" monthlz "-" daylz "T" hour24lz ":" minutelz ":" secondlz frac tzcorrection?;xmlrpc = year4 monthlz daylz "T" hour24 ":" minutelz ":" secondlz;xmlrpcnocolon = year4 monthlz daylz 't' hour24 minutelz secondlz;wddx = year4 "-" month "-" day "T" hour24 ":" minute ":" second;pgydotd = year4 "."? dayofyear;pgtextshort = monthabbr "-" daylz "-" year;pgtextreverse = year "-" monthabbr "-" daylz;isoweekday = year4 "W" weekofyear [0-7];isoweek = year4 "W" weekofyear;exif = year4 ":" monthlz ":" daylz " " hour24lz ":" minutelz ":" secondlz;/* Common Log Format: 10/Oct/2000:13:55:36 -0700 */clf = day "/" monthabbr "/" year4 ":" hour24lz ":" minutelz ":" secondlz space tzcorrection;/* Timestamp format: @1126396800 */timestamp = "@" "-"? [0-9]+;/* To fix some ambiguities */dateshortwithtimeshort12 = datenoyear timeshort12;dateshortwithtimelong12 = datenoyear timelong12;dateshortwithtimeshort = datenoyear timeshort24;dateshortwithtimelong = datenoyear timelong24;dateshortwithtimelongtz = datenoyear iso8601normtz;/* * Relative regexps */reltextnumber = 'first'|'next'|'second'|'third'|'fourth'|'fifth'|'sixth'|'seventh'|'eight'|'ninth'|'tenth'|'eleventh'|'twelfth'|'last'|'previous'|'this';reltextunit = (('sec'|'second'|'min'|'minute'|'hour'|'day'|'week'|'fortnight'|'forthnight'|'month'|'year') 's'?) | daytext;relnumber = ([+-]?[ \t]*[0-9]+);relative = relnumber space? reltextunit;relativetext = reltextnumber space reltextunit;*//*!re2c /* so that vim highlights correctly */ 'yesterday' { DEBUG_OUTPUT("yesterday"); TIMELIB_INIT; TIMELIB_HAVE_RELATIVE(); TIMELIB_UNHAVE_TIME(); s->time->relative.d = -1; TIMELIB_DEINIT; return TIMELIB_RELATIVE; } 'now' { DEBUG_OUTPUT("now"); TIMELIB_INIT; TIMELIB_DEINIT; return TIMELIB_RELATIVE; } 'noon' { DEBUG_OUTPUT("noon"); TIMELIB_INIT; TIMELIB_UNHAVE_TIME(); TIMELIB_HAVE_TIME(); s->time->h = 12; TIMELIB_DEINIT; return TIMELIB_RELATIVE; } 'midnight' | 'today' { DEBUG_OUTPUT("midnight | today"); TIMELIB_INIT; TIMELIB_UNHAVE_TIME(); TIMELIB_DEINIT; return TIMELIB_RELATIVE; } 'tomorrow' { DEBUG_OUTPUT("tomorrow"); TIMELIB_INIT; TIMELIB_HAVE_RELATIVE(); TIMELIB_UNHAVE_TIME(); s->time->relative.d = 1; TIMELIB_DEINIT; return TIMELIB_RELATIVE; } timestamp { timelib_ull i; TIMELIB_INIT; TIMELIB_HAVE_RELATIVE(); TIMELIB_UNHAVE_DATE(); TIMELIB_UNHAVE_TIME(); i = timelib_get_unsigned_nr((char **) &ptr, 24); 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->relative.s += i; s->time->is_localtime = 1; s->time->zone_type = TIMELIB_ZONETYPE_OFFSET; s->time->z = 0; TIMELIB_DEINIT; return TIMELIB_RELATIVE; } timetiny12 | timeshort12 | timelong12 { DEBUG_OUTPUT("timetiny12 | timeshort12 | timelong12"); TIMELIB_INIT; TIMELIB_HAVE_TIME(); s->time->h = timelib_get_nr((char **) &ptr, 2); if (*ptr == ':' || *ptr == '.') { s->time->i = timelib_get_nr((char **) &ptr, 2); if (*ptr == ':' || *ptr == '.') { s->time->s = timelib_get_nr((char **) &ptr, 2); } } s->time->h += timelib_meridian((char **) &ptr, s->time->h); TIMELIB_DEINIT; return TIMELIB_TIME12; } timeshort24 | timelong24 /* | iso8601short | iso8601norm */ | iso8601long /*| iso8601shorttz | iso8601normtz | iso8601longtz*/ { int tz_not_found; DEBUG_OUTPUT("timeshort24 | timelong24 | iso8601long"); TIMELIB_INIT; TIMELIB_HAVE_TIME(); s->time->h = timelib_get_nr((char **) &ptr, 2); s->time->i = timelib_get_nr((char **) &ptr, 2); if (*ptr == ':' || *ptr == '.') { s->time->s = timelib_get_nr((char **) &ptr, 2); if (*ptr == '.') { s->time->f = timelib_get_frac_nr((char **) &ptr, 8); } } if (*ptr != '\0') { s->time->z = timelib_get_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb); if (tz_not_found) { add_error(s, "The timezone could not be found in the database"); } } TIMELIB_DEINIT; return TIMELIB_TIME24_WITH_ZONE; } gnunocolon { DEBUG_OUTPUT("gnunocolon"); TIMELIB_INIT; switch (s->time->have_time) { case 0: s->time->h = timelib_get_nr((char **) &ptr, 2); s->time->i = timelib_get_nr((char **) &ptr, 2); s->time->s = 0; break; case 1: s->time->y = timelib_get_nr((char **) &ptr, 4); break; default: TIMELIB_DEINIT; add_error(s, "Double time specification"); return TIMELIB_ERROR; } s->time->have_time++; TIMELIB_DEINIT; return TIMELIB_GNU_NOCOLON; }/* gnunocolontz { DEBUG_OUTPUT("gnunocolontz"); TIMELIB_INIT; switch (s->time->have_time) { case 0: s->time->h = timelib_get_nr((char **) &ptr, 2); s->time->i = timelib_get_nr((char **) &ptr, 2); s->time->s = 0; s->time->z = timelib_get_zone((char **) &ptr, &s->time->dst, s->time, s->tzdb); break; case 1: s->time->y = timelib_get_nr((char **) &ptr, 4); break; default: TIMELIB_DEINIT; return TIMELIB_ERROR; } s->time->have_time++; TIMELIB_DEINIT; return TIMELIB_GNU_NOCOLON_TZ; }*/ iso8601nocolon /*| iso8601nocolontz*/ { int tz_not_found; DEBUG_OUTPUT("iso8601nocolon"); TIMELIB_INIT; TIMELIB_HAVE_TIME(); s->time->h = timelib_get_nr((char **) &ptr, 2); s->time->i = timelib_get_nr((char **) &ptr, 2); s->time->s = timelib_get_nr((char **) &ptr, 2); if (*ptr != '\0') { s->time->z = timelib_get_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb); if (tz_not_found) { add_error(s, "The timezone could not be found in the database"); } } TIMELIB_DEINIT; return TIMELIB_ISO_NOCOLON; } americanshort | american { DEBUG_OUTPUT("americanshort | american"); TIMELIB_INIT; TIMELIB_HAVE_DATE(); s->time->m = timelib_get_nr((char **) &ptr, 2); s->time->d = timelib_get_nr((char **) &ptr, 2); if (*ptr == '/') { s->time->y = timelib_get_nr((char **) &ptr, 4); TIMELIB_PROCESS_YEAR(s->time->y); } TIMELIB_DEINIT; return TIMELIB_AMERICAN; } iso8601date | iso8601dateslash | dateslash { DEBUG_OUTPUT("iso8601date | iso8601dateslash | dateslash"); TIMELIB_INIT; TIMELIB_HAVE_DATE(); s->time->y = timelib_get_nr((char **) &ptr, 4); s->time->m = timelib_get_nr((char **) &ptr, 2); s->time->d = timelib_get_nr((char **) &ptr, 2); TIMELIB_DEINIT; return TIMELIB_ISO_DATE; } gnudateshorter { DEBUG_OUTPUT("gnudateshorter"); TIMELIB_INIT; TIMELIB_HAVE_DATE(); s->time->y = timelib_get_nr((char **) &ptr, 4); s->time->m = timelib_get_nr((char **) &ptr, 2);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -