Guide API
Skip to main content

RegexValidator

Struct RegexValidator 

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

A Validator driven by a regular expression, giving the same two-phase behavior as PXPictureValidator — is_valid = the input fully matches the pattern; is_valid_input = the input is still a prefix of some complete match (“could it still become valid?”) — but expressed as a regex so callers can leverage regex knowledge instead of Paradox picture-mask syntax.

§Pattern semantics

The pattern describes the complete field value and is implicitly fully anchored. The user pattern is compiled twice (see new); the effective pattern is (?:<pattern>)\z built with an anchored start state. Three pieces cooperate:

  • Start anchor comes from the DFA’s anchored-start configuration (StartKind::Anchored).
  • End anchor: for is_valid it is the next_eoi_state + is_match_state step; the \z in the wrapped pattern is what drives is_valid_input’s dead-state rejection (without it, no trailing input could ever be ruled out).
  • The (?:…) non-capturing group fixes alternation precedence: it anchors the whole alternation, so cat|dog means “(cat or dog), then end” rather than “cat, or (dog then \z)”.

To stop a malformed pattern from escaping that wrap (e.g. an unbalanced ) that would close (?:…) early and silently defeat end-anchoring), the bare user pattern is validated for self-containment before wrapping — see new.

§Per-keystroke viability (is_valid_input)

Uses the DFA dead-state test: walk the anchored DFA over the bytes of the input; if a dead state (one from which no match is ever reachable) is reached, the input cannot become valid no matter what is appended → reject. Unlike PXPictureValidator, RegexValidator performs no autofill and never mutates the input string.

§Construction cost and thread safety

The DFA is compiled once in new and is thereafter immutable. RegexValidator is Send + Sync. \d/\w/\s and other Perl-compatible character classes are available (unicode-perl feature is enabled).

§Turbo Vision heritage

tvision-rs extension: no Turbo Vision counterpart. It sits alongside the faithful PXPictureValidator port.

Implementations§

Source§

impl RegexValidator

Source

pub fn new(pattern: &str) -> Result<Self, RegexError>

Compile pattern as a description of a complete, valid field value.

The pattern is wrapped as (?:<pattern>)\z (end-anchored) and the DFA is built with StartKind::Anchored (start-anchored). Returns Err if the pattern is syntactically invalid or its DFA exceeds build limits.

The bare pattern is built and validated first, before wrapping: a pattern that is not self-contained — e.g. an unbalanced ) that would close the (?:…) group early and silently defeat end-anchoring (the \z binding only part of the pattern) — is rejected here. A balanced bare pattern cannot break out of the wrap, so this closes that hole.

Trait Implementations§

Source§

impl Debug for RegexValidator

Source§

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

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

impl Validator for RegexValidator

Source§

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

The whole input matches the pattern (a complete, valid value).

The regex analogue of PicResult::Complete in the picture validator: both the start and end anchors must be satisfied.

Source§

fn is_valid_input(&self, s: &mut String, _suppress_fill: bool) -> bool

The input is still a prefix of some complete match — “could it become valid if the user keeps typing?”.

Equivalent to “incomplete (or better)” in the picture-validator model: rejects only when the DFA has reached a dead state (no continuation can ever lead to a match). Does not mutate s — unlike PXPictureValidator, there is no autofill.

Source§

fn error(&self, ctx: &mut Context<'_>)

Report an invalid final value via the async-modal-from-a-view seam (informational, OK-only).

Source§

fn validate(&self, s: &str, ctx: &mut Context<'_>) -> bool

Validate s and, if invalid, pop the error box. Call this at the field-commit point (modal OK / focus release): it calls is_valid, and on failure calls error to display the message box before returning false. Returns true immediately when valid without touching the context. Read more
Source§

fn is_status_ok(&self) -> bool

Whether the validator’s status is OK — consulted when the field must commit. The base never enters a non-OK status, so the default is true; PXPictureValidator overrides to report a malformed mask.
Source§

fn transfer_get(&self, _s: &str) -> Option<FieldValue>

Report the field’s current text s as a typed FieldValue during a dialog gather walk. Return Some(typed value) when the validator has transfer enabled and can parse the text; return None to leave the input line carrying its plain text (the default, meaning “I don’t transfer”). Read more
Source§

fn transfer_set(&self, _v: &FieldValue) -> Option<String>

Format a typed FieldValue back to the field’s text during a dialog scatter walk. Return Some(text) when transfer is enabled and v is the type this validator handles; return None to leave the input line on its own text path (the default). Read more

Auto Trait Implementations§

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> CustomValue for T
where T: Any + Debug,

Source§

fn as_any_rc(self: Rc<T>) -> Rc<dyn Any>

Upcast Rc<Self> to Rc<dyn Any> so FieldValue::as_custom / FieldValue::value_as can downcast.
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.