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 ). 4 5 #[diplomat::bridge] 6 #[diplomat::abi_rename = "icu4x_{0}_mv1"] 7 #[diplomat::attr(auto, namespace = "icu4x")] 8 pub mod ffi { 9 use alloc::boxed::Box; 10 #[cfg(any(feature = "compiled_data", feature = "buffer_provider"))] 11 use icu_properties::props::BasicEmoji; 12 13 #[cfg(feature = "buffer_provider")] 14 use crate::{errors::ffi::DataError, provider::ffi::DataProvider}; 15 16 #[diplomat::opaque] 17 /// An ICU4X Unicode Set Property object, capable of querying whether a code point is contained in a set based on a Unicode property. 18 #[diplomat::rust_link(icu::properties, Mod)] 19 #[diplomat::rust_link(icu::properties::EmojiSetData, Struct)] 20 #[diplomat::rust_link(icu::properties::EmojiSetData::new, FnInStruct)] 21 #[diplomat::rust_link(icu::properties::EmojiSetDataBorrowed::new, FnInStruct, hidden)] 22 #[diplomat::rust_link(icu::properties::EmojiSetDataBorrowed, Struct)] 23 pub struct EmojiSetData(pub icu_properties::EmojiSetData); 24 25 impl EmojiSetData { 26 /// Checks whether the string is in the set. 27 #[diplomat::rust_link(icu::properties::EmojiSetDataBorrowed::contains_str, FnInStruct)] 28 #[diplomat::attr(supports = method_overloading, rename = "contains")] contains_str(&self, s: &DiplomatStr) -> bool29 pub fn contains_str(&self, s: &DiplomatStr) -> bool { 30 let Ok(s) = core::str::from_utf8(s) else { 31 return false; 32 }; 33 self.0.as_borrowed().contains_str(s) 34 } 35 /// Checks whether the code point is in the set. 36 #[diplomat::rust_link(icu::properties::EmojiSetDataBorrowed::contains, FnInStruct)] 37 #[diplomat::rust_link( 38 icu::properties::EmojiSetDataBorrowed::contains32, 39 FnInStruct, 40 hidden 41 )] contains(&self, cp: DiplomatChar) -> bool42 pub fn contains(&self, cp: DiplomatChar) -> bool { 43 self.0.as_borrowed().contains32(cp) 44 } 45 46 /// Create a map for the `Basic_Emoji` property, using compiled data. 47 #[diplomat::rust_link(icu::properties::props::BasicEmoji, Struct)] 48 #[diplomat::attr(auto, named_constructor = "basic")] 49 #[cfg(feature = "compiled_data")] create_basic() -> Box<EmojiSetData>50 pub fn create_basic() -> Box<EmojiSetData> { 51 Box::new(EmojiSetData( 52 icu_properties::EmojiSetData::new::<BasicEmoji>().static_to_owned(), 53 )) 54 } 55 /// Create a map for the `Basic_Emoji` property, using a particular data source. 56 #[diplomat::rust_link(icu::properties::props::BasicEmoji, Struct)] 57 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "basic_with_provider")] 58 #[cfg(feature = "buffer_provider")] create_basic_with_provider( provider: &DataProvider, ) -> Result<Box<EmojiSetData>, DataError>59 pub fn create_basic_with_provider( 60 provider: &DataProvider, 61 ) -> Result<Box<EmojiSetData>, DataError> { 62 Ok(Box::new(EmojiSetData( 63 icu_properties::EmojiSetData::try_new_unstable::<BasicEmoji>( 64 &provider.get_unstable()?, 65 )?, 66 ))) 67 } 68 } 69 } 70