fn split_at_utf16_code_unit_offset(
    s: &str,
    offset: u32,
    replace_surrogates: bool
) -> Result<(&str, Option<char>, &str), ()>
Expand description

Split the given string at the given position measured in UTF-16 code units from the start.

  • Err(()) indicates that offset if after the end of the string
  • Ok((before, None, after)) indicates that offset is between Unicode code points. The two string slices are such that: before == s.to_utf16()[..offset].to_utf8() and after == s.to_utf16()[offset..].to_utf8()
  • Ok((before, Some(ch), after)) indicates that offset is “in the middle” of a single Unicode code point that would be represented in UTF-16 by a surrogate pair of two 16-bit code units. ch is that code point. The two string slices are such that: before == s.to_utf16()[..offset - 1].to_utf8() and after == s.to_utf16()[offset + 1..].to_utf8()

Panics

Note that the third variant is only ever returned when the -Z replace-surrogates command-line option is specified. When it would be returned but the option is not specified, this function panics.