#[diplomat::bridge]
#[diplomat::abi_rename = "icu4x_{0}_mv1"]
#[diplomat::attr(auto, namespace = "icu4x")]
pub mod ffi {
use alloc::boxed::Box;
use crate::errors::ffi::DataError;
use crate::provider::ffi::DataProvider;
#[diplomat::opaque]
#[diplomat::rust_link(icu::segmenter::GraphemeClusterSegmenter, Struct)]
pub struct GraphemeClusterSegmenter(icu_segmenter::GraphemeClusterSegmenter);
#[diplomat::opaque]
#[diplomat::rust_link(icu::segmenter::GraphemeClusterBreakIterator, Struct)]
#[diplomat::rust_link(
icu::segmenter::GraphemeClusterBreakIteratorPotentiallyIllFormedUtf8,
Typedef,
hidden
)]
#[diplomat::rust_link(icu::segmenter::GraphemeClusterBreakIteratorUtf8, Typedef, hidden)]
pub struct GraphemeClusterBreakIteratorUtf8<'a>(
icu_segmenter::GraphemeClusterBreakIteratorPotentiallyIllFormedUtf8<'a, 'a>,
);
#[diplomat::opaque]
#[diplomat::rust_link(icu::segmenter::GraphemeClusterBreakIterator, Struct)]
#[diplomat::rust_link(icu::segmenter::GraphemeClusterBreakIteratorUtf16, Typedef, hidden)]
pub struct GraphemeClusterBreakIteratorUtf16<'a>(
icu_segmenter::GraphemeClusterBreakIteratorUtf16<'a, 'a>,
);
#[diplomat::opaque]
#[diplomat::rust_link(icu::segmenter::GraphemeClusterBreakIterator, Struct)]
#[diplomat::rust_link(icu::segmenter::GraphemeClusterBreakIteratorLatin1, Typedef, hidden)]
pub struct GraphemeClusterBreakIteratorLatin1<'a>(
icu_segmenter::GraphemeClusterBreakIteratorLatin1<'a, 'a>,
);
impl GraphemeClusterSegmenter {
#[diplomat::rust_link(icu::segmenter::GraphemeClusterSegmenter::new, FnInStruct)]
#[diplomat::attr(supports = fallible_constructors, constructor)]
pub fn create(provider: &DataProvider) -> Result<Box<GraphemeClusterSegmenter>, DataError> {
Ok(Box::new(GraphemeClusterSegmenter(call_constructor!(
icu_segmenter::GraphemeClusterSegmenter::new [r => Ok(r)],
icu_segmenter::GraphemeClusterSegmenter::try_new_with_any_provider,
icu_segmenter::GraphemeClusterSegmenter::try_new_with_buffer_provider,
provider,
)?)))
}
#[diplomat::rust_link(
icu::segmenter::GraphemeClusterSegmenter::segment_str,
FnInStruct,
hidden
)]
#[diplomat::rust_link(icu::segmenter::GraphemeClusterSegmenter::segment_utf8, FnInStruct)]
#[diplomat::attr(not(supports = utf8_strings), disable)]
#[diplomat::attr(*, rename = "segment")]
pub fn segment_utf8<'a>(
&'a self,
input: &'a DiplomatStr,
) -> Box<GraphemeClusterBreakIteratorUtf8<'a>> {
Box::new(GraphemeClusterBreakIteratorUtf8(self.0.segment_utf8(input)))
}
#[diplomat::rust_link(icu::segmenter::GraphemeClusterSegmenter::segment_utf16, FnInStruct)]
#[diplomat::attr(not(supports = utf8_strings), rename = "segment")]
#[diplomat::attr(supports = utf8_strings, rename = "segment16")]
pub fn segment_utf16<'a>(
&'a self,
input: &'a DiplomatStr16,
) -> Box<GraphemeClusterBreakIteratorUtf16<'a>> {
Box::new(GraphemeClusterBreakIteratorUtf16(
self.0.segment_utf16(input),
))
}
#[diplomat::rust_link(icu::segmenter::GraphemeClusterSegmenter::segment_latin1, FnInStruct)]
#[diplomat::attr(not(supports = utf8_strings), disable)]
pub fn segment_latin1<'a>(
&'a self,
input: &'a [u8],
) -> Box<GraphemeClusterBreakIteratorLatin1<'a>> {
Box::new(GraphemeClusterBreakIteratorLatin1(
self.0.segment_latin1(input),
))
}
}
impl<'a> GraphemeClusterBreakIteratorUtf8<'a> {
#[diplomat::rust_link(icu::segmenter::GraphemeClusterBreakIterator::next, FnInStruct)]
#[diplomat::rust_link(
icu::segmenter::GraphemeClusterBreakIterator::Item,
AssociatedTypeInStruct,
hidden
)]
pub fn next(&mut self) -> i32 {
self.0
.next()
.and_then(|u| i32::try_from(u).ok())
.unwrap_or(-1)
}
}
impl<'a> GraphemeClusterBreakIteratorUtf16<'a> {
#[diplomat::rust_link(icu::segmenter::GraphemeClusterBreakIterator::next, FnInStruct)]
#[diplomat::rust_link(
icu::segmenter::GraphemeClusterBreakIterator::Item,
AssociatedTypeInStruct,
hidden
)]
pub fn next(&mut self) -> i32 {
self.0
.next()
.and_then(|u| i32::try_from(u).ok())
.unwrap_or(-1)
}
}
impl<'a> GraphemeClusterBreakIteratorLatin1<'a> {
#[diplomat::rust_link(icu::segmenter::GraphemeClusterBreakIterator::next, FnInStruct)]
#[diplomat::rust_link(
icu::segmenter::GraphemeClusterBreakIterator::Item,
AssociatedTypeInStruct,
hidden
)]
pub fn next(&mut self) -> i32 {
self.0
.next()
.and_then(|u| i32::try_from(u).ok())
.unwrap_or(-1)
}
}
}