Mercurial > hg > th-libs
view th_strmatch.c @ 454:347bfd3e017e
Bump copyright years.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 02 Jan 2018 22:57:02 +0200 |
parents | efd33accdc81 |
children | 85fa3d333556 |
line wrap: on
line source
/* * String glob match implementation * Programmed and designed by Matti 'ccr' Hamalainen * (C) Copyright 2002-2018 Tecnic Software productions (TNSP) * * Please read file 'COPYING' for information on license and distribution. */ bool TH_STRMATCH_FUNC (const char *haystack, const char *pattern) { bool matched = true, any = false, end = false; const char *tmp = NULL; // Check given pattern and string if (haystack == NULL || pattern == NULL) return false; // Start comparision while (matched && !end) switch (*pattern) { case '?': // Any single character matches if (*haystack) { pattern++; haystack++; } else matched = false; break; case '*': pattern++; if (!*pattern || *pattern == '?') end = true; any = true; tmp = pattern; break; case 0: if (any) { if (*haystack) haystack++; else end = true; } else if (*haystack) { if (tmp) { any = true; pattern = tmp; } else matched = false; } else end = true; break; default: if (any) { if (TH_STRMATCH_COLLATE(*pattern) == TH_STRMATCH_COLLATE(*haystack)) { any = false; } else if (*haystack) haystack++; else matched = false; } else { if (TH_STRMATCH_COLLATE(*pattern) == TH_STRMATCH_COLLATE(*haystack)) { if (*pattern) pattern++; if (*haystack) haystack++; } else if (tmp) { any = true; pattern = tmp; } else matched = false; } if (!*haystack && !*pattern) end = true; break; } return matched; } #undef TH_STRMATCH_FUNC #undef TH_STRMATCH_COLLATE