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
impl SimpleCaseFolder
sourcepub fn new() -> Result<SimpleCaseFolder, CaseFoldError>
pub fn new() -> Result<SimpleCaseFolder, CaseFoldError>
Create a new simple case folder, returning an error if the underlying case folding table is unavailable.
sourcepub fn mapping(&mut self, c: char) -> &'static [char]
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
.
sourcepub fn overlaps(&self, start: char, end: char) -> bool
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
.