use of org.apache.oro.text.regex.Pattern in project jmeter by apache.
the class MultipartUrlConfig method getHeaderValue.
private static String getHeaderValue(String headerName, String multiPart) {
// $NON-NLS-1$
String regularExpression = headerName + "\\s*:\\s*(.*)$";
Perl5Matcher localMatcher = JMeterUtils.getMatcher();
Pattern pattern = JMeterUtils.getPattern(regularExpression, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.MULTILINE_MASK);
if (localMatcher.contains(multiPart, pattern)) {
return localMatcher.getMatch().group(1).trim();
} else {
return null;
}
}
use of org.apache.oro.text.regex.Pattern in project otter by alibaba.
the class ActionProtectedEditor method convertStringToPattern.
/**
* 把字符串转成Pattern和UrlType
*
* @param perl5RegExp
* @return
*/
private ActionPatternHolder convertStringToPattern(String line) {
ActionPatternHolder holder = new ActionPatternHolder();
String[] strs = org.apache.commons.lang.StringUtils.split(line, "|");
if (strs.length != 2) {
throw new IllegalArgumentException("illegal expression: " + line);
}
Pattern compiledPattern;
Perl5Compiler compiler = new Perl5Compiler();
try {
holder.setActionName(strs[0]);
compiledPattern = compiler.compile(strs[0], Perl5Compiler.READ_ONLY_MASK);
holder.setActionPattern(compiledPattern);
} catch (MalformedPatternException mpe) {
throw new IllegalArgumentException("Malformed regular expression: " + strs[0]);
}
try {
holder.setMethodName(strs[1]);
compiledPattern = compiler.compile(strs[1], Perl5Compiler.READ_ONLY_MASK);
holder.setMethodPattern(compiledPattern);
} catch (MalformedPatternException mpe) {
throw new IllegalArgumentException("Malformed regular expression: " + strs[1]);
}
return holder;
}
use of org.apache.oro.text.regex.Pattern in project otter by alibaba.
the class URLProtectedEditor method convertStringToPattern.
/**
* 把字符串转成Pattern和UrlType
*
* @param perl5RegExp
* @return
*/
private URLPatternHolder convertStringToPattern(String line) {
URLPatternHolder holder = new URLPatternHolder();
Pattern compiledPattern;
Perl5Compiler compiler = new Perl5Compiler();
String perl5RegExp = line;
try {
compiledPattern = compiler.compile(perl5RegExp, Perl5Compiler.READ_ONLY_MASK);
holder.setCompiledPattern(compiledPattern);
} catch (MalformedPatternException mpe) {
throw new IllegalArgumentException("Malformed regular expression: " + perl5RegExp);
}
if (logger.isDebugEnabled()) {
logger.debug("Added regular expression: " + compiledPattern.getPattern().toString());
}
return holder;
}
use of org.apache.oro.text.regex.Pattern in project otter by alibaba.
the class ConfigHelperTest method testWildCard.
@Test
public void testWildCard() {
PatternMatcher matcher = new Perl5Matcher();
Pattern pattern = null;
PatternCompiler pc = new Perl5Compiler();
try {
pattern = pc.compile("havana_us_.*", Perl5Compiler.DEFAULT_MASK);
} catch (MalformedPatternException e) {
throw new ConfigException(e);
}
boolean ismatch = matcher.matches("havana_us_0001", pattern);
System.out.println(ismatch);
}
use of org.apache.oro.text.regex.Pattern in project intellij-plugins by JetBrains.
the class GherkinPsiUtil method buildParameterRanges.
@Nullable
public static List<TextRange> buildParameterRanges(@NotNull GherkinStep step, @NotNull AbstractStepDefinition definition, final int shiftOffset) {
final List<TextRange> parameterRanges = new ArrayList<>();
final Pattern pattern = definition.getPattern();
if (pattern == null)
return null;
final Perl5Matcher matcher = new Perl5Matcher();
if (matcher.contains(step.getStepName(), pattern)) {
final MatchResult match = matcher.getMatch();
final int groupCount = match.groups();
for (int i = 1; i < groupCount; i++) {
final int start = match.beginOffset(i);
final int end = match.endOffset(i);
if (start >= 0 && end >= 0) {
parameterRanges.add(new TextRange(start, end).shiftRight(shiftOffset));
}
}
}
int k = step.getText().indexOf(step.getStepName());
k += step.getStepName().length();
if (k < step.getText().length() - 1) {
String text = step.getText().substring(k + 1);
boolean inParam = false;
int paramStart = 0;
int i = 0;
while (i < text.length()) {
if (text.charAt(i) == '<') {
paramStart = i;
inParam = true;
}
if (text.charAt(i) == '>' && inParam) {
parameterRanges.add(new TextRange(paramStart, i + 1).shiftRight(shiftOffset + step.getStepName().length() + 1));
inParam = false;
}
i++;
}
}
return parameterRanges;
}
Aggregations