use of org.apache.oro.text.regex.Perl5Matcher in project jmeter by apache.
the class TestHTTPSamplersAgainstHttpMirrorServer method getPositionOfBody.
private int getPositionOfBody(String stringToCheck) {
Perl5Matcher localMatcher = JMeterUtils.getMatcher();
// The headers and body are divided by a blank line
String regularExpression = "^.$";
Pattern pattern = JMeterUtils.getPattern(regularExpression, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.MULTILINE_MASK);
PatternMatcherInput input = new PatternMatcherInput(stringToCheck);
while (localMatcher.contains(input, pattern)) {
MatchResult match = localMatcher.getMatch();
return match.beginOffset(0);
}
// No divider was found
return -1;
}
use of org.apache.oro.text.regex.Perl5Matcher in project jmeter by apache.
the class RenderAsRegexp method process.
private String process(String textToParse) {
Perl5Matcher matcher = new Perl5Matcher();
PatternMatcherInput input = new PatternMatcherInput(textToParse);
PatternCacheLRU pcLRU = new PatternCacheLRU();
Pattern pattern;
try {
pattern = pcLRU.getPattern(regexpField.getText(), Perl5Compiler.READ_ONLY_MASK);
} catch (MalformedCachePatternException e) {
return e.toString();
}
List<MatchResult> matches = new ArrayList<>();
while (matcher.contains(input, pattern)) {
matches.add(matcher.getMatch());
}
// Construct a multi-line string with all matches
StringBuilder sb = new StringBuilder();
final int size = matches.size();
sb.append("Match count: ").append(size).append("\n");
for (int j = 0; j < size; j++) {
MatchResult mr = matches.get(j);
final int groups = mr.groups();
for (int i = 0; i < groups; i++) {
sb.append("Match[").append(j + 1).append("][").append(i).append("]=").append(mr.group(i)).append("\n");
}
}
return sb.toString();
}
use of org.apache.oro.text.regex.Perl5Matcher in project canal by alibaba.
the class SimpleDdlParser method parseRename.
private static DdlResult parseRename(String queryString, String schmeaName, String pattern) {
Perl5Matcher matcher = new Perl5Matcher();
if (matcher.matches(queryString, PatternUtils.getPattern(pattern))) {
DdlResult orign = parseTableName(matcher.getMatch().group(1), schmeaName);
DdlResult target = parseTableName(matcher.getMatch().group(2), schmeaName);
if (orign != null && target != null) {
return new DdlResult(target.getSchemaName(), target.getTableName(), orign.getSchemaName(), orign.getTableName());
}
}
return null;
}
use of org.apache.oro.text.regex.Perl5Matcher 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;
}
use of org.apache.oro.text.regex.Perl5Matcher in project tdi-studio-se by Talend.
the class AbstractMapComponent method hasOrRenameEntry.
/**
*
* ggu Comment method "hasOrRenameEntry".
*
*/
protected boolean hasOrRenameEntry(IExternalMapEntry entry, String oldName, String newName, boolean renameAction) {
if (entry == null || oldName == null || newName == null && renameAction) {
throw new NullPointerException();
}
if (entry.getExpression() != null) {
Pattern pattern = getRenamePattern(oldName);
if (pattern != null) {
PatternMatcher matcher = new Perl5Matcher();
((Perl5Matcher) matcher).setMultiline(true);
if (renameAction) {
Perl5Substitution substitution = getRenameSubstitution(newName);
String expression = renameDataIntoExpression(pattern, matcher, substitution, entry.getExpression());
entry.setExpression(expression);
} else {
if (hasDataIntoExpression(pattern, matcher, entry.getExpression())) {
return true;
}
}
}
}
return false;
}
Aggregations