Struct sequoia_openpgp::regex::Regex

source ·
pub struct Regex { /* private fields */ }
Expand description

A compiled OpenPGP regular expression for matching UTF-8 encoded strings.

A Regex contains a regular expression compiled according to the rules defined in Section 8 of RFC 4880 modulo two differences. First, the compiler only works on UTF-8 strings (not bytes). Second, ranges in character classes are between UTF-8 characters, not just ASCII characters. Further, by default, strings that don’t pass a sanity check (in particular, include Unicode control characters) never match. This behavior can be customized using Regex::disable_sanitizations.

Regular expressions are used to scope the trust that trust signatures extend.

When working with trust signatures, you’ll usually want to use the RegexSet data structure, which already implements the correct semantics.

See the module-level documentation for more details.

§A note on equality

We define equality on Regex as the equality of the uncompiled regular expression given to the constructor and whether sanitizations are enabled.

Implementations§

source§

impl Regex

source

pub fn new(re: &str) -> Result<Self>

Parses and compiles the regular expression.

By default, strings that don’t pass a sanity check (in particular, include Unicode control characters) never match. This behavior can be customized using Regex::disable_sanitizations.

source

pub fn from_bytes(re: &[u8]) -> Result<Self>

Parses and compiles the regular expression.

Returns an error if re is not a valid UTF-8 string.

By default, strings that don’t pass a sanity check (in particular, include Unicode control characters) never match. This behavior can be customized using Regex::disable_sanitizations.

source

pub fn as_str(&self) -> &str

Returns the string-representation of the regular expression.

source

pub fn disable_sanitizations(&mut self, disabled: bool)

Controls whether matched strings must pass a sanity check.

If false (the default), i.e., sanity checks are enabled, and the string doesn’t pass the sanity check (in particular, it contains a Unicode control character according to char::is_control, including newlines and an embedded NUL byte), this returns false.

source

pub fn is_match(&self, s: &str) -> bool

Returns whether the regular expression matches the string.

If sanity checks are enabled (the default) and the string doesn’t pass the sanity check (in particular, it contains a Unicode control character according to char::is_control, including newlines and an embedded NUL byte), this returns false.

source

pub fn matches_userid(&self, u: &UserID) -> bool

Returns whether the regular expression matches the User ID.

If the User ID is not a valid UTF-8 string, this returns false.

If sanity checks are enabled (the default) and the string doesn’t pass the sanity check (in particular, it contains a Unicode control character according to char::is_control, including newlines and an embedded NUL byte), this returns false.

Trait Implementations§

source§

impl Clone for Regex

source§

fn clone(&self) -> Regex

Returns a copy of the value. Read more
1.0.0 · source§

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 PartialEq for Regex

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
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§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

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

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

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

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

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

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

Performs the conversion.
source§

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.
source§

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

Performs the conversion.
source§

impl<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T