Skip to content

Commit f9cc5d6

Browse files
committed
Fixes after rebase
1 parent e4f54de commit f9cc5d6

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/exec.rs

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use std::collections::HashMap;
12+
use std::sync::Arc;
13+
1114
use backtrack::{self, Backtrack};
1215
use dfa::{self, Dfa, DfaResult};
1316
use input::{ByteInput, CharInput};
@@ -375,6 +378,12 @@ impl Exec {
375378
&self.prog.cap_names
376379
}
377380

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+
378387
/// Return a fresh allocation for storing all possible captures in the
379388
/// underlying regular expression.
380389
pub fn alloc_captures(&self) -> Vec<Option<usize>> {

src/program.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::{char, cmp};
1211
use std::collections::HashMap;
1312
use std::sync::Arc;
1413

@@ -122,10 +121,17 @@ impl ProgramBuilder {
122121
insts.anchored_begin(),
123122
insts.anchored_end(),
124123
);
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+
}
125130
Ok(Program {
126131
original: self.re,
127132
insts: insts,
128133
cap_names: cap_names,
134+
named_groups: Arc::new(named_groups),
129135
prefixes: prefixes,
130136
anchored_begin: anchored_begin,
131137
anchored_end: anchored_end,

src/re.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,8 @@ impl NamedGroups {
820820
match *regex {
821821
Regex::Native(ExNative { ref groups, .. }) =>
822822
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())
825825
}
826826
}
827827

0 commit comments

Comments
 (0)