Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] split_long_word incorrectly splits multi-codepoint character #168

Open
uasi opened this issue Jan 17, 2025 · 1 comment · May be fixed by #170
Open

[Bug] split_long_word incorrectly splits multi-codepoint character #168

uasi opened this issue Jan 17, 2025 · 1 comment · May be fixed by #170
Labels
t: bug Something isn't working

Comments

@uasi
Copy link

uasi commented Jan 17, 2025

Describe the bug

split_long_word() may split multi-codepoint characters, such as â (a + ◌̂ in NFD) and 🇺🇳, in the middle.

Steps to reproduce

use comfy_table::utils::formatting::content_split::split_long_word;
use unicode_width::UnicodeWidthStr;

fn main() {
    let emoji = "🙂‍↕️"; // U+1F642 U+200D U+2195 U+FE0F head shaking vertically
    assert_eq!(emoji.len(), 13);
    assert_eq!(emoji.chars().count(), 4);
    assert_eq!(emoji.width(), 2);

    let (word, remaining) = split_long_word(emoji.width(), &emoji);

    println!("{word}");
    assert_eq!(word, "\u{1F642}\u{200D}");
    assert_eq!(word.len(), 7);
    assert_eq!(word.chars().count(), 2);
    assert_eq!(word.width(), 2);

    println!("{remaining}");
    assert_eq!(remaining, "\u{2195}\u{FE0F}");
    assert_eq!(remaining.len(), 6);
    assert_eq!(remaining.chars().count(), 2);
    assert_eq!(remaining.width(), 2);
}
Image

Logs (if applicable)

No response

Operating system

macOS 15.2

Comfy-table version

v7.1.3

Additional context

No response

@tisonkun
Copy link
Contributor

unicode-rs provides a library to handle clusterng - https://github.com/unicode-rs/unicode-segmentation

Maybe we can see if it helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants