Skip to content

Commit

Permalink
Add an example of std::str::encode_utf16
Browse files Browse the repository at this point in the history
  • Loading branch information
rwakulszowa committed Sep 12, 2017
1 parent efa3ec6 commit b8e0989
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/liballoc/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,19 @@ impl str {
}

/// Returns an iterator of `u16` over the string encoded as UTF-16.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// let text = "Zażółć gęślą jaźń";
///
/// let utf8_len = text.len();
/// let utf16_len = text.encode_utf16().count();
///
/// assert!(utf16_len <= utf8_len);
/// ```
#[stable(feature = "encode_utf16", since = "1.8.0")]
pub fn encode_utf16(&self) -> EncodeUtf16 {
EncodeUtf16 { encoder: Utf16Encoder::new(self[..].chars()) }
Expand Down

0 comments on commit b8e0989

Please sign in to comment.