Skip to content

Commit

Permalink
Optimise and clean up remove_repeated_chars
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev committed Feb 6, 2024
1 parent 7e8b6f3 commit 5d36ba1
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/funcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,19 +250,12 @@ fn attachments_to_format(attachments: &[serenity::Attachment]) -> Option<&'stati
}

fn remove_repeated_chars(content: &str, limit: usize) -> String {
content
.chars()
.group_by(|&c| c)
.into_iter()
.map(|(key, group)| {
let group: String = group.collect();
if group.chars().count() > limit {
key.to_string().repeat(limit)
} else {
group
}
})
.collect()
let mut out = String::new();
for (_, group) in &content.chars().group_by(|&c| c) {
out.extend(group.take(limit));
}

out
}

pub async fn run_checks(
Expand Down

0 comments on commit 5d36ba1

Please sign in to comment.