# HG changeset patch # User reimar # Date 1275937275 0 # Node ID 17db8e56de4c9c3ada6b21cf620220bdd3d9acd2 # Parent 0fc579d95340a209a81bae04010157fc03bf1d88 Extract duplicated code into a separate function. diff -r 0fc579d95340 -r 17db8e56de4c subreader.c --- a/subreader.c Mon Jun 07 18:53:20 2010 +0000 +++ b/subreader.c Mon Jun 07 19:01:15 2010 +0000 @@ -111,6 +111,15 @@ return NULL; } +static void sami_add_line(subtitle *current, char *buffer, char **pos) { + char *p = *pos; + *p = 0; + trail_space(buffer); + if (*buffer && current->lines < SUB_MAX_TEXT) + current->text[current->lines++] = strdup(buffer); + *pos = buffer; +} + static subtitle *sub_read_line_sami(stream_t* st, subtitle *current, int utf16) { static char line[LINE_LEN+1]; static char *s = NULL, *slacktime_s; @@ -162,9 +171,7 @@ case 3: /* get all text until '<' appears */ if (*s == '\0') break; else if (!strncasecmp (s, "
", 4)) { - *p = '\0'; p = text; trail_space (text); - if (text[0] != '\0' && current->lines < SUB_MAX_TEXT) - current->text[current->lines++] = strdup (text); + sami_add_line(current, text, &p); s += 4; } else if ((*s == '{') && !sub_no_text_pp) { state = 5; ++s; continue; } @@ -243,9 +250,7 @@ // For the last subtitle if (current->end <= 0) { current->end = current->start + sub_slacktime; - *p = '\0'; trail_space (text); - if (text[0] != '\0' && current->lines < SUB_MAX_TEXT) - current->text[current->lines++] = strdup (text); + sami_add_line(current, text, &p); } return current;