Skip to content

Commit

Permalink
Add Hangul_Syllable_Type (#4885)
Browse files Browse the repository at this point in the history
Fixes #4884
  • Loading branch information
sffc committed May 10, 2024
1 parent 84986f7 commit c2b78e7
Show file tree
Hide file tree
Showing 44 changed files with 2,319 additions and 52 deletions.
4 changes: 2 additions & 2 deletions components/properties/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ mod trievalue;

pub use props::{
BidiClass, CanonicalCombiningClass, EastAsianWidth, GeneralCategory, GeneralCategoryGroup,
GraphemeClusterBreak, IndicSyllabicCategory, JoiningType, LineBreak, Script, SentenceBreak,
WordBreak,
GraphemeClusterBreak, HangulSyllableType, IndicSyllabicCategory, JoiningType, LineBreak,
Script, SentenceBreak, WordBreak,
};

/// Module for working with the names of property values
Expand Down
26 changes: 26 additions & 0 deletions components/properties/src/maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,32 @@ make_map_property! {
pub fn load_script();
}

make_map_property! {
property: "Hangul_Syllable_Type";
marker: HangulSyllableTypeProperty;
value: crate::HangulSyllableType;
keyed_data_marker: HangulSyllableTypeV1Marker;
func:
/// Returns a [`CodePointMapDataBorrowed`] for the Hangul_Syllable_Type
/// Unicode enumerated property. See [`HangulSyllableType`].
///
/// ✨ *Enabled with the `compiled_data` Cargo feature.*
///
/// [📚 Help choosing a constructor](icu_provider::constructors)
///
/// # Example
///
/// ```
/// use icu::properties::{maps, HangulSyllableType};
///
/// assert_eq!(maps::hangul_syllable_type().get('ᄀ'), HangulSyllableType::LeadingJamo); // U+1100
/// assert_eq!(maps::hangul_syllable_type().get('가'), HangulSyllableType::LeadingVowelSyllable); // U+AC00
/// ```

pub const hangul_syllable_type => SINGLETON_PROPS_HST_V1;
pub fn load_hangul_syllable_type();
}

make_map_property! {
property: "East_Asian_Width";
marker: EastAsianWidthProperty;
Expand Down
108 changes: 108 additions & 0 deletions components/properties/src/props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1578,6 +1578,106 @@ impl_value_getter! {
}
}

/// 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)]
pub struct HangulSyllableType(pub u8);

create_const_array! {
#[allow(non_upper_case_globals)]
impl HangulSyllableType {
/// (`NA`) not applicable (e.g. not a Hangul code point).
pub const NotApplicable: HangulSyllableType = HangulSyllableType(0);
/// (`L`) a conjoining leading consonant Jamo.
pub const LeadingJamo: HangulSyllableType = HangulSyllableType(1);
/// (`V`) a conjoining vowel Jamo.
pub const VowelJamo: HangulSyllableType = HangulSyllableType(2);
/// (`T`) a conjoining trailing consonent Jamo.
pub const TrailingJamo: HangulSyllableType = HangulSyllableType(3);
/// (`LV`) a precomposed syllable with a leading consonant and a vowel.
pub const LeadingVowelSyllable: HangulSyllableType = HangulSyllableType(4);
/// (`LVT`) a precomposed syllable with a leading consonant, a vowel, and a trailing consonant.
pub const 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);
/// ```
pub fn 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"));
/// ```
pub fn 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"));
/// ```
pub fn 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:
Expand Down Expand Up @@ -2616,4 +2716,12 @@ mod test_enumerated_property_completeness {
BidiClass::ALL_CONSTS,
);
}

#[test]
fn test_hst() {
check_enum(
crate::provider::Baked::SINGLETON_PROPNAMES_FROM_HST_V1,
HangulSyllableType::ALL_CONSTS,
);
}
}
14 changes: 14 additions & 0 deletions components/properties/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const _: () = {
icu_properties_data::impl_propnames_from_ea_v1!(Baked);
icu_properties_data::impl_propnames_from_gc_v1!(Baked);
icu_properties_data::impl_propnames_from_gcm_v1!(Baked);
icu_properties_data::impl_propnames_from_hst_v1!(Baked);
icu_properties_data::impl_propnames_from_insc_v1!(Baked);
icu_properties_data::impl_propnames_from_jt_v1!(Baked);
icu_properties_data::impl_propnames_from_lb_v1!(Baked);
Expand All @@ -67,6 +68,7 @@ const _: () = {
icu_properties_data::impl_propnames_to_long_linear_ea_v1!(Baked);
icu_properties_data::impl_propnames_to_long_linear_gc_v1!(Baked);
icu_properties_data::impl_propnames_to_long_linear_gcb_v1!(Baked);
icu_properties_data::impl_propnames_to_long_linear_hst_v1!(Baked);
icu_properties_data::impl_propnames_to_long_linear_insc_v1!(Baked);
icu_properties_data::impl_propnames_to_long_linear_jt_v1!(Baked);
icu_properties_data::impl_propnames_to_long_linear_lb_v1!(Baked);
Expand All @@ -78,6 +80,7 @@ const _: () = {
icu_properties_data::impl_propnames_to_short_linear_ea_v1!(Baked);
icu_properties_data::impl_propnames_to_short_linear_gc_v1!(Baked);
icu_properties_data::impl_propnames_to_short_linear_gcb_v1!(Baked);
icu_properties_data::impl_propnames_to_short_linear_hst_v1!(Baked);
icu_properties_data::impl_propnames_to_short_linear_insc_v1!(Baked);
icu_properties_data::impl_propnames_to_short_linear_jt_v1!(Baked);
icu_properties_data::impl_propnames_to_short_linear_lb_v1!(Baked);
Expand Down Expand Up @@ -128,6 +131,7 @@ const _: () = {
icu_properties_data::impl_props_gr_link_v1!(Baked);
icu_properties_data::impl_props_graph_v1!(Baked);
icu_properties_data::impl_props_hex_v1!(Baked);
icu_properties_data::impl_props_hst_v1!(Baked);
icu_properties_data::impl_props_hyphen_v1!(Baked);
icu_properties_data::impl_props_idc_v1!(Baked);
icu_properties_data::impl_props_ideo_v1!(Baked);
Expand Down Expand Up @@ -840,6 +844,16 @@ expand!(
"sc",
Script
),
(
HangulSyllableTypeV1Marker,
HangulSyllableTypeNameToValueV1Marker,
(
linear: HangulSyllableTypeValueToShortNameV1Marker,
HangulSyllableTypeValueToLongNameV1Marker
),
"hst",
HangulSyllableType
),
(
EastAsianWidthV1Marker,
EastAsianWidthNameToValueV1Marker,
Expand Down
16 changes: 14 additions & 2 deletions components/properties/src/trievalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::provider::bidi_data::{
use crate::script::ScriptWithExt;
use crate::{
BidiClass, CanonicalCombiningClass, EastAsianWidth, GeneralCategory, GeneralCategoryGroup,
GraphemeClusterBreak, IndicSyllabicCategory, JoiningType, LineBreak, Script, SentenceBreak,
WordBreak,
GraphemeClusterBreak, HangulSyllableType, IndicSyllabicCategory, JoiningType, LineBreak,
Script, SentenceBreak, WordBreak,
};
use core::convert::TryInto;
use core::num::TryFromIntError;
Expand Down Expand Up @@ -69,6 +69,18 @@ impl TrieValue for Script {
}
}

impl TrieValue for HangulSyllableType {
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 ScriptWithExt {
type TryFromU32Error = TryFromIntError;

Expand Down
2 changes: 2 additions & 0 deletions ffi/capi/bindings/c/ICU4XCodePointMapData8.h

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

4 changes: 3 additions & 1 deletion ffi/capi/bindings/c/ICU4XPropertyValueNameToEnumMapper.h

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

2 changes: 2 additions & 0 deletions ffi/capi/bindings/cpp/ICU4XCodePointMapData8.h

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

15 changes: 15 additions & 0 deletions ffi/capi/bindings/cpp/ICU4XCodePointMapData8.hpp

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

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

4 changes: 3 additions & 1 deletion ffi/capi/bindings/cpp/ICU4XPropertyValueNameToEnumMapper.h

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

0 comments on commit c2b78e7

Please sign in to comment.