pub struct IntervalSet { /* private fields */ }
Expand description
A collection of non-overlapping Unicode codepoint intervals that enables interval-based operations, such as iteration over all Unicode codepoints or finding the codepoint at a specific position within the intervals.
Implementations§
Source§impl IntervalSet
impl IntervalSet
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of Unicode codepoints in the interval set.
§Examples
let interval_set = unicode_intervals::query()
.include_categories(UnicodeCategory::UPPERCASE_LETTER)
.interval_set()
.expect("Invalid query input");
assert_eq!(interval_set.len(), 1831);
Sourcepub const fn is_empty(&self) -> bool
pub const fn is_empty(&self) -> bool
Returns true
if the interval set contains no elements.
§Examples
let interval_set = unicode_intervals::query()
.include_categories(UnicodeCategory::UPPERCASE_LETTER)
// The first upper case letter has 65
.max_codepoint(50)
.interval_set()
.expect("Invalid query input");
assert!(interval_set.is_empty());
Sourcepub fn contains(&self, codepoint: impl Into<u32>) -> bool
pub fn contains(&self, codepoint: impl Into<u32>) -> bool
Returns true
if the interval set contains a codepoint with the given value.
§Examples
let interval_set = unicode_intervals::query()
.include_categories(UnicodeCategory::UPPERCASE_LETTER)
.interval_set()
.expect("Invalid query input");
assert!(interval_set.contains('C'));
assert!(!interval_set.contains('a'));
Sourcepub fn codepoint_at(&self, index: u32) -> Option<u32>
pub fn codepoint_at(&self, index: u32) -> Option<u32>
Returns the codepoint at index
in the IntervalSet
.
§Examples
let interval_set = unicode_intervals::query()
.include_categories(UnicodeCategory::UPPERCASE_LETTER)
.interval_set()
.expect("Invalid query input");
// Get 10th codepoint in this interval set
assert_eq!(interval_set.codepoint_at(10), Some('K' as u32));
Sourcepub fn index_of(&self, codepoint: impl Into<u32>) -> Option<u32>
pub fn index_of(&self, codepoint: impl Into<u32>) -> Option<u32>
Returns the index of a specific codepoint in the IntervalSet
.
§Examples
let interval_set = unicode_intervals::query()
.include_categories(UnicodeCategory::UPPERCASE_LETTER)
.interval_set()
.expect("Invalid query input");
assert_eq!(interval_set.index_of('A'), Some(0));
assert_eq!(interval_set.index_of('c'), None);
Sourcepub fn index_above(&self, codepoint: impl Into<u32>) -> u32
pub fn index_above(&self, codepoint: impl Into<u32>) -> u32
Returns the index of a specific codepoint in the IntervalSet
if it is present in the set,
or the index of the closest codepoint that is greater than the given one.
If the given codepoint is greater than the largest codepoint in the set, then the set’s size is returned.
§Examples
let interval_set = unicode_intervals::query()
.include_categories(UnicodeCategory::UPPERCASE_LETTER)
.interval_set()
.expect("Invalid query input");
assert_eq!(interval_set.index_above('Z'), 25);
Sourcepub fn iter(&self) -> impl Iterator<Item = u32> + DoubleEndedIterator + '_
pub fn iter(&self) -> impl Iterator<Item = u32> + DoubleEndedIterator + '_
Returns an iterator over all codepoints in all contained intervals.
§Examples
let interval_set = unicode_intervals::query()
.include_categories(UnicodeCategory::UPPERCASE_LETTER)
.max_codepoint(67)
.interval_set()
.expect("Invalid query input");
let mut iterator = interval_set.iter();
assert_eq!(iterator.next(), Some('A' as u32));
assert_eq!(iterator.next(), Some('B' as u32));
assert_eq!(iterator.next(), Some('C' as u32));
assert_eq!(iterator.next(), None);
Trait Implementations§
Source§impl Clone for IntervalSet
impl Clone for IntervalSet
Source§fn clone(&self) -> IntervalSet
fn clone(&self) -> IntervalSet
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read more