1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-12-06 04:11:11 +01:00

Add support for different regex parsers

This commit is contained in:
Paul Schaub 2022-11-29 14:21:44 +01:00
parent 3f10efac7a
commit 21f8ba8ccf
8 changed files with 270 additions and 1 deletions

View file

@ -0,0 +1,33 @@
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package org.pgpainless.algorithm;
import com.basistech.tclre.HsrePattern;
import com.basistech.tclre.PatternFlags;
import com.basistech.tclre.RePattern;
import com.basistech.tclre.RegexException;
public class HSRegexInterpreterFactory extends RegexInterpreterFactory {
public Regex instantiate(String regex) {
return new Regex() {
private final RePattern pattern;
{
try {
pattern = HsrePattern.compile(regex, PatternFlags.ADVANCED);
} catch (RegexException e) {
throw new IllegalArgumentException(e);
}
}
@Override
public boolean matches(String string) {
return pattern.matcher(string).find();
}
};
}
}

View file

@ -0,0 +1,10 @@
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
/**
* Regex interpreter implementation based on Henry Spencers Regular Expression library.
*
* @see <a href="https://www.rfc-editor.org/rfc/rfc4880#section-8">RFC4880 - §8. Regular Expressions</a>
*/
package org.pgpainless.algorithm;