Extract method to escape text.
authorCarl Hetherington <cth@carlh.net>
Wed, 1 Jun 2022 10:23:21 +0000 (12:23 +0200)
committerCarl Hetherington <cth@carlh.net>
Tue, 7 Jun 2022 15:01:06 +0000 (17:01 +0200)
src/lib/text_decoder.cc

index 88cf4bc56e492da0aefbf320fdbe21fc0220bba6..c6563a260fe238656a2c65889c13f8cdb06d1298 100644 (file)
@@ -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, "&", "&amp;");
+       boost::algorithm::replace_all(text, "<", "&lt;");
+       boost::algorithm::replace_all(text, ">", "&gt;");
+       return text;
+}
+
+
 void
 TextDecoder::emit_plain_start (ContentTime from, vector<dcp::SubtitleString> 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, "&", "&amp;");
-               boost::algorithm::replace_all(text, "<", "&lt;");
-               boost::algorithm::replace_all(text, ">", "&gt;");
-               subtitle.set_text (text);
+               subtitle.set_text(escape_text(subtitle.text()));
 
                /* Set any forced appearance */
                if (content()->colour()) {