Skip to main content

MaskedTextProvider

Struct MaskedTextProvider 

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

Provides functionality for formatting a test string against a mask string. MaskedTextProvider::add, MaskedTextProvider::insert_at, MaskedTextProvider::remove_at and the like modify the state of the test string; Clone produces an independent copy with the same state.

Implementations§

Source§

impl MaskedTextProvider

Source

pub const INVALID_INDEX: i32 = INVALID_INDEX

The index returned by the find_* methods when nothing is found (-1).

Source

pub const DEFAULT_PASSWORD_CHAR: char = '*'

The password character used by Self::set_is_password (*).

Source

pub fn new(mask: &str) -> Result<Self, MaskedTextProviderError>

Creates a provider for mask with the current culture, the prompt allowed as input, _ as prompt, no password character and no ASCII restriction.

Source

pub fn new_with_ascii( mask: &str, restrict_to_ascii: bool, ) -> Result<Self, MaskedTextProviderError>

Creates a provider for mask, optionally restricted to ASCII input.

Source

pub fn new_with_culture( mask: &str, culture: Option<CultureInfo>, ) -> Result<Self, MaskedTextProviderError>

Creates a provider for mask with a culture.

Source

pub fn new_with_culture_ascii( mask: &str, culture: Option<CultureInfo>, restrict_to_ascii: bool, ) -> Result<Self, MaskedTextProviderError>

Creates a provider for mask with a culture, optionally restricted to ASCII input.

Source

pub fn new_with_password( mask: &str, password_char: char, allow_prompt_as_input: bool, ) -> Result<Self, MaskedTextProviderError>

Creates a provider for mask with a password character ('\0' for none).

Source

pub fn new_with_culture_password( mask: &str, culture: Option<CultureInfo>, password_char: char, allow_prompt_as_input: bool, ) -> Result<Self, MaskedTextProviderError>

Creates a provider for mask with a culture and a password character ('\0' for none).

Source

pub fn new_full( mask: &str, culture: Option<CultureInfo>, allow_prompt_as_input: bool, prompt_char: char, password_char: char, restrict_to_ascii: bool, ) -> Result<Self, MaskedTextProviderError>

Creates a provider.

  • mask — the mask; must not be empty and must only contain valid mask characters (Self::is_valid_mask_char).
  • culture — the culture providing the separators; None is the current culture.
  • allow_prompt_as_input — whether the prompt character is accepted as input.
  • prompt_char — the character shown at unassigned edit positions.
  • password_char — the character shown instead of the input, '\0' for none.
  • restrict_to_ascii — whether letters and characters are restricted to ASCII.

As in the original, the prompt and password characters are not validated here (only their setters validate).

Source

pub fn allow_prompt_as_input(&self) -> bool

Whether the prompt character is accepted as valid input.

Source

pub fn assigned_edit_position_count(&self) -> i32

The number of edit positions that have a character assigned.

Source

pub fn available_edit_position_count(&self) -> i32

The number of edit positions that have no character assigned.

Source

pub fn culture(&self) -> &CultureInfo

The culture that provides the separators.

Source

pub fn default_password_char() -> char

The default password character (*).

Source

pub fn edit_position_count(&self) -> i32

The number of edit positions in the test string.

Source

pub fn edit_positions(&self) -> impl Iterator<Item = i32> + '_

The edit positions of the test string, in ascending order.

Source

pub fn include_literals(&self) -> bool

Whether literals are included in the formatted string (fmt::Display and the to_string_* methods without an explicit flag). Default true.

Source

pub fn set_include_literals(&mut self, value: bool)

Source

pub fn include_prompt(&self) -> bool

Whether prompt characters are included in the formatted string. Default false.

Source

pub fn set_include_prompt(&mut self, value: bool)

Source

pub fn ascii_only(&self) -> bool

Whether only ASCII characters are valid input for the letter, alphanumeric and “any character” mask elements.

Source

pub fn is_password(&self) -> bool

