Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@ use std::str;
pub fn filter(block_list: &Vec<String>, buf: &[u8]) -> String {
let statsd_str = unsafe { str::from_utf8_unchecked(&buf) };

let result_itr = statsd_str.split("\n").filter(|line| {
for prefix in block_list.iter() {
if line.starts_with(prefix) {
return false;
}
}
return true;
});

let result = result_itr.collect::<Vec<&str>>().join("\n");

return result;
statsd_str.split("\n")
.filter(|line| {
!block_list.iter().any(|prefix| line.starts_with(prefix))
})
.collect::<Vec<&str>>()
.join("\n")
}

#[cfg(test)]
Expand Down