From 3234322758f3c91d25f6539c283d353e26b5c9b3 Mon Sep 17 00:00:00 2001 From: Nicolas Le Cam Date: Sun, 21 Dec 2008 23:28:09 +0000 Subject: [PATCH] Implement simpleMatch that should be use when pattern contains no flags --- token.cpp | 11 +++++++++++ token.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/token.cpp b/token.cpp index 94198eb81..bf45d3d9b 100644 --- a/token.cpp +++ b/token.cpp @@ -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; diff --git a/token.h b/token.h index 6b51d6cd5..dc771a104 100644 --- a/token.h +++ b/token.h @@ -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. *