Struct icu::properties::maps::CodePointMapDataBorrowed
source · pub struct CodePointMapDataBorrowed<'a, T>where
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> CodePointMapDataBorrowed<'a, T>where
T: TrieValue,
impl<'a, T> CodePointMapDataBorrowed<'a, T>where T: TrieValue,
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::{maps, GeneralCategory};
use icu_collections::codepointtrie::CodePointTrie;
let data =
maps::load_general_category(&icu_testdata::unstable())
.expect("The data should be valid");
let gc = data.as_borrowed();
assert_eq!(gc.get('木'), GeneralCategory::OtherLetter); // U+6728
assert_eq!(gc.get('🎃'), GeneralCategory::OtherSymbol); // U+1F383 JACK-O-LANTERN
sourcepub fn get32(self, ch: u32) -> T
pub fn get32(self, ch: u32) -> T
Get the value this map has associated with code point ch
Example
use icu::properties::{maps, GeneralCategory};
use icu_collections::codepointtrie::CodePointTrie;
let data =
maps::load_general_category(&icu_testdata::unstable())
.expect("The data should be valid");
let gc = data.as_borrowed();
assert_eq!(gc.get32(0x6728), GeneralCategory::OtherLetter); // U+6728 (木)
assert_eq!(gc.get32(0x1F383), 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::{maps, GeneralCategory};
use icu_collections::codepointtrie::CodePointTrie;
let data = maps::load_general_category(&icu_testdata::unstable())
.expect("The data should be valid");
let gc = data.as_borrowed();
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 core::ops::RangeInclusive;
use icu::properties::maps::{self, CodePointMapData};
use icu::properties::GeneralCategory;
let data = maps::load_general_category(&icu_testdata::unstable())
.expect("The data should be valid");
let gc = data.as_borrowed();
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 core::ops::RangeInclusive;
use icu::properties::maps::{self, CodePointMapData};
use icu::properties::GeneralCategory;
let data = maps::load_general_category(&icu_testdata::unstable())
.expect("The data should be valid");
let gc = data.as_borrowed();
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<'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 core::ops::RangeInclusive;
use icu::properties::maps::{self, CodePointMapData};
use icu::properties::GeneralCategoryGroup;
let data = maps::load_general_category(&icu_testdata::unstable())
.expect("The data should be valid");
let gc = data.as_borrowed();
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<'a, T> Clone for CodePointMapDataBorrowed<'a, T>where
T: Clone + TrieValue,
impl<'a, T> Clone for CodePointMapDataBorrowed<'a, T>where T: Clone + TrieValue,
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 more