Last active
November 4, 2017 22:17
-
-
Save yupferris/5f67b654762826722d5bc0a8d8f3616d to your computer and use it in GitHub Desktop.
ffs windows, ruining my file watching with your case-insensitivity..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is kindof a crazy way to compare paths, and in certain unicode corner cases will not be entirely correct, | |
// but it's a workaround for file name case insensitivity on Windows and should be good enough for most cases. | |
// The general idea (matching path component suffixes) mimicks Rust's Path::ends_with. | |
fn ends_with_case_insensitive(path: &PathBuf, suffix: &PathBuf) -> bool { | |
let path_comps = path.components().map(|x| String::from(x.as_os_str().to_string_lossy()).to_lowercase()).rev(); | |
let suffix_comps = suffix.components().map(|x| String::from(x.as_os_str().to_string_lossy()).to_lowercase()).rev(); | |
let matching_suffix_pairs = path_comps.zip(suffix_comps).filter(|&(ref x, ref y)| x == y); | |
matching_suffix_pairs.count() == suffix.components().count() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment