Skip to content

Commit 4b7473e

Browse files
jedel1043sffc
authored andcommitted
Backport: Implement Joining_Type property (unicode-org#4599)
1 parent fda6594 commit 4b7473e

File tree

24 files changed

+6848
-19
lines changed

24 files changed

+6848
-19
lines changed

components/properties/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ mod trievalue;
9292

9393
pub use props::{
9494
BidiClass, CanonicalCombiningClass, EastAsianWidth, GeneralCategory, GeneralCategoryGroup,
95-
GraphemeClusterBreak, IndicSyllabicCategory, LineBreak, Script, SentenceBreak, WordBreak,
95+
GraphemeClusterBreak, IndicSyllabicCategory, JoiningType, LineBreak, Script, SentenceBreak,
96+
WordBreak,
9697
};
9798

9899
/// Module for working with the names of property values

components/properties/src/maps.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,3 +600,28 @@ make_map_property! {
600600
pub const indic_syllabic_category => SINGLETON_PROPS_INSC_V1;
601601
pub fn load_indic_syllabic_category();
602602
}
603+
604+
make_map_property! {
605+
property: "Joining_Type";
606+
marker: JoiningTypeProperty;
607+
value: crate::JoiningType;
608+
keyed_data_marker: JoiningTypeV1Marker;
609+
func:
610+
/// Return a [`CodePointMapDataBorrowed`] for the Joining_Type Unicode enumerated
611+
/// property. See [`JoiningType`].
612+
///
613+
/// ✨ *Enabled with the `compiled_data` Cargo feature.*
614+
///
615+
/// [📚 Help choosing a constructor](icu_provider::constructors)
616+
///
617+
/// # Example
618+
///
619+
/// ```
620+
/// use icu::properties::{maps, JoiningType};
621+
///
622+
/// assert_eq!(maps::joining_type().get('ؠ'), JoiningType::DualJoining); // U+0620: Arabic Letter Kashmiri Yeh
623+
/// assert_eq!(maps::joining_type().get('𐫍'), JoiningType::LeftJoining); // U+10ACD: Manichaean Letter Heth
624+
/// ```
625+
pub const joining_type => SINGLETON_PROPS_JT_V1;
626+
pub fn load_joining_type();
627+
}

components/properties/src/props.rs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2363,3 +2363,95 @@ impl_value_getter! {
23632363
pub fn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed;
23642364
}
23652365
}
2366+
/// Enumerated property Joining_Type.
2367+
/// See Section 9.2, Arabic Cursive Joining in The Unicode Standard for the summary of
2368+
/// each property value.
2369+
///
2370+
/// The numeric value is compatible with `UJoiningType` in ICU4C.
2371+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
2372+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2373+
#[cfg_attr(feature = "datagen", derive(databake::Bake))]
2374+
#[cfg_attr(feature = "datagen", databake(path = icu_properties))]
2375+
#[allow(clippy::exhaustive_structs)] // newtype
2376+
#[repr(transparent)]
2377+
#[zerovec::make_ule(JoiningTypeULE)]
2378+
pub struct JoiningType(pub u8);
2379+
2380+
#[allow(missing_docs)] // These constants don't need individual documentation.
2381+
#[allow(non_upper_case_globals)]
2382+
impl JoiningType {
2383+
pub const NonJoining: JoiningType = JoiningType(0); // name="U"
2384+
pub const JoinCausing: JoiningType = JoiningType(1); // name="C"
2385+
pub const DualJoining: JoiningType = JoiningType(2); // name="D"
2386+
pub const LeftJoining: JoiningType = JoiningType(3); // name="L"
2387+
pub const RightJoining: JoiningType = JoiningType(4); // name="R"
2388+
pub const Transparent: JoiningType = JoiningType(5); // name="T"
2389+
}
2390+
2391+
impl_value_getter! {
2392+
markers: JoiningTypeNameToValueV1Marker / SINGLETON_PROPNAMES_FROM_JT_V1, JoiningTypeValueToShortNameV1Marker / SINGLETON_PROPNAMES_TO_SHORT_LINEAR_JT_V1, JoiningTypeValueToLongNameV1Marker / SINGLETON_PROPNAMES_TO_LONG_LINEAR_JT_V1;
2393+
impl JoiningType {
2394+
/// Return a [`PropertyValueNameToEnumMapper`], capable of looking up values
2395+
/// from strings for the `Joining_Type` enumerated property.
2396+
///
2397+
/// ✨ *Enabled with the `compiled_data` Cargo feature.*
2398+
///
2399+
/// [📚 Help choosing a constructor](icu_provider::constructors)
2400+
///
2401+
/// # Example
2402+
///
2403+
/// ```
2404+
/// use icu::properties::JoiningType;
2405+
///
2406+
/// let lookup = JoiningType::name_to_enum_mapper();
2407+
/// // short name for value
2408+
/// assert_eq!(lookup.get_strict("T"), Some(JoiningType::Transparent));
2409+
/// assert_eq!(lookup.get_strict("D"), Some(JoiningType::DualJoining));
2410+
/// // long name for value
2411+
/// assert_eq!(lookup.get_strict("Join_Causing"), Some(JoiningType::JoinCausing));
2412+
/// assert_eq!(lookup.get_strict("Non_Joining"), Some(JoiningType::NonJoining));
2413+
/// // name has incorrect casing
2414+
/// assert_eq!(lookup.get_strict("LEFT_JOINING"), None);
2415+
/// // loose matching of name
2416+
/// assert_eq!(lookup.get_loose("LEFT_JOINING"), Some(JoiningType::LeftJoining));
2417+
/// // fake property
2418+
/// assert_eq!(lookup.get_strict("Inner_Joining"), None);
2419+
/// ```
2420+
pub fn get_name_to_enum_mapper() / name_to_enum_mapper();
2421+
/// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up short names
2422+
/// for values of the `Joining_Type` enumerated property.
2423+
///
2424+
/// ✨ *Enabled with the `compiled_data` Cargo feature.*
2425+
///
2426+
/// [📚 Help choosing a constructor](icu_provider::constructors)
2427+
///
2428+
/// # Example
2429+
///
2430+
/// ```
2431+
/// use icu::properties::JoiningType;
2432+
///
2433+
/// let lookup = JoiningType::enum_to_short_name_mapper();
2434+
/// assert_eq!(lookup.get(JoiningType::JoinCausing), Some("C"));
2435+
/// assert_eq!(lookup.get(JoiningType::LeftJoining), Some("L"));
2436+
/// ```
2437+
pub fn get_enum_to_short_name_mapper() / enum_to_short_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed;
2438+
/// Return a [`PropertyEnumToValueNameLinearMapper`], capable of looking up long names
2439+
/// for values of the `Joining_Type` enumerated property.
2440+
///
2441+
/// ✨ *Enabled with the `compiled_data` Cargo feature.*
2442+
///
2443+
/// [📚 Help choosing a constructor](icu_provider::constructors)
2444+
///
2445+
/// # Example
2446+
///
2447+
/// ```
2448+
/// use icu::properties::JoiningType;
2449+
///
2450+
/// let lookup = JoiningType::enum_to_long_name_mapper();
2451+
/// assert_eq!(lookup.get(JoiningType::Transparent), Some("Transparent"));
2452+
/// assert_eq!(lookup.get(JoiningType::NonJoining), Some("Non_Joining"));
2453+
/// assert_eq!(lookup.get(JoiningType::RightJoining), Some("Right_Joining"));
2454+
/// ```
2455+
pub fn get_enum_to_long_name_mapper() / enum_to_long_name_mapper() -> PropertyEnumToValueNameLinearMapper / PropertyEnumToValueNameLinearMapperBorrowed;
2456+
}
2457+
}

