Skip to content

Commit e4dcdff

Browse files
committed
json_cursor_tests
1 parent 0e75a5a commit e4dcdff

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

include/jsoncons/json_cursor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ class basic_json_cursor : public basic_staj_cursor<CharT>, private virtual ser_c
280280
void read_to(basic_json_visitor<CharT>& visitor,
281281
std::error_code& ec) override
282282
{
283-
if (current().event_type() == staj_event_type::begin_object || current().event_type() == staj_event_type::begin_array)
283+
if (is_begin_container(current().event_type()))
284284
{
285285
parser_.cursor_mode(false);
286286
parser_.mark_level(parser_.level());

include/jsoncons/staj_event.hpp

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,35 @@
3535

3636
namespace jsoncons {
3737

38-
enum class staj_event_type
38+
enum class staj_event_type : uint8_t
3939
{
40-
begin_array,
41-
end_array,
42-
begin_object,
43-
end_object,
44-
key,
45-
string_value,
46-
byte_string_value,
47-
null_value,
48-
bool_value,
49-
int64_value,
50-
uint64_value,
51-
half_value,
52-
double_value
40+
key = 0, // 0000
41+
string_value = 1, // 0001
42+
byte_string_value = 2, // 0010
43+
null_value = 3, // 0011
44+
bool_value = 4, // 0100
45+
int64_value = 5, // 0101
46+
uint64_value = 6, // 0110
47+
half_value = 8, // 1000
48+
double_value = 9, // 1001
49+
begin_object = 13, // 1101
50+
end_object = 7, // 0111
51+
begin_array = 14, // 1110
52+
end_array = 15 // 1111
5353
};
5454

55+
inline bool is_begin_container(staj_event_type event_type) noexcept
56+
{
57+
static const uint8_t mask{ uint8_t(staj_event_type::begin_object) & uint8_t(staj_event_type::begin_array) };
58+
return (uint8_t(event_type) & mask) == mask;
59+
}
60+
61+
inline bool is_end_container(staj_event_type event_type) noexcept
62+
{
63+
static const uint8_t mask{ uint8_t(staj_event_type::end_object) & uint8_t(staj_event_type::end_array) };
64+
return (uint8_t(event_type) & mask) == mask;
65+
}
66+
5567
template <typename CharT>
5668
std::basic_ostream<CharT>& operator<<(std::basic_ostream<CharT>& os, staj_event_type tag)
5769
{

0 commit comments

Comments
 (0)