@@ -7,11 +7,11 @@ use alloc::vec::Vec;
77use icu_properties:: props:: { BidiClass , BidiMirroringGlyph , BidiPairedBracketType } ;
88
99/// Type alias for a bidirectional level.
10- pub ( crate ) type BidiLevel = u8 ;
10+ pub type BidiLevel = u8 ;
1111
1212/// Resolver for the Unicode bidirectional algorithm.
1313#[ derive( Clone , Default ) ]
14- pub ( crate ) struct BidiResolver {
14+ pub struct BidiResolver {
1515 base_level : BidiLevel ,
1616 levels : Vec < BidiLevel > ,
1717 initial_types : Vec < BidiClass > ,
@@ -23,9 +23,18 @@ pub(crate) struct BidiResolver {
2323 flags : u16 ,
2424}
2525
26+ impl core:: fmt:: Debug for BidiResolver {
27+ fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
28+ f. debug_struct ( "BidiResolver" )
29+ . field ( "base_level" , & self . base_level )
30+ . field ( "levels" , & self . levels )
31+ . finish_non_exhaustive ( )
32+ }
33+ }
34+
2635impl BidiResolver {
2736 /// Creates a new resolver.
28- pub ( crate ) fn new ( ) -> Self {
37+ pub fn new ( ) -> Self {
2938 Self {
3039 base_level : 0 ,
3140 levels : Vec :: new ( ) ,
@@ -40,18 +49,18 @@ impl BidiResolver {
4049 }
4150
4251 /// Returns the base level of the text.
43- pub ( crate ) fn base_level ( & self ) -> u8 {
52+ pub fn base_level ( & self ) -> u8 {
4453 self . base_level
4554 }
4655
4756 /// Returns the sequence of bidi levels corresponding to all characters in the
4857 /// paragraph.
49- pub ( crate ) fn levels ( & self ) -> & [ BidiLevel ] {
58+ pub fn levels ( & self ) -> & [ BidiLevel ] {
5059 & self . levels
5160 }
5261
5362 /// Clears the resolver state.
54- pub ( crate ) fn clear ( & mut self ) {
63+ pub fn clear ( & mut self ) {
5564 self . initial_types . clear ( ) ;
5665 self . levels . clear ( ) ;
5766 self . types . clear ( ) ;
@@ -63,7 +72,7 @@ impl BidiResolver {
6372
6473 /// Resolves a paragraph with the specified base direction and
6574 /// precomputed types.
66- pub ( crate ) fn resolve (
75+ pub fn resolve (
6776 & mut self ,
6877 chars : impl Iterator < Item = ( char , ( BidiClass , BidiMirroringGlyph ) ) > ,
6978 base_level : Option < u8 > ,
@@ -240,8 +249,7 @@ impl BidiResolver {
240249 } else {
241250 ( stack. embedding_level ( ) + 2 ) & !1
242251 } ;
243- if new_level <= MAX_STACK as u8 && overflow_isolates == 0 && overflow_embedding == 0
244- {
252+ if new_level <= MAX_STACK && overflow_isolates == 0 && overflow_embedding == 0 {
245253 if is_isolate {
246254 valid_isolates += 1 ;
247255 }
@@ -387,7 +395,7 @@ impl BidiResolver {
387395 }
388396 }
389397
390- #[ allow ( clippy:: needless_range_loop) ]
398+ #[ expect ( clippy:: needless_range_loop, reason = "Deferred" ) ]
391399 fn resolve_sequence ( & mut self , level : u8 , sos : BidiClass , eos : BidiClass , len : usize ) {
392400 if len == 0 {
393401 return ;
@@ -718,7 +726,7 @@ where
718726
719727/// Returns whether the character needs bidirectional resolution.
720728#[ inline( always) ]
721- pub ( crate ) fn needs_bidi_resolution ( bidi_class : BidiClass ) -> bool {
729+ pub fn needs_bidi_resolution ( bidi_class : BidiClass ) -> bool {
722730 mask ( bidi_class) & BIDI_MASK != 0
723731}
724732
@@ -805,22 +813,22 @@ impl Run {
805813 }
806814}
807815
808- const MAX_STACK : usize = 125 ;
816+ const MAX_STACK : u8 = 125 ;
809817
810818struct Stack {
811- embedding_level : [ u8 ; MAX_STACK + 1 ] ,
812- override_status : [ BidiClass ; MAX_STACK + 1 ] ,
813- isolate_status : [ bool ; MAX_STACK + 1 ] ,
819+ embedding_level : [ u8 ; MAX_STACK as usize + 1 ] ,
820+ override_status : [ BidiClass ; MAX_STACK as usize + 1 ] ,
821+ isolate_status : [ bool ; MAX_STACK as usize + 1 ] ,
814822 depth : usize ,
815823}
816824
817825impl Stack {
818826 fn new ( ) -> Self {
819827 Self {
820828 depth : 0 ,
821- embedding_level : [ 0 ; MAX_STACK + 1 ] ,
822- override_status : [ BidiClass :: OtherNeutral ; MAX_STACK + 1 ] ,
823- isolate_status : [ false ; MAX_STACK + 1 ] ,
829+ embedding_level : [ 0 ; MAX_STACK as usize + 1 ] ,
830+ override_status : [ BidiClass :: OtherNeutral ; MAX_STACK as usize + 1 ] ,
831+ isolate_status : [ false ; MAX_STACK as usize + 1 ] ,
824832 }
825833 }
826834
0 commit comments