pub struct AsciiSet {
pub lo_mask: u64,
pub hi_mask: u64,
}
Expand description
Provides a fast method for testing character membership of a purely ASCII set.
This is implemented as a bitset, and will therefore always use 16 bytes, no matter how many characters the set contains.
Fields§
§lo_mask: u64
The bitmask representing characters 0 through 63. If c <= 63
and (lo_mask >> c) & 1 == 1
then the ASCII codepoint c
belongs to this set.
hi_mask: u64
The bitmask representing characters 64 through 127.
Implementations§
Source§impl AsciiSet
impl AsciiSet
Sourcepub fn contains_char(&self, c: char) -> bool
pub fn contains_char(&self, c: char) -> bool
Tests whether this set contains the char c
.
Sourcepub fn contains_byte(&self, c: u8) -> bool
pub fn contains_byte(&self, c: u8) -> bool
Tests whether this set contains the byte c
.
Sourcepub fn insert_byte(&mut self, c: u8)
pub fn insert_byte(&mut self, c: u8)
Sourcepub fn insert_char(&mut self, c: char)
pub fn insert_char(&mut self, c: char)
Sourcepub fn from_ranges<I>(iter: I) -> AsciiSet
pub fn from_ranges<I>(iter: I) -> AsciiSet
Builds an AsciiSet
as a union of ranges (which are inclusive).
§Panics
- if any of the ranges overlap anything outside the ASCII range.
§Examples
use ascii_set::AsciiSet;
let a = AsciiSet::from_ranges(vec![('a', 'e'), ('A', 'E')]);
assert!(a.contains_char('a'));
assert!(a.contains_char('b'));
assert!(a.contains_char('e'));
assert!(!a.contains_char('f'));
Sourcepub fn from_fn<F>(f: F) -> AsciiSet
pub fn from_fn<F>(f: F) -> AsciiSet
Builds the AsciiSet
consisting of all characters for which f
returns true
.
§Examples
use ascii_set::AsciiSet;
assert_eq!(
AsciiSet::from_ranges(vec![('a', 'z'), ('A', 'Z')]),
AsciiSet::from_fn(|c| c.is_alphabetic()));
Sourcepub fn from_chars<I>(iter: I) -> AsciiSetwhere
I: IntoIterator<Item = char>,
pub fn from_chars<I>(iter: I) -> AsciiSetwhere
I: IntoIterator<Item = char>,
Sourcepub fn union(&self, other: &AsciiSet) -> AsciiSet
pub fn union(&self, other: &AsciiSet) -> AsciiSet
Returns the union of this set and other
.
§Examples
use ascii_set::AsciiSet;
assert_eq!(
AsciiSet::letters(),
AsciiSet::upper_case_letters().union(&AsciiSet::lower_case_letters()));
Sourcepub fn intersection(&self, other: &AsciiSet) -> AsciiSet
pub fn intersection(&self, other: &AsciiSet) -> AsciiSet
Returns the intersection of this set and other
.
§Examples
use ascii_set::AsciiSet;
assert_eq!(
AsciiSet::lower_case_letters(),
AsciiSet::letters().intersection(&AsciiSet::lower_case_letters()));
Sourcepub fn difference(&self, other: &AsciiSet) -> AsciiSet
pub fn difference(&self, other: &AsciiSet) -> AsciiSet
Returns the set of chars in self
but not other
.
§Examples
use ascii_set::AsciiSet;
assert_eq!(
AsciiSet::lower_case_letters(),
AsciiSet::letters().difference(&AsciiSet::upper_case_letters()));
Sourcepub fn complement(&self) -> AsciiSet
pub fn complement(&self) -> AsciiSet
Returns the set of all ASCII chars not in self
.
Sourcepub fn lower_case_letters() -> AsciiSet
pub fn lower_case_letters() -> AsciiSet
Returns the set of all lower case letters.
Sourcepub fn upper_case_letters() -> AsciiSet
pub fn upper_case_letters() -> AsciiSet
Returns the set of all upper case letters.