mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 15:33:54 +01:00
ircd::json: Add strict check overload to type() suite.
This commit is contained in:
parent
653c0bc3cc
commit
f6f73e87cb
2 changed files with 50 additions and 1 deletions
|
@ -23,8 +23,11 @@ namespace ircd::json
|
||||||
struct iov;
|
struct iov;
|
||||||
using members = std::initializer_list<const member>;
|
using members = std::initializer_list<const member>;
|
||||||
|
|
||||||
|
IRCD_OVERLOAD(strict)
|
||||||
enum type type(const string_view &);
|
enum type type(const string_view &);
|
||||||
enum type type(const string_view &, std::nothrow_t);
|
enum type type(const string_view &, std::nothrow_t);
|
||||||
|
enum type type(const string_view &, strict_t);
|
||||||
|
enum type type(const string_view &, strict_t, std::nothrow_t);
|
||||||
string_view reflect(const enum type &);
|
string_view reflect(const enum type &);
|
||||||
|
|
||||||
extern const string_view literal_null;
|
extern const string_view literal_null;
|
||||||
|
|
48
ircd/json.cc
48
ircd/json.cc
|
@ -157,7 +157,7 @@ struct ircd::json::input
|
||||||
,"value"
|
,"value"
|
||||||
};
|
};
|
||||||
|
|
||||||
rule<int> type
|
rule<enum json::type> type
|
||||||
{
|
{
|
||||||
(omit[quote] >> attr(json::STRING)) |
|
(omit[quote] >> attr(json::STRING)) |
|
||||||
(omit[object_begin] >> attr(json::OBJECT)) |
|
(omit[object_begin] >> attr(json::OBJECT)) |
|
||||||
|
@ -167,6 +167,16 @@ struct ircd::json::input
|
||||||
,"type"
|
,"type"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
rule<enum json::type> type_strict
|
||||||
|
{
|
||||||
|
(omit[string] >> attr(json::STRING)) |
|
||||||
|
(omit[object(0)] >> attr(json::OBJECT)) |
|
||||||
|
(omit[array(0)] >> attr(json::ARRAY)) |
|
||||||
|
(omit[number] >> attr(json::NUMBER)) |
|
||||||
|
(omit[literal] >> attr(json::LITERAL))
|
||||||
|
,"type"
|
||||||
|
};
|
||||||
|
|
||||||
input()
|
input()
|
||||||
:input::base_type{rule<>{}}
|
:input::base_type{rule<>{}}
|
||||||
{}
|
{}
|
||||||
|
@ -4092,6 +4102,42 @@ ircd::json::serialized(const string_view &v)
|
||||||
// json/json.h
|
// json/json.h
|
||||||
//
|
//
|
||||||
|
|
||||||
|
enum ircd::json::type
|
||||||
|
ircd::json::type(const string_view &buf,
|
||||||
|
strict_t)
|
||||||
|
{
|
||||||
|
static const parser::rule<enum json::type> rule
|
||||||
|
{
|
||||||
|
-parser.ws >> parser.type_strict >> -parser.ws >> eoi
|
||||||
|
};
|
||||||
|
|
||||||
|
enum type ret;
|
||||||
|
if(!qi::parse(begin(buf), end(buf), rule , ret))
|
||||||
|
throw type_error
|
||||||
|
{
|
||||||
|
"Failed to derive JSON value type from input buffer."
|
||||||
|
};
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum ircd::json::type
|
||||||
|
ircd::json::type(const string_view &buf,
|
||||||
|
strict_t,
|
||||||
|
std::nothrow_t)
|
||||||
|
{
|
||||||
|
static const parser::rule<enum json::type> rule
|
||||||
|
{
|
||||||
|
-parser.ws >> parser.type_strict >> -parser.ws >> eoi
|
||||||
|
};
|
||||||
|
|
||||||
|
enum type ret;
|
||||||
|
if(!qi::parse(begin(buf), end(buf), rule, ret))
|
||||||
|
return STRING;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
enum ircd::json::type
|
enum ircd::json::type
|
||||||
ircd::json::type(const string_view &buf)
|
ircd::json::type(const string_view &buf)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue