1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//! Permissive UTF-8 / UTF-16 / UTF-32 transcoding, comparison and BOM
//! detection, with SIMD ASCII fast paths.
//!
//! A Rust port of the `xstd::codepoint_cvt` / `utf_*` family. Design points
//! carried over:
//!
//! - **Permissive, non-validating codecs.** Decoding never fails: truncated
//! UTF-8 sequences decode to `0` (consuming the remainder), lone surrogates
//! pass through, garbage-in produces garbage-out. Values are raw `u32`
//! codepoints, not `char`.
//! - **ASCII-only case folding** for the `*_ignore_ascii_case` operations and
//! [`AsciiCase`] transcoding.
//! - **Foreign endianness** as a type parameter: [`Utf16<true>`](Utf16) is
//! byte-swapped relative to the native byte order (see [`Utf16Be`] /
//! [`Utf16Le`] aliases).
//! - **Terminal text primitives**, allocation-free and generic over the
//! encoding: grapheme segmentation ([`graphemes`], UAX #29 incl. `GB9c` and
//! GB11), visible cell width ([`width`]), width truncation ([`truncate`],
//! returns a borrowed prefix) and greedy word wrap ([`wrap`], yields borrowed
//! sublines), backed by a generated Unicode [`UNICODE_VERSION`] property trie
//! (`scripts/gen_props.py`).
//!
//! Special-op mapping from the C++ original:
//!
//! | C++ (`xstd`) | Rust |
//! |---------------------------------------|---------------------------------------------|
//! | clang vector extensions (`xvec`) | `core::simd` (LLVM vector IR) |
//! | `bit_pdep` / `bit_pext` (BMI2) | `_pdep_u32` / `_pext_u32` under `cfg(bmi2)` |
//! | `assume(..)` | `core::hint::assert_unchecked` |
//! | `bswapw` / `bswapd` | `u16::swap_bytes` / `u32::swap_bytes` |
//! | `lsb(mask())` | `Mask::to_bitmask().trailing_zeros()` |
//! | overlapped tail vector load/store | `Simd::from_slice` / `copy_to_slice` on an |
//! | | overlapping window at `limit - N` |
//!
//! Deliberate fixes over the original:
//! - UTF-16 encode computes the low surrogate as `0xDC00 | (cp & 0x3FF)`; the
//! C++ `0xDC00 | uint16_t(cp)` corrupts pairs when bit 13 of `cp - 0x10000`
//! is set (e.g. U+12000).
//! - `compare` orders by decoded codepoint everywhere (the C++ mixed UTF-16
//! code-unit order with codepoint order) and a longer string with a trailing
//! `NUL` codepoint no longer compares equal to its prefix.
extern crate alloc;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use UNICODE_VERSION;
pub use ;
pub use Unit;
pub use Utf8;
pub use Utf16;
pub use Utf32;
pub use ;
pub use ;
/// Little-endian UTF-16, regardless of the native byte order.
pub type Utf16Le = ;
/// Big-endian UTF-16, regardless of the native byte order.
pub type Utf16Be = ;
/// Little-endian UTF-32, regardless of the native byte order.
pub type Utf32Le = ;
/// Big-endian UTF-32, regardless of the native byte order.
pub type Utf32Be = ;
pub type Utf16Le = ;
pub type Utf16Be = ;
pub type Utf32Le = ;
pub type Utf32Be = ;