mirror of
https://github.com/tristanpenman/valijson.git
synced 2024-12-12 10:13:51 +01:00
Update RapidJsonAdapter to be compatible with both embedded and latest versions of RapidJSON
This commit is contained in:
parent
d538c698c9
commit
9cd913a5cd
@ -219,6 +219,11 @@ class RapidJsonFrozenValue: public FrozenValue
|
||||
{
|
||||
public:
|
||||
|
||||
RapidJsonFrozenValue(const std::string &str)
|
||||
{
|
||||
value.SetString(str.c_str(), (unsigned int)str.length(), allocator);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Make a copy of a RapidJson value
|
||||
*
|
||||
@ -757,10 +762,29 @@ inline RapidJsonObjectMemberIterator RapidJsonObject::end() const
|
||||
inline RapidJsonObjectMemberIterator RapidJsonObject::find(
|
||||
const std::string &propertyName) const
|
||||
{
|
||||
const rapidjson::Value::ConstMemberIterator
|
||||
itr = value.FindMember(propertyName.c_str());
|
||||
const rapidjson::Value::ConstMemberIterator foundItr =
|
||||
value.FindMember(propertyName.c_str());
|
||||
|
||||
return itr ? itr : value.MemberEnd();
|
||||
// Hack to support older versions of rapidjson that use pointers as the
|
||||
// built in iterator type. In those versions, the FindMember function
|
||||
// would return a null pointer when the requested member could not be
|
||||
// found. After calling FindMember on an empty object, we compare the
|
||||
// result against what we would expect if a non-null-pointer iterator was
|
||||
// returned.
|
||||
//
|
||||
// Note that this value cannot be stored statically, as that would not be
|
||||
// thread-safe. If there were performance measurements to justify it, this
|
||||
// could be cached in the RapidJsonObject instance.
|
||||
//
|
||||
const rapidjson::Value empty(rapidjson::kObjectType);
|
||||
const rapidjson::Value::ConstMemberIterator maybeEnd = empty.FindMember("");
|
||||
if (maybeEnd != empty.MemberBegin() + 1) {
|
||||
// At this point, we assume that a null pointer iterator has been
|
||||
// returned by FindMember for any member that cannot be found.
|
||||
return foundItr == maybeEnd ? value.MemberEnd() : foundItr;
|
||||
}
|
||||
|
||||
return foundItr;
|
||||
}
|
||||
|
||||
} // namespace adapters
|
||||
|
Loading…
Reference in New Issue
Block a user