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