Enum icu::casemap::titlecase::LeadingAdjustment
source · #[non_exhaustive]pub enum LeadingAdjustment {
None,
Auto,
ToCased,
}
Expand description
Where to start casing the string.
TitlecaseMapper
by default performs “leading adjustment”, where it searches for the first “relevant” character
in the string before initializing the actual titlecasing. For example, it will skip punctuation at the beginning
of a string, allowing for strings like 'twas
or «hello»
to be appropriately titlecased.
Opinions on exactly what is a “relevant” character may differ. In “adjust to cased” mode the first cased character is considered “relevant”,
whereas in the “auto” mode, it is the first character that is a letter, number, symbol, or private use character. This means
that the strings 49ers
and «丰(abc)»
will titlecase in “adjust to cased” mode to 49Ers
and «丰(Abc)»
, whereas in the “auto” mode they stay unchanged.
This difference largely matters for things that mix numbers and letters, or mix writing systems, within a single segment.
§Examples
use icu::casemap::titlecase::{LeadingAdjustment, TitlecaseOptions};
use icu::casemap::TitlecaseMapper;
use icu::locale::langid;
let cm = TitlecaseMapper::new();
let root = langid!("und");
let default_options = Default::default(); // head adjustment set to Auto
let mut no_adjust: TitlecaseOptions = Default::default();
let mut adjust_to_cased: TitlecaseOptions = Default::default();
no_adjust.leading_adjustment = LeadingAdjustment::None;
adjust_to_cased.leading_adjustment = LeadingAdjustment::ToCased;
// Exhibits leading adjustment when set:
assert_eq!(
cm.titlecase_segment_to_string("«hello»", &root, default_options),
"«Hello»"
);
assert_eq!(
cm.titlecase_segment_to_string("«hello»", &root, adjust_to_cased),
"«Hello»"
);
assert_eq!(
cm.titlecase_segment_to_string("«hello»", &root, no_adjust),
"«hello»"
);
// Only changed in adjust-to-cased mode:
assert_eq!(
cm.titlecase_segment_to_string("丰(abc)", &root, default_options),
"丰(abc)"
);
assert_eq!(
cm.titlecase_segment_to_string("丰(abc)", &root, adjust_to_cased),
"丰(Abc)"
);
assert_eq!(
cm.titlecase_segment_to_string("丰(abc)", &root, no_adjust),
"丰(abc)"
);
// Only changed in adjust-to-cased mode:
assert_eq!(
cm.titlecase_segment_to_string("49ers", &root, default_options),
"49ers"
);
assert_eq!(
cm.titlecase_segment_to_string("49ers", &root, adjust_to_cased),
"49Ers"
);
assert_eq!(
cm.titlecase_segment_to_string("49ers", &root, no_adjust),
"49ers"
);
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
None
Start titlecasing immediately, even if the character is not one that is relevant for casing (“’twixt” -> “’twixt”, “twixt” -> “Twixt”)
Auto
Adjust the string to the first relevant character before beginning to apply casing
(“’twixt” -> “’Twixt”). “Relevant” character is picked by best available algorithm,
by default will adjust to first letter, number, symbol, or private use character,
but if no data is available (e.g. this API is being called via CaseMapper::titlecase_segment_with_only_case_data()
),
then may be equivalent to “adjust to cased”.
This is the default
ToCased
Adjust the string to the first cased character before beginning to apply casing (“’twixt” -> “’Twixt”)
Trait Implementations§
source§impl Clone for LeadingAdjustment
impl Clone for LeadingAdjustment
source§fn clone(&self) -> LeadingAdjustment
fn clone(&self) -> LeadingAdjustment
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for LeadingAdjustment
impl Debug for LeadingAdjustment
source§impl Default for LeadingAdjustment
impl Default for LeadingAdjustment
source§fn default() -> LeadingAdjustment
fn default() -> LeadingAdjustment
source§impl Hash for LeadingAdjustment
impl Hash for LeadingAdjustment
source§impl PartialEq for LeadingAdjustment
impl PartialEq for LeadingAdjustment
impl Copy for LeadingAdjustment
impl Eq for LeadingAdjustment
impl StructuralPartialEq for LeadingAdjustment
Auto Trait Implementations§
impl Freeze for LeadingAdjustment
impl RefUnwindSafe for LeadingAdjustment
impl Send for LeadingAdjustment
impl Sync for LeadingAdjustment
impl Unpin for LeadingAdjustment
impl UnwindSafe for LeadingAdjustment
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more