#[diplomat::bridge]
pub mod ffi {
use crate::errors::ffi::ICU4XError;
use crate::provider::ffi::ICU4XDataProvider;
use alloc::boxed::Box;
use core::convert::TryFrom;
use icu_segmenter::{
SentenceBreakIteratorLatin1, SentenceBreakIteratorPotentiallyIllFormedUtf8,
SentenceBreakIteratorUtf16, SentenceSegmenter,
};
#[diplomat::opaque]
#[diplomat::rust_link(icu::segmenter::SentenceSegmenter, Struct)]
pub struct ICU4XSentenceSegmenter(SentenceSegmenter);
#[diplomat::opaque]
#[diplomat::rust_link(icu::segmenter::SentenceBreakIterator, Struct)]
#[diplomat::rust_link(
icu::segmenter::SentenceBreakIteratorPotentiallyIllFormedUtf8,
Typedef,
hidden
)]
#[diplomat::rust_link(icu::segmenter::SentenceBreakIteratorUtf8, Typedef, hidden)]
pub struct ICU4XSentenceBreakIteratorUtf8<'a>(
SentenceBreakIteratorPotentiallyIllFormedUtf8<'a, 'a>,
);
#[diplomat::opaque]
#[diplomat::rust_link(icu::segmenter::SentenceBreakIterator, Struct)]
#[diplomat::rust_link(icu::segmenter::SentenceBreakIteratorUtf16, Typedef, hidden)]
pub struct ICU4XSentenceBreakIteratorUtf16<'a>(SentenceBreakIteratorUtf16<'a, 'a>);
#[diplomat::opaque]
#[diplomat::rust_link(icu::segmenter::SentenceBreakIterator, Struct)]
#[diplomat::rust_link(icu::segmenter::SentenceBreakIteratorLatin1, Typedef, hidden)]
pub struct ICU4XSentenceBreakIteratorLatin1<'a>(SentenceBreakIteratorLatin1<'a, 'a>);
impl ICU4XSentenceSegmenter {
#[diplomat::rust_link(icu::segmenter::SentenceSegmenter::new, FnInStruct)]
#[diplomat::attr(all(supports = constructors, supports = fallible_constructors), constructor)]
pub fn create(
provider: &ICU4XDataProvider,
) -> Result<Box<ICU4XSentenceSegmenter>, ICU4XError> {
Ok(Box::new(ICU4XSentenceSegmenter(call_constructor!(
SentenceSegmenter::new [r => Ok(r)],
SentenceSegmenter::try_new_with_any_provider,
SentenceSegmenter::try_new_with_buffer_provider,
provider,
)?)))
}
#[diplomat::rust_link(icu::segmenter::SentenceSegmenter::segment_utf8, FnInStruct)]
#[diplomat::rust_link(icu::segmenter::SentenceSegmenter::segment_str, FnInStruct, hidden)]
#[diplomat::attr(dart, disable)]
pub fn segment_utf8<'a>(
&'a self,
input: &'a DiplomatStr,
) -> Box<ICU4XSentenceBreakIteratorUtf8<'a>> {
Box::new(ICU4XSentenceBreakIteratorUtf8(self.0.segment_utf8(input)))
}
#[diplomat::rust_link(icu::segmenter::SentenceSegmenter::segment_utf16, FnInStruct)]
#[diplomat::attr(dart, rename = "segment")]
pub fn segment_utf16<'a>(
&'a self,
input: &'a DiplomatStr16,
) -> Box<ICU4XSentenceBreakIteratorUtf16<'a>> {
Box::new(ICU4XSentenceBreakIteratorUtf16(self.0.segment_utf16(input)))
}
#[diplomat::rust_link(icu::segmenter::SentenceSegmenter::segment_latin1, FnInStruct)]
#[diplomat::attr(dart, disable)]
pub fn segment_latin1<'a>(
&'a self,
input: &'a [u8],
) -> Box<ICU4XSentenceBreakIteratorLatin1<'a>> {
Box::new(ICU4XSentenceBreakIteratorLatin1(
self.0.segment_latin1(input),
))
}
}
impl<'a> ICU4XSentenceBreakIteratorUtf8<'a> {
#[diplomat::rust_link(icu::segmenter::SentenceBreakIterator::next, FnInStruct)]
#[diplomat::rust_link(
icu::segmenter::SentenceBreakIterator::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> ICU4XSentenceBreakIteratorUtf16<'a> {
#[diplomat::rust_link(icu::segmenter::SentenceBreakIterator::next, FnInStruct)]
#[diplomat::rust_link(
icu::segmenter::SentenceBreakIterator::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> ICU4XSentenceBreakIteratorLatin1<'a> {
#[diplomat::rust_link(icu::segmenter::SentenceBreakIterator::next, FnInStruct)]
#[diplomat::rust_link(
icu::segmenter::SentenceBreakIterator::Item,
AssociatedTypeInStruct,
hidden
)]
pub fn next(&mut self) -> i32 {
self.0
.next()
.and_then(|u| i32::try_from(u).ok())
.unwrap_or(-1)
}
}
}