]>
git.proxmox.com Git - cargo.git/blob - vendor/unicode-bidi/src/deprecated.rs
1 // Copyright 2015 The Servo Project Developers. See the
2 // COPYRIGHT file at the top-level directory of this distribution.
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.
10 //! This module holds deprecated assets only.
12 // Doesn't worth updating API here
13 #![cfg_attr(feature="cargo-clippy", allow(needless_pass_by_value))]
17 /// Find the level runs within a line and return them in visual order.
19 /// NOTE: This implementation is incomplete. The algorithm needs information about the text,
20 /// including original `BidiClass` property of each character, to be able to perform correctly.
21 /// Please see [`BidiInfo::visual_runs()`](../struct.BidiInfo.html#method.visual_runs) for the
22 /// improved implementation.
24 /// `line` is a range of bytes indices within `levels`.
26 /// <http://www.unicode.org/reports/tr9/#Reordering_Resolved_Levels>
27 #[deprecated(since = "0.3.0", note = "please use `BidiInfo::visual_runs()` instead.")]
28 pub fn visual_runs(line
: Range
<usize>, levels
: &[Level
]) -> Vec
<LevelRun
> {
29 assert
!(line
.start
<= levels
.len());
30 assert
!(line
.end
<= levels
.len());
32 let mut runs
= Vec
::new();
34 // Find consecutive level runs.
35 let mut start
= line
.start
;
36 let mut run_level
= levels
[start
];
37 let mut min_level
= run_level
;
38 let mut max_level
= run_level
;
40 for (i
, &new_level
) in levels
.iter().enumerate().take(line
.end
).skip(start
+ 1) {
41 if new_level
!= run_level
{
42 // End of the previous run, start of a new one.
45 run_level
= new_level
;
47 min_level
= min(run_level
, min_level
);
48 max_level
= max(run_level
, max_level
);
51 runs
.push(start
..line
.end
);
53 let run_count
= runs
.len();
55 // Re-order the odd runs.
56 // <http://www.unicode.org/reports/tr9/#L2>
58 // Stop at the lowest *odd* level.
59 min_level
= min_level
.new_lowest_ge_rtl().expect("Level error");
61 while max_level
>= min_level
{
62 // Look for the start of a sequence of consecutive runs of max_level or higher.
63 let mut seq_start
= 0;
64 while seq_start
< run_count
{
65 if levels
[runs
[seq_start
].start
] < max_level
{
70 // Found the start of a sequence. Now find the end.
71 let mut seq_end
= seq_start
+ 1;
72 while seq_end
< run_count
{
73 if levels
[runs
[seq_end
].start
] < max_level
{
79 // Reverse the runs within this sequence.
80 runs
[seq_start
..seq_end
].reverse();
84 max_level
.lower(1).expect(
85 "Lowering embedding level below zero",