Mercurial > hg > th-libs
comparison th_strmatch.c @ 457:85fa3d333556
Actually, revert the boolean changes .. meh.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 02 Jan 2018 23:09:29 +0200 |
parents | 347bfd3e017e |
children | e4ce60239d16 |
comparison
equal
deleted
inserted
replaced
456:1bf886fa9db5 | 457:85fa3d333556 |
---|---|
4 * (C) Copyright 2002-2018 Tecnic Software productions (TNSP) | 4 * (C) Copyright 2002-2018 Tecnic Software productions (TNSP) |
5 * | 5 * |
6 * Please read file 'COPYING' for information on license and distribution. | 6 * Please read file 'COPYING' for information on license and distribution. |
7 */ | 7 */ |
8 | 8 |
9 bool TH_STRMATCH_FUNC (const char *haystack, const char *pattern) | 9 BOOL TH_STRMATCH_FUNC (const char *haystack, const char *pattern) |
10 { | 10 { |
11 bool matched = true, any = false, end = false; | 11 BOOL matched = TRUE, any = FALSE, end = FALSE; |
12 const char *tmp = NULL; | 12 const char *tmp = NULL; |
13 | 13 |
14 // Check given pattern and string | 14 // Check given pattern and string |
15 if (haystack == NULL || pattern == NULL) | 15 if (haystack == NULL || pattern == NULL) |
16 return false; | 16 return FALSE; |
17 | 17 |
18 // Start comparision | 18 // Start comparision |
19 while (matched && !end) | 19 while (matched && !end) |
20 switch (*pattern) | 20 switch (*pattern) |
21 { | 21 { |
25 { | 25 { |
26 pattern++; | 26 pattern++; |
27 haystack++; | 27 haystack++; |
28 } | 28 } |
29 else | 29 else |
30 matched = false; | 30 matched = FALSE; |
31 break; | 31 break; |
32 | 32 |
33 case '*': | 33 case '*': |
34 pattern++; | 34 pattern++; |
35 if (!*pattern || *pattern == '?') | 35 if (!*pattern || *pattern == '?') |
36 end = true; | 36 end = TRUE; |
37 any = true; | 37 any = TRUE; |
38 tmp = pattern; | 38 tmp = pattern; |
39 break; | 39 break; |
40 | 40 |
41 case 0: | 41 case 0: |
42 if (any) | 42 if (any) |
43 { | 43 { |
44 if (*haystack) | 44 if (*haystack) |
45 haystack++; | 45 haystack++; |
46 else | 46 else |
47 end = true; | 47 end = TRUE; |
48 } | 48 } |
49 else | 49 else |
50 if (*haystack) | 50 if (*haystack) |
51 { | 51 { |
52 if (tmp) | 52 if (tmp) |
53 { | 53 { |
54 any = true; | 54 any = TRUE; |
55 pattern = tmp; | 55 pattern = tmp; |
56 } | 56 } |
57 else | 57 else |
58 matched = false; | 58 matched = FALSE; |
59 } | 59 } |
60 else | 60 else |
61 end = true; | 61 end = TRUE; |
62 break; | 62 break; |
63 | 63 |
64 default: | 64 default: |
65 if (any) | 65 if (any) |
66 { | 66 { |
67 if (TH_STRMATCH_COLLATE(*pattern) == TH_STRMATCH_COLLATE(*haystack)) | 67 if (TH_STRMATCH_COLLATE(*pattern) == TH_STRMATCH_COLLATE(*haystack)) |
68 { | 68 { |
69 any = false; | 69 any = FALSE; |
70 } | 70 } |
71 else | 71 else |
72 if (*haystack) | 72 if (*haystack) |
73 haystack++; | 73 haystack++; |
74 else | 74 else |
75 matched = false; | 75 matched = FALSE; |
76 } | 76 } |
77 else | 77 else |
78 { | 78 { |
79 if (TH_STRMATCH_COLLATE(*pattern) == TH_STRMATCH_COLLATE(*haystack)) | 79 if (TH_STRMATCH_COLLATE(*pattern) == TH_STRMATCH_COLLATE(*haystack)) |
80 { | 80 { |
84 haystack++; | 84 haystack++; |
85 } | 85 } |
86 else | 86 else |
87 if (tmp) | 87 if (tmp) |
88 { | 88 { |
89 any = true; | 89 any = TRUE; |
90 pattern = tmp; | 90 pattern = tmp; |
91 } | 91 } |
92 else | 92 else |
93 matched = false; | 93 matched = FALSE; |
94 } | 94 } |
95 | 95 |
96 if (!*haystack && !*pattern) | 96 if (!*haystack && !*pattern) |
97 end = true; | 97 end = TRUE; |
98 | 98 |
99 break; | 99 break; |
100 } | 100 } |
101 | 101 |
102 return matched; | 102 return matched; |