From 8d555a1d7463bcb18a561dafbeabd297e7b721b8 Mon Sep 17 00:00:00 2001 From: Oleg Oshmyan Date: Sat, 15 Jun 2013 22:24:45 +0100 Subject: Parse style names like VSFilter does Trim '*' from the start of style name fields of Style and Dialogue lines and normalize the case of "Default" in the style name field of Dialogue lines. --- libass/ass.c | 14 ++++++++++---- libass/ass_utils.c | 16 +++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/libass/ass.c b/libass/ass.c index 576f04b..6505892 100644 --- a/libass/ass.c +++ b/libass/ass.c @@ -240,6 +240,13 @@ static int numpad2align(int val) target->name = strdup(token); \ ass_msg(track->library, MSGL_DBG2, "%s = %s", #name, token); +#define STARREDSTRVAL(name) \ + } else if (strcasecmp(tname, #name) == 0) { \ + if (target->name != NULL) free(target->name); \ + while (*token == '*') ++token; \ + target->name = strdup(token); \ + ass_msg(track->library, MSGL_DBG2, "%s = %s", #name, token); + #define COLORVAL(name) \ } else if (strcasecmp(tname, #name) == 0) { \ target->name = string2color(track->library, token); \ @@ -498,10 +505,9 @@ static int process_style(ASS_Track *track, char *str) NEXT(p, token); if (0) { // cool ;) - STRVAL(Name) - if ((strcmp(target->Name, "Default") == 0) - || (strcmp(target->Name, "*Default") == 0)) - track->default_style = sid; + STARREDSTRVAL(Name) + if (strcmp(target->Name, "Default") == 0) + track->default_style = sid; STRVAL(FontName) COLORVAL(PrimaryColour) COLORVAL(SecondaryColour) diff --git a/libass/ass_utils.c b/libass/ass_utils.c index ba31261..3dab74c 100644 --- a/libass/ass_utils.c +++ b/libass/ass_utils.c @@ -205,14 +205,20 @@ unsigned ass_utf8_get_char(char **str) * \param track track * \param name style name * \return index in track->styles - * Returnes 0 if no styles found => expects at least 1 style. - * Parsing code always adds "Default" style in the end. + * Returns 0 if no styles found => expects at least 1 style. + * Parsing code always adds "Default" style in the beginning. */ int lookup_style(ASS_Track *track, char *name) { int i; - if (*name == '*') - ++name; // FIXME: what does '*' really mean ? + // '*' seem to mean literally nothing; + // VSFilter removes them as soon as it can + while (*name == '*') + ++name; + // VSFilter then normalizes the case of "Default" + // (only in contexts where this function is called) + if (strcasecmp(name, "Default") == 0) + name = "Default"; for (i = track->n_styles - 1; i >= 0; --i) { if (strcmp(track->styles[i].Name, name) == 0) return i; @@ -221,7 +227,7 @@ int lookup_style(ASS_Track *track, char *name) ass_msg(track->library, MSGL_WARN, "[%p]: Warning: no style named '%s' found, using '%s'", track, name, track->styles[i].Name); - return i; // use the first style + return i; } /** -- cgit v1.2.3