Expand description
§Squeeze
A library for extracting rich information from any text.
This crate provides finders for extracting structured data from text:
uri::URI- Extract URIs/URLs/URNs as defined by RFC 3986cidr::Cidr- Extract CIDR notation (IPv4/IPv6 network ranges)codetag::Codetag- Extract codetags (TODO, FIXME, etc.) as defined by PEP 350color::Color- Extract colors (hex, rgb, hsl)datetime::Datetime- Extract ISO 8601 datetimesdomain::Domain- Extract DNS-style domain namesemail::Email- Extract email addressesemoji::Emoji- Extract emojis and emoji sequencesenv::Env- Extract environment variable referenceshandle::Handle- Extract social@handlementionshash::Hash- Extract hashes (MD5, SHA-1, SHA-256, SHA-512)ip::Ip- Extract IP addresses (IPv4, IPv6)json::Json- Extract JSON objects and arraysjwt::Jwt- Extract JSON Web Tokensmac::Mac- Extract MAC addressesmodeline::Modeline- Extract vim/vi/ex modelinespath::Path- Extract file paths (absolute, relative, and home-relative)phone::Phone- Extract phone numberssemver::Semver- Extract semantic versionsuuid::Uuid- Extract UUIDsmirror::Mirror- A passthrough finder that returns the entire input
The scanner::Scanner runs any set of finders over a line, or over a
whole buffer of lines with scanner::Scanner::scan_buffer, in one
pass: a prescan disables finders whose bytes are absent, SIMD
classification and per-finder context gates keep finder calls to the
positions where a match can start, and declarative run rules gate
several finders at once from a single measurement of the digit and hex
runs. See docs/performance.md in the repository for the architecture,
the contracts finders follow, and how to measure.
§Example
use squeeze::{uri::URI, Finder};
let finder = URI::default();
let text = "Visit https://example.com for more info";
if let Some(range) = finder.find(text) {
println!("Found: {}", &text[range]);
}Modules§
- cidr
- codetag
- Codetag finder implementation based on PEP 350.
- color
- datetime
- domain
- Domain name finder.
- emoji
- env
- handle
- Social handle finder.
- hash
- ip
- json
- Strict JSON finder.
- jwt
- mac
- mirror
- Mirror finder - a passthrough finder for debugging.
- modeline
- Vim modeline finder.
- path
- phone
- scanner
- semver
- uri
- URI finder implementation based on RFC 3986.
- uuid
Structs§
- Anchor
- Bytes that every match of a dispatch finder contains, and the bytes that
may lie between a match’s start and its first anchor byte, see
Finder::anchor. - Anchor
Check - When the anchor byte at
posis one ofanchors, the byte at one of theoffsetsafterpos(or at every offset, withall) must be one ofbytes(and exist) forposto be the first anchor byte of a match: an IPv4 address’s first.has another two to four bytes on, a UUID’s first-others 5, 10 and 15 bytes on, a MAC address’s first:others 3, 6, 9 and 12 bytes on. - ByteSet
- A set of bytes, used by
RunRule. - Memo
- Per-line, per-finder scratch handed to
Finder::try_at_memo/Finder::try_trigger_at_memo. - Run
- A maximal run of one
RunClassstarting at a candidate position. - RunRule
- A declarative rule on the run starting at a candidate position, see
Finder::run_rules. - Runs
- The digit, hex and word runs at a candidate position, measured once by
the scanner and shared by every finder’s
RunRules. The word run is only measured when a candidate finder has aRunClass::Wordrule. - Then
- A run required right after the byte that ends the previous run of a
RunRule:classbytes numberingmin..=max, followed by a byte inafter(or the end of the input whenafter_endis set).
Enums§
Constants§
- MAX_
CHECKS - Most checks an
Anchorcan carry (one per group of anchor bytes). - MAX_
CHECK_ OFFSETS - Most offsets an
AnchorCheckcan list. - MAX_
THEN - Most follow-up runs a rule can chain, see
RunRule::then. - RUN_CAP
- Longest run length the scanner distinguishes; longer runs are reported
as this value with
Run::cappedset.
Traits§
- Finder
- A trait for finding patterns in text.