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
impl LocaleCanonicalizer
sourcepub const fn new() -> LocaleCanonicalizer
pub const fn new() -> LocaleCanonicalizer
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<LocaleCanonicalizer, DataError>
pub fn try_new_with_any_provider( provider: &(impl AnyProvider + ?Sized), ) -> Result<LocaleCanonicalizer, 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<LocaleCanonicalizer, DataError>
pub fn try_new_with_buffer_provider( provider: &(impl BufferProvider + ?Sized), ) -> Result<LocaleCanonicalizer, 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<LocaleCanonicalizer, DataError>
pub fn try_new_unstable<P>( provider: &P, ) -> Result<LocaleCanonicalizer, DataError>
A version of Self::new
that uses custom data provided by a DataProvider
.
source§impl<Expander> LocaleCanonicalizer<Expander>where
Expander: AsRef<LocaleExpander>,
impl<Expander> LocaleCanonicalizer<Expander>where
Expander: AsRef<LocaleExpander>,
sourcepub const fn new_with_expander(
expander: Expander,
) -> LocaleCanonicalizer<Expander>
pub const fn new_with_expander( expander: Expander, ) -> LocaleCanonicalizer<Expander>
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<LocaleCanonicalizer<Expander>, DataError>
pub fn try_new_with_expander_unstable<P>( provider: &P, expander: Expander, ) -> Result<LocaleCanonicalizer<Expander>, DataError>
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<LocaleCanonicalizer<Expander>, DataError>
pub fn try_new_with_expander_with_any_provider( provider: &(impl AnyProvider + ?Sized), options: Expander, ) -> Result<LocaleCanonicalizer<Expander>, 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<LocaleCanonicalizer<Expander>, DataError>
pub fn try_new_with_expander_with_buffer_provider( provider: &(impl BufferProvider + ?Sized), options: Expander, ) -> Result<LocaleCanonicalizer<Expander>, 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 for LocaleCanonicalizer<Expander>where
Expander: Debug,
impl<Expander> Debug for LocaleCanonicalizer<Expander>where
Expander: Debug,
source§impl Default for LocaleCanonicalizer
impl Default for LocaleCanonicalizer
source§fn default() -> LocaleCanonicalizer
fn default() -> LocaleCanonicalizer
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