private @Nullable String matchPrefix(String text, String path, boolean caseSensitive) {
    if (startsWith(text, path, caseSensitive, 0)) {
      return "";
    }
    for (String prefix : prefixes) {
      if (startsWith(text, prefix, caseSensitive, 0)) {
        int prefixLength = prefix.length();
        if (startsWith(text, path, caseSensitive, prefixLength)) {
          return prefix;
        }
        if (text.length() > prefixLength && text.charAt(prefixLength) == '/') {
          if (startsWith(text, path, caseSensitive, prefixLength + 1)) {
            return text.substring(0, prefixLength + 1);
          }
          else if (text.length() > prefixLength + 1 && text.charAt(prefixLength + 1) == '/' &&
                   startsWith(text, path, caseSensitive, prefixLength + 2)) {
            return text.substring(0, prefixLength + 2);
          }
        }
        return null;
      }
    }
    return null;
  }
private @Nullable String matchPrefix(String text, String path, boolean caseSensitive)