1 // This file is part of ICU4X. For terms of use, please see the file
2 // called LICENSE at the top level of the ICU4X source tree
3 // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
7 use crate::provider::ffi::ICU4XDataProvider;
10 names::PropertyValueNameToEnumMapper, BidiClass, EastAsianWidth, GeneralCategory,
11 GeneralCategoryGroup, GraphemeClusterBreak, HangulSyllableType, IndicSyllabicCategory,
12 LineBreak, Script, SentenceBreak, WordBreak,
15 use crate::errors::ffi::ICU4XError;
17 /// A type capable of looking up a property value from a string name.
19 #[diplomat::rust_link(icu::properties::names::PropertyValueNameToEnumMapper, Struct)]
20 #[diplomat::rust_link(icu::properties::names::PropertyValueNameToEnumMapperBorrowed, Struct)]
21 #[diplomat::rust_link(
22 icu::properties::names::PropertyValueNameToEnumMapper::from_data,
26 pub struct ICU4XPropertyValueNameToEnumMapper(PropertyValueNameToEnumMapper<u16>);
28 impl ICU4XPropertyValueNameToEnumMapper {
29 /// Get the property value matching the given name, using strict matching
31 /// Returns -1 if the name is unknown for this property
32 #[diplomat::rust_link(
33 icu::properties::names::PropertyValueNameToEnumMapperBorrowed::get_strict,
36 #[diplomat::rust_link(
37 icu::properties::names::PropertyValueNameToEnumMapperBorrowed::get_strict_u16,
41 pub fn get_strict(&self, name: &DiplomatStr) -> i16 {
42 if let Ok(name) = core::str::from_utf8(name) {
43 self.0.as_borrowed().get_strict(name)
47 .map(|u_16| u_16 as i16)
51 /// Get the property value matching the given name, using loose matching
53 /// Returns -1 if the name is unknown for this property
54 #[diplomat::rust_link(
55 icu::properties::names::PropertyValueNameToEnumMapperBorrowed::get_loose,
58 #[diplomat::rust_link(
59 icu::properties::names::PropertyValueNameToEnumMapperBorrowed::get_loose_u16,
63 pub fn get_loose(&self, name: &DiplomatStr) -> i16 {
64 if let Ok(name) = core::str::from_utf8(name) {
65 self.0.as_borrowed().get_loose(name)
69 .map(|u_16| u_16 as i16)
73 #[diplomat::rust_link(icu::properties::GeneralCategory::name_to_enum_mapper, FnInStruct)]
74 #[diplomat::rust_link(
75 icu::properties::GeneralCategory::get_name_to_enum_mapper,
79 #[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "general_category")]
80 pub fn load_general_category(
81 provider: &ICU4XDataProvider,
82 ) -> Result<Box<ICU4XPropertyValueNameToEnumMapper>, ICU4XError> {
83 Ok(Box::new(ICU4XPropertyValueNameToEnumMapper(
84 call_constructor_unstable!(
85 GeneralCategory::name_to_enum_mapper [r => Ok(r.static_to_owned())],
86 GeneralCategory::get_name_to_enum_mapper,
93 #[diplomat::rust_link(icu::properties::HangulSyllableType::name_to_enum_mapper, FnInStruct)]
94 #[diplomat::rust_link(
95 icu::properties::HangulSyllableType::get_name_to_enum_mapper,
99 #[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "hangul_syllable_type")]
100 pub fn load_hangul_syllable_type(
101 provider: &ICU4XDataProvider,
102 ) -> Result<Box<ICU4XPropertyValueNameToEnumMapper>, ICU4XError> {
103 Ok(Box::new(ICU4XPropertyValueNameToEnumMapper(
104 call_constructor_unstable!(
105 HangulSyllableType::name_to_enum_mapper [r => Ok(r.static_to_owned())],
106 HangulSyllableType::get_name_to_enum_mapper,
113 #[diplomat::rust_link(icu::properties::EastAsianWidth::name_to_enum_mapper, FnInStruct)]
114 #[diplomat::rust_link(
115 icu::properties::EastAsianWidth::get_name_to_enum_mapper,
119 #[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "east_asian_width")]
120 pub fn load_east_asian_width(
121 provider: &ICU4XDataProvider,
122 ) -> Result<Box<ICU4XPropertyValueNameToEnumMapper>, ICU4XError> {
123 Ok(Box::new(ICU4XPropertyValueNameToEnumMapper(
124 call_constructor_unstable!(
125 EastAsianWidth::name_to_enum_mapper [r => Ok(r.static_to_owned())],
126 EastAsianWidth::get_name_to_enum_mapper,
133 #[diplomat::rust_link(icu::properties::BidiClass::name_to_enum_mapper, FnInStruct)]
134 #[diplomat::rust_link(
135 icu::properties::BidiClass::get_name_to_enum_mapper,
139 #[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "bidi_class")]
140 pub fn load_bidi_class(
141 provider: &ICU4XDataProvider,
142 ) -> Result<Box<ICU4XPropertyValueNameToEnumMapper>, ICU4XError> {
143 Ok(Box::new(ICU4XPropertyValueNameToEnumMapper(
144 call_constructor_unstable!(
145 BidiClass::name_to_enum_mapper [r => Ok(r.static_to_owned())],
146 BidiClass::get_name_to_enum_mapper,
153 #[diplomat::rust_link(
154 icu::properties::IndicSyllabicCategory::name_to_enum_mapper,
157 #[diplomat::rust_link(
158 icu::properties::IndicSyllabicCategory::get_name_to_enum_mapper,
162 #[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "indic_syllabic_category")]
163 pub fn load_indic_syllabic_category(
164 provider: &ICU4XDataProvider,
165 ) -> Result<Box<ICU4XPropertyValueNameToEnumMapper>, ICU4XError> {
166 Ok(Box::new(ICU4XPropertyValueNameToEnumMapper(
167 call_constructor_unstable!(
168 IndicSyllabicCategory::name_to_enum_mapper [r => Ok(r.static_to_owned())],
169 IndicSyllabicCategory::get_name_to_enum_mapper,
176 #[diplomat::rust_link(icu::properties::LineBreak::name_to_enum_mapper, FnInStruct)]
177 #[diplomat::rust_link(
178 icu::properties::LineBreak::get_name_to_enum_mapper,
182 #[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "line_break")]
183 pub fn load_line_break(
184 provider: &ICU4XDataProvider,
185 ) -> Result<Box<ICU4XPropertyValueNameToEnumMapper>, ICU4XError> {
186 Ok(Box::new(ICU4XPropertyValueNameToEnumMapper(
187 call_constructor_unstable!(
188 LineBreak::name_to_enum_mapper [r => Ok(r.static_to_owned())],
189 LineBreak::get_name_to_enum_mapper,
196 #[diplomat::rust_link(
197 icu::properties::GraphemeClusterBreak::name_to_enum_mapper,
200 #[diplomat::rust_link(
201 icu::properties::GraphemeClusterBreak::get_name_to_enum_mapper,
205 #[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "grapheme_cluster_break")]
206 pub fn load_grapheme_cluster_break(
207 provider: &ICU4XDataProvider,
208 ) -> Result<Box<ICU4XPropertyValueNameToEnumMapper>, ICU4XError> {
209 Ok(Box::new(ICU4XPropertyValueNameToEnumMapper(
210 call_constructor_unstable!(
211 GraphemeClusterBreak::name_to_enum_mapper [r => Ok(r.static_to_owned())],
212 GraphemeClusterBreak::get_name_to_enum_mapper,
219 #[diplomat::rust_link(icu::properties::WordBreak::name_to_enum_mapper, FnInStruct)]
220 #[diplomat::rust_link(
221 icu::properties::WordBreak::get_name_to_enum_mapper,
225 #[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "word_break")]
226 pub fn load_word_break(
227 provider: &ICU4XDataProvider,
228 ) -> Result<Box<ICU4XPropertyValueNameToEnumMapper>, ICU4XError> {
229 Ok(Box::new(ICU4XPropertyValueNameToEnumMapper(
230 call_constructor_unstable!(
231 WordBreak::name_to_enum_mapper [r => Ok(r.static_to_owned())],
232 WordBreak::get_name_to_enum_mapper,
239 #[diplomat::rust_link(icu::properties::SentenceBreak::name_to_enum_mapper, FnInStruct)]
240 #[diplomat::rust_link(
241 icu::properties::SentenceBreak::get_name_to_enum_mapper,
245 #[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "sentence_break")]
246 pub fn load_sentence_break(
247 provider: &ICU4XDataProvider,
248 ) -> Result<Box<ICU4XPropertyValueNameToEnumMapper>, ICU4XError> {
249 Ok(Box::new(ICU4XPropertyValueNameToEnumMapper(
250 call_constructor_unstable!(
251 SentenceBreak::name_to_enum_mapper [r => Ok(r.static_to_owned())],
252 SentenceBreak::get_name_to_enum_mapper,
259 #[diplomat::rust_link(icu::properties::Script::name_to_enum_mapper, FnInStruct)]
260 #[diplomat::rust_link(icu::properties::Script::get_name_to_enum_mapper, FnInStruct, hidden)]
261 #[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "script")]
263 provider: &ICU4XDataProvider,
264 ) -> Result<Box<ICU4XPropertyValueNameToEnumMapper>, ICU4XError> {
265 Ok(Box::new(ICU4XPropertyValueNameToEnumMapper(
266 call_constructor_unstable!(
267 Script::name_to_enum_mapper [r => Ok(r.static_to_owned())],
268 Script::get_name_to_enum_mapper,
276 /// A type capable of looking up General Category mask values from a string name.
278 #[diplomat::rust_link(icu::properties::GeneralCategoryGroup::name_to_enum_mapper, FnInStruct)]
279 #[diplomat::rust_link(
280 icu::properties::GeneralCategoryGroup::get_name_to_enum_mapper,
284 #[diplomat::rust_link(icu::properties::names::PropertyValueNameToEnumMapper, Struct)]
285 pub struct ICU4XGeneralCategoryNameToMaskMapper(
286 PropertyValueNameToEnumMapper<GeneralCategoryGroup>,
289 impl ICU4XGeneralCategoryNameToMaskMapper {
290 /// Get the mask value matching the given name, using strict matching
292 /// Returns 0 if the name is unknown for this property
293 // #[diplomat::rust_link(icu::properties::maps::PropertyValueNameToEnumMapperBorrowed::get_strict, FnInStruct)]
294 // #[diplomat::rust_link(icu::properties::maps::PropertyValueNameToEnumMapperBorrowed::get_strict_u16, FnInStruct, hidden)]
295 pub fn get_strict(&self, name: &DiplomatStr) -> u32 {
296 if let Ok(name) = core::str::from_utf8(name) {
297 self.0.as_borrowed().get_strict(name)
305 /// Get the mask value matching the given name, using loose matching
307 /// Returns 0 if the name is unknown for this property
308 // #[diplomat::rust_link(icu::properties::maps::PropertyValueNameToEnumMapperBorrowed::get_loose, FnInStruct)]
309 // #[diplomat::rust_link(icu::properties::maps::PropertyValueNameToEnumMapperBorrowed::get_loose_u16, FnInStruct, hidden)]
310 pub fn get_loose(&self, name: &DiplomatStr) -> u32 {
311 if let Ok(name) = core::str::from_utf8(name) {
312 self.0.as_borrowed().get_loose(name)
320 #[diplomat::rust_link(
321 icu::properties::GeneralCategoryGroup::name_to_enum_mapper,
324 #[diplomat::rust_link(
325 icu::properties::GeneralCategoryGroup::get_name_to_enum_mapper,
329 #[diplomat::attr(all(supports = constructors, supports = fallible_constructors), constructor)]
331 provider: &ICU4XDataProvider,
332 ) -> Result<Box<ICU4XGeneralCategoryNameToMaskMapper>, ICU4XError> {
333 Ok(Box::new(ICU4XGeneralCategoryNameToMaskMapper(
334 call_constructor_unstable!(
335 GeneralCategoryGroup::name_to_enum_mapper [r => Ok(r.static_to_owned())],
336 GeneralCategoryGroup::get_name_to_enum_mapper,