pub struct TreCompiledPattern { /* private fields */ }Expand description
Owning handle to a TRE-compiled pattern.
Construct via TreCompiledPattern::compile. The native
resources are released by Drop (delegated to the
tre-sys::OwnedRegex field).
Implementations§
Source§impl TreCompiledPattern
impl TreCompiledPattern
Sourcepub fn compile(pattern: &[u8], opts: TreMatchOpts) -> Result<Self, TreError>
pub fn compile(pattern: &[u8], opts: TreMatchOpts) -> Result<Self, TreError>
Compile a regex pattern.
The pattern is read as bytes. The vendored TRE build disables multibyte handling, so byte n in the pattern is matched against byte n in the haystack regardless of the host locale.
Sourcepub fn is_match(&self, text: &[u8]) -> bool
pub fn is_match(&self, text: &[u8]) -> bool
Return true if text contains an approximate match
for the pattern within the configured error budget.
Sourcepub fn matches(&self, text: &[u8]) -> Option<TreMatch>
pub fn matches(&self, text: &[u8]) -> Option<TreMatch>
Return the first approximate match in text, if any.
On a non-REG_OK/REG_NOMATCH return code from TRE
the function returns None and asserts in debug builds.
In release the failure is treated as a no-match because
the only documented non-fatal failure for the
approximate matcher is back-references in the pattern,
which dyntext does not generate.
Sourcepub fn opts(&self) -> TreMatchOpts
pub fn opts(&self) -> TreMatchOpts
Borrow the cached options. Useful for tests and for callers that want to re-use the same configuration.