wildmatch: make dowild() take arbitrary flags
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Jan 1, 2013 at 09:44 UTC
0c528168dadd4209de0213a16ff811a89ee3f206
1 file changed
+6
-7
wildmatch.c
+6
-7
@@ -52,7 +52,7 @@ typedef unsigned char uchar;
52
#define ISXDIGIT(c) (ISASCII(c) && isxdigit(c))
53
54
/* Match pattern "p" against "text" */
55
-static int dowild(const uchar *p, const uchar *text, int force_lower_case)
55
+static int dowild(const uchar *p, const uchar *text, unsigned int flags)
56
{
57
uchar p_ch;
58
const uchar *pattern = p;
@@ -62,9 +62,9 @@ static int dowild(const uchar *p, const uchar *text, int force_lower_case)
62
uchar t_ch, prev_ch;
63
if ((t_ch = *text) == '\0' && p_ch != '*')
64
return WM_ABORT_ALL;
65
- if (force_lower_case && ISUPPER(t_ch))
65
+ if ((flags & WM_CASEFOLD) && ISUPPER(t_ch))
66
t_ch = tolower(t_ch);
67
- if (force_lower_case && ISUPPER(p_ch))
67
+ if ((flags & WM_CASEFOLD) && ISUPPER(p_ch))
68
p_ch = tolower(p_ch);
69
switch (p_ch) {
70
case '\\':
@@ -98,7 +98,7 @@ static int dowild(const uchar *p, const uchar *text, int force_lower_case)
98
* both foo/bar and foo/a/bar.
99
*/
100
if (p[0] == '/' &&
101
- dowild(p + 1, text, force_lower_case) == WM_MATCH)
101
+ dowild(p + 1, text, flags) == WM_MATCH)
102
return WM_MATCH;
103
match_slash = 1;
104
} else
@@ -117,7 +117,7 @@ static int dowild(const uchar *p, const uchar *text, int force_lower_case)
117
while (1) {
118
if (t_ch == '\0')
119
break;
120
- if ((matched = dowild(p, text, force_lower_case)) != WM_NOMATCH) {
120
+ if ((matched = dowild(p, text, flags)) != WM_NOMATCH) {
121
if (!match_slash || matched != WM_ABORT_TO_STARSTAR)
122
return matched;
123
} else if (!match_slash && t_ch == '/')
@@ -228,6 +228,5 @@ static int dowild(const uchar *p, const uchar *text, int force_lower_case)
228
int wildmatch(const char *pattern, const char *text,
229
unsigned int flags, struct wildopts *wo)
230
{
231
- return dowild((const uchar*)pattern, (const uchar*)text,
232
- flags & WM_CASEFOLD ? 1 :0);
231
+ return dowild((const uchar*)pattern, (const uchar*)text, flags);
232
}