Skip to content

Commit

Permalink
Add escaped char support #40
Browse files Browse the repository at this point in the history
  • Loading branch information
dalance committed Nov 29, 2023
1 parent 1bb5517 commit 1ba0025
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/ambr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use amber::pipeline_finder::PipelineFinder;
use amber::pipeline_matcher::PipelineMatcher;
use amber::pipeline_replacer::PipelineReplacer;
use amber::pipeline_sorter::PipelineSorter;
use amber::util::{as_secsf64, decode_error, exit, read_from_file};
use amber::util::{as_secsf64, decode_error, exit, handle_escape, read_from_file};
use crossbeam::channel::unbounded;
use lazy_static::lazy_static;
use serde::Deserialize;
Expand Down Expand Up @@ -379,7 +379,7 @@ fn main() {
}
}
} else {
opt.keyword.into_bytes()
handle_escape(&opt.keyword).into_bytes()
};

let replacement = if opt.rep_from_file {
Expand All @@ -394,7 +394,7 @@ fn main() {
}
}
} else {
opt.replacement.into_bytes()
handle_escape(&opt.replacement).into_bytes()
};

// ---------------------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions src/ambs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use amber::pipeline_finder::PipelineFinder;
use amber::pipeline_matcher::PipelineMatcher;
use amber::pipeline_printer::PipelinePrinter;
use amber::pipeline_sorter::PipelineSorter;
use amber::util::{as_secsf64, decode_error, exit, read_from_file};
use amber::util::{as_secsf64, decode_error, exit, handle_escape, read_from_file};
use crossbeam::channel::unbounded;
use lazy_static::lazy_static;
use serde::Deserialize;
Expand Down Expand Up @@ -357,7 +357,7 @@ fn main() {
}
}
} else {
opt.keyword.into_bytes()
handle_escape(&opt.keyword).into_bytes()
};

// ---------------------------------------------------------------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ pub fn exit(code: i32, console: &mut Console) -> ! {
process::exit(code);
}

pub fn handle_escape(text: &str) -> String {
let text = text.replace("\\n", "\n");
let text = text.replace("\\r", "\r");
let text = text.replace("\\t", "\t");
let text = text.replace("\\\\", "\\");
text
}

#[cfg(not(windows))]
pub fn set_c_lflag(c_lflag: Option<termios::tcflag_t>) {
if let Ok(mut termios) = termios::Termios::from_fd(0) {
Expand Down

0 comments on commit 1ba0025

Please sign in to comment.