Fix escape checking

Signed-off-by: trivernis <trivernis@protonmail.com>
master
trivernis 3 years ago
parent bca9220cab
commit 89a866cb92
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -1,6 +1,6 @@
[package] [package]
name = "charred" name = "charred"
version = "0.3.3" version = "0.3.4"
authors = ["trivernis <trivernis@protonmail.com>"] authors = ["trivernis <trivernis@protonmail.com>"]
edition = "2018" edition = "2018"
license-file = "LICENSE" license-file = "LICENSE"

@ -145,20 +145,30 @@ impl CharTapeMachine {
/// checks if the current char is escaped /// checks if the current char is escaped
#[inline] #[inline]
pub fn check_escaped(&self) -> bool { pub fn check_escaped(&mut self) -> bool {
self.previous_char == ESCAPE 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 /// Returns true if the given character is equal to the current one
/// and the current character is not escaped /// and the current character is not escaped
#[inline] #[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() self.current_char == *value && !self.check_escaped()
} }
/// Checks if one of the given chars matches the current one /// Checks if one of the given chars matches the current one
#[inline] #[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) !self.check_escaped() && chars.contains(&self.current_char)
} }

Loading…
Cancel
Save