Skip to content

Commit

Permalink
Fix bug with leading zero detection in arrays.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chase Geigle committed Jan 19, 2017
1 parent e816a41 commit 32e4309
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions include/cpptoml.h
Original file line number Diff line number Diff line change
Expand Up @@ -2080,8 +2080,8 @@ class parser
std::shared_ptr<base> parse_number(std::string::iterator& it,
const std::string::iterator& end)
{
// determine if we are an integer or a float
auto check_it = it;
auto check_end = find_end_of_number(it, end);

auto eat_sign = [&]() {
if (check_it != end && (*check_it == '-' || *check_it == '+'))
Expand All @@ -2108,7 +2108,7 @@ class parser
};

auto check_no_leading_zero = [&]() {
if (check_it != end && *check_it == '0' && check_it + 1 != end
if (check_it != end && *check_it == '0' && check_it + 1 != check_end
&& check_it[1] != '.')
{
throw_parse_exception("Numbers may not have leading zeros");
Expand Down Expand Up @@ -2213,6 +2213,15 @@ class parser
throw_parse_exception("Attempted to parse invalid boolean value");
}

std::string::iterator find_end_of_number(std::string::iterator it,
std::string::iterator end)
{
return std::find_if(it, end, [this](char c) {
return !is_number(c) && c != '_' && c != '.' && c != 'e' && c != 'E'
&& c != '-' && c != '+';
});
}

std::string::iterator find_end_of_date(std::string::iterator it,
std::string::iterator end)
{
Expand Down

0 comments on commit 32e4309

Please sign in to comment.