Closed
Description
According to the documentation of std::string::Lines
,
Lines are ended with either a newline (\n) or a carriage return with a line feed (\r\n).
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.
By my reading of these rules, a bare carriage return at the end of a string ought to be preserved, because a bare carriage return is not a line ending. That is, I expect the following:
let lines : Vec<&'static str> = "one\r\ntwo\r".lines().collect();
assert_eq!(lines[0], "one");
assert_eq!(lines[1], "two\r");
In fact, this second assertion fails. The actual result is that lines[1] == "two"
.
Meta
rustc --version --verbose
:
rustc 1.66.0 (69f9c33d7 2022-12-12)
binary: rustc
commit-hash: 69f9c33d71c871fc16ac445211281c6e7a340943
commit-date: 2022-12-12
host: x86_64-unknown-linux-gnu
release: 1.66.0
LLVM version: 15.0.2