Struct regex_syntax::unicode::SimpleCaseFolder

source ·
pub struct SimpleCaseFolder {
    table: &'static [(char, &'static [char])],
    last: Option<char>,
    next: usize,
}
Expand description

A state oriented traverser of the simple case folding table.

A case folder can be constructed via SimpleCaseFolder::new(), which will return an error if the underlying case folding table is unavailable.

After construction, it is expected that callers will use SimpleCaseFolder::mapping by calling it with codepoints in strictly increasing order. For example, calling it on b and then on a is illegal and will result in a panic.

The main idea of this type is that it tries hard to make mapping lookups fast by exploiting the structure of the underlying table, and the ordering assumption enables this.

Fields§

§table: &'static [(char, &'static [char])]

The simple case fold table. It’s a sorted association list, where the keys are Unicode scalar values and the values are the corresponding equivalence class (not including the key) of the “simple” case folded Unicode scalar values.

§last: Option<char>

The last codepoint that was used for a lookup.

§next: usize

The index to the entry in table corresponding to the smallest key k such that k > k0, where k0 is the most recent key lookup. Note that in particular, k0 may not be in the table!

Implementations§

source§

impl SimpleCaseFolder

source

pub fn new() -> Result<SimpleCaseFolder, CaseFoldError>

Create a new simple case folder, returning an error if the underlying case folding table is unavailable.

source

pub fn mapping(&mut self, c: char) -> &'static [char]

Return the equivalence class of case folded codepoints for the given codepoint. The equivalence class returned never includes the codepoint given. If the given codepoint has no case folded codepoints (i.e., no entry in the underlying case folding table), then this returns an empty slice.

§Panics

This panics when called with a c that is less than or equal to the previous call. In other words, callers need to use this method with strictly increasing values of c.

source

pub fn overlaps(&self, start: char, end: char) -> bool

Returns true if and only if the given range overlaps with any region of the underlying case folding table. That is, when true, there exists at least one codepoint in the inclusive range [start, end] that has a non-trivial equivalence class of case folded codepoints. Conversely, when this returns false, all codepoints in the range [start, end] correspond to the trivial equivalence class of case folded codepoints, i.e., itself.

This is useful to call before iterating over the codepoints in the range and looking up the mapping for each. If you know none of the mappings will return anything, then you might be able to skip doing it altogether.

§Panics

This panics when end < start.

source

fn get(&self, c: char) -> Result<usize, usize>

Returns the index at which c occurs in the simple case fold table. If c does not occur, then this returns an i such that table[i-1].0 < c and table[i].0 > c.

Trait Implementations§

source§

impl Debug for SimpleCaseFolder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.