-
-
Notifications
You must be signed in to change notification settings - Fork 339
Panic when slice Chinese process name #176
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Each Chinese character has three bytes. So your code in table.rs will cause a panic.
fn truncate_middle(row: &str, max_length: u16) -> String {
if row.len() as u16 > max_length {
let first_slice = &row[0..(max_length as usize / 2) - 2];
let second_slice = &row[(row.len() - (max_length / 2) as usize + 2)..row.len()];
format!("{}[..]{}", first_slice, second_slice)
} else {
row.to_string()
}
}like that:
let s = "中文";
let s = &s[0..2];panicked at 'byte index 2 is not a char boundary; it is inside '中' (bytes 0..3) of 中文
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working