mirror of
https://github.com/matrix-construct/construct
synced 2025-03-14 05:20:17 +01:00
ircd::json: Add a validator suite.
This commit is contained in:
parent
b17293ee86
commit
0e2fe01426
2 changed files with 29 additions and 0 deletions
|
@ -74,6 +74,10 @@ namespace ircd::json
|
|||
|
||||
struct string;
|
||||
using members = std::initializer_list<member>;
|
||||
|
||||
// Validate JSON - checks if canonical value.
|
||||
bool valid(const string_view &, std::nothrow_t) noexcept;
|
||||
void valid(const string_view &);
|
||||
}
|
||||
|
||||
/// Strong type representing quoted strings in JSON (which may be unquoted
|
||||
|
|
25
ircd/json.cc
25
ircd/json.cc
|
@ -1486,6 +1486,31 @@ ircd::json::operator==(const value &a, const value &b)
|
|||
// json.h
|
||||
//
|
||||
|
||||
bool
|
||||
ircd::json::valid(const string_view &s,
|
||||
std::nothrow_t)
|
||||
noexcept try
|
||||
{
|
||||
const char *start(begin(s)), *const stop(end(s));
|
||||
return qi::parse(start, stop, parser.value >> eoi);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
ircd::json::valid(const string_view &s)
|
||||
try
|
||||
{
|
||||
const char *start(begin(s)), *const stop(end(s));
|
||||
qi::parse(start, stop, eps > (parser.value >> eoi));
|
||||
}
|
||||
catch(const qi::expectation_failure<const char *> &e)
|
||||
{
|
||||
throw expectation_failure(begin(s), e);
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::json::stringify(mutable_buffer &buf,
|
||||
const string_view &v)
|
||||
|
|
Loading…
Add table
Reference in a new issue