Trait rust_locale::ctype::CType
source · [−]pub trait CType {
fn is_space(&self) -> bool;
fn is_blank(&self) -> bool;
fn to_uppercase(&self) -> Self;
fn to_lowercase(&self) -> Self;
}
Required Methods
Returns true
if self
is a whitespace character.
Whitespace characters are:
- space (0x20), form feed (0x0c), line feed (0x0a), carriage return (0x0d), horizontal tab (0x09), vertical tab (0x0b)
- whitespace characters specific to the current locale
examples
use rust_locale::CType;
assert!(' '.is_space());
assert!(!'a'.is_space());
std::env::set_var("LC_ALL", "POSIX");
assert!(!'\u{2003}'.is_space());
std::env::set_var("LC_ALL", "en_US");
assert!('\u{2003}'.is_space());
Checks if self
is classified as blank character (that is, a whitespace character used to separate words in a sentence) by the current locale.
examples
use rust_locale::CType;
assert!(' '.is_blank());
assert!(!'\n'.is_blank());
std::env::set_var("LC_ALL", "POSIX");
assert!(!'\u{3000}'.is_blank());
std::env::set_var("LC_ALL", "en_US");
assert!('\u{3000}'.is_blank());
fn to_uppercase(&self) -> Self
fn to_uppercase(&self) -> Self
Converts self
to uppercase listed in the current locale.
If no uppercase version is listed in the current locale, returns unmodified self
.
Only 1:1 character mapping can be performed by this function, e.g. the uppercase form of ‘ß’ is (with some exceptions) the two-character string “SS”, which cannot be obtained.
examples
use rust_locale::CType;
assert_eq!(CType::to_uppercase(&'a'), 'A');
assert_eq!(CType::to_uppercase(&'1'), '1');
std::env::set_var("LC_ALL", "POSIX");
assert_eq!(CType::to_uppercase(&'\u{017F}'), '\u{017F}');
std::env::set_var("LC_ALL", "en_US");
assert_eq!(CType::to_uppercase(&'\u{017F}'), 'S');
fn to_lowercase(&self) -> Self
fn to_lowercase(&self) -> Self
Converts self
to lowercase, if possible.
If no lowercase version is listed in the current locale, returns unmodified self
.
Only 1:1 character mapping can be performed by this function, e.g. the Greek uppercase letter ‘Σ’ has two lowercase forms, depending on the position in a word: ‘σ’ and ‘ς’. A call to this method cannot be used to obtain the correct lowercase form in this case.
examples
use rust_locale::CType;
assert_eq!(CType::to_lowercase(&'A'), 'a');
assert_eq!(CType::to_lowercase(&'1'), '1');
std::env::set_var("LC_ALL", "POSIX");
assert_eq!(CType::to_lowercase(&'\u{0190}'), '\u{0190}');
std::env::set_var("LC_ALL", "en_US");
assert_eq!(CType::to_lowercase(&'\u{0190}'), '\u{025b}');