about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorJesse Ray <jesse@localhost.localdomain>2013-09-23 17:10:48 -0400
committerJesse Ray <jesse@localhost.localdomain>2013-09-23 17:10:48 -0400
commit13571af92fc8f2aa115ce1fcb8b82b5f654e5780 (patch)
tree7d2270f62d693836512f4aeae4dbf712d8ac0eab /src/libstd
parenteb55348a7cb1d99563c9135b8c83bcc20f6346bf (diff)
downloadrust-13571af92fc8f2aa115ce1fcb8b82b5f654e5780.tar.gz
rust-13571af92fc8f2aa115ce1fcb8b82b5f654e5780.zip
Added is_control function, method, and tests.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/char.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/libstd/char.rs b/src/libstd/char.rs
index 431fc27a202..abb1ac5ace8 100644
--- a/src/libstd/char.rs
+++ b/src/libstd/char.rs
@@ -128,6 +128,14 @@ pub fn is_alphanumeric(c: char) -> bool {
         || general_category::No(c)
 }
 
+///
+/// Indicates whether a character is a control character. Control
+/// characters are defined in terms of the Unicode General Category
+/// 'Cc'.
+///
+#[inline]
+pub fn is_control(c: char) -> bool { general_category::Cc(c) }
+
 /// Indicates whether the character is numeric (Nd, Nl, or No)
 #[inline]
 pub fn is_digit(c: char) -> bool {
@@ -354,6 +362,7 @@ pub trait Char {
     fn is_uppercase(&self) -> bool;
     fn is_whitespace(&self) -> bool;
     fn is_alphanumeric(&self) -> bool;
+    fn is_control(&self) -> bool;
     fn is_digit(&self) -> bool;
     fn is_digit_radix(&self, radix: uint) -> bool;
     fn to_digit(&self, radix: uint) -> Option<uint>;
@@ -384,6 +393,8 @@ impl Char for char {
 
     fn is_alphanumeric(&self) -> bool { is_alphanumeric(*self) }
 
+    fn is_control(&self) -> bool { is_control(*self) }
+
     fn is_digit(&self) -> bool { is_digit(*self) }
 
     fn is_digit_radix(&self, radix: uint) -> bool { is_digit_radix(*self, radix) }
@@ -495,6 +506,19 @@ fn test_to_digit() {
 }
 
 #[test]
+fn test_is_control() {
+    assert!('\u0000'.is_control());
+    assert!('\u0003'.is_control());
+    assert!('\u0006'.is_control());
+    assert!('\u0009'.is_control());
+    assert!('\u007f'.is_control());
+    assert!('\u0092'.is_control());
+    assert!(!'\u0020'.is_control());
+    assert!(!'\u0055'.is_control());
+    assert!(!'\u0068'.is_control());
+}
+
+#[test]
 fn test_is_digit() {
    assert!('2'.is_digit());
    assert!('7'.is_digit());