pub struct PXPictureValidator { /* private fields */ }Expand description
The Paradox picture-mask validator.
Validates and auto-fills input against a Paradox “picture” mask: # digit,
? letter, & letter→uppercase, ! any→uppercase, @ any, * repeat,
{}/[] required/optional groups, , alternatives, ; literal-escape, and
any other character is a literal. On an invalid final value, error pops up
an OK-only message box.
The matching engine is a recursive state machine. Its scan cursors are pure
per-call scratch, not validator state, so — because the Validator methods
are &self (object-safe) — that scratch lives in a transient Picture
created fresh per call. Operation is byte-level.
§Turbo Vision heritage
Ports TPXPictureValidator, with the matching engine taken verbatim from
tvalidat.cpp. The streaming machinery is dropped (deviation D12). Where the
original copies the input into a fixed 256-byte stack buffer, tvision-rs lets the
backing String grow instead (real inputs are length-bounded by the field).
No null-mask guard is needed: pic is always a (possibly empty) String,
and an empty or malformed mask yields the same Syntax/Empty results.
Implementations§
Source§impl PXPictureValidator
impl PXPictureValidator
Sourcepub fn new(pic: impl Into<String>, auto_fill: bool) -> Self
pub fn new(pic: impl Into<String>, auto_fill: bool) -> Self
Build a Paradox picture validator from pic (the mask) and
auto_fill (whether to insert mask literals while the user types).
The constructor runs the engine on empty input as a syntax probe:
a well-formed mask returns Empty, leaving is_status_ok() true;
any other result means the mask is malformed and is_status_ok()
returns false. Check is_status_ok() after construction if you want
to report a bad mask before the field is even used.
Trait Implementations§
Source§impl Validator for PXPictureValidator
impl Validator for PXPictureValidator
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
Run the mask while typing (auto-filling unless suppress_fill); returns
whether the result is not an error. MUTATES s in place — autofill of
literals plus uppercase transforms is the whole point of a picture
validator.
Source§fn is_valid(&self, s: &str) -> bool
fn is_valid(&self, s: &str) -> bool
Returns true iff s fully satisfies the mask (i.e. the engine returns
Complete). Runs the matcher on a copy with auto-fill off, so s is
never mutated. Use this at the final-commit check; for the while-typing
path see is_valid_input.
Source§fn is_status_ok(&self) -> bool
fn is_status_ok(&self) -> bool
Whether the mask itself is well-formed — overrides the base accept-all to report a malformed mask.
Source§fn error(&self, ctx: &mut Context<'_>)
fn error(&self, ctx: &mut Context<'_>)
Pop an OK-only error box quoting the malformed mask (“Error in picture
format. {pic}”) via Context::request_message_box. Called
automatically by validate when
is_valid returns false.
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 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 PXPictureValidator
impl RefUnwindSafe for PXPictureValidator
impl Send for PXPictureValidator
impl Sync for PXPictureValidator
impl Unpin for PXPictureValidator
impl UnsafeUnpin for PXPictureValidator
impl UnwindSafe for PXPictureValidator
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.