Function malachite_base::chars::crement::char_to_contiguous_range
source · pub const fn char_to_contiguous_range(c: char) -> u32
Expand description
The conversion is done in such a way that if the next largest char
after $x$ is $y$, then
$\mathrm{char\_to\_contiguous\_range(x)}+1 = \mathrm{char\_to\_contiguous\_range(y)}$.
This can’t be accomplished just through casting, because there is a range of u32
s (the
surrogate code points) that do not
correspond to any char
.
The inverse of this function is contiguous_range_to_char
.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::chars::crement::char_to_contiguous_range;
use std::char;
assert_eq!(char_to_contiguous_range('\u{0}'), 0);
assert_eq!(char_to_contiguous_range('a'), 97);
assert_eq!(char_to_contiguous_range(char::MAX), 1112063);