use of org.apache.oro.text.regex.Pattern in project tdi-studio-se by Talend.
the class MapperComponent method hasOrRenameData.
/**
*
* DOC amaumont Comment method "hasOrRenameData".
*
* @param oldName
* @param newName can be null if <code>renameAction</code> is false
* @param renameAction true to rename in all expressions, false to get boolean if present in one of the expressions
* @return
*/
@Override
protected boolean hasOrRenameData(String oldName, String newName, boolean renameAction) {
if (oldName == null || newName == null && renameAction) {
throw new NullPointerException();
}
if (externalData != null) {
List<ExternalMapperTable> tables = new ArrayList<ExternalMapperTable>(externalData.getInputTables());
tables.addAll(externalData.getOutputTables());
if (externalData.getVarsTables() != null) {
tables.addAll(externalData.getVarsTables());
}
for (ExternalMapperTable table : tables) {
if (table.getExpressionFilter() != 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, table.getExpressionFilter());
table.setExpressionFilter(expression);
} else {
if (hasDataIntoExpression(pattern, matcher, table.getExpressionFilter())) {
return true;
}
}
}
}
List<ExternalMapperTableEntry> metadataTableEntries = table.getMetadataTableEntries();
if (metadataTableEntries != null) {
// loop on all entries of current table
for (ExternalMapperTableEntry entry : metadataTableEntries) {
if (hasOrRenameEntry(entry, oldName, newName, renameAction)) {
// existed
return true;
}
}
// for (ExternalMapperTableEntry entry : metadataTableEntries) {
}
if (table.getConstraintTableEntries() != null) {
for (ExternalMapperTableEntry entry : table.getConstraintTableEntries()) {
if (hasOrRenameEntry(entry, oldName, newName, renameAction)) {
// existed
return true;
}
}
}
}
}
return false;
}
use of org.apache.oro.text.regex.Pattern in project tdi-studio-se by Talend.
the class MapDataDelegateHelper method matchExpression.
private boolean matchExpression(String regex, String expression) {
PatternCompiler compiler = new Perl5Compiler();
try {
//$NON-NLS-1$ //$NON-NLS-2$
Pattern pattern = compiler.compile("\\b(" + UpdateContextVariablesHelper.replaceSpecialChar(regex) + ")(\\b|\\_)");
PatternMatcher matcher = new Perl5Matcher();
((Perl5Matcher) matcher).setMultiline(true);
if (matcher.contains(expression, pattern)) {
return true;
}
} catch (MalformedPatternException e) {
//
}
return false;
}
use of org.apache.oro.text.regex.Pattern in project intellij-plugins by JetBrains.
the class CucumberStepsIndex method findStepDefinitions.
/**
* Searches for ALL step definitions, groups it by step definition class and sorts by pattern size.
* For each step definition class it finds the largest pattern.
*
* @param featureFile file with steps
* @param step step itself
* @return definitions
*/
@NotNull
public Collection<AbstractStepDefinition> findStepDefinitions(@NotNull final PsiFile featureFile, @NotNull final GherkinStep step) {
final Module module = ModuleUtilCore.findModuleForPsiElement(featureFile);
if (module == null) {
return Collections.emptyList();
}
Map<Class<? extends AbstractStepDefinition>, AbstractStepDefinition> definitionsByClass = new java.util.HashMap<>();
List<AbstractStepDefinition> allSteps = loadStepsFor(featureFile, module);
for (AbstractStepDefinition stepDefinition : allSteps) {
if (stepDefinition.matches(step.getSubstitutedName()) && stepDefinition.supportsStep(step)) {
final Pattern currentLongestPattern = getPatternByDefinition(definitionsByClass.get(stepDefinition.getClass()));
final Pattern newPattern = getPatternByDefinition(stepDefinition);
final int newPatternLength = ((newPattern != null) ? newPattern.getPattern().length() : -1);
if ((currentLongestPattern == null) || (currentLongestPattern.getPattern().length() < newPatternLength)) {
definitionsByClass.put(stepDefinition.getClass(), stepDefinition);
}
}
}
return definitionsByClass.values();
}
use of org.apache.oro.text.regex.Pattern in project intellij-plugins by JetBrains.
the class JavaStepDefinition method matches.
@Override
public boolean matches(String stepName) {
Pattern perlPattern = getPattern();
if (perlPattern != null) {
final java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(perlPattern.getPattern());
Matcher m = pattern.matcher(stepName);
return m.matches();
}
return false;
}
use of org.apache.oro.text.regex.Pattern in project Lucee by lucee.
the class Perl5Util method match.
public static Array match(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.MULTILINE_MASK;
if (offset < 1)
offset = 1;
Pattern pattern = getPattern(strPattern, compileOptions);
Array rtn = new ArrayImpl();
MatchResult result;
while (matcher.contains(input, pattern)) {
result = matcher.getMatch();
rtn.appendEL(result.toString());
}
return rtn;
}
Aggregations