File tree 3 files changed +18
-3
lines changed
3 files changed +18
-3
lines changed Original file line number Diff line number Diff line change 8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
+ use std:: collections:: HashMap ;
12
+ use std:: sync:: Arc ;
13
+
11
14
use backtrack:: { self , Backtrack } ;
12
15
use dfa:: { self , Dfa , DfaResult } ;
13
16
use input:: { ByteInput , CharInput } ;
@@ -375,6 +378,12 @@ impl Exec {
375
378
& self . prog . cap_names
376
379
}
377
380
381
+ /// Return a reference to named groups mapping (from group name to
382
+ /// group position).
383
+ pub fn named_groups ( & self ) -> & Arc < HashMap < String , usize > > {
384
+ & self . prog . named_groups
385
+ }
386
+
378
387
/// Return a fresh allocation for storing all possible captures in the
379
388
/// underlying regular expression.
380
389
pub fn alloc_captures ( & self ) -> Vec < Option < usize > > {
Original file line number Diff line number Diff line change 8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- use std:: { char, cmp} ;
12
11
use std:: collections:: HashMap ;
13
12
use std:: sync:: Arc ;
14
13
@@ -122,10 +121,17 @@ impl ProgramBuilder {
122
121
insts. anchored_begin ( ) ,
123
122
insts. anchored_end ( ) ,
124
123
) ;
124
+ let mut named_groups = HashMap :: new ( ) ;
125
+ for ( i, name) in cap_names. iter ( ) . enumerate ( ) {
126
+ if let Some ( ref name) = * name {
127
+ named_groups. insert ( name. to_owned ( ) , i) ;
128
+ }
129
+ }
125
130
Ok ( Program {
126
131
original : self . re ,
127
132
insts : insts,
128
133
cap_names : cap_names,
134
+ named_groups : Arc :: new ( named_groups) ,
129
135
prefixes : prefixes,
130
136
anchored_begin : anchored_begin,
131
137
anchored_end : anchored_end,
Original file line number Diff line number Diff line change @@ -820,8 +820,8 @@ impl NamedGroups {
820
820
match * regex {
821
821
Regex :: Native ( ExNative { ref groups, .. } ) =>
822
822
NamedGroups :: Native ( groups) ,
823
- Regex :: Dynamic ( Program { ref named_groups , .. } ) =>
824
- NamedGroups :: Dynamic ( named_groups. clone ( ) )
823
+ Regex :: Dynamic ( ref exec ) =>
824
+ NamedGroups :: Dynamic ( exec . named_groups ( ) . clone ( ) )
825
825
}
826
826
}
827
827
You can’t perform that action at this time.
0 commit comments