(&mut self, input: &str)
| 809 | } |
| 810 | |
| 811 | pub fn escape_string(&mut self, input: &str) -> Option<String> { |
| 812 | let mut escaped_string = String::new(); |
| 813 | let mut chars = input.chars(); |
| 814 | while let Some(ch) = chars.next() { |
| 815 | if ch == '\\' { |
| 816 | let c = match chars.next() { |
| 817 | Some('n') => '\n', |
| 818 | Some('r') => '\r', |
| 819 | Some('t') => '\t', |
| 820 | Some('\\') => '\\', |
| 821 | Some('\'') => '\'', |
| 822 | Some('\"') => '\"', |
| 823 | Some('0') => '\0', |
| 824 | Some(ch) => { |
| 825 | self.error(&format!("Invalid escape sequence: \\{}", ch)); |
| 826 | return None; |
| 827 | } |
| 828 | None => { |
| 829 | self.error("Unterminated escape sequence"); |
| 830 | return None; |
| 831 | } |
| 832 | }; |
| 833 | escaped_string.push(c); |
| 834 | } else { |
| 835 | escaped_string.push(ch); |
| 836 | } |
| 837 | } |
| 838 | Some(escaped_string) |
| 839 | } |
| 840 | |
| 841 | pub fn advance(&mut self) { |
| 842 | self.previous = mem::take(&mut self.current); |
no test coverage detected