| 12 | |
| 13 | impl From<&str> for Annotation { |
| 14 | fn from(text: &str) -> Self { |
| 15 | const HIDE_LINES: &str = "hide_lines="; |
| 16 | let is_hide_lines = text.starts_with(HIDE_LINES); |
| 17 | |
| 18 | if is_hide_lines { |
| 19 | Annotation::HideLines( |
| 20 | text.get(HIDE_LINES.len()..) |
| 21 | .unwrap_or("") |
| 22 | .split(' ') |
| 23 | .filter(|r| r.trim() != "") |
| 24 | .map(|range| { |
| 25 | let is_range = range.contains('-'); |
| 26 | |
| 27 | if is_range { |
| 28 | let range = range.split('-').collect::<Vec<_>>(); |
| 29 | let start = range[0].parse().unwrap(); |
| 30 | let end = range[1].parse().unwrap(); |
| 31 | |
| 32 | Range { start, end } |
| 33 | } else { |
| 34 | let line_no = range.parse::<usize>().unwrap(); |
| 35 | Range { |
| 36 | start: line_no, |
| 37 | end: line_no, |
| 38 | } |
| 39 | } |
| 40 | }) |
| 41 | .collect(), |
| 42 | ) |
| 43 | } else { |
| 44 | Annotation::Other(String::from(text)) |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | impl Annotation { |