std: Account for CRLF in {str, BufRead}::lines

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
This commit is contained in:
Alex Crichton
2015-08-26 17:30:45 -07:00
parent 35b14544e1
commit 48615a68fb
6 changed files with 27 additions and 16 deletions

View File

@@ -132,7 +132,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String {
if comment.starts_with("/*") {
let lines = comment[3..comment.len() - 2]
.lines_any()
.lines()
.map(|s| s.to_string())
.collect::<Vec<String> >();