pub struct LookMatcher { /* private fields */ }
Expand description

A matcher for look-around assertions.

This matcher permits configuring aspects of how look-around assertions are matched.

Example

A LookMatcher can change the line terminator used for matching multi-line anchors such as (?m:^) and (?m:$).

use regex_automata::{
    nfa::thompson::{self, pikevm::PikeVM},
    util::look::LookMatcher,
    Match, Input,
};

let mut lookm = LookMatcher::new();
lookm.set_line_terminator(b'\x00');

let re = PikeVM::builder()
    .thompson(thompson::Config::new().look_matcher(lookm))
    .build(r"(?m)^[a-z]+$")?;
let mut cache = re.create_cache();

// Multi-line assertions now use NUL as a terminator.
assert_eq!(
    Some(Match::must(0, 1..4)),
    re.find(&mut cache, b"\x00abc\x00"),
);
// ... and \n is no longer recognized as a terminator.
assert_eq!(
    None,
    re.find(&mut cache, b"\nabc\n"),
);

Implementations§

Creates a new default matcher for look-around assertions.

Sets the line terminator for use with (?m:^) and (?m:$).

Namely, instead of ^ matching after \n and $ matching immediately before a \n, this will cause it to match after and before the byte given.

It can occasionally be useful to use this to configure the line terminator to the NUL byte when searching binary data.

Note that this does not apply to CRLF-aware line anchors such as (?Rm:^) and (?Rm:$). CRLF-aware line anchors are hard-coded to use \r and \n.

Returns the line terminator that was configured for this matcher.

If no line terminator was configured, then this returns \n.

Note that the line terminator should only be used for matching (?m:^) and (?m:$) assertions. It specifically should not be used for matching the CRLF aware assertions (?Rm:^) and (?Rm:$).

Returns true when the position at in haystack satisfies the given look-around assertion.

Panics

This panics when testing any Unicode word boundary assertion in this set and when the Unicode word data is not available. Specifically, this only occurs when the unicode-word-boundary feature is not enabled.

Since it’s generally expected that this routine is called inside of a matching engine, callers should check the error condition when building the matching engine. If there is a Unicode word boundary in the matcher and the data isn’t available, then the matcher should fail to build.

Callers can check the error condition with LookSet::available.

This also may panic when at > haystack.len(). Note that at == haystack.len() is legal and guaranteed not to panic.

Returns true when all of the assertions in the given set match at the given position in the haystack.

Panics

This panics when testing any Unicode word boundary assertion in this set and when the Unicode word data is not available. Specifically, this only occurs when the unicode-word-boundary feature is not enabled.

Since it’s generally expected that this routine is called inside of a matching engine, callers should check the error condition when building the matching engine. If there is a Unicode word boundary in the matcher and the data isn’t available, then the matcher should fail to build.

Callers can check the error condition with LookSet::available.

This also may panic when at > haystack.len(). Note that at == haystack.len() is legal and guaranteed not to panic.

Returns true when Look::Start is satisfied at the given position in haystack.

Panics

This may panic when at > haystack.len(). Note that at == haystack.len() is legal and guaranteed not to panic.

Returns true when Look::End is satisfied at the given position in haystack.

Panics

This may panic when at > haystack.len(). Note that at == haystack.len() is legal and guaranteed not to panic.

Returns true when Look::StartLF is satisfied at the given position in haystack.

Panics

This may panic when at > haystack.len(). Note that at == haystack.len() is legal and guaranteed not to panic.

Returns true when Look::EndLF is satisfied at the given position in haystack.

Panics

This may panic when at > haystack.len(). Note that at == haystack.len() is legal and guaranteed not to panic.

Returns true when Look::StartCRLF is satisfied at the given position in haystack.

Panics

This may panic when at > haystack.len(). Note that at == haystack.len() is legal and guaranteed not to panic.

Returns true when Look::EndCRLF is satisfied at the given position in haystack.

Panics

This may panic when at > haystack.len(). Note that at == haystack.len() is legal and guaranteed not to panic.

Returns true when Look::WordAscii is satisfied at the given position in haystack.

Panics

This may panic when at > haystack.len(). Note that at == haystack.len() is legal and guaranteed not to panic.

Returns true when Look::WordAsciiNegate is satisfied at the given position in haystack.

Panics

This may panic when at > haystack.len(). Note that at == haystack.len() is legal and guaranteed not to panic.

Returns true when Look::WordUnicode is satisfied at the given position in haystack.

Panics

This may panic when at > haystack.len(). Note that at == haystack.len() is legal and guaranteed not to panic.

Errors

This returns an error when Unicode word boundary tables are not available. Specifically, this only occurs when the unicode-word-boundary feature is not enabled.

Returns true when Look::WordUnicodeNegate is satisfied at the given position in haystack.

Panics

This may panic when at > haystack.len(). Note that at == haystack.len() is legal and guaranteed not to panic.

Errors

This returns an error when Unicode word boundary tables are not available. Specifically, this only occurs when the unicode-word-boundary feature is not enabled.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.