summaryrefslogtreecommitdiffstats
path: root/sub/sd_ass.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-02-12 12:18:19 +0100
committerwm4 <wm4@nowhere>2015-02-12 12:19:39 +0100
commit545a0e59dfeda5c445e26d32afde444f754f045b (patch)
tree1d6381a2da9001189080a7a20cfd902c554c4d89 /sub/sd_ass.c
parent7bbc6170193a22d5d66370e4e3a97d23bcbc3903 (diff)
downloadmpv-545a0e59dfeda5c445e26d32afde444f754f045b.tar.bz2
mpv-545a0e59dfeda5c445e26d32afde444f754f045b.tar.xz
sd_ass: fix some corner cases in tag stripping
This behavior is implied by VSFilter.
Diffstat (limited to 'sub/sd_ass.c')
-rw-r--r--sub/sd_ass.c19
1 files changed, 14 insertions, 5 deletions
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.