diff options
author | Anthony Ramine <n.oxyde@gmail.com> | 2013-05-30 12:19:10 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-06-02 14:13:05 -0700 |
commit | b79c0c3755f3694a3c7ecd3cad18bda011283db7 (patch) | |
tree | 70ad6297951c02a5a2d8ae5a9f1fd06beec704c0 /wildmatch.c | |
parent | edca4152560522a431a51fc0a06147fc680b5b18 (diff) | |
download | git-b79c0c3755f3694a3c7ecd3cad18bda011283db7.tar.gz |
wildmatch: properly fold case everywhere
Case folding is not done correctly when matching against the [:upper:]
character class and uppercased character ranges (e.g. A-Z).
Specifically, an uppercase letter fails to match against any of them
when case folding is requested because plain characters in the pattern
and the whole string are preemptively lowercased to handle the base case
fast.
That optimization is kept and ISLOWER() is used in the [:upper:] case
when case folding is requested, while matching against a character range
is retried with toupper() if the character was lowercase, as the bounds
of the range itself cannot be modified (in a case-insensitive context,
[A-_] is not equivalent to [a-_]).
Signed-off-by: Anthony Ramine <n.oxyde@gmail.com>
Reviewed-by: Duy Nguyen <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'wildmatch.c')
-rw-r--r-- | wildmatch.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/wildmatch.c b/wildmatch.c index 7192bdc1b8..f91ba99f32 100644 --- a/wildmatch.c +++ b/wildmatch.c @@ -196,6 +196,11 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags) } if (t_ch <= p_ch && t_ch >= prev_ch) matched = 1; + else if ((flags & WM_CASEFOLD) && ISLOWER(t_ch)) { + uchar t_ch_upper = toupper(t_ch); + if (t_ch_upper <= p_ch && t_ch_upper >= prev_ch) + matched = 1; + } p_ch = 0; /* This makes "prev_ch" get set to 0. */ } else if (p_ch == '[' && p[1] == ':') { const uchar *s; @@ -245,6 +250,8 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags) } else if (CC_EQ(s,i, "upper")) { if (ISUPPER(t_ch)) matched = 1; + else if ((flags & WM_CASEFOLD) && ISLOWER(t_ch)) + matched = 1; } else if (CC_EQ(s,i, "xdigit")) { if (ISXDIGIT(t_ch)) matched = 1; |