Function egg_mode_text::url_entities [] [src]

pub fn url_entities(text: &str) -> Vec<Entity>

Parses the given string for URLs.

The entities returned from this function can be used to determine whether a url will be automatically shortened with a t.co link (in fact, this function is called from character_count), or to automatically add hyperlinks to URLs in a text if it hasn't been sent to Twitter yet.

Example

use egg_mode_text::url_entities;

 let text = "sample text with a link to twitter.com and one to rust-lang.org as well";
 let mut results = url_entities(text).into_iter();

 let entity = results.next().unwrap();
 assert_eq!(entity.substr(text), "twitter.com");

 let entity = results.next().unwrap();
 assert_eq!(entity.substr(text), "rust-lang.org");

 assert_eq!(results.next(), None);