1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use inflector::cases::camelcase::*;
use inflector::cases::kebabcase::*;
use inflector::cases::pascalcase::*;
use inflector::cases::screamingsnakecase::*;
use inflector::cases::snakecase::*;
use inflector::cases::traincase::*;
pub enum Query {
Substring(String, String),
Regex(regex::Regex, String),
Subvert(Vec<(String, String)>),
}
impl Query {
pub fn substring(old: &str, new: &str) -> Self {
Self::Substring(old.to_string(), new.to_string())
}
pub fn regex(re: regex::Regex, replacement: &str) -> Self {
Self::Regex(re, replacement.to_string())
}
pub fn subvert(pattern: &str, replacement: &str) -> Self {
fn to_ada_case(input: &str) -> String {
to_train_case(input).replace('-', "_")
}
let mut items = vec![];
for function in &[
to_ada_case,
to_camel_case,
to_kebab_case,
to_pascal_case,
to_screaming_snake_case,
to_snake_case,
to_train_case,
] {
items.push((function(pattern), function(replacement)));
}
Self::Subvert(items)
}
}