@Test void charClass() { assertMatch("ab[c]", Arrays.asList("abc"), Arrays.asList("abx", "ab", "abcd", "ab/")); assertMatch("ab[c-e]", Arrays.asList("abc", "abd", "abe"), Arrays.asList("abx", "ab", "abcd", "ab/")); assertMatch("ab[cde]", Arrays.asList("abc", "abd", "abe"), Arrays.asList("abx", "ab", "abcd", "ab/")); assertMatch("ab[!c]", Arrays.asList("abx"), Arrays.asList("abc", "ab", "abcd", "ab/")); assertMatch("[-]", Arrays.asList("-"), Arrays.asList("/", "a", "c")); assertMatch("[-b]", Arrays.asList("-", "b"), Arrays.asList("/", "a", "c")); assertMatch("[b-]", Arrays.asList("-", "b"), Arrays.asList("/", "a", "c")); }
private static int charClass(String glob, int i, int length, StringBuilder result) { result.append("[[^/]&&["); if (i < length && glob.charAt(i) == '!') { i++; result.append('^'); } while (i < length) { char current = glob.charAt(i++); switch (current) { case ']': result.append("]]"); return i; case '-': result.append('-'); break; case '\\': i = unescape(glob, i, length, result, true); break; default: escapeCharClassIfNeeded(current, result); break; } } throw new IllegalStateException(String.format("Missing ] at the end of input in glob %s", glob)); }
GlobUtil { private static int charClass(String glob, int i, int length, StringBuilder result) { result.append("[[^/]&&["); if (i < length && glob.charAt(i) == '!') { i++; result.append('^'); } while (i < length) { char current = glob.charAt(i++); switch (current) { case ']': result.append("]]"); return i; case '-': result.append('-'); break; case '\\': i = unescape(glob, i, length, result, true); break; default: escapeCharClassIfNeeded(current, result); break; } } throw new IllegalStateException(String.format("Missing ] at the end of input in glob %s", glob)); } }
GlobUtil { private static int charClass(String glob, int i, int length, StringBuilder result) { result.append("[[^/]&&["); if (i < length && glob.charAt(i) == '!') { i++; result.append('^'); } while (i < length) { char current = glob.charAt(i++); switch (current) { case ']': result.append("]]"); return i; case '-': result.append('-'); break; case '\\': i = unescape(glob, i, length, result, true); break; default: escapeCharClassIfNeeded(current, result); break; } } throw new IllegalStateException(String.format("Missing ] at the end of input in glob %s", glob)); } private  GlobUtil(); }
GlobUtil { private static int charClass(String glob, int i, int length, StringBuilder result) { result.append("[[^/]&&["); if (i < length && glob.charAt(i) == '!') { i++; result.append('^'); } while (i < length) { char current = glob.charAt(i++); switch (current) { case ']': result.append("]]"); return i; case '-': result.append('-'); break; case '\\': i = unescape(glob, i, length, result, true); break; default: escapeCharClassIfNeeded(current, result); break; } } throw new IllegalStateException(String.format("Missing ] at the end of input in glob %s", glob)); } private  GlobUtil(); static String toRegexPattern(String glob); }
GlobUtil { private static int charClass(String glob, int i, int length, StringBuilder result) { result.append("[[^/]&&["); if (i < length && glob.charAt(i) == '!') { i++; result.append('^'); } while (i < length) { char current = glob.charAt(i++); switch (current) { case ']': result.append("]]"); return i; case '-': result.append('-'); break; case '\\': i = unescape(glob, i, length, result, true); break; default: escapeCharClassIfNeeded(current, result); break; } } throw new IllegalStateException(String.format("Missing ] at the end of input in glob %s", glob)); } private  GlobUtil(); static String toRegexPattern(String glob);  }