pub struct TitlecaseMapperBorrowed<'a> { /* private fields */ }
Expand description
A borrowed TitlecaseMapper
.
See methods or TitlecaseMapper
for examples.
Implementations§
Source§impl TitlecaseMapperBorrowed<'static>
impl TitlecaseMapperBorrowed<'static>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
A constructor which creates a TitlecaseMapperBorrowed
using compiled data
✨ Enabled with the compiled_data
Cargo feature.
Sourcepub const fn static_to_owned(self) -> TitlecaseMapper<CaseMapper>
pub const fn static_to_owned(self) -> TitlecaseMapper<CaseMapper>
Cheaply converts a [TitlecaseMapperBorrowed<'static>
] into a TitlecaseMapper
.
Note: Due to branching and indirection, using TitlecaseMapper
might inhibit some
compile-time optimizations that are possible with TitlecaseMapper
.
Source§impl<'a> TitlecaseMapperBorrowed<'a>
impl<'a> TitlecaseMapperBorrowed<'a>
Sourcepub fn titlecase_segment(
self,
src: &'a str,
langid: &LanguageIdentifier,
options: TitlecaseOptions,
) -> impl Writeable + 'a
pub fn titlecase_segment( self, src: &'a str, langid: &LanguageIdentifier, options: TitlecaseOptions, ) -> impl Writeable + 'a
Returns the full titlecase mapping of the given string as a [Writeable
], treating
the string as a single segment (and thus only titlecasing the beginning of it).
This should typically be used as a lower-level helper to construct the titlecasing operation desired
by the application, for example one can titlecase on a per-word basis by mixing this with
a WordSegmenter
.
This function is context and language sensitive. Callers should pass the text’s language
as a LanguageIdentifier
(usually the id
field of the Locale
) if available, or
Default::default()
for the root locale.
See TitlecaseMapperBorrowed::titlecase_segment_to_string()
for the equivalent convenience function that returns a String,
as well as for an example.
Sourcepub fn titlecase_segment_to_string(
self,
src: &str,
langid: &LanguageIdentifier,
options: TitlecaseOptions,
) -> String
pub fn titlecase_segment_to_string( self, src: &str, langid: &LanguageIdentifier, options: TitlecaseOptions, ) -> String
Returns the full titlecase mapping of the given string as a String, treating the string as a single segment (and thus only titlecasing the beginning of it).
This should typically be used as a lower-level helper to construct the titlecasing operation desired
by the application, for example one can titlecase on a per-word basis by mixing this with
a WordSegmenter
.
This function is context and language sensitive. Callers should pass the text’s language
as a LanguageIdentifier
(usually the id
field of the Locale
) if available, or
Default::default()
for the root locale.
See TitlecaseMapperBorrowed::titlecase_segment()
for the equivalent lower-level function that returns a [Writeable
]
§Examples
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
Leading adjustment behaviors:
use icu::casemap::options::{LeadingAdjustment, TitlecaseOptions};
use icu::casemap::TitlecaseMapper;
use icu::locale::langid;
let cm = TitlecaseMapper::new();
let root = langid!("und");
let default_options = Default::default();
let mut no_adjust: TitlecaseOptions = Default::default();
no_adjust.leading_adjustment = Some(LeadingAdjustment::None);
// 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, no_adjust),
"«hello»"
);
assert_eq!(
cm.titlecase_segment_to_string("'Twas", &root, default_options),
"'Twas"
);
assert_eq!(
cm.titlecase_segment_to_string("'Twas", &root, no_adjust),
"'twas"
);
assert_eq!(
cm.titlecase_segment_to_string("", &root, default_options),
""
);
assert_eq!(cm.titlecase_segment_to_string("", &root, no_adjust), "");
Tail casing behaviors:
use icu::casemap::options::{TitlecaseOptions, TrailingCase};
use icu::casemap::TitlecaseMapper;
use icu::locale::langid;
let cm = TitlecaseMapper::new();
let root = langid!("und");
let default_options = Default::default();
let mut preserve_case: TitlecaseOptions = Default::default();
preserve_case.trailing_case = Some(TrailingCase::Unchanged);
// Exhibits trailing case when set:
assert_eq!(
cm.titlecase_segment_to_string("spOngeBoB", &root, default_options),
"Spongebob"
);
assert_eq!(
cm.titlecase_segment_to_string("spOngeBoB", &root, preserve_case),
"SpOngeBoB"
);
Trait Implementations§
Source§impl<'a> Clone for TitlecaseMapperBorrowed<'a>
impl<'a> Clone for TitlecaseMapperBorrowed<'a>
Source§fn clone(&self) -> TitlecaseMapperBorrowed<'a>
fn clone(&self) -> TitlecaseMapperBorrowed<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<'a> Debug for TitlecaseMapperBorrowed<'a>
impl<'a> Debug for TitlecaseMapperBorrowed<'a>
Source§impl Default for TitlecaseMapperBorrowed<'static>
impl Default for TitlecaseMapperBorrowed<'static>
impl<'a> Copy for TitlecaseMapperBorrowed<'a>
Auto Trait Implementations§
impl<'a> Freeze for TitlecaseMapperBorrowed<'a>
impl<'a> RefUnwindSafe for TitlecaseMapperBorrowed<'a>
impl<'a> Send for TitlecaseMapperBorrowed<'a>
impl<'a> Sync for TitlecaseMapperBorrowed<'a>
impl<'a> Unpin for TitlecaseMapperBorrowed<'a>
impl<'a> UnwindSafe for TitlecaseMapperBorrowed<'a>
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