From 545a0e59dfeda5c445e26d32afde444f754f045b Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 12 Feb 2015 12:18:19 +0100 Subject: sd_ass: fix some corner cases in tag stripping This behavior is implied by VSFilter. --- sub/sd_ass.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'sub') diff --git a/sub/sd_ass.c b/sub/sd_ass.c index 8bfefb35cb..9e08c2c3b6 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -181,6 +181,7 @@ static void append(struct buf *b, char c) static void ass_to_plaintext(struct buf *b, const char *in) { bool in_tag = false; + const char *open_tag_pos = NULL; bool in_drawing = false; while (*in) { if (in_tag) { @@ -189,11 +190,13 @@ static void ass_to_plaintext(struct buf *b, const char *in) in_tag = false; } else if (in[0] == '\\' && in[1] == 'p') { in += 2; - // skip text between \pN and \p0 tags - if (in[0] == '0') { - in_drawing = false; - } else if (in[0] >= '1' && in[0] <= '9') { - in_drawing = true; + // Skip text between \pN and \p0 tags. A \p without a number + // is the same as \p0, and leading 0s are also allowed. + in_drawing = false; + while (in[0] >= '0' && in[0] <= '9') { + if (in[0] != '0') + in_drawing = true; + in += 1; } } else { in += 1; @@ -206,6 +209,7 @@ static void ass_to_plaintext(struct buf *b, const char *in) in += 2; append(b, ' '); } else if (in[0] == '{') { + open_tag_pos = in; in += 1; in_tag = true; } else { @@ -215,6 +219,11 @@ static void ass_to_plaintext(struct buf *b, const char *in) } } } + // A '{' without a closing '}' is always visible. + if (in_tag) { + while (*open_tag_pos) + append(b, *open_tag_pos++); + } } // Empty string counts as whitespace. Reads s[len-1] even if there are \0s. -- cgit v1.2.3