1616 */
1717
1818use core:: collections:: Collection ;
19- use core:: iter:: { Filter } ;
19+ use core:: iter:: { Filter , AdditiveIterator } ;
2020use core:: str:: { CharSplits , StrSlice } ;
2121use core:: iter:: Iterator ;
2222use u_char;
23+ use u_char:: UnicodeChar ;
2324
2425/// An iterator over the words of a string, separated by a sequence of whitespace
2526pub type Words < ' a > =
@@ -78,7 +79,7 @@ pub trait UnicodeStrSlice<'a> {
7879 /// [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/)
7980 /// recommends that these characters be treated as 1 column (i.e.,
8081 /// `is_cjk` = `false`) if the locale is unknown.
81- // fn width(&self, is_cjk: bool) -> uint;
82+ fn width ( & self , is_cjk : bool ) -> uint ;
8283
8384 /// Returns a string with leading and trailing whitespace removed.
8485 fn trim ( & self ) -> & ' a str ;
@@ -102,6 +103,11 @@ impl<'a> UnicodeStrSlice<'a> for &'a str {
102103 #[ inline]
103104 fn is_alphanumeric ( & self ) -> bool { self . chars ( ) . all ( u_char:: is_alphanumeric) }
104105
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+
105111 #[ inline]
106112 fn trim ( & self ) -> & ' a str {
107113 self . trim_left ( ) . trim_right ( )
0 commit comments