Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions components/properties/src/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,14 @@ impl_value_getter! {
}
}

impl_value_getter! {
impl NumericType {
PropertyNameParseNumericTypeV1 / SINGLETON_PROPERTY_NAME_PARSE_NUMERIC_TYPE_V1;
PropertyEnumToValueNameLinearMap / PropertyNameShortNumericTypeV1 / SINGLETON_PROPERTY_NAME_SHORT_NUMERIC_TYPE_V1;
PropertyEnumToValueNameLinearMap / PropertyNameLongNumericTypeV1 / SINGLETON_PROPERTY_NAME_LONG_NUMERIC_TYPE_V1;
}
}

impl_value_getter! {
impl GeneralCategory {
PropertyNameParseGeneralCategoryV1 / SINGLETON_PROPERTY_NAME_PARSE_GENERAL_CATEGORY_V1;
Expand Down
73 changes: 73 additions & 0 deletions components/properties/src/props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,71 @@ macro_rules! make_enumerated_property {
};
}

/// Enumerated property Numeric_Type.
///
/// See Section 4.6, Numeric Value in The Unicode Standard for the summary of
/// each property value.
///
/// # Example
///
/// ```
/// use icu::properties::{props::NumericType, CodePointMapData};
///
/// assert_eq!(
/// CodePointMapData::<NumericType>::new().get('0'),
/// NumericType::Decimal,
/// ); // U+0030
/// assert_eq!(
/// CodePointMapData::<NumericType>::new().get('½'),
/// NumericType::Numeric,
/// ); // U+00BD
/// ```
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[allow(clippy::exhaustive_structs)] // newtype
#[repr(transparent)]
pub struct NumericType(pub(crate) u8);

impl NumericType {
/// Returns an ICU4C `UNumericType` value.
pub const fn to_icu4c_value(self) -> u8 {
self.0
}
/// Constructor from an ICU4C `UNumericType` value.
pub const fn from_icu4c_value(value: u8) -> Self {
Self(value)
}
}

create_const_array! {
#[allow(non_upper_case_globals)]
impl NumericType {
/// Characters without numeric value
pub const None: NumericType = NumericType(0);
/// (`De`) Characters of positional decimal systems
///
/// These are coextensive with [`GeneralCategory::DecimalNumber`].
pub const Decimal: NumericType = NumericType(1);
/// (`Di`) Variants of positional or sequences thereof.
///
/// The distinction between [`NumericType::Digit`] and [`NumericType::Numeric`]
/// has not proven to be useful, so no further characters will be added to
/// this type.
pub const Digit: NumericType = NumericType(2);
/// (`Nu`) Other characters with numeric value
pub const Numeric: NumericType = NumericType(3);
}
}

make_enumerated_property! {
name: "Numeric_Type";
short_name: "nt";
ident: NumericType;
data_marker: crate::provider::PropertyEnumNumericTypeV1;
singleton: SINGLETON_PROPERTY_ENUM_NUMERIC_TYPE_V1;
ule_ty: u8;
}

/// Enumerated property Bidi_Class
///
/// These are the categories required by the Unicode Bidirectional Algorithm.
Expand Down Expand Up @@ -3303,6 +3368,14 @@ mod test_enumerated_property_completeness {
);
}

#[test]
fn test_nt() {
check_enum(
crate::provider::Baked::SINGLETON_PROPERTY_NAME_PARSE_NUMERIC_TYPE_V1,
NumericType::ALL_VALUES,
);
}

