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

Apply visual run resets to line range. #55

Merged
merged 1 commit into from
Apr 6, 2021
Merged
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
15 changes: 12 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,16 @@ impl<'text> BidiInfo<'text> {
assert!(line.end <= self.levels.len());

let mut levels = self.levels.clone();
let line_classes = &self.original_classes[line.clone()];
let line_levels = &mut levels[line.clone()];

// Reset some whitespace chars to paragraph level.
// <http://www.unicode.org/reports/tr9/#L1>
let line_str: &str = &self.text[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 @@ -395,7 +397,7 @@ impl<'text> BidiInfo<'text> {
if let (Some(from), Some(to)) = (reset_from, reset_to) {
#[cfg_attr(feature = "cargo-clippy", allow(needless_range_loop))]
for j in from..to {
levels[j] = para.level;
line_levels[j] = para.level;
}
reset_from = None;
reset_to = None;
Expand All @@ -404,7 +406,7 @@ impl<'text> BidiInfo<'text> {
if let Some(from) = reset_from {
#[cfg_attr(feature = "cargo-clippy", allow(needless_range_loop))]
for j in from..line_str.len() {
levels[j] = para.level;
line_levels[j] = para.level;
}
}

Expand Down Expand Up @@ -823,6 +825,13 @@ mod tests {
vec![Level::vec(&[0, 0])]
);

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]),
)

/* TODO
/// BidiTest:69635 (AL ET EN)
let text = "\u{060B}\u{20CF}\u{06F9}";
Expand Down