pub struct URI {
pub strict: bool,
/* private fields */
}Expand description
A finder that extracts URIs from text according to RFC 3986.
By default, any scheme is matched, subject to the lax-mode heuristics
below. Use URI::add_scheme to filter by specific schemes.
§Strict Mode
By default, the finder excludes ' characters, unbalanced trailing )
characters (so markdown links [text](url) work while
…/Sport_(disambiguation) stays intact), and trailing sentence
punctuation (.,;:!?) from URIs. It also skips prose and code that
happens to parse as a URI: bare scheme: labels, a::b paths, and opaque
URIs (no // after the colon) whose scheme is neither IANA-registered nor
added with URI::add_scheme. Set URI::strict to true to strictly
follow RFC 3986.
Fields§
§strict: boolWhen true, strictly follows RFC 3986: any scheme matches and
trailing ', ), and punctuation are kept.
When false (default), applies the text-extraction heuristics above.
Implementations§
Source§impl URI
impl URI
Sourcepub fn add_scheme(&mut self, s: &str)
pub fn add_scheme(&mut self, s: &str)
Adds a scheme to the filter list.
When at least one scheme is added, only URIs with matching schemes will be found. Scheme matching is case-insensitive.
§Example
use squeeze::{uri::URI, Finder};
let mut finder = URI::default();
finder.add_scheme("https");
finder.add_scheme("mailto");
// Will match https:// and mailto: URIs, but not http:// or ftp://Trait Implementations§
Source§impl Finder for URI
impl Finder for URI
Source§fn triggerable(&self) -> bool
fn triggerable(&self) -> bool
Source§fn line_agnostic(&self) -> bool
fn line_agnostic(&self) -> bool
try_at/try_trigger_at give the same answer on a whole
buffer as on the line alone: \n and \r never belong to a match,
and every walk treats them exactly like the end of the input (as a
boundary), so a match never depends on what surrounds its line. A
finder that matches “up to the end of the line” (codetag), accepts
line terminators as whitespace (JSON, phone) or otherwise looks at
the line as a whole must keep the default. Line-agnostic finders are
run over whole buffers with absolute positions, which lets the
scanner skip resolving the line of every candidate; property tests
compare both modes. Defaults to false.Source§fn could_trigger_at(&self, byte: u8) -> bool
fn could_trigger_at(&self, byte: u8) -> bool
triggerable returns true.Source§fn could_start_after(&self, prev: u8, _cur: u8) -> bool
fn could_start_after(&self, prev: u8, _cur: u8) -> bool
cur when the byte
immediately before it is prev: a dispatch-mode start, or a
trigger-mode trigger byte. Read moreSource§fn could_continue_with(&self, _cur: u8, next: u8) -> bool
fn could_continue_with(&self, _cur: u8, next: u8) -> bool
cur could succeed when the byte
immediately after it is next. Same contract as
could_start_after.Source§fn has_trigger_context(&self) -> bool
fn has_trigger_context(&self) -> bool
trigger_context over the
65536 pairs of previous bytes and
trigger_context_exempt over the
next bytes, once, and consults them before calling the finder.
Defaults to false.Source§fn trigger_context(&self, prev2: u8, prev1: u8) -> bool
fn trigger_context(&self, prev2: u8, prev1: u8) -> bool
prev2 and
prev1, unless the byte after the trigger is exempt
(trigger_context_exempt): a
necessary condition for try_trigger_at
to match at that position. The scanner passes a space for a missing
previous byte (the trigger sits in the first two bytes of the
input). Defaults to true.Source§fn trigger_context_exempt(&self, next: Option<u8>) -> bool
fn trigger_context_exempt(&self, next: Option<u8>) -> bool
next (None at the end of the
input) escapes the previous-bytes condition: the URI finder needs a
registered scheme before a colon unless // follows. Defaults to
false.Source§fn try_trigger_at(&self, input: &[u8], pos: usize) -> Option<Range<usize>>
fn try_trigger_at(&self, input: &[u8], pos: usize) -> Option<Range<usize>>
pos in the full input.
Only called when triggerable returns true.Source§fn find(&self, s: &str) -> Option<Range<usize>>
fn find(&self, s: &str) -> Option<Range<usize>>
Source§fn dispatchable(&self) -> bool
fn dispatchable(&self) -> bool
try_at.Source§fn could_start_at(&self, _byte: u8) -> bool
fn could_start_at(&self, _byte: u8) -> bool
dispatchable returns true.Source§fn try_at(&self, _input: &[u8], _pos: usize) -> Option<Range<usize>>
fn try_at(&self, _input: &[u8], _pos: usize) -> Option<Range<usize>>
pos in the full input.
Only called when dispatchable returns true.Source§fn try_trigger_at_memo(
&self,
input: &[u8],
pos: usize,
memo: &mut Memo,
) -> Option<Range<usize>>
fn try_trigger_at_memo( &self, input: &[u8], pos: usize, memo: &mut Memo, ) -> Option<Range<usize>>
Source§fn anchor(&self) -> Option<Anchor>
fn anchor(&self) -> Option<Anchor>
bytes), and the
bytes that can separate a match start from the first of them
(walk). When every finder of a scanner declares an anchor (or is a
trigger finder) and the anchor bytes number three or fewer, the
scanner searches for those bytes with memchr, walks back over
walk and tries the dispatch positions in order, so lines without
an anchor byte cost nothing. Read moreSource§fn run_rules(&self) -> Vec<RunRule>
fn run_rules(&self) -> Vec<RunRule>
RunRule::allow before try_at
is called. Same contract as
could_start_after: when the rules
reject a position, try_at must return None there. The scanner
measures the runs once per position for all finders.