MaskedTextProvider
struct · ferroui-controls · v0.5.0
struct MaskedTextProvider
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.
Members
INVALID_INDEXDEFAULT_PASSWORD_CHARnewnew_with_asciinew_with_culturenew_with_culture_asciinew_with_passwordnew_with_culture_passwordnew_fullallow_prompt_as_inputassigned_edit_position_countavailable_edit_position_countculturedefault_password_charedit_position_countedit_positionsinclude_literalsset_include_literalsinclude_promptset_include_promptascii_onlyis_passwordset_is_passwordinvalid_indexlast_assigned_positionlengthmaskmask_completedmask_fullpassword_charset_password_charprompt_charset_prompt_charreset_on_promptset_reset_on_promptreset_on_spaceset_reset_on_spaceskip_literalsset_skip_literalschar_atadd_charadd_char_with_hintaddadd_with_hintclearclear_with_hintfind_assigned_edit_position_fromfind_assigned_edit_position_in_rangefind_edit_position_fromfind_edit_position_in_rangefind_non_edit_position_fromfind_non_edit_position_in_rangefind_unassigned_edit_position_fromfind_unassigned_edit_position_in_rangeget_operation_result_from_hintinsert_at_charinsert_at_char_with_hintinsert_atinsert_at_with_hintis_available_positionis_edit_positionis_valid_input_charis_valid_mask_charis_valid_password_charremoveremove_with_hintremove_atremove_at_rangeremove_at_range_with_hintreplace_charreplace_char_with_hintreplace_char_range_with_hintreplacereplace_with_hintreplace_range_with_hintsetset_with_hintto_display_stringto_string_ignore_passwordto_string_rangeto_string_ignore_password_rangeto_string_includeto_string_include_rangeto_string_withverify_charverify_escape_charverify_stringverify_string_with_hint
INVALID_INDEX
const INVALID_INDEX: i32
The index returned by the find_* methods when nothing is found (-1).
DEFAULT_PASSWORD_CHAR
const DEFAULT_PASSWORD_CHAR: char
The password character used by Self::set_is_password (*).
new
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.
new_with_ascii
fn new_with_ascii(mask: &str, restrict_to_ascii: bool) -> Result<Self, MaskedTextProviderError>
Creates a provider for mask, optionally restricted to ASCII input.
new_with_culture
fn new_with_culture(mask: &str, culture: Option<CultureInfo>) -> Result<Self, MaskedTextProviderError>
Creates a provider for mask with a culture.
new_with_culture_ascii
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.
new_with_password
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).
new_with_culture_password
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).
new_full
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).
allow_prompt_as_input
fn allow_prompt_as_input(self: &Self) -> bool
Whether the prompt character is accepted as valid input.
assigned_edit_position_count
fn assigned_edit_position_count(self: &Self) -> i32
The number of edit positions that have a character assigned.
available_edit_position_count
fn available_edit_position_count(self: &Self) -> i32
The number of edit positions that have no character assigned.
culture
fn culture(self: &Self) -> &CultureInfo
The culture that provides the separators.
default_password_char
fn default_password_char() -> char
The default password character (*).
edit_position_count
fn edit_position_count(self: &Self) -> i32
The number of edit positions in the test string.
edit_positions
fn edit_positions(self: &Self) -> impl Iterator<Item = i32> + '_
The edit positions of the test string, in ascending order.
include_literals
fn include_literals(self: &Self) -> bool
Whether literals are included in the formatted string (fmt::Display
and the to_string_* methods without an explicit flag). Default true.
set_include_literals
fn set_include_literals(self: &mut Self, value: bool)
Sets Self::include_literals.
include_prompt
fn include_prompt(self: &Self) -> bool
Whether prompt characters are included in the formatted string.
Default false.
set_include_prompt
fn set_include_prompt(self: &mut Self, value: bool)
Sets Self::include_prompt.
ascii_only
fn ascii_only(self: &Self) -> bool
Whether only ASCII characters are valid input for the letter, alphanumeric and "any character" mask elements.
is_password
fn is_password(self: &Self) -> bool
Whether the input is displayed with a password character.
set_is_password
fn set_is_password(self: &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.
invalid_index
fn invalid_index() -> i32
The index returned by the find_* methods when nothing is found (-1).
last_assigned_position
fn last_assigned_position(self: &Self) -> i32
The position of the last assigned edit position, or
Self::INVALID_INDEX.
length
fn length(self: &Self) -> i32
The length of the test string (the mask without modifiers and with the separators replaced by the culture's).
mask
fn mask(self: &Self) -> &str
The mask.
mask_completed
fn mask_completed(self: &Self) -> bool
Whether all required edit positions have been assigned.
mask_full
fn mask_full(self: &Self) -> bool
Whether all edit positions (required and optional) have been assigned.
password_char
fn password_char(self: &Self) -> char
The character displayed instead of the input, '\0' for none.
set_password_char
fn set_password_char(self: &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.
prompt_char
fn prompt_char(self: &Self) -> char
The character displayed at unassigned edit positions.
set_prompt_char
fn set_prompt_char(self: &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.
reset_on_prompt
fn reset_on_prompt(self: &Self) -> bool
Whether a prompt character in the input resets the position it lands
on instead of being tested against the mask. Default true.
set_reset_on_prompt
fn set_reset_on_prompt(self: &mut Self, value: bool)
Sets Self::reset_on_prompt.
reset_on_space
fn reset_on_space(self: &Self) -> bool
Whether a space in the input resets the position it lands on instead
of being tested against the mask. Default true.
set_reset_on_space
fn set_reset_on_space(self: &mut Self, value: bool)
Sets Self::reset_on_space.
skip_literals
fn skip_literals(self: &Self) -> bool
Whether an input character equal to the literal at its position is
accepted and skipped. Default true.
set_skip_literals
fn set_skip_literals(self: &mut Self, value: bool)
Sets Self::skip_literals.
char_at
fn char_at(self: &Self, index: i32) -> char
The character of the test string at index.
Panics
Panics when index is out of range.
add_char
fn add_char(self: &mut Self, input: char) -> bool
Attempts to add input at the first edit position after the last
assigned one.
add_char_with_hint
fn add_char_with_hint(self: &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.
add
fn add(self: &mut Self, input: &str) -> bool
Attempts to add the characters of input after the last assigned
position. All of them are added, or none.
add_with_hint
fn add_with_hint(self: &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.
clear
fn clear(self: &mut Self)
Resets all edit positions.
clear_with_hint
fn clear_with_hint(self: &mut Self) -> MaskedTextResultHint
As Self::clear; returns MaskedTextResultHint::NoEffect when
nothing was assigned, MaskedTextResultHint::Success otherwise.
find_assigned_edit_position_from
fn find_assigned_edit_position_from(self: &Self, position: i32, direction: bool) -> i32
The first assigned edit position from position in the direction
(true forward, false backward), or Self::INVALID_INDEX.
find_assigned_edit_position_in_range
fn find_assigned_edit_position_in_range(self: &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.
find_edit_position_from
fn find_edit_position_from(self: &Self, position: i32, direction: bool) -> i32
The first edit position (assigned or not) from position in the
direction, or Self::INVALID_INDEX.
find_edit_position_in_range
fn find_edit_position_in_range(self: &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.
find_non_edit_position_from
fn find_non_edit_position_from(self: &Self, position: i32, direction: bool) -> i32
The first non-edit position (literal or separator) from position in
the direction, or Self::INVALID_INDEX.
find_non_edit_position_in_range
fn find_non_edit_position_in_range(self: &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.
find_unassigned_edit_position_from
fn find_unassigned_edit_position_from(self: &Self, position: i32, direction: bool) -> i32
The first unassigned edit position from position in the direction,
or Self::INVALID_INDEX.
find_unassigned_edit_position_in_range
fn find_unassigned_edit_position_in_range(self: &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.
get_operation_result_from_hint
fn get_operation_result_from_hint(hint: MaskedTextResultHint) -> bool
Whether a hint describes a success (positive) or a failure.
insert_at_char
fn insert_at_char(self: &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.
insert_at_char_with_hint
fn insert_at_char_with_hint(self: &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.
insert_at
fn insert_at(self: &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.
insert_at_with_hint
fn insert_at_with_hint(self: &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.
is_available_position
fn is_available_position(self: &Self, position: i32) -> bool
Whether position is an edit position with no character assigned.
is_edit_position
fn is_edit_position(self: &Self, position: i32) -> bool
Whether position is an edit position.
is_valid_input_char
fn is_valid_input_char(c: char) -> bool
Whether c is a valid input character: a letter, digit, punctuation,
symbol or the space.
is_valid_mask_char
fn is_valid_mask_char(c: char) -> bool
Whether c is a valid mask character (the same set as
Self::is_valid_input_char).
is_valid_password_char
fn is_valid_password_char(c: char) -> bool
Whether c is a valid password character: a valid input character, or
'\0' (no password character).
remove
fn remove(self: &mut Self) -> bool
Removes the last assigned character. Always succeeds.
remove_with_hint
fn remove_with_hint(self: &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.
remove_at
fn remove_at(self: &mut Self, position: i32) -> bool
Removes the character at position, shifting the characters after it
left.
remove_at_range
fn remove_at_range(self: &mut Self, start_position: i32, end_position: i32) -> bool
Removes the characters in the inclusive range, shifting the characters after it left.
remove_at_range_with_hint
fn remove_at_range_with_hint(self: &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.
replace_char
fn replace_char(self: &mut Self, input: char, position: i32) -> bool
Replaces the character at position (or the first edit position after
it) with input.
replace_char_with_hint
fn replace_char_with_hint(self: &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.
replace_char_range_with_hint
fn replace_char_range_with_hint(self: &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.
replace
fn replace(self: &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.
replace_with_hint
fn replace_with_hint(self: &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.
replace_range_with_hint
fn replace_range_with_hint(self: &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.
set
fn set(self: &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.
set_with_hint
fn set_with_hint(self: &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.
to_display_string
fn to_display_string(self: &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.
to_string_ignore_password
fn to_string_ignore_password(self: &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.
to_string_range
fn to_string_range(self: &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.
to_string_ignore_password_range
fn to_string_ignore_password_range(self: &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.
to_string_include
fn to_string_include(self: &Self, include_prompt: bool, include_literals: bool) -> String
The formatted string with or without prompts and literals, ignoring the password character.
to_string_include_range
fn to_string_include_range(self: &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.
to_string_with
fn to_string_with(self: &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.
verify_char
fn verify_char(self: &Self, input: char, position: i32) -> (bool, MaskedTextResultHint)
Tests whether input would be accepted at position, without
changing anything. Returns the result and its hint.
verify_escape_char
fn verify_escape_char(self: &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).
verify_string
fn verify_string(self: &Self, input: &str) -> bool
Tests whether input could be set (Self::set), without changing
anything.
verify_string_with_hint
fn verify_string_with_hint(self: &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
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeBorrow<T>BorrowMut<T>CloneToUninitInto<U>From<T>TryInto<U>TryFrom<U>AnyToOwnedToStringClassDefaultsErasedDestructorIntoEitherCloneDebugDisplayIndex<i32>
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.