diff options
| author | bors <bors@rust-lang.org> | 2015-09-04 08:50:56 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-09-04 08:50:56 +0000 |
| commit | b4de424e4175eefb4fda6e3ed634acfab3ec0daf (patch) | |
| tree | 64071602a54a1c9ad7699862ace3d11667dd422a /src/libcore/str | |
| parent | 9d1f8200e70ade40c12a095c763041bd4cfa9f21 (diff) | |
| parent | 48615a68fb01d09749a5b73816d45e0d0669d1f9 (diff) | |
| download | rust-b4de424e4175eefb4fda6e3ed634acfab3ec0daf.tar.gz rust-b4de424e4175eefb4fda6e3ed634acfab3ec0daf.zip | |
Auto merge of #28034 - alexcrichton:new-lines, r=aturon
This commit is an implementation of [RFC 1212][rfc] which tweaks the behavior of
the `str::lines` and `BufRead::lines` iterators. Both iterators now account for
`\r\n` sequences in addition to `\n`, allowing for less surprising behavior
across platforms (especially in the `BufRead` case). Splitting *only* on the
`\n` character can still be achieved with `split('\n')` in both cases.
The `str::lines_any` function is also now deprecated as `str::lines` is a
drop-in replacement for it.
[rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1212-line-endings.md
Closes #28032
Diffstat (limited to 'src/libcore/str')
| -rw-r--r-- | src/libcore/str/mod.rs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 4612fc89008..4664162358d 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -827,7 +827,7 @@ generate_pattern_iterators! { /// Created with the method `.lines()`. #[stable(feature = "rust1", since = "1.0.0")] #[derive(Clone)] -pub struct Lines<'a>(SplitTerminator<'a, char>); +pub struct Lines<'a>(Map<SplitTerminator<'a, char>, LinesAnyMap>); #[stable(feature = "rust1", since = "1.0.0")] impl<'a> Iterator for Lines<'a> { @@ -854,8 +854,10 @@ impl<'a> DoubleEndedIterator for Lines<'a> { /// Created with the method `.lines_any()`. #[stable(feature = "rust1", since = "1.0.0")] +#[deprecated(since = "1.4.0", reason = "use lines()/Lines instead now")] #[derive(Clone)] -pub struct LinesAny<'a>(Map<Lines<'a>, LinesAnyMap>); +#[allow(deprecated)] +pub struct LinesAny<'a>(Lines<'a>); /// A nameable, clonable fn type #[derive(Clone)] @@ -887,6 +889,7 @@ impl<'a> FnOnce<(&'a str,)> for LinesAnyMap { } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(deprecated)] impl<'a> Iterator for LinesAny<'a> { type Item = &'a str; @@ -902,6 +905,7 @@ impl<'a> Iterator for LinesAny<'a> { } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(deprecated)] impl<'a> DoubleEndedIterator for LinesAny<'a> { #[inline] fn next_back(&mut self) -> Option<&'a str> { @@ -1289,6 +1293,7 @@ pub trait StrExt { fn rmatch_indices<'a, P: Pattern<'a>>(&'a self, pat: P) -> RMatchIndices<'a, P> where P::Searcher: ReverseSearcher<'a>; fn lines(&self) -> Lines; + #[allow(deprecated)] fn lines_any(&self) -> LinesAny; fn char_len(&self) -> usize; fn slice_chars(&self, begin: usize, end: usize) -> &str; @@ -1428,12 +1433,13 @@ impl StrExt for str { } #[inline] fn lines(&self) -> Lines { - Lines(self.split_terminator('\n')) + Lines(self.split_terminator('\n').map(LinesAnyMap)) } #[inline] + #[allow(deprecated)] fn lines_any(&self) -> LinesAny { - LinesAny(self.lines().map(LinesAnyMap)) + LinesAny(self.lines()) } #[inline] |
