summaryrefslogtreecommitdiff
path: root/src/lib/text_decoder.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2022-06-01 12:23:21 +0200
committerCarl Hetherington <cth@carlh.net>2022-06-07 17:01:06 +0200
commita7bd8d64d37ac0fd751226c0fba98e219dea9b0d (patch)
treec26744c2d02aa1c8fdec053ac3a1501f4e9f8bc6 /src/lib/text_decoder.cc
parent96fdcb3161d25a5c5f82f29d89830682241f6f92 (diff)
Extract method to escape text.
Diffstat (limited to 'src/lib/text_decoder.cc')
-rw-r--r--src/lib/text_decoder.cc23
1 files 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, "&", "&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()) {