mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Fix writing escaped string json fields
This commit is contained in:
parent
f2164abf1b
commit
ff18944088
@ -61,17 +61,18 @@ void JsonWriter::writeEntry(JsonVector::const_iterator entry)
|
||||
void JsonWriter::writeString(const std::string &string)
|
||||
{
|
||||
static const std::string escaped = "\"\\\b\f\n\r\t";
|
||||
|
||||
static const std::string escaped_code = "\"\\bfnrt";
|
||||
|
||||
out <<'\"';
|
||||
size_t pos=0, start=0;
|
||||
for (; pos<string.size(); pos++)
|
||||
{
|
||||
size_t escapedChar = escaped.find(string[pos]);
|
||||
size_t escapedPos = escaped.find(string[pos]);
|
||||
|
||||
if (escapedChar != std::string::npos)
|
||||
if (escapedPos != std::string::npos)
|
||||
{
|
||||
out.write(string.data()+start, pos - start);
|
||||
out << '\\' << escaped[escapedChar];
|
||||
out << '\\' << escaped_code[escapedPos];
|
||||
start = pos;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user