1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

ptx: escape regular expression character class special chars

This commit is contained in:
Michael Kefeder 2022-04-30 10:01:11 +02:00
parent 4889128ede
commit 83a64f4afe
3 changed files with 9 additions and 2 deletions

View file

@ -31,6 +31,8 @@ const ABOUT: &str = "\
Mandatory arguments to long options are mandatory for short options too.\n\ Mandatory arguments to long options are mandatory for short options too.\n\
With no FILE, or when FILE is -, read standard input. Default is '-F /'."; With no FILE, or when FILE is -, read standard input. Default is '-F /'.";
const REGEX_CHARCLASS: &str = "^-]\\";
#[derive(Debug)] #[derive(Debug)]
enum OutFormat { enum OutFormat {
Dumb, Dumb,
@ -166,7 +168,11 @@ impl WordFilter {
break_set break_set
.unwrap() .unwrap()
.into_iter() .into_iter()
.map(|c| c.to_string()) .map(|c| if REGEX_CHARCLASS.contains(c) {
format!("\\{}", c)
} else {
c.to_string()
})
.collect::<Vec<String>>() .collect::<Vec<String>>()
.join("") .join("")
) )

View file

@ -1 +1 @@
abc_e abc_e^-]\

View file

@ -29,6 +29,7 @@
.xx "" "let's check special characte" "rs:" "" .xx "" "let's check special characte" "rs:" ""
.xx "" """quote" "s"", for roff" "" .xx "" """quote" "s"", for roff" ""
.xx "" "oh, and back\sla" "sh" "" .xx "" "oh, and back\sla" "sh" ""
.xx "" "oh, and back\" "slash" ""
.xx "" "and" "some other like %a, b#, c$c" "" .xx "" "and" "some other like %a, b#, c$c" ""
.xx "" "let's check" "special characters:" "" .xx "" "let's check" "special characters:" ""
.xx "" "let's check special charac" "ters:" "" .xx "" "let's check special charac" "ters:" ""