diff --git a/include/ircd/json/doc.h b/include/ircd/json/doc.h index e48773731..75cf320ba 100644 --- a/include/ircd/json/doc.h +++ b/include/ircd/json/doc.h @@ -52,6 +52,7 @@ struct doc template T at(const string_view &name) const; string_view operator[](const string_view &name) const; template 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 T ircd::json::doc::get(const string_view &name,