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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations