Fixed JSON library string escape issues.
This commit is contained in:
parent
fe47c9597f
commit
ed7de50138
1 changed files with 7 additions and 6 deletions
13
lib/json.cpp
13
lib/json.cpp
|
@ -52,6 +52,7 @@ std::string JSON::Value::read_string(int separator, std::istream & fromstream){
|
||||||
out += (char)c;
|
out += (char)c;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
escaped = false;
|
||||||
}else{
|
}else{
|
||||||
if (c == separator){
|
if (c == separator){
|
||||||
return out;
|
return out;
|
||||||
|
@ -613,7 +614,7 @@ std::string JSON::Value::toString(){
|
||||||
ObjIter it3 = ObjEnd();
|
ObjIter it3 = ObjEnd();
|
||||||
--it3;
|
--it3;
|
||||||
for (ObjIter it2 = ObjBegin(); it2 != ObjEnd(); it2++){
|
for (ObjIter it2 = ObjBegin(); it2 != ObjEnd(); it2++){
|
||||||
tmp2 += "\"" + it2->first + "\":";
|
tmp2 += string_escape(it2->first)+":";
|
||||||
tmp2 += it2->second.toString();
|
tmp2 += it2->second.toString();
|
||||||
if (it2 != it3){
|
if (it2 != it3){
|
||||||
tmp2 += ",";
|
tmp2 += ",";
|
||||||
|
@ -676,7 +677,7 @@ std::string JSON::Value::toPrettyString(int indentation){
|
||||||
ObjIter it3 = ObjEnd();
|
ObjIter it3 = ObjEnd();
|
||||||
--it3;
|
--it3;
|
||||||
for (ObjIter it2 = ObjBegin(); it2 != ObjEnd(); it2++){
|
for (ObjIter it2 = ObjBegin(); it2 != ObjEnd(); it2++){
|
||||||
tmp2 += (shortMode ? std::string("") : std::string(indentation + 2, ' ')) + "\"" + it2->first + "\":";
|
tmp2 += (shortMode ? std::string("") : std::string(indentation + 2, ' ')) + string_escape(it2->first) + ":";
|
||||||
tmp2 += it2->second.toPrettyString(indentation + 2);
|
tmp2 += it2->second.toPrettyString(indentation + 2);
|
||||||
if (it2 != it3){
|
if (it2 != it3){
|
||||||
tmp2 += "," + std::string((shortMode ? " " : "\n"));
|
tmp2 += "," + std::string((shortMode ? " " : "\n"));
|
||||||
|
@ -859,8 +860,8 @@ JSON::Value JSON::fromDTMI(const unsigned char * data, unsigned int len, unsigne
|
||||||
i += 9; //skip 8(an uint64_t)+1 forwards
|
i += 9; //skip 8(an uint64_t)+1 forwards
|
||||||
uint64_t * d = (uint64_t*)tmpdbl;
|
uint64_t * d = (uint64_t*)tmpdbl;
|
||||||
return JSON::Value((long long int) *d);
|
return JSON::Value((long long int) *d);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 0x02: { //string
|
case 0x02: { //string
|
||||||
if (i+4 >= len){
|
if (i+4 >= len){
|
||||||
return JSON::Value();
|
return JSON::Value();
|
||||||
|
@ -872,8 +873,8 @@ JSON::Value JSON::fromDTMI(const unsigned char * data, unsigned int len, unsigne
|
||||||
}
|
}
|
||||||
i += tmpi + 5; //skip length+size+1 forwards
|
i += tmpi + 5; //skip length+size+1 forwards
|
||||||
return JSON::Value(tmpstr);
|
return JSON::Value(tmpstr);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 0xFF: //also object
|
case 0xFF: //also object
|
||||||
case 0xE0: { //object
|
case 0xE0: { //object
|
||||||
++i;
|
++i;
|
||||||
|
@ -889,8 +890,8 @@ JSON::Value JSON::fromDTMI(const unsigned char * data, unsigned int len, unsigne
|
||||||
}
|
}
|
||||||
i += 3; //skip 0x0000EE
|
i += 3; //skip 0x0000EE
|
||||||
return ret;
|
return ret;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 0x0A: { //array
|
case 0x0A: { //array
|
||||||
JSON::Value ret;
|
JSON::Value ret;
|
||||||
++i;
|
++i;
|
||||||
|
@ -899,8 +900,8 @@ JSON::Value JSON::fromDTMI(const unsigned char * data, unsigned int len, unsigne
|
||||||
}
|
}
|
||||||
i += 3; //skip 0x0000EE
|
i += 3; //skip 0x0000EE
|
||||||
return ret;
|
return ret;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#if DEBUG >= 2
|
#if DEBUG >= 2
|
||||||
fprintf(stderr, "Error: Unimplemented DTMI type %hhx, @ %i / %i - returning.\n", data[i], i, len);
|
fprintf(stderr, "Error: Unimplemented DTMI type %hhx, @ %i / %i - returning.\n", data[i], i, len);
|
||||||
|
|
Loading…
Add table
Reference in a new issue