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

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

The bitmask representing characters 64 through 127.

Methods

impl AsciiSet

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)

Adds a byte to this set.

Panics

  • if c falls outside the ASCII range.

fn insert_char(&mut self, c: char)

Adds a char to this set.

Panics

  • if c falls outside the ASCII range.

fn new() -> AsciiSet

Creates a new, empty, AsciiSet.

fn from_ranges<I>(iter: I) -> AsciiSet where 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

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>

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

Derived Implementations

impl Clone for AsciiSet

fn clone(&self) -> AsciiSet

fn clone_from(&mut self, source: &Self)

impl Debug for AsciiSet

fn fmt(&self, __arg_0: &mut Formatter) -> Result

impl Hash for AsciiSet

fn hash<__H: Hasher>(&self, __arg_0: &mut __H)

fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher

impl PartialEq for AsciiSet

fn eq(&self, __arg_0: &AsciiSet) -> bool

fn ne(&self, __arg_0: &AsciiSet) -> bool

impl Eq for AsciiSet