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:
parent
4889128ede
commit
83a64f4afe
3 changed files with 9 additions and 2 deletions
|
@ -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("")
|
||||||
)
|
)
|
||||||
|
|
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 "" "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:" ""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue