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; 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>(); refptr< vector<string> > ret = new vector<string>();
string s = str;
size_t pos; 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); ret->push_back(t);
s.erase(0, pos + 1); str.erase(0, pos + 1);
} }
if (s != "") if (str != "")
ret->push_back(s); ret->push_back(str);
return ret; return ret;
} }
@ -50,6 +49,12 @@ static string c_escape(const string & orig)
return result; return result;
} }
TokenDefinition::TokenDefinition()
: m_ignored(false)
{
}
bool TokenDefinition::create(const string & name, bool TokenDefinition::create(const string & name,
const string & definition, const string & flags) const string & definition, const string & flags)
{ {
@ -67,6 +72,21 @@ bool TokenDefinition::create(const string & name,
pcre_free(re); pcre_free(re);
refptr< vector< string > > parts = split(",", flags); 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; return true;
} }

View File

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