Open QnnOkabayashi opened 1 month ago
LGTM (once Clippy passes), but I wouldn't merge it without the corresponding changes to the Iterator
/DoubleEndedIterator
impls of RawLines
and Lines
.
For example, this test should pass:
#[test]
fn lines_iterator_len_mismatch() {
let r = Rope::from("foo\n");
assert_eq!(r.lines().len(), 2);
let mut lines = r.lines();
assert_eq!(lines.next().unwrap(), "foo");
assert_eq!(lines.next().unwrap(), "");
assert_eq!(lines.next(), None);
let mut lines = r.lines();
assert_eq!(lines.next_back().unwrap(), "");
assert_eq!(lines.next_back().unwrap(), "foo");
assert_eq!(lines.next_back(), None);
}
Related: https://github.com/nomad/crop/issues/20
This makes the concept of "lines" and line counts align with what we would expect when displaying text in a text editor, e.g. the empty string is 1 line, the string
"foo\n"
is 2 lines,"foo\nbar"
is 2 lines, and so on. The main difference is that trailing newlines now count as another line.