offset-vec 0.3.6

Packer for Vec and String etc, for all methods index add a offset
Documentation
pub(crate) fn transform_char_index(s: &str, byte_index: usize) -> usize {
    debug_assert!(s.is_char_boundary(byte_index),
                 "{s:?} <- {byte_index} is not on char boundary");
    s.char_indices()
        .take_while(|&(i, _)| i < byte_index)
        .count()
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn trst_transform_char_index() {
        let datas = [
            ("", 0, 0),
            ("a", 0, 0),
            ("a", 1, 1),
            ("", 0, 0),
            ("", 3, 1),
            ("你好", 3, 1),
            ("你好", 6, 2),
        ];

        for (s, bi, ci) in datas {
            assert_eq!(transform_char_index(s, bi), ci, "{s:?}, {bi}, {ci}");
        }
    }
}