Skip to content

Updated lines doc to include trailing carriage return note #113512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions library/core/src/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,10 @@ impl str {
///
/// Line terminators are not included in the lines returned by the iterator.
///
/// Note that any carriage return (`\r`) not immediately followed by a
/// line feed (`\n`) does not split a line. These carriage returns are
/// thereby included in the produced lines.
///
/// The final line ending is optional. A string that ends with a final line
/// ending will return the same lines as an otherwise identical string
/// without a final line ending.
Expand All @@ -961,18 +965,19 @@ impl str {
/// Basic usage:
///
/// ```
/// let text = "foo\r\nbar\n\nbaz\n";
/// let text = "foo\r\nbar\n\nbaz\r";
/// let mut lines = text.lines();
///
/// assert_eq!(Some("foo"), lines.next());
/// assert_eq!(Some("bar"), lines.next());
/// assert_eq!(Some(""), lines.next());
/// assert_eq!(Some("baz"), lines.next());
/// // Trailing carriage return is included in the last line
/// assert_eq!(Some("baz\r"), lines.next());
///
/// assert_eq!(None, lines.next());
/// ```
///
/// The final line ending isn't required:
/// The final line does not require any ending:
///
/// ```
/// let text = "foo\nbar\n\r\nbaz";
Expand Down