1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 10:41:16 +02:00

Get rid of most .at calls (#6393)

Use one of `get` or `getOr` instead which will either return a null-pointer (with a nicer error message) or a default value when the key is missing.
This commit is contained in:
Alain Zscheile 2022-05-04 07:44:32 +02:00 committed by GitHub
parent 9489b4b7ef
commit 1385b20078
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 231 additions and 118 deletions

View file

@ -1586,6 +1586,20 @@ std::string stripIndentation(std::string_view s)
}
const nlohmann::json * get(const nlohmann::json & map, const std::string & key)
{
auto i = map.find(key);
if (i == map.end()) return nullptr;
return &*i;
}
nlohmann::json * get(nlohmann::json & map, const std::string & key)
{
auto i = map.find(key);
if (i == map.end()) return nullptr;
return &*i;
}
//////////////////////////////////////////////////////////////////////