runit

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

pmatch.c (790B)


      1 #include "pmatch.h"
      2 
      3 bool pmatch(const char* p, const char* s, unsigned int len) {
      4   for (;;) {
      5     char c =*p++;
      6     if (! c) return(! len);
      7     switch(c) {
      8     case '*':
      9       if (! (c =*p)) return true;
     10       for (;;) {
     11         if (! len) return false;
     12         if (*s == c) break;
     13         ++s; --len;
     14       }
     15       continue;
     16     case '+':
     17       if ((c =*p++) != *s) return false;
     18       for (;;) {
     19         if (! len) return true;
     20         if (*s != c) break;
     21         ++s; --len;
     22       }
     23       continue;
     24       /*
     25     case '?':
     26       if (*p == '?') {
     27         if (*s != '?') return false;
     28         ++p;
     29       }
     30       ++s; --len;
     31       continue;
     32       */
     33     default:
     34       if (! len) return false;
     35       if (*s != c) return false;
     36       ++s; --len;
     37       continue;
     38     }
     39   }
     40   return false;
     41 }