pub struct Pattern { /* private fields */ }Expand description
A compiled XSD §F pattern.
Compilation parses the source and either lowers it to a
forward-only linear matcher (the common [class]{quant}… shape)
or compiles it to an NFA driven by a Pike VM. Matching is
linear in the input length in both cases; the linear path skips
per-codepoint NFA dispatch for the patterns that fit it.
Implementations§
Source§impl Pattern
impl Pattern
Sourcepub fn compile(src: &str) -> Result<Self, String>
pub fn compile(src: &str) -> Result<Self, String>
Compile an XSD §F pattern. Returns Err on syntax errors,
disallowed constructs (back-references, lookaround, inline
modifiers), or quantifier counts that would exceed the
counted-repetition cap.
Sourcepub fn compile_with(src: &str, dialect: Dialect) -> Result<Self, String>
pub fn compile_with(src: &str, dialect: Dialect) -> Result<Self, String>
Compile under a specific source dialect. XPath 2.0 mode
recognises ^ / $ as position anchors; XSD mode treats
them as literal characters. See Dialect.
XSD-mode patterns can take the linear fast path when their shape fits it. XPath-mode patterns always route through the NFA — find semantics needs the VM’s per-position re-seeding, which the linear matcher doesn’t support.
Sourcepub fn is_match(&self, s: &str) -> bool
pub fn is_match(&self, s: &str) -> bool
Returns true iff s matches the pattern in its entirety.
XSD §F patterns are implicitly anchored to both ends of the
lexical value.
Sourcepub fn find_match(&self, s: &str) -> bool
pub fn find_match(&self, s: &str) -> bool
Find-style match: true iff any substring of s matches the
pattern. This is the semantics XPath 2.0 fn:matches uses
— matches("foo bar", "bar") is true. Pair with the
Dialect::Xpath compiler so ^ / $ can be used to
re-anchor when the caller wants whole-input semantics.
Only valid on patterns compiled with Dialect::Xpath —
XSD-mode patterns may take the linear whole-string fast
path and have no NFA to run find against.
Sourcepub fn find_iter(&self, input: &str) -> Vec<(usize, usize)>
pub fn find_iter(&self, input: &str) -> Vec<(usize, usize)>
Iterate the non-overlapping matches of the pattern over
input, in left-to-right order, returning (start_byte, end_byte) for each. Leftmost-first match: at each position
the simulator takes the highest-priority path the NFA admits
(XPath / Perl semantics — a|ana prefers a), then resumes
searching immediately after the match’s end. Zero-length
matches advance one character past the match position so the
loop terminates on patterns like a*.
Used by xsl:analyze-string to partition its input into
matching / non-matching segments. Only valid on patterns
compiled with Dialect::Xpath — XSD-mode patterns may
take the linear whole-string fast path that has no NFA.