0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 12:12:15 +02:00

jsonhelper : added json::get_string_optional() method.

This commit is contained in:
James Yonan 2016-07-27 22:30:28 -07:00 committed by Lev Stipakov
parent 8831925837
commit b850f4875c
No known key found for this signature in database
GPG Key ID: 88670BE258B9C258

View File

@ -88,6 +88,23 @@ namespace openvpn {
dest = value.asString();
}
static void to_string_optional(const Json::Value& root,
std::string& dest,
const std::string& name,
const std::string& default_value,
const std::string& title)
{
const Json::Value& value = root[name];
if (value.isNull())
{
dest = default_value;
return;
}
if (!value.isString())
OPENVPN_THROW(json_parse, "string " << fmt_name(name, title) << " is of incorrect type");
dest = value.asString();
}
static void to_int(const Json::Value& root, int& dest, const std::string& name, const std::string& title)
{
const Json::Value& value = root[name];
@ -157,6 +174,16 @@ namespace openvpn {
return ret;
}
static std::string get_string_optional(const Json::Value& root,
const std::string& name,
const std::string& default_value,
const std::string& title)
{
std::string ret;
to_string_optional(root, ret, name, default_value, title);
return ret;
}
static std::string get_string(const Json::Value& root, const std::string& name)
{
return get_string(root, name, "");