Struct LookMatcher
struct LookMatcher { ... }
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 ;
let mut lookm = new;
lookm.set_line_terminator;
let re = builder
.thompson
.build?;
let mut cache = re.create_cache;
// Multi-line assertions now use NUL as a terminator.
assert_eq!;
// ... and \n is no longer recognized as a terminator.
assert_eq!;
# Ok::
Implementations
impl LookMatcher
fn new() -> LookMatcherCreates a new default matcher for look-around assertions.
fn set_line_terminator(self: &mut Self, byte: u8) -> &mut LookMatcherSets the line terminator for use with
(?m:^)and(?m:$).Namely, instead of
^matching after\nand$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\rand\n.fn get_line_terminator(self: &Self) -> u8Returns 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:$).fn matches(self: &Self, look: Look, haystack: &[u8], at: usize) -> boolReturns true when the position
atinhaystacksatisfies 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-boundaryfeature 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 thatat == haystack.len()is legal and guaranteed not to panic.fn matches_set(self: &Self, set: LookSet, haystack: &[u8], at: usize) -> boolReturns 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-boundaryfeature 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 thatat == haystack.len()is legal and guaranteed not to panic.fn is_start(self: &Self, _haystack: &[u8], at: usize) -> boolReturns true when
Look::Startis satisfiedatthe given position inhaystack.Panics
This may panic when
at > haystack.len(). Note thatat == haystack.len()is legal and guaranteed not to panic.fn is_end(self: &Self, haystack: &[u8], at: usize) -> boolReturns true when
Look::Endis satisfiedatthe given position inhaystack.Panics
This may panic when
at > haystack.len(). Note thatat == haystack.len()is legal and guaranteed not to panic.fn is_start_lf(self: &Self, haystack: &[u8], at: usize) -> boolReturns true when
Look::StartLFis satisfiedatthe given position inhaystack.Panics
This may panic when
at > haystack.len(). Note thatat == haystack.len()is legal and guaranteed not to panic.fn is_end_lf(self: &Self, haystack: &[u8], at: usize) -> boolReturns true when
Look::EndLFis satisfiedatthe given position inhaystack.Panics
This may panic when
at > haystack.len(). Note thatat == haystack.len()is legal and guaranteed not to panic.fn is_start_crlf(self: &Self, haystack: &[u8], at: usize) -> boolReturns true when
Look::StartCRLFis satisfiedatthe given position inhaystack.Panics
This may panic when
at > haystack.len(). Note thatat == haystack.len()is legal and guaranteed not to panic.fn is_end_crlf(self: &Self, haystack: &[u8], at: usize) -> boolReturns true when
Look::EndCRLFis satisfiedatthe given position inhaystack.Panics
This may panic when
at > haystack.len(). Note thatat == haystack.len()is legal and guaranteed not to panic.fn is_word_ascii(self: &Self, haystack: &[u8], at: usize) -> boolReturns true when
Look::WordAsciiis satisfiedatthe given position inhaystack.Panics
This may panic when
at > haystack.len(). Note thatat == haystack.len()is legal and guaranteed not to panic.fn is_word_ascii_negate(self: &Self, haystack: &[u8], at: usize) -> boolReturns true when
Look::WordAsciiNegateis satisfiedatthe given position inhaystack.Panics
This may panic when
at > haystack.len(). Note thatat == haystack.len()is legal and guaranteed not to panic.fn is_word_unicode(self: &Self, haystack: &[u8], at: usize) -> Result<bool, UnicodeWordBoundaryError>Returns true when
Look::WordUnicodeis satisfiedatthe given position inhaystack.Panics
This may panic when
at > haystack.len(). Note thatat == 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-boundaryfeature is not enabled.fn is_word_unicode_negate(self: &Self, haystack: &[u8], at: usize) -> Result<bool, UnicodeWordBoundaryError>Returns true when
Look::WordUnicodeNegateis satisfiedatthe given position inhaystack.Panics
This may panic when
at > haystack.len(). Note thatat == 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-boundaryfeature is not enabled.fn is_word_start_ascii(self: &Self, haystack: &[u8], at: usize) -> boolReturns true when
Look::WordStartAsciiis satisfiedatthe given position inhaystack.Panics
This may panic when
at > haystack.len(). Note thatat == haystack.len()is legal and guaranteed not to panic.fn is_word_end_ascii(self: &Self, haystack: &[u8], at: usize) -> boolReturns true when
Look::WordEndAsciiis satisfiedatthe given position inhaystack.Panics
This may panic when
at > haystack.len(). Note thatat == haystack.len()is legal and guaranteed not to panic.fn is_word_start_unicode(self: &Self, haystack: &[u8], at: usize) -> Result<bool, UnicodeWordBoundaryError>Returns true when
Look::WordStartUnicodeis satisfiedatthe given position inhaystack.Panics
This may panic when
at > haystack.len(). Note thatat == 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-boundaryfeature is not enabled.fn is_word_end_unicode(self: &Self, haystack: &[u8], at: usize) -> Result<bool, UnicodeWordBoundaryError>Returns true when
Look::WordEndUnicodeis satisfiedatthe given position inhaystack.Panics
This may panic when
at > haystack.len(). Note thatat == 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-boundaryfeature is not enabled.fn is_word_start_half_ascii(self: &Self, haystack: &[u8], at: usize) -> boolReturns true when
Look::WordStartHalfAsciiis satisfiedatthe given position inhaystack.Panics
This may panic when
at > haystack.len(). Note thatat == haystack.len()is legal and guaranteed not to panic.fn is_word_end_half_ascii(self: &Self, haystack: &[u8], at: usize) -> boolReturns true when
Look::WordEndHalfAsciiis satisfiedatthe given position inhaystack.Panics
This may panic when
at > haystack.len(). Note thatat == haystack.len()is legal and guaranteed not to panic.fn is_word_start_half_unicode(self: &Self, haystack: &[u8], at: usize) -> Result<bool, UnicodeWordBoundaryError>Returns true when
Look::WordStartHalfUnicodeis satisfiedatthe given position inhaystack.Panics
This may panic when
at > haystack.len(). Note thatat == 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-boundaryfeature is not enabled.fn is_word_end_half_unicode(self: &Self, haystack: &[u8], at: usize) -> Result<bool, UnicodeWordBoundaryError>Returns true when
Look::WordEndHalfUnicodeis satisfiedatthe given position inhaystack.Panics
This may panic when
at > haystack.len(). Note thatat == 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-boundaryfeature is not enabled.
impl Clone for LookMatcher
fn clone(self: &Self) -> LookMatcher
impl Debug for LookMatcher
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Default for LookMatcher
fn default() -> LookMatcher
impl Freeze for LookMatcher
impl RefUnwindSafe for LookMatcher
impl Send for LookMatcher
impl Sync for LookMatcher
impl Unpin for LookMatcher
impl UnsafeUnpin for LookMatcher
impl UnwindSafe for LookMatcher
impl<T> Any for LookMatcher
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for LookMatcher
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for LookMatcher
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for LookMatcher
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for LookMatcher
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for LookMatcher
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for LookMatcher
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for LookMatcher
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for LookMatcher
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>