ruplacer/query.rs
1/// A replacement Query
2pub enum Query {
3 /// Substitute `old` with `new`
4 Simple(String, String),
5 /// Replace the parts matching the regex with `replacement`
6 Regex(regex::Regex, String),
7 /// Replace all instances of `pattern` with `replacement`, by
8 /// using case conversion methods.
9 /// This allows replacing FooBar with SpamEggs and foo_bar with spam_eggs
10 /// using only one query
11 PreserveCase(String, String),
12}
13
14impl Query {
15 /// Constructor for the Substring variant
16 pub fn simple(old: &str, new: &str) -> Self {
17 Self::Simple(old.to_string(), new.to_string())
18 }
19
20 /// Constructor for the Regex variant
21 pub fn regex(re: regex::Regex, replacement: &str) -> Self {
22 Self::Regex(re, replacement.to_string())
23 }
24
25 /// Constructor for the PreserveCase variant
26 pub fn preserve_case(pattern: &str, replacement: &str) -> Self {
27 Self::PreserveCase(pattern.to_string(), replacement.to_string())
28 }
29}