equal
deleted
inserted
replaced
22 use std::vec::Vec; |
22 use std::vec::Vec; |
23 |
23 |
24 lazy_static! { |
24 lazy_static! { |
25 static ref RE_ESCAPE: Vec<Vec<u8>> = { |
25 static ref RE_ESCAPE: Vec<Vec<u8>> = { |
26 let mut v: Vec<Vec<u8>> = (0..=255).map(|byte| vec![byte]).collect(); |
26 let mut v: Vec<Vec<u8>> = (0..=255).map(|byte| vec![byte]).collect(); |
27 let to_escape = b"()[]{}?*+-|^$\\.&~# \t\n\r\x0b\x0c"; |
27 let to_escape = b"()[]{}?*+-|^$\\.&~#\t\n\r\x0b\x0c"; |
28 for byte in to_escape { |
28 for byte in to_escape { |
29 v[*byte as usize].insert(0, b'\\'); |
29 v[*byte as usize].insert(0, b'\\'); |
30 } |
30 } |
31 v |
31 v |
32 }; |
32 }; |
639 let untouched = |
639 let untouched = |
640 br#"!"%',/0123456789:;<=>@ABCDEFGHIJKLMNOPQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz"#; |
640 br#"!"%',/0123456789:;<=>@ABCDEFGHIJKLMNOPQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz"#; |
641 assert_eq!(escape_pattern(untouched), untouched.to_vec()); |
641 assert_eq!(escape_pattern(untouched), untouched.to_vec()); |
642 // All escape codes |
642 // All escape codes |
643 assert_eq!( |
643 assert_eq!( |
644 escape_pattern(br#"()[]{}?*+-|^$\\.&~# \t\n\r\v\f"#), |
644 escape_pattern(br#"()[]{}?*+-|^$\\.&~#\t\n\r\v\f"#), |
645 br#"\(\)\[\]\{\}\?\*\+\-\|\^\$\\\\\.\&\~\#\ \\t\\n\\r\\v\\f"# |
645 br#"\(\)\[\]\{\}\?\*\+\-\|\^\$\\\\\.\&\~\#\\t\\n\\r\\v\\f"# |
646 .to_vec() |
646 .to_vec() |
647 ); |
647 ); |
648 } |
648 } |
649 |
649 |
650 #[test] |
650 #[test] |