List of usage examples for java.lang String regionMatches
public boolean regionMatches(int toffset, String other, int ooffset, int len)
From source file:org.ireland.jnetty.dispatch.servlet.ServletMapping.java
/** * Return <code>true</code> if the context-relative request path matches the requirements of the specified filter * mapping; otherwise, return <code>false</code>. * // ww w .j a va 2 s . c o m * * @param requestPath * Context-relative request path of this request(without query String) * * @param urlPattern * URL mapping being checked */ private static boolean matchServletURL(String requestPath, String urlPattern) { if (urlPattern == null) return (false); // Case 1 - Exact Match if (urlPattern.equals(requestPath)) return (true); // Case 2 - Path Match ("/.../*") if (urlPattern.equals("/*")) return (true); if (urlPattern.endsWith("/*")) { if (urlPattern.regionMatches(0, requestPath, 0, urlPattern.length() - 2)) { if (requestPath.length() == (urlPattern.length() - 2)) { return (true); } else if ('/' == requestPath.charAt(urlPattern.length() - 2)) { return (true); } } return (false); } // Case 3 - Extension Match if (urlPattern.startsWith("*.")) { int slash = requestPath.lastIndexOf('/'); int period = requestPath.lastIndexOf('.'); if ((slash >= 0) && (period > slash) && (period != requestPath.length() - 1) && ((requestPath.length() - period) == (urlPattern.length() - 1))) { return (urlPattern.regionMatches(2, requestPath, period + 1, urlPattern.length() - 2)); } } // Case 4 - "Default" Match return (false); // NOTE - Not relevant for selecting filters }
From source file:Main.java
public static String getQueryParameter(String url, String key) { final String encodedKey = key; final int length = url.length(); int start = 0; start = url.indexOf("?") + 1; do {//from w w w . j av a2s .c om int nextAmpersand = url.indexOf('&', start); int end = nextAmpersand != -1 ? nextAmpersand : length; int separator = url.indexOf('=', start); if (separator > end || separator == -1) { separator = end; } if (separator - start == encodedKey.length() && url.regionMatches(start, encodedKey, 0, encodedKey.length())) { if (separator == end) { return ""; } else { return (url.substring(separator + 1, end)); } } // Move start to end of name. if (nextAmpersand != -1) { start = nextAmpersand + 1; } else { break; } } while (true); return null; }
From source file:com.github.chenxiaolong.dualbootpatcher.pathchooser.PathChooserDialog.java
private static boolean mimeMatches(@Nullable String filter, @Nullable String test) { return test != null && (filter == null || "*/*".equals(filter) || filter.equals(test) || (filter.endsWith("/*") && filter.regionMatches(0, test, 0, filter.indexOf('/')))); }
From source file:net.sf.fdshare.BaseProvider.java
static boolean compareMimeTypes(String concreteType, String desiredType) { final int typeLength = desiredType.length(); if (typeLength == 3 && desiredType.equals("*/*")) { return true; }// ww w. jav a2 s . c om final int slashpos = desiredType.indexOf('/'); if (slashpos > 0) { if (typeLength == slashpos + 2 && desiredType.charAt(slashpos + 1) == '*') { if (desiredType.regionMatches(0, concreteType, 0, slashpos + 1)) { return true; } } else if (desiredType.equals(concreteType)) { return true; } } return false; }
From source file:org.ireland.jnetty.dispatch.filter.FilterMapping.java
/** * Return <code>true</code> if the context-relative request path * matches the requirements of the specified filter mapping; * otherwise, return <code>false</code>. * * //from w w w . ja v a2 s . c o m * @param requestPath Context-relative request path of this request(without query String) * * @param urlPattern URL mapping being checked * */ private static boolean matchFiltersURL(String requestPath, String urlPattern) { if (urlPattern == null) return (false); // Case 1 - Exact Match if (urlPattern.equals(requestPath)) return (true); // Case 2 - Path Match ("/.../*") if (urlPattern.equals("/*")) return (true); if (urlPattern.endsWith("/*")) { if (urlPattern.regionMatches(0, requestPath, 0, urlPattern.length() - 2)) { if (requestPath.length() == (urlPattern.length() - 2)) { return (true); } else if ('/' == requestPath.charAt(urlPattern.length() - 2)) { return (true); } } return (false); } // Case 3 - Extension Match if (urlPattern.startsWith("*.")) { int slash = requestPath.lastIndexOf('/'); int period = requestPath.lastIndexOf('.'); if ((slash >= 0) && (period > slash) && (period != requestPath.length() - 1) && ((requestPath.length() - period) == (urlPattern.length() - 1))) { return (urlPattern.regionMatches(2, requestPath, period + 1, urlPattern.length() - 2)); } } // Case 4 - "Default" Match return (false); // NOTE - Not relevant for selecting filters }
From source file:com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocStyleCheck.java
/** * Finds the index of the first non-whitespace character ignoring the * Javadoc comment start and end strings (/** and */) as well as any * leading asterisk./* ww w. j a v a2 s . com*/ * @param line the Javadoc comment line of text to scan. * @return the int index relative to 0 for the start of text * or -1 if not found. */ private static int findTextStart(String line) { int textStart = -1; for (int i = 0; i < line.length();) { if (!Character.isWhitespace(line.charAt(i))) { if (line.regionMatches(i, "/**", 0, "/**".length())) { i += 2; } else if (line.regionMatches(i, "*/", 0, 2)) { i++; } else if (line.charAt(i) != '*') { textStart = i; break; } } i++; } return textStart; }
From source file:org.ireland.jnetty.dispatch.servlet.ServletMapper.java
/** * ??/*from w ww . j a v a 2 s . c o m*/ * * @param requestPath * @param prefixPattern * @return */ private static boolean prefixPatternMatch(String requestPath, String prefixPattern) { if (prefixPattern == null) return (false); // Case 2 - Path Match ("/.../*") if (prefixPattern.equals("/*")) return (true); if (prefixPattern.endsWith("/*")) { if (prefixPattern.regionMatches(0, requestPath, 0, prefixPattern.length() - 2)) { if (requestPath.length() == (prefixPattern.length() - 2)) { return (true); } else if ('/' == requestPath.charAt(prefixPattern.length() - 2)) { return (true); } } return (false); } return (false); }
From source file:net.lightbody.bmp.proxy.jetty.http.PathMap.java
/** * @return true if match.//from ww w . jav a 2 s.c om */ public static boolean match(String pathSpec, String path) throws IllegalArgumentException { char c = pathSpec.charAt(0); if (c == '/') { if (pathSpec.length() == 1 || pathSpec.equals(path)) return true; if (pathSpec.endsWith("/*") && pathSpec.regionMatches(0, path, 0, pathSpec.length() - 2)) return true; if (path.startsWith(pathSpec) && path.charAt(pathSpec.length()) == ';') return true; } else if (c == '*') return path.regionMatches(path.length() - pathSpec.length() + 1, pathSpec, 1, pathSpec.length() - 1); return false; }
From source file:net.lightbody.bmp.proxy.jetty.http.PathMap.java
/** Return the portion of a path that is after a path spec. * @return The path info string//from w ww. ja v a 2 s . com */ public static String pathInfo(String pathSpec, String path) { char c = pathSpec.charAt(0); if (c == '/') { if (pathSpec.length() == 1) return null; if (pathSpec.equals(path)) return null; if (pathSpec.endsWith("/*") && pathSpec.regionMatches(0, path, 0, pathSpec.length() - 2)) { if (path.length() == pathSpec.length() - 2) return null; return path.substring(pathSpec.length() - 2); } } return null; }
From source file:net.lightbody.bmp.proxy.jetty.http.PathMap.java
/** Return the portion of a path that matches a path spec. * @return null if no match at all.//from w ww . j a v a 2s .c o m */ public static String pathMatch(String pathSpec, String path) { char c = pathSpec.charAt(0); if (c == '/') { if (pathSpec.length() == 1) return path; if (pathSpec.equals(path)) return path; if (pathSpec.endsWith("/*") && pathSpec.regionMatches(0, path, 0, pathSpec.length() - 2)) return path.substring(0, pathSpec.length() - 2); if (path.startsWith(pathSpec) && path.charAt(pathSpec.length()) == ';') return path; } else if (c == '*') { if (path.regionMatches(path.length() - (pathSpec.length() - 1), pathSpec, 1, pathSpec.length() - 1)) return path; } return null; }