/** * Gets the set of unique path parameters used in the given URI. If a parameter is used twice * in the URI, it will only show up once in the set. */ static Set<String> parsePathParameters(String path) { Matcher m = PARAM_URL_REGEX.matcher(path); Set<String> patterns = new LinkedHashSet<>(); while (m.find()) { patterns.add(m.group(1)); } return patterns; }
/** * Returns a new {@code MatchResult} that corresponds to a successful match. Apache Harmony (used * in Android) requires a successful match in order to generate a {@code MatchResult}: * http://goo.gl/5VQFmC */ private static MatchResult newMatchResult() { Matcher matcher = Pattern.compile(".").matcher("X"); matcher.find(); return matcher.toMatchResult(); }
private static void assertContainsRegex(String expectedRegex, String actual) { Pattern pattern = Pattern.compile(expectedRegex); Matcher matcher = pattern.matcher(actual); if (!matcher.find()) { String actualDesc = (actual == null) ? "null" : ('<' + actual + '>'); fail("expected to contain regex:<" + expectedRegex + "> but was:" + actualDesc); } } }
/** * Checks to see if the supplied {@code String} has any placeholders * that are not specified as constants on this class and throws an * {@code IllegalArgumentException} if so. */ private void checkForInvalidPlaceholders(String message) throws IllegalArgumentException { Matcher matcher = PATTERN.matcher(message); while (matcher.find()) { String match = matcher.group(); if (!ALLOWED_PLACEHOLDERS.contains(match)) { throw new IllegalArgumentException("Placeholder [" + match + "] is not valid"); } } }
public Set<String> extractUrlVariableNames(String uriTemplate) { Set<String> variableNames = new HashSet<>(); boolean hasValueInAnnotation = uriTemplate != null; if (hasValueInAnnotation) { Matcher m = NAMES_PATTERN.matcher(uriTemplate); while (m.find()) { variableNames.add(m.group(1)); } } return variableNames; }
static String getContentTypeEncoding(final String httpContentType) { String encoding = null; if (httpContentType != null) { final int i = httpContentType.indexOf(";"); if (i > -1) { final String postMime = httpContentType.substring(i + 1); final Matcher m = CHARSET_PATTERN.matcher(postMime); encoding = m.find() ? m.group(1) : null; encoding = encoding != null ? encoding.toUpperCase() : null; } } return encoding; }
private String getFileName (String line) { Pattern pattern = Pattern.compile("(.*):([0-9])+:[0-9]+:"); Matcher matcher = pattern.matcher(line); matcher.find(); String fileName = matcher.groupCount() >= 2 ? matcher.group(1).trim() : null; if (fileName == null) return null; int index = fileName.indexOf(" "); if (index != -1) return fileName.substring(index).trim(); else return fileName; }