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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//! 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) with double-ended, exact-length iterators, visible cell width
//! ([`width`]), width truncation ([`truncate`]), greedy word wrap ([`wrap`]),
//! and SIMD ANSI/VT stripping in place ([`MakeAnsiStripped`],
//! [`IntoAnsiStripped`]). The [`Text`] extension trait exposes them as
//! methods on `str` and native code-unit slices. Unicode properties come from
//! the generated [`UNICODE_VERSION`] trie (`scripts/gen_props.py`).
//! - **Strict stream decoding** from any [`std::io::BufRead`]
//! ([`BufReadCharsExt`]): batch-decoded `char` iteration in every supported
//! encoding, with errors that carry the offending bytes ([`ReadCharError`]).
//! Drop-in compatible with (and considerably faster than) the `utf8-chars`
//! crate.
//! - **Method-level entry points** for the codec itself: [`Text::transcode`]
//! infers the target encoding from the container it fills ([`TextBuf`]),
//! [`Text::eq_text`] compares across encodings, and [`Encoding::from_bytes`]
//! decodes a BOM-tagged byte stream into that encoding's
//! [`Container`](Encoding::Container).
//!
//! 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 ;
pub use UNICODE_VERSION;
pub use ;
pub use ;
pub use Text;
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 = ;