@VisibleForTesting
  public static String wildcardToRegexp(String globExp) {
    StringBuilder dst = new StringBuilder();
    char[] src = globExp.replace("**/*", "**").toCharArray();
    int i = 0;
    while (i < src.length) {
      char c = src[i++];
      switch (c) {
        case '*':
          // One char lookahead for **
          if (i < src.length && src[i] == '*') {
            dst.append(".*");
            ++i;
          } else {
            dst.append("[^/]*");
          }
          break;
        case '?':
          dst.append("[^/]");
          break;
        case '.':
        case '+':
        case '{':
        case '}':
        case '(':
        case ')':
        case '|':
        case '^':
        case '$':
          // These need to be escaped in regular expressions
          dst.append('\\').append(c);
          break;
        case '\\':
          i = doubleSlashes(dst, src, i);
          break;
        default:
          dst.append(c);
          break;
      }
    }
    return dst.toString();
  }
@Test
  public void testGlobTranslation() {
    assertEquals("foo", wildcardToRegexp("foo"));
    assertEquals("fo[^/]*o", wildcardToRegexp("fo*o"));
    assertEquals("f[^/]*o\\.[^/]", wildcardToRegexp("f*o.?"));
    assertEquals("foo-[0-9][^/]*", wildcardToRegexp("foo-[0-9]*"));
    assertEquals("foo-[0-9].*", wildcardToRegexp("foo-[0-9]**"));
    assertEquals(".*foo", wildcardToRegexp("**/*foo"));
    assertEquals(".*foo", wildcardToRegexp("**foo"));
    assertEquals("foo/[^/]*", wildcardToRegexp("foo/*"));
    assertEquals("foo[^/]*", wildcardToRegexp("foo*"));
    assertEquals("foo/[^/]*/[^/]*/[^/]*", wildcardToRegexp("foo/*/*/*"));
    assertEquals("foo/[^/]*/.*", wildcardToRegexp("foo/*/**"));
    assertEquals("foo.*baz", wildcardToRegexp("foo**baz"));
    assertEquals("foo\\\\", wildcardToRegexp("foo\\"));
    assertEquals("foo/bar\\\\baz[^/]*", wildcardToRegexp("foo/bar\\baz*"));
  }