pub fn slice_at_char_boundaries(
s: &str,
start_byte_index: usize,
end_byte_index: usize,
) -> &str
Expand description
Returns a slice of the given string that starts and ends at character boundaries.
If the given start index is greater than the end index, or if either index is out of bounds, an empty string is returned.
ยงExamples
use television_utils::strings::slice_at_char_boundaries;
let s = "Hello, World!";
assert_eq!(slice_at_char_boundaries(s, 0, 0), "");
assert_eq!(slice_at_char_boundaries(s, 0, 1), "H");
let s = "๐๐!";
assert_eq!(slice_at_char_boundaries(s, 0, 0), "");
assert_eq!(slice_at_char_boundaries(s, 0, 2), "๐");
assert_eq!(slice_at_char_boundaries(s, 0, 5), "๐๐");