Function egg_mode_text::hashtag_entities [] [src]

pub fn hashtag_entities(text: &str, check_url_overlap: bool) -> Vec<Entity>

Parses the given string for hashtags, optionally leaving out those that are part of URLs.

The entities returned by this function can be used to find hashtags for hyperlinking, as well as to provide an autocompletion facility, if the byte-offset position of the cursor is known with relation to the full text.

Example

With the check_url_overlap parameter, you can make sure you don't include text anchors from URLs:

use egg_mode_text::hashtag_entities;

 let text = "some #hashtag with a link to twitter.com/#anchor";
 let mut results = hashtag_entities(text, true).into_iter();

 let tag = results.next().unwrap();
 assert_eq!(tag.substr(text), "#hashtag");

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

If you pass false for that parameter, it won't parse for URLs to check for overlap:

use egg_mode_text::hashtag_entities;

 let text = "some #hashtag with a link to twitter.com/#anchor";
 let mut results = hashtag_entities(text, false).into_iter();

 let tag = results.next().unwrap();
 assert_eq!(tag.substr(text), "#hashtag");

 let tag = results.next().unwrap();
 assert_eq!(tag.substr(text), "#anchor");

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