Search in sources :

Example 61 with Perl5Matcher

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;
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) PatternMatcherInput(org.apache.oro.text.regex.PatternMatcherInput) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MatchResult(org.apache.oro.text.regex.MatchResult)

Example 62 with Perl5Matcher

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();
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) PatternMatcherInput(org.apache.oro.text.regex.PatternMatcherInput) MalformedCachePatternException(org.apache.oro.text.MalformedCachePatternException) ArrayList(java.util.ArrayList) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MatchResult(org.apache.oro.text.regex.MatchResult) PatternCacheLRU(org.apache.oro.text.PatternCacheLRU)

Example 63 with Perl5Matcher

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;
}
Also used : Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher)

Example 64 with Perl5Matcher

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;
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) ArrayList(java.util.ArrayList) TextRange(com.intellij.openapi.util.TextRange) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MatchResult(org.apache.oro.text.regex.MatchResult) Nullable(org.jetbrains.annotations.Nullable)

Example 65 with Perl5Matcher

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;
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) Perl5Substitution(org.apache.oro.text.regex.Perl5Substitution) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) PatternMatcher(org.apache.oro.text.regex.PatternMatcher)

Aggregations

Perl5Matcher (org.apache.oro.text.regex.Perl5Matcher)102 Pattern (org.apache.oro.text.regex.Pattern)78 MatchResult (org.apache.oro.text.regex.MatchResult)39 Perl5Compiler (org.apache.oro.text.regex.Perl5Compiler)38 MalformedPatternException (org.apache.oro.text.regex.MalformedPatternException)37 PatternMatcher (org.apache.oro.text.regex.PatternMatcher)32 PatternMatcherInput (org.apache.oro.text.regex.PatternMatcherInput)22 PatternCompiler (org.apache.oro.text.regex.PatternCompiler)20 ArrayList (java.util.ArrayList)17 IOException (java.io.IOException)8 MalformedCachePatternException (org.apache.oro.text.MalformedCachePatternException)7 Perl5Substitution (org.apache.oro.text.regex.Perl5Substitution)7 MalformedURLException (java.net.MalformedURLException)5 PatternCacheLRU (org.apache.oro.text.PatternCacheLRU)5 PluginException (org.apache.wiki.api.exceptions.PluginException)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 NoSuchElementException (java.util.NoSuchElementException)3 SampleResult (org.apache.jmeter.samplers.SampleResult)3 BufferedReader (java.io.BufferedReader)2 EOFException (java.io.EOFException)2