mirror of
https://github.com/matrix-construct/construct
synced 2025-02-18 01:30:12 +01:00
ircd::json: Consolidate validation grammars; optimize for boolean rule.
This commit is contained in:
parent
005d1226b2
commit
6e89ee4289
1 changed files with 24 additions and 10 deletions
34
ircd/json.cc
34
ircd/json.cc
|
@ -3976,6 +3976,24 @@ ircd::json::operator==(const value &a, const value &b)
|
||||||
// json/util.h
|
// json/util.h
|
||||||
//
|
//
|
||||||
|
|
||||||
|
namespace ircd::json
|
||||||
|
{
|
||||||
|
[[gnu::visibility("internal")]] extern const parser::rule<> validation;
|
||||||
|
[[gnu::visibility("internal")]] extern const parser::rule<> validation_expect;
|
||||||
|
}
|
||||||
|
|
||||||
|
decltype(ircd::json::validation)
|
||||||
|
ircd::json::validation
|
||||||
|
{
|
||||||
|
parser.value(0) >> eoi
|
||||||
|
};
|
||||||
|
|
||||||
|
decltype(ircd::json::validation_expect)
|
||||||
|
ircd::json::validation_expect
|
||||||
|
{
|
||||||
|
expect[validation]
|
||||||
|
};
|
||||||
|
|
||||||
const ircd::string_view ircd::json::literal_null { "null" };
|
const ircd::string_view ircd::json::literal_null { "null" };
|
||||||
const ircd::string_view ircd::json::literal_true { "true" };
|
const ircd::string_view ircd::json::literal_true { "true" };
|
||||||
const ircd::string_view ircd::json::literal_false { "false" };
|
const ircd::string_view ircd::json::literal_false { "false" };
|
||||||
|
@ -4011,16 +4029,12 @@ ircd::json::valid(const string_view &s,
|
||||||
std::nothrow_t)
|
std::nothrow_t)
|
||||||
noexcept try
|
noexcept try
|
||||||
{
|
{
|
||||||
static const parser::rule<> validator
|
|
||||||
{
|
|
||||||
parser.value(0) >> eoi
|
|
||||||
};
|
|
||||||
|
|
||||||
const char *start(begin(s)), *const stop(end(s));
|
const char *start(begin(s)), *const stop(end(s));
|
||||||
return qi::parse(start, stop, validator);
|
return qi::parse(start, stop, validation);
|
||||||
}
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
{
|
{
|
||||||
|
assert(false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4028,13 +4042,13 @@ void
|
||||||
ircd::json::valid(const string_view &s)
|
ircd::json::valid(const string_view &s)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
static const parser::rule<> validator
|
const char *start(begin(s)), *const stop(end(s));
|
||||||
|
const bool ret
|
||||||
{
|
{
|
||||||
eps > parser.value(0) > eoi
|
qi::parse(start, stop, validation_expect)
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *start(begin(s)), *const stop(end(s));
|
assert(ret);
|
||||||
qi::parse(start, stop, validator);
|
|
||||||
}
|
}
|
||||||
catch(const qi::expectation_failure<const char *> &e)
|
catch(const qi::expectation_failure<const char *> &e)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue