@@ -12,19 +12,6 @@ use icu_properties::props::{BidiClass, GeneralCategory, GraphemeClusterBreak, Sc
1212#[ cfg( feature = "baked" ) ]
1313pub mod generated;
1414
15- /// Lookup for [`Properties`]
16- #[ derive( Clone , Debug , Copy ) ]
17- pub struct CompositeProps ;
18-
19- #[ cfg( feature = "baked" ) ]
20- impl CompositeProps {
21- /// Returns the properties for a given character.
22- #[ inline( always) ]
23- pub fn properties ( & self , ch : u32 ) -> Properties {
24- Properties ( generated:: COMPOSITE . get32 ( ch) )
25- }
26- }
27-
2815/// Unicode character properties relevant for text analysis.
2916#[ derive( Copy , Clone , Debug ) ]
3017pub struct Properties ( u32 ) ;
@@ -51,8 +38,13 @@ impl Properties {
5138 const IS_MANDATORY_LINE_BREAK_SHIFT : u32 =
5239 Self :: IS_REGION_INDICATOR_SHIFT + Self :: IS_REGION_INDICATOR_BITS ;
5340
54- /// Packs the given arguments into a single u32.
55- #[ cfg( feature = "datagen" ) ]
41+ #[ cfg( feature = "baked" ) ]
42+ /// Returns the properties for a given character.
43+ pub fn get ( ch : char ) -> Self {
44+ Self ( generated:: COMPOSITE . get ( ch) )
45+ }
46+
47+ /// Creates a new [`Properties`] from the given properties
5648 pub fn new (
5749 script : Script ,
5850 gc : GeneralCategory ,
@@ -81,7 +73,7 @@ impl Properties {
8173 }
8274
8375 #[ inline( always) ]
84- fn get ( & self , shift : u32 , bits : u32 ) -> u32 {
76+ fn bits ( & self , shift : u32 , bits : u32 ) -> u32 {
8577 ( self . 0 >> shift) & ( ( 1 << bits) - 1 )
8678 }
8779
@@ -92,7 +84,7 @@ impl Properties {
9284 clippy:: cast_possible_truncation,
9385 reason = "script data only occupies SCRIPT_BITS bits; we cast to `u16` to fulfil the `from_icu4c_value` contract."
9486 ) ]
95- Script :: from_icu4c_value ( self . get ( Self :: SCRIPT_SHIFT , Self :: SCRIPT_BITS ) as u16 )
87+ Script :: from_icu4c_value ( self . bits ( Self :: SCRIPT_SHIFT , Self :: SCRIPT_BITS ) as u16 )
9688 }
9789
9890 /// Returns the general category for the character.
@@ -102,7 +94,7 @@ impl Properties {
10294 clippy:: cast_possible_truncation,
10395 reason = "general category data only occupies GC_BITS bits."
10496 ) ]
105- GeneralCategory :: try_from ( self . get ( Self :: GC_SHIFT , Self :: GC_BITS ) as u8 ) . unwrap ( )
97+ GeneralCategory :: try_from ( self . bits ( Self :: GC_SHIFT , Self :: GC_BITS ) as u8 ) . unwrap ( )
10698 }
10799
108100 /// Returns the grapheme cluster break for the character.
@@ -112,7 +104,7 @@ impl Properties {
112104 clippy:: cast_possible_truncation,
113105 reason = "cluster break data only occupies GCB_BITS bits"
114106 ) ]
115- GraphemeClusterBreak :: from_icu4c_value ( self . get ( Self :: GCB_SHIFT , Self :: GCB_BITS ) as u8 )
107+ GraphemeClusterBreak :: from_icu4c_value ( self . bits ( Self :: GCB_SHIFT , Self :: GCB_BITS ) as u8 )
116108 }
117109
118110 /// Returns the bidirectional class for the character.
@@ -122,13 +114,13 @@ impl Properties {
122114 clippy:: cast_possible_truncation,
123115 reason = "bidi class data only occupies BIDI_BITS bits"
124116 ) ]
125- BidiClass :: from_icu4c_value ( self . get ( Self :: BIDI_SHIFT , Self :: BIDI_BITS ) as u8 )
117+ BidiClass :: from_icu4c_value ( self . bits ( Self :: BIDI_SHIFT , Self :: BIDI_BITS ) as u8 )
126118 }
127119
128120 /// Returns whether the character is an emoji or pictograph.
129121 #[ inline( always) ]
130122 pub fn is_emoji_or_pictograph ( & self ) -> bool {
131- self . get (
123+ self . bits (
132124 Self :: IS_EMOJI_OR_PICTOGRAPH_SHIFT ,
133125 Self :: IS_EMOJI_OR_PICTOGRAPH_BITS ,
134126 ) != 0
@@ -137,7 +129,7 @@ impl Properties {
137129 /// Returns whether the character is a variation selector.
138130 #[ inline( always) ]
139131 pub fn is_variation_selector ( & self ) -> bool {
140- self . get (
132+ self . bits (
141133 Self :: IS_VARIATION_SELECTOR_SHIFT ,
142134 Self :: IS_VARIATION_SELECTOR_BITS ,
143135 ) != 0
@@ -146,7 +138,7 @@ impl Properties {
146138 /// Returns whether the character is a region indicator.
147139 #[ inline( always) ]
148140 pub fn is_region_indicator ( & self ) -> bool {
149- self . get (
141+ self . bits (
150142 Self :: IS_REGION_INDICATOR_SHIFT ,
151143 Self :: IS_REGION_INDICATOR_BITS ,
152144 ) != 0
@@ -155,7 +147,7 @@ impl Properties {
155147 /// Returns whether the character is a mandatory linebreak.
156148 #[ inline( always) ]
157149 pub fn is_mandatory_linebreak ( & self ) -> bool {
158- self . get (
150+ self . bits (
159151 Self :: IS_MANDATORY_LINE_BREAK_SHIFT ,
160152 Self :: IS_MANDATORY_LINE_BREAK_BITS ,
161153 ) != 0
0 commit comments