aboutsummaryrefslogtreecommitdiff
path: root/src/re_unicode.rs
diff options
context:
space:
mode:
authorHaibo Huang <hhb@google.com>2021-01-08 17:05:43 -0800
committerJeff Vander Stoep <jeffv@google.com>2021-01-15 19:02:13 +0100
commit47619ddc40d9bed36beb6e2f1aa3a2386d13a3e7 (patch)
tree1620dbd114519448d2d614bdc23ea9422b1232f6 /src/re_unicode.rs
parent8cf4014fd8d2440813aca63402c78195be1b33b7 (diff)
downloadregex-47619ddc40d9bed36beb6e2f1aa3a2386d13a3e7.tar.gz
Upgrade rust/crates/regex to 1.4.3
Test: make Change-Id: I0a2f64e0e7e81dc3e46c5c21ffa0bfbc7b1fb28f
Diffstat (limited to 'src/re_unicode.rs')
-rw-r--r--src/re_unicode.rs31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/re_unicode.rs b/src/re_unicode.rs
index ea95c1b..df87c34 100644
--- a/src/re_unicode.rs
+++ b/src/re_unicode.rs
@@ -1,6 +1,7 @@
use std::borrow::Cow;
use std::collections::HashMap;
use std::fmt;
+use std::iter::FusedIterator;
use std::ops::{Index, Range};
use std::str::FromStr;
use std::sync::Arc;
@@ -747,6 +748,7 @@ impl Regex {
/// whole matched region) is always unnamed.
///
/// `'r` is the lifetime of the compiled regular expression.
+#[derive(Clone, Debug)]
pub struct CaptureNames<'r>(::std::slice::Iter<'r, Option<String>>);
impl<'r> Iterator for CaptureNames<'r> {
@@ -762,12 +764,21 @@ impl<'r> Iterator for CaptureNames<'r> {
fn size_hint(&self) -> (usize, Option<usize>) {
self.0.size_hint()
}
+
+ fn count(self) -> usize {
+ self.0.count()
+ }
}
+impl<'r> ExactSizeIterator for CaptureNames<'r> {}
+
+impl<'r> FusedIterator for CaptureNames<'r> {}
+
/// Yields all substrings delimited by a regular expression match.
///
/// `'r` is the lifetime of the compiled regular expression and `'t` is the
/// lifetime of the string being split.
+#[derive(Debug)]
pub struct Split<'r, 't> {
finder: Matches<'r, 't>,
last: usize,
@@ -797,12 +808,15 @@ impl<'r, 't> Iterator for Split<'r, 't> {
}
}
+impl<'r, 't> FusedIterator for Split<'r, 't> {}
+
/// Yields at most `N` substrings delimited by a regular expression match.
///
/// The last substring will be whatever remains after splitting.
///
/// `'r` is the lifetime of the compiled regular expression and `'t` is the
/// lifetime of the string being split.
+#[derive(Debug)]
pub struct SplitN<'r, 't> {
splits: Split<'r, 't>,
n: usize,
@@ -830,8 +844,14 @@ impl<'r, 't> Iterator for SplitN<'r, 't> {
Some(&text[self.splits.last..])
}
}
+
+ fn size_hint(&self) -> (usize, Option<usize>) {
+ (0, Some(self.n))
+ }
}
+impl<'r, 't> FusedIterator for SplitN<'r, 't> {}
+
/// CaptureLocations is a low level representation of the raw offsets of each
/// submatch.
///
@@ -1059,7 +1079,7 @@ impl<'t, 'i> Index<&'i str> for Captures<'t> {
///
/// The lifetime `'c` corresponds to the lifetime of the `Captures` value, and
/// the lifetime `'t` corresponds to the originally matched text.
-#[derive(Clone)]
+#[derive(Clone, Debug)]
pub struct SubCaptureMatches<'c, 't: 'c> {
caps: &'c Captures<'t>,
it: SubCapturesPosIter<'c>,
@@ -1075,6 +1095,8 @@ impl<'c, 't> Iterator for SubCaptureMatches<'c, 't> {
}
}
+impl<'c, 't> FusedIterator for SubCaptureMatches<'c, 't> {}
+
/// An iterator that yields all non-overlapping capture groups matching a
/// particular regular expression.
///
@@ -1082,6 +1104,7 @@ impl<'c, 't> Iterator for SubCaptureMatches<'c, 't> {
///
/// `'r` is the lifetime of the compiled regular expression and `'t` is the
/// lifetime of the matched string.
+#[derive(Debug)]
pub struct CaptureMatches<'r, 't>(
re_trait::CaptureMatches<'t, ExecNoSyncStr<'r>>,
);
@@ -1098,6 +1121,8 @@ impl<'r, 't> Iterator for CaptureMatches<'r, 't> {
}
}
+impl<'r, 't> FusedIterator for CaptureMatches<'r, 't> {}
+
/// An iterator over all non-overlapping matches for a particular string.
///
/// The iterator yields a `Match` value. The iterator stops when no more
@@ -1105,6 +1130,7 @@ impl<'r, 't> Iterator for CaptureMatches<'r, 't> {
///
/// `'r` is the lifetime of the compiled regular expression and `'t` is the
/// lifetime of the matched string.
+#[derive(Debug)]
pub struct Matches<'r, 't>(re_trait::Matches<'t, ExecNoSyncStr<'r>>);
impl<'r, 't> Iterator for Matches<'r, 't> {
@@ -1116,6 +1142,8 @@ impl<'r, 't> Iterator for Matches<'r, 't> {
}
}
+impl<'r, 't> FusedIterator for Matches<'r, 't> {}
+
/// Replacer describes types that can be used to replace matches in a string.
///
/// In general, users of this crate shouldn't need to implement this trait,
@@ -1215,6 +1243,7 @@ where
/// and performant (since capture groups don't need to be found).
///
/// `'t` is the lifetime of the literal text.
+#[derive(Clone, Debug)]
pub struct NoExpand<'t>(pub &'t str);
impl<'t> Replacer for NoExpand<'t> {