Skip to content

Commit

Permalink
YAML CPP: Improve array check
Browse files Browse the repository at this point in the history
  • Loading branch information
sanssecours committed Nov 20, 2018
1 parent 5543be3 commit 9820b7e
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions src/plugins/yamlcpp/write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,9 @@ NameIterator relativeKeyIterator (Key const & key, Key const & parent)
std::pair<bool, unsigned long long> isArrayIndex (NameIterator const & nameIterator)
{
string const name = *nameIterator;
if (name.size () < 2 || name.front () != '#') return std::make_pair (false, 0);

auto errnoValue = errno;

try
{
return std::make_pair (true, stoull (name.substr (name.find_first_not_of ("#\\_"))));
}
catch (invalid_argument const &)
{
return std::make_pair (false, 0);
}
catch (out_of_range const &)
{
errno = errnoValue;
return std::make_pair (false, 0);
}
auto const offsetIndex = ckdb::elektraArrayValidateBaseNameString (name.c_str ());
auto const isArrayElement = offsetIndex >= 1;
return { isArrayElement, isArrayElement ? stoull (name.substr (offsetIndex)) : 0 };
}

/**
Expand Down

0 comments on commit 9820b7e

Please sign in to comment.