Slightly optimize AssDialogue serialization
This commit is contained in:
parent
3844a1cb80
commit
6c0752035c
2 changed files with 15 additions and 15 deletions
|
@ -41,7 +41,6 @@
|
|||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/algorithm/string/join.hpp>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <boost/algorithm/string/trim.hpp>
|
||||
#include <boost/lexical_cast.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) {
|
||||
if (str.find(',') == str.npos)
|
||||
out += str;
|
||||
for (auto c : str) {
|
||||
if (c == ',')
|
||||
out += ';';
|
||||
else
|
||||
out += boost::replace_all_copy(str, ",", ";");
|
||||
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;
|
||||
|
|
|
@ -27,14 +27,15 @@
|
|||
#include <libaegisub/charset_conv.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)
|
||||
: 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<agi::charset::IconvWrapper>("utf-8", encoding.c_str(), true);
|
||||
newline = conv->Convert(newline);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue