Slightly optimize AssDialogue serialization

This commit is contained in:
Thomas Goyne 2014-07-07 07:11:01 -07:00
parent 3844a1cb80
commit 6c0752035c
2 changed files with 15 additions and 15 deletions

View File

@ -41,7 +41,6 @@
#include <boost/algorithm/string/predicate.hpp> #include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/join.hpp> #include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/algorithm/string/trim.hpp> #include <boost/algorithm/string/trim.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/regex.hpp> #include <boost/regex.hpp>
@ -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) { void append_unsafe_str(std::string &out, std::string const& str) {
if (str.find(',') == str.npos) for (auto c : str) {
out += str; if (c == ',')
else out += ';';
out += boost::replace_all_copy(str, ",", ";"); else
out += c;
}
out += ','; out += ',';
} }
@ -177,19 +178,17 @@ std::string AssDialogue::GetEntryData() const {
append_unsafe_str(str, Effect); append_unsafe_str(str, Effect);
if (ExtradataIds.get().size() > 0) { if (ExtradataIds.get().size() > 0) {
str += "{"; str += '{';
for (auto id : ExtradataIds.get()) { for (auto id : ExtradataIds.get()) {
str += "="; str += '=';
boost::spirit::karma::generate(back_inserter(str), boost::spirit::karma::int_, id); boost::spirit::karma::generate(back_inserter(str), boost::spirit::karma::int_, id);
} }
str += "}"; str += '}';
} }
str += Text.get(); for (auto c : Text.get()) {
if (c != '\n' && c != '\r')
if (str.find('\n') != str.npos || str.find('\r') != str.npos) { str += c;
boost::replace_all(str, "\n", "");
boost::replace_all(str, "\r", "");
} }
return str; return str;

View File

@ -27,14 +27,15 @@
#include <libaegisub/charset_conv.h> #include <libaegisub/charset_conv.h>
#include <libaegisub/make_unique.h> #include <libaegisub/make_unique.h>
#include <boost/algorithm/string/predicate.hpp> #include <boost/algorithm/string/case_conv.hpp>
TextFileWriter::TextFileWriter(agi::fs::path const& filename, std::string encoding) TextFileWriter::TextFileWriter(agi::fs::path const& filename, std::string encoding)
: file(new agi::io::Save(filename, true)) : file(new agi::io::Save(filename, true))
{ {
if (encoding.empty()) if (encoding.empty())
encoding = OPT_GET("App/Save Charset")->GetString(); 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<agi::charset::IconvWrapper>("utf-8", encoding.c_str(), true); conv = agi::make_unique<agi::charset::IconvWrapper>("utf-8", encoding.c_str(), true);
newline = conv->Convert(newline); newline = conv->Convert(newline);
} }