comparison th_strmatch.c @ 453:efd33accdc81

Break backwards compatibility by renaming BOOL, TRUE and FALSE to lowercase. Introduce optional but default use of stdbool.h.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 02 Jan 2018 22:56:03 +0200
parents 1b3472ba7b23
children 347bfd3e017e
comparison
equal deleted inserted replaced
452:4471eadea472 453:efd33accdc81
4 * (C) Copyright 2002-2017 Tecnic Software productions (TNSP) 4 * (C) Copyright 2002-2017 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;