Fixed compiler warning ( #81 ) and optimized the speed a little. Removed _cstr from Token class, use _str.c_str() instead.

This commit is contained in:
Reijo Tomperi 2009-02-07 21:05:45 +00:00
parent d48671bdfb
commit 811d76eb31
2 changed files with 7 additions and 11 deletions

View File

@ -26,7 +26,6 @@
Token::Token() :
_str(""),
_cstr(0),
_isName(false),
_isNumber(false),
_isBoolean(false),
@ -40,14 +39,12 @@ Token::Token() :
Token::~Token()
{
std::free(_cstr);
}
void Token::str(const char s[])
{
_str = s;
std::free(_cstr);
_cstr = strdup(s);
_isName = bool(_str[0] == '_' || std::isalpha(_str[0]));
_isNumber = bool(std::isdigit(_str[0]) != 0);
if (_str == "true" || _str == "false")
@ -108,7 +105,7 @@ Token *Token::tokAt(int index)
const char *Token::strAt(int index) const
{
const Token *tok = this->tokAt(index);
return tok ? tok->_cstr : "";
return tok ? tok->_str.c_str() : "";
}
int Token::multiCompare(const char *haystack, const char *needle)
@ -191,7 +188,7 @@ bool Token::simpleMatch(const Token *tok, const char pattern[])
{
size_t length = static_cast<size_t>(next - current);
if (!tok || length != tok->_str.length() || strncmp(current, tok->_cstr, length))
if (!tok || length != tok->_str.length() || strncmp(current, tok->_str.c_str(), length))
return false;
current = next;
@ -322,7 +319,7 @@ bool Token::Match(const Token *tok, const char pattern[], unsigned int varid)
// Parse multi options, such as void|int|char (accept token which is one of these 3)
else if (strchr(str, '|') && (str[0] != '|' || strlen(str) > 2))
{
int res = multiCompare(str, tok->_cstr);
int res = multiCompare(str, tok->_str.c_str());
if (res == 0)
{
// Empty alternative matches, use the same token on next round

View File

@ -36,17 +36,17 @@ public:
const char *aaaa() const
{
return _cstr;
return _str.c_str();
}
char aaaa0() const
{
return _cstr[0];
return _str[0];
}
char aaaa1() const
{
return _cstr[1];
return _str[1];
}
/**
@ -190,7 +190,6 @@ private:
void previous(Token *previous);
std::string _str;
char * _cstr;
bool _isName;
bool _isNumber;
bool _isBoolean;