Skip to content
Snippets Groups Projects
Commit cf9cdd88 authored by Ramin Yaghoubzadeh Torky's avatar Ramin Yaghoubzadeh Torky
Browse files

cpp ATTENTION: Changed semantics for Payload entry casts to bool

For string values, ONLY the empty string "" maps to false
(previously, "false", "False", and "0" also mapped to false)
For list and map values, zero-element ones now map to false
(previously, any list or map would map to true).

The new semantics are identical to Python behavior for your convenience,
since they were not generically prescribed by the STL anyway.
parent 37b70ca0
No related branches found
No related tags found
No related merge requests found
......@@ -153,7 +153,7 @@ IPAACA_EXPORT template<> bool json_value_cast(const rapidjson::Value& v)
{
if (v.IsString()) {
std::string s = v.GetString();
return !((s=="")||(s=="false")||(s=="False")||(s=="0"));
return !(s==""); // NEW: only empty string maps to false
}
if (v.IsBool()) return v.GetBool();
if (v.IsNull()) return false;
......@@ -162,8 +162,10 @@ IPAACA_EXPORT template<> bool json_value_cast(const rapidjson::Value& v)
if (v.IsInt64()) return v.GetInt64() != 0;
if (v.IsUint64()) return v.GetUint64() != 0;
if (v.IsDouble()) return v.GetDouble() != 0.0;
// default: assume "pointer-like" semantics (i.e. objects are TRUE)
return true;
// NEW: empty structures map to false ('Pythonesque' semantics!)
if (v.IsArray()) return v.Size() > 0;
if (v.IsObject()) return v.MemberCount() > 0;
throw NotImplementedError(); // should never be reached anyway
}
//}}}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment