Trait string_patterns::alphanumeric::StripCharacters
source · pub trait StripCharacters {
// Required methods
fn strip_non_alphanum(&self) -> String;
fn strip_non_digits(&self) -> String;
fn to_numeric_strings(&self) -> Vec<String>;
fn to_numeric_strings_euro(&self) -> Vec<String>;
fn to_numeric_strings_conditional(
&self,
enforce_comma_separator: bool
) -> Vec<String>;
fn to_numbers_conditional<T: FromStr>(
&self,
enforce_comma_separator: bool
) -> Vec<T>;
fn correct_numeric_string(&self, enforce_comma_separator: bool) -> String;
fn strip_non_numeric(&self) -> String;
// Provided methods
fn to_numbers<T: FromStr>(&self) -> Vec<T> { ... }
fn to_numbers_euro<T: FromStr>(&self) -> Vec<T> { ... }
fn to_first_number<T: FromStr + Copy>(&self) -> Option<T> { ... }
fn to_first_number_euro<T: FromStr + Copy>(&self) -> Option<T> { ... }
}
Expand description
Set of methods to strip unwanted characters by type or extract vectors of numeric strings, integers or floats
Required Methods§
sourcefn strip_non_alphanum(&self) -> String
fn strip_non_alphanum(&self) -> String
Removes all characters that any are not letters or digits, such as punctuation or symobols Letters include those used in most non-Latin alphabets
fn strip_non_digits(&self) -> String
sourcefn to_numeric_strings(&self) -> Vec<String>
fn to_numeric_strings(&self) -> Vec<String>
Extracts valid numeric string components from a longer string
sourcefn to_numeric_strings_euro(&self) -> Vec<String>
fn to_numeric_strings_euro(&self) -> Vec<String>
Always interpret numeric strings with dots as thousand separators and commas as decimal separators
fn to_numeric_strings_conditional( &self, enforce_comma_separator: bool ) -> Vec<String>
sourcefn to_numbers_conditional<T: FromStr>(
&self,
enforce_comma_separator: bool
) -> Vec<T>
fn to_numbers_conditional<T: FromStr>( &self, enforce_comma_separator: bool ) -> Vec<T>
Extract numeric strings and cast to numbers with conditional logic over commas and dots, The boolean flag enforces European logic where dots separate thousands and commas decimals Otherwise the correct format is deduced. Numeric strings are problematic when they only contain one comma or point. Otherwise the last separator is always considered the decimal separator if it differs from the first separators.
sourcefn correct_numeric_string(&self, enforce_comma_separator: bool) -> String
fn correct_numeric_string(&self, enforce_comma_separator: bool) -> String
Correct numbers to conform to use dots (periods, full-stops) only as decimal separators Works only on the first number encountered and used with to_numeric_strings or to_numeric_strings_euro to correct multiple numbers in a longer string
sourcefn strip_non_numeric(&self) -> String
fn strip_non_numeric(&self) -> String
Removes all characters no used in valid numeric sequences
Provided Methods§
sourcefn to_numbers<T: FromStr>(&self) -> Vec<T>
fn to_numbers<T: FromStr>(&self) -> Vec<T>
Extracts valid integers or floats from a longer string
sourcefn to_numbers_euro<T: FromStr>(&self) -> Vec<T>
fn to_numbers_euro<T: FromStr>(&self) -> Vec<T>
Extract numeric string using European-style decimal commas
sourcefn to_first_number<T: FromStr + Copy>(&self) -> Option<T>
fn to_first_number<T: FromStr + Copy>(&self) -> Option<T>
Extracts the first valid integer or float from a longer string if present
sourcefn to_first_number_euro<T: FromStr + Copy>(&self) -> Option<T>
fn to_first_number_euro<T: FromStr + Copy>(&self) -> Option<T>
Extracts the first valid integer or float from a longer string if commas are used for decimals and dots for thousand separators
Object Safety§
Implementations on Foreign Types§
source§impl StripCharacters for str
impl StripCharacters for str
source§fn strip_non_alphanum(&self) -> String
fn strip_non_alphanum(&self) -> String
Remove all characters that are not letters or numerals for later string comparison. Does not use a regular expression
source§fn strip_non_digits(&self) -> String
fn strip_non_digits(&self) -> String
Remove all characters that are not numerals for later string comparison. Does not use a regular expression
source§fn correct_numeric_string(&self, enforce_comma_separator: bool) -> String
fn correct_numeric_string(&self, enforce_comma_separator: bool) -> String
Correct numeric strings with commas as thousand separators or as decimal separators to a regular format with punctuation only for decimal points before being parsed to an integer or float This is best used only with numeric strings as it will strip commas and dots not used as decimal separators
source§fn to_numeric_strings_conditional(
&self,
enforce_comma_separator: bool
) -> Vec<String>
fn to_numeric_strings_conditional( &self, enforce_comma_separator: bool ) -> Vec<String>
conditionally extract numeric strings from a longer string