Struct regex_syntax::CharClass
[−]
[src]
pub struct CharClass { /* fields omitted */ }
A character class.
A character class has a canonical format that the parser guarantees. Its canonical format is defined by the following invariants:
- Given any Unicode scalar value, it is matched by at most one character range in a canonical character class.
- Every adjacent character range is separated by at least one Unicode scalar value.
- Given any pair of character ranges
r1
andr2
, ifr1.end < r2.start
, thenr1
comes beforer2
in a canonical character class.
In sum, any CharClass
produced by this crate's parser is a sorted
sequence of non-overlapping ranges. This makes it possible to test whether
a character is matched by a class with a binary search.
If the case insensitive flag was set when parsing a character class, then
simple case folding is done automatically. For example, (?i)[a-c]
is
automatically translated to [a-cA-C]
.
Methods
impl CharClass
[src]
fn new(ranges: Vec<ClassRange>) -> CharClass
Create a new class from an existing set of ranges.
fn matches(&self, c: char) -> bool
Returns true if c
is matched by this character class.
fn remove(&mut self, c: char)
Removes the given character from the class if it exists.
Note that this takes O(n)
time in the number of ranges.
fn negate(self) -> CharClass
Negates the character class.
For all c
where c
is a Unicode scalar value, c
matches self
if and only if c
does not match self.negate()
.
fn case_fold(self) -> CharClass
Apply case folding to this character class.
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<ClassRange>>
fn capacity(&self) -> usize
1.0.0
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);
fn into_boxed_slice(self) -> Box<[T]>
1.0.0
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);
fn as_slice(&self) -> &[T]
1.7.0
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();
fn len(&self) -> usize
1.0.0
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);
fn is_empty(&self) -> bool
1.0.0
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 CharClass
[src]
fn clone(&self) -> CharClass
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Debug for CharClass
[src]
impl PartialEq for CharClass
[src]
fn eq(&self, __arg_0: &CharClass) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &CharClass) -> bool
This method tests for !=
.
impl Eq for CharClass
[src]
impl Deref for CharClass
[src]
type Target = Vec<ClassRange>
The resulting type after dereferencing
fn deref(&self) -> &Vec<ClassRange>
The method called to dereference a value
impl IntoIterator for CharClass
[src]
type Item = ClassRange
The type of the elements being iterated over.
type IntoIter = IntoIter<ClassRange>
Which kind of iterator are we turning this into?
fn into_iter(self) -> IntoIter<ClassRange>
Creates an iterator from a value. Read more
impl<'a> IntoIterator for &'a CharClass
[src]
type Item = &'a ClassRange
The type of the elements being iterated over.
type IntoIter = Iter<'a, ClassRange>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Iter<'a, ClassRange>
Creates an iterator from a value. Read more