aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoel Galenson <jgalenson@google.com>2021-05-19 17:44:52 -0700
committerJoel Galenson <jgalenson@google.com>2021-05-19 17:44:52 -0700
commitc62c1264e55407348d2ac83ba51bdab7a910653b (patch)
tree6062f6ae82012e40507103184cec2e6e7569878b /src
parentb7aefdc0505efdf3b85db2fd3d4ad93e638ee09b (diff)
downloadunicode-bidi-c62c1264e55407348d2ac83ba51bdab7a910653b.tar.gz
Upgrade rust/crates/unicode-bidi to 0.3.5
Test: make Change-Id: Iec9215b98154144794fb50209db33f50293b6d70
Diffstat (limited to 'src')
-rw-r--r--src/char_data/mod.rs2
-rw-r--r--src/deprecated.rs3
-rw-r--r--src/explicit.rs8
-rw-r--r--src/implicit.rs11
-rw-r--r--src/level.rs5
-rw-r--r--src/lib.rs86
-rw-r--r--src/prepare.rs11
7 files changed, 55 insertions, 71 deletions
diff --git a/src/char_data/mod.rs b/src/char_data/mod.rs
index 4899a71..da85c84 100644
--- a/src/char_data/mod.rs
+++ b/src/char_data/mod.rs
@@ -17,7 +17,7 @@ use std::cmp::Ordering::{Equal, Less, Greater};
use std::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..8bd206b 100644
--- a/src/deprecated.rs
+++ b/src/deprecated.rs
@@ -9,9 +9,6 @@
//! This module holds deprecated assets only.
-// Doesn't worth updating API here
-#![cfg_attr(feature="cargo-clippy", allow(needless_pass_by_value))]
-
use super::*;
/// Find the level runs within a line and return them in visual order.
diff --git a/src/explicit.rs b/src/explicit.rs
index 4f6f22f..95de505 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 matches::matches;
-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,
diff --git a/src/implicit.rs b/src/implicit.rs
index 4344ea3..7e43294 100644
--- a/src/implicit.rs
+++ b/src/implicit.rs
@@ -10,17 +10,16 @@
//! 3.3.4 - 3.3.6. Resolve implicit levels and types.
use std::cmp::max;
+use matches::matches;
-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();
diff --git a/src/level.rs b/src/level.rs
index 1c195a9..bc74205 100644
--- a/src/level.rs
+++ b/src/level.rs
@@ -28,7 +28,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 +328,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]
diff --git a/src/lib.rs b/src/lib.rs
index 5e1d3e2..ba3220b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -57,24 +57,6 @@
#![forbid(unsafe_code)]
-#![cfg_attr(feature="flame_it", feature(plugin, custom_attribute))]
-#![cfg_attr(feature="flame_it", plugin(flamer))]
-
-
-#[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;
-
-
pub mod deprecated;
pub mod format_chars;
pub mod level;
@@ -84,18 +66,17 @@ 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 crate::BidiClass::*;
+use crate::format_chars as chars;
/// Bidi information about a single paragraph
#[derive(Debug, PartialEq)]
@@ -135,8 +116,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 +242,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 +290,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 +310,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 +335,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 +345,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 +354,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 +376,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 +460,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 +655,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 +684,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 +695,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 +793,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 +804,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..ccb8c0f 100644
--- a/src/prepare.rs
+++ b/src/prepare.rs
@@ -13,12 +13,11 @@
use std::cmp::max;
use std::ops::Range;
+use matches::matches;
-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],
@@ -186,7 +185,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 +230,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() {