remove unnecessary empty check
This commit is contained in:
parent
1e759bef91
commit
51cf318dbc
2 changed files with 5 additions and 3 deletions
|
@ -2217,9 +2217,7 @@ impl Path {
|
||||||
///
|
///
|
||||||
#[unstable(feature = "path_file_prefix", issue = "86319")]
|
#[unstable(feature = "path_file_prefix", issue = "86319")]
|
||||||
pub fn file_prefix(&self) -> Option<&OsStr> {
|
pub fn file_prefix(&self) -> Option<&OsStr> {
|
||||||
self.file_name()
|
self.file_name().map(split_file_at_dot).and_then(|(before, _after)| Some(before))
|
||||||
.map(split_file_at_dot)
|
|
||||||
.and_then(|(before, after)| if before.is_empty() { after } else { Some(before) })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extracts the extension of [`self.file_name`], if possible.
|
/// Extracts the extension of [`self.file_name`], if possible.
|
||||||
|
|
|
@ -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!("..x.y.z", file_stem: Some("..x.y"), extension: Some("z"));
|
||||||
|
|
||||||
t!("", file_stem: None, extension: None);
|
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(".x"), extension: Some("z"));
|
||||||
|
|
||||||
|
t!("..x.y.z", file_prefix: Some("."), extension: Some("z"));
|
||||||
|
|
||||||
t!("", file_prefix: None, extension: None);
|
t!("", file_prefix: None, extension: None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue