Regex

Struct Regex 

Source
pub struct Regex { /* private fields */ }
Expand description

A regular expression engine designed for use within the ad text editor.

This is a relatively naive implementation though it does have some optimisations and runs reasonably quickly. It is not at all designed to be robust against malicious input and it does not attempt to support full PCRE syntax or functionality.

Implementations§

Source§

impl Regex

Source

pub fn compile(re: impl AsRef<str>) -> Result<Self, Error>

Attempt to compile the given regular expression into its optimised VM opcode form.

This method handles pre-allocation of the memory required for running the VM so that the allocation cost is paid once up front rather than on each use of the Regex.

Source

pub fn matches<H>(&self, haystack: &H) -> bool
where H: Haystack,

Determine whether or not this Regex matches the Haystack without searching for the leftmost-longest match and associated submatch boundaries.

Source

pub fn matches_from<H>(&self, haystack: &H, offset: usize) -> bool
where H: Haystack,

Determine whether or not this Regex matches the Haystack from the given offset without searching for the leftmost-longest match and associated submatch boundaries.

Source

pub fn matches_between<H>(&self, haystack: &H, from: usize, to: usize) -> bool
where H: Haystack,

Determine whether or not this Regex matches the Haystack between the given offsets without searching for the leftmost-longest match and associated submatch boundaries.

Source

pub fn find<H>(&self, haystack: &H) -> Option<Match>
where H: Haystack,

Search the given Haystack for the leftmost longest match of this Regex and return the match position along with all submatches.

It is recommended that you call Haystack::try_make_contiguous before calling this method in order to speed up searching whenever this is possible.

Source

pub fn find_from<H>(&self, haystack: &H, offset: usize) -> Option<Match>
where H: Haystack,

Search the given Haystack for the leftmost longest match of this Regex starting from the provided byte offset rather than the beginning of the haystack, returning the match position along with all submatches.

It is recommended that you call Haystack::try_make_contiguous before calling this method in order to speed up searching whenever this is possible.

Source

pub fn find_between<H>( &self, haystack: &H, from: usize, to: usize, ) -> Option<Match>
where H: Haystack,

Search the given Haystack for the leftmost longest match of this Regex starting from the provided byte offset rather than the beginning of the haystack, and ending before the provided char_to, returning the match position along with all submatches.

It is recommended that you call Haystack::try_make_contiguous before calling this method in order to speed up searching whenever this is possible.

Source

pub fn find_iter<'a, H>(&'a mut self, haystack: &'a H) -> MatchIter<'a, H>
where H: Haystack,

It is recommended that you call Haystack::try_make_contiguous before calling this method in order to speed up searching whenever this is possible.

Trait Implementations§

Source§

impl Clone for Regex

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Regex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Regex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Haystack<Regex> for Buffer

Source§

fn is_match_between(&self, re: &Regex, from: usize, to: usize) -> bool

Returns true if there is a match for the regex between the given byte offsets in the haystack. Read more
Source§

fn captures_between( &self, re: &Regex, from: usize, to: usize, ) -> Option<RawCaptures>

Searches for the first match of this regex between the given byte offsets in the given haystack, returning the overall match along with the matches of each capture group in the regex. If no match is found, then None is returned. Read more
Source§

impl<R> Haystack<Regex> for CachingStream<R>
where R: Read,

Source§

fn is_match_between(&self, re: &Regex, from: usize, to: usize) -> bool

Returns true if there is a match for the regex between the given byte offsets in the haystack. Read more
Source§

fn captures_between( &self, re: &Regex, from: usize, to: usize, ) -> Option<RawCaptures>

Searches for the first match of this regex between the given byte offsets in the given haystack, returning the overall match along with the matches of each capture group in the regex. If no match is found, then None is returned. Read more
Source§

impl Haystack<Regex> for GapBuffer

Source§

fn is_match_between(&self, re: &Regex, from: usize, to: usize) -> bool

Returns true if there is a match for the regex between the given byte offsets in the haystack. Read more
Source§

fn captures_between( &self, re: &Regex, from: usize, to: usize, ) -> Option<RawCaptures>

Searches for the first match of this regex between the given byte offsets in the given haystack, returning the overall match along with the matches of each capture group in the regex. If no match is found, then None is returned. Read more
Source§

impl Haystack<Regex> for str

Source§

fn is_match_between(&self, re: &Regex, from: usize, to: usize) -> bool

Returns true if there is a match for the regex between the given byte offsets in the haystack. Read more
Source§

fn captures_between( &self, re: &Regex, from: usize, to: usize, ) -> Option<RawCaptures>

Searches for the first match of this regex between the given byte offsets in the given haystack, returning the overall match along with the matches of each capture group in the regex. If no match is found, then None is returned. Read more
Source§

impl PartialEq for Regex

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl RegexEngine for Regex

Source§

type CompileError = Error

Error type that is returned by the RegexEngine::compile method when compilation of a given regular expression fails. This will be wrapped into an Error when returned from Structex::compile or StructexBuilder::build.
Source§

fn compile(re: &str) -> Result<Self, Self::CompileError>

Attempt to compile the given regular expression for use inside of a Structex. Read more
Source§

impl Eq for Regex

Auto Trait Implementations§

§

impl !Freeze for Regex

§

impl RefUnwindSafe for Regex

§

impl Send for Regex

§

impl Sync for Regex

§

impl Unpin for Regex

§

impl UnwindSafe for Regex

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

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

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T> ToString for T
where T: Display + ?Sized,

§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more