#[diplomat::bridge]
pub mod ffi {
use crate::provider::ffi::ICU4XDataProvider;
use alloc::boxed::Box;
use icu_properties::{script, sets::CodePointSetData, Script};
use crate::errors::ffi::ICU4XError;
use crate::properties_iter::ffi::CodePointRangeIterator;
use crate::properties_sets::ffi::ICU4XCodePointSetData;
#[diplomat::opaque]
#[diplomat::rust_link(icu::properties::script::ScriptWithExtensions, Struct)]
#[diplomat::rust_link(
icu::properties::script::ScriptWithExtensions::from_data,
FnInStruct,
hidden
)]
pub struct ICU4XScriptWithExtensions(pub script::ScriptWithExtensions);
#[diplomat::opaque]
#[diplomat::rust_link(icu::properties::script::ScriptWithExtensionsBorrowed, Struct)]
pub struct ICU4XScriptWithExtensionsBorrowed<'a>(pub script::ScriptWithExtensionsBorrowed<'a>);
#[diplomat::opaque]
#[diplomat::rust_link(icu::properties::script::ScriptExtensionsSet, Struct)]
pub struct ICU4XScriptExtensionsSet<'a>(pub script::ScriptExtensionsSet<'a>);
impl ICU4XScriptWithExtensions {
#[diplomat::rust_link(icu::properties::script::script_with_extensions, Fn)]
#[diplomat::attr(all(supports = constructors, supports = fallible_constructors), constructor)]
pub fn create(
provider: &ICU4XDataProvider,
) -> Result<Box<ICU4XScriptWithExtensions>, ICU4XError> {
Ok(Box::new(ICU4XScriptWithExtensions(call_constructor!(
script::script_with_extensions [r => Ok(r.static_to_owned())],
script::load_script_with_extensions_with_any_provider,
script::load_script_with_extensions_with_buffer_provider,
provider
)?)))
}
#[diplomat::rust_link(
icu::properties::script::ScriptWithExtensionsBorrowed::get_script_val,
FnInStruct
)]
pub fn get_script_val(&self, code_point: u32) -> u16 {
self.0.as_borrowed().get_script_val(code_point).0
}
#[diplomat::rust_link(
icu::properties::script::ScriptWithExtensionsBorrowed::has_script,
FnInStruct
)]
pub fn has_script(&self, code_point: u32, script: u16) -> bool {
self.0.as_borrowed().has_script(code_point, Script(script))
}
#[diplomat::rust_link(
icu::properties::script::ScriptWithExtensions::as_borrowed,
FnInStruct
)]
#[diplomat::attr(supports = accessors, getter)]
pub fn as_borrowed<'a>(&'a self) -> Box<ICU4XScriptWithExtensionsBorrowed<'a>> {
Box::new(ICU4XScriptWithExtensionsBorrowed(self.0.as_borrowed()))
}
#[diplomat::rust_link(
icu::properties::script::ScriptWithExtensionsBorrowed::get_script_extensions_ranges,
FnInStruct
)]
pub fn iter_ranges_for_script<'a>(
&'a self,
script: u16,
) -> Box<CodePointRangeIterator<'a>> {
Box::new(CodePointRangeIterator(Box::new(
self.0
.as_borrowed()
.get_script_extensions_ranges(Script(script)),
)))
}
}
impl<'a> ICU4XScriptWithExtensionsBorrowed<'a> {
#[diplomat::rust_link(
icu::properties::script::ScriptWithExtensionsBorrowed::get_script_val,
FnInStruct
)]
pub fn get_script_val(&self, code_point: u32) -> u16 {
self.0.get_script_val(code_point).0
}
#[diplomat::rust_link(
icu::properties::script::ScriptWithExtensionsBorrowed::get_script_extensions_val,
FnInStruct
)]
pub fn get_script_extensions_val(
&self,
code_point: u32,
) -> Box<ICU4XScriptExtensionsSet<'a>> {
Box::new(ICU4XScriptExtensionsSet(
self.0.get_script_extensions_val(code_point),
))
}
#[diplomat::rust_link(
icu::properties::script::ScriptWithExtensionsBorrowed::has_script,
FnInStruct
)]
pub fn has_script(&self, code_point: u32, script: u16) -> bool {
self.0.has_script(code_point, Script(script))
}
#[diplomat::rust_link(
icu::properties::script::ScriptWithExtensionsBorrowed::get_script_extensions_set,
FnInStruct
)]
pub fn get_script_extensions_set(&self, script: u16) -> Box<ICU4XCodePointSetData> {
let list = self
.0
.get_script_extensions_set(Script(script))
.into_owned();
let set = CodePointSetData::from_code_point_inversion_list(list);
Box::new(ICU4XCodePointSetData(set))
}
}
impl<'a> ICU4XScriptExtensionsSet<'a> {
#[diplomat::rust_link(icu::properties::script::ScriptExtensionsSet::contains, FnInStruct)]
pub fn contains(&self, script: u16) -> bool {
self.0.contains(&Script(script))
}
#[diplomat::rust_link(icu::properties::script::ScriptExtensionsSet::iter, FnInStruct)]
#[diplomat::attr(supports = accessors, getter)]
pub fn count(&self) -> usize {
self.0.array_len()
}
#[diplomat::rust_link(icu::properties::script::ScriptExtensionsSet::iter, FnInStruct)]
pub fn script_at(&self, index: usize) -> Option<u16> {
self.0.array_get(index).map(|x| x.0)
}
}
}