mirror of
https://github.com/matrix-construct/construct
synced 2024-12-27 07:54:05 +01:00
ircd::json: Add get<string_view>() to doc.
This commit is contained in:
parent
49da778def
commit
ff84531ea3
1 changed files with 10 additions and 0 deletions
|
@ -52,6 +52,7 @@ struct doc
|
|||
template<class T> T at(const string_view &name) const;
|
||||
string_view operator[](const string_view &name) const;
|
||||
template<class T = string_view> T get(const string_view &name, const T &def = T()) const;
|
||||
string_view get(const string_view &name, const string_view &def = {}) const;
|
||||
|
||||
explicit operator std::string() const;
|
||||
|
||||
|
@ -116,6 +117,15 @@ struct doc::const_iterator
|
|||
} // namespace json
|
||||
} // namespace ircd
|
||||
|
||||
inline ircd::string_view
|
||||
ircd::json::doc::get(const string_view &name,
|
||||
const string_view &def)
|
||||
const
|
||||
{
|
||||
const string_view sv(operator[](name));
|
||||
return !sv.empty()? sv : def;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T
|
||||
ircd::json::doc::get(const string_view &name,
|
||||
|
|
Loading…
Reference in a new issue