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

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.

The bitmask representing characters 64 through 127.

Methods

impl AsciiSet
[src]

Tests whether this set contains the char c.

Tests whether this set contains the byte c.

Adds a byte to this set.

Panics

  • if c falls outside the ASCII range.

Adds a char to this set.

Panics

  • if c falls outside the ASCII range.

Creates a new, empty, 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'));

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()));

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()));

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()));

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()));

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()));

Returns the set of all ASCII chars not in self.

Returns the set of all lower case letters.

Returns the set of all upper case letters.

Returns the set of all letters.

Returns the set of all digits.

Trait Implementations

impl Eq for AsciiSet
[src]

impl PartialEq for AsciiSet
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Hash for AsciiSet
[src]

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more

impl Debug for AsciiSet
[src]

Formats the value using the given formatter.

impl Clone for AsciiSet
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more