feat: better split for twitter_count

This commit is contained in:
VC
2023-11-29 13:32:04 +01:00
parent 692f4ff040
commit fd84730bdc

View File

@@ -33,19 +33,14 @@ pub fn generate_multi_tweets(content: &str) -> Option<(String, String)> {
fn twitter_count(content: &str) -> usize {
let mut count = 0;
let split_content = content.split(' ');
let split_content = content.split(&[' ', '\n']);
count += split_content.clone().count() - 1; // count the spaces
for word in split_content {
let cr_words = word.split('\n');
count += cr_words.clone().count() - 1; // count the chariot returns
for w in cr_words {
if w.starts_with("http://") || w.starts_with("https://") {
if word.starts_with("http://") || word.starts_with("https://") {
count += 23;
} else {
count += w.chars().count();
}
count += word.chars().count();
}
}