icu_casemap

Struct TitlecaseMapperBorrowed

Source
pub struct TitlecaseMapperBorrowed<'a> { /* private fields */ }
Expand description

A borrowed TitlecaseMapper.

See methods or TitlecaseMapper for examples.

Implementations§

Source§

impl TitlecaseMapperBorrowed<'static>

Source

pub const fn new() -> Self

A constructor which creates a TitlecaseMapperBorrowed using compiled data

Enabled with the compiled_data Cargo feature.

📚 Help choosing a constructor

Source

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>

Source

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.

Source

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>

Source§

fn clone(&self) -> TitlecaseMapperBorrowed<'a>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for TitlecaseMapperBorrowed<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TitlecaseMapperBorrowed<'static>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a> Copy for TitlecaseMapperBorrowed<'a>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> ErasedDestructor for T
where T: 'static,