Skip to content
Merged
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
2 changes: 1 addition & 1 deletion components/properties/src/code_point_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ impl<'a> CodePointMapDataBorrowed<'a, GeneralCategory> {
/// </div>
///
/// [`TR44`]: https://www.unicode.org/reports/tr44
pub trait EnumeratedProperty: crate::private::Sealed + TrieValue {
pub trait EnumeratedProperty: crate::private::Sealed + TrieValue + Default {
#[doc(hidden)]
type DataMarker: DataMarker<DataStruct = PropertyCodePointMap<'static, Self>>;
#[doc(hidden)]
Expand Down
36 changes: 34 additions & 2 deletions components/properties/src/props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@ macro_rules! create_const_array {
(
$ ( #[$meta:meta] )*
impl $enum_ty:ident {
#[default]
$(#[$default_meta:meta])* $dv:vis const $di:ident: $dt:ty = $de:expr;
$( $(#[$const_meta:meta])* $v:vis const $i:ident: $t:ty = $e:expr; )*
}
#[test]
fn $consts_test:ident();
) => {
$( #[$meta] )*
impl $enum_ty {
$(#[$default_meta])*
$dv const $di: $dt = $de;
$(
$(#[$const_meta])*
$v const $i: $t = $e;
Expand All @@ -51,15 +55,23 @@ macro_rules! create_const_array {
/// All possible values of this enum in the Unicode version
/// from this ICU4X release.
pub const ALL_VALUES: &'static [$enum_ty] = &[
$enum_ty::$di,
$($enum_ty::$i),*
];
}

impl Default for $enum_ty {
fn default() -> Self {
Self::$di
}
}

#[cfg(feature = "datagen")]
impl databake::Bake for $enum_ty {
fn bake(&self, env: &databake::CrateEnv) -> databake::TokenStream {
env.insert("icu_properties");
match *self {
$enum_ty::$di => databake::quote!(icu_properties::props::$enum_ty::$di),
$(
Self::$i => databake::quote!(icu_properties::props::$enum_ty::$i),
)*
Expand All @@ -78,6 +90,10 @@ macro_rules! create_const_array {

#[test]
fn $consts_test() {
assert_eq!(
crate::names::PropertyNamesLong::<$enum_ty>::new().get($enum_ty::$di).unwrap().replace('_', ""),
stringify!($di)
);
$(
assert_eq!(
crate::names::PropertyNamesLong::<$enum_ty>::new().get($enum_ty::$i).unwrap()
Expand Down Expand Up @@ -174,6 +190,7 @@ impl BidiClass {
create_const_array! {
#[allow(non_upper_case_globals)]
impl BidiClass {
#[default]
/// (`L`) any strong left-to-right character
pub const LeftToRight: BidiClass = BidiClass(0);
/// (`R`) any strong right-to-left (non-Arabic-type) character
Expand Down Expand Up @@ -273,6 +290,7 @@ impl NumericType {
create_const_array! {
#[allow(non_upper_case_globals)]
impl NumericType {
#[default]
/// Characters without numeric value
pub const None: NumericType = NumericType(0);
/// (`De`) Characters of positional decimal systems
Expand Down Expand Up @@ -327,7 +345,7 @@ pub(crate) mod gc {
/// GeneralCategory::OtherSymbol
/// ); // U+1F383 JACK-O-LANTERN
/// ```
#[derive(Copy, Clone, PartialEq, Eq, Debug, Ord, PartialOrd, Hash)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Ord, PartialOrd, Hash, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "datagen", derive(databake::Bake))]
#[cfg_attr(feature = "datagen", databake(path = icu_properties::props))]
Expand All @@ -336,6 +354,7 @@ pub(crate) mod gc {
#[cfg_attr(not(feature = "alloc"), zerovec::skip_derive(ZeroMapKV))]
#[repr(u8)]
pub enum GeneralCategory {
#[default]
/// (`Cn`) A reserved unassigned code point or a noncharacter
Unassigned = 0,

Expand Down Expand Up @@ -823,6 +842,8 @@ create_const_array! {
#[allow(missing_docs)] // These constants don't need individual documentation.
#[allow(non_upper_case_globals)]
impl Script {
#[default]
pub const Unknown: Script = Script(103);
pub const Adlam: Script = Script(167);
pub const Ahom: Script = Script(161);
pub const AnatolianHieroglyphs: Script = Script(156);
Expand Down Expand Up @@ -991,7 +1012,6 @@ impl Script {
pub const Toto: Script = Script(196);
pub const TuluTigalari: Script = Script(207);
pub const Ugaritic: Script = Script(53);
pub const Unknown: Script = Script(103);
pub const Vai: Script = Script(99);
pub const Vithkuqi: Script = Script(197);
pub const Wancho: Script = Script(188);
Expand Down Expand Up @@ -1083,6 +1103,7 @@ impl HangulSyllableType {
create_const_array! {
#[allow(non_upper_case_globals)]
impl HangulSyllableType {
#[default]
/// (`NA`) not applicable (e.g. not a Hangul code point).
pub const NotApplicable: HangulSyllableType = HangulSyllableType(0);
/// (`L`) a conjoining leading consonant Jamo.
Expand Down Expand Up @@ -1150,6 +1171,7 @@ create_const_array! {
#[allow(missing_docs)] // These constants don't need individual documentation.
#[allow(non_upper_case_globals)]
impl EastAsianWidth {
#[default]
pub const Neutral: EastAsianWidth = EastAsianWidth(0); //name="N"
pub const Ambiguous: EastAsianWidth = EastAsianWidth(1); //name="A"
pub const Halfwidth: EastAsianWidth = EastAsianWidth(2); //name="H"
Expand Down Expand Up @@ -1214,6 +1236,7 @@ create_const_array! {
#[allow(missing_docs)] // These constants don't need individual documentation.
#[allow(non_upper_case_globals)]
impl LineBreak {
#[default]
pub const Unknown: LineBreak = LineBreak(0); // name="XX"
pub const Ambiguous: LineBreak = LineBreak(1); // name="AI"
pub const Alphabetic: LineBreak = LineBreak(2); // name="AL"
Expand Down Expand Up @@ -1324,6 +1347,7 @@ create_const_array! {
#[allow(missing_docs)] // These constants don't need individual documentation.
#[allow(non_upper_case_globals)]
impl GraphemeClusterBreak {
#[default]
pub const Other: GraphemeClusterBreak = GraphemeClusterBreak(0); // name="XX"
pub const Control: GraphemeClusterBreak = GraphemeClusterBreak(1); // name="CN"
pub const CR: GraphemeClusterBreak = GraphemeClusterBreak(2); // name="CR"
Expand Down Expand Up @@ -1403,6 +1427,7 @@ create_const_array! {
#[allow(missing_docs)] // These constants don't need individual documentation.
#[allow(non_upper_case_globals)]
impl WordBreak {
#[default]
pub const Other: WordBreak = WordBreak(0); // name="XX"
pub const ALetter: WordBreak = WordBreak(1); // name="LE"
pub const Format: WordBreak = WordBreak(2); // name="FO"
Expand Down Expand Up @@ -1487,6 +1512,7 @@ create_const_array! {
#[allow(missing_docs)] // These constants don't need individual documentation.
#[allow(non_upper_case_globals)]
impl SentenceBreak {
#[default]
pub const Other: SentenceBreak = SentenceBreak(0); // name="XX"
pub const ATerm: SentenceBreak = SentenceBreak(1); // name="AT"
pub const Close: SentenceBreak = SentenceBreak(2); // name="CL"
Expand Down Expand Up @@ -1567,6 +1593,7 @@ create_const_array! {
#[allow(missing_docs)] // These constants don't need individual documentation.
#[allow(non_upper_case_globals)]
impl CanonicalCombiningClass {
#[default]
pub const NotReordered: CanonicalCombiningClass = CanonicalCombiningClass(0); // name="NR"
pub const Overlay: CanonicalCombiningClass = CanonicalCombiningClass(1); // name="OV"
pub const HanReading: CanonicalCombiningClass = CanonicalCombiningClass(6); // name="HANR"
Expand Down Expand Up @@ -1686,6 +1713,7 @@ create_const_array! {
#[allow(missing_docs)] // These constants don't need individual documentation.
#[allow(non_upper_case_globals)]
impl IndicConjunctBreak {
#[default]
pub const None: IndicConjunctBreak = IndicConjunctBreak(0);
pub const Consonant: IndicConjunctBreak = IndicConjunctBreak(1);
pub const Extend: IndicConjunctBreak = IndicConjunctBreak(2);
Expand Down Expand Up @@ -1743,6 +1771,7 @@ create_const_array! {
#[allow(missing_docs)] // These constants don't need individual documentation.
#[allow(non_upper_case_globals)]
impl IndicSyllabicCategory {
#[default]
pub const Other: IndicSyllabicCategory = IndicSyllabicCategory(0);
pub const Avagraha: IndicSyllabicCategory = IndicSyllabicCategory(1);
pub const Bindu: IndicSyllabicCategory = IndicSyllabicCategory(2);
Expand Down Expand Up @@ -1832,6 +1861,7 @@ create_const_array! {
#[allow(missing_docs)] // These constants don't need individual documentation.
#[allow(non_upper_case_globals)]
impl JoiningGroup {
#[default]
pub const NoJoiningGroup: JoiningGroup = JoiningGroup(0);
pub const Ain: JoiningGroup = JoiningGroup(1);
pub const Alaph: JoiningGroup = JoiningGroup(2);
Expand Down Expand Up @@ -1992,6 +2022,7 @@ create_const_array! {
#[allow(missing_docs)] // These constants don't need individual documentation.
#[allow(non_upper_case_globals)]
impl JoiningType {
#[default]
pub const NonJoining: JoiningType = JoiningType(0); // name="U"
pub const JoinCausing: JoiningType = JoiningType(1); // name="C"
pub const DualJoining: JoiningType = JoiningType(2); // name="D"
Expand Down Expand Up @@ -2060,6 +2091,7 @@ create_const_array! {
#[allow(missing_docs)] // These constants don't need individual documentation.
#[allow(non_upper_case_globals)]
impl VerticalOrientation {
#[default]
pub const Rotated: VerticalOrientation = VerticalOrientation(0); // name="R"
pub const TransformedRotated: VerticalOrientation = VerticalOrientation(1); // name="Tr"
pub const TransformedUpright: VerticalOrientation = VerticalOrientation(2); // name="Tu"
Expand Down
14 changes: 13 additions & 1 deletion components/properties/src/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,19 @@ pub struct ScriptWithExt(pub u16);
#[allow(non_upper_case_globals)]
#[doc(hidden)] // `ScriptWithExt` not intended as public-facing but for `ScriptWithExtensionsProperty` constructor
impl ScriptWithExt {
pub const Unknown: ScriptWithExt = ScriptWithExt(0);
pub const Unknown: ScriptWithExt = Self::single(Script::Unknown);

pub const fn single(script: Script) -> Self {
Self(script.to_icu4c_value() & SCRIPT_X_SCRIPT_VAL)
}

pub const fn new(script: Script, extensions: u16) -> Self {
match script {
Script::Common => Self(1 << SCRIPT_VAL_LENGTH | extensions & SCRIPT_X_SCRIPT_VAL),
Script::Inherited => Self(2 << SCRIPT_VAL_LENGTH | extensions & SCRIPT_X_SCRIPT_VAL),
_script => Self(3 << SCRIPT_VAL_LENGTH | extensions & SCRIPT_X_SCRIPT_VAL),
}
}
}

impl AsULE for ScriptWithExt {
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions provider/data/properties/fingerprints.csv
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ property/binary/white/space/v1, <singleton>, 92B, 62B, 8f045d65fbaa6724
property/binary/xdigit/v1, <singleton>, 488B, 459B, 334cc78d29ee5f0e
property/binary/xid/continue/v1, <singleton>, 4868B, 4839B, 386b045eb6522e2f
property/binary/xid/start/v1, <singleton>, 4178B, 4149B, 5090f2f1b95a3480
property/enum/bidi/class/v1, <singleton>, 9884B, 9828B, 327160efebade591
property/enum/bidi/class/v1, <singleton>, 9888B, 9832B, 6e461ef365a53dcc
property/enum/bidi/mirroring/glyph/v1, <singleton>, 4739B, 4673B, 34ba0898d34a25fb
property/enum/canonical/combining/class/v1, <singleton>, 5452B, 5394B, 6c5392d6fc5f2889
property/enum/east/asian/width/v1, <singleton>, 5004B, 4947B, 881a7ee1402b1937
Expand All @@ -81,7 +81,7 @@ property/enum/joining/group/v1, <singleton>, 1428B, 1370B, a24c126ff86065d8
property/enum/joining/type/v1, <singleton>, 7136B, 7079B, 39f05bd0b9931b55
property/enum/line/break/v1, <singleton>, 15328B, 15272B, d392409dfdd00a74
property/enum/numeric/type/v1, <singleton>, 5900B, 5842B, 9ffe79ebbb54f863
property/enum/script/v1, <singleton>, 25902B, 25847B, 1b972fe75ad7b369
property/enum/script/v1, <singleton>, 25896B, 25841B, 56731d765569d131
property/enum/sentence/break/v1, <singleton>, 13964B, 13907B, 36e6dafc005907f8
property/enum/vertical/orientation/v1, <singleton>, 3280B, 3222B, 36f945b6b4d90bc8
property/enum/word/break/v1, <singleton>, 11136B, 11079B, ae4831ff49f66415
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions provider/source/data/debug/property/enum/bidi/class/v1.json

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

3 changes: 0 additions & 3 deletions provider/source/data/debug/property/enum/script/v1.json

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

Loading
Loading