Function egg_mode_text::mention_list_entities [] [src]

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

Parses the given string for user and list mentions.

As the parsing rules for user mentions and list mentions, this function is able to extract both kinds at once. To differentiate between the two, check the entity's kind field.

The entities returned by this function can be used to find mentions 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

use egg_mode_text::{EntityKind, mention_list_entities};

 let text = "sample text with a mention for @twitter and a link to @rustlang/fakelist";
 let mut results = mention_list_entities(text).into_iter();

 let entity = results.next().unwrap();
 assert_eq!(entity.kind, EntityKind::ScreenName);
 assert_eq!(entity.substr(text), "@twitter");

 let entity = results.next().unwrap();
 assert_eq!(entity.kind, EntityKind::ListName);
 assert_eq!(entity.substr(text), "@rustlang/fakelist");

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