| 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 |
pub mod ffi { |
| 7 |
use crate::locale::ffi::ICU4XLocale; |
| 8 |
use crate::provider::ffi::ICU4XDataProvider; |
| 9 |
use alloc::boxed::Box; |
| 10 |
use core::str; |
| 11 |
use icu_properties::{exemplar_chars, sets}; |
| 12 |
|
| 13 |
use crate::errors::ffi::ICU4XError; |
| 14 |
|
| 15 |
#[diplomat::opaque] |
| 16 |
/// An ICU4X Unicode Set Property object, capable of querying whether a code point is contained in a set based on a Unicode property. |
| 17 |
#[diplomat::rust_link(icu::properties, Mod)] |
| 18 |
#[diplomat::rust_link(icu::properties::sets::UnicodeSetData, Struct)] |
| 19 |
#[diplomat::rust_link(icu::properties::sets::UnicodeSetData::from_data, FnInStruct, hidden)] |
| 20 |
#[diplomat::rust_link(icu::properties::sets::UnicodeSetDataBorrowed, Struct)] |
| 21 |
pub struct ICU4XUnicodeSetData(pub sets::UnicodeSetData); |
| 22 |
|
| 23 |
impl ICU4XUnicodeSetData { |
| 24 |
/// Checks whether the string is in the set. |
| 25 |
#[diplomat::rust_link(icu::properties::sets::UnicodeSetDataBorrowed::contains, FnInStruct)] |
| 26 |
pub fn contains(&self, s: &DiplomatStr) -> bool { |
| 27 |
let s = if let Ok(s) = str::from_utf8(s) { |
| 28 |
s |
| 29 |
} else { |
| 30 |
return false; |
| 31 |
}; |
| 32 |
self.0.as_borrowed().contains(s) |
| 33 |
} |
| 34 |
/// Checks whether the code point is in the set. |
| 35 |
#[diplomat::rust_link( |
| 36 |
icu::properties::sets::UnicodeSetDataBorrowed::contains_char, |
| 37 |
FnInStruct |
| 38 |
)] |
| 39 |
pub fn contains_char(&self, cp: DiplomatChar) -> bool { |
| 40 |
self.0.as_borrowed().contains32(cp) |
| 41 |
} |
| 42 |
/// Checks whether the code point (specified as a 32 bit integer, in UTF-32) is in the set. |
| 43 |
#[diplomat::rust_link( |
| 44 |
icu::properties::sets::UnicodeSetDataBorrowed::contains32, |
| 45 |
FnInStruct, |
| 46 |
hidden |
| 47 |
)] |
| 48 |
#[diplomat::attr(dart, disable)] |
| 49 |
pub fn contains32(&self, cp: u32) -> bool { |
| 50 |
self.contains_char(cp) |
| 51 |
} |
| 52 |
|
| 53 |
#[diplomat::rust_link(icu::properties::sets::basic_emoji, Fn)] |
| 54 |
#[diplomat::rust_link(icu::properties::sets::load_basic_emoji, Fn, hidden)] |
| 55 |
#[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "basic_emoji")] |
| 56 |
pub fn load_basic_emoji( |
| 57 |
provider: &ICU4XDataProvider, |
| 58 |
) -> Result<Box<ICU4XUnicodeSetData>, ICU4XError> { |
| 59 |
Ok(Box::new(ICU4XUnicodeSetData(call_constructor_unstable!( |
| 60 |
sets::basic_emoji [r => Ok(r.static_to_owned())], |
| 61 |
sets::load_basic_emoji, |
| 62 |
provider, |
| 63 |
)?))) |
| 64 |
} |
| 65 |
|
| 66 |
#[diplomat::rust_link(icu::properties::exemplar_chars::exemplars_main, Fn)] |
| 67 |
#[diplomat::rust_link(icu::properties::exemplar_chars::load_exemplars_main, Fn, hidden)] |
| 68 |
#[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "exemplars_main")] |
| 69 |
pub fn load_exemplars_main( |
| 70 |
provider: &ICU4XDataProvider, |
| 71 |
locale: &ICU4XLocale, |
| 72 |
) -> Result<Box<ICU4XUnicodeSetData>, ICU4XError> { |
| 73 |
let locale = locale.to_datalocale(); |
| 74 |
Ok(Box::new(ICU4XUnicodeSetData(call_constructor_unstable!( |
| 75 |
exemplar_chars::exemplars_main, |
| 76 |
exemplar_chars::load_exemplars_main, |
| 77 |
provider, |
| 78 |
&locale |
| 79 |
)?))) |
| 80 |
} |
| 81 |
|
| 82 |
#[diplomat::rust_link(icu::properties::exemplar_chars::exemplars_auxiliary, Fn)] |
| 83 |
#[diplomat::rust_link( |
| 84 |
icu::properties::exemplar_chars::load_exemplars_auxiliary, |
| 85 |
Fn, |
| 86 |
hidden |
| 87 |
)] |
| 88 |
#[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "exemplars_auxiliary")] |
| 89 |
pub fn load_exemplars_auxiliary( |
| 90 |
provider: &ICU4XDataProvider, |
| 91 |
locale: &ICU4XLocale, |
| 92 |
) -> Result<Box<ICU4XUnicodeSetData>, ICU4XError> { |
| 93 |
let locale = locale.to_datalocale(); |
| 94 |
Ok(Box::new(ICU4XUnicodeSetData(call_constructor_unstable!( |
| 95 |
exemplar_chars::exemplars_auxiliary, |
| 96 |
exemplar_chars::load_exemplars_auxiliary, |
| 97 |
provider, |
| 98 |
&locale |
| 99 |
)?))) |
| 100 |
} |
| 101 |
|
| 102 |
#[diplomat::rust_link(icu::properties::exemplar_chars::exemplars_punctuation, Fn)] |
| 103 |
#[diplomat::rust_link( |
| 104 |
icu::properties::exemplar_chars::load_exemplars_punctuation, |
| 105 |
Fn, |
| 106 |
hidden |
| 107 |
)] |
| 108 |
#[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "exemplars_punctuation")] |
| 109 |
pub fn load_exemplars_punctuation( |
| 110 |
provider: &ICU4XDataProvider, |
| 111 |
locale: &ICU4XLocale, |
| 112 |
) -> Result<Box<ICU4XUnicodeSetData>, ICU4XError> { |
| 113 |
let locale = locale.to_datalocale(); |
| 114 |
Ok(Box::new(ICU4XUnicodeSetData(call_constructor_unstable!( |
| 115 |
exemplar_chars::exemplars_punctuation, |
| 116 |
exemplar_chars::load_exemplars_punctuation, |
| 117 |
provider, |
| 118 |
&locale |
| 119 |
)?))) |
| 120 |
} |
| 121 |
|
| 122 |
#[diplomat::rust_link(icu::properties::exemplar_chars::exemplars_numbers, Fn)] |
| 123 |
#[diplomat::rust_link(icu::properties::exemplar_chars::load_exemplars_numbers, Fn, hidden)] |
| 124 |
#[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "exemplars_numbers")] |
| 125 |
pub fn load_exemplars_numbers( |
| 126 |
provider: &ICU4XDataProvider, |
| 127 |
locale: &ICU4XLocale, |
| 128 |
) -> Result<Box<ICU4XUnicodeSetData>, ICU4XError> { |
| 129 |
let locale = locale.to_datalocale(); |
| 130 |
Ok(Box::new(ICU4XUnicodeSetData(call_constructor_unstable!( |
| 131 |
exemplar_chars::exemplars_numbers, |
| 132 |
exemplar_chars::load_exemplars_numbers, |
| 133 |
provider, |
| 134 |
&locale |
| 135 |
)?))) |
| 136 |
} |
| 137 |
|
| 138 |
#[diplomat::rust_link(icu::properties::exemplar_chars::exemplars_index, Fn)] |
| 139 |
#[diplomat::rust_link(icu::properties::exemplar_chars::load_exemplars_index, Fn, hidden)] |
| 140 |
#[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "exemplars_index")] |
| 141 |
pub fn load_exemplars_index( |
| 142 |
provider: &ICU4XDataProvider, |
| 143 |
locale: &ICU4XLocale, |
| 144 |
) -> Result<Box<ICU4XUnicodeSetData>, ICU4XError> { |
| 145 |
let locale = locale.to_datalocale(); |
| 146 |
Ok(Box::new(ICU4XUnicodeSetData(call_constructor_unstable!( |
| 147 |
exemplar_chars::exemplars_index, |
| 148 |
exemplar_chars::load_exemplars_index, |
| 149 |
provider, |
| 150 |
&locale |
| 151 |
)?))) |
| 152 |
} |
| 153 |
} |
| 154 |
} |