Browse Source

Improve parsers

Olivier Marty 8 years ago
parent
commit
42e1dfc316
4 changed files with 9 additions and 9 deletions
  1. 3 3
      parser_srt.c
  2. 2 2
      parser_sub.c
  3. 1 1
      parser_sub2.c
  4. 3 3
      parser_vtt.c

+ 3 - 3
parser_srt.c

@@ -28,12 +28,12 @@ int start_srt(FILE *f)
 int next_srt(FILE *f, int expected, struct SubtitleLine *r)
 {
   int t_h, t_m, t_s, t_ms;
-  fscanf(f, "%*d "); // we ignore it
+  fscanf(f, " %*d "); // we ignore it
 
-  fscanf(f, "%d:%d:%d,%d --> ", &t_h, &t_m, &t_s, &t_ms);
+  fscanf(f, " %d : %d : %d , %d --> ", &t_h, &t_m, &t_s, &t_ms);
   r->begin = timeCreate(t_h*3600 + t_m*60 + t_s, t_ms*1000000);
   // TODO and if there are 4 digits ?
-  fscanf(f, "%d:%d:%d,%d ", &t_h, &t_m, &t_s, &t_ms);
+  fscanf(f, " %d : %d : %d , %d ", &t_h, &t_m, &t_s, &t_ms);
   r->end = timeCreate(t_h*3600 + t_m*60 + t_s, t_ms*1000000);
 
   *(r->text) = '\0';

+ 2 - 2
parser_sub.c

@@ -28,9 +28,9 @@ int start_sub(FILE *f)
 int next_sub(FILE *f, int expected, struct SubtitleLine *r)
 {
   int t_h, t_m, t_s, t_ms;
-  fscanf(f, "%d:%d:%d.%d,", &t_h, &t_m, &t_s, &t_ms);
+  fscanf(f, " %d : %d : %d . %d , ", &t_h, &t_m, &t_s, &t_ms);
   r->begin = timeCreate(t_h*3600 + t_m*60 + t_s, t_ms*10000000);
-  fscanf(f, "%d:%d:%d.%d\n", &t_h, &t_m, &t_s, &t_ms);
+  fscanf(f, " %d : %d : %d . %d ", &t_h, &t_m, &t_s, &t_ms);
   r->end = timeCreate(t_h*3600 + t_m*60 + t_s, t_ms*10000000);
 
   *(r->text) = '\0';

+ 1 - 1
parser_sub2.c

@@ -30,7 +30,7 @@ int next_sub2(FILE *f, int expected, struct SubtitleLine *r)
 {
   float framerate = 23.976; // TODO option
   int tstart, tend;
-  fscanf(f, "{%d}{%d}", &tstart, &tend);
+  fscanf(f, " { %d } { %d } ", &tstart, &tend);
   time_t s = tstart/framerate;
   r->begin = timeCreate(s, (tstart/framerate-s)*1000000000);
   s = tend/framerate;

+ 3 - 3
parser_vtt.c

@@ -29,12 +29,12 @@ int start_vtt(FILE *f)
 int next_vtt(FILE *f, int expected, struct SubtitleLine *r)
 {
   int t_h, t_m, t_s, t_ms;
-  fscanf(f, "%*d "); // we ignore it
+  fscanf(f, " %*d "); // we ignore it
 
-  fscanf(f, "%d:%d:%d.%d --> ", &t_h, &t_m, &t_s, &t_ms);
+  fscanf(f, " %d : %d : %d . %d --> ", &t_h, &t_m, &t_s, &t_ms);
   r->begin = timeCreate(t_h*3600 + t_m*60 + t_s, t_ms*1000000);
   // TODO and if there are 4 digits ?
-  fscanf(f, "%d:%d:%d.%d ", &t_h, &t_m, &t_s, &t_ms);
+  fscanf(f, " %d : %d : %d . %d ", &t_h, &t_m, &t_s, &t_ms);
   r->end = timeCreate(t_h*3600 + t_m*60 + t_s, t_ms*1000000);
 
   *(r->text) = '\0';