Extracts the property line from `path` if present.
(path: P)
| 79 | |
| 80 | /// Extracts the property line from `path` if present. |
| 81 | pub fn extract_propline<P: AsRef<Path>>(path: P) -> io::Result<PropLine> { |
| 82 | let input = File::open(path)?; |
| 83 | let mut input = BufReader::new(input); |
| 84 | |
| 85 | let mut line1 = String::new(); |
| 86 | if input.read_line(&mut line1)? == 0 { |
| 87 | return Ok(PropLine::default()); |
| 88 | } |
| 89 | strip_newline(&mut line1); |
| 90 | if !line1.starts_with("#!") { |
| 91 | return Ok(PropLine::default()); |
| 92 | } |
| 93 | |
| 94 | let mut line2 = String::new(); |
| 95 | if input.read_line(&mut line2)? == 0 { |
| 96 | return Ok(PropLine::default()); |
| 97 | } |
| 98 | strip_newline(&mut line2); |
| 99 | parse_propline(&line2) |
| 100 | } |
| 101 | |
| 102 | #[cfg(test)] |
| 103 | mod tests { |
no test coverage detected