pub trait StripCharacters<'a>where
Self: ToSegments,{
Show 18 methods
// Required methods
fn strip_non_alphanum(&self) -> String;
fn strip_non_digits(&self) -> String;
fn strip_by_type(&self, ct: CharType<'a>) -> String;
fn strip_by_types(&self, cts: &[CharType<'a>]) -> String;
fn filter_by_type(&self, ct: CharType<'a>) -> String;
fn filter_by_types(&self, cts: &[CharType<'a>]) -> 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;
// Provided methods
fn strip_spaces(&self) -> String { ... }
fn to_numeric_strings(&self) -> Vec<String> { ... }
fn to_numeric_strings_euro(&self) -> Vec<String> { ... }
fn to_numbers<T: FromStr>(&self) -> Vec<T> { ... }
fn to_numbers_euro<T: FromStr>(&self) -> Vec<T> { ... }
fn split_to_numbers<T: FromStr + Copy>(&self, pattern: &str) -> Vec<T> { ... }
fn to_first_number<T: FromStr + Copy>(&self) -> Option<T> { ... }
fn to_first_number_euro<T: FromStr + Copy>(&self) -> Option<T> { ... }
fn strip_non_numeric(&self) -> String { ... }
}
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 symbols Letters include those used in most non-Latin alphabets
fn strip_non_digits(&self) -> String
Sourcefn strip_by_type(&self, ct: CharType<'a>) -> String
fn strip_by_type(&self, ct: CharType<'a>) -> String
Remove characters in the specified character category/range
Sourcefn strip_by_types(&self, cts: &[CharType<'a>]) -> String
fn strip_by_types(&self, cts: &[CharType<'a>]) -> String
Remove characters in the specified range or type. Lets you exclude by a set of character types (as an array)
Sourcefn filter_by_type(&self, ct: CharType<'a>) -> String
fn filter_by_type(&self, ct: CharType<'a>) -> String
Return only characters in the specified range or type
Sourcefn filter_by_types(&self, cts: &[CharType<'a>]) -> String
fn filter_by_types(&self, cts: &[CharType<'a>]) -> String
Filter characters in the specified range or type. Lets you filter by a set of character types (as an array)
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
Provided Methods§
fn strip_spaces(&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
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 split_to_numbers<T: FromStr + Copy>(&self, pattern: &str) -> Vec<T>
fn split_to_numbers<T: FromStr + Copy>(&self, pattern: &str) -> Vec<T>
Split a string on a separator and retunr a vector of all segments that may parsed as numbers This may fail with to_numbers() as the separator may be decimal or thousand separator
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
Sourcefn strip_non_numeric(&self) -> String
fn strip_non_numeric(&self) -> String
Removes all characters not used in valid numeric sequences with single spaces between numbers
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl<'a> StripCharacters<'a> for str
impl<'a> StripCharacters<'a> 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 Will remove all spaces separating words
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 Will remove all spaces separating numbers Use strip_non_numeric to extract a string with valid numbers only separated by spaces
Source§fn strip_by_type(&self, ct: CharType<'a>) -> String
fn strip_by_type(&self, ct: CharType<'a>) -> String
remove all characters in the specified category or range
Source§fn strip_by_types(&self, cts: &[CharType<'a>]) -> String
fn strip_by_types(&self, cts: &[CharType<'a>]) -> String
remove all characters in the specified set of categories or ranges
Source§fn filter_by_type(&self, ct: CharType<'a>) -> String
fn filter_by_type(&self, ct: CharType<'a>) -> String
Filter all characters in the specified category or range
Source§fn filter_by_types(&self, cts: &[CharType<'a>]) -> String
fn filter_by_types(&self, cts: &[CharType<'a>]) -> String
Filter all characters in the specified set of categories or ranges
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