Skip to content

Commit 09dd215

Browse files
committed
Remove last_match fields
1 parent f824afb commit 09dd215

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

src/re.rs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ impl Regex {
350350
re: self,
351351
search: text,
352352
last_end: 0,
353-
last_match: None,
354353
}
355354
}
356355

@@ -454,7 +453,6 @@ impl Regex {
454453
FindCaptures {
455454
re: self,
456455
search: text,
457-
last_match: None,
458456
last_end: 0,
459457
}
460458
}
@@ -1059,7 +1057,6 @@ impl<'t> Iterator for SubCapturesNamed<'t> {
10591057
pub struct FindCaptures<'r, 't> {
10601058
re: &'r Regex,
10611059
search: &'t str,
1062-
last_match: Option<usize>,
10631060
last_end: usize,
10641061
}
10651062

@@ -1079,16 +1076,12 @@ impl<'r, 't> Iterator for FindCaptures<'r, 't> {
10791076

10801077
// Don't accept empty matches immediately following a match.
10811078
// 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 {
10861080
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;
10891084
}
1090-
self.last_end = e;
1091-
self.last_match = Some(self.last_end);
10921085
Some(Captures::new(self.re, self.search, caps))
10931086
}
10941087
}
@@ -1104,7 +1097,6 @@ impl<'r, 't> Iterator for FindCaptures<'r, 't> {
11041097
pub struct FindMatches<'r, 't> {
11051098
re: &'r Regex,
11061099
search: &'t str,
1107-
last_match: Option<usize>,
11081100
last_end: usize,
11091101
}
11101102

@@ -1124,16 +1116,12 @@ impl<'r, 't> Iterator for FindMatches<'r, 't> {
11241116

11251117
// Don't accept empty matches immediately following a match.
11261118
// 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 {
11311120
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;
11341124
}
1135-
self.last_end = e;
1136-
self.last_match = Some(self.last_end);
11371125
Some((s, e))
11381126
}
11391127
}

0 commit comments

Comments
 (0)