@@ -811,6 +811,7 @@ impl<'r, 't> Iterator for RegexSplitsN<'r, 't> {
811
811
}
812
812
813
813
enum NamedGroups {
814
+ Empty ,
814
815
Native ( & ' static [ ( & ' static str , usize ) ] ) ,
815
816
Dynamic ( Arc < HashMap < String , usize > > ) ,
816
817
}
@@ -821,12 +822,17 @@ impl NamedGroups {
821
822
Regex :: Native ( ExNative { ref groups, .. } ) =>
822
823
NamedGroups :: Native ( groups) ,
823
824
Regex :: Dynamic ( ref exec) =>
824
- NamedGroups :: Dynamic ( exec. named_groups ( ) . clone ( ) )
825
+ if exec. named_groups ( ) . is_empty ( ) {
826
+ NamedGroups :: Empty
827
+ } else {
828
+ NamedGroups :: Dynamic ( exec. named_groups ( ) . clone ( ) )
829
+ }
825
830
}
826
831
}
827
832
828
833
fn pos ( & self , name : & str ) -> Option < usize > {
829
834
match * self {
835
+ NamedGroups :: Empty => None ,
830
836
NamedGroups :: Native ( groups) => {
831
837
groups. binary_search_by ( |& ( n, _) | n. cmp ( name) )
832
838
. ok ( ) . map ( |i| groups[ i] . 1 )
@@ -839,13 +845,15 @@ impl NamedGroups {
839
845
840
846
fn iter < ' n > ( & ' n self ) -> NamedGroupsIter < ' n > {
841
847
match * self {
848
+ NamedGroups :: Empty => NamedGroupsIter :: Empty ,
842
849
NamedGroups :: Native ( g) => NamedGroupsIter :: Native ( g. iter ( ) ) ,
843
850
NamedGroups :: Dynamic ( ref g) => NamedGroupsIter :: Dynamic ( g. iter ( ) ) ,
844
851
}
845
852
}
846
853
}
847
854
848
855
enum NamedGroupsIter < ' n > {
856
+ Empty ,
849
857
Native ( :: std:: slice:: Iter < ' static , ( & ' static str , usize ) > ) ,
850
858
Dynamic ( :: std:: collections:: hash_map:: Iter < ' n , String , usize > ) ,
851
859
}
@@ -855,6 +863,8 @@ impl<'n> Iterator for NamedGroupsIter<'n> {
855
863
856
864
fn next ( & mut self ) -> Option < Self :: Item > {
857
865
match * self {
866
+ NamedGroupsIter :: Empty =>
867
+ None ,
858
868
NamedGroupsIter :: Native ( ref mut it) =>
859
869
it. next ( ) . map ( |& v| v) ,
860
870
NamedGroupsIter :: Dynamic ( ref mut it) =>
0 commit comments