code: private static boolean translate(String glob, StringBuilder result) {
          int i;
          int max;
          char c;
          int j;
          String stuff;
          int escaped;
          
          escaped = 0;
          max = glob.length();
          for (i = 0; i < max;) {
              c = glob.charAt(i++);
              if (c == '*') {
                  result.append(".*");
              } else if (c == '?') {
                  result.append('.');
              } else if (c == '[') {
                  j = i;
                  if (j < max && glob.charAt(j) == '!') {
                      j++;
                  }
                  if (j < max && glob.charAt(j) == ']') {
                      j++;
                  }
                  while (j < max && glob.charAt(j) != ']') {
                      j++;
                  }
                  if (j >= max) {
                      result.append("\\[");
                  } else {
                      stuff = glob.substring(i, j);
                      stuff = Strings.replace(stuff, "\\", "\\\\");
                      i = j+1;
                      if (stuff.charAt(0) == '!') {
                          stuff = '^' + stuff.substring(1);
                      } else if (stuff.charAt(0) == '^') {
                          stuff = '\\' + stuff;
                      }
                      result.append('[');
                      result.append(stuff);
                      result.append(']');
                  }
              } else {
              	escaped++;
                  result.append(escape(c));
              }
          }
          result.append('$');
          return escaped == max;
      }
docs: Translate a glob PATTERN to a regular expression.