Function egg_mode_text::character_count [] [src]

pub fn character_count(
    text: &str,
    http_url_len: i32,
    https_url_len: i32
) -> usize

Returns how many characters the given text would be, after accounting for URL shortening.

For the http_url_len and https_url_len parameters, call GET help/configuration in the Twitter API (in the egg-mode crate, this is exposed in egg_mode::service::config) and use the short_url_len and short_url_len_https fields on the struct that's returned. If you want to perform these checks offline, twitter-text's sample code and tests assume 23 characters for both sizes. At the time of this writing (2016-11-28), those numbers were also being returned from the service itself.

Examples

use egg_mode_text::character_count;

 let count = character_count("This is a test.", 23, 23);
 assert_eq!(count, 15);

 // URLs get replaced by a t.co URL of the given length
 let count = character_count("test.com", 23, 23);
 assert_eq!(count, 23);

 // Multiple URLs get shortened individually
 let count =
     character_count("Test https://test.com test https://test.com test.com test", 23, 23);
 assert_eq!(count, 86);