diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-05-11 05:07:32 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-05-11 05:07:32 +0000 |
commit | 6e625bd790814ed885fe663fb89758650c9299fc (patch) | |
tree | a1afe3b3cb6a1d4d7a42915fea2419272d51fa23 | |
parent | 87076c3b5a518f87e132b59a5fd1309051aab57b (diff) | |
parent | f517c46dbb314e55c044d264212aac8e53a9f3f4 (diff) | |
download | unicode-bidi-android13-mainline-scheduling-release.tar.gz |
Snap for 8570526 from f517c46dbb314e55c044d264212aac8e53a9f3f4 to mainline-scheduling-releaseaml_sch_331113000aml_sch_331111000android13-mainline-scheduling-release
Change-Id: Ic14d17d91791ff7f3c54aa022607010ecb208057
-rw-r--r-- | .cargo_vcs_info.json | 5 | ||||
-rw-r--r-- | .github/workflows/main.yml | 36 | ||||
-rw-r--r-- | .travis.yml | 38 | ||||
-rw-r--r-- | Android.bp | 48 | ||||
-rw-r--r-- | Cargo.toml | 36 | ||||
-rw-r--r-- | Cargo.toml.orig | 27 | ||||
-rw-r--r-- | METADATA | 10 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | TEST_MAPPING | 23 | ||||
-rw-r--r-- | src/char_data/mod.rs | 6 | ||||
-rw-r--r-- | src/deprecated.rs | 3 | ||||
-rw-r--r-- | src/explicit.rs | 13 | ||||
-rw-r--r-- | src/implicit.rs | 18 | ||||
-rw-r--r-- | src/level.rs | 9 | ||||
-rw-r--r-- | src/lib.rs | 106 | ||||
-rw-r--r-- | src/prepare.rs | 24 |
16 files changed, 224 insertions, 180 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json new file mode 100644 index 0000000..8b4acfd --- /dev/null +++ b/.cargo_vcs_info.json @@ -0,0 +1,5 @@ +{ + "git": { + "sha1": "121c26b55190e14cac4b56fea02bb1e4420c4c00" + } +} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..419cc67 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,36 @@ +name: CI + +on: + push: + branches: ['master'] + pull_request: + +jobs: + Test: + strategy: + matrix: + os: [ubuntu-latest] + rust: [1.36.0, stable, beta, nightly] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.rust }} + override: true + - uses: actions-rs/cargo@v1 + with: + command: build + args: --all-targets + - uses: actions-rs/cargo@v1 + with: + command: test + - uses: actions-rs/cargo@v1 + with: + command: test + args: --features "serde" + - uses: actions-rs/cargo@v1 + with: + command: test + args: --no-default-features diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 76a90be..0000000 --- a/.travis.yml +++ /dev/null @@ -1,38 +0,0 @@ -language: rust -sudo: false -os: linux -dist: trusty - -rust: - - nightly - - beta - - stable - - 1.17.0 - -matrix: - fast_finish: true - allow_failures: - - rust: nightly - -notifications: - webhooks: http://build.servo.org:54856/travis - email: - on_success: never - -env: - global: - - RUST_BACKTRACE=full - -script: - - cargo build --verbose - - cargo doc --verbose --no-deps - - - cargo test --verbose - - cargo test --verbose --features 'serde' - - cargo test --verbose --features 'with_serde' - - - test "$TRAVIS_RUST_VERSION" != "nightly" || - cargo bench --verbose --features 'bench_it' - - - test "$TRAVIS_RUST_VERSION" != "nightly" || - cargo run --verbose --features 'flame_it' --example 'flame_udhr' @@ -40,14 +40,15 @@ license { rust_library { name: "libunicode_bidi", - // has rustc warnings host_supported: true, crate_name: "unicode_bidi", + cargo_env_compat: true, + cargo_pkg_version: "0.3.7", srcs: ["src/lib.rs"], - edition: "2015", - features: ["default"], - rustlibs: [ - "libmatches", + edition: "2018", + features: [ + "default", + "std", ], apex_available: [ "//apex_available:platform", @@ -56,35 +57,24 @@ rust_library { min_sdk_version: "29", } -rust_defaults { - name: "unicode-bidi_defaults", +rust_test { + name: "unicode-bidi_test_src_lib", + host_supported: true, crate_name: "unicode_bidi", - // has rustc warnings + cargo_env_compat: true, + cargo_pkg_version: "0.3.7", srcs: ["src/lib.rs"], test_suites: ["general-tests"], auto_gen_config: true, - edition: "2015", - features: ["default"], - rustlibs: [ - "libmatches", - "libserde_test", - ], -} - -rust_test_host { - name: "unicode-bidi_host_test_src_lib", - defaults: ["unicode-bidi_defaults"], test_options: { unit_test: true, }, + edition: "2018", + features: [ + "default", + "std", + ], + rustlibs: [ + "libserde_test", + ], } - -rust_test { - name: "unicode-bidi_device_test_src_lib", - defaults: ["unicode-bidi_defaults"], -} - -// dependent_library ["feature_list"] -// matches-0.1.8 -// serde-1.0.125 "default,std" -// serde_test-1.0.125 @@ -3,47 +3,53 @@ # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies -# to registry (e.g. crates.io) dependencies +# to registry (e.g., crates.io) dependencies. # -# If you believe there's an error in this file please file an -# issue against the rust-lang/cargo repository. If you're -# editing this file be aware that the upstream Cargo.toml -# will likely look very different (and much more reasonable) +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. [package] +edition = "2018" name = "unicode-bidi" -version = "0.3.4" +version = "0.3.7" authors = ["The Servo Project Developers"] exclude = ["benches/**", "data/**", "examples/**", "tests/**", "tools/**"] description = "Implementation of the Unicode Bidirectional Algorithm" -documentation = "http://doc.servo.org/unicode_bidi/" +documentation = "https://docs.rs/unicode-bidi/" +readme = "README.md" keywords = ["rtl", "unicode", "text", "layout", "bidi"] +categories = ["no-std", "encoding", "text-processing"] license = "MIT / Apache-2.0" repository = "https://github.com/servo/unicode-bidi" [lib] name = "unicode_bidi" [dependencies.flame] -version = "0.1" +version = "0.2" optional = true [dependencies.flamer] -version = "0.1" +version = "0.4" optional = true [dependencies.serde] version = ">=0.8, <2.0" features = ["derive"] optional = true - -[dependencies.matches] -version = "0.1" +default-features = false [dev-dependencies.serde_test] version = ">=0.8, <2.0" [features] -with_serde = ["serde"] +bench_it = [] +default = ["std"] flame_it = ["flame", "flamer"] +std = [] unstable = [] -default = [] -bench_it = [] +with_serde = ["serde"] +[badges.appveyor] +repository = "servo/unicode-bidi" + +[badges.travis-ci] +repository = "servo/unicode-bidi" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index abfcaac..812c27c 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,12 +1,19 @@ [package] name = "unicode-bidi" -version = "0.3.4" +version = "0.3.7" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" description = "Implementation of the Unicode Bidirectional Algorithm" repository = "https://github.com/servo/unicode-bidi" -documentation = "http://doc.servo.org/unicode_bidi/" +documentation = "https://docs.rs/unicode-bidi/" keywords = ["rtl", "unicode", "text", "layout", "bidi"] +readme="README.md" +edition = "2018" +categories = [ + "no-std", + "encoding", + "text-processing", +] # No data is shipped; benches, examples and tests also depend on data. exclude = [ @@ -17,20 +24,26 @@ exclude = [ "tools/**", ] +[badges] +travis-ci = { repository = "servo/unicode-bidi" } +appveyor = { repository = "servo/unicode-bidi" } + [lib] name = "unicode_bidi" [dependencies] -flame = { version = "0.1", optional = true } -flamer = { version = "0.1", optional = true } -matches = "0.1" -serde = { version = ">=0.8, <2.0", optional = true, features = ["derive"] } +flame = { version = "0.2", optional = true } +flamer = { version = "0.4", optional = true } +serde = { version = ">=0.8, <2.0", default-features = false, optional = true, features = ["derive"] } [dev-dependencies] serde_test = ">=0.8, <2.0" [features] -default = [] +# Note: We don't actually use the `std` feature for anything other than making +# doctests work. But it may come in handy in the future. +default = ["std"] +std = [] unstable = [] # travis-cargo needs it bench_it = [] flame_it = ["flame", "flamer"] @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/unicode-bidi/unicode-bidi-0.3.4.crate" + value: "https://static.crates.io/crates/unicode-bidi/unicode-bidi-0.3.7.crate" } - version: "0.3.4" + version: "0.3.7" license_type: NOTICE last_upgrade_date { - year: 2020 - month: 12 - day: 15 + year: 2022 + month: 3 + day: 1 } } @@ -4,7 +4,7 @@ This crate implements the [Unicode Bidirectional Algorithm][tr9] for display of mixed right-to-left and left-to-right text. It is written in safe Rust, compatible with the current stable release. -[Documentation](http://doc.servo.org/unicode_bidi/) +[Documentation](https://docs.rs/unicode-bidi/) [![Travis-CI](https://travis-ci.org/servo/unicode-bidi.svg?branch=master)](https://travis-ci.org/servo/unicode-bidi) [![AppVeyor](https://img.shields.io/appveyor/ci/servo/unicode-bidi/master.svg)](https://ci.appveyor.com/project/servo/unicode-bidi) diff --git a/TEST_MAPPING b/TEST_MAPPING index d1919fd..2f8032a 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -1,8 +1,27 @@ -// Generated by cargo2android.py for tests in Android.bp +// Generated by update_crate_tests.py for tests that depend on this crate. { + "imports": [ + { + "path": "external/rust/crates/quiche" + }, + { + "path": "external/rust/crates/url" + } + ], "presubmit": [ { - "name": "unicode-bidi_device_test_src_lib" + "name": "doh_unit_test" + }, + { + "name": "unicode-bidi_test_src_lib" + } + ], + "presubmit-rust": [ + { + "name": "doh_unit_test" + }, + { + "name": "unicode-bidi_test_src_lib" } ] } diff --git a/src/char_data/mod.rs b/src/char_data/mod.rs index 4899a71..c91bfad 100644 --- a/src/char_data/mod.rs +++ b/src/char_data/mod.rs @@ -13,11 +13,11 @@ mod tables; pub use self::tables::{BidiClass, UNICODE_VERSION}; -use std::cmp::Ordering::{Equal, Less, Greater}; -use std::char; +use core::cmp::Ordering::{Equal, Less, Greater}; +use core::char; use self::tables::bidi_class_table; -use BidiClass::*; +use crate::BidiClass::*; /// Find the `BidiClass` of a single char. pub fn bidi_class(c: char) -> BidiClass { diff --git a/src/deprecated.rs b/src/deprecated.rs index 4d4b76e..491436a 100644 --- a/src/deprecated.rs +++ b/src/deprecated.rs @@ -9,8 +9,7 @@ //! This module holds deprecated assets only. -// Doesn't worth updating API here -#![cfg_attr(feature="cargo-clippy", allow(needless_pass_by_value))] +use alloc::vec::Vec; use super::*; diff --git a/src/explicit.rs b/src/explicit.rs index 4f6f22f..ec39dee 100644 --- a/src/explicit.rs +++ b/src/explicit.rs @@ -11,16 +11,16 @@ //! //! <http://www.unicode.org/reports/tr9/#Explicit_Levels_and_Directions> -use super::char_data::{BidiClass, is_rtl}; -use super::level::Level; +use alloc::vec::Vec; -use BidiClass::*; +use super::char_data::{BidiClass::{self, *}, is_rtl}; +use super::level::Level; /// Compute explicit embedding levels for one paragraph of text (X1-X8). /// /// `processing_classes[i]` must contain the `BidiClass` of the char at byte index `i`, /// for each char in `text`. -#[cfg_attr(feature = "flame_it", flame)] +#[cfg_attr(feature = "flame_it", flamer::flame)] pub fn compute( text: &str, para_level: Level, @@ -46,7 +46,10 @@ pub fn compute( let last_level = stack.last().level; // X5a-X5c: Isolate initiators get the level of the last entry on the stack. - let is_isolate = matches!(original_classes[i], RLI | LRI | FSI); + let is_isolate = match original_classes[i] { + RLI | LRI | FSI => true, + _ => false, + }; if is_isolate { levels[i] = last_level; match stack.last().status { diff --git a/src/implicit.rs b/src/implicit.rs index 4344ea3..2bb3581 100644 --- a/src/implicit.rs +++ b/src/implicit.rs @@ -9,18 +9,17 @@ //! 3.3.4 - 3.3.6. Resolve implicit levels and types. -use std::cmp::max; +use core::cmp::max; +use alloc::vec::Vec; -use super::char_data::BidiClass; +use super::char_data::BidiClass::{self, *}; use super::prepare::{IsolatingRunSequence, LevelRun, not_removed_by_x9, removed_by_x9}; use super::level::Level; -use BidiClass::*; - /// 3.3.4 Resolving Weak Types /// /// <http://www.unicode.org/reports/tr9/#Resolving_Weak_Types> -#[cfg_attr(feature = "flame_it", flame)] +#[cfg_attr(feature = "flame_it", flamer::flame)] pub fn resolve_weak(sequence: &IsolatingRunSequence, processing_classes: &mut [BidiClass]) { // FIXME (#8): This function applies steps W1-W6 in a single pass. This can produce // incorrect results in cases where a "later" rule changes the value of `prev_class` seen @@ -135,7 +134,7 @@ pub fn resolve_weak(sequence: &IsolatingRunSequence, processing_classes: &mut [B /// 3.3.5 Resolving Neutral Types /// /// <http://www.unicode.org/reports/tr9/#Resolving_Neutral_Types> -#[cfg_attr(feature = "flame_it", flame)] +#[cfg_attr(feature = "flame_it", flamer::flame)] pub fn resolve_neutral( sequence: &IsolatingRunSequence, levels: &[Level], @@ -200,7 +199,7 @@ pub fn resolve_neutral( /// Returns the maximum embedding level in the paragraph. /// /// <http://www.unicode.org/reports/tr9/#Resolving_Implicit_Levels> -#[cfg_attr(feature = "flame_it", flame)] +#[cfg_attr(feature = "flame_it", flamer::flame)] pub fn resolve_levels(original_classes: &[BidiClass], levels: &mut [Level]) -> Level { let mut max_level = Level::ltr(); @@ -224,5 +223,8 @@ pub fn resolve_levels(original_classes: &[BidiClass], levels: &mut [Level]) -> L /// <http://www.unicode.org/reports/tr9/#NI> #[allow(non_snake_case)] fn is_NI(class: BidiClass) -> bool { - matches!(class, B | S | WS | ON | FSI | LRI | RLI | PDI) + match class { + B | S | WS | ON | FSI | LRI | RLI | PDI => true, + _ => false, + } } diff --git a/src/level.rs b/src/level.rs index 1c195a9..c1adf1f 100644 --- a/src/level.rs +++ b/src/level.rs @@ -13,7 +13,9 @@ //! //! <http://www.unicode.org/reports/tr9/#BD2> -use std::convert::{From, Into}; +use alloc::vec::Vec; +use core::convert::{From, Into}; +use alloc::string::{String, ToString}; use super::char_data::BidiClass; @@ -28,7 +30,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(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Level(u8); pub const LTR_LEVEL: Level = Level(0); @@ -328,7 +330,8 @@ mod tests { #[test] fn test_into() { let level = Level::rtl(); - assert_eq!(1u8, level.into()); + let number: u8 = level.into(); + assert_eq!(1u8, number); } #[test] @@ -53,27 +53,23 @@ //! ]); //! ``` //! +//! # Features +//! +//! - `std`: Enabled by default, but can be disabled to make `unicode_bidi` +//! `#![no_std]` + `alloc` compatible. +//! - `serde`: Adds [`serde::Serialize`] and [`serde::Deserialize`] +//! implementations to relevant types. +//! //! [tr9]: <http://www.unicode.org/reports/tr9/> #![forbid(unsafe_code)] -#![cfg_attr(feature="flame_it", feature(plugin, custom_attribute))] -#![cfg_attr(feature="flame_it", plugin(flamer))] - - +#![no_std] +// We need to link to std to make doc tests work on older Rust versions +#[cfg(feature = "std")] +extern crate std; #[macro_use] -extern crate matches; - -#[cfg(feature = "serde")] -#[macro_use] -extern crate serde; - -#[cfg(all(feature = "serde", test))] -extern crate serde_test; - -#[cfg(feature = "flame_it")] -extern crate flame; - +extern crate alloc; pub mod deprecated; pub mod format_chars; @@ -84,18 +80,19 @@ mod explicit; mod implicit; mod prepare; -pub use char_data::{BidiClass, bidi_class, UNICODE_VERSION}; -pub use level::{Level, LTR_LEVEL, RTL_LEVEL}; -pub use prepare::LevelRun; +pub use crate::char_data::{BidiClass, bidi_class, UNICODE_VERSION}; +pub use crate::level::{Level, LTR_LEVEL, RTL_LEVEL}; +pub use crate::prepare::LevelRun; -use std::borrow::Cow; -use std::cmp::{max, min}; -use std::iter::repeat; -use std::ops::Range; - -use BidiClass::*; -use format_chars as chars; +use alloc::borrow::Cow; +use alloc::vec::Vec; +use alloc::string::String; +use core::cmp::{max, min}; +use core::iter::repeat; +use core::ops::Range; +use crate::BidiClass::*; +use crate::format_chars as chars; /// Bidi information about a single paragraph #[derive(Debug, PartialEq)] @@ -135,8 +132,8 @@ impl<'text> InitialInfo<'text> { /// Also sets the class for each First Strong Isolate initiator (FSI) to LRI or RLI if a strong /// character is found before the matching PDI. If no strong character is found, the class will /// remain FSI, and it's up to later stages to treat these as LRI when needed. - #[cfg_attr(feature = "flame_it", flame)] - pub fn new(text: &str, default_para_level: Option<Level>) -> InitialInfo { + #[cfg_attr(feature = "flame_it", flamer::flame)] + pub fn new(text: &str, default_para_level: Option<Level>) -> InitialInfo<'_> { let mut original_classes = Vec::with_capacity(text.len()); // The stack contains the starting byte index for each nested isolate we're inside. @@ -261,8 +258,8 @@ impl<'text> BidiInfo<'text> { /// text that is entirely LTR. See the `nsBidi` class from Gecko for comparison. /// /// TODO: Support auto-RTL base direction - #[cfg_attr(feature = "flame_it", flame)] - pub fn new(text: &str, default_para_level: Option<Level>) -> BidiInfo { + #[cfg_attr(feature = "flame_it", flamer::flame)] + pub fn new(text: &str, default_para_level: Option<Level>) -> BidiInfo<'_> { let InitialInfo { original_classes, paragraphs, @@ -309,15 +306,15 @@ impl<'text> BidiInfo<'text> { /// Re-order a line based on resolved levels and return only the embedding levels, one `Level` /// per *byte*. - #[cfg_attr(feature = "flame_it", flame)] + #[cfg_attr(feature = "flame_it", flamer::flame)] pub fn reordered_levels(&self, para: &ParagraphInfo, line: Range<usize>) -> Vec<Level> { - let (levels, _) = self.visual_runs(para, line.clone()); + let (levels, _) = self.visual_runs(para, line); levels } /// Re-order a line based on resolved levels and return only the embedding levels, one `Level` /// per *character*. - #[cfg_attr(feature = "flame_it", flame)] + #[cfg_attr(feature = "flame_it", flamer::flame)] pub fn reordered_levels_per_char( &self, para: &ParagraphInfo, @@ -329,13 +326,13 @@ impl<'text> BidiInfo<'text> { /// Re-order a line based on resolved levels and return the line in display order. - #[cfg_attr(feature = "flame_it", flame)] + #[cfg_attr(feature = "flame_it", flamer::flame)] pub fn reorder_line(&self, para: &ParagraphInfo, line: Range<usize>) -> Cow<'text, str> { let (levels, runs) = self.visual_runs(para, line.clone()); // If all isolating run sequences are LTR, no reordering is needed if runs.iter().all(|run| levels[run.start].is_ltr()) { - return self.text[line.clone()].into(); + return self.text[line].into(); } let mut result = String::with_capacity(line.len()); @@ -354,7 +351,7 @@ impl<'text> BidiInfo<'text> { /// `line` is a range of bytes indices within `levels`. /// /// <http://www.unicode.org/reports/tr9/#Reordering_Resolved_Levels> - #[cfg_attr(feature = "flame_it", flame)] + #[cfg_attr(feature = "flame_it", flamer::flame)] pub fn visual_runs( &self, para: &ParagraphInfo, @@ -364,6 +361,8 @@ 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> @@ -371,7 +370,7 @@ impl<'text> BidiInfo<'text> { 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 @@ -393,18 +392,16 @@ 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; + for level in &mut line_levels[from..to] { + *level = para.level; } reset_from = None; reset_to = None; } } 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; + for level in &mut line_levels[from..] { + *level = para.level; } } @@ -479,7 +476,7 @@ impl<'text> BidiInfo<'text> { /// /// The levels assigned to these characters are not specified by the algorithm. This function /// assigns each one the level of the previous character, to avoid breaking level runs. -#[cfg_attr(feature = "flame_it", flame)] +#[cfg_attr(feature = "flame_it", flamer::flame)] fn assign_levels_to_removed_chars(para_level: Level, classes: &[BidiClass], levels: &mut [Level]) { for i in 0..levels.len() { if prepare::removed_by_x9(classes[i]) { @@ -674,7 +671,7 @@ mod tests { } ); - /// BidiTest:69635 (AL ET EN) + // BidiTest:69635 (AL ET EN) let bidi_info = BidiInfo::new("\u{060B}\u{20CF}\u{06F9}", None); assert_eq!(bidi_info.original_classes, vec![AL, AL, ET, ET, ET, EN, EN]); } @@ -703,7 +700,7 @@ mod tests { assert_eq!(BidiInfo::new("אבּג\n123", None).has_rtl(), true); } - fn reorder_paras(text: &str) -> Vec<Cow<str>> { + fn reorder_paras(text: &str) -> Vec<Cow<'_, str>> { let bidi_info = BidiInfo::new(text, None); bidi_info .paragraphs @@ -714,22 +711,22 @@ mod tests { #[test] fn test_reorder_line() { - /// Bidi_Class: L L L B L L L B L L L + // Bidi_Class: L L L B L L L B L L L assert_eq!( reorder_paras("abc\ndef\nghi"), vec!["abc\n", "def\n", "ghi"] ); - /// Bidi_Class: L L EN B L L EN B L L EN + // Bidi_Class: L L EN B L L EN B L L EN assert_eq!( reorder_paras("ab1\nde2\ngh3"), vec!["ab1\n", "de2\n", "gh3"] ); - /// Bidi_Class: L L L B AL AL AL + // Bidi_Class: L L L B AL AL AL assert_eq!(reorder_paras("abc\nابج"), vec!["abc\n", "جبا"]); - /// Bidi_Class: AL AL AL B L L L + // Bidi_Class: AL AL AL B L L L assert_eq!(reorder_paras("ابج\nabc"), vec!["\nجبا", "abc"]); assert_eq!(reorder_paras("1.-2"), vec!["1.-2"]); @@ -812,7 +809,7 @@ mod tests { #[test] fn test_reordered_levels() { - /// BidiTest:946 (LRI PDI) + // BidiTest:946 (LRI PDI) let text = "\u{2067}\u{2069}"; assert_eq!( reordered_levels_for_paras(text), @@ -823,6 +820,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}"; diff --git a/src/prepare.rs b/src/prepare.rs index 7983962..752087b 100644 --- a/src/prepare.rs +++ b/src/prepare.rs @@ -11,14 +11,13 @@ //! //! <http://www.unicode.org/reports/tr9/#Preparations_for_Implicit_Processing> -use std::cmp::max; -use std::ops::Range; +use core::cmp::max; +use core::ops::Range; +use alloc::vec::Vec; -use super::char_data::BidiClass; +use super::BidiClass::{self, *}; use super::level::Level; -use BidiClass::*; - /// A maximal substring of characters with the same embedding level. /// /// Represented as a range of byte indices. @@ -41,7 +40,7 @@ pub struct IsolatingRunSequence { /// whose matching PDI is the first character of the next level run in the sequence. /// /// Note: This function does *not* return the sequences in order by their first characters. -#[cfg_attr(feature = "flame_it", flame)] +#[cfg_attr(feature = "flame_it", flamer::flame)] pub fn isolating_run_sequences( para_level: Level, original_classes: &[BidiClass], @@ -74,7 +73,7 @@ pub fn isolating_run_sequences( sequence.push(run); - if matches!(end_class, RLI | LRI | FSI) { + if let RLI | LRI | FSI = end_class { // Resume this sequence after the isolate. stack.push(sequence); } else { @@ -114,7 +113,7 @@ pub fn isolating_run_sequences( }; // Get the level of the next non-removed char after the runs. - let succ_level = if matches!(original_classes[end_of_seq - 1], RLI | LRI | FSI) { + let succ_level = if let RLI | LRI | FSI = original_classes[end_of_seq - 1] { para_level } else { match original_classes[end_of_seq..].iter().position( @@ -164,7 +163,10 @@ fn level_runs(levels: &[Level], original_classes: &[BidiClass]) -> Vec<LevelRun> /// /// <http://www.unicode.org/reports/tr9/#X9> pub fn removed_by_x9(class: BidiClass) -> bool { - matches!(class, RLE | LRE | RLO | LRO | PDF | BN) + match class { + RLE | LRE | RLO | LRO | PDF | BN => true, + _ => false, + } } // For use as a predicate for `position` / `rposition` @@ -186,7 +188,7 @@ mod tests { } // From <http://www.unicode.org/reports/tr9/#BD13> - #[cfg_attr(rustfmt, rustfmt_skip)] + #[rustfmt::skip] #[test] fn test_isolating_run_sequences() { @@ -231,7 +233,7 @@ mod tests { } // From <http://www.unicode.org/reports/tr9/#X10> - #[cfg_attr(rustfmt, rustfmt_skip)] + #[rustfmt::skip] #[test] fn test_isolating_run_sequences_sos_and_eos() { |