ICU-12979 Fix \Q...\E in UnicodeRegex#transform (#23)
This commit is contained in:
parent
00ccb44a30
commit
378b04c1b2
@ -116,7 +116,7 @@ public class UnicodeRegex implements Cloneable, Freezable<UnicodeRegex>, StringT
|
|||||||
|
|
||||||
case 1: // we are after a \
|
case 1: // we are after a \
|
||||||
if (ch == 'Q') {
|
if (ch == 'Q') {
|
||||||
state = 1;
|
state = 2;
|
||||||
} else {
|
} else {
|
||||||
state = 0;
|
state = 0;
|
||||||
}
|
}
|
||||||
@ -128,11 +128,12 @@ public class UnicodeRegex implements Cloneable, Freezable<UnicodeRegex>, StringT
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3: // we are in at \Q...\
|
case 3: // we are in a \Q...\
|
||||||
if (ch == 'E') {
|
if (ch == 'E') {
|
||||||
state = 0;
|
state = 0;
|
||||||
|
} else if (ch != '\\') {
|
||||||
|
state = 2;
|
||||||
}
|
}
|
||||||
state = 2;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
result.append(ch);
|
result.append(ch);
|
||||||
|
@ -216,6 +216,29 @@ public class RegexUtilitiesTest extends TestFmwk {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check {@code \Q} and {@code \E}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void TestTransformQuotation() {
|
||||||
|
String[][] tests = {
|
||||||
|
{"a\\Qb", "a\\Qb"},
|
||||||
|
{"a\\Eb", "a\\Eb"},
|
||||||
|
{"\\Q[ba]", "\\Q[ba]"},
|
||||||
|
{"\\\\Q[ba]", "\\\\Q[ab]"},
|
||||||
|
{"\\Q[ba]\\e[ba]", "\\Q[ba]\\e[ba]"},
|
||||||
|
{"\\Q[ba]\\E[ba]", "\\Q[ba]\\E[ab]"},
|
||||||
|
{"\\Q[ba]\\\\E[ba]", "\\Q[ba]\\\\E[ab]"},
|
||||||
|
};
|
||||||
|
UnicodeRegex regex = new UnicodeRegex();
|
||||||
|
for (int i = 0; i < tests.length; ++i) {
|
||||||
|
final String source = tests[i][0];
|
||||||
|
String expected = tests[i][1];
|
||||||
|
String actual = regex.transform(source);
|
||||||
|
assertEquals(source, expected, actual);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility for checking patterns
|
* Utility for checking patterns
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user