File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #[ derive( Debug ) ]
2+ pub struct Pair {
3+ regex : regex:: Regex ,
4+ rep : String ,
5+ }
6+
7+ #[ derive( Debug ) ]
8+ pub enum Opt {
9+ ReplaceLineIfMatch ,
10+ AnotherOption ,
11+ }
12+
13+ pub fn replace_line < P : AsRef < [ Pair ] > , S : AsRef < str > > (
14+ pairs : P ,
15+ opts : Vec < Opt > ,
16+ content : S ,
17+ ) -> Vec < String > {
18+ let pairs = pairs. as_ref ( ) ;
19+ let content = content. as_ref ( ) ;
20+
21+ let mut lines = content. lines ( ) . map ( |x| x. to_owned ( ) ) . collect :: < Vec < _ > > ( ) ;
22+
23+ for opt in opts {
24+ match opt {
25+ Opt :: ReplaceLineIfMatch => replace_line_if_match ( pairs, & mut lines) ,
26+ Opt :: AnotherOption => other ( pairs, & mut lines) ,
27+ }
28+ }
29+ lines
30+ }
31+
32+ fn replace_line_if_match ( pairs : & [ Pair ] , lines : & mut Vec < String > ) {
33+ for line in lines. iter_mut ( ) {
34+ for Pair { regex, rep } in pairs {
35+ if regex. is_match ( & line) {
36+ * line = rep. clone ( ) ;
37+ }
38+ }
39+ }
40+ }
41+
42+ fn other ( pairs : & [ Pair ] , lines : & mut Vec < String > ) {
43+ unimplemented ! ( )
44+ }
File renamed without changes.
You can’t perform that action at this time.
0 commit comments