From 89a866cb926874890f5888292608e14be43983eb Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 17 Jan 2021 13:14:50 +0100 Subject: [PATCH] Fix escape checking Signed-off-by: trivernis --- Cargo.toml | 2 +- src/tapemachine.rs | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 68f2722..76687b5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "charred" -version = "0.3.3" +version = "0.3.4" authors = ["trivernis "] edition = "2018" license-file = "LICENSE" diff --git a/src/tapemachine.rs b/src/tapemachine.rs index c375796..b8d963b 100644 --- a/src/tapemachine.rs +++ b/src/tapemachine.rs @@ -145,20 +145,30 @@ impl CharTapeMachine { /// checks if the current char is escaped #[inline] - pub fn check_escaped(&self) -> bool { - self.previous_char == ESCAPE + pub fn check_escaped(&mut self) -> bool { + let start = self.index; + + let escaped = if self.previous_char == ESCAPE { + self.rewind(start - 1); + !self.check_escaped() + } else { + false + }; + self.rewind(start); + + escaped } /// Returns true if the given character is equal to the current one /// and the current character is not escaped #[inline] - pub fn check_char(&self, value: &char) -> bool { + pub fn check_char(&mut self, value: &char) -> bool { self.current_char == *value && !self.check_escaped() } /// Checks if one of the given chars matches the current one #[inline] - pub fn check_any(&self, chars: &[char]) -> bool { + pub fn check_any(&mut self, chars: &[char]) -> bool { !self.check_escaped() && chars.contains(&self.current_char) }