diff mbox

[FFmpeg-devel] add locale month names to av_small_strptime

Message ID 20170221004802.20303-2-micahgalizia@gmail.com
State Accepted
Commit 489c09ad4b1a0753310a0f0391640f00621fe76e
Headers show

Commit Message

Micah Galizia Feb. 21, 2017, 12:48 a.m. UTC
Signed-off-by: Micah Galizia <micahgalizia@gmail.com>
---
 libavutil/parseutils.c       | 28 ++++++++++++++++++++++++++++
 libavutil/tests/parseutils.c |  7 +++++++
 tests/ref/fate/parseutils    |  7 +++++++
 3 files changed, 42 insertions(+)

Comments

Micah Galizia Feb. 24, 2017, 2:34 a.m. UTC | #1
Hello,

Is someone able to take a look at this and accept or reject it -- its
been a few days since I submitted.

Sorry to pester -- thanks in advance.

On Mon, Feb 20, 2017 at 7:48 PM, Micah Galizia <micahgalizia@gmail.com> wrote:
> Signed-off-by: Micah Galizia <micahgalizia@gmail.com>
> ---
>  libavutil/parseutils.c       | 28 ++++++++++++++++++++++++++++
>  libavutil/tests/parseutils.c |  7 +++++++
>  tests/ref/fate/parseutils    |  7 +++++++
>  3 files changed, 42 insertions(+)
>
> diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c
> index 86d3dac..7ca07b3 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 682b390..180f624 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);
> diff --git a/tests/ref/fate/parseutils b/tests/ref/fate/parseutils
> index 1aad5ec..568b6d2 100644
> --- a/tests/ref/fate/parseutils
> +++ b/tests/ref/fate/parseutils
> @@ -68,6 +68,13 @@ fmt:'%Y-%m-%d' spec:'2012-12-21' -> 2012-12-21 00:00:00
>  fmt:'%Y - %m - %d' spec:'2012-12-21' -> 2012-12-21 00:00:00
>  fmt:'%Y-%m-%d %H:%M:%S' spec:'2012-12-21 20:12:21' -> 2012-12-21 20:12:21
>  fmt:'  %Y - %m - %d %H : %M : %S' spec:'   2012 - 12 -  21   20 : 12 : 21' -> 2012-12-21 20:12:21
> +fmt:'  %Y - %b - %d %H : %M : %S' spec:'   2012 - nOV -  21   20 : 12 : 21' -> 2012-11-21 20:12:21
> +fmt:'  %Y - %B - %d %H : %M : %S' spec:'   2012 - nOVemBeR -  21   20 : 12 : 21' -> 2012-11-21 20:12:21
> +fmt:'  %Y - %B%d %H : %M : %S' spec:'   2012 - may21   20 : 12 : 21' -> 2012-05-21 20:12:21
> +fmt:'  %Y - %B%d %H : %M : %S' spec:'   2012 - mby21   20 : 12 : 21' -> error
> +fmt:'  %Y - %B - %d %H : %M : %S' spec:'   2012 - JunE -  21   20 : 12 : 21' -> 2012-06-21 20:12:21
> +fmt:'  %Y - %B - %d %H : %M : %S' spec:'   2012 - Jane -  21   20 : 12 : 21' -> error
> +fmt:'  %Y - %B - %d %H : %M : %S' spec:'   2012 - January -  21   20 : 12 : 21' -> 2012-01-21 20:12:21
>
>  Testing av_parse_time()
>  (now is 2012-03-17 09:14:13.2 +0100, local time is UTC+1)
> --
> 2.9.3
>
Michael Niedermayer Feb. 26, 2017, 4:12 p.m. UTC | #2
On Thu, Feb 23, 2017 at 09:34:28PM -0500, Micah Galizia wrote:
> Hello,
> 
> Is someone able to take a look at this and accept or reject it -- its
> been a few days since I submitted.

applied

thx

[...]
Micah Galizia Feb. 27, 2017, 12:45 a.m. UTC | #3
On Sun, Feb 26, 2017 at 11:12 AM, Michael Niedermayer
<michael@niedermayer.cc> wrote:
> On Thu, Feb 23, 2017 at 09:34:28PM -0500, Micah Galizia wrote:
>> Hello,
>>
>> Is someone able to take a look at this and accept or reject it -- its
>> been a few days since I submitted.
>
> applied
>
> thx

Awesome -- thank you. On to the next one :)
diff mbox

Patch

diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c
index 86d3dac..7ca07b3 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 682b390..180f624 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);
diff --git a/tests/ref/fate/parseutils b/tests/ref/fate/parseutils
index 1aad5ec..568b6d2 100644
--- a/tests/ref/fate/parseutils
+++ b/tests/ref/fate/parseutils
@@ -68,6 +68,13 @@  fmt:'%Y-%m-%d' spec:'2012-12-21' -> 2012-12-21 00:00:00
 fmt:'%Y - %m - %d' spec:'2012-12-21' -> 2012-12-21 00:00:00
 fmt:'%Y-%m-%d %H:%M:%S' spec:'2012-12-21 20:12:21' -> 2012-12-21 20:12:21
 fmt:'  %Y - %m - %d %H : %M : %S' spec:'   2012 - 12 -  21   20 : 12 : 21' -> 2012-12-21 20:12:21
+fmt:'  %Y - %b - %d %H : %M : %S' spec:'   2012 - nOV -  21   20 : 12 : 21' -> 2012-11-21 20:12:21
+fmt:'  %Y - %B - %d %H : %M : %S' spec:'   2012 - nOVemBeR -  21   20 : 12 : 21' -> 2012-11-21 20:12:21
+fmt:'  %Y - %B%d %H : %M : %S' spec:'   2012 - may21   20 : 12 : 21' -> 2012-05-21 20:12:21
+fmt:'  %Y - %B%d %H : %M : %S' spec:'   2012 - mby21   20 : 12 : 21' -> error
+fmt:'  %Y - %B - %d %H : %M : %S' spec:'   2012 - JunE -  21   20 : 12 : 21' -> 2012-06-21 20:12:21
+fmt:'  %Y - %B - %d %H : %M : %S' spec:'   2012 - Jane -  21   20 : 12 : 21' -> error
+fmt:'  %Y - %B - %d %H : %M : %S' spec:'   2012 - January -  21   20 : 12 : 21' -> 2012-01-21 20:12:21
 
 Testing av_parse_time()
 (now is 2012-03-17 09:14:13.2 +0100, local time is UTC+1)