diff options
| author | Nathan Jaremko | 2019-03-08 01:22:45 -0500 | 
|---|---|---|
| committer | Nathan Jaremko | 2019-03-08 01:22:45 -0500 | 
| commit | 1f529fde9e67f5b9c5a4984453d844357532910f (patch) | |
| tree | a262eaa17b8eff551ba4c67c9c5c6cded1bab698 /src/utils.rs | |
| parent | cf8d69e765549bd08b4e05313927068b96c7cbe7 (diff) | |
| download | podcast-1f529fde9e67f5b9c5a4984453d844357532910f.tar.bz2 | |
Add podcast search support
Diffstat (limited to 'src/utils.rs')
| -rw-r--r-- | src/utils.rs | 13 | 
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(()) | 
