Skip to content

Commit dc7e44a

Browse files
committed
add enumerated property for Numeric_Type
1 parent ce3610d commit dc7e44a

18 files changed

+813
-12
lines changed

components/properties/src/names.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,14 @@ impl_value_getter! {
807807
}
808808
}
809809

810+
impl_value_getter! {
811+
impl NumericType {
812+
PropertyNameParseNumericTypeV1 / SINGLETON_PROPERTY_NAME_PARSE_NUMERIC_TYPE_V1;
813+
PropertyEnumToValueNameLinearMap / PropertyNameShortNumericTypeV1 / SINGLETON_PROPERTY_NAME_SHORT_NUMERIC_TYPE_V1;
814+
PropertyEnumToValueNameLinearMap / PropertyNameLongNumericTypeV1 / SINGLETON_PROPERTY_NAME_LONG_NUMERIC_TYPE_V1;
815+
}
816+
}
817+
810818
impl_value_getter! {
811819
impl GeneralCategory {
812820
PropertyNameParseGeneralCategoryV1 / SINGLETON_PROPERTY_NAME_PARSE_GENERAL_CATEGORY_V1;

components/properties/src/props.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,71 @@ macro_rules! make_enumerated_property {
112112
};
113113
}
114114

115+
/// Enumerated property Numeric_Type.
116+
///
117+
/// See Section 4.6, Numeric Value in The Unicode Standard for the summary of
118+
/// each property value.
119+
///
120+
/// # Example
121+
///
122+
/// ```
123+
/// use icu::properties::{props::NumericType, CodePointMapData};
124+
///
125+
/// assert_eq!(
126+
/// CodePointMapData::<NumericType>::new().get('0'),
127+
/// NumericType::Decimal,
128+
/// ); // U+0030
129+
/// assert_eq!(
130+
/// CodePointMapData::<NumericType>::new().get('½'),
131+
/// NumericType::Numeric,
132+
/// ); // U+00BD
133+
/// ```
134+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
135+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
136+
#[allow(clippy::exhaustive_structs)] // newtype
137+
#[repr(transparent)]
138+
pub struct NumericType(pub(crate) u8);
139+
140+
impl NumericType {
141+
/// Returns an ICU4C `UNumericType` value.
142+
pub const fn to_icu4c_value(self) -> u8 {
143+
self.0
144+
}
145+
/// Constructor from an ICU4C `UNumericType` value.
146+
pub const fn from_icu4c_value(value: u8) -> Self {
147+
Self(value)
148+
}
149+
}
150+
151+
create_const_array! {
152+
#[allow(non_upper_case_globals)]
153+
impl NumericType {
154+
/// Characters without numeric value
155+
pub const None: NumericType = NumericType(0);
156+
/// (`De`) Characters of positional decimal systems
157+
///
158+
/// These are coextensive with [`GeneralCategory::DecimalNumber`].
159+
pub const Decimal: NumericType = NumericType(1);
160+
/// (`Di`) Variants of positional or sequences thereof.
161+
///
162+
/// The distinction between [`NumericType::Digit`] and [`NumericType::Numeric`]
163+
/// has not proven to be useful, so no further characters will be added to
164+
/// this type.
165+
pub const Digit: NumericType = NumericType(2);
166+
/// (`Nu`) Other characters with numeric value
167+
pub const Numeric: NumericType = NumericType(3);
168+
}
169+
}
170+
171+
make_enumerated_property! {
172+
name: "Numeric_Type";
173+
short_name: "nt";
174+
ident: NumericType;
175+
data_marker: crate::provider::PropertyEnumNumericTypeV1;
176+
singleton: SINGLETON_PROPERTY_ENUM_NUMERIC_TYPE_V1;
177+
ule_ty: u8;
178+
}
179+
115180
/// Enumerated property Bidi_Class
116181
///
117182
/// These are the categories required by the Unicode Bidirectional Algorithm.
@@ -3303,6 +3368,14 @@ mod test_enumerated_property_completeness {
33033368
);
33043369
}
33053370

