mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2025-02-16 23:27:17 +02:00
change implementation of optionalValueAt
This commit is contained in:
parent
aa438b8fba
commit
bb939d3772
2 changed files with 5 additions and 7 deletions
|
@ -30,14 +30,12 @@ const nlohmann::json & valueAt(
|
||||||
return map.at(key);
|
return map.at(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<nlohmann::json> optionalValueAt(const nlohmann::json & value, const std::string & key)
|
std::optional<nlohmann::json> optionalValueAt(const nlohmann::json::object_t & map, const std::string & key)
|
||||||
{
|
{
|
||||||
try {
|
if (!map.contains(key))
|
||||||
auto & v = valueAt(value, key);
|
|
||||||
return v.get<nlohmann::json>();
|
|
||||||
} catch (...) {
|
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
|
||||||
|
return std::optional { map.at(key) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ const nlohmann::json & valueAt(
|
||||||
const nlohmann::json::object_t & map,
|
const nlohmann::json::object_t & map,
|
||||||
const std::string & key);
|
const std::string & key);
|
||||||
|
|
||||||
std::optional<nlohmann::json> optionalValueAt(const nlohmann::json & value, const std::string & key);
|
std::optional<nlohmann::json> optionalValueAt(const nlohmann::json::object_t & value, const std::string & key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Downcast the json object, failing with a nice error if the conversion fails.
|
* Downcast the json object, failing with a nice error if the conversion fails.
|
||||||
|
|
Loading…
Add table
Reference in a new issue