use case::CaseExt;
use regex::Regex;
pub trait NamesChanger {
type Owned;
fn camel_to_snack(&self) -> Self::Owned;
}
impl NamesChanger for str {
type Owned = String;
fn camel_to_snack(&self) -> String {
let re =
Regex::new(r"([a-z]?[a-z]*[A-Z]+[a-z]+([A-Z]?[a-z]*[\w]){0,10})")
.unwrap();
let mut result = Vec::new();
for line in self.lines() {
let mut f = false;
let mut w = String::new();
let mut l = String::new();
for word in line.split(' ') {
if f {
l.push(' ');
}
if re.is_match(word) {
w = word.parse().unwrap();
w = w.to_snake();
} else {
w = word.to_string();
}
l.push_str(&w);
f = true;
}
result.push(l);
}
let result:String = result.join("\n");
result
}
}