remove unnecessary empty check

This commit is contained in:
Michael Hall 2021-08-17 12:24:28 +10:00
parent 1e759bef91
commit 51cf318dbc
2 changed files with 5 additions and 3 deletions

View file

@ -2217,9 +2217,7 @@ impl Path {
///
#[unstable(feature = "path_file_prefix", issue = "86319")]
pub fn file_prefix(&self) -> Option<&OsStr> {
self.file_name()
.map(split_file_at_dot)
.and_then(|(before, after)| if before.is_empty() { after } else { Some(before) })
self.file_name().map(split_file_at_dot).and_then(|(before, _after)| Some(before))
}
/// Extracts the extension of [`self.file_name`], if possible.

View file

@ -1127,6 +1127,8 @@ pub fn test_stem_ext() {
t!(".x.y.z", file_stem: Some(".x.y"), extension: Some("z"));
t!("..x.y.z", file_stem: Some("..x.y"), extension: Some("z"));
t!("", file_stem: None, extension: None);
}
@ -1168,6 +1170,8 @@ pub fn test_prefix_ext() {
t!(".x.y.z", file_prefix: Some(".x"), extension: Some("z"));
t!("..x.y.z", file_prefix: Some("."), extension: Some("z"));
t!("", file_prefix: None, extension: None);
}