gameboard 0.1.0

Rust library for creating game board for text UI games.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use unicode_segmentation::UnicodeSegmentation;

pub(crate) const GOTO_SEQUENCE_WIDTH: usize = 16;

pub(crate) fn get_str_range(text: &str, start: usize, end: usize) -> &str {
    let mut iter = UnicodeSegmentation::grapheme_indices(text, true);
    let (s, _) = iter.nth(start).expect("Invalid string range index.");
    match iter.nth(end - start - 1) {
        Some((e, _)) => &text[s as usize..e as usize],
        None => &text[s as usize..]
    }
}

pub(crate) fn get_str_len(text: &str) -> usize {
    UnicodeSegmentation::graphemes(text, true).count()
}