Struct icu::locid_transform::LocaleExpander
source · [−]pub struct LocaleExpander { /* private fields */ }
Expand description
LocaleExpander supports the minimize
and maximize
likely subtags
algorithms as described in UTS #35: Unicode LDML 3. Likely Subtags
.
The maximize method potentially updates a passed in locale in place
depending up the results of running the ‘Add Likely Subtags’ algorithm
from UTS #35: Unicode LDML 3. Likely Subtags
.
This minimize method returns a new Locale that is the result of running the
‘Remove Likely Subtags’ algorithm from UTS #35: Unicode LDML 3. Likely Subtags
.
Examples
use icu_locid::locale;
use icu_locid_transform::{LocaleExpander, TransformResult};
let lc = LocaleExpander::try_new_unstable(&icu_testdata::unstable())
.expect("create failed");
let mut locale = locale!("zh-CN");
assert_eq!(lc.maximize(&mut locale), TransformResult::Modified);
assert_eq!(locale, locale!("zh-Hans-CN"));
let mut locale = locale!("zh-Hant-TW");
assert_eq!(lc.maximize(&mut locale), TransformResult::Unmodified);
assert_eq!(locale, locale!("zh-Hant-TW"));
use icu_locid::locale;
use icu_locid_transform::{LocaleExpander, TransformResult};
let lc = LocaleExpander::try_new_unstable(&icu_testdata::unstable())
.expect("create failed");
let mut locale = locale!("zh-Hans-CN");
assert_eq!(lc.minimize(&mut locale), TransformResult::Modified);
assert_eq!(locale, locale!("zh"));
let mut locale = locale!("zh");
assert_eq!(lc.minimize(&mut locale), TransformResult::Unmodified);
assert_eq!(locale, locale!("zh"));
Implementations
sourceimpl LocaleExpander
impl LocaleExpander
sourcepub fn try_new_unstable<P>(
provider: &P
) -> Result<LocaleExpander, LocaleTransformError> where
P: DataProvider<LikelySubtagsV1Marker> + ?Sized,
pub fn try_new_unstable<P>(
provider: &P
) -> Result<LocaleExpander, LocaleTransformError> where
P: DataProvider<LikelySubtagsV1Marker> + ?Sized,
A constructor which takes a DataProvider
and creates a LocaleExpander
.
sourcepub fn try_new_with_any_provider(
provider: &impl AnyProvider
) -> Result<LocaleExpander, LocaleTransformError>
pub fn try_new_with_any_provider(
provider: &impl AnyProvider
) -> Result<LocaleExpander, 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<LocaleExpander, LocaleTransformError>
pub fn try_new_with_buffer_provider(
provider: &impl BufferProvider
) -> Result<LocaleExpander, 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 maximize<T>(&self, langid: T) -> TransformResult where
T: AsMut<LanguageIdentifier>,
pub fn maximize<T>(&self, langid: T) -> TransformResult where
T: AsMut<LanguageIdentifier>,
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 TransformResult::Modified
. Otherwise, the method
returns TransformResult::Unmodified
and the locale argument is
unchanged.
Examples
use icu_locid::locale;
use icu_locid_transform::{LocaleExpander, TransformResult};
let lc = LocaleExpander::try_new_unstable(&icu_testdata::unstable())
.expect("create failed");
let mut locale = locale!("zh-CN");
assert_eq!(lc.maximize(&mut locale), TransformResult::Modified);
assert_eq!(locale, locale!("zh-Hans-CN"));
let mut locale = locale!("zh-Hant-TW");
assert_eq!(lc.maximize(&mut locale), TransformResult::Unmodified);
assert_eq!(locale, locale!("zh-Hant-TW"));
sourcepub fn minimize<T>(&self, langid: T) -> TransformResult where
T: AsMut<LanguageIdentifier>,
pub fn minimize<T>(&self, langid: T) -> TransformResult where
T: AsMut<LanguageIdentifier>,
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 TransformResult::Modified
. Otherwise, the method
returns TransformResult::Unmodified
and the locale argument is
unchanged.
Examples
use icu_locid::locale;
use icu_locid_transform::{LocaleExpander, TransformResult};
let lc = LocaleExpander::try_new_unstable(&icu_testdata::unstable())
.expect("creation failed");
let mut locale = locale!("zh-Hans-CN");
assert_eq!(lc.minimize(&mut locale), TransformResult::Modified);
assert_eq!(locale, locale!("zh"));
let mut locale = locale!("zh");
assert_eq!(lc.minimize(&mut locale), TransformResult::Unmodified);
assert_eq!(locale, locale!("zh"));
Auto Trait Implementations
impl RefUnwindSafe for LocaleExpander
impl Send for LocaleExpander
impl Sync for LocaleExpander
impl Unpin for LocaleExpander
impl UnwindSafe for LocaleExpander
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