pub struct CharSet { /* private fields */ }
Expand description
Interval [start, end] where start <= end <= MAX_CHAR.
This represents a range of characters.
Implementations§
Source§impl CharSet
impl CharSet
Sourcepub fn singleton(x: u32) -> CharSet
pub fn singleton(x: u32) -> CharSet
Construct the singleton interval [x, x]
- the integer x must be a valid SMT-LIB character (i.e., 0 <= x <= MAX_CHAR)
Sourcepub fn range(x: u32, y: u32) -> CharSet
pub fn range(x: u32, y: u32) -> CharSet
Construct the interval [x, y]
- requires x <= y <= MAX_CHAR
Sourcepub fn contains(&self, x: u32) -> bool
pub fn contains(&self, x: u32) -> bool
Check whether x is in this interval
§Example
use aws_smt_strings::character_sets::CharSet;
let c = CharSet::range('a' as u32, 'z' as u32);
assert!(c.contains('g' as u32));
assert!(!c.contains('0' as u32));
Sourcepub fn covers(&self, other: &CharSet) -> bool
pub fn covers(&self, other: &CharSet) -> bool
Check whether other is a subset of this set
§Example
use aws_smt_strings::character_sets::CharSet;
let c = CharSet::range('a' as u32, 'z' as u32);
assert!(c.covers(&CharSet::singleton('g' as u32)));
assert!(c.covers(&CharSet::range('t' as u32, 'z' as u32)));
assert!(! c.covers(&CharSet::range(0, 'k' as u32)));
Sourcepub fn is_before(&self, x: u32) -> bool
pub fn is_before(&self, x: u32) -> bool
Check whether this set is before x
If set is [a, b] this checks whether b < x.
§Example
use aws_smt_strings::character_sets::CharSet;
let c = CharSet::range('a' as u32, 'z' as u32);
assert!(c.is_before(127));
assert!(! c.is_before('c' as u32));
Sourcepub fn is_after(&self, x: u32) -> bool
pub fn is_after(&self, x: u32) -> bool
Check whether this set is after x
If set is the interval [a, b], this checks whether x < a.
§Example
use aws_smt_strings::character_sets::CharSet;
let c = CharSet::range('a' as u32, 'z' as u32);
assert!(! c.is_after(127));
assert!(c.is_after('Z' as u32));
Sourcepub fn size(&self) -> u32
pub fn size(&self) -> u32
Get the size of this set
Return the number of characters in the interval
§Example
use aws_smt_strings::character_sets::CharSet;
let c = CharSet::range('a' as u32, 'z' as u32);
assert_eq!(c.size(), 26);
Sourcepub fn is_singleton(&self) -> bool
pub fn is_singleton(&self) -> bool
Check whether the set is a singleton
§Example
use aws_smt_strings::character_sets::CharSet;
let c = CharSet::range('a' as u32, 'z' as u32);
let d = CharSet::singleton('K' as u32);
assert!(d.is_singleton());
assert!(! c.is_singleton());
Sourcepub fn is_alphabet(&self) -> bool
pub fn is_alphabet(&self) -> bool
Check whether this set is the full alphabet
§Example
use aws_smt_strings::{character_sets::CharSet, smt_strings::MAX_CHAR};
let c = CharSet::range(0, MAX_CHAR);
let d = CharSet::range('a' as u32, 'z' as u32);
assert!(c.is_alphabet());
assert!(! d.is_alphabet());
Sourcepub fn pick(&self) -> u32
pub fn pick(&self) -> u32
Pick a character in the set
§Example
use aws_smt_strings::character_sets::CharSet;
let c = CharSet::range('a' as u32, 'z' as u32);
let d = c.pick();
assert!('a' as u32 <= d && d <= 'z' as u32);
Sourcepub fn inter(&self, other: &CharSet) -> Option<CharSet>
pub fn inter(&self, other: &CharSet) -> Option<CharSet>
Intersection of two intervals
- return None if the intersection is empty
- return Some(charset) otherwise.
§Example
use aws_smt_strings::character_sets::CharSet;
let c = CharSet::range('a' as u32, 'z' as u32); // ['a', 'z']
let d = CharSet::range('t' as u32, 127); // ['t', 127]
// the intersection of c and d is ['t', 'z']
assert_eq!(c.inter(&d), Some(CharSet::range('t' as u32, 'z' as u32)));
Sourcepub fn inter_list(a: &[CharSet]) -> Option<CharSet>
pub fn inter_list(a: &[CharSet]) -> Option<CharSet>
Intersection of an array of intervals
See inter
- return None if the intersection is empty
- return Some(c) otherwise
Sourcepub fn union(&self, other: &CharSet) -> Option<CharSet>
pub fn union(&self, other: &CharSet) -> Option<CharSet>
Union of two intervals
- return None if the union is not an interval
- return Some(c) where c is a CharSet otherwise.
§Example
use aws_smt_strings::character_sets::CharSet;
let c = CharSet::range('a' as u32, 'z' as u32);
let d = CharSet::range('t' as u32, 127);
let e = CharSet::range('0' as u32, '9' as u32);
assert_eq!(c.union(&d), Some(CharSet::range('a' as u32, 127)));
assert_eq!(c.union(&e), None);
Trait Implementations§
Source§impl PartialOrd for CharSet
impl PartialOrd for CharSet
impl Copy for CharSet
impl Eq for CharSet
impl StructuralPartialEq for CharSet
Auto Trait Implementations§
impl Freeze for CharSet
impl RefUnwindSafe for CharSet
impl Send for CharSet
impl Sync for CharSet
impl Unpin for CharSet
impl UnwindSafe for CharSet
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
Mutably borrows from an owned value. Read more