summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-09-25 03:55:56 -0700
committerbors <bors@rust-lang.org>2013-09-25 03:55:56 -0700
commitdf97d23c71f6fbe300d3bc0dca23b063044b3934 (patch)
treec547494b35d37a114e61d19f16a5a5dd792f7a7e
parentf6c9ff392becd86ee22ad96cd66e137b65195f97 (diff)
parent13571af92fc8f2aa115ce1fcb8b82b5f654e5780 (diff)
downloadrust-df97d23c71f6fbe300d3bc0dca23b063044b3934.tar.gz
rust-df97d23c71f6fbe300d3bc0dca23b063044b3934.zip
auto merge of #9455 : jesseray/rust/master, r=pnkfelix
In "/src/libstd/char.rs", there are function and method definitions for `is_lowercase()`, `is_uppercase()`, `is_whitespace()`, etc. However, there was no function or method for control characters, so I added the `is_control()` function and method definitions along with documentation and tests. Running `./configure && make check` shows that all tests for `is_control()` pass.
-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());