Search in sources :

Example 46 with Pattern

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

the class UpgradeParameterHelper method hasParent.

/*
     * check the parent form name
     */
private static boolean hasParent(final String name, final String parent) {
    if (name == null) {
        return false;
    }
    if (parent != null) {
        final String parentExp = parent + COLON;
        if (name.contains(parentExp)) {
            Perl5Matcher matcher = new Perl5Matcher();
            Perl5Compiler compiler = new Perl5Compiler();
            Pattern pattern;
            try {
                //$NON-NLS-1$ //$NON-NLS-2$
                pattern = compiler.compile("\\b(" + parentExp + ")\\b");
                if (matcher.contains(name, pattern)) {
                    return true;
                }
            } catch (MalformedPatternException e) {
            //
            }
        }
    }
    return false;
}
Also used : Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler) Pattern(org.apache.oro.text.regex.Pattern) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException)

Example 47 with Pattern

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

the class VarsTable method validateColumnName.

/**
     * 
     * DOC amaumont Comment method "validateColumnName".
     * 
     * @param columnName
     * @return true if columnName has a valid value
     */
public String validateColumnName(String columnName, int beanPosition) {
    if (columnName == null) {
        //$NON-NLS-1$
        return Messages.getString("VarsTable.columnNameIsNull");
    }
    Pattern validPatternColumnNameRegexp = null;
    if (validPatternColumnNameRegexp == null) {
        try {
            validPatternColumnNameRegexp = COMPILER.compile(VALID_PATTERN_COLUMN_NAME);
        } catch (MalformedPatternException e) {
            throw new RuntimeException(e);
        }
    }
    Perl5Matcher matcher = new Perl5Matcher();
    boolean match = matcher.matches(columnName, validPatternColumnNameRegexp);
    // System.out.println(columnName + " -> "+ match);
    if (!match) {
        //$NON-NLS-1$ //$NON-NLS-2$
        return Messages.getString("VarsTable.columnNameTip") + columnName + Messages.getString("VarsTable.invalidTip");
    }
    int lstSize = dataMapTableEntries.size();
    for (int i = 0; i < lstSize; i++) {
        if (columnName.equals(dataMapTableEntries.get(i).getName()) && i != beanPosition) {
            //$NON-NLS-1$ //$NON-NLS-2$
            return Messages.getString("VarsTable.columnNameTip") + columnName + Messages.getString("VarsTable.existTip");
        }
    }
    return null;
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException)

Example 48 with Pattern

use of org.apache.oro.text.regex.Pattern 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)

Example 49 with Pattern

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

the class Perl5Util method find.

/**
 * find occurence of a pattern in a string (same like indexOf), but dont return first ocurence , it return
 * struct with all information
 * @param strPattern
 * @param strInput
 * @param offset
 * @param caseSensitive
 * @return
 * @throws MalformedPatternException
 */
public static Struct find(String strPattern, String strInput, int offset, boolean caseSensitive) throws MalformedPatternException {
    Perl5Matcher matcher = new Perl5Matcher();
    PatternMatcherInput input = new PatternMatcherInput(strInput);
    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)) {
        MatchResult result = matcher.getMatch();
        int groupCount = result.groups();
        Array posArray = new ArrayImpl();
        Array lenArray = new ArrayImpl();
        for (int i = 0; i < groupCount; i++) {
            int off = result.beginOffset(i);
            posArray.appendEL(Integer.valueOf(off + 1));
            lenArray.appendEL(Integer.valueOf(result.endOffset(i) - off));
        }
        Struct struct = new StructImpl();
        struct.setEL("pos", posArray);
        struct.setEL("len", lenArray);
        return struct;
    }
    Array posArray = new ArrayImpl();
    Array lenArray = new ArrayImpl();
    posArray.appendEL(Constants.INTEGER_0);
    lenArray.appendEL(Constants.INTEGER_0);
    Struct struct = new StructImpl();
    struct.setEL("pos", posArray);
    struct.setEL("len", lenArray);
    return struct;
}
Also used : Array(lucee.runtime.type.Array) Pattern(org.apache.oro.text.regex.Pattern) StructImpl(lucee.runtime.type.StructImpl) PatternMatcherInput(org.apache.oro.text.regex.PatternMatcherInput) ArrayImpl(lucee.runtime.type.ArrayImpl) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MatchResult(org.apache.oro.text.regex.MatchResult) Struct(lucee.runtime.type.Struct)

Example 50 with Pattern

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

the class Perl5Util method getPattern.

private static Pattern getPattern(String strPattern, int type) throws MalformedPatternException {
    Object o = patterns.get(strPattern + type);
    if (o == null) {
        Pattern pattern = new Perl5Compiler().compile(strPattern, type);
        patterns.put(strPattern + type, pattern);
        return pattern;
    }
    return (Pattern) o;
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler)

Aggregations

Pattern (org.apache.oro.text.regex.Pattern)52 Perl5Matcher (org.apache.oro.text.regex.Perl5Matcher)42 Perl5Compiler (org.apache.oro.text.regex.Perl5Compiler)24 MalformedPatternException (org.apache.oro.text.regex.MalformedPatternException)20 MatchResult (org.apache.oro.text.regex.MatchResult)18 PatternMatcherInput (org.apache.oro.text.regex.PatternMatcherInput)15 ArrayList (java.util.ArrayList)10 PatternMatcher (org.apache.oro.text.regex.PatternMatcher)9 PatternCompiler (org.apache.oro.text.regex.PatternCompiler)8 MalformedURLException (java.net.MalformedURLException)6 MalformedCachePatternException (org.apache.oro.text.MalformedCachePatternException)6 IOException (java.io.IOException)3 URL (java.net.URL)3 Perl5Substitution (org.apache.oro.text.regex.Perl5Substitution)3 BufferedReader (java.io.BufferedReader)2 EOFException (java.io.EOFException)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStreamReader (java.io.InputStreamReader)2