Skip to main content

Pattern

Struct Pattern 

Source
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

Source

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.

Source

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.

Examples found in repository?
examples/probe_re.rs (line 3)
2fn check(p: &str) {
3    match Pattern::compile_with(p, Dialect::Xpath) {
4        Ok(_)  => println!("  OK    {p:?}"),
5        Err(e) => println!("  ERR   {p:?} → {e}"),
6    }
7}
Source

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.

Source

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.

Source

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.

Source

pub fn src(&self) -> &str

Original XSD-flavour source, preserved for diagnostics.

Trait Implementations§

Source§

impl Clone for Pattern

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Pattern

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.