10
10
11
11
use std:: borrow:: Cow ;
12
12
use std:: collections:: HashMap ;
13
- use std:: collections:: hash_map;
14
13
use std:: fmt;
15
14
use std:: ops:: Index ;
16
15
use std:: str:: FromStr ;
@@ -22,7 +21,7 @@ use exec::{Exec, ExecNoSync};
22
21
use expand:: expand_bytes;
23
22
use error:: Error ;
24
23
use re_builder:: bytes:: RegexBuilder ;
25
- use re_trait:: { self , RegularExpression , Locations , SubCapturesPosIter } ;
24
+ use re_trait:: { self , RegularExpression , Locations } ;
26
25
27
26
/// Match represents a single match of a regex in a haystack.
28
27
///
@@ -790,29 +789,6 @@ impl<'t> Captures<'t> {
790
789
self . named_groups . get ( name) . and_then ( |& i| self . get ( i) )
791
790
}
792
791
793
- /// Creates an iterator of all the capture groups in order of appearance
794
- /// in the regular expression.
795
- pub fn iter < ' c > ( & ' c self ) -> SubCapturesIter < ' c , ' t > {
796
- SubCapturesIter { idx : 0 , caps : self }
797
- }
798
-
799
- /// Creates an iterator of all the capture group positions in order of
800
- /// appearance in the regular expression. Positions are byte indices
801
- /// in terms of the original string matched.
802
- pub fn iter_pos ( & self ) -> SubCapturesPosIter {
803
- self . locs . iter ( )
804
- }
805
-
806
- /// Creates an iterator of all named groups as an tuple with the group
807
- /// name and the value. The iterator returns these values in arbitrary
808
- /// order.
809
- pub fn iter_named < ' c > ( & ' c self ) -> SubCapturesNamedIter < ' c , ' t > {
810
- SubCapturesNamedIter {
811
- caps : self ,
812
- names : self . named_groups . iter ( )
813
- }
814
- }
815
-
816
792
/// Expands all instances of `$name` in `text` to the corresponding capture
817
793
/// group `name`, and writes them to the `dst` buffer given.
818
794
///
@@ -873,7 +849,7 @@ impl<'c, 't> fmt::Debug for CapturesDebug<'c, 't> {
873
849
let slot_to_name: HashMap < & usize , & String > =
874
850
self . 0 . named_groups . iter ( ) . map ( |( a, b) | ( b, a) ) . collect ( ) ;
875
851
let mut map = f. debug_map ( ) ;
876
- for ( slot, m) in self . 0 . iter_pos ( ) . enumerate ( ) {
852
+ for ( slot, m) in self . 0 . locs . iter ( ) . enumerate ( ) {
877
853
let m = m. map ( |( s, e) | escape_bytes ( & self . 0 . text [ s..e] ) ) ;
878
854
if let Some ( ref name) = slot_to_name. get ( & slot) {
879
855
map. entry ( & name, & m) ;
@@ -926,49 +902,6 @@ impl<'t, 'i> Index<&'i str> for Captures<'t> {
926
902
}
927
903
}
928
904
929
- /// An iterator over capture groups for a particular match of a regular
930
- /// expression.
931
- ///
932
- /// `'c` is the lifetime of the captures and `'t` is the lifetime of the
933
- /// matched text.
934
- pub struct SubCapturesIter < ' c , ' t : ' c > {
935
- idx : usize ,
936
- caps : & ' c Captures < ' t > ,
937
- }
938
-
939
- impl < ' c , ' t > Iterator for SubCapturesIter < ' c , ' t > {
940
- type Item = Option < & ' t [ u8 ] > ;
941
-
942
- fn next ( & mut self ) -> Option < Option < & ' t [ u8 ] > > {
943
- if self . idx < self . caps . len ( ) {
944
- self . idx += 1 ;
945
- Some ( self . caps . get ( self . idx - 1 ) . map ( |m| m. as_bytes ( ) ) )
946
- } else {
947
- None
948
- }
949
- }
950
- }
951
-
952
- /// An Iterator over named capture groups as a tuple with the group name and
953
- /// the value.
954
- ///
955
- /// `'c` is the lifetime of the captures and `'t` is the lifetime of the
956
- /// matched text.
957
- pub struct SubCapturesNamedIter < ' c , ' t : ' c > {
958
- caps : & ' c Captures < ' t > ,
959
- names : hash_map:: Iter < ' c , String , usize > ,
960
- }
961
-
962
- impl < ' c , ' t > Iterator for SubCapturesNamedIter < ' c , ' t > {
963
- type Item = ( & ' c str , Option < & ' t [ u8 ] > ) ;
964
-
965
- fn next ( & mut self ) -> Option < ( & ' c str , Option < & ' t [ u8 ] > ) > {
966
- self . names . next ( ) . map ( |( name, & pos) | {
967
- ( & * * name, self . caps . get ( pos) . map ( |m| m. as_bytes ( ) ) )
968
- } )
969
- }
970
- }
971
-
972
905
/// Replacer describes types that can be used to replace matches in a byte
973
906
/// string.
974
907
///
0 commit comments