Skip to content

Commit

Permalink
Rollup merge of #113512 - vallentin:lines-doc, r=workingjubilee
Browse files Browse the repository at this point in the history
Updated lines doc to include trailing carriage return note

Updated `str::lines` doc to include explicit info about (trailing) carriage returns.

Reference: #100311
  • Loading branch information
fee1-dead authored Jul 30, 2023
2 parents 3143030 + 116aacc commit b97da75
Showing 1 changed file with 8 additions and 3 deletions.
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

0 comments on commit b97da75

Please sign in to comment.