diff options
| author | fee1-dead <ent3rm4n@gmail.com> | 2023-07-30 07:13:02 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-30 07:13:02 +0000 |
| commit | b97da7515648b571e859745e4e563b13fc39ecab (patch) | |
| tree | 3d735b9568d4deedc843150569f9b3b0fdb5f7c5 | |
| parent | 3143030cda04212275a6121c6156c57478cb6681 (diff) | |
| parent | 116aacc2a9ce7f39e50584169d6d8917eb33ca2b (diff) | |
| download | rust-b97da7515648b571e859745e4e563b13fc39ecab.tar.gz rust-b97da7515648b571e859745e4e563b13fc39ecab.zip | |
Rollup merge of #113512 - vallentin:lines-doc, r=workingjubilee
Updated lines doc to include trailing carriage return note Updated `str::lines` doc to include explicit info about (trailing) carriage returns. Reference: #100311
| -rw-r--r-- | library/core/src/str/mod.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index 07a5990e595..71c03f7bfc5 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -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. @@ -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"; |
