//! A collection of property definitions shared across contexts //! (ex: representing trie values). //! //! This module defines enums / newtypes for enumerated properties. //! String properties are represented as newtypes if their //! values represent code points.
usecrate::provider::{names::*, *}; usecrate::PropertiesError; use core::marker::PhantomData; use icu_collections::codepointtrie::TrieValue; use icu_provider::prelude::*; use zerovec::ule::VarULE;
#[cfg(feature = "serde")] use serde::{Deserialize, Serialize};
/// Private marker type for PropertyValueNameToEnumMapper /// to work for all properties at once #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] pub(crate) struct ErasedNameToEnumMapV1Marker; impl DataMarker for ErasedNameToEnumMapV1Marker { type Yokeable = PropertyValueNameToEnumMapV1<'static>;
}
/// A struct capable of looking up a property value from a string name. /// Access its data by calling [`Self::as_borrowed()`] and using the methods on /// [`PropertyValueNameToEnumMapperBorrowed`]. /// /// The name can be a short name (`Lu`), a long name(`Uppercase_Letter`), /// or an alias. /// /// Property names can be looked up using "strict" matching (looking for a name /// that matches exactly), or "loose matching", where the name is allowed to deviate /// in terms of ASCII casing, whitespace, underscores, and hyphens. /// /// # Example /// /// ``` /// use icu::properties::GeneralCategory; /// /// let lookup = GeneralCategory::name_to_enum_mapper(); /// // short name for value /// assert_eq!( /// lookup.get_strict("Lu"), /// Some(GeneralCategory::UppercaseLetter) /// ); /// assert_eq!( /// lookup.get_strict("Pd"), /// Some(GeneralCategory::DashPunctuation) /// ); /// // long name for value /// assert_eq!( /// lookup.get_strict("Uppercase_Letter"), /// Some(GeneralCategory::UppercaseLetter) /// ); /// assert_eq!( /// lookup.get_strict("Dash_Punctuation"), /// Some(GeneralCategory::DashPunctuation) /// ); /// // name has incorrect casing /// assert_eq!(lookup.get_strict("dashpunctuation"), None); /// // loose matching of name /// assert_eq!( /// lookup.get_loose("dash-punctuation"), /// Some(GeneralCategory::DashPunctuation) /// ); /// // fake property /// assert_eq!(lookup.get_strict("Animated_Gif"), None); /// ``` #[derive(Debug)] pubstruct PropertyValueNameToEnumMapper<T> {
map: DataPayload<ErasedNameToEnumMapV1Marker>,
markers: PhantomData<fn() -> T>,
}
/// A borrowed wrapper around property value name-to-enum data, returned by /// [`PropertyValueNameToEnumMapper::as_borrowed()`]. More efficient to query. #[derive(Debug, Copy, Clone)] pubstruct PropertyValueNameToEnumMapperBorrowed<'a, T> {
map: &'a PropertyValueNameToEnumMapV1<'a>,
markers: PhantomData<fn() -> T>,
}
impl<T: TrieValue> PropertyValueNameToEnumMapper<T> { /// Construct a borrowed version of this type that can be queried. /// /// This avoids a potential small underlying cost per API call (like `get_strict()`) by consolidating it /// up front. #[inline] pubfn as_borrowed(&self) -> PropertyValueNameToEnumMapperBorrowed<'_, T> {
PropertyValueNameToEnumMapperBorrowed {
map: self.map.get(),
markers: PhantomData,
}
}
#[doc(hidden)] // used by FFI code pubfn erase(self) -> PropertyValueNameToEnumMapper<u16> {
PropertyValueNameToEnumMapper {
map: self.map.cast(),
markers: PhantomData,
}
}
}
impl<T: TrieValue> PropertyValueNameToEnumMapperBorrowed<'_, T> { /// Get the property value as a u16, doing a strict search looking for /// names that match exactly /// /// # Example /// /// ``` /// use icu::properties::GeneralCategory; /// /// let lookup = GeneralCategory::name_to_enum_mapper(); /// assert_eq!( /// lookup.get_strict_u16("Lu"), /// Some(GeneralCategory::UppercaseLetter as u16) /// ); /// assert_eq!( /// lookup.get_strict_u16("Uppercase_Letter"), /// Some(GeneralCategory::UppercaseLetter as u16) /// ); /// // does not do loose matching /// assert_eq!(lookup.get_strict_u16("UppercaseLetter"), None); /// ``` #[inline] pubfn get_strict_u16(&self, name: &str) -> Option<u16> {
get_strict_u16(self.map, name)
}
/// Get the property value as a `T`, doing a strict search looking for /// names that match exactly /// /// # Example /// /// ``` /// use icu::properties::GeneralCategory; /// /// let lookup = GeneralCategory::name_to_enum_mapper(); /// assert_eq!( /// lookup.get_strict("Lu"), /// Some(GeneralCategory::UppercaseLetter) /// ); /// assert_eq!( /// lookup.get_strict("Uppercase_Letter"), /// Some(GeneralCategory::UppercaseLetter) /// ); /// // does not do loose matching /// assert_eq!(lookup.get_strict("UppercaseLetter"), None); /// ``` #[inline] pubfn get_strict(&self, name: &str) -> Option<T> {
T::try_from_u32(self.get_strict_u16(name)? as u32).ok()
}
/// Get the property value as a u16, doing a loose search looking for /// names that match case-insensitively, ignoring ASCII hyphens, underscores, and /// whitespaces. /// /// # Example /// /// ``` /// use icu::properties::GeneralCategory; /// /// let lookup = GeneralCategory::name_to_enum_mapper(); /// assert_eq!( /// lookup.get_loose_u16("Lu"), /// Some(GeneralCategory::UppercaseLetter as u16) /// ); /// assert_eq!( /// lookup.get_loose_u16("Uppercase_Letter"), /// Some(GeneralCategory::UppercaseLetter as u16) /// ); /// // does do loose matching /// assert_eq!( /// lookup.get_loose_u16("UppercaseLetter"), /// Some(GeneralCategory::UppercaseLetter as u16) /// ); /// ``` #[inline] pubfn get_loose_u16(&self, name: &str) -> Option<u16> {
get_loose_u16(self.map, name)
}
/// Get the property value as a `T`, doing a loose search looking for /// names that match case-insensitively, ignoring ASCII hyphens, underscores, and /// whitespaces. /// /// # Example /// /// ``` /// use icu::properties::GeneralCategory; /// /// let lookup = GeneralCategory::name_to_enum_mapper(); /// assert_eq!( /// lookup.get_loose("Lu"), /// Some(GeneralCategory::UppercaseLetter) /// ); /// assert_eq!( /// lookup.get_loose("Uppercase_Letter"), /// Some(GeneralCategory::UppercaseLetter) /// ); /// // does do loose matching /// assert_eq!( /// lookup.get_loose("UppercaseLetter"), /// Some(GeneralCategory::UppercaseLetter) /// ); /// ``` #[inline] pubfn get_loose(&self, name: &str) -> Option<T> {
T::try_from_u32(self.get_loose_u16(name)? as u32).ok()
}
}
impl<T: TrieValue> PropertyValueNameToEnumMapperBorrowed<'static, T> { /// Cheaply converts a [`PropertyValueNameToEnumMapperBorrowed<'static>`] into a [`PropertyValueNameToEnumMapper`]. /// /// Note: Due to branching and indirection, using [`PropertyValueNameToEnumMapper`] might inhibit some /// compile-time optimizations that are possible with [`PropertyValueNameToEnumMapperBorrowed`]. pubconstfn static_to_owned(self) -> PropertyValueNameToEnumMapper<T> {
PropertyValueNameToEnumMapper {
map: DataPayload::from_static_ref(self.map),
markers: PhantomData,
}
}
}
/// Avoid monomorphizing multiple copies of this function fn get_strict_u16(payload: &PropertyValueNameToEnumMapV1<'_>, name: &str) -> Option<u16> { // NormalizedPropertyName has no invariants so this should be free, but // avoid introducing a panic regardless let name = NormalizedPropertyNameStr::parse_byte_slice(name.as_bytes()).ok()?;
payload.map.get_copied(name)
}
/// Avoid monomorphizing multiple copies of this function fn get_loose_u16(payload: &PropertyValueNameToEnumMapV1<'_>, name: &str) -> Option<u16> { // NormalizedPropertyName has no invariants so this should be free, but // avoid introducing a panic regardless let name = NormalizedPropertyNameStr::parse_byte_slice(name.as_bytes()).ok()?;
payload.map.get_copied_by(|p| p.cmp_loose(name))
}
/// Private marker type for PropertyEnumToValueNameSparseMapper /// to work for all properties at once #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] pub(crate) struct ErasedEnumToValueNameSparseMapV1Marker; impl DataMarker for ErasedEnumToValueNameSparseMapV1Marker { type Yokeable = PropertyEnumToValueNameSparseMapV1<'static>;
}
/// A struct capable of looking up a property name from a value /// Access its data by calling [`Self::as_borrowed()`] and using the methods on /// [`PropertyEnumToValueNameSparseMapperBorrowed`]. /// /// This mapper is used for properties with sparse values, like [`CanonicalCombiningClass`]. /// It may be obtained using methods like [`CanonicalCombiningClass::get_enum_to_long_name_mapper()`]. /// /// The name returned may be a short (`"KV"`) or long (`"Kana_Voicing"`) name, depending /// on the constructor used. /// /// # Example /// /// ``` /// use icu::properties::CanonicalCombiningClass; /// /// let lookup = CanonicalCombiningClass::enum_to_long_name_mapper(); /// assert_eq!( /// lookup.get(CanonicalCombiningClass::KanaVoicing), /// Some("Kana_Voicing") /// ); /// assert_eq!( /// lookup.get(CanonicalCombiningClass::AboveLeft), /// Some("Above_Left") /// ); /// ``` #[derive(Debug)] pubstruct PropertyEnumToValueNameSparseMapper<T> {
map: DataPayload<ErasedEnumToValueNameSparseMapV1Marker>,
markers: PhantomData<fn(T) -> ()>,
}
/// A borrowed wrapper around property value name-to-enum data, returned by /// [`PropertyEnumToValueNameSparseMapper::as_borrowed()`]. More efficient to query. #[derive(Debug, Copy, Clone)] pubstruct PropertyEnumToValueNameSparseMapperBorrowed<'a, T> {
map: &'a PropertyEnumToValueNameSparseMapV1<'a>,
markers: PhantomData<fn(T) -> ()>,
}
impl<T: TrieValue> PropertyEnumToValueNameSparseMapper<T> { /// Construct a borrowed version of this type that can be queried. /// /// This avoids a potential small underlying cost per API call (like `get_static()`) by consolidating it /// up front. #[inline] pubfn as_borrowed(&self) -> PropertyEnumToValueNameSparseMapperBorrowed<'_, T> {
PropertyEnumToValueNameSparseMapperBorrowed {
map: self.map.get(),
markers: PhantomData,
}
}
/// Construct a new one from loaded data /// /// Typically it is preferable to use methods on individual property value types /// (like [`Script::TBD()`]) instead. pub(crate) fn from_data<M>(data: DataPayload<M>) -> Self where
M: DataMarker<Yokeable = PropertyEnumToValueNameSparseMapV1<'static>>,
{ Self {
map: data.cast(),
markers: PhantomData,
}
}
}
impl<T: TrieValue> PropertyEnumToValueNameSparseMapperBorrowed<'_, T> { /// Get the property name given a value /// /// # Example /// /// ```rust /// use icu::properties::CanonicalCombiningClass; /// /// let lookup = CanonicalCombiningClass::enum_to_long_name_mapper(); /// assert_eq!( /// lookup.get(CanonicalCombiningClass::KanaVoicing), /// Some("Kana_Voicing") /// ); /// assert_eq!( /// lookup.get(CanonicalCombiningClass::AboveLeft), /// Some("Above_Left") /// ); /// ``` #[inline] pubfn get(&self, property: T) -> Option<&str> { let prop = u16::try_from(property.to_u32()).ok()?; self.map.map.get(&prop)
}
}
impl<T: TrieValue> PropertyEnumToValueNameSparseMapperBorrowed<'static, T> { /// Cheaply converts a [`PropertyEnumToValueNameSparseMapperBorrowed<'static>`] into a [`PropertyEnumToValueNameSparseMapper`]. /// /// Note: Due to branching and indirection, using [`PropertyEnumToValueNameSparseMapper`] might inhibit some /// compile-time optimizations that are possible with [`PropertyEnumToValueNameSparseMapperBorrowed`]. pubconstfn static_to_owned(self) -> PropertyEnumToValueNameSparseMapper<T> {
PropertyEnumToValueNameSparseMapper {
map: DataPayload::from_static_ref(self.map),
markers: PhantomData,
}
}
}
/// Private marker type for PropertyEnumToValueNameLinearMapper /// to work for all properties at once #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] pub(crate) struct ErasedEnumToValueNameLinearMapV1Marker; impl DataMarker for ErasedEnumToValueNameLinearMapV1Marker { type Yokeable = PropertyEnumToValueNameLinearMapV1<'static>;
}
/// A struct capable of looking up a property name from a value /// Access its data by calling [`Self::as_borrowed()`] and using the methods on /// [`PropertyEnumToValueNameLinearMapperBorrowed`]. /// /// This mapper is used for properties with sequential values, like [`GeneralCategory`]. /// It may be obtained using methods like [`GeneralCategory::get_enum_to_long_name_mapper()`]. /// /// The name returned may be a short (`"Lu"`) or long (`"Uppercase_Letter"`) name, depending /// on the constructor used. /// /// # Example /// /// ``` /// use icu::properties::GeneralCategory; /// /// let lookup = GeneralCategory::enum_to_long_name_mapper(); /// assert_eq!( /// lookup.get(GeneralCategory::UppercaseLetter), /// Some("Uppercase_Letter") /// ); /// assert_eq!( /// lookup.get(GeneralCategory::DashPunctuation), /// Some("Dash_Punctuation") /// ); /// ``` #[derive(Debug)] pubstruct PropertyEnumToValueNameLinearMapper<T> {
map: DataPayload<ErasedEnumToValueNameLinearMapV1Marker>,
markers: PhantomData<fn(T) -> ()>,
}
/// A borrowed wrapper around property value name-to-enum data, returned by /// [`PropertyEnumToValueNameLinearMapper::as_borrowed()`]. More efficient to query. #[derive(Debug, Copy, Clone)] pubstruct PropertyEnumToValueNameLinearMapperBorrowed<'a, T> {
map: &'a PropertyEnumToValueNameLinearMapV1<'a>,
markers: PhantomData<fn(T) -> ()>,
}
impl<T: TrieValue> PropertyEnumToValueNameLinearMapper<T> { /// Construct a borrowed version of this type that can be queried. /// /// This avoids a potential small underlying cost per API call (like `get_static()`) by consolidating it /// up front. #[inline] pubfn as_borrowed(&self) -> PropertyEnumToValueNameLinearMapperBorrowed<'_, T> {
PropertyEnumToValueNameLinearMapperBorrowed {
map: self.map.get(),
markers: PhantomData,
}
}
/// Construct a new one from loaded data /// /// Typically it is preferable to use methods on individual property value types /// (like [`Script::TBD()`]) instead. pub(crate) fn from_data<M>(data: DataPayload<M>) -> Self where
M: DataMarker<Yokeable = PropertyEnumToValueNameLinearMapV1<'static>>,
{ Self {
map: data.cast(),
markers: PhantomData,
}
}
}
impl<T: TrieValue> PropertyEnumToValueNameLinearMapperBorrowed<'_, T> { /// Get the property name given a value /// /// # Example /// /// ```rust /// use icu::properties::GeneralCategory; /// /// let lookup = GeneralCategory::enum_to_short_name_mapper(); /// assert_eq!(lookup.get(GeneralCategory::UppercaseLetter), Some("Lu")); /// assert_eq!(lookup.get(GeneralCategory::DashPunctuation), Some("Pd")); /// ``` #[inline] pubfn get(&self, property: T) -> Option<&str> { let prop = usize::try_from(property.to_u32()).ok()?; self.map.map.get(prop).filter(|x| !x.is_empty())
}
}
impl<T: TrieValue> PropertyEnumToValueNameLinearMapperBorrowed<'static, T> { /// Cheaply converts a [`PropertyEnumToValueNameLinearMapperBorrowed<'static>`] into a [`PropertyEnumToValueNameLinearMapper`]. /// /// Note: Due to branching and indirection, using [`PropertyEnumToValueNameLinearMapper`] might inhibit some /// compile-time optimizations that are possible with [`PropertyEnumToValueNameLinearMapperBorrowed`]. pubconstfn static_to_owned(self) -> PropertyEnumToValueNameLinearMapper<T> {
PropertyEnumToValueNameLinearMapper {
map: DataPayload::from_static_ref(self.map),
markers: PhantomData,
}
}
}
/// Private marker type for PropertyEnumToValueNameLinearTiny4Mapper /// to work for all properties at once #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] pub(crate) struct ErasedEnumToValueNameLinearTiny4MapV1Marker; impl DataMarker for ErasedEnumToValueNameLinearTiny4MapV1Marker { type Yokeable = PropertyEnumToValueNameLinearTiny4MapV1<'static>;
}
/// A struct capable of looking up a property name from a value /// Access its data by calling [`Self::as_borrowed()`] and using the methods on /// [`PropertyEnumToValueNameLinearTiny4MapperBorrowed`]. /// /// This mapper is used for properties with sequential values and names with four or fewer characters, /// like the [`Script`] short names. /// It may be obtained using methods like [`Script::get_enum_to_short_name_mapper()`]. /// /// # Example /// /// ``` /// use icu::properties::Script; /// use tinystr::tinystr; /// /// let lookup = Script::enum_to_short_name_mapper(); /// assert_eq!(lookup.get(Script::Brahmi), Some(tinystr!(4, "Brah"))); /// assert_eq!(lookup.get(Script::Hangul), Some(tinystr!(4, "Hang"))); /// ``` #[derive(Debug)] pubstruct PropertyEnumToValueNameLinearTiny4Mapper<T> {
map: DataPayload<ErasedEnumToValueNameLinearTiny4MapV1Marker>,
markers: PhantomData<fn(T) -> ()>,
}
/// A borrowed wrapper around property value name-to-enum data, returned by /// [`PropertyEnumToValueNameLinearTiny4Mapper::as_borrowed()`]. More efficient to query. #[derive(Debug, Copy, Clone)] pubstruct PropertyEnumToValueNameLinearTiny4MapperBorrowed<'a, T> {
map: &'a PropertyEnumToValueNameLinearTiny4MapV1<'a>,
markers: PhantomData<fn(T) -> ()>,
}
impl<T: TrieValue> PropertyEnumToValueNameLinearTiny4Mapper<T> { /// Construct a borrowed version of this type that can be queried. /// /// This avoids a potential small underlying cost per API call (like `get_static()`) by consolidating it /// up front. #[inline] pubfn as_borrowed(&self) -> PropertyEnumToValueNameLinearTiny4MapperBorrowed<'_, T> {
PropertyEnumToValueNameLinearTiny4MapperBorrowed {
map: self.map.get(),
markers: PhantomData,
}
}
/// Construct a new one from loaded data /// /// Typically it is preferable to use methods on individual property value types /// (like [`Script::TBD()`]) instead. pub(crate) fn from_data<M>(data: DataPayload<M>) -> Self where
M: DataMarker<Yokeable = PropertyEnumToValueNameLinearTiny4MapV1<'static>>,
{ Self {
map: data.cast(),
markers: PhantomData,
}
}
}
impl<T: TrieValue> PropertyEnumToValueNameLinearTiny4MapperBorrowed<'_, T> { /// Get the property name given a value /// /// # Example /// /// ```rust /// use icu::properties::Script; /// use tinystr::tinystr; /// /// let lookup = Script::enum_to_short_name_mapper(); /// assert_eq!(lookup.get(Script::Brahmi), Some(tinystr!(4, "Brah"))); /// assert_eq!(lookup.get(Script::Hangul), Some(tinystr!(4, "Hang"))); /// ``` #[inline] pubfn get(&self, property: T) -> Option<tinystr::TinyStr4> { let prop = usize::try_from(property.to_u32()).ok()?; self.map.map.get(prop).filter(|x| !x.is_empty())
}
}
impl<T: TrieValue> PropertyEnumToValueNameLinearTiny4MapperBorrowed<'static, T> { /// Cheaply converts a [`PropertyEnumToValueNameLinearTiny4MapperBorrowed<'static>`] into a [`PropertyEnumToValueNameLinearTiny4Mapper`]. /// /// Note: Due to branching and indirection, using [`PropertyEnumToValueNameLinearTiny4Mapper`] might inhibit some /// compile-time optimizations that are possible with [`PropertyEnumToValueNameLinearTiny4MapperBorrowed`]. pubconstfn static_to_owned(self) -> PropertyEnumToValueNameLinearTiny4Mapper<T> {
PropertyEnumToValueNameLinearTiny4Mapper {
map: DataPayload::from_static_ref(self.map),
markers: PhantomData,
}
}
}
#[doc = concat!("A version of [`", stringify!($ty), "::", stringify!($cname_n2e), "()`] that uses custom data provided by a [`DataProvider`].")] /// /// [ Help choosing a constructor](icu_provider::constructors)
$vis_n2e fn $name_n2e(
provider: &(impl DataProvider<$marker_n2e> + ?Sized)
) -> Result<PropertyValueNameToEnumMapper<$ty>, PropertiesError> {
Ok(provider.load(Default::default()).and_then(DataResponse::take_payload).map(PropertyValueNameToEnumMapper::from_data)?)
}
#[doc = concat!("A version of [`", stringify!($ty), "::", stringify!($cname_e2sn), "()`] that uses custom data provided by a [`DataProvider`].")] /// /// [ Help choosing a constructor](icu_provider::constructors)
$vis_e2sn fn $name_e2sn(
provider: &(impl DataProvider<$marker_e2sn> + ?Sized)
) -> Result<$mapper_e2sn<$ty>, PropertiesError> {
Ok(provider.load(Default::default()).and_then(DataResponse::take_payload).map($mapper_e2sn::from_data)?)
}
/// Enumerated property Bidi_Class /// /// These are the categories required by the Unicode Bidirectional Algorithm. /// For the property values, see [Bidirectional Class Values](https://unicode.org/reports/tr44/#Bidi_Class_Values). /// For more information, see [Unicode Standard Annex #9](https://unicode.org/reports/tr41/tr41-28.html#UAX9). #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "datagen", derive(databake::Bake))] #[cfg_attr(feature = "datagen", databake(path = icu_properties))] #[allow(clippy::exhaustive_structs)] // newtype #[repr(transparent)] #[zerovec::make_ule(BidiClassULE)] pubstruct BidiClass(pub u8);
create_const_array! { #[allow(non_upper_case_globals)] impl BidiClass { /// (`L`) any strong left-to-right character pubconst LeftToRight: BidiClass = BidiClass(0); /// (`R`) any strong right-to-left (non-Arabic-type) character pubconst RightToLeft: BidiClass = BidiClass(1); /// (`EN`) any ASCII digit or Eastern Arabic-Indic digit pubconst EuropeanNumber: BidiClass = BidiClass(2); /// (`ES`) plus and minus signs pubconst EuropeanSeparator: BidiClass = BidiClass(3); /// (`ET`) a terminator in a numeric format context, includes currency signs pubconst EuropeanTerminator: BidiClass = BidiClass(4); /// (`AN`) any Arabic-Indic digit pubconst ArabicNumber: BidiClass = BidiClass(5); /// (`CS`) commas, colons, and slashes pubconst CommonSeparator: BidiClass = BidiClass(6); /// (`B`) various newline characters pubconst ParagraphSeparator: BidiClass = BidiClass(7); /// (`S`) various segment-related control codes pubconst SegmentSeparator: BidiClass = BidiClass(8); /// (`WS`) spaces pubconst WhiteSpace: BidiClass = BidiClass(9); /// (`ON`) most other symbols and punctuation marks pubconst OtherNeutral: BidiClass = BidiClass(10); /// (`LRE`) U+202A: the LR embedding control pubconst LeftToRightEmbedding: BidiClass = BidiClass(11); /// (`LRO`) U+202D: the LR override control pubconst LeftToRightOverride: BidiClass = BidiClass(12); /// (`AL`) any strong right-to-left (Arabic-type) character pubconst ArabicLetter: BidiClass = BidiClass(13); /// (`RLE`) U+202B: the RL embedding control pubconst RightToLeftEmbedding: BidiClass = BidiClass(14); /// (`RLO`) U+202E: the RL override control pubconst RightToLeftOverride: BidiClass = BidiClass(15); /// (`PDF`) U+202C: terminates an embedding or override control pubconst PopDirectionalFormat: BidiClass = BidiClass(16); /// (`NSM`) any nonspacing mark pubconst NonspacingMark: BidiClass = BidiClass(17); /// (`BN`) most format characters, control codes, or noncharacters pubconst BoundaryNeutral: BidiClass = BidiClass(18); /// (`FSI`) U+2068: the first strong isolate control pubconst FirstStrongIsolate: BidiClass = BidiClass(19); /// (`LRI`) U+2066: the LR isolate control pubconst LeftToRightIsolate: BidiClass = BidiClass(20); /// (`RLI`) U+2067: the RL isolate control pubconst RightToLeftIsolate: BidiClass = BidiClass(21); /// (`PDI`) U+2069: terminates an isolate control pubconst PopDirectionalIsolate: BidiClass = BidiClass(22);
}
}
impl_value_getter! {
markers: BidiClassNameToValueV1Marker / SINGLETON_PROPNAMES_FROM_BC_V1, BidiClassValueToShortNameV1Marker / SINGLETON_PROPNAMES_TO_SHORT_LINEAR_BC_V1, BidiClassValueToLongNameV1Marker / SINGLETON_PROPNAMES_TO_LONG_LINEAR_BC_V1; impl BidiClass { /// Return a [`PropertyValueNameToEnumMapper`], capable of looking up values /// from strings for the `Bidi_Class` enumerated property /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::BidiClass; /// /// let lookup = BidiClass::name_to_enum_mapper(); /// // short name for value /// assert_eq!(lookup.get_strict("AN"), Some(BidiClass::ArabicNumber)); /// assert_eq!(lookup.get_strict("NSM"), Some(BidiClass::NonspacingMark)); /// // long name for value /// assert_eq!(lookup.get_strict("Arabic_Number"), Some(BidiClass::ArabicNumber)); /// assert_eq!(lookup.get_strict("Nonspacing_Mark"), Some(BidiClass::NonspacingMark)); /// // name has incorrect casing /// assert_eq!(lookup.get_strict("arabicnumber"), None); /// // loose matching of name /// assert_eq!(lookup.get_loose("arabicnumber"), Some(BidiClass::ArabicNumber)); /// // fake property /// assert_eq!(lookup.get_strict("Upside_Down_Vertical_Backwards_Mirrored"), None); /// ``` pubfn get_name_to_enum_mapper() / name_to_enum_mapper(); /// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up short names /// for values of the `Bidi_Class` enumerated property /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::BidiClass; /// /// let lookup = BidiClass::enum_to_short_name_mapper(); /// assert_eq!(lookup.get(BidiClass::ArabicNumber), Some("AN")); /// assert_eq!(lookup.get(BidiClass::NonspacingMark), Some("NSM")); /// ``` pubfn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed; /// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up long names /// for values of the `Bidi_Class` enumerated property /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::BidiClass; /// /// let lookup = BidiClass::enum_to_long_name_mapper(); /// assert_eq!(lookup.get(BidiClass::ArabicNumber), Some("Arabic_Number")); /// assert_eq!(lookup.get(BidiClass::NonspacingMark), Some("Nonspacing_Mark")); /// ``` pubfn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed;
}
}
/// Enumerated property General_Category. /// /// General_Category specifies the most general classification of a code point, usually /// determined based on the primary characteristic of the assigned character. For example, is the /// character a letter, a mark, a number, punctuation, or a symbol, and if so, of what type? /// /// GeneralCategory only supports specific subcategories (eg `UppercaseLetter`). /// It does not support grouped categories (eg `Letter`). For grouped categories, use [`GeneralCategoryGroup`]. #[derive(Copy, Clone, PartialEq, Eq, Debug, Ord, PartialOrd, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "datagen", derive(databake::Bake))] #[cfg_attr(feature = "datagen", databake(path = icu_properties))] #[allow(clippy::exhaustive_enums)] // this type is stable #[zerovec::make_ule(GeneralCategoryULE)] #[repr(u8)] pubenum GeneralCategory { /// (`Cn`) A reserved unassigned code point or a noncharacter
Unassigned = 0,
/// (`Lu`) An uppercase letter
UppercaseLetter = 1, /// (`Ll`) A lowercase letter
LowercaseLetter = 2, /// (`Lt`) A digraphic letter, with first part uppercase
TitlecaseLetter = 3, /// (`Lm`) A modifier letter
ModifierLetter = 4, /// (`Lo`) Other letters, including syllables and ideographs
OtherLetter = 5,
/// (`Mn`) A nonspacing combining mark (zero advance width)
NonspacingMark = 6, /// (`Mc`) A spacing combining mark (positive advance width)
SpacingMark = 8, /// (`Me`) An enclosing combining mark
EnclosingMark = 7,
/// (`Nd`) A decimal digit
DecimalNumber = 9, /// (`Nl`) A letterlike numeric character
LetterNumber = 10, /// (`No`) A numeric character of other type
OtherNumber = 11,
/// (`Zs`) A space character (of various non-zero widths)
SpaceSeparator = 12, /// (`Zl`) U+2028 LINE SEPARATOR only
LineSeparator = 13, /// (`Zp`) U+2029 PARAGRAPH SEPARATOR only
ParagraphSeparator = 14,
/// (`Cc`) A C0 or C1 control code
Control = 15, /// (`Cf`) A format control character
Format = 16, /// (`Co`) A private-use character
PrivateUse = 17, /// (`Cs`) A surrogate code point
Surrogate = 18,
/// (`Pd`) A dash or hyphen punctuation mark
DashPunctuation = 19, /// (`Ps`) An opening punctuation mark (of a pair)
OpenPunctuation = 20, /// (`Pe`) A closing punctuation mark (of a pair)
ClosePunctuation = 21, /// (`Pc`) A connecting punctuation mark, like a tie
ConnectorPunctuation = 22, /// (`Pi`) An initial quotation mark
InitialPunctuation = 28, /// (`Pf`) A final quotation mark
FinalPunctuation = 29, /// (`Po`) A punctuation mark of other type
OtherPunctuation = 23,
/// (`Sm`) A symbol of mathematical use
MathSymbol = 24, /// (`Sc`) A currency sign
CurrencySymbol = 25, /// (`Sk`) A non-letterlike modifier symbol
ModifierSymbol = 26, /// (`So`) A symbol of other type
OtherSymbol = 27,
}
impl_value_getter! {
markers: GeneralCategoryNameToValueV1Marker / SINGLETON_PROPNAMES_FROM_GC_V1, GeneralCategoryValueToShortNameV1Marker / SINGLETON_PROPNAMES_TO_SHORT_LINEAR_GC_V1, GeneralCategoryValueToLongNameV1Marker / SINGLETON_PROPNAMES_TO_LONG_LINEAR_GC_V1; impl GeneralCategory { /// Return a [`PropertyValueNameToEnumMapper`], capable of looking up values /// from strings for the `General_Category` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::GeneralCategory; /// /// let lookup = GeneralCategory::name_to_enum_mapper(); /// // short name for value /// assert_eq!(lookup.get_strict("Lu"), Some(GeneralCategory::UppercaseLetter)); /// assert_eq!(lookup.get_strict("Pd"), Some(GeneralCategory::DashPunctuation)); /// // long name for value /// assert_eq!(lookup.get_strict("Uppercase_Letter"), Some(GeneralCategory::UppercaseLetter)); /// assert_eq!(lookup.get_strict("Dash_Punctuation"), Some(GeneralCategory::DashPunctuation)); /// // name has incorrect casing /// assert_eq!(lookup.get_strict("dashpunctuation"), None); /// // loose matching of name /// assert_eq!(lookup.get_loose("dash-punctuation"), Some(GeneralCategory::DashPunctuation)); /// // fake property /// assert_eq!(lookup.get_loose("Animated_Gif"), None); /// ``` pubfn get_name_to_enum_mapper() / name_to_enum_mapper(); /// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up short names /// for values of the `General_Category` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::GeneralCategory; /// /// let lookup = GeneralCategory::enum_to_short_name_mapper(); /// assert_eq!(lookup.get(GeneralCategory::UppercaseLetter), Some("Lu")); /// assert_eq!(lookup.get(GeneralCategory::DashPunctuation), Some("Pd")); /// assert_eq!(lookup.get(GeneralCategory::FinalPunctuation), Some("Pf")); /// ``` pubfn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed; /// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up long names /// for values of the `General_Category` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::GeneralCategory; /// /// let lookup = GeneralCategory::enum_to_long_name_mapper(); /// assert_eq!(lookup.get(GeneralCategory::UppercaseLetter), Some("Uppercase_Letter")); /// assert_eq!(lookup.get(GeneralCategory::DashPunctuation), Some("Dash_Punctuation")); /// assert_eq!(lookup.get(GeneralCategory::FinalPunctuation), Some("Final_Punctuation")); /// ``` pubfn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed;
}
}
impl TryFrom<u8> for GeneralCategory { type Error = GeneralCategoryTryFromError; /// Construct this [`GeneralCategory`] from an integer, returning /// an error if it is out of bounds fn try_from(val: u8) -> Result<Self, GeneralCategoryTryFromError> {
GeneralCategory::new_from_u8(val).ok_or(GeneralCategoryTryFromError)
}
}
/// Groupings of multiple General_Category property values. /// /// Instances of `GeneralCategoryGroup` represent the defined multi-category /// values that are useful for users in certain contexts, such as regex. In /// other words, unlike [`GeneralCategory`], this supports groups of general /// categories: for example, `Letter` /// is the union of `UppercaseLetter`, /// `LowercaseLetter`, etc. /// /// See <https://www.unicode.org/reports/tr44/> . /// /// The discriminants correspond to the `U_GC_XX_MASK` constants in ICU4C. /// Unlike [`GeneralCategory`], this supports groups of general categories: for example, `Letter` /// is the union of `UppercaseLetter`, `LowercaseLetter`, etc. /// /// See `UCharCategory` and `U_GET_GC_MASK` in ICU4C. #[derive(Copy, Clone, PartialEq, Debug, Eq)] #[allow(clippy::exhaustive_structs)] // newtype #[repr(transparent)] pubstruct GeneralCategoryGroup(pub(crate) u32);
use GeneralCategory as GC; use GeneralCategoryGroup as GCG;
#[allow(non_upper_case_globals)] impl GeneralCategoryGroup { /// (`Lu`) An uppercase letter pubconst UppercaseLetter: GeneralCategoryGroup = GCG(1 << (GC::UppercaseLetter as u32)); /// (`Ll`) A lowercase letter pubconst LowercaseLetter: GeneralCategoryGroup = GCG(1 << (GC::LowercaseLetter as u32)); /// (`Lt`) A digraphic letter, with first part uppercase pubconst TitlecaseLetter: GeneralCategoryGroup = GCG(1 << (GC::TitlecaseLetter as u32)); /// (`Lm`) A modifier letter pubconst ModifierLetter: GeneralCategoryGroup = GCG(1 << (GC::ModifierLetter as u32)); /// (`Lo`) Other letters, including syllables and ideographs pubconst OtherLetter: GeneralCategoryGroup = GCG(1 << (GC::OtherLetter as u32)); /// (`LC`) The union of UppercaseLetter, LowercaseLetter, and TitlecaseLetter pubconst CasedLetter: GeneralCategoryGroup = GCG(1 << (GC::UppercaseLetter as u32)
| 1 << (GC::LowercaseLetter as u32)
| 1 << (GC::TitlecaseLetter as u32)); /// (`L`) The union of all letter categories pubconst Letter: GeneralCategoryGroup = GCG(1 << (GC::UppercaseLetter as u32)
| 1 << (GC::LowercaseLetter as u32)
| 1 << (GC::TitlecaseLetter as u32)
| 1 << (GC::ModifierLetter as u32)
| 1 << (GC::OtherLetter as u32));
/// (`Mn`) A nonspacing combining mark (zero advance width) pubconst NonspacingMark: GeneralCategoryGroup = GCG(1 << (GC::NonspacingMark as u32)); /// (`Mc`) A spacing combining mark (positive advance width) pubconst EnclosingMark: GeneralCategoryGroup = GCG(1 << (GC::EnclosingMark as u32)); /// (`Me`) An enclosing combining mark pubconst SpacingMark: GeneralCategoryGroup = GCG(1 << (GC::SpacingMark as u32)); /// (`M`) The union of all mark categories pubconst Mark: GeneralCategoryGroup = GCG(1 << (GC::NonspacingMark as u32)
| 1 << (GC::EnclosingMark as u32)
| 1 << (GC::SpacingMark as u32));
/// (`Nd`) A decimal digit pubconst DecimalNumber: GeneralCategoryGroup = GCG(1 << (GC::DecimalNumber as u32)); /// (`Nl`) A letterlike numeric character pubconst LetterNumber: GeneralCategoryGroup = GCG(1 << (GC::LetterNumber as u32)); /// (`No`) A numeric character of other type pubconst OtherNumber: GeneralCategoryGroup = GCG(1 << (GC::OtherNumber as u32)); /// (`N`) The union of all number categories pubconst Number: GeneralCategoryGroup = GCG(1 << (GC::DecimalNumber as u32)
| 1 << (GC::LetterNumber as u32)
| 1 << (GC::OtherNumber as u32));
/// (`Zs`) A space character (of various non-zero widths) pubconst SpaceSeparator: GeneralCategoryGroup = GCG(1 << (GC::SpaceSeparator as u32)); /// (`Zl`) U+2028 LINE SEPARATOR only pubconst LineSeparator: GeneralCategoryGroup = GCG(1 << (GC::LineSeparator as u32)); /// (`Zp`) U+2029 PARAGRAPH SEPARATOR only pubconst ParagraphSeparator: GeneralCategoryGroup = GCG(1 << (GC::ParagraphSeparator as u32)); /// (`Z`) The union of all separator categories pubconst Separator: GeneralCategoryGroup = GCG(1 << (GC::SpaceSeparator as u32)
| 1 << (GC::LineSeparator as u32)
| 1 << (GC::ParagraphSeparator as u32));
/// (`Cc`) A C0 or C1 control code pubconst Control: GeneralCategoryGroup = GCG(1 << (GC::Control as u32)); /// (`Cf`) A format control character pubconst Format: GeneralCategoryGroup = GCG(1 << (GC::Format as u32)); /// (`Co`) A private-use character pubconst PrivateUse: GeneralCategoryGroup = GCG(1 << (GC::PrivateUse as u32)); /// (`Cs`) A surrogate code point pubconst Surrogate: GeneralCategoryGroup = GCG(1 << (GC::Surrogate as u32)); /// (`Cn`) A reserved unassigned code point or a noncharacter pubconst Unassigned: GeneralCategoryGroup = GCG(1 << (GC::Unassigned as u32)); /// (`C`) The union of all control code, reserved, and unassigned categories pubconst Other: GeneralCategoryGroup = GCG(1 << (GC::Control as u32)
| 1 << (GC::Format as u32)
| 1 << (GC::PrivateUse as u32)
| 1 << (GC::Surrogate as u32)
| 1 << (GC::Unassigned as u32));
/// (`Pd`) A dash or hyphen punctuation mark pubconst DashPunctuation: GeneralCategoryGroup = GCG(1 << (GC::DashPunctuation as u32)); /// (`Ps`) An opening punctuation mark (of a pair) pubconst OpenPunctuation: GeneralCategoryGroup = GCG(1 << (GC::OpenPunctuation as u32)); /// (`Pe`) A closing punctuation mark (of a pair) pubconst ClosePunctuation: GeneralCategoryGroup = GCG(1 << (GC::ClosePunctuation as u32)); /// (`Pc`) A connecting punctuation mark, like a tie pubconst ConnectorPunctuation: GeneralCategoryGroup =
GCG(1 << (GC::ConnectorPunctuation as u32)); /// (`Pi`) An initial quotation mark pubconst InitialPunctuation: GeneralCategoryGroup = GCG(1 << (GC::InitialPunctuation as u32)); /// (`Pf`) A final quotation mark pubconst FinalPunctuation: GeneralCategoryGroup = GCG(1 << (GC::FinalPunctuation as u32)); /// (`Po`) A punctuation mark of other type pubconst OtherPunctuation: GeneralCategoryGroup = GCG(1 << (GC::OtherPunctuation as u32)); /// (`P`) The union of all punctuation categories pubconst Punctuation: GeneralCategoryGroup = GCG(1 << (GC::DashPunctuation as u32)
| 1 << (GC::OpenPunctuation as u32)
| 1 << (GC::ClosePunctuation as u32)
| 1 << (GC::ConnectorPunctuation as u32)
| 1 << (GC::OtherPunctuation as u32)
| 1 << (GC::InitialPunctuation as u32)
| 1 << (GC::FinalPunctuation as u32));
/// (`Sm`) A symbol of mathematical use pubconst MathSymbol: GeneralCategoryGroup = GCG(1 << (GC::MathSymbol as u32)); /// (`Sc`) A currency sign pubconst CurrencySymbol: GeneralCategoryGroup = GCG(1 << (GC::CurrencySymbol as u32)); /// (`Sk`) A non-letterlike modifier symbol pubconst ModifierSymbol: GeneralCategoryGroup = GCG(1 << (GC::ModifierSymbol as u32)); /// (`So`) A symbol of other type pubconst OtherSymbol: GeneralCategoryGroup = GCG(1 << (GC::OtherSymbol as u32)); /// (`S`) The union of all symbol categories pubconst Symbol: GeneralCategoryGroup = GCG(1 << (GC::MathSymbol as u32)
| 1 << (GC::CurrencySymbol as u32)
| 1 << (GC::ModifierSymbol as u32)
| 1 << (GC::OtherSymbol as u32));
/// Produce a GeneralCategoryGroup that is the inverse of this one /// /// # Example /// /// ```rust /// use icu::properties::{GeneralCategory, GeneralCategoryGroup}; /// /// let letter = GeneralCategoryGroup::Letter; /// let not_letter = letter.complement(); /// /// assert!(not_letter.contains(GeneralCategory::MathSymbol)); /// assert!(!letter.contains(GeneralCategory::MathSymbol)); /// assert!(not_letter.contains(GeneralCategory::OtherPunctuation)); /// assert!(!letter.contains(GeneralCategory::OtherPunctuation)); /// assert!(!not_letter.contains(GeneralCategory::UppercaseLetter)); /// assert!(letter.contains(GeneralCategory::UppercaseLetter)); /// ``` pubconstfn complement(self) -> Self { // Mask off things not in Self::ALL to guarantee the mask // values stay in-range
GeneralCategoryGroup(!self.0 & Self::ALL)
}
/// Return the group representing all GeneralCategory values /// /// # Example /// /// ```rust /// use icu::properties::{GeneralCategory, GeneralCategoryGroup}; /// /// let all = GeneralCategoryGroup::all(); /// /// assert!(all.contains(GeneralCategory::MathSymbol)); /// assert!(all.contains(GeneralCategory::OtherPunctuation)); /// assert!(all.contains(GeneralCategory::UppercaseLetter)); /// ``` pubconstfn all() -> Self { Self(Self::ALL)
}
/// Return the empty group /// /// # Example /// /// ```rust /// use icu::properties::{GeneralCategory, GeneralCategoryGroup}; /// /// let empty = GeneralCategoryGroup::empty(); /// /// assert!(!empty.contains(GeneralCategory::MathSymbol)); /// assert!(!empty.contains(GeneralCategory::OtherPunctuation)); /// assert!(!empty.contains(GeneralCategory::UppercaseLetter)); /// ``` pubconstfn empty() -> Self { Self(0)
}
/// Take the union of two groups /// /// # Example /// /// ```rust /// use icu::properties::{GeneralCategory, GeneralCategoryGroup}; /// /// let letter = GeneralCategoryGroup::Letter; /// let symbol = GeneralCategoryGroup::Symbol; /// let union = letter.union(symbol); /// /// assert!(union.contains(GeneralCategory::MathSymbol)); /// assert!(!union.contains(GeneralCategory::OtherPunctuation)); /// assert!(union.contains(GeneralCategory::UppercaseLetter)); /// ``` pubconstfn union(self, other: Self) -> Self { Self(self.0 | other.0)
}
/// Take the intersection of two groups /// /// # Example /// /// ```rust /// use icu::properties::{GeneralCategory, GeneralCategoryGroup}; /// /// let letter = GeneralCategoryGroup::Letter; /// let lu = GeneralCategoryGroup::UppercaseLetter; /// let intersection = letter.intersection(lu); /// /// assert!(!intersection.contains(GeneralCategory::MathSymbol)); /// assert!(!intersection.contains(GeneralCategory::OtherPunctuation)); /// assert!(intersection.contains(GeneralCategory::UppercaseLetter)); /// assert!(!intersection.contains(GeneralCategory::LowercaseLetter)); /// ``` pubconstfn intersection(self, other: Self) -> Self { Self(self.0 & other.0)
}
}
impl_value_getter! {
markers: GeneralCategoryMaskNameToValueV1Marker / SINGLETON_PROPNAMES_FROM_GCM_V1; impl GeneralCategoryGroup { /// Return a [`PropertyValueNameToEnumMapper`], capable of looking up values /// from strings for the `General_Category_Mask` mask property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::GeneralCategoryGroup; /// /// let lookup = GeneralCategoryGroup::name_to_enum_mapper(); /// // short name for value /// assert_eq!(lookup.get_strict("L"), Some(GeneralCategoryGroup::Letter)); /// assert_eq!(lookup.get_strict("LC"), Some(GeneralCategoryGroup::CasedLetter)); /// assert_eq!(lookup.get_strict("Lu"), Some(GeneralCategoryGroup::UppercaseLetter)); /// assert_eq!(lookup.get_strict("Zp"), Some(GeneralCategoryGroup::ParagraphSeparator)); /// assert_eq!(lookup.get_strict("P"), Some(GeneralCategoryGroup::Punctuation)); /// // long name for value /// assert_eq!(lookup.get_strict("Letter"), Some(GeneralCategoryGroup::Letter)); /// assert_eq!(lookup.get_strict("Cased_Letter"), Some(GeneralCategoryGroup::CasedLetter)); /// assert_eq!(lookup.get_strict("Uppercase_Letter"), Some(GeneralCategoryGroup::UppercaseLetter)); /// // alias name /// assert_eq!(lookup.get_strict("punct"), Some(GeneralCategoryGroup::Punctuation)); /// // name has incorrect casing /// assert_eq!(lookup.get_strict("letter"), None); /// // loose matching of name /// assert_eq!(lookup.get_loose("letter"), Some(GeneralCategoryGroup::Letter)); /// // fake property /// assert_eq!(lookup.get_strict("EverythingLol"), None); /// ``` pubfn get_name_to_enum_mapper() / name_to_enum_mapper();
}
}
impl From<GeneralCategory> for GeneralCategoryGroup { fn from(subcategory: GeneralCategory) -> Self {
GeneralCategoryGroup(1 << (subcategory as u32))
}
} impl From<u32> for GeneralCategoryGroup { fn from(mask: u32) -> Self { // Mask off things not in Self::ALL to guarantee the mask // values stay in-range
GeneralCategoryGroup(mask & Self::ALL)
}
} impl From<GeneralCategoryGroup> for u32 { fn from(group: GeneralCategoryGroup) -> Self {
group.0
}
} /// Enumerated property Script. /// /// This is used with both the Script and Script_Extensions Unicode properties. /// Each character is assigned a single Script, but characters that are used in /// a particular subset of scripts will be in more than one Script_Extensions set. /// For example, DEVANAGARI DIGIT NINE has Script=Devanagari, but is also in the /// Script_Extensions set for Dogra, Kaithi, and Mahajani. /// /// For more information, see UAX #24: <http://www.unicode.org/reports/tr24/>. /// See `UScriptCode` in ICU4C. #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "datagen", derive(databake::Bake))] #[cfg_attr(feature = "datagen", databake(path = icu_properties))] #[allow(clippy::exhaustive_structs)] // newtype #[repr(transparent)] #[zerovec::make_ule(ScriptULE)] pubstruct Script(pub u16);
impl_value_getter! {
markers: ScriptNameToValueV1Marker / SINGLETON_PROPNAMES_FROM_SC_V1, ScriptValueToShortNameV1Marker / SINGLETON_PROPNAMES_TO_SHORT_LINEAR4_SC_V1, ScriptValueToLongNameV1Marker / SINGLETON_PROPNAMES_TO_LONG_LINEAR_SC_V1; impl Script { /// Return a [`PropertyValueNameToEnumMapper`], capable of looking up values /// from strings for the `Script` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::Script; /// /// let lookup = Script::name_to_enum_mapper(); /// // short name for value /// assert_eq!(lookup.get_strict("Brah"), Some(Script::Brahmi)); /// assert_eq!(lookup.get_strict("Hang"), Some(Script::Hangul)); /// // long name for value /// assert_eq!(lookup.get_strict("Brahmi"), Some(Script::Brahmi)); /// assert_eq!(lookup.get_strict("Hangul"), Some(Script::Hangul)); /// // name has incorrect casing /// assert_eq!(lookup.get_strict("brahmi"), None); /// // loose matching of name /// assert_eq!(lookup.get_loose("brahmi"), Some(Script::Brahmi)); /// // fake property /// assert_eq!(lookup.get_strict("Linear_Z"), None); /// ``` pubfn get_name_to_enum_mapper() / name_to_enum_mapper(); /// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up short names /// for values of the `Script` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::Script; /// use tinystr::tinystr; /// /// let lookup = Script::enum_to_short_name_mapper(); /// assert_eq!(lookup.get(Script::Brahmi), Some(tinystr!(4, "Brah"))); /// assert_eq!(lookup.get(Script::Hangul), Some(tinystr!(4, "Hang"))); /// ``` pubfn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameLinearTiny4Mapper / PropertyEnumToValueNameLinearTiny4MapperBorrowed; /// Return a [`PropertyEnumToValueNameLinearTiny4Mapper`], capable of looking up long names /// for values of the `Script` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::Script; /// /// let lookup = Script::enum_to_long_name_mapper(); /// assert_eq!(lookup.get(Script::Brahmi), Some("Brahmi")); /// assert_eq!(lookup.get(Script::Hangul), Some("Hangul")); /// ``` pubfn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed;
}
}
/// Enumerated property Hangul_Syllable_Type /// /// The Unicode standard provides both precomposed Hangul syllables and conjoining Jamo to compose /// arbitrary Hangul syllables. This property provies that ontology of Hangul code points. /// /// For more information, see the [Unicode Korean FAQ](https://www.unicode.org/faq/korean.html). #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "datagen", derive(databake::Bake))] #[cfg_attr(feature = "datagen", databake(path = icu_properties))] #[allow(clippy::exhaustive_structs)] // newtype #[repr(transparent)] #[zerovec::make_ule(HangulSyllableTypeULE)] pubstruct HangulSyllableType(pub u8);
create_const_array! { #[allow(non_upper_case_globals)] impl HangulSyllableType { /// (`NA`) not applicable (e.g. not a Hangul code point). pubconst NotApplicable: HangulSyllableType = HangulSyllableType(0); /// (`L`) a conjoining leading consonant Jamo. pubconst LeadingJamo: HangulSyllableType = HangulSyllableType(1); /// (`V`) a conjoining vowel Jamo. pubconst VowelJamo: HangulSyllableType = HangulSyllableType(2); /// (`T`) a conjoining trailing consonent Jamo. pubconst TrailingJamo: HangulSyllableType = HangulSyllableType(3); /// (`LV`) a precomposed syllable with a leading consonant and a vowel. pubconst LeadingVowelSyllable: HangulSyllableType = HangulSyllableType(4); /// (`LVT`) a precomposed syllable with a leading consonant, a vowel, and a trailing consonant. pubconst LeadingVowelTrailingSyllable: HangulSyllableType = HangulSyllableType(5);
}
}
impl_value_getter! {
markers: HangulSyllableTypeNameToValueV1Marker / SINGLETON_PROPNAMES_FROM_HST_V1, HangulSyllableTypeValueToShortNameV1Marker / SINGLETON_PROPNAMES_TO_SHORT_LINEAR_HST_V1, HangulSyllableTypeValueToLongNameV1Marker / SINGLETON_PROPNAMES_TO_LONG_LINEAR_HST_V1; impl HangulSyllableType { /// Return a [`PropertyValueNameToEnumMapper`], capable of looking up values /// from strings for the `Bidi_Class` enumerated property /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::HangulSyllableType; /// /// let lookup = HangulSyllableType::name_to_enum_mapper(); /// // short name for value /// assert_eq!(lookup.get_strict("L"), Some(HangulSyllableType::LeadingJamo)); /// assert_eq!(lookup.get_strict("LV"), Some(HangulSyllableType::LeadingVowelSyllable)); /// // long name for value /// assert_eq!(lookup.get_strict("Leading_Jamo"), Some(HangulSyllableType::LeadingJamo)); /// assert_eq!(lookup.get_strict("LV_Syllable"), Some(HangulSyllableType::LeadingVowelSyllable)); /// // name has incorrect casing /// assert_eq!(lookup.get_strict("lv"), None); /// // loose matching of name /// assert_eq!(lookup.get_loose("lv"), Some(HangulSyllableType::LeadingVowelSyllable)); /// // fake property /// assert_eq!(lookup.get_strict("LT_Syllable"), None); /// ``` pubfn get_name_to_enum_mapper() / name_to_enum_mapper(); /// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up short names /// for values of the `Bidi_Class` enumerated property /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::HangulSyllableType; /// /// let lookup = HangulSyllableType::enum_to_short_name_mapper(); /// assert_eq!(lookup.get(HangulSyllableType::LeadingJamo), Some("L")); /// assert_eq!(lookup.get(HangulSyllableType::LeadingVowelSyllable), Some("LV")); /// ``` pubfn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed; /// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up long names /// for values of the `Bidi_Class` enumerated property /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::HangulSyllableType; /// /// let lookup = HangulSyllableType::enum_to_long_name_mapper(); /// assert_eq!(lookup.get(HangulSyllableType::LeadingJamo), Some("Leading_Jamo")); /// assert_eq!(lookup.get(HangulSyllableType::LeadingVowelSyllable), Some("LV_Syllable")); /// ``` pubfn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed;
}
}
/// Enumerated property East_Asian_Width. /// /// See "Definition" in UAX #11 for the summary of each property value: /// <https://www.unicode.org/reports/tr11/#Definitions> /// /// The numeric value is compatible with `UEastAsianWidth` in ICU4C. #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "datagen", derive(databake::Bake))] #[cfg_attr(feature = "datagen", databake(path = icu_properties))] #[allow(clippy::exhaustive_structs)] // newtype #[repr(transparent)] #[zerovec::make_ule(EastAsianWidthULE)] pubstruct EastAsianWidth(pub u8);
impl_value_getter! {
markers: EastAsianWidthNameToValueV1Marker / SINGLETON_PROPNAMES_FROM_EA_V1, EastAsianWidthValueToShortNameV1Marker / SINGLETON_PROPNAMES_TO_SHORT_LINEAR_EA_V1, EastAsianWidthValueToLongNameV1Marker / SINGLETON_PROPNAMES_TO_LONG_LINEAR_EA_V1; impl EastAsianWidth { /// Return a [`PropertyValueNameToEnumMapper`], capable of looking up values /// from strings for the `East_Asian_Width` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::EastAsianWidth; /// /// let lookup = EastAsianWidth::name_to_enum_mapper(); /// // short name for value /// assert_eq!(lookup.get_strict("N"), Some(EastAsianWidth::Neutral)); /// assert_eq!(lookup.get_strict("H"), Some(EastAsianWidth::Halfwidth)); /// // long name for value /// assert_eq!(lookup.get_strict("Neutral"), Some(EastAsianWidth::Neutral)); /// assert_eq!(lookup.get_strict("Halfwidth"), Some(EastAsianWidth::Halfwidth)); /// // name has incorrect casing / extra hyphen /// assert_eq!(lookup.get_strict("half-width"), None); /// // loose matching of name /// assert_eq!(lookup.get_loose("half-width"), Some(EastAsianWidth::Halfwidth)); /// // fake property /// assert_eq!(lookup.get_strict("TwoPointFiveWidth"), None); /// ``` pubfn get_name_to_enum_mapper() / name_to_enum_mapper(); /// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up short names /// for values of the `East_Asian_Width` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::EastAsianWidth; /// /// let lookup = EastAsianWidth::enum_to_short_name_mapper(); /// assert_eq!(lookup.get(EastAsianWidth::Neutral), Some("N")); /// assert_eq!(lookup.get(EastAsianWidth::Halfwidth), Some("H")); /// ``` pubfn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed; /// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up long names /// for values of the `East_Asian_Width` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::EastAsianWidth; /// /// let lookup = EastAsianWidth::enum_to_long_name_mapper(); /// assert_eq!(lookup.get(EastAsianWidth::Neutral), Some("Neutral")); /// assert_eq!(lookup.get(EastAsianWidth::Halfwidth), Some("Halfwidth")); /// ``` pubfn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed;
}
}
/// Enumerated property Line_Break. /// /// See "Line Breaking Properties" in UAX #14 for the summary of each property /// value: <https://www.unicode.org/reports/tr14/#Properties> /// /// The numeric value is compatible with `ULineBreak` in ICU4C. #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "datagen", derive(databake::Bake))] #[cfg_attr(feature = "datagen", databake(path = icu_properties))] #[allow(clippy::exhaustive_structs)] // newtype #[repr(transparent)] #[zerovec::make_ule(LineBreakULE)] pubstruct LineBreak(pub u8);
impl_value_getter! {
markers: LineBreakNameToValueV1Marker / SINGLETON_PROPNAMES_FROM_LB_V1, LineBreakValueToShortNameV1Marker / SINGLETON_PROPNAMES_TO_SHORT_LINEAR_LB_V1, LineBreakValueToLongNameV1Marker / SINGLETON_PROPNAMES_TO_LONG_LINEAR_LB_V1; impl LineBreak { /// Return a [`PropertyValueNameToEnumMapper`], capable of looking up values /// from strings for the `Line_Break` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::LineBreak; /// /// let lookup = LineBreak::name_to_enum_mapper(); /// // short name for value /// assert_eq!(lookup.get_strict("BK"), Some(LineBreak::MandatoryBreak)); /// assert_eq!(lookup.get_strict("AL"), Some(LineBreak::Alphabetic)); /// // long name for value /// assert_eq!(lookup.get_strict("Mandatory_Break"), Some(LineBreak::MandatoryBreak)); /// assert_eq!(lookup.get_strict("Alphabetic"), Some(LineBreak::Alphabetic)); /// // name has incorrect casing and dash instead of underscore /// assert_eq!(lookup.get_strict("mandatory-Break"), None); /// // loose matching of name /// assert_eq!(lookup.get_loose("mandatory-Break"), Some(LineBreak::MandatoryBreak)); /// // fake property /// assert_eq!(lookup.get_strict("Stochastic_Break"), None); /// ``` pubfn get_name_to_enum_mapper() / name_to_enum_mapper(); /// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up short names /// for values of the `Line_Break` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::LineBreak; /// /// let lookup = LineBreak::enum_to_short_name_mapper(); /// assert_eq!(lookup.get(LineBreak::MandatoryBreak), Some("BK")); /// assert_eq!(lookup.get(LineBreak::Alphabetic), Some("AL")); /// ``` pubfn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed; /// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up long names /// for values of the `Line_Break` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::LineBreak; /// /// let lookup = LineBreak::enum_to_long_name_mapper(); /// assert_eq!(lookup.get(LineBreak::MandatoryBreak), Some("Mandatory_Break")); /// assert_eq!(lookup.get(LineBreak::Alphabetic), Some("Alphabetic")); /// ``` pubfn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed;
}
}
/// Enumerated property Grapheme_Cluster_Break. /// /// See "Default Grapheme Cluster Boundary Specification" in UAX #29 for the /// summary of each property value: /// <https://www.unicode.org/reports/tr29/#Default_Grapheme_Cluster_Table> /// /// The numeric value is compatible with `UGraphemeClusterBreak` in ICU4C. #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "datagen", derive(databake::Bake))] #[cfg_attr(feature = "datagen", databake(path = icu_properties))] #[allow(clippy::exhaustive_structs)] // this type is stable #[repr(transparent)] #[zerovec::make_ule(GraphemeClusterBreakULE)] pubstruct GraphemeClusterBreak(pub u8);
#[allow(missing_docs)] // These constants don't need individual documentation. #[allow(non_upper_case_globals)] impl GraphemeClusterBreak { pubconst Other: GraphemeClusterBreak = GraphemeClusterBreak(0); // name="XX" pubconst Control: GraphemeClusterBreak = GraphemeClusterBreak(1); // name="CN" pubconst CR: GraphemeClusterBreak = GraphemeClusterBreak(2); // name="CR" pubconst Extend: GraphemeClusterBreak = GraphemeClusterBreak(3); // name="EX" pubconst L: GraphemeClusterBreak = GraphemeClusterBreak(4); // name="L" pubconst LF: GraphemeClusterBreak = GraphemeClusterBreak(5); // name="LF" pubconst LV: GraphemeClusterBreak = GraphemeClusterBreak(6); // name="LV" pubconst LVT: GraphemeClusterBreak = GraphemeClusterBreak(7); // name="LVT" pubconst T: GraphemeClusterBreak = GraphemeClusterBreak(8); // name="T" pubconst V: GraphemeClusterBreak = GraphemeClusterBreak(9); // name="V" pubconst SpacingMark: GraphemeClusterBreak = GraphemeClusterBreak(10); // name="SM" pubconst Prepend: GraphemeClusterBreak = GraphemeClusterBreak(11); // name="PP" pubconst RegionalIndicator: GraphemeClusterBreak = GraphemeClusterBreak(12); // name="RI" /// This value is obsolete and unused. pubconst EBase: GraphemeClusterBreak = GraphemeClusterBreak(13); // name="EB" /// This value is obsolete and unused. pubconst EBaseGAZ: GraphemeClusterBreak = GraphemeClusterBreak(14); // name="EBG" /// This value is obsolete and unused. pubconst EModifier: GraphemeClusterBreak = GraphemeClusterBreak(15); // name="EM" /// This value is obsolete and unused. pubconst GlueAfterZwj: GraphemeClusterBreak = GraphemeClusterBreak(16); // name="GAZ" pubconst ZWJ: GraphemeClusterBreak = GraphemeClusterBreak(17); // name="ZWJ"
}
impl_value_getter! {
markers: GraphemeClusterBreakNameToValueV1Marker / SINGLETON_PROPNAMES_FROM_GCB_V1, GraphemeClusterBreakValueToShortNameV1Marker / SINGLETON_PROPNAMES_TO_SHORT_LINEAR_GCB_V1, GraphemeClusterBreakValueToLongNameV1Marker / SINGLETON_PROPNAMES_TO_LONG_LINEAR_GCB_V1; impl GraphemeClusterBreak { /// Return a [`PropertyValueNameToEnumMapper`], capable of looking up values /// from strings for the `Grapheme_Cluster_Break` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::GraphemeClusterBreak; /// /// let lookup = GraphemeClusterBreak::name_to_enum_mapper(); /// // short name for value /// assert_eq!(lookup.get_strict("EX"), Some(GraphemeClusterBreak::Extend)); /// assert_eq!(lookup.get_strict("RI"), Some(GraphemeClusterBreak::RegionalIndicator)); /// // long name for value /// assert_eq!(lookup.get_strict("Extend"), Some(GraphemeClusterBreak::Extend)); /// assert_eq!(lookup.get_strict("Regional_Indicator"), Some(GraphemeClusterBreak::RegionalIndicator)); /// // name has incorrect casing and lacks an underscore /// assert_eq!(lookup.get_strict("regionalindicator"), None); /// // loose matching of name /// assert_eq!(lookup.get_loose("regionalindicator"), Some(GraphemeClusterBreak::RegionalIndicator)); /// // fake property /// assert_eq!(lookup.get_strict("Regional_Indicator_Two_Point_Oh"), None); /// ``` pubfn get_name_to_enum_mapper() / name_to_enum_mapper(); /// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up short names /// for values of the `Grapheme_Cluster_Break` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::GraphemeClusterBreak; /// /// let lookup = GraphemeClusterBreak::enum_to_short_name_mapper(); /// assert_eq!(lookup.get(GraphemeClusterBreak::Extend), Some("EX")); /// assert_eq!(lookup.get(GraphemeClusterBreak::RegionalIndicator), Some("RI")); /// ``` pubfn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed; /// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up long names /// for values of the `Grapheme_Cluster_Break` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::GraphemeClusterBreak; /// /// let lookup = GraphemeClusterBreak::enum_to_long_name_mapper(); /// assert_eq!(lookup.get(GraphemeClusterBreak::Extend), Some("Extend")); /// assert_eq!(lookup.get(GraphemeClusterBreak::RegionalIndicator), Some("Regional_Indicator")); /// ``` pubfn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed;
}
}
/// Enumerated property Word_Break. /// /// See "Default Word Boundary Specification" in UAX #29 for the summary of /// each property value: /// <https://www.unicode.org/reports/tr29/#Default_Word_Boundaries>. /// /// The numeric value is compatible with `UWordBreakValues` in ICU4C. #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "datagen", derive(databake::Bake))] #[cfg_attr(feature = "datagen", databake(path = icu_properties))] #[allow(clippy::exhaustive_structs)] // newtype #[repr(transparent)] #[zerovec::make_ule(WordBreakULE)] pubstruct WordBreak(pub u8);
impl_value_getter! {
markers: WordBreakNameToValueV1Marker / SINGLETON_PROPNAMES_FROM_WB_V1, WordBreakValueToShortNameV1Marker / SINGLETON_PROPNAMES_TO_SHORT_LINEAR_WB_V1, WordBreakValueToLongNameV1Marker / SINGLETON_PROPNAMES_TO_LONG_LINEAR_WB_V1; impl WordBreak { /// Return a [`PropertyValueNameToEnumMapper`], capable of looking up values /// from strings for the `Word_Break` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::WordBreak; /// /// let lookup = WordBreak::name_to_enum_mapper(); /// // short name for value /// assert_eq!(lookup.get_strict("KA"), Some(WordBreak::Katakana)); /// assert_eq!(lookup.get_strict("LE"), Some(WordBreak::ALetter)); /// // long name for value /// assert_eq!(lookup.get_strict("Katakana"), Some(WordBreak::Katakana)); /// assert_eq!(lookup.get_strict("ALetter"), Some(WordBreak::ALetter)); /// // name has incorrect casing /// assert_eq!(lookup.get_strict("Aletter"), None); /// // loose matching of name /// assert_eq!(lookup.get_loose("Aletter"), Some(WordBreak::ALetter)); /// assert_eq!(lookup.get_loose("w_seg_space"), Some(WordBreak::WSegSpace)); /// // fake property /// assert_eq!(lookup.get_strict("Quadruple_Quote"), None); /// ``` pubfn get_name_to_enum_mapper() / name_to_enum_mapper(); /// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up short names /// for values of the `Word_Break` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::WordBreak; /// /// let lookup = WordBreak::enum_to_short_name_mapper(); /// assert_eq!(lookup.get(WordBreak::Katakana), Some("KA")); /// assert_eq!(lookup.get(WordBreak::ALetter), Some("LE")); /// assert_eq!(lookup.get(WordBreak::WSegSpace), Some("WSegSpace")); /// ``` pubfn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed; /// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up long names /// for values of the `Word_Break` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::WordBreak; /// /// let lookup = WordBreak::enum_to_long_name_mapper(); /// assert_eq!(lookup.get(WordBreak::Katakana), Some("Katakana")); /// assert_eq!(lookup.get(WordBreak::ALetter), Some("ALetter")); /// assert_eq!(lookup.get(WordBreak::WSegSpace), Some("WSegSpace")); /// ``` pubfn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed;
}
}
/// Enumerated property Sentence_Break. /// See "Default Sentence Boundary Specification" in UAX #29 for the summary of /// each property value: /// <https://www.unicode.org/reports/tr29/#Default_Word_Boundaries>. /// /// The numeric value is compatible with `USentenceBreak` in ICU4C. #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "datagen", derive(databake::Bake))] #[cfg_attr(feature = "datagen", databake(path = icu_properties))] #[allow(clippy::exhaustive_structs)] // newtype #[repr(transparent)] #[zerovec::make_ule(SentenceBreakULE)] pubstruct SentenceBreak(pub u8);
impl_value_getter! {
markers: SentenceBreakNameToValueV1Marker / SINGLETON_PROPNAMES_FROM_SB_V1, SentenceBreakValueToShortNameV1Marker / SINGLETON_PROPNAMES_TO_SHORT_LINEAR_SB_V1, SentenceBreakValueToLongNameV1Marker / SINGLETON_PROPNAMES_TO_LONG_LINEAR_SB_V1; impl SentenceBreak { /// Return a [`PropertyValueNameToEnumMapper`], capable of looking up values /// from strings for the `Sentence_Break` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::SentenceBreak; /// /// let lookup = SentenceBreak::name_to_enum_mapper(); /// // short name for value /// assert_eq!(lookup.get_strict("FO"), Some(SentenceBreak::Format)); /// assert_eq!(lookup.get_strict("NU"), Some(SentenceBreak::Numeric)); /// // long name for value /// assert_eq!(lookup.get_strict("Format"), Some(SentenceBreak::Format)); /// assert_eq!(lookup.get_strict("Numeric"), Some(SentenceBreak::Numeric)); /// // name has incorrect casing /// assert_eq!(lookup.get_strict("fOrmat"), None); /// // loose matching of name /// assert_eq!(lookup.get_loose("fOrmat"), Some(SentenceBreak::Format)); /// // fake property /// assert_eq!(lookup.get_strict("Fixer_Upper"), None); /// ``` pubfn get_name_to_enum_mapper() / name_to_enum_mapper(); /// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up short names /// for values of the `Sentence_Break` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::SentenceBreak; /// /// let lookup = SentenceBreak::enum_to_short_name_mapper(); /// assert_eq!(lookup.get(SentenceBreak::Format), Some("FO")); /// assert_eq!(lookup.get(SentenceBreak::Numeric), Some("NU")); /// ``` pubfn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed; /// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up long names /// for values of the `Sentence_Break` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::SentenceBreak; /// /// let lookup = SentenceBreak::enum_to_long_name_mapper(); /// assert_eq!(lookup.get(SentenceBreak::Format), Some("Format")); /// assert_eq!(lookup.get(SentenceBreak::Numeric), Some("Numeric")); /// assert_eq!(lookup.get(SentenceBreak::SContinue), Some("SContinue")); /// ``` pubfn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed;
}
} /// Property Canonical_Combining_Class. /// See UAX #15: /// <https://www.unicode.org/reports/tr15/>. /// /// See `icu::normalizer::properties::CanonicalCombiningClassMap` for the API /// to look up the Canonical_Combining_Class property by scalar value. // // NOTE: The Pernosco debugger has special knowledge // of this struct. Please do not change the bit layout // or the crate-module-qualified name of this struct // without coordination. #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "datagen", derive(databake::Bake))] #[cfg_attr(feature = "datagen", databake(path = icu_properties))] #[allow(clippy::exhaustive_structs)] // newtype #[repr(transparent)] #[zerovec::make_ule(CanonicalCombiningClassULE)] pubstruct CanonicalCombiningClass(pub u8);
impl_value_getter! {
markers: CanonicalCombiningClassNameToValueV1Marker / SINGLETON_PROPNAMES_FROM_CCC_V1, CanonicalCombiningClassValueToShortNameV1Marker / SINGLETON_PROPNAMES_TO_SHORT_SPARSE_CCC_V1, CanonicalCombiningClassValueToLongNameV1Marker / SINGLETON_PROPNAMES_TO_LONG_SPARSE_CCC_V1; impl CanonicalCombiningClass { /// Return a [`PropertyValueNameToEnumMapper`], capable of looking up values /// from strings for the `Canonical_Combining_Class` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::CanonicalCombiningClass; /// /// let lookup = CanonicalCombiningClass::name_to_enum_mapper(); /// // short name for value /// assert_eq!(lookup.get_strict("AL"), Some(CanonicalCombiningClass::AboveLeft)); /// assert_eq!(lookup.get_strict("ATBL"), Some(CanonicalCombiningClass::AttachedBelowLeft)); /// assert_eq!(lookup.get_strict("CCC10"), Some(CanonicalCombiningClass::CCC10)); /// // long name for value /// assert_eq!(lookup.get_strict("Above_Left"), Some(CanonicalCombiningClass::AboveLeft)); /// assert_eq!(lookup.get_strict("Attached_Below_Left"), Some(CanonicalCombiningClass::AttachedBelowLeft)); /// // name has incorrect casing and hyphens /// assert_eq!(lookup.get_strict("attached-below-left"), None); /// // loose matching of name /// assert_eq!(lookup.get_loose("attached-below-left"), Some(CanonicalCombiningClass::AttachedBelowLeft)); /// // fake property /// assert_eq!(lookup.get_strict("Linear_Z"), None); /// ``` pubfn get_name_to_enum_mapper() / name_to_enum_mapper(); /// Return a [`PropertyEnumToValueNameSparseMapper`], capable of looking up short names /// for values of the `Canonical_Combining_Class` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::CanonicalCombiningClass; /// /// let lookup = CanonicalCombiningClass::enum_to_short_name_mapper(); /// assert_eq!(lookup.get(CanonicalCombiningClass::AboveLeft), Some("AL")); /// assert_eq!(lookup.get(CanonicalCombiningClass::AttachedBelowLeft), Some("ATBL")); /// assert_eq!(lookup.get(CanonicalCombiningClass::CCC10), Some("CCC10")); /// ``` pubfn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameSparseMapper / PropertyEnumToValueNameSparseMapperBorrowed; /// Return a [`PropertyEnumToValueNameSparseMapper`], capable of looking up long names /// for values of the `Canonical_Combining_Class` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::CanonicalCombiningClass; /// /// let lookup = CanonicalCombiningClass::enum_to_long_name_mapper(); /// assert_eq!(lookup.get(CanonicalCombiningClass::AboveLeft), Some("Above_Left")); /// assert_eq!(lookup.get(CanonicalCombiningClass::AttachedBelowLeft), Some("Attached_Below_Left")); /// assert_eq!(lookup.get(CanonicalCombiningClass::CCC10), Some("CCC10")); /// ``` pubfn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameSparseMapper / PropertyEnumToValueNameSparseMapperBorrowed;
}
}
/// Property Indic_Syllabic_Category. /// See UAX #44: /// <https://www.unicode.org/reports/tr44/#Indic_Syllabic_Category>. /// /// The numeric value is compatible with `UIndicSyllabicCategory` in ICU4C. #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "datagen", derive(databake::Bake))] #[cfg_attr(feature = "datagen", databake(path = icu_properties))] #[allow(clippy::exhaustive_structs)] // newtype #[repr(transparent)] #[zerovec::make_ule(IndicSyllabicCategoryULE)] pubstruct IndicSyllabicCategory(pub u8);
impl_value_getter! {
markers: IndicSyllabicCategoryNameToValueV1Marker / SINGLETON_PROPNAMES_FROM_INSC_V1, IndicSyllabicCategoryValueToShortNameV1Marker / SINGLETON_PROPNAMES_TO_SHORT_LINEAR_INSC_V1, IndicSyllabicCategoryValueToLongNameV1Marker / SINGLETON_PROPNAMES_TO_LONG_LINEAR_INSC_V1; impl IndicSyllabicCategory { /// Return a [`PropertyValueNameToEnumMapper`], capable of looking up values /// from strings for the `Indic_Syllabic_Category` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::IndicSyllabicCategory; /// /// let lookup = IndicSyllabicCategory::name_to_enum_mapper(); /// // long/short name for value /// assert_eq!(lookup.get_strict("Brahmi_Joining_Number"), Some(IndicSyllabicCategory::BrahmiJoiningNumber)); /// assert_eq!(lookup.get_strict("Vowel_Independent"), Some(IndicSyllabicCategory::VowelIndependent)); /// // name has incorrect casing and hyphens /// assert_eq!(lookup.get_strict("brahmi-joining-number"), None); /// // loose matching of name /// assert_eq!(lookup.get_loose("brahmi-joining-number"), Some(IndicSyllabicCategory::BrahmiJoiningNumber)); /// // fake property /// assert_eq!(lookup.get_strict("Tone_Number"), None); /// ``` pubfn get_name_to_enum_mapper() / name_to_enum_mapper(); /// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up short names /// for values of the `Indic_Syllabic_Category` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::IndicSyllabicCategory; /// /// let lookup = IndicSyllabicCategory::enum_to_short_name_mapper(); /// assert_eq!(lookup.get(IndicSyllabicCategory::BrahmiJoiningNumber), Some("Brahmi_Joining_Number")); /// assert_eq!(lookup.get(IndicSyllabicCategory::VowelIndependent), Some("Vowel_Independent")); /// ``` pubfn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed; /// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up long names /// for values of the `Indic_Syllabic_Category` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::IndicSyllabicCategory; /// /// let lookup = IndicSyllabicCategory::enum_to_long_name_mapper(); /// assert_eq!(lookup.get(IndicSyllabicCategory::BrahmiJoiningNumber), Some("Brahmi_Joining_Number")); /// assert_eq!(lookup.get(IndicSyllabicCategory::VowelIndependent), Some("Vowel_Independent")); /// ``` pubfn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed;
}
} /// Enumerated property Joining_Type. /// See Section 9.2, Arabic Cursive Joining in The Unicode Standard for the summary of /// each property value. /// /// The numeric value is compatible with `UJoiningType` in ICU4C. #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "datagen", derive(databake::Bake))] #[cfg_attr(feature = "datagen", databake(path = icu_properties))] #[allow(clippy::exhaustive_structs)] // newtype #[repr(transparent)] #[zerovec::make_ule(JoiningTypeULE)] pubstruct JoiningType(pub u8);
impl_value_getter! {
markers: JoiningTypeNameToValueV1Marker / SINGLETON_PROPNAMES_FROM_JT_V1, JoiningTypeValueToShortNameV1Marker / SINGLETON_PROPNAMES_TO_SHORT_LINEAR_JT_V1, JoiningTypeValueToLongNameV1Marker / SINGLETON_PROPNAMES_TO_LONG_LINEAR_JT_V1; impl JoiningType { /// Return a [`PropertyValueNameToEnumMapper`], capable of looking up values /// from strings for the `Joining_Type` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::JoiningType; /// /// let lookup = JoiningType::name_to_enum_mapper(); /// // short name for value /// assert_eq!(lookup.get_strict("T"), Some(JoiningType::Transparent)); /// assert_eq!(lookup.get_strict("D"), Some(JoiningType::DualJoining)); /// // long name for value /// assert_eq!(lookup.get_strict("Join_Causing"), Some(JoiningType::JoinCausing)); /// assert_eq!(lookup.get_strict("Non_Joining"), Some(JoiningType::NonJoining)); /// // name has incorrect casing /// assert_eq!(lookup.get_strict("LEFT_JOINING"), None); /// // loose matching of name /// assert_eq!(lookup.get_loose("LEFT_JOINING"), Some(JoiningType::LeftJoining)); /// // fake property /// assert_eq!(lookup.get_strict("Inner_Joining"), None); /// ``` pubfn get_name_to_enum_mapper() / name_to_enum_mapper(); /// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up short names /// for values of the `Joining_Type` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::JoiningType; /// /// let lookup = JoiningType::enum_to_short_name_mapper(); /// assert_eq!(lookup.get(JoiningType::JoinCausing), Some("C")); /// assert_eq!(lookup.get(JoiningType::LeftJoining), Some("L")); /// ``` pubfn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed; /// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up long names /// for values of the `Joining_Type` enumerated property. /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// /// [ Help choosing a constructor](icu_provider::constructors) /// /// # Example /// /// ``` /// use icu::properties::JoiningType; /// /// let lookup = JoiningType::enum_to_long_name_mapper(); /// assert_eq!(lookup.get(JoiningType::Transparent), Some("Transparent")); /// assert_eq!(lookup.get(JoiningType::NonJoining), Some("Non_Joining")); /// assert_eq!(lookup.get(JoiningType::RightJoining), Some("Right_Joining")); /// ``` pubfn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed;
}
} #[cfg(test)] mod test_enumerated_property_completeness { usesuper::*; use alloc::collections::BTreeMap;
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.