File tree 8 files changed +15
-15
lines changed
8 files changed +15
-15
lines changed Original file line number Diff line number Diff line change @@ -457,13 +457,13 @@ def emit_charwidth_module(f, width_table):
457
457
""" )
458
458
459
459
f .write ("""
460
- pub fn width(c: char, is_cjk: bool) -> Option<usize > {
461
- match c as usize {
460
+ pub fn width(c: char, is_cjk: bool) -> Option<u32 > {
461
+ match c as u32 {
462
462
_c @ 0 => Some(0), // null is zero width
463
463
cu if cu < 0x20 => None, // control sequences have no width
464
464
cu if cu < 0x7F => Some(1), // ASCII
465
465
cu if cu < 0xA0 => None, // more control sequences
466
- _ => Some(bsearch_range_value_table(c, is_cjk, charwidth_table) as usize )
466
+ _ => Some(bsearch_range_value_table(c, is_cjk, charwidth_table) as u32 )
467
467
}
468
468
}
469
469
Original file line number Diff line number Diff line change @@ -1456,7 +1456,7 @@ impl str {
1456
1456
/// characters be treated as 1 column (i.e., `is_cjk = false`) if the locale is unknown.
1457
1457
#[ unstable( feature = "unicode" ,
1458
1458
reason = "this functionality may only be provided by libunicode" ) ]
1459
- pub fn width ( & self , is_cjk : bool ) -> usize {
1459
+ pub fn width ( & self , is_cjk : bool ) -> u32 {
1460
1460
UnicodeStr :: width ( & self [ ..] , is_cjk)
1461
1461
}
1462
1462
Original file line number Diff line number Diff line change @@ -286,7 +286,7 @@ enum EscapeUnicodeState {
286
286
Backslash ,
287
287
Type ,
288
288
LeftBrace ,
289
- Value ( usize ) ,
289
+ Value ( u8 ) ,
290
290
RightBrace ,
291
291
Done ,
292
292
}
Original file line number Diff line number Diff line change @@ -576,7 +576,7 @@ Available lint options:
576
576
. map ( |& s| s. name . width ( true ) )
577
577
. max ( ) . unwrap_or ( 0 ) ;
578
578
let padded = |x : & str | {
579
- let mut s = repeat ( " " ) . take ( max_name_len - x. chars ( ) . count ( ) )
579
+ let mut s = repeat ( " " ) . take ( ( max_name_len - x. width ( true ) ) as usize )
580
580
. collect :: < String > ( ) ;
581
581
s. push_str ( x) ;
582
582
s
@@ -603,7 +603,7 @@ Available lint options:
603
603
. map ( |& ( s, _) | s. width ( true ) )
604
604
. max ( ) . unwrap_or ( 0 ) ;
605
605
let padded = |x : & str | {
606
- let mut s = repeat ( " " ) . take ( max_name_len - x. chars ( ) . count ( ) )
606
+ let mut s = repeat ( " " ) . take ( ( max_name_len - x. width ( true ) ) as usize )
607
607
. collect :: < String > ( ) ;
608
608
s. push_str ( x) ;
609
609
s
Original file line number Diff line number Diff line change @@ -545,7 +545,7 @@ fn highlight_lines(err: &mut EmitterWriter,
545
545
_ => lastc. width ( false ) . unwrap_or ( 0 ) ,
546
546
} ;
547
547
col += count;
548
- s. extend ( :: std:: iter:: repeat ( '~' ) . take ( count) ) ;
548
+ s. extend ( :: std:: iter:: repeat ( '~' ) . take ( count as usize ) ) ;
549
549
550
550
let hi = cm. lookup_char_pos ( sp. hi ) ;
551
551
if hi. col != lo. col {
@@ -556,7 +556,7 @@ fn highlight_lines(err: &mut EmitterWriter,
556
556
_ => ch. width ( false ) . unwrap_or ( 0 ) ,
557
557
} ;
558
558
col += count;
559
- s. extend ( :: std:: iter:: repeat ( '~' ) . take ( count) ) ;
559
+ s. extend ( :: std:: iter:: repeat ( '~' ) . take ( count as usize ) ) ;
560
560
}
561
561
}
562
562
Original file line number Diff line number Diff line change @@ -447,5 +447,5 @@ impl char {
447
447
/// `is_cjk` = `false`) if the context cannot be reliably determined.
448
448
#[ unstable( feature = "unicode" ,
449
449
reason = "needs expert opinion. is_cjk flag stands out as ugly" ) ]
450
- pub fn width ( self , is_cjk : bool ) -> Option < usize > { charwidth:: width ( self , is_cjk) }
450
+ pub fn width ( self , is_cjk : bool ) -> Option < u32 > { charwidth:: width ( self , is_cjk) }
451
451
}
Original file line number Diff line number Diff line change @@ -7603,13 +7603,13 @@ pub mod charwidth {
7603
7603
}
7604
7604
}
7605
7605
7606
- pub fn width(c: char, is_cjk: bool) -> Option<usize > {
7607
- match c as usize {
7606
+ pub fn width(c: char, is_cjk: bool) -> Option<u32 > {
7607
+ match c as u32 {
7608
7608
_c @ 0 => Some(0), // null is zero width
7609
7609
cu if cu < 0x20 => None, // control sequences have no width
7610
7610
cu if cu < 0x7F => Some(1), // ASCII
7611
7611
cu if cu < 0xA0 => None, // more control sequences
7612
- _ => Some(bsearch_range_value_table(c, is_cjk, charwidth_table) as usize )
7612
+ _ => Some(bsearch_range_value_table(c, is_cjk, charwidth_table) as u32 )
7613
7613
}
7614
7614
}
7615
7615
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ pub trait UnicodeStr {
41
41
fn words < ' a > ( & ' a self ) -> Words < ' a > ;
42
42
fn is_whitespace ( & self ) -> bool ;
43
43
fn is_alphanumeric ( & self ) -> bool ;
44
- fn width ( & self , is_cjk : bool ) -> usize ;
44
+ fn width ( & self , is_cjk : bool ) -> u32 ;
45
45
fn trim < ' a > ( & ' a self ) -> & ' a str ;
46
46
fn trim_left < ' a > ( & ' a self ) -> & ' a str ;
47
47
fn trim_right < ' a > ( & ' a self ) -> & ' a str ;
@@ -76,7 +76,7 @@ impl UnicodeStr for str {
76
76
fn is_alphanumeric ( & self ) -> bool { self . chars ( ) . all ( |c| c. is_alphanumeric ( ) ) }
77
77
78
78
#[ inline]
79
- fn width ( & self , is_cjk : bool ) -> usize {
79
+ fn width ( & self , is_cjk : bool ) -> u32 {
80
80
self . chars ( ) . map ( |c| c. width ( is_cjk) . unwrap_or ( 0 ) ) . sum ( )
81
81
}
82
82
You can’t perform that action at this time.
0 commit comments