Whether the input is displayed with a password character.

Source

pub fn set_is_password(&mut self, value: bool)

Turns the password display on (with Self::DEFAULT_PASSWORD_CHAR) or off; does nothing when it already is in the requested state.

Source

pub fn invalid_index() -> i32

The index returned by the find_* methods when nothing is found (-1).

Source

pub fn last_assigned_position(&self) -> i32

The position of the last assigned edit position, or Self::INVALID_INDEX.

Source

pub fn length(&self) -> i32

The length of the test string (the mask without modifiers and with the separators replaced by the culture’s).

Source

pub fn mask(&self) -> &str

The mask.

Source

pub fn mask_completed(&self) -> bool

Whether all required edit positions have been assigned.

Source

pub fn mask_full(&self) -> bool

Whether all edit positions (required and optional) have been assigned.

Source

pub fn password_char(&self) -> char

The character displayed instead of the input, '\0' for none.

Source

pub fn set_password_char( &mut self, value: char, ) -> Result<(), MaskedTextProviderError>

Sets the password character ('\0' for none). It must differ from the prompt character and be a valid password character.

Source

pub fn prompt_char(&self) -> char

The character displayed at unassigned edit positions.

Source

pub fn set_prompt_char( &mut self, value: char, ) -> Result<(), MaskedTextProviderError>

Sets the prompt character. It must differ from the password character and be a valid input character. The unassigned edit positions of the test string are updated.

Source

pub fn reset_on_prompt(&self) -> bool

Whether a prompt character in the input resets the position it lands on instead of being tested against the mask. Default true.

Source

pub fn set_reset_on_prompt(&mut self, value: bool)

Source

pub fn reset_on_space(&self) -> bool

Whether a space in the input resets the position it lands on instead of being tested against the mask. Default true.

Source

pub fn set_reset_on_space(&mut self, value: bool)

Source

pub fn skip_literals(&self) -> bool

Whether an input character equal to the literal at its position is accepted and skipped. Default true.

Source

pub fn set_skip_literals(&mut self, value: bool)

Source

pub fn char_at(&self, index: i32) -> char

The character of the test string at index.

§Panics

Panics when index is out of range.

Source

pub fn add_char(&mut self, input: char) -> bool

Attempts to add input at the first edit position after the last assigned one.

Source

pub fn add_char_with_hint( &mut self, input: char, ) -> (bool, i32, MaskedTextResultHint)

As Self::add_char; also returns the position the character was tested at (the length of the test string when there is none) and the result hint.

Source

pub fn add(&mut self, input: &str) -> bool

Attempts to add the characters of input after the last assigned position. All of them are added, or none.

Source

pub fn add_with_hint( &mut self, input: &str, ) -> (bool, i32, MaskedTextResultHint)

As Self::add; also returns the position of the last character tested (on failure: the failing position) and the result hint.

Source

pub fn clear(&mut self)

Resets all edit positions.

Source

pub fn clear_with_hint(&mut self) -> MaskedTextResultHint

As Self::clear; returns MaskedTextResultHint::NoEffect when nothing was assigned, MaskedTextResultHint::Success otherwise.

Source

pub fn find_assigned_edit_position_from( &self, position: i32, direction: bool, ) -> i32

The first assigned edit position from position in the direction (true forward, false backward), or Self::INVALID_INDEX.

Source

pub fn find_assigned_edit_position_in_range( &self, start_position: i32, end_position: i32, direction: bool, ) -> i32

The first assigned edit position in the inclusive range, searching in the direction, or Self::INVALID_INDEX.

Source

pub fn find_edit_position_from(&self, position: i32, direction: bool) -> i32

The first edit position (assigned or not) from position in the direction, or Self::INVALID_INDEX.

Source

pub fn find_edit_position_in_range( &self, start_position: i32, end_position: i32, direction: bool, ) -> i32

The first edit position (assigned or not) in the inclusive range, searching in the direction, or Self::INVALID_INDEX.

