From a7bd8d64d37ac0fd751226c0fba98e219dea9b0d Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 1 Jun 2022 12:23:21 +0200 Subject: [PATCH] Extract method to escape text. --- src/lib/text_decoder.cc | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/lib/text_decoder.cc b/src/lib/text_decoder.cc index 88cf4bc56..c6563a260 100644 --- a/src/lib/text_decoder.cc +++ b/src/lib/text_decoder.cc @@ -67,18 +67,25 @@ TextDecoder::emit_bitmap_start (ContentBitmapText const& bitmap) } +static +string +escape_text (string text) +{ + /* We must escape some things, otherwise they might confuse our subtitle + renderer (which uses entities and some HTML-esque markup to do bold/italic etc.) + */ + boost::algorithm::replace_all(text, "&", "&"); + boost::algorithm::replace_all(text, "<", "<"); + boost::algorithm::replace_all(text, ">", ">"); + return text; +} + + void TextDecoder::emit_plain_start (ContentTime from, vector subtitles) { for (auto& subtitle: subtitles) { - /* We must escape some things, otherwise they might confuse our subtitle - renderer (which uses entities and some HTML-esque markup to do bold/italic etc.) - */ - string text = subtitle.text(); - boost::algorithm::replace_all(text, "&", "&"); - boost::algorithm::replace_all(text, "<", "<"); - boost::algorithm::replace_all(text, ">", ">"); - subtitle.set_text (text); + subtitle.set_text(escape_text(subtitle.text())); /* Set any forced appearance */ if (content()->colour()) { -- 2.30.2