mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-20 20:34:25 -04: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
1 changed files with 26 additions and 1 deletions
|
@ -501,6 +501,7 @@ void Object::Clear()
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
std::string SerializeArray(const Array& a);
|
std::string SerializeArray(const Array& a);
|
||||||
|
static std::string EscapeJSONString(const std::string& in);
|
||||||
|
|
||||||
std::string SerializeValue(const Value& v)
|
std::string SerializeValue(const Value& v)
|
||||||
{
|
{
|
||||||
|
@ -517,7 +518,7 @@ std::string SerializeValue(const Value& v)
|
||||||
case NULLVal : str = "null"; break;
|
case NULLVal : str = "null"; break;
|
||||||
case ObjectVal : str = Serialize(v); break;
|
case ObjectVal : str = Serialize(v); break;
|
||||||
case ArrayVal : str = SerializeArray(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;
|
return str;
|
||||||
|
@ -543,6 +544,30 @@ std::string SerializeArray(const Array& a)
|
||||||
return str;
|
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 json::Serialize(const Value& v)
|
||||||
{
|
{
|
||||||
std::string str;
|
std::string str;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue