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
impl MaskedTextProvider
Sourcepub const INVALID_INDEX: i32 = INVALID_INDEX
pub const INVALID_INDEX: i32 = INVALID_INDEX
The index returned by the find_* methods when nothing is found (-1).
Sourcepub const DEFAULT_PASSWORD_CHAR: char = '*'
pub const DEFAULT_PASSWORD_CHAR: char = '*'
The password character used by Self::set_is_password (*).
Sourcepub fn new(mask: &str) -> Result<Self, MaskedTextProviderError>
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.
Sourcepub fn new_with_ascii(
mask: &str,
restrict_to_ascii: bool,
) -> Result<Self, MaskedTextProviderError>
pub fn new_with_ascii( mask: &str, restrict_to_ascii: bool, ) -> Result<Self, MaskedTextProviderError>
Creates a provider for mask, optionally restricted to ASCII input.
Sourcepub fn new_with_culture(
mask: &str,
culture: Option<CultureInfo>,
) -> Result<Self, MaskedTextProviderError>
pub fn new_with_culture( mask: &str, culture: Option<CultureInfo>, ) -> Result<Self, MaskedTextProviderError>
Creates a provider for mask with a culture.
Sourcepub fn new_with_culture_ascii(
mask: &str,
culture: Option<CultureInfo>,
restrict_to_ascii: bool,
) -> Result<Self, MaskedTextProviderError>
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.
Sourcepub fn new_with_password(
mask: &str,
password_char: char,
allow_prompt_as_input: bool,
) -> Result<Self, MaskedTextProviderError>
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).
Sourcepub fn new_with_culture_password(
mask: &str,
culture: Option<CultureInfo>,
password_char: char,
allow_prompt_as_input: bool,
) -> Result<Self, MaskedTextProviderError>
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).
Sourcepub 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>
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;Noneis 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).
Sourcepub fn allow_prompt_as_input(&self) -> bool
pub fn allow_prompt_as_input(&self) -> bool
Whether the prompt character is accepted as valid input.
Sourcepub fn assigned_edit_position_count(&self) -> i32
pub fn assigned_edit_position_count(&self) -> i32
The number of edit positions that have a character assigned.
Sourcepub fn available_edit_position_count(&self) -> i32
pub fn available_edit_position_count(&self) -> i32
The number of edit positions that have no character assigned.
Sourcepub fn culture(&self) -> &CultureInfo
pub fn culture(&self) -> &CultureInfo
The culture that provides the separators.
Sourcepub fn default_password_char() -> char
pub fn default_password_char() -> char
The default password character (*).
Sourcepub fn edit_position_count(&self) -> i32
pub fn edit_position_count(&self) -> i32
The number of edit positions in the test string.
Sourcepub fn edit_positions(&self) -> impl Iterator<Item = i32> + '_
pub fn edit_positions(&self) -> impl Iterator<Item = i32> + '_
The edit positions of the test string, in ascending order.
Sourcepub fn include_literals(&self) -> bool
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.
Sourcepub fn set_include_literals(&mut self, value: bool)
pub fn set_include_literals(&mut self, value: bool)
Sets Self::include_literals.
Sourcepub fn include_prompt(&self) -> bool
pub fn include_prompt(&self) -> bool
Whether prompt characters are included in the formatted string.
Default false.
Sourcepub fn set_include_prompt(&mut self, value: bool)
pub fn set_include_prompt(&mut self, value: bool)
Sets Self::include_prompt.
Sourcepub fn ascii_only(&self) -> bool
pub fn ascii_only(&self) -> bool
Whether only ASCII characters are valid input for the letter, alphanumeric and “any character” mask elements.
Sourcepub fn is_password(&self) -> bool
pub fn is_password(&self) -> bool
Whether the input is displayed with a password character.
Sourcepub fn set_is_password(&mut self, value: bool)
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.
Sourcepub fn invalid_index() -> i32
pub fn invalid_index() -> i32
The index returned by the find_* methods when nothing is found (-1).
Sourcepub fn last_assigned_position(&self) -> i32
pub fn last_assigned_position(&self) -> i32
The position of the last assigned edit position, or
Self::INVALID_INDEX.
Sourcepub fn length(&self) -> i32
pub fn length(&self) -> i32
The length of the test string (the mask without modifiers and with the separators replaced by the culture’s).
Sourcepub fn mask_completed(&self) -> bool
pub fn mask_completed(&self) -> bool
Whether all required edit positions have been assigned.
Sourcepub fn mask_full(&self) -> bool
pub fn mask_full(&self) -> bool
Whether all edit positions (required and optional) have been assigned.
Sourcepub fn password_char(&self) -> char
pub fn password_char(&self) -> char
The character displayed instead of the input, '\0' for none.
Sourcepub fn set_password_char(
&mut self,
value: char,
) -> Result<(), MaskedTextProviderError>
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.
Sourcepub fn prompt_char(&self) -> char
pub fn prompt_char(&self) -> char
The character displayed at unassigned edit positions.
Sourcepub fn set_prompt_char(
&mut self,
value: char,
) -> Result<(), MaskedTextProviderError>
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.
Sourcepub fn reset_on_prompt(&self) -> bool
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.
Sourcepub fn set_reset_on_prompt(&mut self, value: bool)
pub fn set_reset_on_prompt(&mut self, value: bool)
Sets Self::reset_on_prompt.
Sourcepub fn reset_on_space(&self) -> bool
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.
Sourcepub fn set_reset_on_space(&mut self, value: bool)
pub fn set_reset_on_space(&mut self, value: bool)
Sets Self::reset_on_space.
Sourcepub fn skip_literals(&self) -> bool
pub fn skip_literals(&self) -> bool
Whether an input character equal to the literal at its position is
accepted and skipped. Default true.
Sourcepub fn set_skip_literals(&mut self, value: bool)
pub fn set_skip_literals(&mut self, value: bool)
Sets Self::skip_literals.
Sourcepub fn add_char(&mut self, input: char) -> bool
pub fn add_char(&mut self, input: char) -> bool
Attempts to add input at the first edit position after the last
assigned one.
Sourcepub fn add_char_with_hint(
&mut self,
input: char,
) -> (bool, i32, MaskedTextResultHint)
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.
Sourcepub fn add(&mut self, input: &str) -> bool
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.
Sourcepub fn add_with_hint(
&mut self,
input: &str,
) -> (bool, i32, MaskedTextResultHint)
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.
Sourcepub fn clear_with_hint(&mut self) -> MaskedTextResultHint
pub fn clear_with_hint(&mut self) -> MaskedTextResultHint
As Self::clear; returns MaskedTextResultHint::NoEffect when
nothing was assigned, MaskedTextResultHint::Success otherwise.
Sourcepub fn find_assigned_edit_position_from(
&self,
position: i32,
direction: bool,
) -> i32
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.
Sourcepub fn find_assigned_edit_position_in_range(
&self,
start_position: i32,
end_position: i32,
direction: bool,
) -> i32
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.
Sourcepub fn find_edit_position_from(&self, position: i32, direction: bool) -> i32
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.
Sourcepub fn find_edit_position_in_range(
&self,
start_position: i32,
end_position: i32,
direction: bool,
) -> i32
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.
Sourcepub fn find_non_edit_position_from(&self, position: i32, direction: bool) -> i32
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.
Sourcepub fn find_non_edit_position_in_range(
&self,
start_position: i32,
end_position: i32,
direction: bool,
) -> i32
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.
Sourcepub fn find_unassigned_edit_position_from(
&self,
position: i32,
direction: bool,
) -> i32
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.
Sourcepub fn find_unassigned_edit_position_in_range(
&self,
start_position: i32,
end_position: i32,
direction: bool,
) -> i32
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.
Sourcepub fn get_operation_result_from_hint(hint: MaskedTextResultHint) -> bool
pub fn get_operation_result_from_hint(hint: MaskedTextResultHint) -> bool
Whether a hint describes a success (positive) or a failure.
Sourcepub fn insert_at_char(&mut self, input: char, position: i32) -> bool
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.
Sourcepub fn insert_at_char_with_hint(
&mut self,
input: char,
position: i32,
) -> (bool, i32, MaskedTextResultHint)
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.
Sourcepub fn insert_at(&mut self, input: &str, position: i32) -> bool
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.
Sourcepub fn insert_at_with_hint(
&mut self,
input: &str,
position: i32,
) -> (bool, i32, MaskedTextResultHint)
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.
Sourcepub fn is_available_position(&self, position: i32) -> bool
pub fn is_available_position(&self, position: i32) -> bool
Whether position is an edit position with no character assigned.
Sourcepub fn is_edit_position(&self, position: i32) -> bool
pub fn is_edit_position(&self, position: i32) -> bool
Whether position is an edit position.
Sourcepub fn is_valid_input_char(c: char) -> bool
pub fn is_valid_input_char(c: char) -> bool
Whether c is a valid input character: a letter, digit, punctuation,
symbol or the space.
Sourcepub fn is_valid_mask_char(c: char) -> bool
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).
Sourcepub fn is_valid_password_char(c: char) -> bool
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).
Sourcepub fn remove_with_hint(&mut self) -> (bool, i32, MaskedTextResultHint)
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.
Sourcepub fn remove_at(&mut self, position: i32) -> bool
pub fn remove_at(&mut self, position: i32) -> bool
Removes the character at position, shifting the characters after it
left.
Sourcepub fn remove_at_range(
&mut self,
start_position: i32,
end_position: i32,
) -> bool
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.
Sourcepub fn remove_at_range_with_hint(
&mut self,
start_position: i32,
end_position: i32,
) -> (bool, i32, MaskedTextResultHint)
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.
Sourcepub fn replace_char(&mut self, input: char, position: i32) -> bool
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.
Sourcepub fn replace_char_with_hint(
&mut self,
input: char,
position: i32,
) -> (bool, i32, MaskedTextResultHint)
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.
Sourcepub fn replace_char_range_with_hint(
&mut self,
input: char,
start_position: i32,
end_position: i32,
) -> (bool, i32, MaskedTextResultHint)
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.
Sourcepub fn replace(&mut self, input: &str, position: i32) -> bool
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.
Sourcepub fn replace_with_hint(
&mut self,
input: &str,
position: i32,
) -> (bool, i32, MaskedTextResultHint)
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.
Sourcepub fn replace_range_with_hint(
&mut self,
input: &str,
start_position: i32,
end_position: i32,
) -> (bool, i32, MaskedTextResultHint)
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.
Sourcepub fn set(&mut self, input: &str) -> bool
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.
Sourcepub fn set_with_hint(
&mut self,
input: &str,
) -> (bool, i32, MaskedTextResultHint)
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.
Sourcepub fn to_display_string(&self) -> String
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.
Sourcepub fn to_string_ignore_password(&self, ignore_password_char: bool) -> String
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.
Sourcepub fn to_string_range(&self, start_position: i32, length: i32) -> String
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.
Sourcepub fn to_string_ignore_password_range(
&self,
ignore_password_char: bool,
start_position: i32,
length: i32,
) -> String
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.
Sourcepub fn to_string_include(
&self,
include_prompt: bool,
include_literals: bool,
) -> String
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.
Sourcepub fn to_string_include_range(
&self,
include_prompt: bool,
include_literals: bool,
start_position: i32,
length: i32,
) -> String
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.
Sourcepub fn to_string_with(
&self,
ignore_password_char: bool,
include_prompt: bool,
include_literals: bool,
start_position: i32,
length: i32,
) -> String
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.
Sourcepub fn verify_char(
&self,
input: char,
position: i32,
) -> (bool, MaskedTextResultHint)
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.
Sourcepub fn verify_escape_char(&self, input: char, position: i32) -> bool
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).
Sourcepub fn verify_string(&self, input: &str) -> bool
pub fn verify_string(&self, input: &str) -> bool
Tests whether input could be set (Self::set), without changing
anything.
Sourcepub fn verify_string_with_hint(
&self,
input: &str,
) -> (bool, i32, MaskedTextResultHint)
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
impl Clone for MaskedTextProvider
Source§impl Debug for MaskedTextProvider
impl Debug for MaskedTextProvider
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.
impl Display for MaskedTextProvider
The formatted string with prompts and literals according to
MaskedTextProvider::include_prompt and
MaskedTextProvider::include_literals, ignoring the password character.
Auto Trait Implementations§
impl !RefUnwindSafe for MaskedTextProvider
impl !Send for MaskedTextProvider
impl !Sync for MaskedTextProvider
impl !UnwindSafe for MaskedTextProvider
impl Freeze for MaskedTextProvider
impl Unpin for MaskedTextProvider
impl UnsafeUnpin for MaskedTextProvider
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
Source§impl<T> ClassDefaults for Twhere
T: ?Sized,
impl<T> ClassDefaults for Twhere
T: ?Sized,
Source§fn static_constructor()
fn static_constructor()
affects_render, metadata
overrides). Read more