diff --git a/include/ircd/json/json.h b/include/ircd/json/json.h index cbb73a9c2..c4bc83224 100644 --- a/include/ircd/json/json.h +++ b/include/ircd/json/json.h @@ -78,6 +78,10 @@ namespace ircd::json // Validate JSON - checks if canonical value. bool valid(const string_view &, std::nothrow_t) noexcept; void valid(const string_view &); + + // Convert to canonical JSON + string_view canonize(const mutable_buffer &out, const string_view &in); + std::string canonize(const string_view &in); } /// Strong type representing quoted strings in JSON (which may be unquoted diff --git a/ircd/json.cc b/ircd/json.cc index 31c2a8006..12af82e06 100644 --- a/ircd/json.cc +++ b/ircd/json.cc @@ -1486,6 +1486,28 @@ ircd::json::operator==(const value &a, const value &b) // json.h // +std::string +ircd::json::canonize(const string_view &in) +{ + std::string ret(size(in), char{}); + ret.resize(size(canonize(mutable_buffer{ret}, in))); + return ret; +} + +ircd::string_view +ircd::json::canonize(const mutable_buffer &out, + const string_view &in) +try +{ + //TODO: XXX + assert(0); + return in; +} +catch(const qi::expectation_failure &e) +{ + throw expectation_failure(begin(in), e); +} + bool ircd::json::valid(const string_view &s, std::nothrow_t)