Struct icu_locale::LocaleCanonicalizer
source · pub struct LocaleCanonicalizer<Expander = LocaleExpander> { /* private fields */ }
Expand description
Implements the algorithm defined in UTS #35: Annex C, LocaleId Canonicalization.
§Examples
use icu::locale::Locale;
use icu::locale::{LocaleCanonicalizer, TransformResult};
let lc = LocaleCanonicalizer::new();
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§
source§impl LocaleCanonicalizer<LocaleExpander>
impl LocaleCanonicalizer<LocaleExpander>
sourcepub const fn new() -> Self
pub const fn new() -> Self
A constructor which creates a LocaleCanonicalizer
from compiled data.
✨ Enabled with the compiled_data
Cargo feature.
sourcepub fn try_new_with_any_provider(
provider: &(impl AnyProvider + ?Sized),
) -> Result<Self, DataError>
pub fn try_new_with_any_provider( provider: &(impl AnyProvider + ?Sized), ) -> Result<Self, DataError>
A version of [Self :: new
] that uses custom data provided by an AnyProvider
.
sourcepub fn try_new_with_buffer_provider(
provider: &(impl BufferProvider + ?Sized),
) -> Result<Self, DataError>
pub fn try_new_with_buffer_provider( provider: &(impl BufferProvider + ?Sized), ) -> Result<Self, DataError>
A version of [Self :: new
] that uses custom data provided by a BufferProvider
.
✨ Enabled with the serde
feature.
sourcepub fn try_new_unstable<P>(provider: &P) -> Result<Self, DataError>where
P: DataProvider<AliasesV2Marker> + DataProvider<LikelySubtagsForLanguageV1Marker> + DataProvider<LikelySubtagsForScriptRegionV1Marker> + ?Sized,
pub fn try_new_unstable<P>(provider: &P) -> Result<Self, DataError>where
P: DataProvider<AliasesV2Marker> + DataProvider<LikelySubtagsForLanguageV1Marker> + DataProvider<LikelySubtagsForScriptRegionV1Marker> + ?Sized,
A version of Self::new
that uses custom data provided by a DataProvider
.
source§impl<Expander: AsRef<LocaleExpander>> LocaleCanonicalizer<Expander>
impl<Expander: AsRef<LocaleExpander>> LocaleCanonicalizer<Expander>
sourcepub const fn new_with_expander(expander: Expander) -> Self
pub const fn new_with_expander(expander: Expander) -> Self
Creates a LocaleCanonicalizer
with a custom LocaleExpander
and compiled data.
✨ Enabled with the compiled_data
Cargo feature.
sourcepub fn try_new_with_expander_unstable<P>(
provider: &P,
expander: Expander,
) -> Result<Self, DataError>where
P: DataProvider<AliasesV2Marker> + ?Sized,
pub fn try_new_with_expander_unstable<P>(
provider: &P,
expander: Expander,
) -> Result<Self, DataError>where
P: DataProvider<AliasesV2Marker> + ?Sized,
A version of Self::new_with_expander
that uses custom data provided by a DataProvider
.
sourcepub fn try_new_with_expander_with_any_provider(
provider: &(impl AnyProvider + ?Sized),
options: Expander,
) -> Result<Self, DataError>
pub fn try_new_with_expander_with_any_provider( provider: &(impl AnyProvider + ?Sized), options: Expander, ) -> Result<Self, DataError>
A version of [Self :: new_with_expander
] that uses custom data provided by an AnyProvider
.
sourcepub fn try_new_with_expander_with_buffer_provider(
provider: &(impl BufferProvider + ?Sized),
options: Expander,
) -> Result<Self, DataError>
pub fn try_new_with_expander_with_buffer_provider( provider: &(impl BufferProvider + ?Sized), options: Expander, ) -> Result<Self, DataError>
A version of [Self :: new_with_expander
] that uses custom data provided by a BufferProvider
.
✨ Enabled with the serde
feature.
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. See:
https://github.com/unicode-org/icu4x/issues/746
§Examples
use icu::locale::{Locale, LocaleCanonicalizer, TransformResult};
let lc = LocaleCanonicalizer::new();
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());
Trait Implementations§
source§impl<Expander: Debug> Debug for LocaleCanonicalizer<Expander>
impl<Expander: Debug> Debug for LocaleCanonicalizer<Expander>
source§impl Default for LocaleCanonicalizer<LocaleExpander>
impl Default for LocaleCanonicalizer<LocaleExpander>
Auto Trait Implementations§
impl<Expander> Freeze for LocaleCanonicalizer<Expander>where
Expander: Freeze,
impl<Expander> RefUnwindSafe for LocaleCanonicalizer<Expander>where
Expander: RefUnwindSafe,
impl<Expander> Send for LocaleCanonicalizer<Expander>where
Expander: Send,
impl<Expander> Sync for LocaleCanonicalizer<Expander>where
Expander: Sync,
impl<Expander> Unpin for LocaleCanonicalizer<Expander>where
Expander: Unpin,
impl<Expander> UnwindSafe for LocaleCanonicalizer<Expander>where
Expander: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more