diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-06-01 12:23:21 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-06-06 23:25:56 +0200 |
| commit | 4d6ca25589de9893687f5dc7aeaad3d04471ecac (patch) | |
| tree | a40f81cde482b7883469cb859fa26b8165d08a2f | |
| parent | 70ca2da57fcdac7cf5c6e59adf1ac43925225bc9 (diff) | |
Extract method to escape text.
| -rw-r--r-- | src/lib/text_decoder.cc | 23 |
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, "&", "&"); + boost::algorithm::replace_all(text, "<", "<"); + boost::algorithm::replace_all(text, ">", ">"); + 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, "&", "&"); - 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()) { |
