1use alloc::string::String;
2
3use super::{Chars, Rope};
4
5pub struct Lines<'a> {
6 chars: Chars<'a>,
7}
8
9unsafe impl<'a> Sync for Lines<'a> {}
10unsafe impl<'a> Send for Lines<'a> {}
11
12impl<'a> From<&'a Rope> for Lines<'a> {
13 #[inline]
14 fn from(rope: &'a Rope) -> Lines<'a> {
15 Lines {
16 chars: Chars::from(rope),
17 }
18 }
19}
20
21impl<'a> Iterator for Lines<'a> {
22 type Item = String;
23
24 #[inline]
25 fn next(&mut self) -> Option<Self::Item> {
26 let mut string = String::new();
27
28 while let Some(ch) = self.chars.next() {
29 if ch == '\r' {
30 if let Some(next_ch) = self.chars.next() {
31 if next_ch == '\n' {
32 continue;
33 } else {
34 string.push(ch);
35 string.push(next_ch);
36 }
37 } else {
38 string.push(ch);
39 break;
40 }
41 } else if ch != '\n' {
42 string.push(ch);
43 } else {
44 break;
45 }
46 }
47
48 if string.len() != 0 {
49 Some(string)
50 } else {
51 None
52 }
53 }
54}