diff options
author | Micah Galizia <micahgalizia@gmail.com> | 2017-02-21 20:37:25 -0500 |
---|---|---|
committer | Michael Niedermayer <michael@niedermayer.cc> | 2017-02-26 17:16:22 +0100 |
commit | 489c09ad4b1a0753310a0f0391640f00621fe76e (patch) | |
tree | d44731044574d14398d51e02bb6dd311129415e5 /libavutil | |
parent | 3a003cc3817f97f92e572ce41379011bf7f705b7 (diff) | |
download | ffmpeg-489c09ad4b1a0753310a0f0391640f00621fe76e.tar.gz |
add locale month names to av_small_strptime
Signed-off-by: Micah Galizia <micahgalizia@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavutil')
-rw-r--r-- | libavutil/parseutils.c | 28 | ||||
-rw-r--r-- | libavutil/tests/parseutils.c | 7 |
2 files changed, 35 insertions, 0 deletions
diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c index 86d3dac57c..7ca07b37a1 100644 --- a/libavutil/parseutils.c +++ b/libavutil/parseutils.c @@ -140,6 +140,11 @@ static const VideoRateAbbr video_rate_abbrs[]= { { "ntsc-film", { 24000, 1001 } }, }; +static const char *months[12] = { + "january", "february", "march", "april", "may", "june", "july", "august", + "september", "october", "november", "december" +}; + int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str) { int i; @@ -466,6 +471,21 @@ static int date_get_num(const char **pp, return val; } +static int date_get_month(const char **pp) { + int i = 0; + for (; i < 12; i++) { + if (!av_strncasecmp(*pp, months[i], 3)) { + const char *mo_full = months[i] + 3; + int len = strlen(mo_full); + *pp += 3; + if (len > 0 && !av_strncasecmp(*pp, mo_full, len)) + *pp += len; + return i; + } + } + return -1; +} + char *av_small_strptime(const char *p, const char *fmt, struct tm *dt) { int c, val; @@ -525,6 +545,14 @@ char *av_small_strptime(const char *p, const char *fmt, struct tm *dt) if (!p) return NULL; break; + case 'b': + case 'B': + case 'h': + val = date_get_month(&p); + if (val == -1) + return NULL; + dt->tm_mon = val; + break; case '%': if (*p++ != '%') return NULL; diff --git a/libavutil/tests/parseutils.c b/libavutil/tests/parseutils.c index 682b3907cf..180f624002 100644 --- a/libavutil/tests/parseutils.c +++ b/libavutil/tests/parseutils.c @@ -138,6 +138,13 @@ static void test_av_small_strptime(void) { "%Y - %m - %d", "2012-12-21" }, { "%Y-%m-%d %H:%M:%S", "2012-12-21 20:12:21" }, { " %Y - %m - %d %H : %M : %S", " 2012 - 12 - 21 20 : 12 : 21" }, + { " %Y - %b - %d %H : %M : %S", " 2012 - nOV - 21 20 : 12 : 21" }, + { " %Y - %B - %d %H : %M : %S", " 2012 - nOVemBeR - 21 20 : 12 : 21" }, + { " %Y - %B%d %H : %M : %S", " 2012 - may21 20 : 12 : 21" }, + { " %Y - %B%d %H : %M : %S", " 2012 - mby21 20 : 12 : 21" }, + { " %Y - %B - %d %H : %M : %S", " 2012 - JunE - 21 20 : 12 : 21" }, + { " %Y - %B - %d %H : %M : %S", " 2012 - Jane - 21 20 : 12 : 21" }, + { " %Y - %B - %d %H : %M : %S", " 2012 - January - 21 20 : 12 : 21" }, }; av_log_set_level(AV_LOG_DEBUG); |