mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-27 08:29:26 -05:00
added string escape in SuperEasyJSON serialization
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8218 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
a126461beb
commit
744f340746
@ -501,6 +501,7 @@ void Object::Clear()
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
std::string SerializeArray(const Array& a);
|
||||
static std::string EscapeJSONString(const std::string& in);
|
||||
|
||||
std::string SerializeValue(const Value& v)
|
||||
{
|
||||
@ -517,7 +518,7 @@ std::string SerializeValue(const Value& v)
|
||||
case NULLVal : str = "null"; break;
|
||||
case ObjectVal : str = Serialize(v); break;
|
||||
case ArrayVal : str = SerializeArray(v); break;
|
||||
case StringVal : str = std::string("\"") + (std::string)v + std::string("\""); break;
|
||||
case StringVal : str = "\"" + EscapeJSONString((std::string)v) + "\""; break;
|
||||
}
|
||||
|
||||
return str;
|
||||
@ -543,6 +544,30 @@ std::string SerializeArray(const Array& a)
|
||||
return str;
|
||||
}
|
||||
|
||||
// in can be utf-8
|
||||
static std::string EscapeJSONString(const std::string &in)
|
||||
{
|
||||
std::string out = "";
|
||||
|
||||
for (std::string::size_type i = 0; i < in.length(); i++)
|
||||
{
|
||||
switch (in[i])
|
||||
{
|
||||
case '"' : out += "\\\""; break;
|
||||
case '\\' : out += "\\\\"; break;
|
||||
case '/' : out += "\\/"; break;
|
||||
case '\t' : out += "\\t"; break;
|
||||
case '\n' : out += "\\n"; break;
|
||||
case '\r' : out += "\\r"; break;
|
||||
case '\b' : out += "\\b"; break;
|
||||
case '\f' : out += "\\f"; break;
|
||||
default : out += in[i]; break;
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
std::string json::Serialize(const Value& v)
|
||||
{
|
||||
std::string str;
|
||||
|
Loading…
Reference in New Issue
Block a user