Implement simpleMatch that should be use when pattern contains no flags

This commit is contained in:
Nicolas Le Cam 2008-12-21 23:28:09 +00:00
parent 85e6ab5226
commit 3234322758
2 changed files with 13 additions and 0 deletions

View File

@ -135,6 +135,17 @@ int TOKEN::multiCompare( const char *needle, const char *haystack )
return -1;
}
bool TOKEN::simpleMatch(const TOKEN *tok, const char pattern[])
{
for ( const char *current = pattern, *next = strchr(pattern, ' '), *tmp; *current; current = next,
next = *next ? ((tmp = strchr(++current, ' ')) ? tmp : (current + strlen(current))) : next, tok = tok->next() )
{
if ( !tok || (next-current) != tok->_str.length() || strncmp( current, tok->_cstr, next-current) )
return false;
}
return true;
}
bool TOKEN::Match(const TOKEN *tok, const char pattern[], const char *varname1[], const char *varname2[], unsigned int varid)
{
const char *p = pattern;

View File

@ -54,6 +54,8 @@ public:
const char *strAt(int index) const;
static bool simpleMatch(const TOKEN *tok, const char pattern[]);
/**
* Match given token (or list of tokens) to a pattern list.
*