Struct ascii_set::AsciiSet
[−]
[src]
pub struct AsciiSet { pub lo_mask: u64, pub hi_mask: u64, }
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.
Methods
impl AsciiSet
[src]
fn contains_char(&self, c: char) -> bool
Tests whether this set contains the char c
.
fn contains_byte(&self, c: u8) -> bool
Tests whether this set contains the byte c
.
fn insert_byte(&mut self, c: u8)
fn insert_char(&mut self, c: char)
fn new() -> AsciiSet
Creates a new, empty, AsciiSet
.
fn from_ranges<I>(iter: I) -> AsciiSet where
I: IntoIterator<Item = (char, char)>,
I: IntoIterator<Item = (char, char)>,
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'));
fn from_fn<F>(f: F) -> AsciiSet where
F: FnMut(char) -> bool,
F: FnMut(char) -> bool,
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()));
fn from_chars<I>(iter: I) -> AsciiSet where
I: IntoIterator<Item = char>,
I: IntoIterator<Item = char>,
Builds the AsciiSet
consisting of all characters yielded by iter
.
Panics
- if
iter
yields any non-ASCII characters.
Examples
use ascii_set::AsciiSet; assert_eq!( AsciiSet::from_ranges(vec![('a', 'z')]), AsciiSet::from_chars("abcdefghijklmnopqrstuvwxyz".chars()));
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()));
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()));
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()));
fn complement(&self) -> AsciiSet
Returns the set of all ASCII chars not in self
.
fn lower_case_letters() -> AsciiSet
Returns the set of all lower case letters.
fn upper_case_letters() -> AsciiSet
Returns the set of all upper case letters.
fn letters() -> AsciiSet
Returns the set of all letters.
fn digits() -> AsciiSet
Returns the set of all digits.
Trait Implementations
impl Eq for AsciiSet
[src]
impl PartialEq for AsciiSet
[src]
fn eq(&self, __arg_0: &AsciiSet) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &AsciiSet) -> bool
This method tests for !=
.
impl Hash for AsciiSet
[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl Debug for AsciiSet
[src]
impl Clone for AsciiSet
[src]
fn clone(&self) -> AsciiSet
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more