From: Carl Hetherington Date: Wed, 1 Jun 2022 10:23:21 +0000 (+0200) Subject: Extract method to escape text. X-Git-Tag: v2.16.14~27 X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=a7bd8d64d37ac0fd751226c0fba98e219dea9b0d Extract method to escape text. --- 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()) {