Added small a utility that eats extra whitespace.
This commit is contained in:
parent
1266c6e971
commit
48e61c6377
@ -105,6 +105,15 @@ pub fn url_cleaner(s: &str) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Placeholder
|
||||||
|
// TODO: Docs
|
||||||
|
pub fn replace_extra_spaces(s: &str) -> String {
|
||||||
|
s.lines()
|
||||||
|
.map(|x| x.split_whitespace().collect::<Vec<_>>().join(" "))
|
||||||
|
.filter(|x| !x.is_empty())
|
||||||
|
.collect::<Vec<_>>().join("\n")
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
extern crate tempdir;
|
extern crate tempdir;
|
||||||
@ -241,4 +250,22 @@ mod tests {
|
|||||||
assert_eq!(url_cleaner(good_url), good_url);
|
assert_eq!(url_cleaner(good_url), good_url);
|
||||||
assert_eq!(url_cleaner(&format!(" {}\t\n", bad_url)), good_url);
|
assert_eq!(url_cleaner(&format!(" {}\t\n", bad_url)), good_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_whitespace() {
|
||||||
|
let bad_txt = "1 2 3 4 5";
|
||||||
|
let valid_txt = "1 2 3 4 5";
|
||||||
|
|
||||||
|
assert_eq!(replace_extra_spaces(&bad_txt), valid_txt);
|
||||||
|
|
||||||
|
let bad_txt = "1 2 3 \n 4 5\n";
|
||||||
|
let valid_txt = "1 2 3\n4 5";
|
||||||
|
|
||||||
|
assert_eq!(replace_extra_spaces(&bad_txt), valid_txt);
|
||||||
|
|
||||||
|
let bad_txt = "1 2 3 \n\n\n \n 4 5\n";
|
||||||
|
let valid_txt = "1 2 3\n4 5";
|
||||||
|
|
||||||
|
assert_eq!(replace_extra_spaces(&bad_txt), valid_txt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@ use hammond_data::{Episode, Podcast};
|
|||||||
use hammond_downloader::downloader;
|
use hammond_downloader::downloader;
|
||||||
use hammond_data::utils::*;
|
use hammond_data::utils::*;
|
||||||
use hammond_data::errors::*;
|
use hammond_data::errors::*;
|
||||||
|
use hammond_data::utils::replace_extra_spaces;
|
||||||
|
|
||||||
// use utils::html_to_markup;
|
// use utils::html_to_markup;
|
||||||
|
|
||||||
@ -90,10 +91,10 @@ impl EpisodeWidget {
|
|||||||
// html_to_markup(&mut text);
|
// html_to_markup(&mut text);
|
||||||
// description.set_markup(&text)
|
// description.set_markup(&text)
|
||||||
|
|
||||||
let plain_text = strip_html_tags(&text).join("");
|
let plain_text = strip_html_tags(&text).join(" ");
|
||||||
// TODO: handle unwrap
|
// TODO: handle unwrap
|
||||||
let buff = description.get_buffer().unwrap();
|
let buff = description.get_buffer().unwrap();
|
||||||
buff.set_text(plain_text.trim());
|
buff.set_text(&replace_extra_spaces(&plain_text));
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user