summaryrefslogtreecommitdiffstats
path: root/sub
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-06-02 19:11:25 +0200
committerwm4 <wm4@nowhere>2013-06-03 22:40:06 +0200
commite42a7714133bc0dd0b786af45749ea894f32e6a7 (patch)
tree3f5553449d13b8c5a5c00229be927c410d3415f5 /sub
parent6dbedd27d53b61744d512e27bb0c3853cf6d7bba (diff)
downloadmpv-e42a7714133bc0dd0b786af45749ea894f32e6a7.tar.bz2
mpv-e42a7714133bc0dd0b786af45749ea894f32e6a7.tar.xz
sd_ass: strip empty/whitespace lines in -no-ass mode
Will just destroy output. In some cases empty newlines might be used by bad scripts for spacing; too bad for them.
Diffstat (limited to 'sub')
-rw-r--r--sub/sd_ass.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/sub/sd_ass.c b/sub/sd_ass.c
index d8951df96f..21d941933c 100644
--- a/sub/sd_ass.c
+++ b/sub/sd_ass.c
@@ -224,6 +224,16 @@ static void ass_to_plaintext(struct buf *b, const char *in)
}
}
+// Empty string counts as whitespace. Reads s[len-1] even if there are \0s.
+static bool is_whitespace_only(char *s, int len)
+{
+ for (int n = 0; n < len; n++) {
+ if (s[n] != ' ' && s[n] != '\t')
+ return false;
+ }
+ return true;
+}
+
static char *get_text(struct sd *sd, double pts)
{
struct sd_ass_priv *ctx = sd->priv;
@@ -240,8 +250,10 @@ static char *get_text(struct sd *sd, double pts)
double end = (event->Start + event->Duration) / 1000.0;
if (pts >= start && pts < end) {
if (event->Text) {
+ int start = b.len;
ass_to_plaintext(&b, event->Text);
- append(&b, '\n');
+ if (!is_whitespace_only(&b.start[b.len], b.len - start))
+ append(&b, '\n');
}
}
}