Skip to content

Commit

Permalink
Merge pull request nlohmann#36 from nlohmann/develop
Browse files Browse the repository at this point in the history
Sync Fork from Upstream Repo
  • Loading branch information
sthagen authored Feb 3, 2021
2 parents e17fed9 + 6d4eed5 commit 6416d5e
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 132 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1638,4 +1638,6 @@ In case you have downloaded the library rather than checked out the code via Git

Some tests change the installed files and hence make the whole process not reproducible. Please execute `ctest -LE not_reproducible` to skip these tests. See [issue #2324](https://github.com/nlohmann/json/issues/2324) for more information.

Note you need to call `cmake -LE "not_reproducible|git_required"` to exclude both labels. See [issue #2596](https://github.com/nlohmann/json/issues/2596) for more information.

As Intel compilers use unsafe floating point optimization by default, the unit tests may fail. Use flag [`/fp:precise`](https://software.intel.com/content/www/us/en/develop/documentation/cpp-compiler-developer-guide-and-reference/top/compiler-reference/compiler-options/compiler-option-details/floating-point-options/fp-model-fp.html) then.
24 changes: 11 additions & 13 deletions include/nlohmann/detail/conversions/to_chars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,51 +490,49 @@ inline int find_largest_pow10(const std::uint32_t n, std::uint32_t& pow10)
return 10;
}
// LCOV_EXCL_STOP
else if (n >= 100000000)
if (n >= 100000000)
{
pow10 = 100000000;
return 9;
}
else if (n >= 10000000)
if (n >= 10000000)
{
pow10 = 10000000;
return 8;
}
else if (n >= 1000000)
if (n >= 1000000)
{
pow10 = 1000000;
return 7;
}
else if (n >= 100000)
if (n >= 100000)
{
pow10 = 100000;
return 6;
}
else if (n >= 10000)
if (n >= 10000)
{
pow10 = 10000;
return 5;
}
else if (n >= 1000)
if (n >= 1000)
{
pow10 = 1000;
return 4;
}
else if (n >= 100)
if (n >= 100)
{
pow10 = 100;
return 3;
}
else if (n >= 10)
if (n >= 10)
{
pow10 = 10;
return 2;
}
else
{
pow10 = 1;
return 1;
}

pow10 = 1;
return 1;
}

inline void grisu2_round(char* buf, int len, std::uint64_t dist, std::uint64_t delta,
Expand Down
6 changes: 2 additions & 4 deletions include/nlohmann/detail/input/input_adapters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,8 @@ class iterator_input_adapter
std::advance(current, 1);
return result;
}
else
{
return std::char_traits<char_type>::eof();
}

return std::char_traits<char_type>::eof();
}

private:
Expand Down
92 changes: 46 additions & 46 deletions include/nlohmann/detail/input/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,62 +393,62 @@ class parser
parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::end_array, "array")));
}
else // object
{
// comma -> next value
if (get_token() == token_type::value_separator)
{
// parse key
if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string))
{
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::value_string, "object key")));
}

if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
{
return false;
}
// states.back() is false -> object

// parse separator (:)
if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
{
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::name_separator, "object separator")));
}
// comma -> next value
if (get_token() == token_type::value_separator)
{
// parse key
if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string))
{
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::value_string, "object key")));
}

// parse values
get_token();
continue;
if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
{
return false;
}

// closing }
if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object))
// parse separator (:)
if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
{
if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
{
return false;
}
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::name_separator, "object separator")));
}

// We are done with this object. Before we can parse a
// new value, we need to evaluate the new state first.
// By setting skip_to_state_evaluation to false, we
// are effectively jumping to the beginning of this if.
JSON_ASSERT(!states.empty());
states.pop_back();
skip_to_state_evaluation = true;
continue;
// parse values
get_token();
continue;
}

// closing }
if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object))
{
if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
{
return false;
}

return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::end_object, "object")));
// We are done with this object. Before we can parse a
// new value, we need to evaluate the new state first.
// By setting skip_to_state_evaluation to false, we
// are effectively jumping to the beginning of this if.
JSON_ASSERT(!states.empty());
states.pop_back();
skip_to_state_evaluation = true;
continue;
}

