From e42a7714133bc0dd0b786af45749ea894f32e6a7 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 2 Jun 2013 19:11:25 +0200 Subject: 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. --- sub/sd_ass.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'sub') 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'); } } } -- cgit v1.2.3