Files
schemaCheck/src/main/java/com/codechecker/cache/analyze/GlobMatcher.java
dongzi 110beb79c0
All checks were successful
缓存序列化结构检查 / cache-schema-check (push) Has been skipped
feat: 项目整体命名修改cache-schema-checker
2026-07-14 11:03:34 +08:00

35 lines
984 B
Java

package com.codechecker.cache.analyze;
import java.util.regex.Pattern;
/**
* 极简 glob 匹配:{@code *} 与 {@code **} 均匹配任意字符(含空),其余按字面匹配。整串锚定。
*/
public final class GlobMatcher {
private GlobMatcher() {
}
public static boolean matches(String glob, String input) {
if (glob == null || input == null) {
return false;
}
StringBuilder regex = new StringBuilder("^");
int i = 0;
while (i < glob.length()) {
char ch = glob.charAt(i);
if (ch == '*') {
while (i < glob.length() && glob.charAt(i) == '*') {
i++;
}
regex.append(".*");
} else {
regex.append(Pattern.quote(String.valueOf(ch)));
i++;
}
}
regex.append('$');
return Pattern.compile(regex.toString()).matcher(input).matches();
}
}