Search in sources :

Example 1 with Matcher

use of java.util.regex.Matcher in project jetty.project by eclipse.

the class UriTemplatePathSpec method getPathParams.

public Map<String, String> getPathParams(String path) {
    Matcher matcher = getMatcher(path);
    if (matcher.matches()) {
        if (group == PathSpecGroup.EXACT) {
            return Collections.emptyMap();
        }
        Map<String, String> ret = new HashMap<>();
        int groupCount = matcher.groupCount();
        for (int i = 1; i <= groupCount; i++) {
            ret.put(this.variables[i - 1], matcher.group(i));
        }
        return ret;
    }
    return null;
}
Also used : Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap)

Example 2 with Matcher

use of java.util.regex.Matcher in project elasticsearch by elastic.

the class EvilLoggerTests method assertLogLine.

private void assertLogLine(final String logLine, final Level level, final String location, final String message) {
    final Matcher matcher = Pattern.compile("\\[(.*)\\]\\[(.*)\\(.*\\)\\] (.*)").matcher(logLine);
    assertTrue(logLine, matcher.matches());
    assertThat(matcher.group(1), equalTo(level.toString()));
    assertThat(matcher.group(2), RegexMatcher.matches(location));
    assertThat(matcher.group(3), RegexMatcher.matches(message));
}
Also used : Matcher(java.util.regex.Matcher) RegexMatcher(org.elasticsearch.test.hamcrest.RegexMatcher)

Example 3 with Matcher

use of java.util.regex.Matcher in project elasticsearch by elastic.

the class Stash method getValue.

/**
     * Retrieves a value from the current stash.
     * The stash contains fields eventually extracted from previous responses that can be reused
     * as arguments for following requests (e.g. scroll_id)
     */
public Object getValue(String key) throws IOException {
    if (key.charAt(0) == '$' && key.charAt(1) != '{') {
        return unstash(key.substring(1));
    }
    Matcher matcher = EXTENDED_KEY.matcher(key);
    /*
         * String*Buffer* because that is what the Matcher API takes. In modern versions of java the uncontended synchronization is very,
         * very cheap so that should not be a problem.
         */
    StringBuffer result = new StringBuffer(key.length());
    if (false == matcher.find()) {
        throw new IllegalArgumentException("Doesn't contain any stash keys [" + key + "]");
    }
    do {
        matcher.appendReplacement(result, Matcher.quoteReplacement(unstash(matcher.group(1)).toString()));
    } while (matcher.find());
    matcher.appendTail(result);
    return result.toString();
}
Also used : Matcher(java.util.regex.Matcher)

Example 4 with Matcher

use of java.util.regex.Matcher in project buck by facebook.

the class AndroidPlatformTarget method getTargetForId.

/**
   * @param platformId for the platform, such as "Google Inc.:Google APIs:16"
   */
public static Optional<AndroidPlatformTarget> getTargetForId(String platformId, AndroidDirectoryResolver androidDirectoryResolver, Optional<Path> aaptOverride) {
    Matcher platformMatcher = PLATFORM_TARGET_PATTERN.matcher(platformId);
    if (platformMatcher.matches()) {
        try {
            String apiLevel = platformMatcher.group(1);
            Factory platformTargetFactory;
            if (platformId.contains("Google APIs")) {
                platformTargetFactory = new AndroidWithGoogleApisFactory();
            } else {
                platformTargetFactory = new AndroidWithoutGoogleApisFactory();
            }
            return Optional.of(platformTargetFactory.newInstance(androidDirectoryResolver, apiLevel, aaptOverride));
        } catch (NumberFormatException e) {
            return Optional.empty();
        }
    } else {
        return Optional.empty();
    }
}
Also used : Matcher(java.util.regex.Matcher)

Example 5 with Matcher

use of java.util.regex.Matcher in project buck by facebook.

the class AndroidBinaryDescription method addFallbackLocales.

private ImmutableSet<String> addFallbackLocales(ImmutableSet<String> locales) {
    ImmutableSet.Builder<String> allLocales = ImmutableSet.builder();
    for (String locale : locales) {
        allLocales.add(locale);
        Matcher matcher = COUNTRY_LOCALE_PATTERN.matcher(locale);
        if (matcher.matches()) {
            allLocales.add(matcher.group(1));
        }
    }
    return allLocales.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Matcher(java.util.regex.Matcher)

Aggregations

Matcher (java.util.regex.Matcher)12473 Pattern (java.util.regex.Pattern)5010 ArrayList (java.util.ArrayList)1516 IOException (java.io.IOException)904 HashMap (java.util.HashMap)565 File (java.io.File)487 Test (org.junit.Test)442 BufferedReader (java.io.BufferedReader)428 Map (java.util.Map)363 List (java.util.List)287 InputStreamReader (java.io.InputStreamReader)266 HashSet (java.util.HashSet)236 MalformedURLException (java.net.MalformedURLException)163 URL (java.net.URL)155 Date (java.util.Date)152 InputStream (java.io.InputStream)147 Field (java.lang.reflect.Field)130 PatternSyntaxException (java.util.regex.PatternSyntaxException)128 ParseException (java.text.ParseException)127 LinkedHashMap (java.util.LinkedHashMap)120