//! This module provides APIs for getting exemplar characters for a locale. //! //! Exemplars are characters used by a language, separated into different sets. //! The sets are: main, auxiliary, punctuation, numbers, and index. //! //! The sets define, according to typical usage in the language, //! which characters occur in which contexts with which frequency. //! For more information, see the documentation in the //! [Exemplars section in Unicode Technical Standard #35](https://unicode.org/reports/tr35/tr35-general.html#Exemplars) //! of the LDML specification. //! //! # Examples //! //! ``` //! use icu::locale::exemplar_chars::ExemplarCharacters; //! use icu::locale::locale; //! //! let locale = locale!("en-001").into(); //! let exemplars_main = ExemplarCharacters::try_new_main(&locale) //! .expect("locale should be present"); //! //! assert!(exemplars_main.contains('a')); //! assert!(exemplars_main.contains('z')); //! assert!(exemplars_main.contains_str("a")); //! assert!(!exemplars_main.contains_str("ä")); //! assert!(!exemplars_main.contains_str("ng")); //! ```
usecrate::provider::*; use core::ops::Deref; use icu_collections::codepointinvliststringlist::CodePointInversionListAndStringList; use icu_provider::{marker::ErasedMarker, prelude::*};
/// A wrapper around `UnicodeSet` data (characters and strings) #[derive(Debug)] pubstruct ExemplarCharacters {
data: DataPayload<ErasedMarker<ExemplarCharactersData<'static>>>,
}
impl ExemplarCharacters { /// Construct a borrowed version of this type that can be queried. /// /// This avoids a potential small underlying cost per API call (ex: `contains()`) by consolidating it /// up front. #[inline] pubfn as_borrowed(&self) -> ExemplarCharactersBorrowed<'_> {
ExemplarCharactersBorrowed {
data: self.data.get(),
}
}
}
/// A borrowed wrapper around code point set data, returned by /// [`ExemplarCharacters::as_borrowed()`]. More efficient to query. #[derive(Clone, Copy, Debug)] pubstruct ExemplarCharactersBorrowed<'a> {
data: &'a ExemplarCharactersData<'a>,
}
impl<'a> Deref for ExemplarCharactersBorrowed<'a> { type Target = CodePointInversionListAndStringList<'a>;
impl ExemplarCharactersBorrowed<'static> { /// Cheaply converts a [`ExemplarCharactersBorrowed<'static>`] into a [`ExemplarCharacters`]. /// /// Note: Due to branching and indirection, using [`ExemplarCharacters`] might inhibit some /// compile-time optimizations that are possible with [`ExemplarCharactersBorrowed`]. pubconstfn static_to_owned(self) -> ExemplarCharacters {
ExemplarCharacters {
data: DataPayload::from_static_ref(self.data),
}
}
}
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.