television_utils::strings

Function prev_char_boundary

Source
pub fn prev_char_boundary(s: &str, start: usize) -> usize
Expand description

Returns the index of the previous character boundary in the given string.

If the given index is already a character boundary, it is returned as is. If the given index is out of bounds, 0 is returned.

ยงExamples

use television_utils::strings::prev_char_boundary;

let s = "Hello, World!";
assert_eq!(prev_char_boundary(s, 0), 0);
assert_eq!(prev_char_boundary(s, 1), 1);
assert_eq!(prev_char_boundary(s, 5), 5);

let s = "๐Ÿ‘‹๐ŸŒ!";
assert_eq!(prev_char_boundary(s, 0), 0);
assert_eq!(prev_char_boundary(s, 4), 4);
assert_eq!(prev_char_boundary(s, 6), 4);