TitleCase

Trait TitleCase 

Source
pub trait TitleCase {
    // Required methods
    fn to_titlecase(self) -> ToTitleCase ;
    fn to_titlecase_tr_or_az(self) -> ToTitleCase ;
    fn is_titlecase(&self) -> bool;
}
Expand description

This trait adds title case methods to char. They function the same as the std library’s char::to_lowercase and char::to_uppercase using a custom ToTitleCase iterator.

Required Methods§

Source

fn to_titlecase(self) -> ToTitleCase

Wraps to_titlecase in an iterator. The iterator will yield at most 3 chars.

§Examples

If the character is already titlecase then it will return itself

use unicode_titlecase::TitleCase;
assert_eq!('A'.to_titlecase().to_string(), "A")

Single-char characters are mapped:

use unicode_titlecase::TitleCase;
assert_eq!('DŽ'.to_titlecase().to_string(), "Dž")

Multi-char ligatures are converted:

use unicode_titlecase::TitleCase;
assert_eq!('ffl'.to_titlecase().to_string(), "Ffl")

Locale is ignored:

use unicode_titlecase::TitleCase;
assert_eq!('i'.to_titlecase().to_string(), "I")
§Locale

This function is not locale specific. Unicode special casing has rules for tr and az that this function does not take into account. For tr and az locales use TitleCase::to_titlecase_tr_or_az

Source

fn to_titlecase_tr_or_az(self) -> ToTitleCase

Wraps to_titlecase_tr_or_az in an iterator. The iterator will yield at most 3 chars.

§Examples

If the character is already titlecase then it will return itself

use unicode_titlecase::TitleCase;
assert_eq!('A'.to_titlecase_tr_or_az().to_string(), "A")

Single-char characters are mapped:

use unicode_titlecase::TitleCase;
assert_eq!('DŽ'.to_titlecase_tr_or_az().to_string(), "Dž")

Multi-char ligatures are converted:

use unicode_titlecase::TitleCase;
assert_eq!('ffl'.to_titlecase_tr_or_az().to_string(), "Ffl")

Locale is tr/az:

use unicode_titlecase::TitleCase;
assert_eq!('i'.to_titlecase_tr_or_az().to_string(), "İ")
§Locale

This function is specific to the tr and az locales. It returns different results for certain chars. To use locale agnostic version see TitleCase::to_titlecase.

Source

fn is_titlecase(&self) -> bool

Returns true if the given character is a titlecase character. This function works for all locales including tr and az.

§Examples
use unicode_titlecase::TitleCase;
assert!('A'.is_titlecase());
assert!('Dž'.is_titlecase());
assert!('İ'.is_titlecase());

assert!(!'a'.is_titlecase());
assert!(!'DŽ'.is_titlecase());
assert!(!'ffl'.is_titlecase());

Implementations on Foreign Types§

Source§

impl TitleCase for char

Implementors§