StrTitleCase

Trait StrTitleCase 

Source
pub trait StrTitleCase {
    // Required methods
    fn to_titlecase(&self) -> String;
    fn to_titlecase_lower_rest(&self) -> String;
    fn to_titlecase_tr_or_az(&self) -> String;
    fn to_titlecase_tr_or_az_lower_rest(&self) -> String;
    fn starts_titlecase(&self) -> bool;
    fn starts_titlecase_rest_lower(&self) -> bool;
}
Expand description

Trait to add titlecase operations to Strings and string slices. Both locale agnostic and TR/AZ versions of the functions are supplied.

Required Methods§

Source

fn to_titlecase(&self) -> String

Titlecases the first char of a string, leaves the rest unchanged, and returns a copy.

§Examples

If the str is already titlecase then it will return itself

use unicode_titlecase::StrTitleCase;
assert_eq!("ABC".to_titlecase(), "ABC")

Single-char characters are mapped:

use unicode_titlecase::StrTitleCase;
assert_eq!("DŽDŽ".to_titlecase(), "DžDŽ")

Multi-char ligatures are converted:

use unicode_titlecase::StrTitleCase;
assert_eq!("fflabc".to_titlecase(), "Fflabc")

Locale is ignored:

use unicode_titlecase::StrTitleCase;
assert_eq!("iii".to_titlecase(), "Iii")
§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 StrTitleCase::to_titlecase_tr_or_az

Source

fn to_titlecase_lower_rest(&self) -> String

Titlecases the first char of a string, lowercases the rest of the string, and returns a copy.

§Examples

If the str is already titlecase then it will return itself

use unicode_titlecase::StrTitleCase;
assert_eq!("ABC".to_titlecase_lower_rest(), "Abc")

Single-char characters are mapped:

use unicode_titlecase::StrTitleCase;
assert_eq!("DŽDŽ".to_titlecase_lower_rest(), "Dždž")

Multi-char ligatures are converted:

use unicode_titlecase::StrTitleCase;
assert_eq!("fflabc".to_titlecase_lower_rest(), "Fflabc")

Locale is ignored:

use unicode_titlecase::StrTitleCase;
assert_eq!("iIi".to_titlecase_lower_rest(), "Iii")
§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 StrTitleCase::to_titlecase_tr_or_az_lower_rest

Source

fn to_titlecase_tr_or_az(&self) -> String

This functions the same way as StrTitleCase::to_titlecase except that it uses the TR/AZ locales. This has one major change:

use unicode_titlecase::StrTitleCase;
assert_eq!("iIi".to_titlecase_tr_or_az(), "İIi")

For the locale agnostic version use StrTitleCase::to_titlecase.

Source

fn to_titlecase_tr_or_az_lower_rest(&self) -> String

This functions the same way as StrTitleCase::to_titlecase_lower_rest except that it uses the TR/AZ locales. This has one major change, ‘i’ maps to ‘İ’:

use unicode_titlecase::StrTitleCase;
assert_eq!("iIiİ".to_titlecase_tr_or_az_lower_rest(), "İıii")

When lowercasing in these locales there are a couple differences to note:

  1. ‘I’ maps to ‘ı’–\u{0049} LATIN CAPITAL LETTER I -> \u{0131} LATIN SMALL LETTER DOTLESS I
  2. ‘İ’ maps to ‘i’–\u{130} LATIN CAPITAL LETTER I WITH DOT ABOVE -> \u{0069} LATIN SMALL LETTER I

For the locale agnostic version use StrTitleCase::to_titlecase_lower_rest.

Source

fn starts_titlecase(&self) -> bool

Tests if the first char of this string is titlecase. This is locale agnostic and returns the same values in the tr/az locales.

§Returns

True if the first character of the string is title case, ignoring the rest of the string. False if first character is not title case or the string is empty.

§Examples
use unicode_titlecase::StrTitleCase;
assert!("Abc".starts_titlecase());
assert!("ABC".starts_titlecase());

assert!(!"abc".starts_titlecase());
Source

fn starts_titlecase_rest_lower(&self) -> bool

Tests if the first char of this string is titlecase and the rest of the string is lowercase. This is locale agnostic and returns the same values in the tr/az locales.

§Returns

True if the first character of the string is title case and the rest of the string is lowercase. False if first character is not title case or the string is empty.

§Examples
use unicode_titlecase::StrTitleCase;
assert!("Abc".starts_titlecase_rest_lower());
assert!("İbc".starts_titlecase_rest_lower());

assert!(!"abc".starts_titlecase_rest_lower());
assert!(!"ABC".starts_titlecase_rest_lower());
assert!(!"İİ".starts_titlecase_rest_lower());

Implementations on Foreign Types§

Source§

impl StrTitleCase for str

Implementors§