Struct icu_properties::CodePointMapDataBorrowed
source · pub struct CodePointMapDataBorrowed<'a, T: TrieValue> { /* private fields */ }
Expand description
A borrowed wrapper around code point set data, returned by
CodePointSetData::as_borrowed()
. More efficient to query.
Implementations§
source§impl<'a, T: TrieValue> CodePointMapDataBorrowed<'a, T>
impl<'a, T: TrieValue> CodePointMapDataBorrowed<'a, T>
sourcepub fn get(self, ch: char) -> T
pub fn get(self, ch: char) -> T
Get the value this map has associated with code point ch
§Example
use icu::properties::CodePointMapData;
use icu::properties::props::GeneralCategory;
let gc = CodePointMapData::<GeneralCategory>::new();
assert_eq!(gc.get('木'), GeneralCategory::OtherLetter); // U+6728
assert_eq!(gc.get('🎃'), GeneralCategory::OtherSymbol); // U+1F383 JACK-O-LANTERN
sourcepub fn get_set_for_value(self, value: T) -> CodePointSetData
pub fn get_set_for_value(self, value: T) -> CodePointSetData
Get a CodePointSetData
for all elements corresponding to a particular value
§Example
use icu::properties::CodePointMapData;
use icu::properties::props::GeneralCategory;
let gc = CodePointMapData::<GeneralCategory>::new();
let other_letter_set_data =
gc.get_set_for_value(GeneralCategory::OtherLetter);
let other_letter_set = other_letter_set_data.as_borrowed();
assert!(other_letter_set.contains('木')); // U+6728
assert!(!other_letter_set.contains('🎃')); // U+1F383 JACK-O-LANTERN
sourcepub fn iter_ranges(self) -> impl Iterator<Item = CodePointMapRange<T>> + 'a
pub fn iter_ranges(self) -> impl Iterator<Item = CodePointMapRange<T>> + 'a
Yields an Iterator
returning ranges of consecutive code points that
share the same value in the CodePointMapData
.
§Examples
use icu::properties::CodePointMapData;
use icu::properties::props::GeneralCategory;
let gc = CodePointMapData::<GeneralCategory>::new();
let mut ranges = gc.iter_ranges();
let next = ranges.next().unwrap();
assert_eq!(next.range, 0..=31);
assert_eq!(next.value, GeneralCategory::Control);
let next = ranges.next().unwrap();
assert_eq!(next.range, 32..=32);
assert_eq!(next.value, GeneralCategory::SpaceSeparator);
sourcepub fn iter_ranges_for_value(
self,
val: T,
) -> impl Iterator<Item = RangeInclusive<u32>> + 'a
pub fn iter_ranges_for_value( self, val: T, ) -> impl Iterator<Item = RangeInclusive<u32>> + 'a
Yields an Iterator
returning ranges of consecutive code points that
share the same value v
in the CodePointMapData
.
§Examples
use icu::properties::CodePointMapData;
use icu::properties::props::GeneralCategory;
let gc = CodePointMapData::<GeneralCategory>::new();
let mut ranges = gc.iter_ranges_for_value(GeneralCategory::UppercaseLetter);
assert_eq!(ranges.next().unwrap(), 'A' as u32..='Z' as u32);
assert_eq!(ranges.next().unwrap(), 'À' as u32..='Ö' as u32);
assert_eq!(ranges.next().unwrap(), 'Ø' as u32..='Þ' as u32);
sourcepub fn iter_ranges_for_value_complemented(
self,
val: T,
) -> impl Iterator<Item = RangeInclusive<u32>> + 'a
pub fn iter_ranges_for_value_complemented( self, val: T, ) -> impl Iterator<Item = RangeInclusive<u32>> + 'a
Yields an Iterator
returning ranges of consecutive code points that
do not have the value v
in the CodePointMapData
.
source§impl CodePointMapDataBorrowed<'_, GeneralCategory>
impl CodePointMapDataBorrowed<'_, GeneralCategory>
sourcepub fn get_set_for_value_group(
&self,
value: GeneralCategoryGroup,
) -> CodePointSetData
pub fn get_set_for_value_group( &self, value: GeneralCategoryGroup, ) -> CodePointSetData
TODO
source§impl<T: TrieValue> CodePointMapDataBorrowed<'static, T>
impl<T: TrieValue> CodePointMapDataBorrowed<'static, T>
sourcepub const fn new() -> Selfwhere
T: EnumeratedProperty,
pub const fn new() -> Selfwhere
T: EnumeratedProperty,
Creates a new CodePointMapDataBorrowed
for a EnumeratedProperty
.
See the documentation on EnumeratedProperty
implementations for details.
✨ Enabled with the compiled_data
Cargo feature.
sourcepub const fn static_to_owned(self) -> CodePointMapData<T>
pub const fn static_to_owned(self) -> CodePointMapData<T>
Cheaply converts a [CodePointMapDataBorrowed<'static>
] into a CodePointMapData
.
Note: Due to branching and indirection, using CodePointMapData
might inhibit some
compile-time optimizations that are possible with CodePointMapDataBorrowed
.
source§impl<'a> CodePointMapDataBorrowed<'a, GeneralCategory>
impl<'a> CodePointMapDataBorrowed<'a, GeneralCategory>
sourcepub fn iter_ranges_for_group(
self,
group: GeneralCategoryGroup,
) -> impl Iterator<Item = RangeInclusive<u32>> + 'a
pub fn iter_ranges_for_group( self, group: GeneralCategoryGroup, ) -> impl Iterator<Item = RangeInclusive<u32>> + 'a
Yields an Iterator
returning ranges of consecutive code points that
have a General_Category
value belonging to the specified GeneralCategoryGroup
§Examples
use icu::properties::CodePointMapData;
use icu::properties::props::{GeneralCategory, GeneralCategoryGroup};
let gc = CodePointMapData::<GeneralCategory>::new();
let mut ranges = gc.iter_ranges_for_group(GeneralCategoryGroup::Letter);
assert_eq!(ranges.next().unwrap(), 'A' as u32..='Z' as u32);
assert_eq!(ranges.next().unwrap(), 'a' as u32..='z' as u32);
assert_eq!(ranges.next().unwrap(), 'ª' as u32..='ª' as u32);
assert_eq!(ranges.next().unwrap(), 'µ' as u32..='µ' as u32);
assert_eq!(ranges.next().unwrap(), 'º' as u32..='º' as u32);
assert_eq!(ranges.next().unwrap(), 'À' as u32..='Ö' as u32);
assert_eq!(ranges.next().unwrap(), 'Ø' as u32..='ö' as u32);
Trait Implementations§
source§impl BidiDataSource for CodePointMapDataBorrowed<'_, BidiClass>
impl BidiDataSource for CodePointMapDataBorrowed<'_, BidiClass>
Implements [unicode_bidi::BidiDataSource
] on CodePointMapDataBorrowed<BidiClass>
.
✨ Enabled with the unicode_bidi
Cargo feature.
§Examples
use icu::properties::CodePointMapData;
use icu::properties::props::BidiClass;
use unicode_bidi::BidiInfo;
// This example text is defined using `concat!` because some browsers
// and text editors have trouble displaying bidi strings.
let text = concat!["א", // RTL#1
"ב", // RTL#2
"ג", // RTL#3
"a", // LTR#1
"b", // LTR#2
"c", // LTR#3
]; //
let bidi_map = CodePointMapData::<BidiClass>::new();
// Resolve embedding levels within the text. Pass `None` to detect the
// paragraph level automatically.
let bidi_info = BidiInfo::new_with_data_source(&bidi_map, text, None);
// This paragraph has embedding level 1 because its first strong character is RTL.
assert_eq!(bidi_info.paragraphs.len(), 1);
let para = &bidi_info.paragraphs[0];
assert_eq!(para.level.number(), 1);
assert!(para.level.is_rtl());
// Re-ordering is done after wrapping each paragraph into a sequence of
// lines. For this example, I'll just use a single line that spans the
// entire paragraph.
let line = para.range.clone();
let display = bidi_info.reorder_line(para, line);
assert_eq!(display, concat!["a", // LTR#1
"b", // LTR#2
"c", // LTR#3
"ג", // RTL#3
"ב", // RTL#2
"א", // RTL#1
]);
fn bidi_class(&self, c: char) -> BidiClass
§fn bidi_matched_opening_bracket(
&self,
c: char,
) -> Option<BidiMatchedOpeningBracket>
fn bidi_matched_opening_bracket( &self, c: char, ) -> Option<BidiMatchedOpeningBracket>
source§impl<'a, T: Clone + TrieValue> Clone for CodePointMapDataBorrowed<'a, T>
impl<'a, T: Clone + TrieValue> Clone for CodePointMapDataBorrowed<'a, T>
source§fn clone(&self) -> CodePointMapDataBorrowed<'a, T>
fn clone(&self) -> CodePointMapDataBorrowed<'a, T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<'a, T: Debug + TrieValue> Debug for CodePointMapDataBorrowed<'a, T>
impl<'a, T: Debug + TrieValue> Debug for CodePointMapDataBorrowed<'a, T>
source§impl<T: EnumeratedProperty> Default for CodePointMapDataBorrowed<'static, T>
impl<T: EnumeratedProperty> Default for CodePointMapDataBorrowed<'static, T>
impl<'a, T: Copy + TrieValue> Copy for CodePointMapDataBorrowed<'a, T>
Auto Trait Implementations§
impl<'a, T> Freeze for CodePointMapDataBorrowed<'a, T>
impl<'a, T> RefUnwindSafe for CodePointMapDataBorrowed<'a, T>where
T: RefUnwindSafe,
<T as AsULE>::ULE: RefUnwindSafe,
impl<'a, T> Send for CodePointMapDataBorrowed<'a, T>
impl<'a, T> Sync for CodePointMapDataBorrowed<'a, T>
impl<'a, T> Unpin for CodePointMapDataBorrowed<'a, T>
impl<'a, T> UnwindSafe for CodePointMapDataBorrowed<'a, T>where
T: RefUnwindSafe,
<T as AsULE>::ULE: RefUnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more