diff options
Diffstat (limited to 'sub')
-rw-r--r-- | sub/filter_jsre.c | 5 | ||||
-rw-r--r-- | sub/filter_regex.c | 5 | ||||
-rw-r--r-- | sub/sd.h | 5 | ||||
-rw-r--r-- | sub/sd_ass.c | 9 |
4 files changed, 22 insertions, 2 deletions
diff --git a/sub/filter_jsre.c b/sub/filter_jsre.c index 896382714a..af4fbbeba3 100644 --- a/sub/filter_jsre.c +++ b/sub/filter_jsre.c @@ -87,7 +87,7 @@ static bool jsre_init(struct sd_filter *ft) for (int n = 0; ft->opts->jsre_items && ft->opts->jsre_items[n]; n++) { char *item = ft->opts->jsre_items[n]; - int err = p_regcomp(p->J, p->num_regexes, item, JS_REGEXP_I); + int err = p_regcomp(p->J, p->num_regexes, item, JS_REGEXP_I | JS_REGEXP_M); if (err) { MP_ERR(ft, "jsre: %s -- '%s'\n", get_err(p->J), item); js_pop(p->J, 1); @@ -111,6 +111,9 @@ static struct demux_packet *jsre_filter(struct sd_filter *ft, char *text = bstrto0(NULL, sd_ass_pkt_text(ft, pkt, p->offset)); bool drop = false; + if (ft->opts->rf_plain) + sd_ass_to_plaintext(text, strlen(text), text); + for (int n = 0; n < p->num_regexes; n++) { int found, err = p_regexec(p->J, n, text, &found); if (err == 0 && found) { diff --git a/sub/filter_regex.c b/sub/filter_regex.c index 66e4b1a1da..8e299918ce 100644 --- a/sub/filter_regex.c +++ b/sub/filter_regex.c @@ -30,7 +30,7 @@ static bool rf_init(struct sd_filter *ft) MP_TARRAY_GROW(p, p->regexes, p->num_regexes); regex_t *preg = &p->regexes[p->num_regexes]; - int err = regcomp(preg, item, REG_ICASE | REG_EXTENDED | REG_NOSUB); + int err = regcomp(preg, item, REG_ICASE | REG_EXTENDED | REG_NOSUB | REG_NEWLINE); if (err) { char errbuf[512]; regerror(err, preg, errbuf, sizeof(errbuf)); @@ -63,6 +63,9 @@ static struct demux_packet *rf_filter(struct sd_filter *ft, char *text = bstrto0(NULL, sd_ass_pkt_text(ft, pkt, p->offset)); bool drop = false; + if (ft->opts->rf_plain) + sd_ass_to_plaintext(text, strlen(text), text); + for (int n = 0; n < p->num_regexes; n++) { int err = regexec(&p->regexes[n], text, 0, NULL, 0); if (err == 0) { @@ -101,4 +101,9 @@ int sd_ass_fmt_offset(const char *event_format); // on malformed event: warns and returns (bstr){NULL,0} bstr sd_ass_pkt_text(struct sd_filter *ft, struct demux_packet *pkt, int offset); +// convert \0-terminated "Text" (ass) content to plaintext, possibly in-place. +// result.start is out, result.len is MIN(out_siz, strlen(in)) or smaller. +// if there's room: out[result.len] is set to \0. out == in is allowed. +bstr sd_ass_to_plaintext(char *out, size_t out_siz, const char *in); + #endif diff --git a/sub/sd_ass.c b/sub/sd_ass.c index e100b5c5e0..939c000156 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -973,3 +973,12 @@ bstr sd_ass_pkt_text(struct sd_filter *ft, struct demux_packet *pkt, int offset) } return txt; } + +bstr sd_ass_to_plaintext(char *out, size_t out_siz, const char *in) +{ + struct buf b = {out, out_siz, 0}; + ass_to_plaintext(&b, in); + if (b.len < out_siz) + out[b.len] = 0; + return (bstr){out, b.len}; +} |