From 67793f1aedab8cae956e8df0eec5e6a99f06b87b Mon Sep 17 00:00:00 2001 From: RJ Catalano Date: Tue, 8 Mar 2016 11:23:32 -0600 Subject: [PATCH] changed documentation and using lexical cast --- libsolidity/parsing/Token.cpp | 8 ++------ libsolidity/parsing/Token.h | 6 +----- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/libsolidity/parsing/Token.cpp b/libsolidity/parsing/Token.cpp index 332d27f7a..4f04ea7ab 100644 --- a/libsolidity/parsing/Token.cpp +++ b/libsolidity/parsing/Token.cpp @@ -112,14 +112,10 @@ unsigned Token::extractUnsigned(string::const_iterator const& _begin, string::co { try { - unsigned short m = stoi(string(_begin, _end)); + unsigned short m = boost::lexical_cast(string(_begin, _end)); return m; } - catch(out_of_range& e) - { - return 0; - } - catch (invalid_argument& e) + catch(const boost::bad_lexical_cast &) { return 0; } diff --git a/libsolidity/parsing/Token.h b/libsolidity/parsing/Token.h index fea80ef77..0e5b594c5 100644 --- a/libsolidity/parsing/Token.h +++ b/libsolidity/parsing/Token.h @@ -305,11 +305,7 @@ public: static std::tuple fromIdentifierOrKeyword(std::string const& _literal); private: - // extractUnsigned provides a safe way to extract numbers, - // if out_of_range error is thrown, they returns 0s, therefore securing - // 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) - // then a 0 is thrown to purposely ensure that it will declare itself as an identifier + // @returns 0 on error (invalid digit or number too large) 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. static Token::Value keywordByName(std::string const& _name);