fix: count 26 chars per url each time

This commit is contained in:
VC
2025-06-12 14:37:02 +02:00
parent 5606d00da2
commit 3ea2478512
3 changed files with 12 additions and 6 deletions

View File

@@ -38,7 +38,13 @@ fn twitter_count(content: &str) -> usize {
for word in split_content {
if word.starts_with("http://") || word.starts_with("https://") {
count += 23;
// Its not that simple. Bsky adapts itself to the URL.
// https://github.com -> 10 chars
// https://github.com/ -> 10 chars
// https://github.com/NVNTLabs -> 19 chars
// https://github.com/NVNTLabs/ -> 20 chars
// so taking the maximum here to simplify things
count += 26;
} else {
count += word.chars().count();
}
@@ -100,11 +106,11 @@ mod tests {
let content = "Shoot out to https://y.ml/ !";
assert_eq!(twitter_count(content), 38);
assert_eq!(twitter_count(content), 41);
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), 79);
let content = "multi ple space";
@@ -112,7 +118,7 @@ mod tests {
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);
assert_eq!(twitter_count(content), 48);
}
#[test]