git_conventional/lines.rs
1#[derive(Clone, Debug)]
2pub(crate) struct LinesWithTerminator<'a> {
3 data: &'a str,
4}
5
6impl<'a> LinesWithTerminator<'a> {
7 pub(crate) fn new(data: &'a str) -> LinesWithTerminator<'a> {
8 LinesWithTerminator { data }
9 }
10}
11
12impl<'a> Iterator for LinesWithTerminator<'a> {
13 type Item = &'a str;
14
15 #[inline]
16 fn next(&mut self) -> Option<&'a str> {
17 match self.data.find('\n') {
18 None if self.data.is_empty() => None,
19 None => {
20 let line = self.data;
21 self.data = "";
22 Some(line)
23 }
24 Some(end) => {
25 let line = &self.data[..end + 1];
26 self.data = &self.data[end + 1..];
27 Some(line)
28 }
29 }
30 }
31}