Skip to main content

Crate squeeze

Crate squeeze 

Source
Expand description

§Squeeze

A library for extracting rich information from any text.

This crate provides finders for extracting structured data from text:

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.
email
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.
AnchorCheck
When the anchor byte at pos is one of anchors, the byte at one of the offsets after pos (or at every offset, with all) must be one of bytes (and exist) for pos to 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 RunClass starting 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 a RunClass::Word rule.
Then
A run required right after the byte that ends the previous run of a RunRule: class bytes numbering min..=max, followed by a byte in after (or the end of the input when after_end is set).

Enums§

RunClass
The byte class a RunRule measures.

Constants§

MAX_CHECKS
Most checks an Anchor can carry (one per group of anchor bytes).
MAX_CHECK_OFFSETS
Most offsets an AnchorCheck can 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::capped set.

Traits§

Finder
A trait for finding patterns in text.