pub struct Utf16LeStr<'a> { /* private fields */ }Expand description
Borrowed UTF-16LE string data.
This is a zero-copy view into an underlying byte buffer (typically an MFT entry buffer). The bytes are interpreted as UTF-16LE code units.
Notes:
- The view is not required to be valid UTF-16. Lone surrogates are dropped when converting
to UTF-8 (WTF-16 style), matching
utf16-simd’s semantics. - This type is intentionally optimized for “decode only at output time” use-cases.
Implementations§
Source§impl<'a> Utf16LeStr<'a>
impl<'a> Utf16LeStr<'a>
Sourcepub fn from_utf16le_bytes(utf16le: &'a [u8]) -> Self
pub fn from_utf16le_bytes(utf16le: &'a [u8]) -> Self
Construct a borrowed UTF-16LE string from bytes.
The slice length should be a multiple of 2. If it’s not, the trailing odd byte is ignored.
Sourcepub fn from_utf16le_bytes_until_nul(utf16le: &'a [u8]) -> Self
pub fn from_utf16le_bytes_until_nul(utf16le: &'a [u8]) -> Self
Construct a borrowed UTF-16LE string from bytes, truncating at the first UTF-16 NUL
(0x0000) code unit, if present.
pub fn empty() -> Self
pub fn is_empty(&self) -> bool
pub fn as_utf16le_bytes(&self) -> &'a [u8] ⓘ
pub fn len_units(&self) -> usize
Sourcepub fn with_utf8<R>(&self, f: impl FnOnce(&str) -> R) -> R
pub fn with_utf8<R>(&self, f: impl FnOnce(&str) -> R) -> R
Execute f with a temporary UTF-8 view of this string.
This does not allocate per call (it reuses a thread-local scratch buffer), but callers
must not try to re-enter Utf16LeStr conversion APIs from inside f.
Sourcepub fn to_utf8_string(&self) -> String
pub fn to_utf8_string(&self) -> String
Allocate a UTF-8 String for this UTF-16LE data.
Sourcepub fn eq_utf8(&self, other: &str) -> bool
pub fn eq_utf8(&self, other: &str) -> bool
Compare this UTF-16LE string to a UTF-8 &str without allocating.
Fast path: if other is ASCII, compare directly against UTF-16LE bytes by requiring
hi == 0 for each code unit.
Sourcepub fn eq_ignore_ascii_case(&self, other: &str) -> bool
pub fn eq_ignore_ascii_case(&self, other: &str) -> bool
ASCII-only case-insensitive equality against a UTF-8 &str, without allocating.
Fast path: if other is ASCII, compare directly against UTF-16LE bytes by requiring
hi == 0 for each code unit and using to_ascii_lowercase() on the low byte.