aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/utils.rs b/src/utils.rs
index bb96909..21b01a7 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -13,7 +13,7 @@ const UNSUBSCRIBE_NOTE: &str = "Note: this does NOT delete any downloaded podcas
pub fn trim_extension(filename: &str) -> Option<String> {
let name = String::from(filename);
- if name.contains(".") {
+ if name.contains('.') {
name.rfind('.').map(|index| String::from(&name[0..index]))
} else {
Some(name)
@@ -21,7 +21,7 @@ pub fn trim_extension(filename: &str) -> Option<String> {
}
pub fn find_extension(input: &str) -> Option<String> {
- let s: Vec<String> = input.split(".").map(|s| s.to_string()).collect();
+ let s: Vec<String> = input.split('.').map(|s| s.to_string()).collect();
if s.len() > 1 {
return s.last().cloned();
}
@@ -39,6 +39,15 @@ pub fn get_podcast_dir() -> Result<PathBuf> {
}
}
+pub fn append_extension(filename: &str, ext: &str) -> String {
+ let mut f = filename.to_string();
+ if !f.ends_with('.') {
+ f.push_str(".");
+ }
+ f.push_str(ext);
+ f
+}
+
pub fn create_dir_if_not_exist(path: &PathBuf) -> Result<()> {
DirBuilder::new().recursive(true).create(&path)?;
Ok(())