From ff84531ea3a2fa739317cfbe7e48fe4827bbbf1c Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 2 Apr 2017 20:53:56 -0700 Subject: [PATCH] ircd::json: Add get() to doc. --- include/ircd/json/doc.h | 10 ++++++++++ 1 file changed, 10 insertions(+) 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,