mirror of
https://github.com/mpv-player/mpv
synced 2025-02-27 02:40:53 +00:00
sd_ass: fix some corner cases in tag stripping
This behavior is implied by VSFilter.
This commit is contained in:
parent
7bbc617019
commit
545a0e59df
19
sub/sd_ass.c
19
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.
|
||||
|
Loading…
Reference in New Issue
Block a user