aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShivakumar Neginal <shivaneginal@google.com>2023-04-05 09:17:11 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-04-05 09:17:11 +0000
commit3c5d59abebcfb0d15fa96827f6c8458a8650524e (patch)
treec8be7253f288ecf0a50056a27b7cad1c00650a6a
parent6415a5cc2f9154b86cb4c9156e60cd2db86ff950 (diff)
parent90ef16a61a121bd4a9a0995261e2994f9cc3695b (diff)
downloadunicode-bidi-3c5d59abebcfb0d15fa96827f6c8458a8650524e.tar.gz
Revert "Upgrade unicode-bidi to 0.3.13" am: 90ef16a61a
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/unicode-bidi/+/2524735 Change-Id: I88922a9f700395acef06d0aa4c5fbb3b8c32b038 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--.rustfmt.toml1
-rw-r--r--Android.bp26
-rw-r--r--Cargo.toml2
-rw-r--r--Cargo.toml.orig2
-rw-r--r--METADATA8
-rw-r--r--cargo2android.json5
-rw-r--r--src/deprecated.rs4
-rw-r--r--src/level.rs15
-rw-r--r--src/lib.rs87
10 files changed, 54 insertions, 98 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index c19fe9b..67b5a63 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,6 +1,6 @@
{
"git": {
- "sha1": "3b7a02fd6006a0f83c78a3f59405e97dfd75e311"
+ "sha1": "cd1de5d1ddbba789c29b6d69811ef49c820eefd4"
},
"path_in_vcs": ""
} \ No newline at end of file
diff --git a/.rustfmt.toml b/.rustfmt.toml
index e416686..7587a1d 100644
--- a/.rustfmt.toml
+++ b/.rustfmt.toml
@@ -1 +1,2 @@
array_width = 80
+brace_style = "SameLineWhere"
diff --git a/Android.bp b/Android.bp
index 8b9c0c5..86d4b8e 100644
--- a/Android.bp
+++ b/Android.bp
@@ -44,7 +44,7 @@ rust_library {
host_supported: true,
crate_name: "unicode_bidi",
cargo_env_compat: true,
- cargo_pkg_version: "0.3.13",
+ cargo_pkg_version: "0.3.10",
srcs: ["src/lib.rs"],
edition: "2018",
features: [
@@ -60,3 +60,27 @@ rust_library {
vendor_available: true,
min_sdk_version: "29",
}
+
+rust_test {
+ name: "unicode-bidi_test_src_lib",
+ // has rustc warnings
+ host_supported: true,
+ crate_name: "unicode_bidi",
+ cargo_env_compat: true,
+ cargo_pkg_version: "0.3.10",
+ srcs: ["src/lib.rs"],
+ test_suites: ["general-tests"],
+ auto_gen_config: true,
+ test_options: {
+ unit_test: true,
+ },
+ edition: "2018",
+ features: [
+ "default",
+ "hardcoded-data",
+ "std",
+ ],
+ rustlibs: [
+ "libserde_test",
+ ],
+}
diff --git a/Cargo.toml b/Cargo.toml
index 81aee5c..02ea8fa 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,7 +12,7 @@
[package]
edition = "2018"
name = "unicode-bidi"
-version = "0.3.13"
+version = "0.3.10"
authors = ["The Servo Project Developers"]
exclude = [
"benches/**",
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 1343fa4..02bc85b 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
[package]
name = "unicode-bidi"
-version = "0.3.13"
+version = "0.3.10"
authors = ["The Servo Project Developers"]
license = "MIT OR Apache-2.0"
description = "Implementation of the Unicode Bidirectional Algorithm"
diff --git a/METADATA b/METADATA
index e9008d6..2b51f3e 100644
--- a/METADATA
+++ b/METADATA
@@ -11,13 +11,13 @@ third_party {
}
url {
type: ARCHIVE
- value: "https://static.crates.io/crates/unicode-bidi/unicode-bidi-0.3.13.crate"
+ value: "https://static.crates.io/crates/unicode-bidi/unicode-bidi-0.3.10.crate"
}
- version: "0.3.13"
+ version: "0.3.10"
license_type: NOTICE
last_upgrade_date {
year: 2023
- month: 3
- day: 30
+ month: 2
+ day: 6
}
}
diff --git a/cargo2android.json b/cargo2android.json
index da28e2c..911c36f 100644
--- a/cargo2android.json
+++ b/cargo2android.json
@@ -6,5 +6,6 @@
"dependencies": true,
"device": true,
"min-sdk-version": "29",
- "run": true
-}
+ "run": true,
+ "tests": true
+} \ No newline at end of file
diff --git a/src/deprecated.rs b/src/deprecated.rs
index 74a24f5..ec3b84f 100644
--- a/src/deprecated.rs
+++ b/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 = cmp::min(run_level, min_level);
- max_level = cmp::max(run_level, max_level);
+ min_level = min(run_level, min_level);
+ max_level = max(run_level, max_level);
}
}
runs.push(start..line.end);
diff --git a/src/level.rs b/src/level.rs
index ef4f6d9..f2e0d99 100644
--- a/src/level.rs
+++ b/src/level.rs
@@ -16,7 +16,6 @@
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use core::convert::{From, Into};
-use core::slice;
use super::char_data::BidiClass;
@@ -32,7 +31,6 @@ 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);
@@ -196,19 +194,6 @@ 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/src/lib.rs b/src/lib.rs
index 28178bb..81d4fb5 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -65,6 +65,7 @@
//!
//! [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")]
@@ -93,7 +94,7 @@ pub use crate::char_data::{bidi_class, HardcodedBidiData};
use alloc::borrow::Cow;
use alloc::string::String;
use alloc::vec::Vec;
-use core::cmp;
+use core::cmp::{max, min};
use core::iter::repeat;
use core::ops::Range;
@@ -425,14 +426,6 @@ 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;
@@ -450,31 +443,18 @@ 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, 6, 7, 5, 4, 3]);
+ /// assert_eq!(index_map, [0, 1, 2, 5, 4, 3, 6, 7]);
/// ```
pub fn reorder_visual(levels: &[Level]) -> Vec<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> {
+ // Gets the next range
+ fn next_range(levels: &[level::Level], start_index: usize) -> 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 let Some(l) = levels.get(end_index) {
- if *l < max {
+ while end_index < levels.len() {
+ if levels[start_index] != levels[end_index] {
return start_index..end_index;
}
end_index += 1;
@@ -483,50 +463,21 @@ 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();
- 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);
+ let mut range: Range<usize> = 0..0;
+ loop {
+ range = next_range(levels, range.end);
+ if levels[range.start].is_rtl() {
result[range.clone()].reverse();
-
- if range.end >= levels.len() {
- break;
- }
}
- max.lower(1).expect("Level error");
+ if range.end >= levels.len() {
+ break;
+ }
}
result
@@ -613,8 +564,8 @@ impl<'text> BidiInfo<'text> {
runs.push(start..i);
start = i;
run_level = new_level;
- min_level = cmp::min(run_level, min_level);
- max_level = cmp::max(run_level, max_level);
+ min_level = min(run_level, min_level);
+ max_level = max(run_level, max_level);
}
}
runs.push(start..line.end);
@@ -627,12 +578,6 @@ 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;