components/properties/src/provider.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const _: () = {
5757
icu_properties_data::impl_propnames_from_gc_v1!(Baked);
5858
icu_properties_data::impl_propnames_from_gcm_v1!(Baked);
5959
icu_properties_data::impl_propnames_from_insc_v1!(Baked);
60+
icu_properties_data::impl_propnames_from_jt_v1!(Baked);
6061
icu_properties_data::impl_propnames_from_lb_v1!(Baked);
6162
icu_properties_data::impl_propnames_from_sb_v1!(Baked);
6263
icu_properties_data::impl_propnames_from_sc_v1!(Baked);
@@ -66,6 +67,7 @@ const _: () = {
6667
icu_properties_data::impl_propnames_to_long_linear_gc_v1!(Baked);
6768
icu_properties_data::impl_propnames_to_long_linear_gcb_v1!(Baked);
6869
icu_properties_data::impl_propnames_to_long_linear_insc_v1!(Baked);
70+
icu_properties_data::impl_propnames_to_long_linear_jt_v1!(Baked);
6971
icu_properties_data::impl_propnames_to_long_linear_lb_v1!(Baked);
7072
icu_properties_data::impl_propnames_to_long_linear_sb_v1!(Baked);
7173
icu_properties_data::impl_propnames_to_long_linear_sc_v1!(Baked);
@@ -76,6 +78,7 @@ const _: () = {
7678
icu_properties_data::impl_propnames_to_short_linear_gc_v1!(Baked);
7779
icu_properties_data::impl_propnames_to_short_linear_gcb_v1!(Baked);
7880
icu_properties_data::impl_propnames_to_short_linear_insc_v1!(Baked);
81+
icu_properties_data::impl_propnames_to_short_linear_jt_v1!(Baked);
7982
icu_properties_data::impl_propnames_to_short_linear_lb_v1!(Baked);
8083
icu_properties_data::impl_propnames_to_short_linear_sb_v1!(Baked);
8184
icu_properties_data::impl_propnames_to_short_linear_wb_v1!(Baked);
@@ -132,6 +135,7 @@ const _: () = {
132135
icu_properties_data::impl_props_idst_v1!(Baked);
133136
icu_properties_data::impl_props_insc_v1!(Baked);
134137
icu_properties_data::impl_props_join_c_v1!(Baked);
138+
icu_properties_data::impl_props_jt_v1!(Baked);
135139
icu_properties_data::impl_props_lb_v1!(Baked);
136140
icu_properties_data::impl_props_loe_v1!(Baked);
137141
icu_properties_data::impl_props_lower_v1!(Baked);
@@ -895,6 +899,16 @@ expand!(
895899
"InSC",
896900
IndicSyllabicCategory
897901
),
902+
(
903+
JoiningTypeV1Marker,
904+
JoiningTypeNameToValueV1Marker,
905+
(
906+
linear: JoiningTypeValueToShortNameV1Marker,
907+
JoiningTypeValueToLongNameV1Marker
908+
),
909+
"jt",
910+
JoiningType
911+
),
898912
// note: the names key for the GCM mask is handled above
899913
)
900914
);

components/properties/src/trievalue.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use crate::provider::bidi_data::{
88
use crate::script::ScriptWithExt;
99
use crate::{
1010
BidiClass, CanonicalCombiningClass, EastAsianWidth, GeneralCategory, GeneralCategoryGroup,
11-
GraphemeClusterBreak, IndicSyllabicCategory, LineBreak, Script, SentenceBreak, WordBreak,
11+
GraphemeClusterBreak, IndicSyllabicCategory, JoiningType, LineBreak, Script, SentenceBreak,
12+
WordBreak,
1213
};
1314
use core::convert::TryInto;
1415
use core::num::TryFromIntError;
@@ -246,3 +247,15 @@ impl TrieValue for MirroredPairedBracketData {
246247
Self::try_from(i)
247248
}
248249
}
250+
251+
impl TrieValue for JoiningType {
252+
type TryFromU32Error = TryFromIntError;
253+
254+
fn try_from_u32(i: u32) -> Result<Self, Self::TryFromU32Error> {
255+
u8::try_from(i).map(Self)
256+
}
257+
258+
fn to_u32(self) -> u32 {
259+
u32::from(self.0)
260+
}
261+
}

ffi/capi/dart/package/lib/src/lib.g.dart

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

0 commit comments

Comments
 (0)