Source

pub fn find_non_edit_position_from(&self, position: i32, direction: bool) -> i32

The first non-edit position (literal or separator) from position in the direction, or Self::INVALID_INDEX.

Source

pub fn find_non_edit_position_in_range( &self, start_position: i32, end_position: i32, direction: bool, ) -> i32

The first non-edit position in the inclusive range, searching in the direction, or Self::INVALID_INDEX.

Source

pub fn find_unassigned_edit_position_from( &self, position: i32, direction: bool, ) -> i32

The first unassigned edit position from position in the direction, or Self::INVALID_INDEX.

Source

pub fn find_unassigned_edit_position_in_range( &self, start_position: i32, end_position: i32, direction: bool, ) -> i32

The first unassigned edit position in the inclusive range, searching in the direction, or Self::INVALID_INDEX.

Source

pub fn get_operation_result_from_hint(hint: MaskedTextResultHint) -> bool

Whether a hint describes a success (positive) or a failure.

Source

pub fn insert_at_char(&mut self, input: char, position: i32) -> bool

Attempts to insert input at position (or the first edit position after it), shifting the existing characters right.

Source

pub fn insert_at_char_with_hint( &mut self, input: char, position: i32, ) -> (bool, i32, MaskedTextResultHint)

As Self::insert_at_char; also returns the position of the inserted character (on failure: the failing position) and the result hint.

Source

pub fn insert_at(&mut self, input: &str, position: i32) -> bool

Attempts to insert the characters of input from position, shifting the existing characters right. All of them are inserted, or none.

Source

pub fn insert_at_with_hint( &mut self, input: &str, position: i32, ) -> (bool, i32, MaskedTextResultHint)

As Self::insert_at; also returns the position of the last inserted character (on failure: the failing position) and the result hint.

Source

pub fn is_available_position(&self, position: i32) -> bool

Whether position is an edit position with no character assigned.

Source

pub fn is_edit_position(&self, position: i32) -> bool

Whether position is an edit position.

Source

pub fn is_valid_input_char(c: char) -> bool

Whether c is a valid input character: a letter, digit, punctuation, symbol or the space.

Source

pub fn is_valid_mask_char(c: char) -> bool

Whether c is a valid mask character (the same set as Self::is_valid_input_char).

Source

pub fn is_valid_password_char(c: char) -> bool

Whether c is a valid password character: a valid input character, or '\0' (no password character).

Source

pub fn remove(&mut self) -> bool

Removes the last assigned character. Always succeeds.

Source

pub fn remove_with_hint(&mut self) -> (bool, i32, MaskedTextResultHint)

As Self::remove; also returns the position of the removed character (0 when there was none) and the result hint.

Source

pub fn remove_at(&mut self, position: i32) -> bool

Removes the character at position, shifting the characters after it left.

Source

pub fn remove_at_range( &mut self, start_position: i32, end_position: i32, ) -> bool

Removes the characters in the inclusive range, shifting the characters after it left.

Source

pub fn remove_at_range_with_hint( &mut self, start_position: i32, end_position: i32, ) -> (bool, i32, MaskedTextResultHint)

As Self::remove_at_range; also returns the position the operation was performed at (on failure: the failing position) and the result hint.

Source

pub fn replace_char(&mut self, input: char, position: i32) -> bool

Replaces the character at position (or the first edit position after it) with input.

Source

pub fn replace_char_with_hint( &mut self, input: char, position: i32, ) -> (bool, i32, MaskedTextResultHint)

As Self::replace_char; also returns the position of the replaced character (on failure: the failing position) and the result hint.

Source

pub fn replace_char_range_with_hint( &mut self, input: char, start_position: i32, end_position: i32, ) -> (bool, i32, MaskedTextResultHint)

Replaces the characters in the inclusive range with input, removing the rest of the range and shifting the characters after it left.

Source

pub fn replace(&mut self, input: &str, position: i32) -> bool

Replaces the characters from position with the characters of input, without shifting. An empty input removes the character at position.

