Match a [...] character class at current position. * Returns true if matched. Advances *pat_out past the closing ']'. */
| 99 | /* Match a [...] character class at current position. |
| 100 | * Returns true if matched. Advances *pat_out past the closing ']'. */ |
| 101 | static bool glob_match_charclass(const char *pat, char ch, const char **pat_out) { |
| 102 | bool negate_class = false; |
| 103 | if (*pat == '!' || *pat == '^') { |
| 104 | negate_class = true; |
| 105 | pat++; |
| 106 | } |
| 107 | bool matched = false; |
| 108 | char prev = 0; |
| 109 | while (*pat && *pat != ']') { |
| 110 | if (*pat == '-' && prev && pat[GI_CHAR_IDX1] && pat[GI_CHAR_IDX1] != ']') { |
| 111 | pat++; |
| 112 | if (ch >= prev && ch <= *pat) { |
| 113 | matched = true; |
| 114 | } |
| 115 | prev = *pat; |
| 116 | pat++; |
| 117 | } else { |
| 118 | if (ch == *pat) { |
| 119 | matched = true; |
| 120 | } |
| 121 | prev = *pat; |
| 122 | pat++; |
| 123 | } |
| 124 | } |
| 125 | if (*pat == ']') { |
| 126 | pat++; |
| 127 | } |
| 128 | *pat_out = pat; |
| 129 | return negate_class ? !matched : matched; |
| 130 | } |
| 131 | |
| 132 | /* |
| 133 | * Match a glob pattern against a string. |