1
Fork 0

Rollup merge of #136283 - hkBst:patch-31, r=workingjubilee

Update encode_utf16 to mention it is native endian

Fixes #83102
This commit is contained in:
Matthias Krüger 2025-02-02 18:05:22 +01:00 committed by GitHub
commit 198384c8cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 12 deletions

View file

@ -712,8 +712,8 @@ impl String {
} }
} }
/// Decode a UTF-16encoded vector `v` into a `String`, returning [`Err`] /// Decode a native endian UTF-16encoded vector `v` into a `String`,
/// if `v` contains any invalid data. /// returning [`Err`] if `v` contains any invalid data.
/// ///
/// # Examples /// # Examples
/// ///
@ -745,8 +745,8 @@ impl String {
Ok(ret) Ok(ret)
} }
/// Decode a UTF-16encoded slice `v` into a `String`, replacing /// Decode a native endian UTF-16encoded slice `v` into a `String`,
/// invalid data with [the replacement character (`U+FFFD`)][U+FFFD]. /// replacing invalid data with [the replacement character (`U+FFFD`)][U+FFFD].
/// ///
/// Unlike [`from_utf8_lossy`] which returns a [`Cow<'a, str>`], /// Unlike [`from_utf8_lossy`] which returns a [`Cow<'a, str>`],
/// `from_utf16_lossy` returns a `String` since the UTF-16 to UTF-8 /// `from_utf16_lossy` returns a `String` since the UTF-16 to UTF-8
@ -777,8 +777,8 @@ impl String {
.collect() .collect()
} }
/// Decode a UTF-16LEencoded vector `v` into a `String`, returning [`Err`] /// Decode a UTF-16LEencoded vector `v` into a `String`,
/// if `v` contains any invalid data. /// returning [`Err`] if `v` contains any invalid data.
/// ///
/// # Examples /// # Examples
/// ///
@ -852,8 +852,8 @@ impl String {
} }
} }
/// Decode a UTF-16BEencoded vector `v` into a `String`, returning [`Err`] /// Decode a UTF-16BEencoded vector `v` into a `String`,
/// if `v` contains any invalid data. /// returning [`Err`] if `v` contains any invalid data.
/// ///
/// # Examples /// # Examples
/// ///

View file

@ -92,7 +92,7 @@ impl char {
#[stable(feature = "assoc_char_consts", since = "1.52.0")] #[stable(feature = "assoc_char_consts", since = "1.52.0")]
pub const UNICODE_VERSION: (u8, u8, u8) = crate::unicode::UNICODE_VERSION; pub const UNICODE_VERSION: (u8, u8, u8) = crate::unicode::UNICODE_VERSION;
/// Creates an iterator over the UTF-16 encoded code points in `iter`, /// Creates an iterator over the native endian UTF-16 encoded code points in `iter`,
/// returning unpaired surrogates as `Err`s. /// returning unpaired surrogates as `Err`s.
/// ///
/// # Examples /// # Examples
@ -704,7 +704,7 @@ impl char {
unsafe { from_utf8_unchecked_mut(encode_utf8_raw(self as u32, dst)) } unsafe { from_utf8_unchecked_mut(encode_utf8_raw(self as u32, dst)) }
} }
/// Encodes this character as UTF-16 into the provided `u16` buffer, /// Encodes this character as native endian UTF-16 into the provided `u16` buffer,
/// and then returns the subslice of the buffer that contains the encoded character. /// and then returns the subslice of the buffer that contains the encoded character.
/// ///
/// # Panics /// # Panics
@ -1828,7 +1828,7 @@ pub const fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> &mut [u8] {
unsafe { slice::from_raw_parts_mut(dst.as_mut_ptr(), len) } unsafe { slice::from_raw_parts_mut(dst.as_mut_ptr(), len) }
} }
/// Encodes a raw `u32` value as UTF-16 into the provided `u16` buffer, /// Encodes a raw `u32` value as native endian UTF-16 into the provided `u16` buffer,
/// and then returns the subslice of the buffer that contains the encoded character. /// and then returns the subslice of the buffer that contains the encoded character.
/// ///
/// Unlike `char::encode_utf16`, this method also handles codepoints in the surrogate range. /// Unlike `char::encode_utf16`, this method also handles codepoints in the surrogate range.

View file

@ -1108,7 +1108,8 @@ impl str {
LinesAny(self.lines()) LinesAny(self.lines())
} }
/// Returns an iterator of `u16` over the string encoded as UTF-16. /// Returns an iterator of `u16` over the string encoded
/// as native endian UTF-16 (without byte-order mark).
/// ///
/// # Examples /// # Examples
/// ///