Refine search
/** * Returns {@code true} if the exclusion {@link Pattern} at index {@code patternIndex} * matches the supplied candidate {@code String}. */ @Override protected boolean matchesExclusion(String candidate, int patternIndex) { Matcher matcher = this.compiledExclusionPatterns[patternIndex].matcher(candidate); return matcher.matches(); }
private String getError (String line) { Pattern pattern = Pattern.compile(":[0-9]+:[0-9]+:(.+)"); Matcher matcher = pattern.matcher(line); matcher.find(); return matcher.groupCount() >= 1 ? matcher.group(1).trim() : null; }
/** * Returns the length of the given pattern, where template variables are considered to be 1 long. */ public int getLength() { if (this.length == null) { this.length = (this.pattern != null ? VARIABLE_PATTERN.matcher(this.pattern).replaceAll("#").length() : 0); } return this.length; } }
public SubText(Matcher m, int textOffset) { start = m.start() + textOffset; end = m.end() + textOffset; int cnt = m.groupCount(); groups = new int[cnt*2]; for( int i=0; i<cnt; i++ ) { groups[i*2 ] = m.start(i+1) + textOffset; groups[i*2+1] = m.end(i+1) + textOffset; } }
/** * 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(); }
/** * 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; }
/** * Extracts the hostname from a "host:port" address string. * @param address address string to parse * @return hostname or null if the given address is incorrect */ public static String getHost(String address) { Matcher matcher = HOST_PORT_PATTERN.matcher(address); return matcher.matches() ? matcher.group(1) : null; }
protected static String sanitize(String namespace) { Pattern DOT_OR_WHITESPACE = Pattern.compile("[\\s]+|[.]+"); return DOT_OR_WHITESPACE.matcher(namespace).replaceAll("_"); } }
/** * 驼峰转下划线,效率比上面高 * @param str * @return */ public static String humpToLine(String str) { Matcher matcher = humpPattern.matcher(str); StringBuffer sb = new StringBuffer(); while (matcher.find()) { matcher.appendReplacement(sb, "_" + matcher.group(0).toLowerCase()); } matcher.appendTail(sb); return sb.toString(); }
private void assertDescriptionContainsExpectedPath(ClassPathResource resource, String expectedPath) { Matcher matcher = DESCRIPTION_PATTERN.matcher(resource.getDescription()); assertTrue(matcher.matches()); assertEquals(1, matcher.groupCount()); String match = matcher.group(1); assertEquals(expectedPath, match); }
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); } } }
private static String cleanCookieHeader(String cookie) { for (Pattern stripPtn : RE_STRIP) { Matcher matcher = stripPtn.matcher(cookie); if (matcher.find()) { cookie = matcher.replaceAll(""); } } return cookie; }
@Override boolean parse(final FastDateParser parser, final Calendar calendar, final String source, final ParsePosition pos, final int maxWidth) { final Matcher matcher = pattern.matcher(source.substring(pos.getIndex())); if (!matcher.lookingAt()) { pos.setErrorIndex(pos.getIndex()); return false; } pos.setIndex(pos.getIndex() + matcher.end(1)); setCalendar(parser, calendar, matcher.group(1)); return true; }
public BinaryLiteral(Optional<NodeLocation> location, String value) { super(location); requireNonNull(value, "value is null"); String hexString = WHITESPACE_PATTERN.matcher(value).replaceAll("").toUpperCase(); if (NOT_HEX_DIGIT_PATTERN.matcher(hexString).matches()) { throw new ParsingException("Binary literal can only contain hexadecimal digits", location.get()); } if (hexString.length() % 2 != 0) { throw new ParsingException("Binary literal must contain an even number of digits", location.get()); } this.value = Slices.wrappedBuffer(BaseEncoding.base16().decode(hexString)); }
private String escape(String jsonStringValue) { String replace1 = DOUBLEQUOTE.matcher(jsonStringValue).replaceAll(Matcher.quoteReplacement("\\\"")); return BACKSLASH.matcher(replace1).replaceAll(Matcher.quoteReplacement("\\\\")); }
private void validatePathName(int p, String name) { if (!PARAM_NAME_REGEX.matcher(name).matches()) { throw parameterError(method, p, "@Path parameter name must match %s. Found: %s", PARAM_URL_REGEX.pattern(), name); } // Verify URL replacement name is actually present in the URL path. if (!relativeUrlParamNames.contains(name)) { throw parameterError(method, p, "URL \"%s\" does not contain \"{%s}\".", relativeUrl, name); } }
@Override public boolean matches() { return matcher.matches(); }