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;
}
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));
}
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();
}
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();
}
}
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();
}
Aggregations