annotate 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
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
454
347bfd3e017e Bump copyright years.
Matti Hamalainen <ccr@tnsp.org>
parents: 453
diff changeset
4 * (C) Copyright 2002-2018 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
453
efd33accdc81 Break backwards compatibility by renaming BOOL, TRUE and FALSE to lowercase.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
9 bool TH_STRMATCH_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 {
453
efd33accdc81 Break backwards compatibility by renaming BOOL, TRUE and FALSE to lowercase.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
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)
453
efd33accdc81 Break backwards compatibility by renaming BOOL, TRUE and FALSE to lowercase.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
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
453
efd33accdc81 Break backwards compatibility by renaming BOOL, TRUE and FALSE to lowercase.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
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 == '?')
453
efd33accdc81 Break backwards compatibility by renaming BOOL, TRUE and FALSE to lowercase.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
36 end = true;
efd33accdc81 Break backwards compatibility by renaming BOOL, TRUE and FALSE to lowercase.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
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
453
efd33accdc81 Break backwards compatibility by renaming BOOL, TRUE and FALSE to lowercase.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
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 {
453
efd33accdc81 Break backwards compatibility by renaming BOOL, TRUE and FALSE to lowercase.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
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
453
efd33accdc81 Break backwards compatibility by renaming BOOL, TRUE and FALSE to lowercase.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
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
453
efd33accdc81 Break backwards compatibility by renaming BOOL, TRUE and FALSE to lowercase.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
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 if (any)
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 {
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 if (TH_STRMATCH_COLLATE(*pattern) == TH_STRMATCH_COLLATE(*haystack))
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 {
453
efd33accdc81 Break backwards compatibility by renaming BOOL, TRUE and FALSE to lowercase.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
69 any = false;
414
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 }
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 else
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 if (*haystack)
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 haystack++;
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 else
453
efd33accdc81 Break backwards compatibility by renaming BOOL, TRUE and FALSE to lowercase.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
75 matched = false;
414
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 }
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 else
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 if (TH_STRMATCH_COLLATE(*pattern) == TH_STRMATCH_COLLATE(*haystack))
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 {
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 if (*pattern)
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 pattern++;
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 if (*haystack)
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 haystack++;
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 }
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 else
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 if (tmp)
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 {
453
efd33accdc81 Break backwards compatibility by renaming BOOL, TRUE and FALSE to lowercase.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
89 any = true;
414
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 pattern = tmp;
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 }
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 else
453
efd33accdc81 Break backwards compatibility by renaming BOOL, TRUE and FALSE to lowercase.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
93 matched = false;
414
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 }
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 if (!*haystack && !*pattern)
453
efd33accdc81 Break backwards compatibility by renaming BOOL, TRUE and FALSE to lowercase.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
97 end = true;
414
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 break;
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
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 return matched;
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
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 #undef TH_STRMATCH_FUNC
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 #undef TH_STRMATCH_COLLATE
77fd4f0327dc Split th_str{case}match() into another file to reduce code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108