diff --git a/src/dir_entry.rs b/src/dir_entry.rs index 6ae0e14..d27852a 100644 --- a/src/dir_entry.rs +++ b/src/dir_entry.rs @@ -105,6 +105,21 @@ impl DirFileEntryData { &self.name } + pub(crate) fn lowercase_name(&self) -> String { + let mut name_copy: [u8; 11] = self.name; + if self.lowercase_basename() { + for c in &mut name_copy[..8] { + *c = (*c as char).to_ascii_lowercase() as u8; + } + } + if self.lowercase_ext() { + for c in &mut name_copy[8..] { + *c = (*c as char).to_ascii_lowercase() as u8; + } + } + ShortName::new(&name_copy).to_str().to_string() + } + pub(crate) fn first_cluster(&self, fat_type: FatType) -> Option { let first_cluster_hi = if fat_type == FatType::Fat32 { self.first_cluster_hi } else { 0 }; let n = ((first_cluster_hi as u32) << 16) | self.first_cluster_lo as u32; @@ -139,6 +154,14 @@ impl DirFileEntryData { !self.is_dir() } + pub(crate) fn lowercase_basename(&self) -> bool { + self.reserved_0 & (1 << 3) != 0 + } + + pub(crate) fn lowercase_ext(&self) -> bool { + self.reserved_0 & (1 << 4) != 0 + } + fn created(&self) -> DateTime { DateTime::from_u16(self.create_date, self.create_time_1) } @@ -605,7 +628,7 @@ impl <'a, 'b> DirEntry<'a, 'b> { if self.lfn.len() > 0 { String::from_utf16_lossy(&self.lfn) } else { - self.short_file_name() + self.data.lowercase_name() } } #[cfg(not(feature = "alloc"))]