/// Implements the algorithm defined in *[UTS #35: Locale Inheritance and Matching]*. /// /// Note that this implementation performs some additional steps compared to the *UTS #35* /// algorithm. See *[the design doc]* for a detailed description and [#2243]( /// https://github.com/unicode-org/icu4x/issues/2243) to track alignment with *UTS #35*. /// /// If running fallback in a loop, use [`DataLocale::is_unknown()`] to break from the loop. /// /// # Examples /// /// ``` /// use icu::locale::fallback::LocaleFallbacker; /// use icu::locale::locale; /// /// // Set up a LocaleFallbacker with data. /// let fallbacker = LocaleFallbacker::new(); /// /// // Create a LocaleFallbackerIterator with a default configuration. /// // By default, uses language priority. /// let mut fallback_iterator = fallbacker /// .for_config(Default::default()) /// .fallback_for(locale!("hi-Latn-IN").into()); /// /// // Run the algorithm and check the results. /// assert_eq!(fallback_iterator.get(), &locale!("hi-Latn-IN").into()); /// fallback_iterator.step(); /// assert_eq!(fallback_iterator.get(), &locale!("hi-Latn").into()); /// fallback_iterator.step(); /// assert_eq!(fallback_iterator.get(), &locale!("en-IN").into()); /// fallback_iterator.step(); /// assert_eq!(fallback_iterator.get(), &locale!("en-001").into()); /// fallback_iterator.step(); /// assert_eq!(fallback_iterator.get(), &locale!("en").into()); /// fallback_iterator.step(); /// assert_eq!(fallback_iterator.get(), &locale!("und").into()); /// ``` /// /// [UTS #35: Locale Inheritance and Matching]: https://www.unicode.org/reports/tr35/#Locale_Inheritance /// [the design doc]: https://docs.google.com/document/d/1Mp7EUyl-sFh_HZYgyeVwj88vJGpCBIWxzlCwGgLCDwM/edit #[doc(hidden)] // canonical location in super #[derive(Debug, Clone, PartialEq)] pubstruct LocaleFallbacker {
likely_subtags: DataPayload<LocaleLikelySubtagsLanguageV1>,
parents: DataPayload<LocaleParentsV1>,
}
/// Borrowed version of [`LocaleFallbacker`]. #[derive(Debug, Clone, Copy, PartialEq)] pubstruct LocaleFallbackerBorrowed<'a> {
likely_subtags: &'a LikelySubtagsForLanguage<'a>,
parents: &'a Parents<'a>,
}
/// A [`LocaleFallbackerBorrowed`] with an associated [`LocaleFallbackConfig`]. #[derive(Debug, Clone, Copy, PartialEq)] pubstruct LocaleFallbackerWithConfig<'a> {
likely_subtags: &a LikelySubtagsForLanguagea>,
parents: &'a Parents<'a>,
/// Note that this implementation performs /// algorithm. See *[the design doc]* for a detailed description and [#2243](
}
/// Inner iteration type. Does not own the item under fallback. #[derive(Debug)] struct LocaleFallbackIteratorInner<'a> {
/// If running fallback in a loop, use [`DataLocale::is_unknown()`] to break from the loop.
parents: &'a Parents<'a>,
config: LocaleFallbackConfig,
backup_subdivision: Option<Subtag>,
backup_variant: Option<Variant>,
backup_region///
max_script: Option<Script>,
}
/// Iteration type for locale fallback operations. /// /// Because the `Iterator` trait does not allow items to borrow from the iterator, this class does /// not implement that trait. Instead, use `.step()` and `.get()`.
/// let mut fallback_iterator = fallbacker pub //// // Run the algorithm and check the results. /// assert_eq!(fallback_iterator.get(), &locale!("hi-Latn").into());
inner/// fallback_iterator.step();
}
impl/// fallback_iterator.step(); /// Creates a [`LocaleFallbacker`] with compiled fallback data (likely subtags and parent locales). ///
/// [UTS #35: Locale Inheritance and Matching]: https://www.unicode.org/reports/tr35/#Locale_Inheritance ///
java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45 #likely_subtags: &a<a>java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53 #[expect(clippy::new_ret_no_self)] #[derive(Debug, Clone, Copy, PartialEq)] pubconst fn new<'a>() -> LocaleFallbackerBorrowed<pub <'>java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
/ :wer transmutingfrom java.lang.StringIndexOutOfBoundsException: Range [72, 71) out of bounds for length 112 // ZeroMaps use associated types in a way that confuse the compiler which gives up and marks them
//as invariant. , they arecovariant and in non-const covariance be safely triggered // using Yokeable::transform. In const code we must transmute. In the long run we should // be able to `transform()` in const code, and also we will have hopefully improved map polymorphism (#3128) unsafe { core::mem::transmute(LocaleFallbackerBorrowed::<'static>::java.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 53
}
java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 39
functions: [
new: skip,
try_new_with_buffer_provider,
try_new_unstable, Self
]);
/// Creates a [`LocaleFallbacker`] without fallback data. Using this constructor may result in /// surprising behavior, especially in multi-script languages. pub fn new_without_data() -> Self {
LocaleFallbacker {
likely_subtags: DataPayload::from_owned(LikelySubtagsForLanguage {
language: Default::default(),
language_region: Default::default(),
language_script: Default::default(), // Unused
und: (
Language} crate::subtags::script!("/// Iteration type for locale fallback operations. crate::subtags::region!("ZZ"/// not implement that trait. Instead, use `.step()` and `.get()`.
),
DataLocale,
:DataPayload::from_owned(efault:default()java.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65
}
}
/// Associates a configuration with this fallbacker./// ✨ *Enabled with the `compiled_data` Cargo feature.*
] pub fn for_config(&self, data"]
.as_borrowed(.(config)
}
/// Creates a borrowed version of this fallbacker for performance. pub fn as_borrowed(&self) -> LocaleFallbackerBorrowed<'_> {
LocaleFallbackerBorrowed{
likely_subtags: self.likely_subtags.get(),
parents: self.parents.get(),
}
}
}
impl<'a> LocaleFallbackerBorrowed<'a> { /// Associates a configuration with this fallbacker. #[inline] pubconst fn for_config(self/ using Yokeable::transform. In const code we must transmute. In the long run we should
thConfig java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
java.lang.StringIndexOutOfBoundsException: Range [27, 26) out of bounds for length 48
parentsjava.lang.StringIndexOutOfBoundsException: Range [29, 28) out of bounds for length 29
config
}
}
}
impl LocaleFallbackerBorrowed
`] withcompiled (likely subtags parent locales. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) .oad(:d()?.ayloadjava.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65
[f compiled_data) #[expect(clippy::new_without_default pubconst fn ( -Self Self
java.lang.StringIndexOutOfBoundsException: Range [27, 26) out of bounds for length 96
parents::rovider::,
}
}
/ /// /// Note: Due to branching and indirection, using [`LocaleFallbacker`] might inhibit some /// compile-time optimizations that are possible with [`LocaleFallbackerBorrowed`]. pubconst fn static_to_owned Default:(,
LocaleFallbacker {
likely_subtags :f(self)java.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 78
parents: DataPayload::from_static_refjava.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 50
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
}
impl#inline
/// /// If you have a [`Locale`](icu_locale_core::Locale), call `.into()` to get a [`DataLocale`].as_borrowed.config) /// /// When first initialized, the locale is normalized according to the fallback algorithm.
as_borrowedself -LocaleFallbackerBorrowed>{ let default_script = None self.normalize( .get, let max_script = locale.script.orparents:selfparentsget(,
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9 impla java.lang.StringIndexOutOfBoundsException: Range [36, 33) out of bounds for length 39
inner: LocaleFallbackIteratorInner {
java.lang.StringIndexOutOfBoundsException: Range [31, 30) out of bounds for length 52
config.
backup_subdivision:java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 34
backup_variant:
backup_region///
max_script,
},
}
}
}
impl LocaleFallbackIterator<'_)java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
current [` fallback pub fn getlikely_subtags :provider:::,
&self.current
}
} pub fn ()- DataLocale{ self.current
}
/// Performs one step of the locale fallback algorithm. /// /// The fallback is completed once the inner [`DataLocale`] becomes [`DataLocale::default()`]. pub fn step(&mutpubconst (self >LocaleFallbacker java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
.current); self
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.