@@ -128,6 +128,14 @@ pub fn is_alphanumeric(c: char) -> bool {
128128 || general_category:: No ( c)
129129}
130130
131+ ///
132+ /// Indicates whether a character is a control character. Control
133+ /// characters are defined in terms of the Unicode General Category
134+ /// 'Cc'.
135+ ///
136+ #[ inline]
137+ pub fn is_control ( c : char ) -> bool { general_category:: Cc ( c) }
138+
131139/// Indicates whether the character is numeric (Nd, Nl, or No)
132140#[ inline]
133141pub fn is_digit ( c : char ) -> bool {
@@ -354,6 +362,7 @@ pub trait Char {
354362 fn is_uppercase ( & self ) -> bool ;
355363 fn is_whitespace ( & self ) -> bool ;
356364 fn is_alphanumeric ( & self ) -> bool ;
365+ fn is_control ( & self ) -> bool ;
357366 fn is_digit ( & self ) -> bool ;
358367 fn is_digit_radix ( & self , radix : uint ) -> bool ;
359368 fn to_digit ( & self , radix : uint ) -> Option < uint > ;
@@ -384,6 +393,8 @@ impl Char for char {
384393
385394 fn is_alphanumeric ( & self ) -> bool { is_alphanumeric ( * self ) }
386395
396+ fn is_control ( & self ) -> bool { is_control ( * self ) }
397+
387398 fn is_digit ( & self ) -> bool { is_digit ( * self ) }
388399
389400 fn is_digit_radix ( & self , radix : uint ) -> bool { is_digit_radix ( * self , radix) }
@@ -494,6 +505,19 @@ fn test_to_digit() {
494505 assert_eq ! ( '$' . to_digit( 36 u) , None ) ;
495506}
496507
508+ #[ test]
509+ fn test_is_control ( ) {
510+ assert ! ( '\u0000' . is_control( ) ) ;
511+ assert ! ( '\u0003' . is_control( ) ) ;
512+ assert ! ( '\u0006' . is_control( ) ) ;
513+ assert ! ( '\u0009' . is_control( ) ) ;
514+ assert ! ( '\u007f' . is_control( ) ) ;
515+ assert ! ( '\u0092' . is_control( ) ) ;
516+ assert ! ( !'\u0020' . is_control( ) ) ;
517+ assert ! ( !'\u0055' . is_control( ) ) ;
518+ assert ! ( !'\u0068' . is_control( ) ) ;
519+ }
520+
497521#[ test]
498522fn test_is_digit ( ) {
499523 assert ! ( '2' . is_digit( ) ) ;
0 commit comments