mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-23 00:28:08 +02:00
Fix writing escaped string json fields
This commit is contained in:
@ -61,17 +61,18 @@ void JsonWriter::writeEntry(JsonVector::const_iterator entry)
|
|||||||
void JsonWriter::writeString(const std::string &string)
|
void JsonWriter::writeString(const std::string &string)
|
||||||
{
|
{
|
||||||
static const std::string escaped = "\"\\\b\f\n\r\t";
|
static const std::string escaped = "\"\\\b\f\n\r\t";
|
||||||
|
static const std::string escaped_code = "\"\\bfnrt";
|
||||||
|
|
||||||
out <<'\"';
|
out <<'\"';
|
||||||
size_t pos=0, start=0;
|
size_t pos=0, start=0;
|
||||||
for (; pos<string.size(); pos++)
|
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.write(string.data()+start, pos - start);
|
||||||
out << '\\' << escaped[escapedChar];
|
out << '\\' << escaped_code[escapedPos];
|
||||||
start = pos;
|
start = pos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user