Struct hyperscan::expression::ExprExt
source · pub struct ExprExt(/* private fields */);compiler only.Expand description
Configuration for extended hyperscan parameters.
These parameters cover various types of fuzzy search as well as input subsetting features. See Extended Parameters for a further reference.
This structure may be passed in when building a database with
ExpressionSet::with_exts(), or used to interrogate a single expression
with Expression::ext_info().
Like many other flags arguments, this struct also supports ops::BitOr
and the | operator for composition:
use hyperscan::{expression::*, flags::*, matchers::*};
// Apply extended configuration to one version of the pattern, but not the other:
let a: Expression = "ab".parse()?;
let ext = ExprExt::from_min_offset(3) | ExprExt::from_max_offset(15);
let set = ExpressionSet::from_exprs([&a, &a])
.with_exts([Some(&ext), None])
.with_ids([ExprId(1), ExprId(2)])
.compile(Mode::BLOCK)?;
let mut scratch = set.allocate_scratch()?;
let msg: ByteSlice = "ab ab ab".into();
let mut matches: Vec<ExpressionIndex> = Vec::new();
scratch.scan_sync(&set, msg, |m| {
matches.push(m.id);
MatchResult::Continue
})?;
// The configured pattern misses out on the first and last match of "ab":
assert_eq!(&matches, &[
ExpressionIndex(2), ExpressionIndex(1), ExpressionIndex(2), ExpressionIndex(2),
]);Implementations§
source§impl ExprExt
impl ExprExt
sourcepub fn from_min_offset(x: usize) -> Self
pub fn from_min_offset(x: usize) -> Self
The minimum end offset in the data stream at which this expression should match successfully.
sourcepub fn from_max_offset(x: usize) -> Self
pub fn from_max_offset(x: usize) -> Self
The maximum end offset in the data stream at which this expression should match successfully.
sourcepub fn from_min_length(x: usize) -> Self
pub fn from_min_length(x: usize) -> Self
The minimum match length (from start to end) required to successfully match this expression.
This is one alternative to the use of Flags::ALLOWEMPTY.
This does not require Flags::SOM_LEFTMOST:
use hyperscan::{expression::*, flags::*, matchers::*};
let a: Expression = "a.*b".parse()?;
let ext = ExprExt::from_min_length(4);
let set = ExpressionSet::from_exprs([&a])
.with_exts([Some(&ext)])
.compile(Mode::BLOCK)?;
let mut scratch = set.allocate_scratch()?;
let msg: ByteSlice = " ab ab ".into();
let mut matches: Vec<&str> = Vec::new();
scratch.scan_sync(&set, msg, |m| {
matches.push(unsafe { m.source.as_str() });
MatchResult::Continue
})?;
// `SOM_LEFTMOST` is disabled, so we don't know the match start,
// but the min_length property is correctly applied regardless:
assert_eq!(&matches, &[" ab ab"]);sourcepub fn from_edit_distance(x: usize) -> Self
pub fn from_edit_distance(x: usize) -> Self
Allow patterns to approximately match within this edit (Levenshtein) distance.
sourcepub fn from_hamming_distance(x: usize) -> Self
pub fn from_hamming_distance(x: usize) -> Self
Allow patterns to approximately match within this Hamming distance.
sourcepub fn min_offset(&self) -> Option<c_ulonglong>
pub fn min_offset(&self) -> Option<c_ulonglong>
Get the min_offset value that will be provided to hyperscan, or None
if not activated.
sourcepub fn max_offset(&self) -> Option<c_ulonglong>
pub fn max_offset(&self) -> Option<c_ulonglong>
Get the max_offset value that will be provided to hyperscan, or None
if not activated.
sourcepub fn min_length(&self) -> Option<c_ulonglong>
pub fn min_length(&self) -> Option<c_ulonglong>
Get the min_length value that will be provided to hyperscan, or None
if not activated.
sourcepub fn edit_distance(&self) -> Option<c_uint>
pub fn edit_distance(&self) -> Option<c_uint>
Get the edit_distance value that will be provided to hyperscan, or
None if not activated.
sourcepub fn hamming_distance(&self) -> Option<c_uint>
pub fn hamming_distance(&self) -> Option<c_uint>
Get the hamming_distance value that will be provided to hyperscan, or
None if not activated.
Trait Implementations§
source§impl BitOrAssign for ExprExt
impl BitOrAssign for ExprExt
source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|= operation. Read more