123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #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 (;;) {
- 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
- break;
- }
- }
- }
-
- while (*spec) {
- char p = *spec++;
- if (p == '\\')
- p = *spec++;
- if (p == '|') {
-
- b_spec = NULL;
- str = o_str;
- goto retry;
- }
- }
- return 0;
- }
- #endif
- #endif
|