Struct icu::locid_transform::LocaleCanonicalizer
source · [−]pub struct LocaleCanonicalizer { /* private fields */ }
Expand description
The LocaleCanonicalizer provides methods to canonicalize Locales and
LanguageIdentifiers based upon CLDR
data.
It currently supports locale canonicalization based upon the canonicalization
algorithm from UTS #35: Unicode LDML 3. LocaleId Canonicalization
.
Examples
use icu_locid::Locale;
use icu_locid_transform::{LocaleCanonicalizer, TransformResult};
let lc = LocaleCanonicalizer::try_new_unstable(&icu_testdata::unstable())
.expect("create failed");
let mut locale: Locale = "ja-Latn-fonipa-hepburn-heploc".parse().unwrap();
assert_eq!(lc.canonicalize(&mut locale), TransformResult::Modified);
assert_eq!(locale, "ja-Latn-alalc97-fonipa".parse().unwrap());
Implementations
sourceimpl LocaleCanonicalizer
impl LocaleCanonicalizer
sourcepub fn try_new_unstable<P>(
provider: &P
) -> Result<LocaleCanonicalizer, LocaleTransformError> where
P: DataProvider<AliasesV1Marker> + DataProvider<LikelySubtagsV1Marker> + ?Sized,
pub fn try_new_unstable<P>(
provider: &P
) -> Result<LocaleCanonicalizer, LocaleTransformError> where
P: DataProvider<AliasesV1Marker> + DataProvider<LikelySubtagsV1Marker> + ?Sized,
A constructor which takes a DataProvider
and creates a LocaleCanonicalizer
.
sourcepub fn try_new_with_any_provider(
provider: &impl AnyProvider
) -> Result<LocaleCanonicalizer, LocaleTransformError>
pub fn try_new_with_any_provider(
provider: &impl AnyProvider
) -> Result<LocaleCanonicalizer, LocaleTransformError>
Creates a new instance using an AnyProvider
.
For details on the behavior of this function, see: Self::try_new_unstable
sourcepub fn try_new_with_buffer_provider(
provider: &impl BufferProvider
) -> Result<LocaleCanonicalizer, LocaleTransformError>
pub fn try_new_with_buffer_provider(
provider: &impl BufferProvider
) -> Result<LocaleCanonicalizer, LocaleTransformError>
✨ Enabled with the "serde"
feature.
Creates a new instance using a BufferProvider
.
For details on the behavior of this function, see: Self::try_new_unstable
sourcepub fn canonicalize(&self, locale: &mut Locale) -> TransformResult
pub fn canonicalize(&self, locale: &mut Locale) -> TransformResult
The canonicalize method potentially updates a passed in locale in place depending up the results of running the canonicalization algorithm from http://unicode.org/reports/tr35/#LocaleId_Canonicalization.
Some BCP47 canonicalization data is not part of the CLDR json package. Because
of this, some canonicalizations are not performed, e.g. the canonicalization of
und-u-ca-islamicc
to und-u-ca-islamic-civil
. This will be fixed in a future
release once the missing data has been added to the CLDR json data.
Examples
use icu_locid::Locale;
use icu_locid_transform::{LocaleCanonicalizer, TransformResult};
let lc = LocaleCanonicalizer::try_new_unstable(&icu_testdata::unstable())
.expect("create failed");
let mut locale: Locale = "ja-Latn-fonipa-hepburn-heploc".parse().unwrap();
assert_eq!(lc.canonicalize(&mut locale), TransformResult::Modified);
assert_eq!(locale, "ja-Latn-alalc97-fonipa".parse().unwrap());
Auto Trait Implementations
impl RefUnwindSafe for LocaleCanonicalizer
impl Send for LocaleCanonicalizer
impl Sync for LocaleCanonicalizer
impl Unpin for LocaleCanonicalizer
impl UnwindSafe for LocaleCanonicalizer
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more