1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- #ifndef _XS_MATCH_H
- #define _XS_MATCH_H
- int xs_match(const char *str, const char *spec);
- #ifdef XS_IMPLEMENTATION
- int xs_match(const char *str, const char *spec)
- {
- const char *b_str;
- const char *b_spec = NULL;
- const char *o_str = str;
- retry:
- for (;;) {
- const char *q = spec;
- char c = *str++;
- char p = *spec++;
- if (c == '\0') {
-
- if (p == '\0' || p == '|')
- return 1;
- else
- break;
- }
- else
- if (p == '?') {
-
- if (c == '\0')
- return 0;
- }
- else
- if (p == '*') {
-
- if (*spec == '\0')
- return 1;
-
- b_spec = spec;
-
- b_str = --str;
- }
- else {
- if (p == '\\')
- p = *spec++;
- if (c != p) {
-
- if (b_spec) {
-
- spec = b_spec;
- str = ++b_str;
- }
- else {
- if (*q == '|')
- spec = q;
- break;
- }
- }
- }
- }
-
- while (*spec) {
- char p = *spec++;
- if (p == '\\')
- p = *spec++;
- if (p == '|') {
-
- b_spec = NULL;
- str = o_str;
- goto retry;
- }
- }
- return 0;
- }
- #endif
- #endif
|