changed extractUnsigned to handle iterators rather than a string

This commit is contained in:
RJ Catalano 2016-03-07 15:36:25 -06:00 committed by chriseth
parent 2738f4066a
commit 9f5c3977fb
2 changed files with 5 additions and 5 deletions

View File

@ -108,11 +108,11 @@ char const Token::m_tokenType[] =
{ {
TOKEN_LIST(KT, KK) TOKEN_LIST(KT, KK)
}; };
unsigned Token::extractUnsigned(string const& _literal) unsigned Token::extractUnsigned(string::const_iterator const& _begin, string::const_iterator const& _end)
{ {
try try
{ {
unsigned short m = stoi(_literal); unsigned short m = stoi(string(_begin, _end));
return m; return m;
} }
catch(out_of_range& e) catch(out_of_range& e)
@ -131,7 +131,7 @@ tuple<Token::Value, unsigned short, unsigned short> Token::fromIdentifierOrKeywo
{ {
string baseType(_literal.begin(), positionM); string baseType(_literal.begin(), positionM);
auto positionX = find_if_not(positionM, _literal.end(), ::isdigit); auto positionX = find_if_not(positionM, _literal.end(), ::isdigit);
unsigned short m = extractUnsigned(string(positionM, positionX)); unsigned short m = extractUnsigned(positionM, positionX);
Token::Value keyword = keywordByName(baseType); Token::Value keyword = keywordByName(baseType);
if (keyword == Token::Bytes) if (keyword == Token::Bytes)
{ {
@ -151,7 +151,7 @@ tuple<Token::Value, unsigned short, unsigned short> Token::fromIdentifierOrKeywo
else if (keyword == Token::UFixed || keyword == Token::Fixed) else if (keyword == Token::UFixed || keyword == Token::Fixed)
{ {
auto positionN = find_if_not(positionX + 1, _literal.end(), ::isdigit); auto positionN = find_if_not(positionX + 1, _literal.end(), ::isdigit);
unsigned short n = extractUnsigned(string(positionX + 1, positionN)); unsigned short n = extractUnsigned(positionX + 1, positionN);
if ( if (
0 < m + n && 0 < m + n &&
m + n <= 256 && m + n <= 256 &&

View File

@ -310,7 +310,7 @@ private:
// the variable's identity as an identifier. If an invalid conversion // the variable's identity as an identifier. If an invalid conversion
// error is thrown (usually in the case of grabbing N from a fixed type) // error is thrown (usually in the case of grabbing N from a fixed type)
// then a 0 is thrown to purposely ensure that it will declare itself as an identifier // then a 0 is thrown to purposely ensure that it will declare itself as an identifier
static unsigned extractUnsigned(std::string const& _literal); static unsigned extractUnsigned(std::string::const_iterator const& _begin, std::string::const_iterator const& _end);
// @returns the keyword with name @a _name or Token::Identifier of no such keyword exists. // @returns the keyword with name @a _name or Token::Identifier of no such keyword exists.
static Token::Value keywordByName(std::string const& _name); static Token::Value keywordByName(std::string const& _name);
static char const* const m_name[NUM_TOKENS]; static char const* const m_name[NUM_TOKENS];