mirror of
https://framagit.org/veretcle/oolatoocs.git
synced 2025-07-20 12:31:18 +02:00
feat: better split for twitter_count
This commit is contained in:
15
src/utils.rs
15
src/utils.rs
@@ -33,19 +33,14 @@ pub fn generate_multi_tweets(content: &str) -> Option<(String, String)> {
|
|||||||
fn twitter_count(content: &str) -> usize {
|
fn twitter_count(content: &str) -> usize {
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
|
|
||||||
let split_content = content.split(' ');
|
let split_content = content.split(&[' ', '\n']);
|
||||||
count += split_content.clone().count() - 1; // count the spaces
|
count += split_content.clone().count() - 1; // count the spaces
|
||||||
|
|
||||||
for word in split_content {
|
for word in split_content {
|
||||||
let cr_words = word.split('\n');
|
if word.starts_with("http://") || word.starts_with("https://") {
|
||||||
count += cr_words.clone().count() - 1; // count the chariot returns
|
count += 23;
|
||||||
|
} else {
|
||||||
for w in cr_words {
|
count += word.chars().count();
|
||||||
if w.starts_with("http://") || w.starts_with("https://") {
|
|
||||||
count += 23;
|
|
||||||
} else {
|
|
||||||
count += w.chars().count();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user