@@ -952,6 +952,10 @@ impl str {
952
952
///
953
953
/// Line terminators are not included in the lines returned by the iterator.
954
954
///
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
+ ///
955
959
/// The final line ending is optional. A string that ends with a final line
956
960
/// ending will return the same lines as an otherwise identical string
957
961
/// without a final line ending.
@@ -961,18 +965,19 @@ impl str {
961
965
/// Basic usage:
962
966
///
963
967
/// ```
964
- /// let text = "foo\r\nbar\n\nbaz\n ";
968
+ /// let text = "foo\r\nbar\n\nbaz\r ";
965
969
/// let mut lines = text.lines();
966
970
///
967
971
/// assert_eq!(Some("foo"), lines.next());
968
972
/// assert_eq!(Some("bar"), lines.next());
969
973
/// 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());
971
976
///
972
977
/// assert_eq!(None, lines.next());
973
978
/// ```
974
979
///
975
- /// The final line ending isn't required :
980
+ /// The final line does not require any ending :
976
981
///
977
982
/// ```
978
983
/// let text = "foo\nbar\n\r\nbaz";
0 commit comments