Ejemplo n.º 1
0
 string Tokenizer::nextToken() {
     string result = "";
     size_t len = source.length();
     // skip leading whitespace
     while (pos < len && isSeperator(source[pos])) {
         pos++;
     }
     // gather a token
     while (pos < len && !isSeperator(source[pos])) {
         result += source[pos++];
     }
     return result;
 }
Ejemplo n.º 2
0
/*
   test if a given string  and a pattern  matches use adblock plus rule
   give a string s and a pattern p ,
   if they match,return 1, then return 0
   */
static bool adbMatch(const char *  s,  const char *  p,bool caseSensitivie) {
    for (;;) {
        switch(*p++) {
            case '*' :	// match 0-n of any characters
                if (!*p) return true; // do trailing * quickly
                while (!adbMatch(s, p,caseSensitivie))
                {
#if 0
                     if (!*s++) return 0;
#else
                    if(!*s) return false;
                    s+=patternStep(s,p);
#endif
                }
                return true;
            case '^':
                if(isSeperator(*s))
                {
                    s++;
                    break;
                }
                else
                    return false;//expect a sepetor,
            case '\0':	// end of pattern
                return !*s;
			case '?':
				s++;
				break;
            default  :
                if (getCaseChar(*s++,caseSensitivie) !=
                    getCaseChar(*(p-1),caseSensitivie)) return false;
                break;
        }
    }
}