mirror of
https://github.com/uutils/coreutils
synced 2024-07-23 10:54:14 +00:00
ptx: escape regular expression character class special chars
This commit is contained in:
parent
4889128ede
commit
83a64f4afe
|
@ -31,6 +31,8 @@ const ABOUT: &str = "\
|
|||
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 /'.";
|
||||
|
||||
const REGEX_CHARCLASS: &str = "^-]\\";
|
||||
|
||||
#[derive(Debug)]
|
||||
enum OutFormat {
|
||||
Dumb,
|
||||
|
@ -166,7 +168,11 @@ impl WordFilter {
|
|||
break_set
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(|c| c.to_string())
|
||||
.map(|c| if REGEX_CHARCLASS.contains(c) {
|
||||
format!("\\{}", c)
|
||||
} else {
|
||||
c.to_string()
|
||||
})
|
||||
.collect::<Vec<String>>()
|
||||
.join("")
|
||||
)
|
||||
|
|
2
tests/fixtures/ptx/break_file
vendored
2
tests/fixtures/ptx/break_file
vendored
|
@ -1 +1 @@
|
|||
abc_e
|
||||
abc_e^-]\
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
.xx "" "let's check special characte" "rs:" ""
|
||||
.xx "" """quote" "s"", for roff" ""
|
||||
.xx "" "oh, and back\sla" "sh" ""
|
||||
.xx "" "oh, and back\" "slash" ""
|
||||
.xx "" "and" "some other like %a, b#, c$c" ""
|
||||
.xx "" "let's check" "special characters:" ""
|
||||
.xx "" "let's check special charac" "ters:" ""
|
||||
|
|
Loading…
Reference in a new issue