summaryrefslogtreecommitdiffstats
path: root/vendor/unicode-bidi
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/unicode-bidi
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/unicode-bidi')
-rw-r--r--vendor/unicode-bidi/.cargo-checksum.json2
-rw-r--r--vendor/unicode-bidi/Cargo.toml2
-rw-r--r--vendor/unicode-bidi/src/deprecated.rs4
-rw-r--r--vendor/unicode-bidi/src/level.rs15
-rw-r--r--vendor/unicode-bidi/src/lib.rs87
5 files changed, 90 insertions, 20 deletions
diff --git a/vendor/unicode-bidi/.cargo-checksum.json b/vendor/unicode-bidi/.cargo-checksum.json
index ab0bb707a..5a4e0d965 100644
--- a/vendor/unicode-bidi/.cargo-checksum.json
+++ b/vendor/unicode-bidi/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{"AUTHORS":"1ff3a7c8519b29544bb28ba9b1e7502df0cb764051fb9a1172e60006aa2b8dcc","COPYRIGHT":"edb20b474f6cbd4f4db066b54a9e0f687d0009d309412a63431189b59b8e2a07","Cargo.toml":"bac3b9c34e93bfab34060c48f493cd82eece9ae99d9b1c98df1d875a8266bfff","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"7b63ecd5f1902af1b63729947373683c32745c16a10e8e6292e2e2dcd7e90ae0","README.md":"81d3dc6d894a68894d982760b0a907f9dcbb0da179a8063ed9de1d2257518957","src/char_data/mod.rs":"0622df8ce4b4de60aea7e4787635d3187f79f7a3f9001e3d209f58fd07d03887","src/char_data/tables.rs":"50faf4eef73c831a38b735309ff3415e9f65992a0474ff5c055138f91c91ee16","src/data_source.rs":"36fa0785e51c549c1f72f09040cfe515b848d1b23fb30d469770a6b4b17b49df","src/deprecated.rs":"3c8b465b827a487df7945cb928e1eae98f9929b71c4d0c99511a470704455a8c","src/explicit.rs":"53428d618aef86c6790d195eb9477f09decc396772581427241d34139f886517","src/format_chars.rs":"678399fec3f4bfaf4093f38cfdb8956288313386dc3511dab9fb58164e8dc01b","src/implicit.rs":"454f35f0803ae7d1d7fdb2d1fb0cd675dd83c5dd92a8d31445847a5a2a16b6bf","src/level.rs":"9bf4943fe3f6c134640e37acbf1bfcaf8b074739c7625736823bf0bc185e1e0d","src/lib.rs":"33830f404ebdf3a0561c415ed3f0e5d8739e749db27f21f9e2644031afa511fa","src/prepare.rs":"7aa46ba8d0448a34be704cc3a1f49bc52ddfce62fa66af65618c2ac94cb88a4e"},"package":"d54675592c1dbefd78cbd98db9bacd89886e1ca50692a0692baefffdeb92dd58"} \ No newline at end of file
+{"files":{"AUTHORS":"1ff3a7c8519b29544bb28ba9b1e7502df0cb764051fb9a1172e60006aa2b8dcc","COPYRIGHT":"edb20b474f6cbd4f4db066b54a9e0f687d0009d309412a63431189b59b8e2a07","Cargo.toml":"6abc8483d33ece6e5f450e7bbce8110a2bc7c1eca7e34858aac7d5ccd3d6b0bb","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"7b63ecd5f1902af1b63729947373683c32745c16a10e8e6292e2e2dcd7e90ae0","README.md":"81d3dc6d894a68894d982760b0a907f9dcbb0da179a8063ed9de1d2257518957","src/char_data/mod.rs":"0622df8ce4b4de60aea7e4787635d3187f79f7a3f9001e3d209f58fd07d03887","src/char_data/tables.rs":"50faf4eef73c831a38b735309ff3415e9f65992a0474ff5c055138f91c91ee16","src/data_source.rs":"36fa0785e51c549c1f72f09040cfe515b848d1b23fb30d469770a6b4b17b49df","src/deprecated.rs":"46c5a8bb1e6aa6193eec8269891d4cbbb5fd92214eb55eac7ea5e7ca193386aa","src/explicit.rs":"53428d618aef86c6790d195eb9477f09decc396772581427241d34139f886517","src/format_chars.rs":"678399fec3f4bfaf4093f38cfdb8956288313386dc3511dab9fb58164e8dc01b","src/implicit.rs":"454f35f0803ae7d1d7fdb2d1fb0cd675dd83c5dd92a8d31445847a5a2a16b6bf","src/level.rs":"921fb7b8960f6cc703a51936075302db513927b8c5d5d760536b6ff70ddab0dd","src/lib.rs":"9e1d78e80264c9ef85aa9300eb52e5b08766584913895fa7df1f01f2cbf565c8","src/prepare.rs":"7aa46ba8d0448a34be704cc3a1f49bc52ddfce62fa66af65618c2ac94cb88a4e"},"package":"92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460"} \ No newline at end of file
diff --git a/vendor/unicode-bidi/Cargo.toml b/vendor/unicode-bidi/Cargo.toml
index 02ea8fabf..81aee5c08 100644
--- a/vendor/unicode-bidi/Cargo.toml
+++ b/vendor/unicode-bidi/Cargo.toml
@@ -12,7 +12,7 @@
[package]
edition = "2018"
name = "unicode-bidi"
-version = "0.3.10"
+version = "0.3.13"
authors = ["The Servo Project Developers"]
exclude = [
"benches/**",
diff --git a/vendor/unicode-bidi/src/deprecated.rs b/vendor/unicode-bidi/src/deprecated.rs
index ec3b84f67..74a24f5b8 100644
--- a/vendor/unicode-bidi/src/deprecated.rs
+++ b/vendor/unicode-bidi/src/deprecated.rs
@@ -46,8 +46,8 @@ pub fn visual_runs(line: Range<usize>, levels: &[Level]) -> Vec<LevelRun> {
start = i;
run_level = new_level;
- min_level = min(run_level, min_level);
- max_level = max(run_level, max_level);
+ min_level = cmp::min(run_level, min_level);
+ max_level = cmp::max(run_level, max_level);
}
}
runs.push(start..line.end);
diff --git a/vendor/unicode-bidi/src/level.rs b/vendor/unicode-bidi/src/level.rs
index f2e0d99ab..ef4f6d9e4 100644
--- a/vendor/unicode-bidi/src/level.rs
+++ b/vendor/unicode-bidi/src/level.rs
@@ -16,6 +16,7 @@
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use core::convert::{From, Into};
+use core::slice;
use super::char_data::BidiClass;
@@ -31,6 +32,7 @@ use super::char_data::BidiClass;
/// <http://www.unicode.org/reports/tr9/#BD2>
#[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
+#[repr(transparent)]
pub struct Level(u8);
pub const LTR_LEVEL: Level = Level(0);
@@ -194,6 +196,19 @@ impl Level {
pub fn vec(v: &[u8]) -> Vec<Level> {
v.iter().map(|&x| x.into()).collect()
}
+
+ /// Converts a byte slice to a slice of Levels
+ ///
+ /// Does _not_ check if each level is within bounds (`<=` [`MAX_IMPLICIT_DEPTH`]),
+ /// which is not a requirement for safety but is a requirement for correctness of the algorithm.
+ pub fn from_slice_unchecked(v: &[u8]) -> &[Level] {
+ debug_assert_eq!(core::mem::size_of::<u8>(), core::mem::size_of::<Level>());
+ unsafe {
+ // Safety: The two arrays are the same size and layout-compatible since
+ // Level is `repr(transparent)` over `u8`
+ slice::from_raw_parts(v as *const [u8] as *const u8 as *const Level, v.len())
+ }
+ }
}
/// If levels has any RTL (odd) level
diff --git a/vendor/unicode-bidi/src/lib.rs b/vendor/unicode-bidi/src/lib.rs
index 81d4fb5f5..28178bb51 100644
--- a/vendor/unicode-bidi/src/lib.rs
+++ b/vendor/unicode-bidi/src/lib.rs
@@ -65,7 +65,6 @@
//!
//! [tr9]: <http://www.unicode.org/reports/tr9/>
-#![forbid(unsafe_code)]
#![no_std]
// We need to link to std to make doc tests work on older Rust versions
#[cfg(feature = "std")]
@@ -94,7 +93,7 @@ pub use crate::char_data::{bidi_class, HardcodedBidiData};
use alloc::borrow::Cow;
use alloc::string::String;
use alloc::vec::Vec;
-use core::cmp::{max, min};
+use core::cmp;
use core::iter::repeat;
use core::ops::Range;
@@ -426,6 +425,14 @@ impl<'text> BidiInfo<'text> {
///
/// the index map will result in `indexMap[visualIndex]==logicalIndex`.
///
+ /// This only runs [Rule L2](http://www.unicode.org/reports/tr9/#L2) as it does not have
+ /// information about the actual text.
+ ///
+ /// Furthermore, if `levels` is an array that is aligned with code units, bytes within a codepoint may be
+ /// reversed. You may need to fix up the map to deal with this. Alternatively, only pass in arrays where each `Level`
+ /// is for a single code point.
+ ///
+ ///
/// # # Example
/// ```
/// use unicode_bidi::BidiInfo;
@@ -443,18 +450,31 @@ impl<'text> BidiInfo<'text> {
/// let levels: Vec<Level> = vec![l0, l0, l0, l1, l1, l1, l2, l2];
/// let index_map = BidiInfo::reorder_visual(&levels);
/// assert_eq!(levels.len(), index_map.len());
- /// assert_eq!(index_map, [0, 1, 2, 5, 4, 3, 6, 7]);
+ /// assert_eq!(index_map, [0, 1, 2, 6, 7, 5, 4, 3]);
/// ```
pub fn reorder_visual(levels: &[Level]) -> Vec<usize> {
- // Gets the next range
- fn next_range(levels: &[level::Level], start_index: usize) -> Range<usize> {
+ // Gets the next range of characters after start_index with a level greater
+ // than or equal to `max`
+ fn next_range(levels: &[level::Level], mut start_index: usize, max: Level) -> Range<usize> {
if levels.is_empty() || start_index >= levels.len() {
return start_index..start_index;
}
+ while let Some(l) = levels.get(start_index) {
+ if *l >= max {
+ break;
+ }
+ start_index += 1;
+ }
+
+ if levels.get(start_index).is_none() {
+ // If at the end of the array, adding one will
+ // produce an out-of-range end element
+ return start_index..start_index;
+ }
let mut end_index = start_index + 1;
- while end_index < levels.len() {
- if levels[start_index] != levels[end_index] {
+ while let Some(l) = levels.get(end_index) {
+ if *l < max {
return start_index..end_index;
}
end_index += 1;
@@ -463,21 +483,50 @@ impl<'text> BidiInfo<'text> {
start_index..end_index
}
+ // This implementation is similar to the L2 implementation in `visual_runs()`
+ // but it cannot benefit from a precalculated LevelRun vector so needs to be different.
+
if levels.is_empty() {
return vec![];
}
+
+ // Get the min and max levels
+ let (mut min, mut max) = levels
+ .iter()
+ .fold((levels[0], levels[0]), |(min, max), &l| {
+ (cmp::min(min, l), cmp::max(max, l))
+ });
+
+ // Initialize an index map
let mut result: Vec<usize> = (0..levels.len()).collect();
- let mut range: Range<usize> = 0..0;
- loop {
- range = next_range(levels, range.end);
- if levels[range.start].is_rtl() {
+ if min == max && min.is_ltr() {
+ // Everything is LTR and at the same level, do nothing
+ return result;
+ }
+
+ // Stop at the lowest *odd* level, since everything below that
+ // is LTR and does not need further reordering
+ min = min.new_lowest_ge_rtl().expect("Level error");
+
+ // For each max level, take all contiguous chunks of
+ // levels ≥ max and reverse them
+ //
+ // We can do this check with the original levels instead of checking reorderings because all
+ // prior reorderings will have been for contiguous chunks of levels >> max, which will
+ // be a subset of these chunks anyway.
+ while min <= max {
+ let mut range = 0..0;
+ loop {
+ range = next_range(levels, range.end, max);
result[range.clone()].reverse();
- }
- if range.end >= levels.len() {
- break;
+ if range.end >= levels.len() {
+ break;
+ }
}
+
+ max.lower(1).expect("Level error");
}
result
@@ -564,8 +613,8 @@ impl<'text> BidiInfo<'text> {
runs.push(start..i);
start = i;
run_level = new_level;
- min_level = min(run_level, min_level);
- max_level = max(run_level, max_level);
+ min_level = cmp::min(run_level, min_level);
+ max_level = cmp::max(run_level, max_level);
}
}
runs.push(start..line.end);
@@ -578,6 +627,12 @@ impl<'text> BidiInfo<'text> {
// Stop at the lowest *odd* level.
min_level = min_level.new_lowest_ge_rtl().expect("Level error");
+ // This loop goes through contiguous chunks of level runs that have a level
+ // ≥ max_level and reverses their contents, reducing max_level by 1 each time.
+ //
+ // It can do this check with the original levels instead of checking reorderings because all
+ // prior reorderings will have been for contiguous chunks of levels >> max, which will
+ // be a subset of these chunks anyway.
while max_level >= min_level {
// Look for the start of a sequence of consecutive runs of max_level or higher.
let mut seq_start = 0;