Struct regex_syntax::CharClass [−][src]
pub struct CharClass { /* fields omitted */ }
Expand description
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]
.
Implementations
Create a new class from an existing set of ranges.
Removes the given character from the class if it exists.
Note that this takes O(n)
time in the number of ranges.
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()
.
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>>
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);
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 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); } }
🔬 This is a nightly-only experimental API. (allocator_api
)
allocator_api
)Returns a reference to the underlying allocator.
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);
Trait Implementations
type Target = Vec<ClassRange>
type Target = Vec<ClassRange>
The resulting type after dereferencing.
Dereferences the value.
type Item = ClassRange
type Item = ClassRange
The type of the elements being iterated over.
type IntoIter = IntoIter<ClassRange>
type IntoIter = IntoIter<ClassRange>
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
type Item = &'a ClassRange
type Item = &'a ClassRange
The type of the elements being iterated over.
type IntoIter = Iter<'a, ClassRange>
type IntoIter = Iter<'a, ClassRange>
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
Auto Trait Implementations
impl RefUnwindSafe for CharClass
impl UnwindSafe for CharClass
Blanket Implementations
Mutably borrows from an owned value. Read more