rfind_url

Crates.iorfind_url
lib.rsrfind_url
version0.4.4
sourcesrc
created_at2019-03-16 23:21:06.791997
updated_at2019-10-07 18:34:19.01658
descriptionParser to search strings for URLs in reverse order
homepage
repositoryhttps://github.com/chrisduerr/rfind_url.git
max_upload_size
id121460
size33,374
Christian Duerr (chrisduerr)

documentation

https://docs.rs/rfind_url

README

Reverse Find URL

Build Status crates.io

This crate provides a parser to search a string for URLs in reverse order.

All functionality is handled by the Parser struct which takes chars as input.

Examples

Text can be fed into the parser in reverse order:

use rfind_url::{Parser, ParserState};

let mut parser = Parser::new();

for c in "There_is_no_URL_here".chars().rev() {
    assert_eq!(parser.advance(c), ParserState::MaybeUrl);
}

The parser returns the length of the URL as soon as the last character of the URL is pushed into it. Otherwise it will return None:

use rfind_url::{Parser, ParserState};

let mut parser = Parser::new();

// Parser guarantees there's currently no active URL
assert_eq!(parser.advance(' '), ParserState::NoUrl);

// URLs are only returned once they are complete
for c in "ttps://example.org".chars().rev() {
    assert_eq!(parser.advance(c), ParserState::MaybeUrl);
}

// Parser has detected a URL spanning the last 19 characters
assert_eq!(parser.advance('h'), ParserState::Url(19));
Commit count: 28

cargo fmt