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:
- Given any byte, it is matched by at most one byte range in a canonical character class.
- Every adjacent byte range is separated by at least one byte.
- Given any pair of byte ranges
r1andr2, ifr1.end < r2.start, thenr1comes beforer2in 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]
impl ByteClasspub fn new(ranges: Vec<ByteRange>) -> ByteClass[src]
pub fn new(ranges: Vec<ByteRange>) -> ByteClassCreate a new class from an existing set of ranges.
pub fn matches(&self, b: u8) -> bool[src]
pub fn matches(&self, b: u8) -> boolReturns true if b is matched by this byte class.
pub fn remove(&mut self, b: u8)[src]
pub fn remove(&mut self, b: u8)Removes the given byte from the class if it exists.
Note that this takes O(n) time in the number of ranges.
pub fn negate(self) -> ByteClass[src]
pub fn negate(self) -> ByteClassNegates the byte class.
For all b where b is a byte, b matches self if and only if b
does not match self.negate().
pub fn case_fold(self) -> ByteClass[src]
pub fn case_fold(self) -> ByteClassApply 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>>
pub fn capacity(&self) -> usize1.0.0[src]
pub fn capacity(&self) -> usizeReturns the number of elements the vector can hold without reallocating.
Examples
let vec: Vec<i32> = Vec::with_capacity(10); assert_eq!(vec.capacity(), 10);
pub fn as_slice(&self) -> &[T]1.7.0[src]
pub fn as_slice(&self) -> &[T]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();
pub fn len(&self) -> usize1.0.0[src]
pub fn len(&self) -> usizeReturns the number of elements in the vector, also referred to as its 'length'.
Examples
let a = vec![1, 2, 3]; assert_eq!(a.len(), 3);
pub fn is_empty(&self) -> bool1.0.0[src]
pub fn is_empty(&self) -> boolReturns 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]
impl Clone for ByteClassfn clone(&self) -> ByteClass[src]
fn clone(&self) -> ByteClassReturns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src]
fn clone_from(&mut self, source: &Self)Performs copy-assignment from source. Read more
impl Debug for ByteClass[src]
impl Debug for ByteClassfn fmt(&self, __arg_0: &mut Formatter) -> Result[src]
fn fmt(&self, __arg_0: &mut Formatter) -> ResultFormats the value using the given formatter. Read more
impl PartialEq for ByteClass[src]
impl PartialEq for ByteClassfn eq(&self, __arg_0: &ByteClass) -> bool[src]
fn eq(&self, __arg_0: &ByteClass) -> boolThis method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, __arg_0: &ByteClass) -> bool[src]
fn ne(&self, __arg_0: &ByteClass) -> boolThis method tests for !=.
impl Eq for ByteClass[src]
impl Eq for ByteClassimpl Deref for ByteClass[src]
impl Deref for ByteClasstype Target = Vec<ByteRange>
The resulting type after dereferencing.
fn deref(&self) -> &Vec<ByteRange>[src]
fn deref(&self) -> &Vec<ByteRange>Dereferences the value.
impl IntoIterator for ByteClass[src]
impl IntoIterator for ByteClasstype Item = ByteRange
The type of the elements being iterated over.
type IntoIter = IntoIter<ByteRange>
Which kind of iterator are we turning this into?
ⓘImportant traits for IntoIter<T>fn into_iter(self) -> IntoIter<ByteRange>[src]
fn into_iter(self) -> IntoIter<ByteRange>Creates an iterator from a value. Read more
impl<'a> IntoIterator for &'a ByteClass[src]
impl<'a> IntoIterator for &'a ByteClasstype Item = &'a ByteRange
The type of the elements being iterated over.
type IntoIter = Iter<'a, ByteRange>
Which kind of iterator are we turning this into?
ⓘImportant traits for Iter<'a, T>fn into_iter(self) -> Iter<'a, ByteRange>[src]
fn into_iter(self) -> Iter<'a, ByteRange>Creates an iterator from a value. Read more
impl Display for ByteClass[src]
impl Display for ByteClass