Skip to content

Commit 7d33cbd

Browse files
add enumerated property NumericType to icu_properties (#7157)
<!-- Thank you for your pull request to ICU4X! Reminder: try to use [Conventional Comments](https://conventionalcomments.org/) to make comments clearer. Please see https://github.com/unicode-org/icu4x/blob/main/CONTRIBUTING.md for general information on contributing to ICU4X. --> did not find an existing issue issue, but i needed (wanted) to read this property and found out it wasn't available, so here it is ... --------- Co-authored-by: Robert Bastian <[email protected]>
1 parent 3fa7ff0 commit 7d33cbd

File tree

54 files changed

+6038
-13
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+6038
-13
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: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,73 @@ make_enumerated_property! {
233233
ule_ty: u8;
234234
}
235235

236+
/// Enumerated property Numeric_Type.
237+
///
238+
/// See Section 4.6, Numeric Value in The Unicode Standard for the summary of
239+
/// each property value.
240+
///
241+
/// # Example
242+
///
243+
/// ```
244+
/// use icu::properties::{props::NumericType, CodePointMapData};
245+
///
246+
/// assert_eq!(
247+
/// CodePointMapData::<NumericType>::new().get('0'),
248+
/// NumericType::Decimal,
249+
/// ); // U+0030
250+
/// assert_eq!(
251+
/// CodePointMapData::<NumericType>::new().get('½'),
252+
/// NumericType::Numeric,
253+
/// ); // U+00BD
254+
/// ```
255+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
256+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
257+
#[allow(clippy::exhaustive_structs)] // newtype
258+
#[repr(transparent)]
259+
pub struct NumericType(pub(crate) u8);
260+
261+
impl NumericType {
262+
/// Returns an ICU4C `UNumericType` value.
263+
pub const fn to_icu4c_value(self) -> u8 {
264+
self.0
265+
}
266+
/// Constructor from an ICU4C `UNumericType` value.
267+
pub const fn from_icu4c_value(value: u8) -> Self {
268+
Self(value)
269+
}
270+
}
271+
272+
create_const_array! {
273+
#[allow(non_upper_case_globals)]
274+
impl NumericType {
275+
/// Characters without numeric value
276+
pub const None: NumericType = NumericType(0);
277+
/// (`De`) Characters of positional decimal systems
278+
///
279+
/// These are coextensive with [`GeneralCategory::DecimalNumber`].
280+
pub const Decimal: NumericType = NumericType(1);
281+
/// (`Di`) Variants of positional or sequences thereof.
282+
///
283+
/// The distinction between [`NumericType::Digit`] and [`NumericType::Numeric`]
284+
/// has not proven to be useful, so no further characters will be added to
285+
/// this type.
286+
pub const Digit: NumericType = NumericType(2);
287+
/// (`Nu`) Other characters with numeric value
288+
pub const Numeric: NumericType = NumericType(3);
289+
}
290+
#[test]
291+
fn numeric_type_consts();
292+
}
293+
294+
make_enumerated_property! {
295+
name: "Numeric_Type";
296+
short_name: "nt";
297+
ident: NumericType;
298+
data_marker: crate::provider::PropertyEnumNumericTypeV1;
299+
singleton: SINGLETON_PROPERTY_ENUM_NUMERIC_TYPE_V1;
300+
ule_ty: u8;
301+
}
302+
236303
// This exists to encapsulate GeneralCategoryULE so that it can exist in the provider module rather than props
237304
pub(crate) mod gc {
238305
/// Enumerated property General_Category.
@@ -3404,6 +3471,14 @@ mod test_enumerated_property_completeness {
34043471
);
34053472
}
34063473

3474+
#[test]
3475+
fn test_nt() {
3476+
check_enum(
3477+
crate::provider::Baked::SINGLETON_PROPERTY_NAME_PARSE_NUMERIC_TYPE_V1,
3478+
NumericType::ALL_VALUES,
3479+
);
3480+
}
3481+
34073482
#[test]
34083483
fn test_hst() {
34093484
check_enum(

components/properties/src/provider.rs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,23 @@ pub use names::{
2727
PropertyNameLongGeneralCategoryV1, PropertyNameLongGraphemeClusterBreakV1,
2828
PropertyNameLongHangulSyllableTypeV1, PropertyNameLongIndicConjunctBreakV1,
2929
PropertyNameLongIndicSyllabicCategoryV1, PropertyNameLongJoiningTypeV1,
30-
PropertyNameLongLineBreakV1, PropertyNameLongScriptV1, PropertyNameLongSentenceBreakV1,
31-
PropertyNameLongVerticalOrientationV1, PropertyNameLongWordBreakV1,
32-
PropertyNameParseBidiClassV1, PropertyNameParseCanonicalCombiningClassV1,
33-
PropertyNameParseEastAsianWidthV1, PropertyNameParseGeneralCategoryMaskV1,
34-
PropertyNameParseGeneralCategoryV1, PropertyNameParseGraphemeClusterBreakV1,
35-
PropertyNameParseHangulSyllableTypeV1, PropertyNameParseIndicConjunctBreakV1,
36-
PropertyNameParseIndicSyllabicCategoryV1, PropertyNameParseJoiningTypeV1,
37-
PropertyNameParseLineBreakV1, PropertyNameParseScriptV1, PropertyNameParseSentenceBreakV1,
30+
PropertyNameLongLineBreakV1, PropertyNameLongNumericTypeV1, PropertyNameLongScriptV1,
31+
PropertyNameLongSentenceBreakV1, PropertyNameLongVerticalOrientationV1,
32+
PropertyNameLongWordBreakV1, PropertyNameParseBidiClassV1,
33+
PropertyNameParseCanonicalCombiningClassV1, PropertyNameParseEastAsianWidthV1,
34+
PropertyNameParseGeneralCategoryMaskV1, PropertyNameParseGeneralCategoryV1,
35+
PropertyNameParseGraphemeClusterBreakV1, PropertyNameParseHangulSyllableTypeV1,
36+
PropertyNameParseIndicConjunctBreakV1, PropertyNameParseIndicSyllabicCategoryV1,
37+
PropertyNameParseJoiningTypeV1, PropertyNameParseLineBreakV1, PropertyNameParseNumericTypeV1,
38+
PropertyNameParseScriptV1, PropertyNameParseSentenceBreakV1,
3839
PropertyNameParseVerticalOrientationV1, PropertyNameParseWordBreakV1,
3940
PropertyNameShortBidiClassV1, PropertyNameShortEastAsianWidthV1,
4041
PropertyNameShortGeneralCategoryV1, PropertyNameShortGraphemeClusterBreakV1,
4142
PropertyNameShortHangulSyllableTypeV1, PropertyNameShortIndicConjunctBreakV1,
4243
PropertyNameShortIndicSyllabicCategoryV1, PropertyNameShortJoiningTypeV1,
43-
PropertyNameShortLineBreakV1, PropertyNameShortScriptV1, PropertyNameShortSentenceBreakV1,
44-
PropertyNameShortVerticalOrientationV1, PropertyNameShortWordBreakV1,
44+
PropertyNameShortLineBreakV1, PropertyNameShortNumericTypeV1, PropertyNameShortScriptV1,
45+
PropertyNameShortSentenceBreakV1, PropertyNameShortVerticalOrientationV1,
46+
PropertyNameShortWordBreakV1,
4547
};
4648

4749
pub use crate::props::gc::GeneralCategoryULE;
@@ -156,6 +158,7 @@ const _: () = {
156158
impl_property_enum_indic_syllabic_category_v1!(Baked);
157159
impl_property_enum_joining_type_v1!(Baked);
158160
impl_property_enum_line_break_v1!(Baked);
161+
impl_property_enum_numeric_type_v1!(Baked);
159162
impl_property_enum_script_v1!(Baked);
160163
impl_property_enum_sentence_break_v1!(Baked);
161164
impl_property_enum_vertical_orientation_v1!(Baked);
@@ -171,6 +174,7 @@ const _: () = {
171174
impl_property_name_long_indic_conjunct_break_v1!(Baked);
172175
impl_property_name_long_joining_type_v1!(Baked);
173176
impl_property_name_long_line_break_v1!(Baked);
177+
impl_property_name_long_numeric_type_v1!(Baked);
174178
impl_property_name_long_script_v1!(Baked);
175179
impl_property_name_long_sentence_break_v1!(Baked);
176180
impl_property_name_long_vertical_orientation_v1!(Baked);
@@ -186,6 +190,7 @@ const _: () = {
186190
impl_property_name_parse_indic_conjunct_break_v1!(Baked);
187191
impl_property_name_parse_joining_type_v1!(Baked);
188192
impl_property_name_parse_line_break_v1!(Baked);
193+
impl_property_name_parse_numeric_type_v1!(Baked);
189194
impl_property_name_parse_script_v1!(Baked);
190195
impl_property_name_parse_sentence_break_v1!(Baked);
191196
impl_property_name_parse_vertical_orientation_v1!(Baked);
@@ -201,6 +206,7 @@ const _: () = {
201206
impl_property_name_short_indic_conjunct_break_v1!(Baked);
202207
impl_property_name_short_joining_type_v1!(Baked);
203208
impl_property_name_short_line_break_v1!(Baked);
209+
impl_property_name_short_numeric_type_v1!(Baked);
204210
impl_property_name_short_script_v1!(Baked);
205211
impl_property_name_short_sentence_break_v1!(Baked);
206212
impl_property_name_short_vertical_orientation_v1!(Baked);
@@ -682,6 +688,12 @@ icu_provider::data_marker!(
682688
PropertyCodePointMap<'static, crate::props::LineBreak>,
683689
is_singleton = true,
684690
);
691+
icu_provider::data_marker!(
692+
/// Data marker for the 'NumericValue' Unicode property
693+
PropertyEnumNumericTypeV1,
694+
PropertyCodePointMap<'static, crate::props::NumericType>,
695+
is_singleton = true,
696+
);
685697
icu_provider::data_marker!(
686698
/// Data marker for the 'Script' Unicode property
687699
PropertyEnumScriptV1,
@@ -738,6 +750,7 @@ pub const MARKERS: &[DataMarkerInfo] = &[
738750
PropertyNameLongIndicConjunctBreakV1::INFO,
739751
PropertyNameLongJoiningTypeV1::INFO,
740752
PropertyNameLongLineBreakV1::INFO,
753+
PropertyNameLongNumericTypeV1::INFO,
741754
PropertyNameLongScriptV1::INFO,
742755
PropertyNameLongSentenceBreakV1::INFO,
743756
PropertyNameLongVerticalOrientationV1::INFO,
@@ -753,6 +766,7 @@ pub const MARKERS: &[DataMarkerInfo] = &[
753766
PropertyNameParseIndicConjunctBreakV1::INFO,
754767
PropertyNameParseJoiningTypeV1::INFO,
755768
PropertyNameParseLineBreakV1::INFO,
769+
PropertyNameParseNumericTypeV1::INFO,
756770
PropertyNameParseScriptV1::INFO,
757771
PropertyNameParseSentenceBreakV1::INFO,
758772
PropertyNameParseVerticalOrientationV1::INFO,
@@ -768,6 +782,7 @@ pub const MARKERS: &[DataMarkerInfo] = &[
768782
PropertyNameShortIndicConjunctBreakV1::INFO,
769783
PropertyNameShortJoiningTypeV1::INFO,
770784
PropertyNameShortLineBreakV1::INFO,
785+
PropertyNameShortNumericTypeV1::INFO,
771786
PropertyNameShortScriptV1::INFO,
772787
PropertyNameShortSentenceBreakV1::INFO,
773788
PropertyNameShortVerticalOrientationV1::INFO,
@@ -851,6 +866,7 @@ pub const MARKERS: &[DataMarkerInfo] = &[
851866
PropertyEnumIndicSyllabicCategoryV1::INFO,
852867
PropertyEnumJoiningTypeV1::INFO,
853868
PropertyEnumLineBreakV1::INFO,
869+
PropertyEnumNumericTypeV1::INFO,
854870
PropertyEnumScriptV1::INFO,
855871
PropertyEnumSentenceBreakV1::INFO,
856872
PropertyEnumVerticalOrientationV1::INFO,

components/properties/src/provider/names.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ icu_provider::data_marker!(
8585
PropertyValueNameToEnumMap<'static>,
8686
is_singleton = true
8787
);
88+
icu_provider::data_marker!(
89+
/// `PropertyNameParseNumericTypeV1`
90+
PropertyNameParseNumericTypeV1,
91+
PropertyValueNameToEnumMap<'static>,
92+
is_singleton = true
93+
);
8894
icu_provider::data_marker!(
8995
/// `PropertyNameParseScriptV1`
9096
PropertyNameParseScriptV1,
@@ -211,6 +217,18 @@ icu_provider::data_marker!(
211217
PropertyEnumToValueNameLinearMap<'static>,
212218
is_singleton = true
213219
);
220+
icu_provider::data_marker!(
221+
/// `PropertyNameLongNumericTypeV1`
222+
PropertyNameLongNumericTypeV1,
223+
PropertyEnumToValueNameLinearMap<'static>,
224+
is_singleton = true,
225+
);
226+
icu_provider::data_marker!(
227+
/// `PropertyNameShortNumericTypeV1`
228+
PropertyNameShortNumericTypeV1,
229+
PropertyEnumToValueNameLinearMap<'static>,
230+
is_singleton = true,
231+
);
214232
icu_provider::data_marker!(
215233
/// `PropertyNameShortLineBreakV1`
216234
PropertyNameShortLineBreakV1,

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

ffi/capi/bindings/c/CodePointMapData8.h

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

ffi/capi/bindings/c/NumericType.d.h

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

ffi/capi/bindings/c/NumericType.h

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

ffi/capi/bindings/c/PropertyValueNameToEnumMapper.h

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

ffi/capi/bindings/cpp/icu4x/CodePointMapData8.d.hpp

Lines changed: 14 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)