pub struct TitlecaseMapper<CM> { /* private fields */ }
Expand description
A wrapper around CaseMapper
that can compute titlecasing stuff, and is able to load additional data
to support the non-legacy “head adjustment” behavior.
Most methods for this type live on TitlecaseMapperBorrowed
, which you can obtain via
TitlecaseMapper::new()
or TitlecaseMapper::as_borrowed()
.
By default, TitlecaseMapperBorrowed::titlecase_segment()
and TitlecaseMapperBorrowed::titlecase_segment_to_string()
perform “leading adjustment”,
where they wait till the first relevant character to begin titlecasing. For example, in the string 'twixt
, the apostrophe
is ignored because the word starts at the first “t”, which will get titlecased (producing 'Twixt
). Other punctuation will
also be ignored, like in the string «hello»
, which will get titlecased to «Hello»
.
This is a separate type from CaseMapper
because it loads the additional data
required by LeadingAdjustment::Auto
to perform the best possible leading adjustment.
If you are planning on only using LeadingAdjustment::None
or LeadingAdjustment::ToCased
, consider using CaseMapper
directly; this
type will have no additional behavior.
§Examples
Basic casemapping behavior:
use icu::casemap::TitlecaseMapper;
use icu::locale::langid;
let cm = TitlecaseMapper::new();
let root = langid!("und");
let default_options = Default::default();
// note that the subsequent words are not titlecased, this function assumes
// that the entire string is a single segment and only titlecases at the beginning.
assert_eq!(cm.titlecase_segment_to_string("hEllO WorLd", &root, default_options), "Hello world");
assert_eq!(cm.titlecase_segment_to_string("Γειά σου Κόσμε", &root, default_options), "Γειά σου κόσμε");
assert_eq!(cm.titlecase_segment_to_string("नमस्ते दुनिया", &root, default_options), "नमस्ते दुनिया");
assert_eq!(cm.titlecase_segment_to_string("Привет мир", &root, default_options), "Привет мир");
// Some behavior is language-sensitive
assert_eq!(cm.titlecase_segment_to_string("istanbul", &root, default_options), "Istanbul");
assert_eq!(cm.titlecase_segment_to_string("istanbul", &langid!("tr"), default_options), "İstanbul"); // Turkish dotted i
assert_eq!(cm.titlecase_segment_to_string("և Երևանի", &root, default_options), "Եւ երևանի");
assert_eq!(cm.titlecase_segment_to_string("և Երևանի", &langid!("hy"), default_options), "Եվ երևանի"); // Eastern Armenian ech-yiwn ligature
assert_eq!(cm.titlecase_segment_to_string("ijkdijk", &root, default_options), "Ijkdijk");
assert_eq!(cm.titlecase_segment_to_string("ijkdijk", &langid!("nl"), default_options), "IJkdijk"); // Dutch IJ digraph
Implementations§
Source§impl TitlecaseMapper<CaseMapper>
impl TitlecaseMapper<CaseMapper>
Sourcepub fn try_new_with_buffer_provider(
provider: &(impl BufferProvider + ?Sized),
) -> Result<Self, DataError>
pub fn try_new_with_buffer_provider( provider: &(impl BufferProvider + ?Sized), ) -> Result<Self, DataError>
A version of [Self :: new
] that uses custom data provided by a BufferProvider
.
✨ Enabled with the serde
feature.
Sourcepub fn try_new_unstable<P>(provider: &P) -> Result<Self, DataError>
pub fn try_new_unstable<P>(provider: &P) -> Result<Self, DataError>
A version of Self::new
that uses custom data provided by a DataProvider
.
Source§impl TitlecaseMapper<CaseMapper>
impl TitlecaseMapper<CaseMapper>
Sourcepub const fn new() -> TitlecaseMapperBorrowed<'static>
pub const fn new() -> TitlecaseMapperBorrowed<'static>
A constructor which creates a TitlecaseMapperBorrowed
using compiled data
✨ Enabled with the compiled_data
Cargo feature.
Source§impl<CM: AsRef<CaseMapper>> TitlecaseMapper<CM>
impl<CM: AsRef<CaseMapper>> TitlecaseMapper<CM>
Sourcepub fn try_new_with_mapper_with_buffer_provider(
provider: &(impl BufferProvider + ?Sized),
casemapper: CM,
) -> Result<Self, DataError>
pub fn try_new_with_mapper_with_buffer_provider( provider: &(impl BufferProvider + ?Sized), casemapper: CM, ) -> Result<Self, DataError>
A version of [Self :: new_with_mapper
] that uses custom data provided by a BufferProvider
.
✨ Enabled with the serde
feature.
Sourcepub const fn new_with_mapper(casemapper: CM) -> Self
pub const fn new_with_mapper(casemapper: CM) -> Self
A constructor which creates a TitlecaseMapper
from an existing CaseMapper
(either owned or as a reference) and compiled data
✨ Enabled with the compiled_data
Cargo feature.
Sourcepub fn try_new_with_mapper_unstable<P>(
provider: &P,
casemapper: CM,
) -> Result<Self, DataError>
pub fn try_new_with_mapper_unstable<P>( provider: &P, casemapper: CM, ) -> Result<Self, DataError>
Construct this object to wrap an existing CaseMapper (or a reference to one), loading additional data as needed.
A version of Self::new_with_mapper
that uses custom data provided by a DataProvider
.
Sourcepub fn as_borrowed(&self) -> TitlecaseMapperBorrowed<'_>
pub fn as_borrowed(&self) -> TitlecaseMapperBorrowed<'_>
Constructs a borrowed version of this type for more efficient querying.
Trait Implementations§
Source§impl<CM: Clone> Clone for TitlecaseMapper<CM>
impl<CM: Clone> Clone for TitlecaseMapper<CM>
Source§fn clone(&self) -> TitlecaseMapper<CM>
fn clone(&self) -> TitlecaseMapper<CM>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl<CM> Freeze for TitlecaseMapper<CM>where
CM: Freeze,
impl<CM> RefUnwindSafe for TitlecaseMapper<CM>where
CM: RefUnwindSafe,
impl<CM> Send for TitlecaseMapper<CM>where
CM: Send,
impl<CM> Sync for TitlecaseMapper<CM>where
CM: Sync,
impl<CM> Unpin for TitlecaseMapper<CM>where
CM: Unpin,
impl<CM> UnwindSafe for TitlecaseMapper<CM>where
CM: UnwindSafe,
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§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