diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2015-04-07 19:58:31 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2015-04-07 20:01:36 +0200 |
commit | 0739179bfb002324eea20f1c44c5f586b6bd3e04 (patch) | |
tree | 106761bd7844229b1050ce4a0584ba6187532a69 | |
parent | 6fd300ac6c2c3871736ce0e6df95603255004dc6 (diff) | |
parent | 108f2f381acb93827fb4add0517eeae859afa3bf (diff) | |
download | ffmpeg-0739179bfb002324eea20f1c44c5f586b6bd3e04.tar.gz |
Merge commit '108f2f381acb93827fb4add0517eeae859afa3bf'
* commit '108f2f381acb93827fb4add0517eeae859afa3bf':
parseutils: Extend small_strptime to be used in avformat
Conflicts:
libavutil/parseutils.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavutil/parseutils.c | 115 |
1 files changed, 59 insertions, 56 deletions
diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c index 8cd844e422..98858394ea 100644 --- a/libavutil/parseutils.c +++ b/libavutil/parseutils.c @@ -465,68 +465,71 @@ char *av_small_strptime(const char *p, const char *fmt, struct tm *dt) { int c, val; - for(;;) { - /* consume time string until a non whitespace char is found */ - while (av_isspace(*fmt)) { - while (av_isspace(*p)) - p++; - fmt++; + while((c = *fmt++)) { + if (c != '%') { + if (av_isspace(c)) + for (; *p && av_isspace(*p); p++); + else if (*p != c) + return NULL; + else p++; + continue; } + c = *fmt++; - if (c == '\0') { - return (char *)p; - } else if (c == '%') { - c = *fmt++; - switch(c) { - case 'H': - case 'J': - val = date_get_num(&p, 0, c == 'H' ? 23 : INT_MAX, 2); - if (val == -1) - return NULL; - dt->tm_hour = val; - break; - case 'M': - val = date_get_num(&p, 0, 59, 2); - if (val == -1) - return NULL; - dt->tm_min = val; - break; - case 'S': - val = date_get_num(&p, 0, 59, 2); - if (val == -1) - return NULL; - dt->tm_sec = val; - break; - case 'Y': - val = date_get_num(&p, 0, 9999, 4); - if (val == -1) - return NULL; - dt->tm_year = val - 1900; - break; - case 'm': - val = date_get_num(&p, 1, 12, 2); - if (val == -1) - return NULL; - dt->tm_mon = val - 1; - break; - case 'd': - val = date_get_num(&p, 1, 31, 2); - if (val == -1) - return NULL; - dt->tm_mday = val; - break; - case '%': - goto match; - default: + switch(c) { + case 'H': + case 'J': + val = date_get_num(&p, 0, c == 'H' ? 23 : INT_MAX, 2); + + if (val == -1) return NULL; - } - } else { - match: - if (c != *p) + dt->tm_hour = val; + break; + case 'M': + val = date_get_num(&p, 0, 59, 2); + if (val == -1) return NULL; - p++; + dt->tm_min = val; + break; + case 'S': + val = date_get_num(&p, 0, 59, 2); + if (val == -1) + return NULL; + dt->tm_sec = val; + break; + case 'Y': + val = date_get_num(&p, 0, 9999, 4); + if (val == -1) + return NULL; + dt->tm_year = val - 1900; + break; + case 'm': + val = date_get_num(&p, 1, 12, 2); + if (val == -1) + return NULL; + dt->tm_mon = val - 1; + break; + case 'd': + val = date_get_num(&p, 1, 31, 2); + if (val == -1) + return NULL; + dt->tm_mday = val; + break; + case 'T': + p = av_small_strptime(p, "%H:%M:%S", dt); + if (!p) + return NULL; + break; + case '%': + if (*p++ != '%') + return NULL; + break; + default: + return NULL; } } + + return (char*)p; } time_t av_timegm(struct tm *tm) |