use of dk.brics.automaton.Automaton in project intellij-community by JetBrains.
the class StringPattern method matchesBrics.
@NotNull
public StringPattern matchesBrics(@NonNls @NotNull final String s) {
final String escaped = StringUtil.escapeToRegexp(s);
if (escaped.equals(s)) {
return equalTo(s);
}
StringBuilder sb = new StringBuilder(s.length() * 5);
for (int i = 0; i < s.length(); i++) {
final char c = s.charAt(i);
if (c == ' ') {
sb.append("<whitespacechar>");
} else //This is really stupid and inconvenient builder - it breaks any normal pattern with uppercase
if (Character.isUpperCase(c)) {
sb.append('[').append(Character.toUpperCase(c)).append(Character.toLowerCase(c)).append(']');
} else {
sb.append(c);
}
}
final RegExp regExp = new RegExp(sb.toString());
final Automaton automaton = regExp.toAutomaton(new DatatypesAutomatonProvider());
final RunAutomaton runAutomaton = new RunAutomaton(automaton, true);
return with(new ValuePatternCondition<String>("matchesBrics") {
@Override
public boolean accepts(@NotNull String str, final ProcessingContext context) {
return runAutomaton.run(str);
}
@Override
public Collection<String> getValues() {
return Collections.singleton(s);
}
});
}
Aggregations