mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8065554: MatchResult should provide values of named-capturing groups
Reviewed-by: smarks
This commit is contained in:
parent
1decdcee71
commit
ce85cac947
4 changed files with 619 additions and 52 deletions
|
@ -1843,7 +1843,7 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) {
|
|||
topClosureNodes = null;
|
||||
}
|
||||
|
||||
Map<String, Integer> namedGroups() {
|
||||
private Map<String, Integer> namedGroupsMap() {
|
||||
Map<String, Integer> groups = namedGroups;
|
||||
if (groups == null) {
|
||||
namedGroups = groups = new HashMap<>(2);
|
||||
|
@ -1851,6 +1851,18 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) {
|
|||
return groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable map from capturing group names to group numbers.
|
||||
* If there are no named groups, returns an empty map.
|
||||
*
|
||||
* @return an unmodifiable map from capturing group names to group numbers
|
||||
*
|
||||
* @since 20
|
||||
*/
|
||||
public Map<String, Integer> namedGroups() {
|
||||
return Map.copyOf(namedGroupsMap());
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to accumulate information about a subtree of the object graph
|
||||
* so that optimizations can be applied to the subtree.
|
||||
|
@ -2554,14 +2566,14 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) {
|
|||
if (read() != '<')
|
||||
throw error("\\k is not followed by '<' for named capturing group");
|
||||
String name = groupname(read());
|
||||
if (!namedGroups().containsKey(name))
|
||||
if (!namedGroupsMap().containsKey(name))
|
||||
throw error("named capturing group <" + name + "> does not exist");
|
||||
if (create) {
|
||||
hasGroupRef = true;
|
||||
if (has(CASE_INSENSITIVE))
|
||||
root = new CIBackRef(namedGroups().get(name), has(UNICODE_CASE));
|
||||
root = new CIBackRef(namedGroupsMap().get(name), has(UNICODE_CASE));
|
||||
else
|
||||
root = new BackRef(namedGroups().get(name));
|
||||
root = new BackRef(namedGroupsMap().get(name));
|
||||
}
|
||||
return -1;
|
||||
case 'l':
|
||||
|
@ -3008,13 +3020,13 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) {
|
|||
if (ch != '=' && ch != '!') {
|
||||
// named captured group
|
||||
String name = groupname(ch);
|
||||
if (namedGroups().containsKey(name))
|
||||
if (namedGroupsMap().containsKey(name))
|
||||
throw error("Named capturing group <" + name
|
||||
+ "> is already defined");
|
||||
capturingGroup = true;
|
||||
head = createGroup(false);
|
||||
tail = root;
|
||||
namedGroups().put(name, capturingGroupCount - 1);
|
||||
namedGroupsMap().put(name, capturingGroupCount - 1);
|
||||
head.next = expr(tail);
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue