changed documentation and using lexical cast

This commit is contained in:
RJ Catalano 2016-03-08 11:23:32 -06:00 committed by chriseth
parent 9f5c3977fb
commit 67793f1aed
2 changed files with 3 additions and 11 deletions

View File

@ -112,14 +112,10 @@ unsigned Token::extractUnsigned(string::const_iterator const& _begin, string::co
{ {
try try
{ {
unsigned short m = stoi(string(_begin, _end)); unsigned short m = boost::lexical_cast<unsigned short>(string(_begin, _end));
return m; return m;
} }
catch(out_of_range& e) catch(const boost::bad_lexical_cast &)
{
return 0;
}
catch (invalid_argument& e)
{ {
return 0; return 0;
} }

View File

@ -305,11 +305,7 @@ public:
static std::tuple<Token::Value, unsigned short, unsigned short> fromIdentifierOrKeyword(std::string const& _literal); static std::tuple<Token::Value, unsigned short, unsigned short> fromIdentifierOrKeyword(std::string const& _literal);
private: private:
// extractUnsigned provides a safe way to extract numbers, // @returns 0 on error (invalid digit or number too large)
// 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
static unsigned extractUnsigned(std::string::const_iterator const& _begin, std::string::const_iterator const& _end); 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);