summaryrefslogtreecommitdiffstats
path: root/intl/icu_capi/src/properties_unisets.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /intl/icu_capi/src/properties_unisets.rs
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'intl/icu_capi/src/properties_unisets.rs')
-rw-r--r--intl/icu_capi/src/properties_unisets.rs149
1 files changed, 149 insertions, 0 deletions
diff --git a/intl/icu_capi/src/properties_unisets.rs b/intl/icu_capi/src/properties_unisets.rs
new file mode 100644
index 0000000000..7d2cf8cccc
--- /dev/null
+++ b/intl/icu_capi/src/properties_unisets.rs
@@ -0,0 +1,149 @@
+// This file is part of ICU4X. For terms of use, please see the file
+// called LICENSE at the top level of the ICU4X source tree
+// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
+
+#[diplomat::bridge]
+pub mod ffi {
+ use crate::locale::ffi::ICU4XLocale;
+ use crate::provider::ffi::ICU4XDataProvider;
+ use alloc::boxed::Box;
+ use core::str;
+ use icu_properties::{exemplar_chars, sets};
+
+ use crate::errors::ffi::ICU4XError;
+
+ #[diplomat::opaque]
+ /// An ICU4X Unicode Set Property object, capable of querying whether a code point is contained in a set based on a Unicode property.
+ #[diplomat::rust_link(icu::properties, Mod)]
+ #[diplomat::rust_link(icu::properties::sets::UnicodeSetData, Struct)]
+ #[diplomat::rust_link(icu::properties::sets::UnicodeSetData::from_data, FnInStruct, hidden)]
+ #[diplomat::rust_link(icu::properties::sets::UnicodeSetDataBorrowed, Struct)]
+ pub struct ICU4XUnicodeSetData(pub sets::UnicodeSetData);
+
+ impl ICU4XUnicodeSetData {
+ /// Checks whether the string is in the set.
+ #[diplomat::rust_link(icu::properties::sets::UnicodeSetDataBorrowed::contains, FnInStruct)]
+ pub fn contains(&self, s: &str) -> bool {
+ let s = s.as_bytes(); // #2520
+ let s = if let Ok(s) = str::from_utf8(s) {
+ s
+ } else {
+ return false;
+ };
+ self.0.as_borrowed().contains(s)
+ }
+ /// Checks whether the code point is in the set.
+ #[diplomat::rust_link(
+ icu::properties::sets::UnicodeSetDataBorrowed::contains_char,
+ FnInStruct
+ )]
+ pub fn contains_char(&self, cp: char) -> bool {
+ self.0.as_borrowed().contains_char(cp)
+ }
+ /// Checks whether the code point (specified as a 32 bit integer, in UTF-32) is in the set.
+ #[diplomat::rust_link(
+ icu::properties::sets::UnicodeSetDataBorrowed::contains32,
+ FnInStruct,
+ hidden
+ )]
+ #[diplomat::attr(dart, disable)]
+ pub fn contains32(&self, cp: u32) -> bool {
+ self.0.as_borrowed().contains32(cp)
+ }
+
+ #[diplomat::rust_link(icu::properties::sets::basic_emoji, Fn)]
+ #[diplomat::rust_link(icu::properties::sets::load_basic_emoji, Fn, hidden)]
+ pub fn load_basic_emoji(
+ provider: &ICU4XDataProvider,
+ ) -> Result<Box<ICU4XUnicodeSetData>, ICU4XError> {
+ Ok(Box::new(ICU4XUnicodeSetData(call_constructor_unstable!(
+ sets::basic_emoji [r => Ok(r.static_to_owned())],
+ sets::load_basic_emoji,
+ provider,
+ )?)))
+ }
+
+ #[diplomat::rust_link(icu::properties::exemplar_chars::exemplars_main, Fn)]
+ #[diplomat::rust_link(icu::properties::exemplar_chars::load_exemplars_main, Fn, hidden)]
+ pub fn load_exemplars_main(
+ provider: &ICU4XDataProvider,
+ locale: &ICU4XLocale,
+ ) -> Result<Box<ICU4XUnicodeSetData>, ICU4XError> {
+ let locale = locale.to_datalocale();
+ Ok(Box::new(ICU4XUnicodeSetData(call_constructor_unstable!(
+ exemplar_chars::exemplars_main,
+ exemplar_chars::load_exemplars_main,
+ provider,
+ &locale
+ )?)))
+ }
+
+ #[diplomat::rust_link(icu::properties::exemplar_chars::exemplars_auxiliary, Fn)]
+ #[diplomat::rust_link(
+ icu::properties::exemplar_chars::load_exemplars_auxiliary,
+ Fn,
+ hidden
+ )]
+ pub fn load_exemplars_auxiliary(
+ provider: &ICU4XDataProvider,
+ locale: &ICU4XLocale,
+ ) -> Result<Box<ICU4XUnicodeSetData>, ICU4XError> {
+ let locale = locale.to_datalocale();
+ Ok(Box::new(ICU4XUnicodeSetData(call_constructor_unstable!(
+ exemplar_chars::exemplars_auxiliary,
+ exemplar_chars::load_exemplars_auxiliary,
+ provider,
+ &locale
+ )?)))
+ }
+
+ #[diplomat::rust_link(icu::properties::exemplar_chars::exemplars_punctuation, Fn)]
+ #[diplomat::rust_link(
+ icu::properties::exemplar_chars::load_exemplars_punctuation,
+ Fn,
+ hidden
+ )]
+ pub fn load_exemplars_punctuation(
+ provider: &ICU4XDataProvider,
+ locale: &ICU4XLocale,
+ ) -> Result<Box<ICU4XUnicodeSetData>, ICU4XError> {
+ let locale = locale.to_datalocale();
+ Ok(Box::new(ICU4XUnicodeSetData(call_constructor_unstable!(
+ exemplar_chars::exemplars_punctuation,
+ exemplar_chars::load_exemplars_punctuation,
+ provider,
+ &locale
+ )?)))
+ }
+
+ #[diplomat::rust_link(icu::properties::exemplar_chars::exemplars_numbers, Fn)]
+ #[diplomat::rust_link(icu::properties::exemplar_chars::load_exemplars_numbers, Fn, hidden)]
+ pub fn load_exemplars_numbers(
+ provider: &ICU4XDataProvider,
+ locale: &ICU4XLocale,
+ ) -> Result<Box<ICU4XUnicodeSetData>, ICU4XError> {
+ let locale = locale.to_datalocale();
+ Ok(Box::new(ICU4XUnicodeSetData(call_constructor_unstable!(
+ exemplar_chars::exemplars_numbers,
+ exemplar_chars::load_exemplars_numbers,
+ provider,
+ &locale
+ )?)))
+ }
+
+ #[diplomat::rust_link(icu::properties::exemplar_chars::exemplars_index, Fn)]
+ #[diplomat::rust_link(icu::properties::exemplar_chars::load_exemplars_index, Fn, hidden)]
+ pub fn load_exemplars_index(
+ provider: &ICU4XDataProvider,
+ locale: &ICU4XLocale,
+ ) -> Result<Box<ICU4XUnicodeSetData>, ICU4XError> {
+ let locale = locale.to_datalocale();
+ Ok(Box::new(ICU4XUnicodeSetData(call_constructor_unstable!(
+ exemplar_chars::exemplars_index,
+ exemplar_chars::load_exemplars_index,
+ provider,
+ &locale
+ )?)))
+ }
+ }
+}