mirror of
https://github.com/boostorg/json.git
synced 2026-02-13 00:22:21 +00:00
basic_parser improvement
This commit is contained in:
@@ -34,8 +34,10 @@ class basic_parser
|
||||
|
||||
detail::static_stack<state, 1024> st_;
|
||||
detail::number_parser iep_;
|
||||
std::size_t depth_;
|
||||
std::size_t depth_ = 0;
|
||||
std::size_t max_depth_ = 32;
|
||||
char const* lit_;
|
||||
error ev_;
|
||||
long u0_;
|
||||
unsigned short u_;
|
||||
bool is_key_;
|
||||
@@ -48,11 +50,35 @@ public:
|
||||
// link errors on some older toolchains.
|
||||
}
|
||||
|
||||
/// Returns `true` if the parser has completed without error
|
||||
/** Return true if a complete JSON has been parsed.
|
||||
|
||||
This function returns `true` when all of these
|
||||
conditions are met:
|
||||
|
||||
@li A complete serialized JSON has been
|
||||
presented to the parser, and
|
||||
|
||||
@li No error has occurred since the parser
|
||||
was constructed, or since the last call
|
||||
to @ref reset,
|
||||
|
||||
@par Complexity
|
||||
|
||||
Constant.
|
||||
*/
|
||||
bool
|
||||
is_done() const noexcept
|
||||
{
|
||||
return st_.size() == 1;
|
||||
return static_cast<
|
||||
char>(*st_) == 0;
|
||||
}
|
||||
|
||||
/** Returns the current depth of the JSON being parsed.
|
||||
*/
|
||||
std::size_t
|
||||
depth() const noexcept
|
||||
{
|
||||
return depth_;
|
||||
}
|
||||
|
||||
/** Returns the maximum allowed depth of input JSON.
|
||||
@@ -71,12 +97,6 @@ public:
|
||||
max_depth_ = levels;
|
||||
}
|
||||
|
||||
/** Reset the state, to parse a new document.
|
||||
*/
|
||||
BOOST_JSON_DECL
|
||||
void
|
||||
reset() noexcept;
|
||||
|
||||
BOOST_JSON_DECL
|
||||
std::size_t
|
||||
write_some(
|
||||
@@ -100,6 +120,12 @@ protected:
|
||||
BOOST_JSON_DECL
|
||||
basic_parser();
|
||||
|
||||
/** Reset the state, to parse a new document.
|
||||
*/
|
||||
BOOST_JSON_DECL
|
||||
void
|
||||
reset() noexcept;
|
||||
|
||||
virtual
|
||||
void
|
||||
on_document_begin(
|
||||
|
||||
@@ -259,7 +259,16 @@ loop:
|
||||
st_ = state::exp1;
|
||||
goto loop;
|
||||
}
|
||||
n_.u = m;
|
||||
if(m <= INT64_MAX)
|
||||
{
|
||||
n_.i = static_cast<
|
||||
int64_t>(m);
|
||||
}
|
||||
else
|
||||
{
|
||||
n_.u = m;
|
||||
n_.kind = kind::uint64;
|
||||
}
|
||||
st_ = state::done;
|
||||
goto finish;
|
||||
}
|
||||
@@ -546,7 +555,8 @@ write(
|
||||
if(! ec)
|
||||
{
|
||||
if(n < size)
|
||||
ec = error::illegal_extra_chars;
|
||||
n += write_some(
|
||||
data + n, size - n, ec);
|
||||
}
|
||||
if(! ec)
|
||||
write_eof(ec);
|
||||
|
||||
@@ -58,6 +58,18 @@ public:
|
||||
return *top_;
|
||||
}
|
||||
|
||||
T&
|
||||
operator*() noexcept
|
||||
{
|
||||
return *top_;
|
||||
}
|
||||
|
||||
T const&
|
||||
operator*() const noexcept
|
||||
{
|
||||
return *top_;
|
||||
}
|
||||
|
||||
// capacity
|
||||
|
||||
bool
|
||||
|
||||
@@ -55,6 +55,10 @@ enum class error
|
||||
/// illegal trailing surrogate
|
||||
illegal_trailing_surrogate,
|
||||
|
||||
/** The parser needs a reset.
|
||||
*/
|
||||
need_reset,
|
||||
|
||||
/// expected comma
|
||||
expected_comma,
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -44,6 +44,7 @@ make_error_code(error e)
|
||||
case error::illegal_extra_chars: return "illegal extra characters";
|
||||
case error::illegal_leading_surrogate: return "illegal leading surrogate";
|
||||
case error::illegal_trailing_surrogate: return "illegal trailing surrogate";
|
||||
case error::need_reset: return "need reset";
|
||||
|
||||
case error::expected_comma: return "expected comma";
|
||||
case error::expected_colon: return "expected colon";
|
||||
@@ -66,6 +67,7 @@ make_error_code(error e)
|
||||
case error::integer_overflow: return "integer overflowed";
|
||||
|
||||
case error::key_not_found: return "key not found";
|
||||
|
||||
case error::test_failure: return "test failure";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user