The strptime implementation is supposed to support whitespace and %T.
---

I tested it a little with

"2001 - 10 - 1 1:1:1", "2001 - 10 - 1T1:1:1", "2001 -  10 -  1  1:1:1 ",
"2008-1-1 12:12:12",

and seems working as expected for the two usecases we have.

 libavutil/parseutils.c | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c
index 4ae47ee..1fe4745 100644
--- a/libavutil/parseutils.c
+++ b/libavutil/parseutils.c
@@ -404,11 +404,16 @@ static const char *small_strptime(const char *p, const 
char *fmt, struct tm *dt)
 {
     int c, val;

-    for(;;) {
-        c = *fmt++;
-        if (c == '\0') {
-            return p;
-        } else if (c == '%') {
+    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++;
             switch(c) {
             case 'H':
@@ -447,18 +452,21 @@ static const char *small_strptime(const char *p, const 
char *fmt, struct tm *dt)
                     return NULL;
                 dt->tm_mday = val;
                 break;
+            case 'T':
+                p = small_strptime(p, "%H:%M:%S", dt);
+                if (!p)
+                    return NULL;
+                break;
             case '%':
-                goto match;
+                if (*p++ != '%')
+                    return NULL;
+                break;
             default:
                 return NULL;
             }
-        } else {
-        match:
-            if (c != *p)
-                return NULL;
-            p++;
-        }
     }
+
+    return p;
 }

 time_t av_timegm(struct tm *tm)
--
2.3.2

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to