feat: 项目整体命名修改cache-schema-checker
All checks were successful
缓存序列化结构检查 / cache-schema-check (push) Has been skipped
All checks were successful
缓存序列化结构检查 / cache-schema-check (push) Has been skipped
This commit is contained in:
34
src/main/java/com/codechecker/cache/analyze/GlobMatcher.java
vendored
Normal file
34
src/main/java/com/codechecker/cache/analyze/GlobMatcher.java
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user