[−][src]Struct regex_syntax::ByteClass
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
r1
andr2
, ifr1.end < r2.start
, thenr1
comes beforer2
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]
pub fn new(ranges: Vec<ByteRange>) -> ByteClass
[src]
Create a new class from an existing set of ranges.
pub fn matches(&self, b: u8) -> bool
[src]
Returns true if b
is matched by this byte class.
pub fn remove(&mut self, b: u8)
[src]
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]
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()
.
pub fn case_fold(self) -> ByteClass
[src]
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>>
pub fn capacity(&self) -> usize
1.0.0[src]
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);
pub fn as_slice(&self) -> &[T]
1.7.0[src]
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 as_ptr(&self) -> *const T
1.37.0[src]
Returns a raw pointer to the vector's buffer.
The caller must ensure that the vector outlives the pointer this function returns, or else it will end up pointing to garbage. Modifying the vector may cause its buffer to be reallocated, which would also make any pointers to it invalid.
The caller must also ensure that the memory the pointer (non-transitively) points to
is never written to (except inside an UnsafeCell
) using this pointer or any pointer
derived from it. If you need to mutate the contents of the slice, use as_mut_ptr
.
Examples
let x = vec![1, 2, 4]; let x_ptr = x.as_ptr(); unsafe { for i in 0..x.len() { assert_eq!(*x_ptr.add(i), 1 << i); } }
pub fn len(&self) -> usize
1.0.0[src]
Returns 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) -> bool
1.0.0[src]
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 IntoIterator for ByteClass
[src]
type Item = ByteRange
The type of the elements being iterated over.
type IntoIter = IntoIter<ByteRange>
Which kind of iterator are we turning this into?
fn into_iter(self) -> IntoIter<ByteRange>
[src]
impl<'a> IntoIterator for &'a ByteClass
[src]
type 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?
fn into_iter(self) -> Iter<'a, ByteRange>
[src]
impl Clone for ByteClass
[src]
impl Eq for ByteClass
[src]
impl PartialEq<ByteClass> for ByteClass
[src]
impl Display for ByteClass
[src]
impl Debug for ByteClass
[src]
impl Deref for ByteClass
[src]
type Target = Vec<ByteRange>
The resulting type after dereferencing.
fn deref(&self) -> &Vec<ByteRange>
[src]
impl StructuralPartialEq for ByteClass
[src]
impl StructuralEq for ByteClass
[src]
Auto Trait Implementations
impl Send for ByteClass
impl Sync for ByteClass
impl Unpin for ByteClass
impl UnwindSafe for ByteClass
impl RefUnwindSafe for ByteClass
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,