From f8b16a7ddd818f10e8a770007e0e13ae212847cf Mon Sep 17 00:00:00 2001 From: Arijit Basu Date: Wed, 26 Oct 2022 04:10:56 +0530 Subject: [PATCH] Rebase main --- src/init.lua | 1 - src/lib.rs | 1 - src/newlines.rs | 79 ------------------------------------------------- 3 files changed, 81 deletions(-) delete mode 100644 src/newlines.rs diff --git a/src/init.lua b/src/init.lua index ce7acf56..4a82bb6b 100644 --- a/src/init.lua +++ b/src/init.lua @@ -2563,4 +2563,3 @@ end -- You can also use nested tables such as -- `xplr.fn.custom.my_plugin.my_function` to define custom functions. xplr.fn.custom = {} - diff --git a/src/lib.rs b/src/lib.rs index c1f48f80..8314c804 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,6 @@ pub mod pipe; pub mod pwd_watcher; pub mod runner; pub mod ui; -pub mod newlines; #[cfg(test)] mod tests { diff --git a/src/newlines.rs b/src/newlines.rs deleted file mode 100644 index 231ba282..00000000 --- a/src/newlines.rs +++ /dev/null @@ -1,79 +0,0 @@ -struct UnescapedString<'a> { - s: std::str::Chars<'a>, -} - -impl<'a> UnescapedString<'a> { - fn new(s: &'a str) -> Self { - Self { s: s.chars() } - } -} - -impl Iterator for UnescapedString<'_> { - type Item = Result; - - fn next(&mut self) -> Option { - self.s.next().map(|c| match c { - '\\' => match self.s.next() { - None => Err(Error::EscapeAtEndOfString), - Some('n') => Ok('\n'), - Some('\\') => Ok('\\'), - Some(c) => Err(Error::UnrecognizedEscapedChar(c)), - }, - c => Ok(c), - }) - } -} - -#[derive(Debug, PartialEq)] -pub enum Error { - EscapeAtEndOfString, - UnrecognizedEscapedChar(char), -} - -use std::fmt; - -impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Error::EscapeAtEndOfString => { - write!(f, "Escape character at the end of the string") - } - Error::UnrecognizedEscapedChar(c) => { - write!(f, "Unrecognized escaped char: '{}'", c) - } - } - } -} - -impl std::error::Error for Error {} - -struct EscapedString<'a> { - s: std::str::Chars<'a>, -} - -impl<'a> EscapedString<'a> { - fn new(s: &'a str) -> Self { - Self { s: s.chars() } - } -} - -impl Iterator for EscapedString<'_> { - type Item = String; - - fn next(&mut self) -> Option { - match self.s.next() { - None => None, - Some('\\') => Some(String::from("\\\\")), - Some('\n') => Some(String::from("\\n")), - Some(c) => Some(String::from(c)), - } - } -} - -pub fn escape_string(s: &str) -> String { - EscapedString::new(s).collect() -} - -pub fn unescape_string(s: &str) -> Result { - UnescapedString::new(s).collect() -}