8222684: Better support for patterns

8223163: Better pattern recognition

Reviewed-by: ahgross, bchristi, jeff, rhalade, rriggs, smarks
This commit is contained in:
Ivan Gerasimov 2019-05-22 19:41:59 -07:00
parent 75745ee70d
commit 844e811d56

View file

@ -1427,7 +1427,11 @@ public final class Pattern
localTCNCount = 0;
if (!pattern.isEmpty()) {
compile();
try {
compile();
} catch (StackOverflowError soe) {
throw error("Stack overflow during pattern compilation");
}
} else {
root = new Start(lastAccept);
matchRoot = lastAccept;
@ -1965,6 +1969,10 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) {
int ch = temp[cursor++];
while (ch != 0 && !isLineSeparator(ch))
ch = temp[cursor++];
if (ch == 0 && cursor > patternLength) {
cursor = patternLength;
ch = temp[cursor++];
}
return ch;
}
@ -1975,6 +1983,10 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) {
int ch = temp[++cursor];
while (ch != 0 && !isLineSeparator(ch))
ch = temp[++cursor];
if (ch == 0 && cursor > patternLength) {
cursor = patternLength;
ch = temp[cursor];
}
return ch;
}
@ -3415,9 +3427,10 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) {
private int N() {
if (read() == '{') {
int i = cursor;
while (cursor < patternLength && read() != '}') {}
if (cursor > patternLength)
throw error("Unclosed character name escape sequence");
while (read() != '}') {
if (cursor >= patternLength)
throw error("Unclosed character name escape sequence");
}
String name = new String(temp, i, cursor - i - 1);
try {
return Character.codePointOf(name);