Struct icu_locale_canonicalizer::locale_canonicalizer::LocaleCanonicalizer [−][src]
pub struct LocaleCanonicalizer<'a> { /* fields omitted */ }
Implementations
impl LocaleCanonicalizer<'_>
[src]
impl LocaleCanonicalizer<'_>
[src]pub fn new<'d>(
provider: &impl DataProvider<'d, LikelySubtagsV1> + ?Sized
) -> Result<LocaleCanonicalizer<'d>, DataError>
[src]
provider: &impl DataProvider<'d, LikelySubtagsV1> + ?Sized
) -> Result<LocaleCanonicalizer<'d>, DataError>
A constructor which takes a DataProvider
and creates a LocaleCanonicalizer
.
pub fn maximize<T: AsMut<LanguageIdentifier>>(
&self,
langid: T
) -> CanonicalizationResult
[src]
&self,
langid: T
) -> CanonicalizationResult
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]
&self,
langid: T
) -> CanonicalizationResult
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> RefUnwindSafe for LocaleCanonicalizer<'a>
impl<'a> Send for LocaleCanonicalizer<'a>
impl<'a> Send for LocaleCanonicalizer<'a>
impl<'a> Sync for LocaleCanonicalizer<'a>
impl<'a> Sync for LocaleCanonicalizer<'a>
impl<'a> Unpin for LocaleCanonicalizer<'a>
impl<'a> Unpin for LocaleCanonicalizer<'a>
impl<'a> UnwindSafe for LocaleCanonicalizer<'a>
impl<'a> UnwindSafe for LocaleCanonicalizer<'a>