pub struct Expression(/* private fields */);
compiler
only.Expand description
Vectorscan regex pattern string.
Vectorscan itself supports a subset of PCRE syntax in the pattern string; see Pattern Support for reference. The use of unsupported constructs will result in compilation errors.
Note that as the underlying vectorscan library interprets pattern strings as
null-terminated CStr
s, null bytes are not supported within
Expression
strings. Use a Literal
or LiteralSet
database if you
need to match against pattern strings containing explicit null bytes.
Instances can be created equivalently with Self::new()
or
str::parse()
via the str::FromStr
impl:
use vectorscan::expression::Expression;
let e1: Expression = "asdf+".parse()?;
let e2 = Expression::new("asdf+")?;
assert_eq!(e1, e2);
Implementations§
Source§impl Expression
impl Expression
Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Reference the underlying bytes, without the trailing null terminator.
let e = vectorscan::expression::Expression::new("asdf")?;
assert_eq!(e.as_bytes(), b"asdf");
Sourcepub fn new(x: impl Into<Vec<u8>>) -> Result<Self, VectorscanCompileError>
pub fn new(x: impl Into<Vec<u8>>) -> Result<Self, VectorscanCompileError>
Produce a NULL
-terminated C-style wrapper for the given pattern string.
This will fail if the string contains any internal NULL
bytes, as those
are not supported by the vectorscan regex compiler:
use vectorscan::{expression::*, error::*};
let pat = "as\0df";
let e = match Expression::new(pat) {
Err(VectorscanCompileError::NullByte(e)) => e,
_ => unreachable!(),
};
assert_eq!(e.nul_position(), 2);
Sourcepub fn info(&self, flags: Flags) -> Result<ExprInfo, VectorscanCompileError>
pub fn info(&self, flags: Flags) -> Result<ExprInfo, VectorscanCompileError>
Utility function providing information about a regular expression. The
information provided in info::ExprInfo
includes the minimum and
maximum width of a pattern match.
Note: successful analysis of an expression with this function does not
imply that compilation of the same expression (via
Database::compile()
or Database::compile_multi()
) would succeed.
This function may return Ok
for regular expressions that
Vectorscan cannot compile.
Note: some per-pattern flags (such as Flags::ALLOWEMPTY
and
Flags::SOM_LEFTMOST
) are accepted by this call, but as they do not
affect the properties returned in the info::ExprInfo
structure,
they will not affect the outcome of this function.
use vectorscan::{expression::{*, info::*}, flags::Flags};
let expr: Expression = "(he)llo".parse()?;
let info = expr.info(Flags::default())?;
assert_eq!(info, ExprInfo {
min_width: ExprWidth(5),
max_width: Some(ExprWidth(5)),
unordered_matches: UnorderedMatchBehavior::OnlyOrdered,
matches_at_eod: MatchAtEndBehavior::WillNeverMatchAtEOD,
});
Sourcepub fn ext_info(
&self,
flags: Flags,
ext_flags: &ExprExt,
) -> Result<ExprInfo, VectorscanCompileError>
pub fn ext_info( &self, flags: Flags, ext_flags: &ExprExt, ) -> Result<ExprInfo, VectorscanCompileError>
Utility function providing information about a regular expression, with
extended parameter support. The information provided in info::ExprInfo
includes the minimum and maximum width of a pattern match.
Note: successful analysis of an expression with this function does not
imply that compilation of the same expression (via
Database::compile()
or Database::compile_multi()
) would succeed.
This function may return Ok
for regular expressions that
Vectorscan cannot compile.
Note: some per-pattern flags (such as Flags::ALLOWEMPTY
and
Flags::SOM_LEFTMOST
) are accepted by this call, but as they do not
affect the properties returned in the info::ExprInfo
structure,
they will not affect the outcome of this function.
use vectorscan::{expression::{*, info::*}, flags::Flags};
let expr: Expression = ".*lo".parse()?;
let ext = ExprExt::from_min_length(4);
let info = expr.ext_info(Flags::default(), &ext)?;
assert_eq!(info, ExprInfo {
min_width: ExprWidth(4),
max_width: None,
unordered_matches: UnorderedMatchBehavior::OnlyOrdered,
matches_at_eod: MatchAtEndBehavior::WillNeverMatchAtEOD,
});
Sourcepub fn compile(
&self,
flags: Flags,
mode: Mode,
) -> Result<Database, VectorscanCompileError>
pub fn compile( &self, flags: Flags, mode: Mode, ) -> Result<Database, VectorscanCompileError>
Call Database::compile()
with None
for the platform.
Trait Implementations§
Source§impl Clone for Expression
impl Clone for Expression
Source§fn clone(&self) -> Expression
fn clone(&self) -> Expression
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for Expression
impl Debug for Expression
Source§impl Display for Expression
impl Display for Expression
Source§impl FromStr for Expression
impl FromStr for Expression
Source§impl Hash for Expression
impl Hash for Expression
Source§impl Ord for Expression
impl Ord for Expression
Source§fn cmp(&self, other: &Expression) -> Ordering
fn cmp(&self, other: &Expression) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for Expression
impl PartialEq for Expression
Source§impl PartialOrd for Expression
impl PartialOrd for Expression
impl Eq for Expression
impl StructuralPartialEq for Expression
Auto Trait Implementations§
impl Freeze for Expression
impl RefUnwindSafe for Expression
impl Send for Expression
impl Sync for Expression
impl Unpin for Expression
impl UnwindSafe for Expression
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.