Coverage Report

Created: 2026-02-14 06:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/unicode-bidi-0.3.18/src/deprecated.rs
Line
Count
Source
1
// Copyright 2015 The Servo Project Developers. See the
2
// COPYRIGHT file at the top-level directory of this distribution.
3
//
4
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7
// option. This file may not be copied, modified, or distributed
8
// except according to those terms.
9
10
//! This module holds deprecated assets only.
11
12
use super::*;
13
14
/// Find the level runs within a line and return them in visual order.
15
///
16
/// NOTE: This implementation is incomplete. The algorithm needs information about the text,
17
/// including original `BidiClass` property of each character, to be able to perform correctly.
18
/// Please see [`BidiInfo::visual_runs()`](../struct.BidiInfo.html#method.visual_runs) for the
19
/// improved implementation.
20
///
21
/// `line` is a range of bytes indices within `levels`.
22
///
23
/// <http://www.unicode.org/reports/tr9/#Reordering_Resolved_Levels>
24
#[deprecated(
25
    since = "0.3.0",
26
    note = "please use `BidiInfo::visual_runs()` instead."
27
)]
28
0
pub fn visual_runs(line: Range<usize>, levels: &[Level]) -> Vec<LevelRun> {
29
0
    assert!(line.start <= levels.len());
30
0
    assert!(line.end <= levels.len());
31
32
0
    let mut runs = Vec::new();
33
34
    // Find consecutive level runs.
35
0
    let mut start = line.start;
36
0
    let mut run_level = levels[start];
37
0
    let mut min_level = run_level;
38
0
    let mut max_level = run_level;
39
40
0
    for (i, &new_level) in levels.iter().enumerate().take(line.end).skip(start + 1) {
41
0
        if new_level != run_level {
42
0
            // End of the previous run, start of a new one.
43
0
            runs.push(start..i);
44
0
            start = i;
45
0
            run_level = new_level;
46
0
47
0
            min_level = cmp::min(run_level, min_level);
48
0
            max_level = cmp::max(run_level, max_level);
49
0
        }
50
    }
51
0
    runs.push(start..line.end);
52
53
0
    let run_count = runs.len();
54
55
    // Re-order the odd runs.
56
    // <http://www.unicode.org/reports/tr9/#L2>
57
58
    // Stop at the lowest *odd* level.
59
0
    min_level = min_level.new_lowest_ge_rtl().expect("Level error");
60
61
0
    while max_level >= min_level {
62
        // Look for the start of a sequence of consecutive runs of max_level or higher.
63
0
        let mut seq_start = 0;
64
0
        while seq_start < run_count {
65
0
            if levels[runs[seq_start].start] < max_level {
66
0
                seq_start += 1;
67
0
                continue;
68
0
            }
69
70
            // Found the start of a sequence. Now find the end.
71
0
            let mut seq_end = seq_start + 1;
72
73
0
            while seq_end < run_count && levels[runs[seq_end].start] >= max_level {
74
0
                seq_end += 1;
75
0
            }
76
77
            // Reverse the runs within this sequence.
78
0
            runs[seq_start..seq_end].reverse();
79
80
0
            seq_start = seq_end;
81
        }
82
83
0
        max_level
84
0
            .lower(1)
85
0
            .expect("Lowering embedding level below zero");
86
    }
87
88
0
    runs
89
0
}