comparison rust/hg-core/src/utils/files.rs @ 42840:b1b984f9c01d

rust-utils: add normalize_case util to mirror Python one While we still don't handle filenames properly cross-platform, this at least sticks closer to the Python behavior. Differential Revision: https://phab.mercurial-scm.org/D6756
author Raphaël Gomès <rgomes@octobus.net>
date Thu, 22 Aug 2019 14:31:07 +0200
parents 4b3b27d567d5
children 7a01778bc7b7
comparison
equal deleted inserted replaced
42839:ee0f511b7a22 42840:b1b984f9c01d
69 dirs.next(); // skip itself 69 dirs.next(); // skip itself
70 } 70 }
71 dirs 71 dirs
72 } 72 }
73 73
74 /// TODO improve handling of utf8 file names. Our overall strategy for
75 /// filenames has to be revisited anyway, since Windows is UTF-16.
76 pub fn normalize_case(bytes: &[u8]) -> Vec<u8> {
77 #[cfg(windows)] // NTFS compares via upper()
78 return bytes.to_ascii_uppercase();
79 #[cfg(unix)]
80 bytes.to_ascii_lowercase()
81 }
82
74 #[cfg(test)] 83 #[cfg(test)]
75 mod tests { 84 mod tests {
76 #[test] 85 #[test]
77 fn find_dirs_some() { 86 fn find_dirs_some() {
78 let mut dirs = super::find_dirs(b"foo/bar/baz"); 87 let mut dirs = super::find_dirs(b"foo/bar/baz");