@@ -952,6 +952,10 @@ impl str {
952952 ///
953953 /// Line terminators are not included in the lines returned by the iterator.
954954 ///
955+ /// Note that any carriage return (`\r`) not immediately followed by a
956+ /// line feed (`\n`) does not split a line. These carriage returns are
957+ /// thereby included in the produced lines.
958+ ///
955959 /// The final line ending is optional. A string that ends with a final line
956960 /// ending will return the same lines as an otherwise identical string
957961 /// without a final line ending.
@@ -961,18 +965,19 @@ impl str {
961965 /// Basic usage:
962966 ///
963967 /// ```
964- /// let text = "foo\r\nbar\n\nbaz\n ";
968+ /// let text = "foo\r\nbar\n\nbaz\r ";
965969 /// let mut lines = text.lines();
966970 ///
967971 /// assert_eq!(Some("foo"), lines.next());
968972 /// assert_eq!(Some("bar"), lines.next());
969973 /// assert_eq!(Some(""), lines.next());
970- /// assert_eq!(Some("baz"), lines.next());
974+ /// // Trailing carriage return is included in the last line
975+ /// assert_eq!(Some("baz\r"), lines.next());
971976 ///
972977 /// assert_eq!(None, lines.next());
973978 /// ```
974979 ///
975- /// The final line ending isn't required :
980+ /// The final line does not require any ending :
976981 ///
977982 /// ```
978983 /// let text = "foo\nbar\n\r\nbaz";
0 commit comments