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(); } }