From a33a04a39297bcb38c48ee7f809e76ed9d1fd508 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 19 Mar 2021 14:12:09 -0400 Subject: [PATCH] Remove redundant has_next() check in Tokenizer --- src/tokenizer.cpp | 70 ++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 40 deletions(-) diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index 8467d07b95..03fe06080b 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -197,70 +197,60 @@ bool ValueTokenizer::contains(const std::string &value) const { * * \return string with next token */ std::string ValueTokenizer::next_string() { - if (has_next()) { - std::string value = tokens.next(); - return value; - } throw TokenizerException("Not enough tokens",""); + std::string value = tokens.next(); + return value; } /*! Retrieve next token and convert to int * * \return value of next token */ int ValueTokenizer::next_int() { - if (has_next()) { - std::string current = tokens.next(); - if (utils::has_utf8(current)) current = utils::utf8_subst(current); - if (!utils::is_integer(current)) { - throw InvalidIntegerException(current); - } - int value = atoi(current.c_str()); - return value; - } throw TokenizerException("Not enough tokens",""); + std::string current = tokens.next(); + if (utils::has_utf8(current)) current = utils::utf8_subst(current); + if (!utils::is_integer(current)) { + throw InvalidIntegerException(current); + } + int value = atoi(current.c_str()); + return value; } /*! Retrieve next token and convert to bigint * * \return value of next token */ bigint ValueTokenizer::next_bigint() { - if (has_next()) { - std::string current = tokens.next(); - if (utils::has_utf8(current)) current = utils::utf8_subst(current); - if (!utils::is_integer(current)) { - throw InvalidIntegerException(current); - } - bigint value = ATOBIGINT(current.c_str()); - return value; - } throw TokenizerException("Not enough tokens",""); + std::string current = tokens.next(); + if (utils::has_utf8(current)) current = utils::utf8_subst(current); + if (!utils::is_integer(current)) { + throw InvalidIntegerException(current); + } + bigint value = ATOBIGINT(current.c_str()); + return value; } /*! Retrieve next token and convert to tagint * * \return value of next token */ tagint ValueTokenizer::next_tagint() { - if (has_next()) { - std::string current = tokens.next(); - if (utils::has_utf8(current)) current = utils::utf8_subst(current); - if (!utils::is_integer(current)) { - throw InvalidIntegerException(current); - } - tagint value = ATOTAGINT(current.c_str()); - return value; - } throw TokenizerException("Not enough tokens",""); + std::string current = tokens.next(); + if (utils::has_utf8(current)) current = utils::utf8_subst(current); + if (!utils::is_integer(current)) { + throw InvalidIntegerException(current); + } + tagint value = ATOTAGINT(current.c_str()); + return value; } /*! Retrieve next token and convert to double * * \return value of next token */ double ValueTokenizer::next_double() { - if (has_next()) { - std::string current = tokens.next(); - if (utils::has_utf8(current)) current = utils::utf8_subst(current); - if (!utils::is_double(current)) { - throw InvalidFloatException(current); - } - double value = atof(current.c_str()); - return value; - } throw TokenizerException("Not enough tokens",""); + std::string current = tokens.next(); + if (utils::has_utf8(current)) current = utils::utf8_subst(current); + if (!utils::is_double(current)) { + throw InvalidFloatException(current); + } + double value = atof(current.c_str()); + return value; } /*! Skip over a given number of tokens