fix: fix multibyte handling
This commit is contained in:
parent
f07ebae7c3
commit
1743406317
24
src/lib.rs
24
src/lib.rs
@ -34,9 +34,9 @@ pub fn layout(text: impl AsRef<str>, width: usize, lang: Lang) -> Vec<String> {
|
||||
let mut last_break_opportunity = 0;
|
||||
for (idx, break_opportunity) in linebreaks(s) {
|
||||
let trimmed = if idx == s.len() {
|
||||
&s[last_break_opportunity..idx]
|
||||
&s[last_break_opportunity..]
|
||||
} else {
|
||||
&s[last_break_opportunity..idx - 1]
|
||||
s[last_break_opportunity..idx].trim_end()
|
||||
};
|
||||
let mut last_word_end = 0;
|
||||
for (start, word) in trimmed.unicode_word_indices() {
|
||||
@ -78,13 +78,19 @@ pub fn layout(text: impl AsRef<str>, width: usize, lang: Lang) -> Vec<String> {
|
||||
data: "",
|
||||
});
|
||||
} else {
|
||||
(s[idx - 1..].chars().next());
|
||||
items.push(Item::Glue {
|
||||
width: 1f32,
|
||||
stretch: 1f32,
|
||||
shrink: 0f32,
|
||||
data: " ",
|
||||
});
|
||||
let first_ws = s[last_break_opportunity..idx]
|
||||
.char_indices()
|
||||
.rev()
|
||||
.take_while(|(_, c)| c.is_whitespace())
|
||||
.last();
|
||||
if let Some((first_ws, _)) = first_ws {
|
||||
items.push(Item::Glue {
|
||||
width: 1f32,
|
||||
stretch: 1f32,
|
||||
shrink: 0f32,
|
||||
data: &s[(last_break_opportunity + first_ws)..idx],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
last_break_opportunity = idx;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user