@Test public void testGlobToRegex() throws Exception { assertEquals(true, "abc/def".matches(Capsule.globToRegex("abc/def"))); assertEquals(true, "abc/def".matches(Capsule.globToRegex("*/d*"))); assertEquals(true, "abc/def".matches(Capsule.globToRegex("a*/d*"))); assertEquals(true, "abc/def".matches(Capsule.globToRegex("*/*"))); assertEquals(false, "abc/def".matches(Capsule.globToRegex("abc/d"))); assertEquals(false, "abc/def".matches(Capsule.globToRegex("*"))); assertEquals(false, "abc/def".matches(Capsule.globToRegex("d*"))); assertEquals(false, "abc/def".matches(Capsule.globToRegex("abc?d*"))); }
@SuppressWarnings("fallthrough") static String globToRegex(String pattern) { final String DOT = "[^/]"; final StringBuilder sb = new StringBuilder(pattern.length()); int inGroup = 0; int inClass = 0; int firstIndexInClass = -1; char[] arr = pattern.toCharArray(); for (int i = 0; i < arr.length; i++) { char ch = arr[i]; switch (ch) { case '\\': if (++i >= arr.length) { sb.append('\\'); } else { char next = arr[i]; switch (next) { case ',': break; case 'Q': case 'E': sb.append('\\'); default: sb.append('\\'); } sb.append(next); } break; case '*': if (inClass == 0) sb.append(DOT + "*"); else sb.append('*'); break; case '?': if (inClass == 0) sb.append(DOT); else sb.append('?'); break; case '[': inClass++; firstIndexInClass = i + 1; sb.append('['); break; case ']': inClass--; sb.append(']'); break; case '.': case '(': case ')': case '+': case '|': case '^': case '$': case '@': case '%': if (inClass == 0 || (firstIndexInClass == i && ch == '^')) sb.append('\\'); sb.append(ch); break; case '!': if (firstIndexInClass == i) sb.append('^'); else sb.append('!'); break; case '{': inGroup++; sb.append('('); break; case '}': inGroup--; sb.append(')'); break; case ',': if (inGroup > 0) sb.append('|'); else sb.append(','); break; default: sb.append(ch); } } return sb.toString(); }
Capsule implements Runnable, InvocationHandler { @SuppressWarnings("fallthrough") static String globToRegex(String pattern) { final String DOT = "[^/]"; final StringBuilder sb = new StringBuilder(pattern.length()); int inGroup = 0; int inClass = 0; int firstIndexInClass = -1; char[] arr = pattern.toCharArray(); for (int i = 0; i < arr.length; i++) { char ch = arr[i]; switch (ch) { case '\\': if (++i >= arr.length) { sb.append('\\'); } else { char next = arr[i]; switch (next) { case ',': break; case 'Q': case 'E': sb.append('\\'); default: sb.append('\\'); } sb.append(next); } break; case '*': if (inClass == 0) sb.append(DOT + "*"); else sb.append('*'); break; case '?': if (inClass == 0) sb.append(DOT); else sb.append('?'); break; case '[': inClass++; firstIndexInClass = i + 1; sb.append('['); break; case ']': inClass--; sb.append(']'); break; case '.': case '(': case ')': case '+': case '|': case '^': case '$': case '@': case '%': if (inClass == 0 || (firstIndexInClass == i && ch == '^')) sb.append('\\'); sb.append(ch); break; case '!': if (firstIndexInClass == i) sb.append('^'); else sb.append('!'); break; case '{': inGroup++; sb.append('('); break; case '}': inGroup--; sb.append(')'); break; case ',': if (inGroup > 0) sb.append('|'); else sb.append(','); break; default: sb.append(ch); } } return sb.toString(); } }
Capsule implements Runnable, InvocationHandler { @SuppressWarnings("fallthrough") static String globToRegex(String pattern) { final String DOT = "[^/]"; final StringBuilder sb = new StringBuilder(pattern.length()); int inGroup = 0; int inClass = 0; int firstIndexInClass = -1; char[] arr = pattern.toCharArray(); for (int i = 0; i < arr.length; i++) { char ch = arr[i]; switch (ch) { case '\\': if (++i >= arr.length) { sb.append('\\'); } else { char next = arr[i]; switch (next) { case ',': break; case 'Q': case 'E': sb.append('\\'); default: sb.append('\\'); } sb.append(next); } break; case '*': if (inClass == 0) sb.append(DOT + "*"); else sb.append('*'); break; case '?': if (inClass == 0) sb.append(DOT); else sb.append('?'); break; case '[': inClass++; firstIndexInClass = i + 1; sb.append('['); break; case ']': inClass--; sb.append(']'); break; case '.': case '(': case ')': case '+': case '|': case '^': case '$': case '@': case '%': if (inClass == 0 || (firstIndexInClass == i && ch == '^')) sb.append('\\'); sb.append(ch); break; case '!': if (firstIndexInClass == i) sb.append('^'); else sb.append('!'); break; case '{': inGroup++; sb.append('('); break; case '}': inGroup--; sb.append(')'); break; case ',': if (inGroup > 0) sb.append('|'); else sb.append(','); break; default: sb.append(ch); } } return sb.toString(); } @SuppressWarnings({"OverridableMethodCallInConstructor", "LeakingThisInConstructor"}) protected  Capsule(Path jarFile); @SuppressWarnings("LeakingThisInConstructor") protected  Capsule(Capsule pred); }
Capsule implements Runnable, InvocationHandler { @SuppressWarnings("fallthrough") static String globToRegex(String pattern) { final String DOT = "[^/]"; final StringBuilder sb = new StringBuilder(pattern.length()); int inGroup = 0; int inClass = 0; int firstIndexInClass = -1; char[] arr = pattern.toCharArray(); for (int i = 0; i < arr.length; i++) { char ch = arr[i]; switch (ch) { case '\\': if (++i >= arr.length) { sb.append('\\'); } else { char next = arr[i]; switch (next) { case ',': break; case 'Q': case 'E': sb.append('\\'); default: sb.append('\\'); } sb.append(next); } break; case '*': if (inClass == 0) sb.append(DOT + "*"); else sb.append('*'); break; case '?': if (inClass == 0) sb.append(DOT); else sb.append('?'); break; case '[': inClass++; firstIndexInClass = i + 1; sb.append('['); break; case ']': inClass--; sb.append(']'); break; case '.': case '(': case ')': case '+': case '|': case '^': case '$': case '@': case '%': if (inClass == 0 || (firstIndexInClass == i && ch == '^')) sb.append('\\'); sb.append(ch); break; case '!': if (firstIndexInClass == i) sb.append('^'); else sb.append('!'); break; case '{': inGroup++; sb.append('('); break; case '}': inGroup--; sb.append(')'); break; case ',': if (inGroup > 0) sb.append('|'); else sb.append(','); break; default: sb.append(ch); } } return sb.toString(); } @SuppressWarnings({"OverridableMethodCallInConstructor", "LeakingThisInConstructor"}) protected  Capsule(Path jarFile); @SuppressWarnings("LeakingThisInConstructor") protected  Capsule(Capsule pred); static final void main(String[] args); @SuppressWarnings({"BroadCatchBlock", "UnusedAssignment"}) static int main0(String[] args0); static void premain(String agentArgs, Instrumentation inst); static Object getCapsule(String capletClassName); boolean isAgent(); @Override final void run(); @Override Object invoke(Object proxy, Method method, Object[] args); @Override final int hashCode(); @Override final boolean equals(Object obj); @Override String toString(); }
Capsule implements Runnable, InvocationHandler { @SuppressWarnings("fallthrough") static String globToRegex(String pattern) { final String DOT = "[^/]"; final StringBuilder sb = new StringBuilder(pattern.length()); int inGroup = 0; int inClass = 0; int firstIndexInClass = -1; char[] arr = pattern.toCharArray(); for (int i = 0; i < arr.length; i++) { char ch = arr[i]; switch (ch) { case '\\': if (++i >= arr.length) { sb.append('\\'); } else { char next = arr[i]; switch (next) { case ',': break; case 'Q': case 'E': sb.append('\\'); default: sb.append('\\'); } sb.append(next); } break; case '*': if (inClass == 0) sb.append(DOT + "*"); else sb.append('*'); break; case '?': if (inClass == 0) sb.append(DOT); else sb.append('?'); break; case '[': inClass++; firstIndexInClass = i + 1; sb.append('['); break; case ']': inClass--; sb.append(']'); break; case '.': case '(': case ')': case '+': case '|': case '^': case '$': case '@': case '%': if (inClass == 0 || (firstIndexInClass == i && ch == '^')) sb.append('\\'); sb.append(ch); break; case '!': if (firstIndexInClass == i) sb.append('^'); else sb.append('!'); break; case '{': inGroup++; sb.append('('); break; case '}': inGroup--; sb.append(')'); break; case ',': if (inGroup > 0) sb.append('|'); else sb.append(','); break; default: sb.append(ch); } } return sb.toString(); } @SuppressWarnings({"OverridableMethodCallInConstructor", "LeakingThisInConstructor"}) protected  Capsule(Path jarFile); @SuppressWarnings("LeakingThisInConstructor") protected  Capsule(Capsule pred); static final void main(String[] args); @SuppressWarnings({"BroadCatchBlock", "UnusedAssignment"}) static int main0(String[] args0); static void premain(String agentArgs, Instrumentation inst); static Object getCapsule(String capletClassName); boolean isAgent(); @Override final void run(); @Override Object invoke(Object proxy, Method method, Object[] args); @Override final int hashCode(); @Override final boolean equals(Object obj); @Override String toString(); static final String VERSION; }