Classlib: fix bug in regexp implementation

This commit is contained in:
Alexey Andreev 2022-02-25 20:32:24 +03:00
parent 19f070840c
commit 393ab3b09e
4 changed files with 12 additions and 3 deletions

View File

@ -700,6 +700,7 @@ public final class TMatcher implements TMatchResult {
this.rightBound = string.length();
matchResult = new TMatchResultImpl(cs, leftBound, rightBound, pat.groupCount(), pat.compCount(),
pat.consCount());
matchResult.useAnchoringBounds(true);
}
@Override

View File

@ -52,7 +52,7 @@ class TMultiLineEOLSet extends TAbstractSet {
@Override
public int matches(int strIndex, CharSequence testString, TMatchResultImpl matchResult) {
int strDif = matchResult.hasAnchoringBounds()
? matchResult.getLeftBound() - strIndex
? matchResult.getRightBound() - strIndex
: testString.length() - strIndex;
char ch1;
char ch2;

View File

@ -47,8 +47,7 @@ final class TSOLSet extends TAbstractSet {
public int matches(int strIndex, CharSequence testString,
TMatchResultImpl matchResult) {
if (strIndex == 0
|| (matchResult.hasAnchoringBounds() && strIndex == matchResult
.getLeftBound())) {
|| (matchResult.hasAnchoringBounds() && strIndex == matchResult.getLeftBound())) {
return next.matches(strIndex, testString, matchResult);
}
return -1;

View File

@ -726,6 +726,15 @@ public class MatcherTest {
assertTrue("The result doesn't contain pattern info", result.contains("(\\d{1,3})"));
}
@Test
public void testSOLRegion() {
Pattern pattern = Pattern.compile("^cd");
String input = "abcde";
Matcher matcher = pattern.matcher(input);
matcher.region(2, input.length());
assertTrue(matcher.lookingAt());
}
private void hitEndTest(boolean callFind, String testNo, String regex,
String input, boolean hit) {
Pattern pattern = Pattern.compile(regex);