#[test]
fn test_hst() {
check_enum(
Expand Down
37 changes: 26 additions & 11 deletions components/properties/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,22 @@ pub use names::{
PropertyNameLongBidiClassV1, PropertyNameLongEastAsianWidthV1,
PropertyNameLongGeneralCategoryV1, PropertyNameLongGraphemeClusterBreakV1,
PropertyNameLongHangulSyllableTypeV1, PropertyNameLongIndicSyllabicCategoryV1,
PropertyNameLongJoiningTypeV1, PropertyNameLongLineBreakV1, PropertyNameLongScriptV1,
PropertyNameLongSentenceBreakV1, PropertyNameLongVerticalOrientationV1,
PropertyNameLongWordBreakV1, PropertyNameParseBidiClassV1,
PropertyNameParseCanonicalCombiningClassV1, PropertyNameParseEastAsianWidthV1,
PropertyNameParseGeneralCategoryMaskV1, PropertyNameParseGeneralCategoryV1,
PropertyNameParseGraphemeClusterBreakV1, PropertyNameParseHangulSyllableTypeV1,
PropertyNameParseIndicSyllabicCategoryV1, PropertyNameParseJoiningTypeV1,
PropertyNameParseLineBreakV1, PropertyNameParseScriptV1, PropertyNameParseSentenceBreakV1,
PropertyNameLongJoiningTypeV1, PropertyNameLongLineBreakV1, PropertyNameLongNumericTypeV1,
PropertyNameLongScriptV1, PropertyNameLongSentenceBreakV1,
PropertyNameLongVerticalOrientationV1, PropertyNameLongWordBreakV1,
PropertyNameParseBidiClassV1, PropertyNameParseCanonicalCombiningClassV1,
PropertyNameParseEastAsianWidthV1, PropertyNameParseGeneralCategoryMaskV1,
PropertyNameParseGeneralCategoryV1, PropertyNameParseGraphemeClusterBreakV1,
PropertyNameParseHangulSyllableTypeV1, PropertyNameParseIndicSyllabicCategoryV1,
PropertyNameParseJoiningTypeV1, PropertyNameParseLineBreakV1, PropertyNameParseNumericTypeV1,
PropertyNameParseScriptV1, PropertyNameParseSentenceBreakV1,
PropertyNameParseVerticalOrientationV1, PropertyNameParseWordBreakV1,
PropertyNameShortBidiClassV1, PropertyNameShortEastAsianWidthV1,
PropertyNameShortGeneralCategoryV1, PropertyNameShortGraphemeClusterBreakV1,
PropertyNameShortHangulSyllableTypeV1, PropertyNameShortIndicSyllabicCategoryV1,
PropertyNameShortJoiningTypeV1, PropertyNameShortLineBreakV1, PropertyNameShortScriptV1,
PropertyNameShortSentenceBreakV1, PropertyNameShortVerticalOrientationV1,
PropertyNameShortWordBreakV1,
PropertyNameShortJoiningTypeV1, PropertyNameShortLineBreakV1, PropertyNameShortNumericTypeV1,
PropertyNameShortScriptV1, PropertyNameShortSentenceBreakV1,
PropertyNameShortVerticalOrientationV1, PropertyNameShortWordBreakV1,
};

pub use crate::props::gc::GeneralCategoryULE;
Expand Down Expand Up @@ -145,6 +146,7 @@ const _: () = {
impl_property_binary_xid_continue_v1!(Baked);
impl_property_binary_xid_start_v1!(Baked);
impl_property_enum_bidi_class_v1!(Baked);
impl_property_enum_numeric_type_v1!(Baked);
impl_property_enum_bidi_mirroring_glyph_v1!(Baked);
impl_property_enum_canonical_combining_class_v1!(Baked);
impl_property_enum_east_asian_width_v1!(Baked);
Expand All @@ -160,6 +162,7 @@ const _: () = {
impl_property_enum_vertical_orientation_v1!(Baked);
impl_property_enum_word_break_v1!(Baked);
impl_property_name_long_bidi_class_v1!(Baked);
impl_property_name_long_numeric_type_v1!(Baked);
#[cfg(feature = "alloc")]
impl_property_name_long_canonical_combining_class_v1!(Baked);
impl_property_name_long_east_asian_width_v1!(Baked);
Expand All @@ -174,6 +177,7 @@ const _: () = {
impl_property_name_long_vertical_orientation_v1!(Baked);
impl_property_name_long_word_break_v1!(Baked);
impl_property_name_parse_bidi_class_v1!(Baked);
impl_property_name_parse_numeric_type_v1!(Baked);
impl_property_name_parse_canonical_combining_class_v1!(Baked);
impl_property_name_parse_east_asian_width_v1!(Baked);
impl_property_name_parse_general_category_mask_v1!(Baked);
Expand All @@ -188,6 +192,7 @@ const _: () = {
impl_property_name_parse_vertical_orientation_v1!(Baked);
impl_property_name_parse_word_break_v1!(Baked);
impl_property_name_short_bidi_class_v1!(Baked);
impl_property_name_short_numeric_type_v1!(Baked);
#[cfg(feature = "alloc")]
impl_property_name_short_canonical_combining_class_v1!(Baked);
impl_property_name_short_east_asian_width_v1!(Baked);
Expand Down Expand Up @@ -624,6 +629,12 @@ icu_provider::data_marker!(
PropertyCodePointMap<'static, crate::props::BidiClass>,
is_singleton = true,
);
icu_provider::data_marker!(
/// Data marker for the #NumericValue' Unicode property
PropertyEnumNumericTypeV1,
PropertyCodePointMap<'static, crate::props::NumericType>,
is_singleton = true,
);
icu_provider::data_marker!(
/// Data marker for the 'CanonicalCombiningClass' Unicode property
PropertyEnumCanonicalCombiningClassV1,
Expand Down Expand Up @@ -724,6 +735,7 @@ icu_provider::data_marker!(
/// All data keys in this module.
pub const MARKERS: &[DataMarkerInfo] = &[
PropertyNameLongBidiClassV1::INFO,
PropertyNameLongNumericTypeV1::INFO,
#[cfg(feature = "alloc")]
PropertyNameLongCanonicalCombiningClassV1::INFO,
PropertyNameLongEastAsianWidthV1::INFO,
Expand All @@ -738,6 +750,7 @@ pub const MARKERS: &[DataMarkerInfo] = &[
PropertyNameLongVerticalOrientationV1::INFO,
PropertyNameLongWordBreakV1::INFO,
PropertyNameParseBidiClassV1::INFO,
PropertyNameParseNumericTypeV1::INFO,
PropertyNameParseCanonicalCombiningClassV1::INFO,
PropertyNameParseEastAsianWidthV1::INFO,
PropertyNameParseGeneralCategoryMaskV1::INFO,
Expand All @@ -752,6 +765,7 @@ pub const MARKERS: &[DataMarkerInfo] = &[
PropertyNameParseVerticalOrientationV1::INFO,
PropertyNameParseWordBreakV1::INFO,
PropertyNameShortBidiClassV1::INFO,
PropertyNameShortNumericTypeV1::INFO,
#[cfg(feature = "alloc")]
PropertyNameShortCanonicalCombiningClassV1::INFO,
PropertyNameShortEastAsianWidthV1::INFO,
Expand Down Expand Up @@ -835,6 +849,7 @@ pub const MARKERS: &[DataMarkerInfo] = &[
PropertyBinaryXidContinueV1::INFO,
PropertyBinaryXidStartV1::INFO,
PropertyEnumBidiClassV1::INFO,
PropertyEnumNumericTypeV1::INFO,
PropertyEnumCanonicalCombiningClassV1::INFO,
PropertyEnumEastAsianWidthV1::INFO,
PropertyEnumGeneralCategoryV1::INFO,
Expand Down
18 changes: 18 additions & 0 deletions components/properties/src/provider/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ icu_provider::data_marker!(
PropertyValueNameToEnumMap<'static>,
is_singleton = true
);
icu_provider::data_marker!(
/// `PropertyNameParseNumericTypeV1`
PropertyNameParseNumericTypeV1,
PropertyValueNameToEnumMap<'static>,
is_singleton = true
);
icu_provider::data_marker!(
/// `PropertyNameParseCanonicalCombiningClassV1`
PropertyNameParseCanonicalCombiningClassV1,
Expand Down Expand Up @@ -115,6 +121,18 @@ icu_provider::data_marker!(
PropertyEnumToValueNameLinearMap<'static>,
is_singleton = true
);
icu_provider::data_marker!(
/// `PropertyNameLongNumericTypeV1`
PropertyNameLongNumericTypeV1,
PropertyEnumToValueNameLinearMap<'static>,
is_singleton = true,
);
icu_provider::data_marker!(
/// `PropertyNameShortNumericTypeV1`
PropertyNameShortNumericTypeV1,
PropertyEnumToValueNameLinearMap<'static>,
is_singleton = true,
);
icu_provider::data_marker!(
/// `PropertyNameLongEastAsianWidthV1`
PropertyNameLongEastAsianWidthV1,
Expand Down
14 changes: 13 additions & 1 deletion components/properties/src/trievalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::bidi::BidiMirroringGlyph;
use crate::props::{
BidiClass, CanonicalCombiningClass, EastAsianWidth, GeneralCategory, GeneralCategoryGroup,
GraphemeClusterBreak, HangulSyllableType, IndicConjunctBreak, IndicSyllabicCategory,
JoiningType, LineBreak, Script, SentenceBreak, VerticalOrientation, WordBreak,
JoiningType, LineBreak, NumericType, Script, SentenceBreak, VerticalOrientation, WordBreak,
};
use crate::script::ScriptWithExt;
use core::convert::TryInto;
Expand All @@ -29,6 +29,18 @@ impl TrieValue for CanonicalCombiningClass {
}
}

impl TrieValue for NumericType {
type TryFromU32Error = TryFromIntError;

fn try_from_u32(i: u32) -> Result<Self, Self::TryFromU32Error> {
u8::try_from(i).map(Self)
}

fn to_u32(self) -> u32 {
u32::from(self.0)
}
}

impl TrieValue for BidiClass {
type TryFromU32Error = TryFromIntError;

Expand Down
5 changes: 5 additions & 0 deletions ffi/capi/bindings/c/CodePointMapData8.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions ffi/capi/bindings/c/NumericType.d.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions ffi/capi/bindings/c/NumericType.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions ffi/capi/bindings/c/PropertyValueNameToEnumMapper.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions ffi/capi/bindings/cpp/icu4x/CodePointMapData8.d.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading