https://github.com/chrisduerr/rfind_url
Parser to search strings for URLs in reverse order
https://github.com/chrisduerr/rfind_url
parser reverse rust stream url
Last synced: 10 months ago
JSON representation
Parser to search strings for URLs in reverse order
- Host: GitHub
- URL: https://github.com/chrisduerr/rfind_url
- Owner: chrisduerr
- License: apache-2.0
- Created: 2019-03-16T23:17:30.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-10-07T18:34:14.000Z (over 6 years ago)
- Last Synced: 2025-03-25T07:03:50.245Z (11 months ago)
- Topics: parser, reverse, rust, stream, url
- Language: Rust
- Size: 42 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# Reverse Find URL
[](https://travis-ci.org/chrisduerr/rfind_url)
[](https://crates.io/crates/rfind_url)
This crate provides a parser to search a string for URLs **in reverse order**.
All functionality is handled by the
[`Parser`](https://docs.rs/rfind_url/*/rfind_url/struct.Parser.html) struct which takes
[`chars`](https://doc.rust-lang.org/std/primitive.char.html) as input.
# Examples
Text can be fed into the parser in reverse order:
```rust
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`](https://doc.rust-lang.org/std/option/enum.Option.html#variant.None):
```rust
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));
```