16
16
*/
17
17
18
18
use core:: collections:: Collection ;
19
- use core:: iter:: { Filter } ;
19
+ use core:: iter:: { Filter , AdditiveIterator } ;
20
20
use core:: str:: { CharSplits , StrSlice } ;
21
21
use core:: iter:: Iterator ;
22
22
use u_char;
23
+ use u_char:: UnicodeChar ;
23
24
24
25
/// An iterator over the words of a string, separated by a sequence of whitespace
25
26
pub type Words < ' a > =
@@ -78,7 +79,7 @@ pub trait UnicodeStrSlice<'a> {
78
79
/// [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/)
79
80
/// recommends that these characters be treated as 1 column (i.e.,
80
81
/// `is_cjk` = `false`) if the locale is unknown.
81
- // fn width(&self, is_cjk: bool) -> uint;
82
+ fn width ( & self , is_cjk : bool ) -> uint ;
82
83
83
84
/// Returns a string with leading and trailing whitespace removed.
84
85
fn trim ( & self ) -> & ' a str ;
@@ -102,6 +103,11 @@ impl<'a> UnicodeStrSlice<'a> for &'a str {
102
103
#[ inline]
103
104
fn is_alphanumeric ( & self ) -> bool { self . chars ( ) . all ( u_char:: is_alphanumeric) }
104
105
106
+ #[ inline]
107
+ fn width ( & self , is_cjk : bool ) -> uint {
108
+ self . chars ( ) . map ( |c| c. width ( is_cjk) . unwrap_or ( 0 ) ) . sum ( )
109
+ }
110
+
105
111
#[ inline]
106
112
fn trim ( & self ) -> & ' a str {
107
113
self . trim_left ( ) . trim_right ( )
0 commit comments