code: private static int leftmostOuterCurlyContainingSlash(String filePattern,
        int offset) throws IOException {
      int curlyOpen = 0;
      int leftmost = -1;
      boolean seenSlash = false;
      for (int i = offset; i < filePattern.length(); i++) {
        char c = filePattern.charAt(i);
        if (c == '\\') {
          i++;
          if (i >= filePattern.length()) {
            throw new IOException("Illegal file pattern: "
                + "An escaped character does not present for glob "
                + filePattern + " at " + i);
          }
        } else if (c == '{') {
          if (curlyOpen++ == 0) {
            leftmost = i;
          }
        } else if (c == '}' && curlyOpen > 0) {
          if (--curlyOpen == 0 && leftmost != -1 && seenSlash) {
            return leftmost;
          }
        } else if (c == '/' && curlyOpen > 0) {
          seenSlash = true;
        }
      }
      return -1;
    }
docs: Finds the index of the leftmost opening curly bracket containing a
  slash character ("/") in <code>filePattern</code>.
  @param filePattern
  @return the index of the leftmost opening curly bracket containing a
  slash character ("/"), or -1 if there is no such bracket
  @throws IOException