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:
parent
8831925837
commit
b850f4875c
@ -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, "");
|
||||
|
Loading…
Reference in New Issue
Block a user