Function grapheme_widths

Source
pub fn grapheme_widths(s: &str) -> Vec<(&str, usize)>
Expand description

Re-exports: Primary public API Returns the display width of each grapheme cluster in the input string.

This function splits the string into Unicode grapheme clusters and pairs each one with its terminal display width (in columns). This is useful for visually aligned rendering, layout calculation, and Unicode debugging, especially with complex emoji or East Asian characters.

§Arguments

  • s - The input string to analyze

§Returns

A vector of tuples, where each item is a grapheme cluster and its corresponding display width: (&str, usize)

§Example

use runefix_core::grapheme_widths;
 
let result = grapheme_widths("Hi,世界");
assert_eq!(
    result,
    vec![("H", 1), ("i", 1), (",", 2), ("世", 2), ("界", 2)]
);