changeset 33513:65e6c1de4afa

vobsub: simplify timestamp parsing.
author cboesch
date Sun, 12 Jun 2011 10:55:24 +0000
parents 2d1fa588834a
children 30e54bd66d39
files sub/vobsub.c
diffstat 1 files changed, 2 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/sub/vobsub.c	Sun Jun 12 10:41:49 2011 +0000
+++ b/sub/vobsub.c	Sun Jun 12 10:55:24 2011 +0000
@@ -693,55 +693,11 @@
 
 static int vobsub_parse_timestamp(vobsub_t *vob, const char *line)
 {
-    // timestamp: HH:MM:SS.mmm, filepos: 0nnnnnnnnn
-    const char *p;
     int h, m, s, ms;
     off_t filepos;
-    while (isspace(*line))
-        ++line;
-    p = line;
-    while (isdigit(*p))
-        ++p;
-    if (p - line != 2)
-        return -1;
-    h = atoi(line);
-    if (*p != ':')
-        return -1;
-    line = ++p;
-    while (isdigit(*p))
-        ++p;
-    if (p - line != 2)
-        return -1;
-    m = atoi(line);
-    if (*p != ':')
-        return -1;
-    line = ++p;
-    while (isdigit(*p))
-        ++p;
-    if (p - line != 2)
+    if (sscanf(line, " %02d:%02d:%02d:%03d, filepos: %09lx",
+               &h, &m, &s, &ms, &filepos) != 5)
         return -1;
-    s = atoi(line);
-    if (*p != ':')
-        return -1;
-    line = ++p;
-    while (isdigit(*p))
-        ++p;
-    if (p - line != 3)
-        return -1;
-    ms = atoi(line);
-    if (*p != ',')
-        return -1;
-    line = p + 1;
-    while (isspace(*line))
-        ++line;
-    if (strncmp("filepos:", line, 8))
-        return -1;
-    line += 8;
-    while (isspace(*line))
-        ++line;
-    if (! isxdigit(*line))
-        return -1;
-    filepos = strtol(line, NULL, 16);
     return vobsub_add_timestamp(vob, filepos, vob->delay + ms + 1000 * (s + 60 * (m + 60 * h)));
 }