60
60
#![ cfg_attr( feature="flame_it" , feature( plugin, custom_attribute) ) ]
61
61
#![ cfg_attr( feature="flame_it" , plugin( flamer) ) ]
62
62
63
-
64
- #[ macro_use]
65
- extern crate matches;
66
-
67
- #[ cfg( feature = "serde" ) ]
68
- #[ macro_use]
69
- extern crate serde;
70
-
71
- #[ cfg( all( feature = "serde" , test) ) ]
72
- extern crate serde_test;
73
-
74
- #[ cfg( feature = "flame_it" ) ]
75
- extern crate flame;
76
-
77
-
78
63
pub mod deprecated;
79
64
pub mod format_chars;
80
65
pub mod level;
@@ -84,18 +69,17 @@ mod explicit;
84
69
mod implicit;
85
70
mod prepare;
86
71
87
- pub use char_data:: { BidiClass , bidi_class, UNICODE_VERSION } ;
88
- pub use level:: { Level , LTR_LEVEL , RTL_LEVEL } ;
89
- pub use prepare:: LevelRun ;
72
+ pub use crate :: char_data:: { BidiClass , bidi_class, UNICODE_VERSION } ;
73
+ pub use crate :: level:: { Level , LTR_LEVEL , RTL_LEVEL } ;
74
+ pub use crate :: prepare:: LevelRun ;
90
75
91
76
use std:: borrow:: Cow ;
92
77
use std:: cmp:: { max, min} ;
93
78
use std:: iter:: repeat;
94
79
use std:: ops:: Range ;
95
80
96
- use BidiClass :: * ;
97
- use format_chars as chars;
98
-
81
+ use crate :: BidiClass :: * ;
82
+ use crate :: format_chars as chars;
99
83
100
84
/// Bidi information about a single paragraph
101
85
#[ derive( Debug , PartialEq ) ]
@@ -136,7 +120,7 @@ impl<'text> InitialInfo<'text> {
136
120
/// character is found before the matching PDI. If no strong character is found, the class will
137
121
/// remain FSI, and it's up to later stages to treat these as LRI when needed.
138
122
#[ cfg_attr( feature = "flame_it" , flame) ]
139
- pub fn new ( text : & str , default_para_level : Option < Level > ) -> InitialInfo {
123
+ pub fn new ( text : & str , default_para_level : Option < Level > ) -> InitialInfo < ' _ > {
140
124
let mut original_classes = Vec :: with_capacity ( text. len ( ) ) ;
141
125
142
126
// The stack contains the starting byte index for each nested isolate we're inside.
@@ -262,7 +246,7 @@ impl<'text> BidiInfo<'text> {
262
246
///
263
247
/// TODO: Support auto-RTL base direction
264
248
#[ cfg_attr( feature = "flame_it" , flame) ]
265
- pub fn new ( text : & str , default_para_level : Option < Level > ) -> BidiInfo {
249
+ pub fn new ( text : & str , default_para_level : Option < Level > ) -> BidiInfo < ' _ > {
266
250
let InitialInfo {
267
251
original_classes,
268
252
paragraphs,
@@ -311,7 +295,7 @@ impl<'text> BidiInfo<'text> {
311
295
/// per *byte*.
312
296
#[ cfg_attr( feature = "flame_it" , flame) ]
313
297
pub fn reordered_levels ( & self , para : & ParagraphInfo , line : Range < usize > ) -> Vec < Level > {
314
- let ( levels, _) = self . visual_runs ( para, line. clone ( ) ) ;
298
+ let ( levels, _) = self . visual_runs ( para, line) ;
315
299
levels
316
300
}
317
301
@@ -335,7 +319,7 @@ impl<'text> BidiInfo<'text> {
335
319
336
320
// If all isolating run sequences are LTR, no reordering is needed
337
321
if runs. iter ( ) . all ( |run| levels[ run. start ] . is_ltr ( ) ) {
338
- return self . text [ line. clone ( ) ] . into ( ) ;
322
+ return self . text [ line] . into ( ) ;
339
323
}
340
324
341
325
let mut result = String :: with_capacity ( line. len ( ) ) ;
@@ -395,18 +379,16 @@ impl<'text> BidiInfo<'text> {
395
379
}
396
380
}
397
381
if let ( Some ( from) , Some ( to) ) = ( reset_from, reset_to) {
398
- #[ cfg_attr( feature = "cargo-clippy" , allow( needless_range_loop) ) ]
399
- for j in from..to {
400
- line_levels[ j] = para. level ;
382
+ for level in & mut line_levels[ from..to] {
383
+ * level = para. level ;
401
384
}
402
385
reset_from = None ;
403
386
reset_to = None ;
404
387
}
405
388
}
406
389
if let Some ( from) = reset_from {
407
- #[ cfg_attr( feature = "cargo-clippy" , allow( needless_range_loop) ) ]
408
- for j in from..line_str. len ( ) {
409
- line_levels[ j] = para. level ;
390
+ for level in & mut line_levels[ from..] {
391
+ * level = para. level ;
410
392
}
411
393
}
412
394
@@ -676,7 +658,7 @@ mod tests {
676
658
}
677
659
) ;
678
660
679
- /// BidiTest:69635 (AL ET EN)
661
+ // BidiTest:69635 (AL ET EN)
680
662
let bidi_info = BidiInfo :: new ( "\u{060B} \u{20CF} \u{06F9} " , None ) ;
681
663
assert_eq ! ( bidi_info. original_classes, vec![ AL , AL , ET , ET , ET , EN , EN ] ) ;
682
664
}
@@ -705,7 +687,7 @@ mod tests {
705
687
assert_eq ! ( BidiInfo :: new( "אבּג\n 123" , None ) . has_rtl( ) , true ) ;
706
688
}
707
689
708
- fn reorder_paras ( text : & str ) -> Vec < Cow < str > > {
690
+ fn reorder_paras ( text : & str ) -> Vec < Cow < ' _ , str > > {
709
691
let bidi_info = BidiInfo :: new ( text, None ) ;
710
692
bidi_info
711
693
. paragraphs
@@ -716,22 +698,22 @@ mod tests {
716
698
717
699
#[ test]
718
700
fn test_reorder_line ( ) {
719
- /// Bidi_Class: L L L B L L L B L L L
701
+ // Bidi_Class: L L L B L L L B L L L
720
702
assert_eq ! (
721
703
reorder_paras( "abc\n def\n ghi" ) ,
722
704
vec![ "abc\n " , "def\n " , "ghi" ]
723
705
) ;
724
706
725
- /// Bidi_Class: L L EN B L L EN B L L EN
707
+ // Bidi_Class: L L EN B L L EN B L L EN
726
708
assert_eq ! (
727
709
reorder_paras( "ab1\n de2\n gh3" ) ,
728
710
vec![ "ab1\n " , "de2\n " , "gh3" ]
729
711
) ;
730
712
731
- /// Bidi_Class: L L L B AL AL AL
713
+ // Bidi_Class: L L L B AL AL AL
732
714
assert_eq ! ( reorder_paras( "abc\n ابج" ) , vec![ "abc\n " , "جبا" ] ) ;
733
715
734
- /// Bidi_Class: AL AL AL B L L L
716
+ // Bidi_Class: AL AL AL B L L L
735
717
assert_eq ! ( reorder_paras( "ابج\n abc" ) , vec![ "\n جبا" , "abc" ] ) ;
736
718
737
719
assert_eq ! ( reorder_paras( "1.-2" ) , vec![ "1.-2" ] ) ;
@@ -814,7 +796,7 @@ mod tests {
814
796
#[ test]
815
797
fn test_reordered_levels ( ) {
816
798
817
- /// BidiTest:946 (LRI PDI)
799
+ // BidiTest:946 (LRI PDI)
818
800
let text = "\u{2067} \u{2069} " ;
819
801
assert_eq ! (
820
802
reordered_levels_for_paras( text) ,
0 commit comments