Struct regex_syntax::ByteClass [] [src]

pub struct ByteClass { /* fields omitted */ }

A byte class for byte ranges only.

A byte class has a canonical format that the parser guarantees. Its canonical format is defined by the following invariants:

  1. Given any byte, it is matched by at most one byte range in a canonical character class.
  2. Every adjacent byte range is separated by at least one byte.
  3. Given any pair of byte ranges r1 and r2, if r1.end < r2.start, then r1 comes before r2 in a canonical character class.

In sum, any ByteClass produced by this crate's parser is a sorted sequence of non-overlapping ranges. This makes it possible to test whether a byte is matched by a class with a binary search.

If the case insensitive flag was set when parsing a character class, then simple ASCII-only case folding is done automatically. For example, (?i)[a-c] is automatically translated to [a-cA-C].

Methods

impl ByteClass
[src]

Create a new class from an existing set of ranges.

Returns true if b is matched by this byte class.

Removes the given byte from the class if it exists.

Note that this takes O(n) time in the number of ranges.

Negates the byte class.

For all b where b is a byte, b matches self if and only if b does not match self.negate().

Apply case folding to this byte class.

This assumes that the bytes in the ranges are ASCII compatible.

N.B. Applying case folding to a negated character class probably won't produce the expected result. e.g., (?i)[^x] really should match any character sans x and X, but if [^x] is negated before being case folded, you'll end up matching any character.

Methods from Deref<Target=Vec<ByteRange>>

Returns the number of elements the vector can hold without reallocating.

Examples

let vec: Vec<i32> = Vec::with_capacity(10);
assert_eq!(vec.capacity(), 10);

Converts the vector into Box<[T]>.

Note that this will drop any excess capacity. Calling this and converting back to a vector with into_vec() is equivalent to calling shrink_to_fit().

Examples

let v = vec![1, 2, 3];

let slice = v.into_boxed_slice();

Any excess capacity is removed:

let mut vec = Vec::with_capacity(10);
vec.extend([1, 2, 3].iter().cloned());

assert_eq!(vec.capacity(), 10);
let slice = vec.into_boxed_slice();
assert_eq!(slice.into_vec().capacity(), 3);

Extracts a slice containing the entire vector.

Equivalent to &s[..].

Examples

use std::io::{self, Write};
let buffer = vec![1, 2, 3, 5, 8];
io::sink().write(buffer.as_slice()).unwrap();

Returns the number of elements in the vector.

Examples

let a = vec![1, 2, 3];
assert_eq!(a.len(), 3);

Returns true if the vector contains no elements.

Examples

let mut v = Vec::new();
assert!(v.is_empty());

v.push(1);
assert!(!v.is_empty());

Trait Implementations

impl Clone for ByteClass
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for ByteClass
[src]

Formats the value using the given formatter.

impl PartialEq for ByteClass
[src]

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

This method tests for !=.

impl Eq for ByteClass
[src]

impl Deref for ByteClass
[src]

The resulting type after dereferencing

The method called to dereference a value

impl IntoIterator for ByteClass
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

impl<'a> IntoIterator for &'a ByteClass
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

impl Display for ByteClass
[src]

Formats the value using the given formatter.