@@ -350,7 +350,6 @@ impl Regex {
350
350
re : self ,
351
351
search : text,
352
352
last_end : 0 ,
353
- last_match : None ,
354
353
}
355
354
}
356
355
@@ -454,7 +453,6 @@ impl Regex {
454
453
FindCaptures {
455
454
re : self ,
456
455
search : text,
457
- last_match : None ,
458
456
last_end : 0 ,
459
457
}
460
458
}
@@ -1059,7 +1057,6 @@ impl<'t> Iterator for SubCapturesNamed<'t> {
1059
1057
pub struct FindCaptures < ' r , ' t > {
1060
1058
re : & ' r Regex ,
1061
1059
search : & ' t str ,
1062
- last_match : Option < usize > ,
1063
1060
last_end : usize ,
1064
1061
}
1065
1062
@@ -1079,16 +1076,12 @@ impl<'r, 't> Iterator for FindCaptures<'r, 't> {
1079
1076
1080
1077
// Don't accept empty matches immediately following a match.
1081
1078
// i.e., no infinite loops please.
1082
- if e == s && Some ( self . last_end ) == self . last_match {
1083
- if self . last_end >= self . search . len ( ) {
1084
- return None ;
1085
- }
1079
+ if e == s {
1086
1080
self . last_end += self . search [ self . last_end ..] . chars ( )
1087
- . next ( ) . unwrap ( ) . len_utf8 ( ) ;
1088
- return self . next ( )
1081
+ . next ( ) . map ( |c| c. len_utf8 ( ) ) . unwrap_or ( 0 ) ;
1082
+ } else {
1083
+ self . last_end = e;
1089
1084
}
1090
- self . last_end = e;
1091
- self . last_match = Some ( self . last_end ) ;
1092
1085
Some ( Captures :: new ( self . re , self . search , caps) )
1093
1086
}
1094
1087
}
@@ -1104,7 +1097,6 @@ impl<'r, 't> Iterator for FindCaptures<'r, 't> {
1104
1097
pub struct FindMatches < ' r , ' t > {
1105
1098
re : & ' r Regex ,
1106
1099
search : & ' t str ,
1107
- last_match : Option < usize > ,
1108
1100
last_end : usize ,
1109
1101
}
1110
1102
@@ -1124,16 +1116,12 @@ impl<'r, 't> Iterator for FindMatches<'r, 't> {
1124
1116
1125
1117
// Don't accept empty matches immediately following a match.
1126
1118
// i.e., no infinite loops please.
1127
- if e == s && Some ( self . last_end ) == self . last_match {
1128
- if self . last_end >= self . search . len ( ) {
1129
- return None ;
1130
- }
1119
+ if e == s {
1131
1120
self . last_end += self . search [ self . last_end ..] . chars ( )
1132
- . next ( ) . unwrap ( ) . len_utf8 ( ) ;
1133
- return self . next ( )
1121
+ . next ( ) . map ( |c| c. len_utf8 ( ) ) . unwrap_or ( 1 ) ;
1122
+ } else {
1123
+ self . last_end = e;
1134
1124
}
1135
- self . last_end = e;
1136
- self . last_match = Some ( self . last_end ) ;
1137
1125
Some ( ( s, e) )
1138
1126
}
1139
1127
}
0 commit comments