Search in sources :

Example 21 with PatternMatcherInput

use of org.apache.oro.text.regex.PatternMatcherInput in project tdi-studio-se by Talend.

the class XmlMapExpressionManager method getMatchedExpression.

public List<String> getMatchedExpression(String expression) {
    List<String> matched = new ArrayList<String>();
    if (expression == null) {
        return matched;
    }
    recompilePatternIfNecessary(EXPRESSION_PATTERN);
    patternMatcherInput = new PatternMatcherInput(expression);
    while (matcher.contains(patternMatcherInput, pattern)) {
        MatchResult matchResult = matcher.getMatch();
        if (matchResult.group(0) != null) {
            matched.add(matchResult.group(0).trim());
        }
    }
    return matched;
}
Also used : PatternMatcherInput(org.apache.oro.text.regex.PatternMatcherInput) ArrayList(java.util.ArrayList) MatchResult(org.apache.oro.text.regex.MatchResult)

Example 22 with PatternMatcherInput

use of org.apache.oro.text.regex.PatternMatcherInput in project tdi-studio-se by Talend.

the class DataMapExpressionParser method parseTableEntryLocations.

public TableEntryLocation[] parseTableEntryLocations(String expression) {
    resultList.clear();
    if (expression != null) {
        matcher.setMultiline(true);
        if (patternMatcherInput == null) {
            patternMatcherInput = new PatternMatcherInput(expression);
        } else {
            patternMatcherInput.setInput(expression);
        }
        recompilePatternIfNecessary(EXPRESSION_PATTERN);
        while (matcher.contains(patternMatcherInput, pattern)) {
            MatchResult matchResult = matcher.getMatch();
            TableEntryLocation location = null;
            if (matchResult.group(1) != null) {
                // context.schema.context.table.comlumn
                location = new TableEntryLocation(matchResult.group(2) + DOT_STR + matchResult.group(3) + DOT_STR + matchResult.group(4) + DOT_STR + matchResult.group(5), matchResult.group(6));
            } else if (matchResult.group(7) != null) {
                // context.schema.table.comlumn | schema.context.table.comlumn
                location = new TableEntryLocation(matchResult.group(8) + DOT_STR + matchResult.group(9) + DOT_STR + matchResult.group(10), matchResult.group(11));
            } else if (matchResult.group(12) != null) {
                // schema.table.column
                location = new TableEntryLocation(matchResult.group(13) + DOT_STR + matchResult.group(14), matchResult.group(15));
            } else if (matchResult.group(16) != null) {
                // table.column
                location = new TableEntryLocation(matchResult.group(17), matchResult.group(18));
            }
            if (location != null) {
                resultList.add(location);
            }
        }
    }
    return resultList.toArray(new TableEntryLocation[resultList.size()]);
}
Also used : PatternMatcherInput(org.apache.oro.text.regex.PatternMatcherInput) TableEntryLocation(org.talend.designer.dbmap.model.tableentry.TableEntryLocation) MatchResult(org.apache.oro.text.regex.MatchResult)

Example 23 with PatternMatcherInput

use of org.apache.oro.text.regex.PatternMatcherInput in project tdi-studio-se by Talend.

the class MapExpressionParser method substitute.

private String substitute(PatternMatcher matcher, Pattern pattern, Substitution sub, String input, int numSubs) {
    StringBuffer buffer = new StringBuffer(input.length());
    PatternMatcherInput pinput = new PatternMatcherInput(input);
    // are performed,
    if (substitute(buffer, matcher, pattern, sub, pinput, numSubs) != 0) {
        return buffer.toString();
    }
    return input;
}
Also used : PatternMatcherInput(org.apache.oro.text.regex.PatternMatcherInput)

Example 24 with PatternMatcherInput

use of org.apache.oro.text.regex.PatternMatcherInput in project tdi-studio-se by Talend.

the class MapExpressionParser method parseInTableEntryLocations.

public List<Map<String, String>> parseInTableEntryLocations(String expression) {
    List<Map<String, String>> result = new ArrayList<Map<String, String>>();
    if (expression != null) {
        matcher.setMultiline(true);
        if (patternMatcherInput == null) {
            patternMatcherInput = new PatternMatcherInput(expression);
        } else {
            patternMatcherInput.setInput(expression);
        }
        recompilePatternIfNecessary(locationPattern);
        while (matcher.contains(patternMatcherInput, pattern)) {
            MatchResult matchResult = matcher.getMatch();
            Map<String, String> map = new HashMap<String, String>();
            if (matchResult.group(3) != null && !"".equals(matchResult.group(3))) {
                map.put(matchResult.group(3), matchResult.group(1) + "." + matchResult.group(2));
            } else {
                map.put(matchResult.group(2), matchResult.group(1));
            }
            result.add(map);
        }
    }
    // .toArray(new TableEntryLocation[0]);
    return result;
}
Also used : PatternMatcherInput(org.apache.oro.text.regex.PatternMatcherInput) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) MatchResult(org.apache.oro.text.regex.MatchResult)

Example 25 with PatternMatcherInput

use of org.apache.oro.text.regex.PatternMatcherInput in project Lucee by lucee.

the class Perl5Util method indexOf.

/**
 * return index of the first occurence of the pattern in input text
 * @param strPattern pattern to search
 * @param strInput text to search pattern
 * @param offset
 * @param caseSensitive
 * @return position of the first occurence
 * @throws MalformedPatternException
 */
public static int indexOf(String strPattern, String strInput, int offset, boolean caseSensitive) throws MalformedPatternException {
    // Perl5Compiler compiler = new Perl5Compiler();
    PatternMatcherInput input = new PatternMatcherInput(strInput);
    Perl5Matcher matcher = new Perl5Matcher();
    int compileOptions = caseSensitive ? 0 : Perl5Compiler.CASE_INSENSITIVE_MASK;
    compileOptions += Perl5Compiler.SINGLELINE_MASK;
    if (offset < 1)
        offset = 1;
    Pattern pattern = getPattern(strPattern, compileOptions);
    if (offset <= strInput.length())
        input.setCurrentOffset(offset - 1);
    if (offset <= strInput.length() && matcher.contains(input, pattern)) {
        return matcher.getMatch().beginOffset(0) + 1;
    }
    return 0;
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) PatternMatcherInput(org.apache.oro.text.regex.PatternMatcherInput) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher)

Aggregations

PatternMatcherInput (org.apache.oro.text.regex.PatternMatcherInput)28 MatchResult (org.apache.oro.text.regex.MatchResult)20 Pattern (org.apache.oro.text.regex.Pattern)15 Perl5Matcher (org.apache.oro.text.regex.Perl5Matcher)14 ArrayList (java.util.ArrayList)9 PatternMatcher (org.apache.oro.text.regex.PatternMatcher)5 Perl5Compiler (org.apache.oro.text.regex.Perl5Compiler)5 MalformedURLException (java.net.MalformedURLException)3 HashMap (java.util.HashMap)3 MalformedCachePatternException (org.apache.oro.text.MalformedCachePatternException)3 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 Array (lucee.runtime.type.Array)2 ArrayImpl (lucee.runtime.type.ArrayImpl)2 PatternCompiler (org.apache.oro.text.regex.PatternCompiler)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URL (java.net.URL)1 HashSet (java.util.HashSet)1 Struct (lucee.runtime.type.Struct)1