Source

pub fn replace_with_hint( &mut self, input: &str, position: i32, ) -> (bool, i32, MaskedTextResultHint)

As Self::replace; also returns the position of the last replaced character (on failure: the failing position) and the result hint.

Source

pub fn replace_range_with_hint( &mut self, input: &str, start_position: i32, end_position: i32, ) -> (bool, i32, MaskedTextResultHint)

Replaces the characters in the inclusive range with the characters of input: when the input is shorter than the range the rest of the range is removed, when it is longer the characters after the range shift right. An empty input removes the range.

Source

pub fn set(&mut self, input: &str) -> bool

Sets the test string to input: the previous content is replaced. Nothing changes when the input does not fit the mask.

Source

pub fn set_with_hint( &mut self, input: &str, ) -> (bool, i32, MaskedTextResultHint)

As Self::set; also returns the position of the last character set (on failure: the failing position) and the result hint.

Source

pub fn to_display_string(&self) -> String

The formatted string as it is to be displayed: prompts and literals included, and the input replaced by the password character if there is one.

Source

pub fn to_string_ignore_password(&self, ignore_password_char: bool) -> String

The formatted string, with prompts and literals according to Self::include_prompt and Self::include_literals; the password character is used unless ignore_password_char.

Source

pub fn to_string_range(&self, start_position: i32, length: i32) -> String

A part of the formatted string, with prompts and literals according to Self::include_prompt and Self::include_literals, ignoring the password character.

Source

pub fn to_string_ignore_password_range( &self, ignore_password_char: bool, start_position: i32, length: i32, ) -> String

A part of the formatted string, with prompts and literals according to Self::include_prompt and Self::include_literals; the password character is used unless ignore_password_char.

Source

pub fn to_string_include( &self, include_prompt: bool, include_literals: bool, ) -> String

The formatted string with or without prompts and literals, ignoring the password character.

Source

pub fn to_string_include_range( &self, include_prompt: bool, include_literals: bool, start_position: i32, length: i32, ) -> String

A part of the formatted string with or without prompts and literals, ignoring the password character.

Source

pub fn to_string_with( &self, ignore_password_char: bool, include_prompt: bool, include_literals: bool, start_position: i32, length: i32, ) -> String

A part of the formatted string.

  • ignore_password_char — show the input even when there is a password character.
  • include_prompt — keep the prompt at unassigned positions; without it they become spaces, and the string ends at the last assigned position (or the last literal, when literals are included).
  • include_literals — keep the literals and separators.
  • start_position, length — the part of the test string; clamped to it.
Source

pub fn verify_char( &self, input: char, position: i32, ) -> (bool, MaskedTextResultHint)

Tests whether input would be accepted at position, without changing anything. Returns the result and its hint.

Source

pub fn verify_escape_char(&self, input: char, position: i32) -> bool

Tests whether input would be escaped at position: skipped as a matching literal, or taken as a reset (prompt or space).

Source

pub fn verify_string(&self, input: &str) -> bool

Tests whether input could be set (Self::set), without changing anything.

Source

pub fn verify_string_with_hint( &self, input: &str, ) -> (bool, i32, MaskedTextResultHint)

As Self::verify_string; also returns the position of the last character tested (on failure: the failing position) and the result hint.

Trait Implementations§

Source§

impl Clone for MaskedTextProvider

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for MaskedTextProvider

Source§

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

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

impl Display for MaskedTextProvider

The formatted string with prompts and literals according to MaskedTextProvider::include_prompt and MaskedTextProvider::include_literals, ignoring the password character.

Source§

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

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

impl Index<i32> for MaskedTextProvider

The character of the test string at an index; panics when it is out of range.

Source§

type Output = char

The returned type after indexing.
Source§

fn index(&self, index: i32) -> &char

Performs the indexing (container[index]) operation. 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> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). Read more
Source§

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

Source§

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<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> ToOwned for T
where T: Clone,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.