Created
May 31, 2016 06:57
-
-
Save b4284/20833d58ec0d0b31583f1f578cd93e6c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| bool StringMatch(const char *str, size_t strn, | |
| const char *pat, size_t patn) | |
| { | |
| size_t stri = 0; | |
| for (size_t i = 0; i < patn; ++i) { | |
| switch (pat[i]) { | |
| case '?': | |
| if (stri < strn) { | |
| stri += 1; | |
| continue; | |
| } | |
| break; | |
| case '*': | |
| if (i == patn - 1) { | |
| return true; | |
| } else { | |
| const char *strtmp = strchr(str + stri, pat[i + 1]); | |
| while (strtmp != NULL) { | |
| if (StringMatch(strtmp, strn - (strtmp - str), | |
| pat + i + 1, patn - i - 1)) | |
| { | |
| return true; | |
| } else { | |
| strtmp = strchr(strtmp + 1, pat[i + 1]); | |
| continue; | |
| } | |
| } | |
| return false; | |
| } | |
| break; | |
| default: | |
| if (pat[i] == str[stri]) { | |
| stri += 1; | |
| continue; | |
| } else { | |
| return false; | |
| } | |
| break; | |
| } | |
| } | |
| return true; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment