fixed buffer overrun and removed redundant function Token::str

This commit is contained in:
Daniel Marjamäki 2009-11-28 09:48:43 +01:00
parent 67f5d666c7
commit 3db49aee71
2 changed files with 9 additions and 7 deletions

15
lib/token.cpp Normal file → Executable file
View File

@ -48,8 +48,16 @@ Token::~Token()
void Token::str(const std::string &s)
{
_str = s;
_isName = bool(_str[0] == '_' || std::isalpha(_str[0]));
_isNumber = bool(std::isdigit(_str[(_str[0] == '-') ? 1 : 0]) != 0);
if (std::isdigit(_str[0]))
_isNumber = true;
else if (_str.length() > 1 && _str[0] == '-' && std::isdigit(_str[0]))
_isNumber = true;
else
_isNumber = false;
if (_str == "true" || _str == "false")
_isBoolean = true;
else
@ -58,11 +66,6 @@ void Token::str(const std::string &s)
_varId = 0;
}
void Token::str(const char s[])
{
str(std::string(s));
}
void Token::concatStr(std::string const& b)
{
_str.erase(_str.length() - 1);

1
lib/token.h Normal file → Executable file
View File

@ -42,7 +42,6 @@ public:
~Token();
void str(const std::string &s);
void str(const char s[]);
void concatStr(std::string const& b);