🚨 fixed some more clang-tidy warnings
This commit is contained in:
parent
858e75c4df
commit
3abb788139
6 changed files with 102 additions and 122 deletions
|
@ -286,20 +286,19 @@ class json_sax_dom_parser
|
||||||
root = BasicJsonType(std::forward<Value>(v));
|
root = BasicJsonType(std::forward<Value>(v));
|
||||||
return &root;
|
return &root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(ref_stack.back()->is_array() or ref_stack.back()->is_object());
|
||||||
|
|
||||||
|
if (ref_stack.back()->is_array())
|
||||||
|
{
|
||||||
|
ref_stack.back()->m_value.array->emplace_back(std::forward<Value>(v));
|
||||||
|
return &(ref_stack.back()->m_value.array->back());
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
assert(ref_stack.back()->is_array() or ref_stack.back()->is_object());
|
assert(object_element);
|
||||||
if (ref_stack.back()->is_array())
|
*object_element = BasicJsonType(std::forward<Value>(v));
|
||||||
{
|
return object_element;
|
||||||
ref_stack.back()->m_value.array->emplace_back(std::forward<Value>(v));
|
|
||||||
return &(ref_stack.back()->m_value.array->back());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
assert(object_element);
|
|
||||||
*object_element = BasicJsonType(std::forward<Value>(v));
|
|
||||||
return object_element;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -574,37 +573,37 @@ class json_sax_dom_callback_parser
|
||||||
root = std::move(value);
|
root = std::move(value);
|
||||||
return {true, &root};
|
return {true, &root};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// skip this value if we already decided to skip the parent
|
||||||
|
// (https://github.com/nlohmann/json/issues/971#issuecomment-413678360)
|
||||||
|
if (not ref_stack.back())
|
||||||
|
{
|
||||||
|
return {false, nullptr};
|
||||||
|
}
|
||||||
|
|
||||||
|
// we now only expect arrays and objects
|
||||||
|
assert(ref_stack.back()->is_array() or ref_stack.back()->is_object());
|
||||||
|
|
||||||
|
if (ref_stack.back()->is_array())
|
||||||
|
{
|
||||||
|
ref_stack.back()->m_value.array->push_back(std::move(value));
|
||||||
|
return {true, &(ref_stack.back()->m_value.array->back())};
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// skip this value if we already decided to skip the parent
|
// check if we should store an element for the current key
|
||||||
// (https://github.com/nlohmann/json/issues/971#issuecomment-413678360)
|
assert(not key_keep_stack.empty());
|
||||||
if (not ref_stack.back())
|
const bool store_element = key_keep_stack.back();
|
||||||
|
key_keep_stack.pop_back();
|
||||||
|
|
||||||
|
if (not store_element)
|
||||||
{
|
{
|
||||||
return {false, nullptr};
|
return {false, nullptr};
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(ref_stack.back()->is_array() or ref_stack.back()->is_object());
|
assert(object_element);
|
||||||
if (ref_stack.back()->is_array())
|
*object_element = std::move(value);
|
||||||
{
|
return {true, object_element};
|
||||||
ref_stack.back()->m_value.array->push_back(std::move(value));
|
|
||||||
return {true, &(ref_stack.back()->m_value.array->back())};
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// check if we should store an element for the current key
|
|
||||||
assert(not key_keep_stack.empty());
|
|
||||||
const bool store_element = key_keep_stack.back();
|
|
||||||
key_keep_stack.pop_back();
|
|
||||||
|
|
||||||
if (not store_element)
|
|
||||||
{
|
|
||||||
return {false, nullptr};
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(object_element);
|
|
||||||
*object_element = std::move(value);
|
|
||||||
return {true, object_element};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1214,13 +1214,11 @@ scan_number_done:
|
||||||
// check if we completely parse the BOM
|
// check if we completely parse the BOM
|
||||||
return get() == 0xBB and get() == 0xBF;
|
return get() == 0xBB and get() == 0xBF;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
// the first character is not the beginning of the BOM; unget it to
|
||||||
// the first character is not the beginning of the BOM; unget it to
|
// process is later
|
||||||
// process is later
|
unget();
|
||||||
unget();
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
token_type scan()
|
token_type scan()
|
||||||
|
|
|
@ -201,12 +201,9 @@ class parser
|
||||||
m_lexer.get_token_string(),
|
m_lexer.get_token_string(),
|
||||||
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string)));
|
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string)));
|
||||||
}
|
}
|
||||||
else
|
if (JSON_UNLIKELY(not sax->key(m_lexer.get_string())))
|
||||||
{
|
{
|
||||||
if (JSON_UNLIKELY(not sax->key(m_lexer.get_string())))
|
return false;
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse separator (:)
|
// parse separator (:)
|
||||||
|
|
|
@ -851,22 +851,20 @@ class binary_writer
|
||||||
{
|
{
|
||||||
return 'i';
|
return 'i';
|
||||||
}
|
}
|
||||||
else if ((std::numeric_limits<uint8_t>::min)() <= j.m_value.number_integer and j.m_value.number_integer <= (std::numeric_limits<uint8_t>::max)())
|
if ((std::numeric_limits<uint8_t>::min)() <= j.m_value.number_integer and j.m_value.number_integer <= (std::numeric_limits<uint8_t>::max)())
|
||||||
{
|
{
|
||||||
return 'U';
|
return 'U';
|
||||||
}
|
}
|
||||||
else if ((std::numeric_limits<int16_t>::min)() <= j.m_value.number_integer and j.m_value.number_integer <= (std::numeric_limits<int16_t>::max)())
|
if ((std::numeric_limits<int16_t>::min)() <= j.m_value.number_integer and j.m_value.number_integer <= (std::numeric_limits<int16_t>::max)())
|
||||||
{
|
{
|
||||||
return 'I';
|
return 'I';
|
||||||
}
|
}
|
||||||
else if ((std::numeric_limits<int32_t>::min)() <= j.m_value.number_integer and j.m_value.number_integer <= (std::numeric_limits<int32_t>::max)())
|
if ((std::numeric_limits<int32_t>::min)() <= j.m_value.number_integer and j.m_value.number_integer <= (std::numeric_limits<int32_t>::max)())
|
||||||
{
|
{
|
||||||
return 'l';
|
return 'l';
|
||||||
}
|
}
|
||||||
else // no check and assume int64_t (see note above)
|
// no check and assume int64_t (see note above)
|
||||||
{
|
return 'L';
|
||||||
return 'L';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case value_t::number_unsigned:
|
case value_t::number_unsigned:
|
||||||
|
@ -875,22 +873,20 @@ class binary_writer
|
||||||
{
|
{
|
||||||
return 'i';
|
return 'i';
|
||||||
}
|
}
|
||||||
else if (j.m_value.number_unsigned <= (std::numeric_limits<uint8_t>::max)())
|
if (j.m_value.number_unsigned <= (std::numeric_limits<uint8_t>::max)())
|
||||||
{
|
{
|
||||||
return 'U';
|
return 'U';
|
||||||
}
|
}
|
||||||
else if (j.m_value.number_unsigned <= (std::numeric_limits<int16_t>::max)())
|
if (j.m_value.number_unsigned <= (std::numeric_limits<int16_t>::max)())
|
||||||
{
|
{
|
||||||
return 'I';
|
return 'I';
|
||||||
}
|
}
|
||||||
else if (j.m_value.number_unsigned <= (std::numeric_limits<int32_t>::max)())
|
if (j.m_value.number_unsigned <= (std::numeric_limits<int32_t>::max)())
|
||||||
{
|
{
|
||||||
return 'l';
|
return 'l';
|
||||||
}
|
}
|
||||||
else // no check and assume int64_t (see note above)
|
// no check and assume int64_t (see note above)
|
||||||
{
|
return 'L';
|
||||||
return 'L';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case value_t::number_float:
|
case value_t::number_float:
|
||||||
|
|
|
@ -7289,11 +7289,9 @@ class basic_json
|
||||||
// avoid undefined behavior
|
// avoid undefined behavior
|
||||||
JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range"));
|
JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range"));
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
// default case: insert add offset
|
||||||
// default case: insert add offset
|
parent.insert(parent.begin() + static_cast<difference_type>(idx), val);
|
||||||
parent.insert(parent.begin() + static_cast<difference_type>(idx), val);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3483,13 +3483,11 @@ scan_number_done:
|
||||||
// check if we completely parse the BOM
|
// check if we completely parse the BOM
|
||||||
return get() == 0xBB and get() == 0xBF;
|
return get() == 0xBB and get() == 0xBF;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
// the first character is not the beginning of the BOM; unget it to
|
||||||
// the first character is not the beginning of the BOM; unget it to
|
// process is later
|
||||||
// process is later
|
unget();
|
||||||
unget();
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
token_type scan()
|
token_type scan()
|
||||||
|
@ -4048,20 +4046,19 @@ class json_sax_dom_parser
|
||||||
root = BasicJsonType(std::forward<Value>(v));
|
root = BasicJsonType(std::forward<Value>(v));
|
||||||
return &root;
|
return &root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(ref_stack.back()->is_array() or ref_stack.back()->is_object());
|
||||||
|
|
||||||
|
if (ref_stack.back()->is_array())
|
||||||
|
{
|
||||||
|
ref_stack.back()->m_value.array->emplace_back(std::forward<Value>(v));
|
||||||
|
return &(ref_stack.back()->m_value.array->back());
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
assert(ref_stack.back()->is_array() or ref_stack.back()->is_object());
|
assert(object_element);
|
||||||
if (ref_stack.back()->is_array())
|
*object_element = BasicJsonType(std::forward<Value>(v));
|
||||||
{
|
return object_element;
|
||||||
ref_stack.back()->m_value.array->emplace_back(std::forward<Value>(v));
|
|
||||||
return &(ref_stack.back()->m_value.array->back());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
assert(object_element);
|
|
||||||
*object_element = BasicJsonType(std::forward<Value>(v));
|
|
||||||
return object_element;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4336,37 +4333,37 @@ class json_sax_dom_callback_parser
|
||||||
root = std::move(value);
|
root = std::move(value);
|
||||||
return {true, &root};
|
return {true, &root};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// skip this value if we already decided to skip the parent
|
||||||
|
// (https://github.com/nlohmann/json/issues/971#issuecomment-413678360)
|
||||||
|
if (not ref_stack.back())
|
||||||
|
{
|
||||||
|
return {false, nullptr};
|
||||||
|
}
|
||||||
|
|
||||||
|
// we now only expect arrays and objects
|
||||||
|
assert(ref_stack.back()->is_array() or ref_stack.back()->is_object());
|
||||||
|
|
||||||
|
if (ref_stack.back()->is_array())
|
||||||
|
{
|
||||||
|
ref_stack.back()->m_value.array->push_back(std::move(value));
|
||||||
|
return {true, &(ref_stack.back()->m_value.array->back())};
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// skip this value if we already decided to skip the parent
|
// check if we should store an element for the current key
|
||||||
// (https://github.com/nlohmann/json/issues/971#issuecomment-413678360)
|
assert(not key_keep_stack.empty());
|
||||||
if (not ref_stack.back())
|
const bool store_element = key_keep_stack.back();
|
||||||
|
key_keep_stack.pop_back();
|
||||||
|
|
||||||
|
if (not store_element)
|
||||||
{
|
{
|
||||||
return {false, nullptr};
|
return {false, nullptr};
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(ref_stack.back()->is_array() or ref_stack.back()->is_object());
|
assert(object_element);
|
||||||
if (ref_stack.back()->is_array())
|
*object_element = std::move(value);
|
||||||
{
|
return {true, object_element};
|
||||||
ref_stack.back()->m_value.array->push_back(std::move(value));
|
|
||||||
return {true, &(ref_stack.back()->m_value.array->back())};
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// check if we should store an element for the current key
|
|
||||||
assert(not key_keep_stack.empty());
|
|
||||||
const bool store_element = key_keep_stack.back();
|
|
||||||
key_keep_stack.pop_back();
|
|
||||||
|
|
||||||
if (not store_element)
|
|
||||||
{
|
|
||||||
return {false, nullptr};
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(object_element);
|
|
||||||
*object_element = std::move(value);
|
|
||||||
return {true, object_element};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4654,12 +4651,9 @@ class parser
|
||||||
m_lexer.get_token_string(),
|
m_lexer.get_token_string(),
|
||||||
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string)));
|
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string)));
|
||||||
}
|
}
|
||||||
else
|
if (JSON_UNLIKELY(not sax->key(m_lexer.get_string())))
|
||||||
{
|
{
|
||||||
if (JSON_UNLIKELY(not sax->key(m_lexer.get_string())))
|
return false;
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse separator (:)
|
// parse separator (:)
|
||||||
|
@ -18392,11 +18386,9 @@ class basic_json
|
||||||
// avoid undefined behavior
|
// avoid undefined behavior
|
||||||
JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range"));
|
JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range"));
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
// default case: insert add offset
|
||||||
// default case: insert add offset
|
parent.insert(parent.begin() + static_cast<difference_type>(idx), val);
|
||||||
parent.insert(parent.begin() + static_cast<difference_type>(idx), val);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue