mirror of https://github.com/rust-lang/rfcs.git
Update builder and iterator types.
This commit is contained in:
parent
20ffd8c2b8
commit
5ecde0cabd
|
@ -177,7 +177,7 @@ impl Regex {
|
|||
|
||||
/// Returns an iterator of successive non-overlapping matches of this regex
|
||||
/// in the text given.
|
||||
pub fn find_iter<'r, 't>(&'r self, text: &'t str) -> FindIter<'r, 't>;
|
||||
pub fn find_iter<'r, 't>(&'r self, text: &'t str) -> Matches<'r, 't>;
|
||||
|
||||
/// Returns the leftmost-first match of this regex in the text given with
|
||||
/// locations for all capturing groups that participated in the match.
|
||||
|
@ -185,7 +185,7 @@ impl Regex {
|
|||
|
||||
/// Returns an iterator of successive non-overlapping matches with capturing
|
||||
/// group information in the text given.
|
||||
pub fn captures_iter<'r, 't>(&'r self, text: &'t str) -> CapturesIter<'r, 't>;
|
||||
pub fn captures_iter<'r, 't>(&'r self, text: &'t str) -> CaptureMatches<'r, 't>;
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -216,14 +216,14 @@ impl Regex {
|
|||
/// Returns an iterator of substrings of `text` delimited by a match of
|
||||
/// this regular expression. Each element yielded by the iterator corresponds
|
||||
/// to text that *isn't* matched by this regex.
|
||||
pub fn split<'r, 't>(&'r self, text: &'t str) -> SplitsIter<'r, 't>;
|
||||
pub fn split<'r, 't>(&'r self, text: &'t str) -> Split<'r, 't>;
|
||||
|
||||
/// Returns an iterator of at most `limit` substrings of `text` delimited by
|
||||
/// a match of this regular expression. Each element yielded by the iterator
|
||||
/// corresponds to text that *isn't* matched by this regex. The remainder of
|
||||
/// `text` that is not split will be the last element yielded by the
|
||||
/// iterator.
|
||||
pub fn splitn<'r, 't>(&'r self, text: &'t str, limit: usize) -> SplitsNIter<'r, 't>;
|
||||
pub fn splitn<'r, 't>(&'r self, text: &'t str, limit: usize) -> SplitN<'r, 't>;
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -254,7 +254,7 @@ impl Regex {
|
|||
/// Returns an iterator over all capturing group in the pattern in the order
|
||||
/// they were defined (by position of the leftmost parenthesis). The name of
|
||||
/// the group is yielded if it has a name, otherwise None is yielded.
|
||||
pub fn capture_names(&self) -> CaptureNamesIter;
|
||||
pub fn capture_names(&self) -> CaptureNames;
|
||||
|
||||
/// Returns the total number of capturing groups in the pattern. This
|
||||
/// includes the implicit capturing group corresponding to the entire
|
||||
|
@ -313,39 +313,39 @@ impl RegexBuilder {
|
|||
///
|
||||
/// N.B. `RegexBuilder::new("...").compile()` is equivalent to
|
||||
/// `Regex::new("...")`.
|
||||
pub fn compile(self) -> Result<Regex, Error>;
|
||||
pub fn build(&self) -> Result<Regex, Error>;
|
||||
|
||||
/// Set the case insensitive flag (i).
|
||||
pub fn case_insensitive(self, yes: bool) -> RegexBuilder;
|
||||
pub fn case_insensitive(&mut self, yes: bool);
|
||||
|
||||
/// Set the multi line flag (m).
|
||||
pub fn multi_line(self, yes: bool) -> RegexBuilder;
|
||||
pub fn multi_line(&mut self, yes: bool);
|
||||
|
||||
/// Set the dot-matches-any-character flag (s).
|
||||
pub fn dot_matches_new_line(self, yes: bool) -> RegexBuilder;
|
||||
pub fn dot_matches_new_line(&mut self, yes: bool);
|
||||
|
||||
/// Set the swap-greedy flag (U).
|
||||
pub fn swap_greed(self, yes: bool) -> RegexBuilder;
|
||||
pub fn swap_greed(&mut self, yes: bool);
|
||||
|
||||
/// Set the ignore whitespace flag (x).
|
||||
pub fn ignore_whitespace(self, yes: bool) -> RegexBuilder;
|
||||
pub fn ignore_whitespace(&mut self, yes: bool);
|
||||
|
||||
/// Set the Unicode flag (u).
|
||||
pub fn unicode(self, yes: bool) -> RegexBuilder;
|
||||
pub fn unicode(&mut self, yes: bool);
|
||||
|
||||
/// Set the approximate size limit (in bytes) of the compiled regular
|
||||
/// expression.
|
||||
///
|
||||
/// If compiling a pattern would approximately exceed this size, then
|
||||
/// compilation will fail.
|
||||
pub fn size_limit(self, limit: usize) -> RegexBuilder;
|
||||
pub fn size_limit(&mut self, limit: usize);
|
||||
|
||||
/// Set the approximate size limit (in bytes) of the cache used by the DFA.
|
||||
///
|
||||
/// This is a per thread limit. Once the DFA fills the cache, it will be
|
||||
/// wiped and refilled again. If the cache is wiped too frequently, the
|
||||
/// DFA will quit and fall back to another matching engine.
|
||||
pub fn dfa_size_limit(self, limit: usize) -> RegexBuilder;
|
||||
pub fn dfa_size_limit(&mut self, limit: usize);
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -402,7 +402,7 @@ and `Index<str>` (for named capture groups). A downside of the `Index` impls is
|
|||
that the return value is bounded to the lifetime of `Captures` instead of the
|
||||
lifetime of the actual text searched because of how the `Index` trait is
|
||||
defined. Callers can work around that limitation if necessary by using an
|
||||
explicit method such as `at` or `name`.
|
||||
explicit method such as `get` or `name`.
|
||||
|
||||
## Replacer
|
||||
[replacer]: #replacer
|
||||
|
@ -759,8 +759,8 @@ trait Regex {
|
|||
type Text: ?Sized;
|
||||
|
||||
fn is_match(&self, text: &Self::Text) -> bool;
|
||||
fn find(&self, text: &Self::Text) -> Option<(usize, usize)>;
|
||||
fn find_iter<'r, 't>(&'r self, text: &'t Self::Text) -> FindIter<'r, 't, Self::Text>;
|
||||
fn find(&self, text: &Self::Text) -> Option<Match>;
|
||||
fn find_iter<'r, 't>(&'r self, text: &'t Self::Text) -> Matches<'r, 't, Self::Text>;
|
||||
// and so on
|
||||
}
|
||||
```
|
||||
|
@ -771,7 +771,7 @@ generic code that searches either a `&str` or a `&[u8]` possible, but the
|
|||
semantics of searching `&str` (always valid UTF-8) or `&[u8]` are quite a bit
|
||||
different with respect to the original `Regex`. Secondly, the trait isn't
|
||||
obviously implementable by others. For example, some of the methods return
|
||||
iterator types such as `FindIter` that are typically implemented with a
|
||||
iterator types such as `Matches` that are typically implemented with a
|
||||
lower level API that isn't exposed. This suggests that a straight-forward
|
||||
traitification of the current API probably isn't appropriate, and perhaps,
|
||||
a better trait needs to be more fundamental to regex searching.
|
||||
|
@ -817,7 +817,7 @@ trait Replacer {
|
|||
```
|
||||
|
||||
But parameterizing the `Captures` type is a little bit tricky. Namely, methods
|
||||
like `at` want to slice the text at match offsets, but this can't be done
|
||||
like `get` want to slice the text at match offsets, but this can't be done
|
||||
safely in generic code without introducing another public trait.
|
||||
|
||||
The final death knell in this idea is that these two implementations cannot
|
||||
|
@ -965,3 +965,7 @@ API proposed in this RFC.
|
|||
error information, use the `regex-syntax` crate directly.
|
||||
* To allow future growth, some character classes may no longer compile to make
|
||||
room for possibly adding class set notation in the future.
|
||||
* Various iterator types have been renamed.
|
||||
* The `RegexBuilder` type now takes an `&mut self` on most methods instead of
|
||||
`self`. Additionally, the final build step now uses `build()` instead of
|
||||
`compile()`.
|
||||
|
|
Loading…
Reference in New Issue