Struct regex_syntax::utf8::Utf8Sequences [−][src]
An iterator over ranges of matching UTF-8 byte sequences.
The iteration represents an alternation of comprehensive byte sequences that match precisely the set of UTF-8 encoded scalar values.
A byte sequence corresponds to one of the scalar values in the range given if and only if it completely matches exactly one of the sequences of byte ranges produced by this iterator.
Each sequence of byte ranges matches a unique set of bytes. That is, no two sequences will match the same bytes.
Example
This shows how to match an arbitrary byte sequence against a range of scalar values.
use regex_syntax::utf8::{Utf8Sequences, Utf8Sequence}; fn matches(seqs: &[Utf8Sequence], bytes: &[u8]) -> bool { for range in seqs { if range.matches(bytes) { return true; } } false } // Test the basic multilingual plane. let seqs: Vec<_> = Utf8Sequences::new('\u{0}', '\u{FFFF}').collect(); // UTF-8 encoding of 'a'. assert!(matches(&seqs, &[0x61])); // UTF-8 encoding of '☃' (`\u{2603}`). assert!(matches(&seqs, &[0xE2, 0x98, 0x83])); // UTF-8 encoding of `\u{10348}` (outside the BMP). assert!(!matches(&seqs, &[0xF0, 0x90, 0x8D, 0x88])); // Tries to match against a UTF-8 encoding of a surrogate codepoint, // which is invalid UTF-8, and therefore fails, despite the fact that // the corresponding codepoint (0xD800) falls in the range given. assert!(!matches(&seqs, &[0xED, 0xA0, 0x80])); // And fails against plain old invalid UTF-8. assert!(!matches(&seqs, &[0xFF, 0xFF]));
If this example seems circuitous, that’s because it is! It’s meant to be illustrative. In practice, you could just try to decode your byte sequence and compare it with the scalar value range directly. However, this is not always possible (for example, in a byte based automaton).
Implementations
impl Utf8Sequences
[src][−]
pub fn new(start: char, end: char) -> Self
[src][−]
Create a new iterator over UTF-8 byte ranges for the scalar value range given.
Trait Implementations
impl Debug for Utf8Sequences
[src][+]
impl FusedIterator for Utf8Sequences
[src]
impl Iterator for Utf8Sequences
[src][+]
Auto Trait Implementations
impl RefUnwindSafe for Utf8Sequences
impl Send for Utf8Sequences
impl Sync for Utf8Sequences
impl Unpin for Utf8Sequences
impl UnwindSafe for Utf8Sequences
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src][+]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src][+]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src][+]
T: ?Sized,
impl<T> From<T> for T
[src][+]
impl<T, U> Into<U> for T where
U: From<T>,
[src][+]
U: From<T>,
impl<I> IntoIterator for I where
I: Iterator,
[src][+]
I: Iterator,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src][+]
U: Into<T>,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src][+]
U: TryFrom<T>,