annotate th_strglob.c @ 722:4ca6a3b30fe8

Bump copyright years.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 02 Jan 2021 11:35:54 +0200
parents b87395754c8d
children 29e44a58bc73
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
414
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * String glob match implementation
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Programmed and designed by Matti 'ccr' Hamalainen
722
4ca6a3b30fe8 Bump copyright years.
Matti Hamalainen <ccr@tnsp.org>
parents: 615
diff changeset
4 * (C) Copyright 2002-2021 Tecnic Software productions (TNSP)
414
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 *
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 * Please read file 'COPYING' for information on license and distribution.
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 */
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8
593
1a33088e7fa9 Rename some internal preprocessor macros.
Matti Hamalainen <ccr@tnsp.org>
parents: 553
diff changeset
9 BOOL TH_STRGLOB_FUNC (const char *haystack, const char *pattern)
414
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 {
457
85fa3d333556 Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents: 454
diff changeset
11 BOOL matched = TRUE, any = FALSE, end = FALSE;
414
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 const char *tmp = NULL;
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 // Check given pattern and string
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 if (haystack == NULL || pattern == NULL)
457
85fa3d333556 Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents: 454
diff changeset
16 return FALSE;
414
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 // Start comparision
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 while (matched && !end)
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 switch (*pattern)
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 {
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 case '?':
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 // Any single character matches
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 if (*haystack)
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 {
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 pattern++;
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 haystack++;
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 }
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 else
457
85fa3d333556 Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents: 454
diff changeset
30 matched = FALSE;
414
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 break;
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 case '*':
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 pattern++;
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 if (!*pattern || *pattern == '?')
457
85fa3d333556 Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents: 454
diff changeset
36 end = TRUE;
85fa3d333556 Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents: 454
diff changeset
37 any = TRUE;
414
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 tmp = pattern;
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 break;
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 case 0:
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 if (any)
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 {
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 if (*haystack)
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 haystack++;
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 else
457
85fa3d333556 Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents: 454
diff changeset
47 end = TRUE;
414
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 }
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 else
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 if (*haystack)
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 {
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 if (tmp)
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 {
457
85fa3d333556 Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents: 454
diff changeset
54 any = TRUE;
414
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 pattern = tmp;
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 }
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 else
457
85fa3d333556 Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents: 454
diff changeset
58 matched = FALSE;
414
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 }
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 else
457
85fa3d333556 Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents: 454
diff changeset
61 end = TRUE;
414
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 break;
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 default:
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 {
615
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
66 BOOL equals = TH_STRGLOB_COLLATE(*pattern) == TH_STRGLOB_COLLATE(*haystack);
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
67 if (any)
414
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 {
615
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
69 if (equals)
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
70 {
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
71 any = FALSE;
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
72 }
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
73 else
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
74 if (*haystack)
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
75 haystack++;
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
76 else
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
77 matched = FALSE;
414
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 }
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 else
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 {
615
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
81 if (equals)
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
82 {
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
83 if (*pattern)
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
84 pattern++;
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
85 if (*haystack)
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
86 haystack++;
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
87 }
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
88 else
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
89 if (tmp)
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
90 {
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
91 any = TRUE;
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
92 pattern = tmp;
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
93 }
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
94 else
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
95 matched = FALSE;
414
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 }
615
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
97
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
98 if (!*haystack && !*pattern)
b87395754c8d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 606
diff changeset
99 end = TRUE;
414
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 }
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 break;
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 }
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 return matched;
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 }
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107
593
1a33088e7fa9 Rename some internal preprocessor macros.
Matti Hamalainen <ccr@tnsp.org>
parents: 553
diff changeset
108 #undef TH_STRGLOB_FUNC
1a33088e7fa9 Rename some internal preprocessor macros.
Matti Hamalainen <ccr@tnsp.org>
parents: 553
diff changeset
109 #undef TH_STRGLOB_COLLATE
414
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110