return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::end_object, "object")));
}
}

Expand Down
2 changes: 1 addition & 1 deletion include/nlohmann/detail/iterators/iteration_proxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ template<typename IteratorType> class iteration_proxy_value
/// a string representation of the array index
mutable string_type array_index_str = "0";
/// an empty string (to return a reference for primitive values)
const string_type empty_str = "";
const string_type empty_str{};

public:
explicit iteration_proxy_value(IteratorType it) noexcept : anchor(it) {}
Expand Down
124 changes: 60 additions & 64 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3944,7 +3944,7 @@ template<typename IteratorType> class iteration_proxy_value
/// a string representation of the array index
mutable string_type array_index_str = "0";
/// an empty string (to return a reference for primitive values)
const string_type empty_str = "";
const string_type empty_str{};

public:
explicit iteration_proxy_value(IteratorType it) noexcept : anchor(it) {}
Expand Down Expand Up @@ -4947,10 +4947,8 @@ class iterator_input_adapter
std::advance(current, 1);
return result;
}
else
{
return std::char_traits<char_type>::eof();
}

return std::char_traits<char_type>::eof();
}

private:
Expand Down Expand Up @@ -10618,62 +10616,62 @@ class parser
parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::end_array, "array")));
}
else // object
{
// comma -> next value
if (get_token() == token_type::value_separator)
{
// parse key
if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string))
{
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::value_string, "object key")));
}

if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
{
return false;
}
// states.back() is false -> object

// parse separator (:)
if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
{
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::name_separator, "object separator")));
}
// comma -> next value
if (get_token() == token_type::value_separator)
{
// parse key
if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string))
{
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::value_string, "object key")));
}

// parse values
get_token();
continue;
if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
{
return false;
}

// closing }
if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object))
// parse separator (:)
if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
{
if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
{
return false;
}
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::name_separator, "object separator")));
}

// We are done with this object. Before we can parse a
// new value, we need to evaluate the new state first.
// By setting skip_to_state_evaluation to false, we
// are effectively jumping to the beginning of this if.
JSON_ASSERT(!states.empty());
states.pop_back();
skip_to_state_evaluation = true;
continue;
// parse values
get_token();
continue;
}

// closing }
if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object))
{
if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
{
return false;
}

return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::end_object, "object")));
// We are done with this object. Before we can parse a
// new value, we need to evaluate the new state first.
// By setting skip_to_state_evaluation to false, we
// are effectively jumping to the beginning of this if.
JSON_ASSERT(!states.empty());
states.pop_back();
skip_to_state_evaluation = true;
continue;
}

return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::end_object, "object")));
}
}

Expand Down Expand Up @@ -14948,51 +14946,49 @@ inline int find_largest_pow10(const std::uint32_t n, std::uint32_t& pow10)
return 10;
}
// LCOV_EXCL_STOP
else if (n >= 100000000)
if (n >= 100000000)
{
pow10 = 100000000;
return 9;
}
else if (n >= 10000000)
if (n >= 10000000)
{
pow10 = 10000000;
return 8;
}
else if (n >= 1000000)
if (n >= 1000000)
{
pow10 = 1000000;
return 7;
}
else if (n >= 100000)
if (n >= 100000)
{
pow10 = 100000;
return 6;
}
else if (n >= 10000)
if (n >= 10000)
{
pow10 = 10000;
return 5;
}
else if (n >= 1000)
if (n >= 1000)
{
pow10 = 1000;
return 4;
}
else if (n >= 100)
if (n >= 100)
{
pow10 = 100;
return 3;
}
else if (n >= 10)
if (n >= 10)
{
pow10 = 10;
return 2;
}
else
{
pow10 = 1;
return 1;
}

pow10 = 1;
return 1;
}

inline void grisu2_round(char* buf, int len, std::uint64_t dist, std::uint64_t delta,
Expand Down
Loading

0 comments on commit 6416d5e

Please sign in to comment.