3371+
#[test]
3372+
fn test_nt() {
3373+
check_enum(
3374+
crate::provider::Baked::SINGLETON_PROPERTY_NAME_PARSE_NUMERIC_TYPE_V1,
3375+
NumericType::ALL_VALUES,
3376+
);
3377+
}
3378+
33063379
#[test]
33073380
fn test_hst() {
33083381
check_enum(

components/properties/src/provider.rs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,22 @@ pub use names::{
2626
PropertyNameLongBidiClassV1, PropertyNameLongEastAsianWidthV1,
2727
PropertyNameLongGeneralCategoryV1, PropertyNameLongGraphemeClusterBreakV1,
2828
PropertyNameLongHangulSyllableTypeV1, PropertyNameLongIndicSyllabicCategoryV1,
29-
PropertyNameLongJoiningTypeV1, PropertyNameLongLineBreakV1, PropertyNameLongScriptV1,
30-
PropertyNameLongSentenceBreakV1, PropertyNameLongVerticalOrientationV1,
31-
PropertyNameLongWordBreakV1, PropertyNameParseBidiClassV1,
32-
PropertyNameParseCanonicalCombiningClassV1, PropertyNameParseEastAsianWidthV1,
33-
PropertyNameParseGeneralCategoryMaskV1, PropertyNameParseGeneralCategoryV1,
34-
PropertyNameParseGraphemeClusterBreakV1, PropertyNameParseHangulSyllableTypeV1,
35-
PropertyNameParseIndicSyllabicCategoryV1, PropertyNameParseJoiningTypeV1,
36-
PropertyNameParseLineBreakV1, PropertyNameParseScriptV1, PropertyNameParseSentenceBreakV1,
29+
PropertyNameLongJoiningTypeV1, PropertyNameLongLineBreakV1, PropertyNameLongNumericTypeV1,
30+
PropertyNameLongScriptV1, PropertyNameLongSentenceBreakV1,
31+
PropertyNameLongVerticalOrientationV1, PropertyNameLongWordBreakV1,
32+
PropertyNameParseBidiClassV1, PropertyNameParseCanonicalCombiningClassV1,
33+
PropertyNameParseEastAsianWidthV1, PropertyNameParseGeneralCategoryMaskV1,
34+
PropertyNameParseGeneralCategoryV1, PropertyNameParseGraphemeClusterBreakV1,
35+
PropertyNameParseHangulSyllableTypeV1, PropertyNameParseIndicSyllabicCategoryV1,
36+
PropertyNameParseJoiningTypeV1, PropertyNameParseLineBreakV1, PropertyNameParseNumericTypeV1,
37+
PropertyNameParseScriptV1, PropertyNameParseSentenceBreakV1,
3738
PropertyNameParseVerticalOrientationV1, PropertyNameParseWordBreakV1,
3839
PropertyNameShortBidiClassV1, PropertyNameShortEastAsianWidthV1,
3940
PropertyNameShortGeneralCategoryV1, PropertyNameShortGraphemeClusterBreakV1,
4041
PropertyNameShortHangulSyllableTypeV1, PropertyNameShortIndicSyllabicCategoryV1,
41-
PropertyNameShortJoiningTypeV1, PropertyNameShortLineBreakV1, PropertyNameShortScriptV1,
42-
PropertyNameShortSentenceBreakV1, PropertyNameShortVerticalOrientationV1,
43-
PropertyNameShortWordBreakV1,
42+
PropertyNameShortJoiningTypeV1, PropertyNameShortLineBreakV1, PropertyNameShortNumericTypeV1,
43+
PropertyNameShortScriptV1, PropertyNameShortSentenceBreakV1,
44+
PropertyNameShortVerticalOrientationV1, PropertyNameShortWordBreakV1,
4445
};
4546

4647
pub use crate::props::gc::GeneralCategoryULE;
@@ -145,6 +146,7 @@ const _: () = {
145146
impl_property_binary_xid_continue_v1!(Baked);
146147
impl_property_binary_xid_start_v1!(Baked);
147148
impl_property_enum_bidi_class_v1!(Baked);
149+
impl_property_enum_numeric_type_v1!(Baked);
148150
impl_property_enum_bidi_mirroring_glyph_v1!(Baked);
149151
impl_property_enum_canonical_combining_class_v1!(Baked);
150152
impl_property_enum_east_asian_width_v1!(Baked);
@@ -160,6 +162,7 @@ const _: () = {
160162
impl_property_enum_vertical_orientation_v1!(Baked);
161163
impl_property_enum_word_break_v1!(Baked);
162164
impl_property_name_long_bidi_class_v1!(Baked);
165+
impl_property_name_long_numeric_type_v1!(Baked);
163166
#[cfg(feature = "alloc")]
164167
impl_property_name_long_canonical_combining_class_v1!(Baked);
165168
impl_property_name_long_east_asian_width_v1!(Baked);
@@ -174,6 +177,7 @@ const _: () = {
174177
impl_property_name_long_vertical_orientation_v1!(Baked);
175178
impl_property_name_long_word_break_v1!(Baked);
176179
impl_property_name_parse_bidi_class_v1!(Baked);
180+
impl_property_name_parse_numeric_type_v1!(Baked);
177181
impl_property_name_parse_canonical_combining_class_v1!(Baked);
178182
impl_property_name_parse_east_asian_width_v1!(Baked);
179183
impl_property_name_parse_general_category_mask_v1!(Baked);
@@ -188,6 +192,7 @@ const _: () = {
188192
impl_property_name_parse_vertical_orientation_v1!(Baked);
189193
impl_property_name_parse_word_break_v1!(Baked);
190194
impl_property_name_short_bidi_class_v1!(Baked);
195+
impl_property_name_short_numeric_type_v1!(Baked);
191196
#[cfg(feature = "alloc")]
192197
impl_property_name_short_canonical_combining_class_v1!(Baked);
193198
impl_property_name_short_east_asian_width_v1!(Baked);
@@ -624,6 +629,12 @@ icu_provider::data_marker!(
624629
PropertyCodePointMap<'static, crate::props::BidiClass>,
625630
is_singleton = true,
626631
);
632+
icu_provider::data_marker!(
633+
/// Data marker for the #NumericValue' Unicode property
634+
PropertyEnumNumericTypeV1,
635+
PropertyCodePointMap<'static, crate::props::NumericType>,
636+
is_singleton = true,
637+
);
627638
icu_provider::data_marker!(
628639
/// Data marker for the 'CanonicalCombiningClass' Unicode property
629640
PropertyEnumCanonicalCombiningClassV1,
@@ -724,6 +735,7 @@ icu_provider::data_marker!(
724735
/// All data keys in this module.
725736
pub const MARKERS: &[DataMarkerInfo] = &[
726737
PropertyNameLongBidiClassV1::INFO,
738+
PropertyNameLongNumericTypeV1::INFO,
727739
#[cfg(feature = "alloc")]
728740
PropertyNameLongCanonicalCombiningClassV1::INFO,
729741
PropertyNameLongEastAsianWidthV1::INFO,
@@ -738,6 +750,7 @@ pub const MARKERS: &[DataMarkerInfo] = &[
738750
PropertyNameLongVerticalOrientationV1::INFO,
739751
PropertyNameLongWordBreakV1::INFO,
740752
PropertyNameParseBidiClassV1::INFO,
753+
PropertyNameParseNumericTypeV1::INFO,
741754
PropertyNameParseCanonicalCombiningClassV1::INFO,
742755
PropertyNameParseEastAsianWidthV1::INFO,
743756
PropertyNameParseGeneralCategoryMaskV1::INFO,
@@ -752,6 +765,7 @@ pub const MARKERS: &[DataMarkerInfo] = &[
752765
PropertyNameParseVerticalOrientationV1::INFO,
753766
PropertyNameParseWordBreakV1::INFO,
754767
PropertyNameShortBidiClassV1::INFO,
768+
PropertyNameShortNumericTypeV1::INFO,
755769
#[cfg(feature = "alloc")]
756770
PropertyNameShortCanonicalCombiningClassV1::INFO,
757771
PropertyNameShortEastAsianWidthV1::INFO,
@@ -835,6 +849,7 @@ pub const MARKERS: &[DataMarkerInfo] = &[
835849
PropertyBinaryXidContinueV1::INFO,
836850
PropertyBinaryXidStartV1::INFO,
837851
PropertyEnumBidiClassV1::INFO,
852+
PropertyEnumNumericTypeV1::INFO,
838853
PropertyEnumCanonicalCombiningClassV1::INFO,
839854
PropertyEnumEastAsianWidthV1::INFO,
840855
PropertyEnumGeneralCategoryV1::INFO,

components/properties/src/provider/names.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ icu_provider::data_marker!(
2525
PropertyValueNameToEnumMap<'static>,
2626
is_singleton = true
2727
);
28+
icu_provider::data_marker!(
29+
/// `PropertyNameParseNumericTypeV1`
30+
PropertyNameParseNumericTypeV1,
31+
PropertyValueNameToEnumMap<'static>,
32+
is_singleton = true
33+
);
2834
icu_provider::data_marker!(
2935
/// `PropertyNameParseCanonicalCombiningClassV1`
3036
PropertyNameParseCanonicalCombiningClassV1,
@@ -115,6 +121,18 @@ icu_provider::data_marker!(
115121
PropertyEnumToValueNameLinearMap<'static>,
116122
is_singleton = true
117123
);
124+
icu_provider::data_marker!(
125+
/// `PropertyNameLongNumericTypeV1`
126+
PropertyNameLongNumericTypeV1,
127+
PropertyEnumToValueNameLinearMap<'static>,
128+
is_singleton = true,
129+
);
130+
icu_provider::data_marker!(
131+
/// `PropertyNameShortNumericTypeV1`
132+
PropertyNameShortNumericTypeV1,
133+
PropertyEnumToValueNameLinearMap<'static>,
134+
is_singleton = true,
135+
);
118136
icu_provider::data_marker!(
119137
/// `PropertyNameLongEastAsianWidthV1`
120138
PropertyNameLongEastAsianWidthV1,

components/properties/src/trievalue.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::bidi::BidiMirroringGlyph;
66
use crate::props::{
77
BidiClass, CanonicalCombiningClass, EastAsianWidth, GeneralCategory, GeneralCategoryGroup,
88
GraphemeClusterBreak, HangulSyllableType, IndicConjunctBreak, IndicSyllabicCategory,
9-
JoiningType, LineBreak, Script, SentenceBreak, VerticalOrientation, WordBreak,
9+
JoiningType, LineBreak, NumericType, Script, SentenceBreak, VerticalOrientation, WordBreak,
1010
};
1111
use crate::script::ScriptWithExt;
1212
use core::convert::TryInto;
@@ -29,6 +29,18 @@ impl TrieValue for CanonicalCombiningClass {
2929
}
3030
}
3131

32+
impl TrieValue for NumericType {
33+
type TryFromU32Error = TryFromIntError;
34+
35+
fn try_from_u32(i: u32) -> Result<Self, Self::TryFromU32Error> {
36+
u8::try_from(i).map(Self)
37+
}
38+
39+
fn to_u32(self) -> u32 {
40+
u32::from(self.0)
41+
}
42+
}
43+
3244
impl TrieValue for BidiClass {
3345
type TryFromU32Error = TryFromIntError;
3446

provider/data/properties/data/mod.rs

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)