rust_qt_binding_generator/
util.rs1use regex::Regex;
2use std::fs;
3use std::io::Result;
4use std::path::Path;
5
6pub fn write_if_different<P: AsRef<Path>>(path: P, contents: &[u8]) -> Result<()> {
7 let old_contents = fs::read(&path).ok();
8 if old_contents.map(|c| c == contents).unwrap_or(false) {
9 Ok(())
10 } else {
11 let _ = fs::create_dir_all(path.as_ref().parent().unwrap());
12 fs::write(path, contents)
13 }
14}
15
16pub fn snake_case(name: &str) -> String {
17 let re = Regex::new("([A-Z])").unwrap();
18 (name[..1].to_string() + &re.replace_all(&name[1..], "_$1")).to_lowercase()
19}