Struct icu_locale_canonicalizer::locale_canonicalizer::LocaleCanonicalizer[][src]

pub struct LocaleCanonicalizer<'a> { /* fields omitted */ }

Implementations

impl LocaleCanonicalizer<'_>[src]

pub fn new<'d>(
    provider: &impl DataProvider<'d, LikelySubtagsV1> + ?Sized
) -> Result<LocaleCanonicalizer<'d>, DataError>
[src]

A constructor which takes a DataProvider and creates a LocaleCanonicalizer.

pub fn maximize<T: AsMut<LanguageIdentifier>>(
    &self,
    langid: T
) -> CanonicalizationResult
[src]

The maximize method potentially updates a passed in locale in place depending up the results of running the ‘Add Likely Subtags’ algorithm from https://www.unicode.org/reports/tr35/#Likely_Subtags.

If the result of running the algorithm would result in a new locale, the locale argument is updated in place to match the result, and the method returns CanonicalizationResult::Modified. Otherwise, the method returns CanonicalizationResult::Unmodified and the locale argument is unchanged.

Examples

use icu_locale_canonicalizer::{CanonicalizationResult, LocaleCanonicalizer};
use icu_locid::Locale;

let provider = icu_testdata::get_provider();
let lc = LocaleCanonicalizer::new(&provider)
    .expect("create failed");

let mut locale : Locale = "zh-CN".parse()
    .expect("parse failed");
assert_eq!(lc.maximize(&mut locale), CanonicalizationResult::Modified);
assert_eq!(locale.to_string(), "zh-Hans-CN");

let mut locale : Locale = "zh-Hant-TW".parse()
    .expect("parse failed");
assert_eq!(lc.maximize(&mut locale), CanonicalizationResult::Unmodified);
assert_eq!(locale.to_string(), "zh-Hant-TW");

pub fn minimize<T: AsMut<LanguageIdentifier>>(
    &self,
    langid: T
) -> CanonicalizationResult
[src]

This returns a new Locale that is the result of running the ‘Remove Likely Subtags’ algorithm from https://www.unicode.org/reports/tr35/#Likely_Subtags.

If the result of running the algorithm would result in a new locale, the locale argument is updated in place to match the result, and the method returns CanonicalizationResult::Modified. Otherwise, the method returns CanonicalizationResult::Unmodified and the locale argument is unchanged.

Examples

use icu_locale_canonicalizer::{CanonicalizationResult, LocaleCanonicalizer};
use icu_locid::Locale;

let provider = icu_testdata::get_provider();
let lc = LocaleCanonicalizer::new(&provider)
    .expect("creation failed");

let mut locale : Locale = "zh-Hans-CN".parse()
    .expect("parse failed");
assert_eq!(lc.minimize(&mut locale), CanonicalizationResult::Modified);
assert_eq!(locale.to_string(), "zh");

let mut locale : Locale = "zh".parse()
    .expect("parse failed");
assert_eq!(lc.minimize(&mut locale), CanonicalizationResult::Unmodified);
assert_eq!(locale.to_string(), "zh");

Auto Trait Implementations

impl<'a> RefUnwindSafe for LocaleCanonicalizer<'a>

impl<'a> Send for LocaleCanonicalizer<'a>

impl<'a> Sync for LocaleCanonicalizer<'a>

impl<'a> Unpin for LocaleCanonicalizer<'a>

impl<'a> UnwindSafe for LocaleCanonicalizer<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.