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

Fix indexing within lines in BidiInfo::visual_runs #278

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions unic/bidi/src/bidi_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,12 @@ impl<'text> BidiInfo<'text> {
// Reset some whitespace chars to paragraph level.
// <https://www.unicode.org/reports/tr9/#L1>
let line_str: &str = &self.text[line.clone()];
let line_classes = &self.original_classes[line.clone()];
let line_levels = &mut levels[line.clone()];
let mut reset_from: Option<usize> = Some(0);
let mut reset_to: Option<usize> = None;
for (i, c) in line_str.char_indices() {
match self.original_classes[i] {
match line_classes[i] {
// Ignored by X9
RLE | LRE | RLO | LRO | PDF | BN => {}
// Segment separator, Paragraph separator
Expand All @@ -318,15 +320,15 @@ impl<'text> BidiInfo<'text> {
}
if let (Some(from), Some(to)) = (reset_from, reset_to) {
for j in from..to {
levels[j] = para.level;
line_levels[j] = para.level;
}
reset_from = None;
reset_to = None;
}
}
if let Some(from) = reset_from {
for j in from..line_str.len() {
levels[j] = para.level;
line_levels[j] = para.level;
}
}

Expand Down Expand Up @@ -751,6 +753,16 @@ mod tests {
"2 paragraphs with a maximum bidirectional level of 1"
);
}

#[test]
fn test_reordered_levels_line() {
let text = "aa טֶ";
let bidi_info = BidiInfo::new(text, None);
assert_eq!(
bidi_info.reordered_levels(&bidi_info.paragraphs[0], 3..7),
Level::vec(&[0, 0, 0, 1, 1, 1, 1]),
);
}
}

#[cfg(all(feature = "serde", test))]
Expand Down