@@ -128,6 +128,14 @@ pub fn is_alphanumeric(c: char) -> bool {
128
128
|| general_category:: No ( c)
129
129
}
130
130
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
+
131
139
/// Indicates whether the character is numeric (Nd, Nl, or No)
132
140
#[ inline]
133
141
pub fn is_digit ( c : char ) -> bool {
@@ -354,6 +362,7 @@ pub trait Char {
354
362
fn is_uppercase ( & self ) -> bool ;
355
363
fn is_whitespace ( & self ) -> bool ;
356
364
fn is_alphanumeric ( & self ) -> bool ;
365
+ fn is_control ( & self ) -> bool ;
357
366
fn is_digit ( & self ) -> bool ;
358
367
fn is_digit_radix ( & self , radix : uint ) -> bool ;
359
368
fn to_digit ( & self , radix : uint ) -> Option < uint > ;
@@ -384,6 +393,8 @@ impl Char for char {
384
393
385
394
fn is_alphanumeric ( & self ) -> bool { is_alphanumeric ( * self ) }
386
395
396
+ fn is_control ( & self ) -> bool { is_control ( * self ) }
397
+
387
398
fn is_digit ( & self ) -> bool { is_digit ( * self ) }
388
399
389
400
fn is_digit_radix ( & self , radix : uint ) -> bool { is_digit_radix ( * self , radix) }
@@ -494,6 +505,19 @@ fn test_to_digit() {
494
505
assert_eq ! ( '$' . to_digit( 36 u) , None ) ;
495
506
}
496
507
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
+
497
521
#[ test]
498
522
fn test_is_digit ( ) {
499
523
assert ! ( '2' . is_digit( ) ) ;
0 commit comments