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_validit is thenext_eoi_state+is_match_statestep; the\zin the wrapped pattern is what drivesis_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, socat|dogmeans “(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
impl RegexValidator
Sourcepub fn new(pattern: &str) -> Result<Self, RegexError>
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
impl Debug for RegexValidator
Source§impl Validator for RegexValidator
impl Validator for RegexValidator
Source§fn is_valid(&self, s: &str) -> bool
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
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<'_>)
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
fn validate(&self, s: &str, ctx: &mut Context<'_>) -> bool
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 moreSource§fn is_status_ok(&self) -> bool
fn is_status_ok(&self) -> bool
true;
PXPictureValidator overrides to report a malformed mask.Source§fn transfer_get(&self, _s: &str) -> Option<FieldValue>
fn transfer_get(&self, _s: &str) -> Option<FieldValue>
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 moreSource§fn transfer_set(&self, _v: &FieldValue) -> Option<String>
fn transfer_set(&self, _v: &FieldValue) -> Option<String>
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 moreAuto Trait Implementations§
impl Freeze for RegexValidator
impl RefUnwindSafe for RegexValidator
impl Send for RegexValidator
impl Sync for RegexValidator
impl Unpin for RegexValidator
impl UnsafeUnpin for RegexValidator
impl UnwindSafe for RegexValidator
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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.