mirror of
https://framagit.org/veretcle/oolatoocs.git
synced 2025-07-20 20:41:17 +02:00
fix: properly count URL when preceeded by '\n'
This commit is contained in:
21
src/utils.rs
21
src/utils.rs
@@ -37,10 +37,15 @@ fn twitter_count(content: &str) -> usize {
|
|||||||
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 {
|
||||||
if word.starts_with("http://") || word.starts_with("https://") {
|
let cr_words = word.split('\n');
|
||||||
count += 23;
|
count += cr_words.clone().count() - 1; // count the chariot returns
|
||||||
} else {
|
|
||||||
count += word.chars().count();
|
for w in cr_words {
|
||||||
|
if w.starts_with("http://") || w.starts_with("https://") {
|
||||||
|
count += 23;
|
||||||
|
} else {
|
||||||
|
count += w.chars().count();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,6 +110,14 @@ mod tests {
|
|||||||
let content = "this is the link https://www.google.com/tamerelol/youpi/tonperemdr/tarace.html if you like! What if I shit a final";
|
let content = "this is the link https://www.google.com/tamerelol/youpi/tonperemdr/tarace.html if you like! What if I shit a final";
|
||||||
|
|
||||||
assert_eq!(twitter_count(content), 76);
|
assert_eq!(twitter_count(content), 76);
|
||||||
|
|
||||||
|
let content = "multi ple space";
|
||||||
|
|
||||||
|
assert_eq!(twitter_count(content), content.chars().count());
|
||||||
|
|
||||||
|
let content = "This link is LEEEEET\n\nhttps://www.factornews.com/actualites/ca-sent-le-sapin-pour-free-radical-design-49985.html";
|
||||||
|
|
||||||
|
assert_eq!(twitter_count(content), 45);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Reference in New Issue
Block a user