Alphabetize list output
This commit is contained in:
parent
704fc91ef8
commit
acda290c4b
23
src/manip.rs
23
src/manip.rs
|
@ -103,10 +103,15 @@ impl ModMap {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn export_file(self, block_path: &str, mute_path: &str, heat: (u16, u16)) -> std::io::Result<()> {
|
||||
pub fn export_file(
|
||||
self,
|
||||
block_path: &str,
|
||||
mute_path: &str,
|
||||
heat: (u16, u16),
|
||||
) -> std::io::Result<()> {
|
||||
if self.0.is_empty() {
|
||||
error!("Nothing to export!");
|
||||
return Ok(())
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let (block_thresh, mute_thresh) = heat;
|
||||
|
@ -125,9 +130,19 @@ impl ModMap {
|
|||
}
|
||||
}
|
||||
|
||||
fs::write(block_path, block_output)?;
|
||||
fs::write(mute_path, mute_output)?;
|
||||
fs::write(block_path, alphabetize_lines(block_output))?;
|
||||
fs::write(mute_path, alphabetize_lines(mute_output))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn alphabetize_lines(string: String) -> String {
|
||||
let mut v = string
|
||||
.lines()
|
||||
.map(|literal| literal.to_string())
|
||||
.collect::<Vec<String>>();
|
||||
v.sort_by_key(|a| a.to_lowercase());
|
||||
|
||||
v.join("\n") + "\n"
|
||||
}
|
||||
|
|
|
@ -196,5 +196,5 @@ fn modmap_export_txt() {
|
|||
let mutes: String = fs::read_to_string("test_mutes.txt").unwrap();
|
||||
|
||||
assert_eq!(blocks, "example.com\n");
|
||||
assert!(mutes == "example.org\nexample.net\n" || mutes == "example.net\nexample.org\n");
|
||||
assert_eq!(mutes, "example.net\nexample.org\n");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue