/* * wildcharMatcher.cpp * * Created on: Nov 4, 2010 * Author: Miha Vitorovic */ #include #include using std::cout; using namespace epics::pvData; namespace epics { namespace pvAccess { /** Wildchar matcher debug */ const bool WCM_DEBUG = false; /** Value of initial state */ const int WCM_INITIAL = 0; /** Value of final state */ const int WCM_FINAL = 2; /** Value of error state */ const int WCM_ERROR = 99; /** Any character (except control, unless escaped) */ const int WCM_TOKEN_CHAR = 0; /** Token for end of set: ] */ const int WCM_TOKEN_END = 1; /** Token for negation: */ const int WCM_TOKEN_NOT = 2; /** Token for range specification: - */ const int WCM_TOKEN_MINUS = 3; /** * Transition table holds the nextState used in set parsing. Rows define * states, columns define tokens. transitions[1][3] = 5 means: if in state * 1 next token is 3, goto state 5 */ const int TRANSITIONS[][4] = { { 1, WCM_FINAL, 3, 4 }, { 1, WCM_FINAL, WCM_ERROR, 5 }, { WCM_ERROR, WCM_ERROR, WCM_ERROR, WCM_ERROR }, { 1, WCM_FINAL, WCM_ERROR, 4 }, { 6, WCM_ERROR, WCM_ERROR, WCM_ERROR }, { 6, WCM_FINAL, WCM_ERROR, WCM_ERROR }, { 1, WCM_FINAL, WCM_ERROR, WCM_ERROR } }; int getToken(const char ch) { switch(ch) { case ']': return WCM_TOKEN_END; case '!': return WCM_TOKEN_NOT; case '-': return WCM_TOKEN_MINUS; default: return WCM_TOKEN_CHAR; } } bool testSet(const String pattern, int offset, const char ch) { int n = pattern.length(); int state = WCM_INITIAL; int nextToken = ' '; char nextChar = ' '; char ch1 = ' '; bool found = false; bool negate = false; while(!found) { // Check for offset in case of final state, which is over the limit, // if ] is at the end of the string. if(offset=ch1)&&(ch <=nextChar)); // condition ...a-z... if(nextToken==WCM_TOKEN_END) found = (ch>=ch1); // condition ...a-] break; } if(WCM_DEBUG) { cout<<"( "< "<-1)&&(is>-1)&&(ip-1)&&(is>-1)&&(ip