added "ignored" flag in TokenDefinition, parsing token flags now

This commit is contained in:
Josh Holtrop 2010-05-17 15:32:27 -04:00
parent 593c0d6cb6
commit 89a414ff93
2 changed files with 29 additions and 7 deletions

View File

@ -22,19 +22,18 @@ static string trim(string s)
return s;
}
static refptr< vector<string> > split(const string & delim, const string & str)
static refptr< vector<string> > split(const string & delim, string str)
{
refptr< vector<string> > ret = new vector<string>();
string s = str;
size_t pos;
while ( (pos = s.find(delim)) != string::npos )
while ( (pos = str.find(delim)) != string::npos )
{
string t = s.substr(0, pos);
string t = str.substr(0, pos);
ret->push_back(t);
s.erase(0, pos + 1);
str.erase(0, pos + 1);
}
if (s != "")
ret->push_back(s);
if (str != "")
ret->push_back(str);
return ret;
}
@ -50,6 +49,12 @@ static string c_escape(const string & orig)
return result;
}
TokenDefinition::TokenDefinition()
: m_ignored(false)
{
}
bool TokenDefinition::create(const string & name,
const string & definition, const string & flags)
{
@ -67,6 +72,21 @@ bool TokenDefinition::create(const string & name,
pcre_free(re);
refptr< vector< string > > parts = split(",", flags);
for (int i = 0, sz = parts->size(); i < sz; i++)
{
(*parts)[i] = trim((*parts)[i]);
string & s = (*parts)[i];
if (s == "i")
{
m_ignored = true;
}
else
{
cerr << "Unknown token flag \"" << s << "\"" << endl;
return false;
}
}
return true;
}

View File

@ -7,6 +7,7 @@
class TokenDefinition
{
public:
TokenDefinition();
bool create(const std::string & name,
const std::string & definition, const std::string & flags);
std::string getCString() const;
@ -15,6 +16,7 @@ class TokenDefinition
protected:
std::string m_name;
std::string m_definition;
bool m_ignored;
};
#endif