extern crate twitter_text_config;
extern crate twitter_text_parser;
extern crate unicode_normalization;
extern crate idna;
extern crate pest;
pub mod extractor;
pub mod hit_highlighter;
pub mod autolinker;
pub mod entity;
pub mod validator;
use twitter_text_config::Configuration;
use twitter_text_config::Range;
use extractor::Extract;
use extractor::ValidatingExtractor;
#[derive(PartialEq, Eq, Hash, Debug, Clone, Copy)]
pub struct TwitterTextParseResults {
pub weighted_length: i32,
pub permillage: i32,
pub is_valid: bool,
pub display_text_range: Range,
pub valid_text_range: Range
}
impl TwitterTextParseResults {
pub fn new(weighted_length: i32,
permillage: i32,
is_valid: bool,
display_text_range: Range,
valid_text_range: Range) -> TwitterTextParseResults {
TwitterTextParseResults {
weighted_length,
permillage,
is_valid,
display_text_range,
valid_text_range
}
}
pub fn empty() -> TwitterTextParseResults {
TwitterTextParseResults {
weighted_length: 0,
permillage: 0,
is_valid: false,
display_text_range: Range::empty(),
valid_text_range: Range::empty()
}
}
}
pub fn parse(text: &str, config: &Configuration, extract_urls: bool) -> TwitterTextParseResults {
let mut extractor = ValidatingExtractor::new(config);
let input = extractor.prep_input(text);
if extract_urls {
extractor.extract_urls_with_indices(input.as_str()).parse_results
} else {
extractor.extract_scan(input.as_str()).parse_results
}
}