From 6c0752035c1eb04a62b677a5af99f82ebeb61daa Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 7 Jul 2014 07:11:01 -0700 Subject: [PATCH] Slightly optimize AssDialogue serialization --- src/ass_dialogue.cpp | 25 ++++++++++++------------- src/text_file_writer.cpp | 5 +++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/ass_dialogue.cpp b/src/ass_dialogue.cpp index 40d2599fa..e2088e80c 100644 --- a/src/ass_dialogue.cpp +++ b/src/ass_dialogue.cpp @@ -41,7 +41,6 @@ #include #include -#include #include #include #include @@ -156,10 +155,12 @@ void append_str(std::string &out, std::string const& str) { } void append_unsafe_str(std::string &out, std::string const& str) { - if (str.find(',') == str.npos) - out += str; - else - out += boost::replace_all_copy(str, ",", ";"); + for (auto c : str) { + if (c == ',') + out += ';'; + else + out += c; + } out += ','; } @@ -177,19 +178,17 @@ std::string AssDialogue::GetEntryData() const { append_unsafe_str(str, Effect); if (ExtradataIds.get().size() > 0) { - str += "{"; + str += '{'; for (auto id : ExtradataIds.get()) { - str += "="; + str += '='; boost::spirit::karma::generate(back_inserter(str), boost::spirit::karma::int_, id); } - str += "}"; + str += '}'; } - str += Text.get(); - - if (str.find('\n') != str.npos || str.find('\r') != str.npos) { - boost::replace_all(str, "\n", ""); - boost::replace_all(str, "\r", ""); + for (auto c : Text.get()) { + if (c != '\n' && c != '\r') + str += c; } return str; diff --git a/src/text_file_writer.cpp b/src/text_file_writer.cpp index b77af0942..328c30cb0 100644 --- a/src/text_file_writer.cpp +++ b/src/text_file_writer.cpp @@ -27,14 +27,15 @@ #include #include -#include +#include TextFileWriter::TextFileWriter(agi::fs::path const& filename, std::string encoding) : file(new agi::io::Save(filename, true)) { if (encoding.empty()) encoding = OPT_GET("App/Save Charset")->GetString(); - if (!boost::iequals(encoding, "utf-8")) { + boost::to_lower(encoding); + if (encoding != "utf-8") { conv = agi::make_unique("utf-8", encoding.c_str(), true); newline = conv->Convert(newline); }