Warning, /sdk/rust-qt-binding-generator/src/util.rs is written in an unsupported language. File is not indexed.

0001 use regex::Regex;
0002 use std::fs;
0003 use std::io::Result;
0004 use std::path::Path;
0005 
0006 pub fn write_if_different<P: AsRef<Path>>(path: P, contents: &[u8]) -> Result<()> {
0007     let old_contents = fs::read(&path).ok();
0008     if old_contents.map(|c| c == contents).unwrap_or(false) {
0009         Ok(())
0010     } else {
0011         let _ = fs::create_dir_all(path.as_ref().parent().unwrap());
0012         fs::write(path, contents)
0013     }
0014 }
0015 
0016 pub fn snake_case(name: &str) -> String {
0017     let re = Regex::new("([A-Z])").unwrap();
0018     (name[..1].to_string() + &re.replace_all(&name[1..], "_$1")).to_lowercase()
0019 }