about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorPiotr Zolnierek <pz@anixe.pl>2014-03-01 07:40:38 +0100
committerPiotr Zolnierek <pz@anixe.pl>2014-03-13 12:23:24 +0100
commitdba5625cb8e8b0d7463f23c8ec9ba5f373707ef5 (patch)
tree1b1284c24d902b0fe59855ea678725a65d6bad5d /src/libstd
parent04170b0a4166de0612d24bb3a22a133dbe99cc15 (diff)
downloadrust-dba5625cb8e8b0d7463f23c8ec9ba5f373707ef5.tar.gz
rust-dba5625cb8e8b0d7463f23c8ec9ba5f373707ef5.zip
Remove code duplication
Remove whitespace

Update documentation for to_uppercase, to_lowercase
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/char.rs14
-rw-r--r--src/libstd/unicode.rs70
2 files changed, 32 insertions, 52 deletions
diff --git a/src/libstd/char.rs b/src/libstd/char.rs
index 3fb9e47dbdc..52ca28c4ce8 100644
--- a/src/libstd/char.rs
+++ b/src/libstd/char.rs
@@ -228,11 +228,17 @@ pub fn to_digit(c: char, radix: uint) -> Option<uint> {
 /// Convert a char to its uppercase equivalent
 ///
 /// The case-folding performed is the common or simple mapping:
-/// it only maps a codepoint to its equivalent if it is also a single codepoint
+/// it maps one unicode codepoint (one char in Rust) to its uppercase equivalent according
+/// to the Unicode database at ftp://ftp.unicode.org/Public/UNIDATA/UnicodeData.txt
+/// The additional SpecialCasing.txt is not considered here, as it expands to multiple
+/// codepoints in some cases.
+///
+/// A full reference can be found here
+/// http://www.unicode.org/versions/Unicode4.0.0/ch03.pdf#G33992
 ///
 /// # Return value
 ///
-/// Returns the char itself if no conversion if possible
+/// Returns the char itself if no conversion was made
 #[inline]
 pub fn to_uppercase(c: char) -> char {
     conversions::to_upper(c)
@@ -240,8 +246,8 @@ pub fn to_uppercase(c: char) -> char {
 
 /// Convert a char to its lowercase equivalent
 ///
-/// The case-folding performed is the common or simple mapping:
-/// it only maps a codepoint to its equivalent if it is also a single codepoint
+/// The case-folding performed is the common or simple mapping
+/// see `to_uppercase` for references and more information
 ///
 /// # Return value
 ///
diff --git a/src/libstd/unicode.rs b/src/libstd/unicode.rs
index d55ddbda002..b43003f0de2 100644
--- a/src/libstd/unicode.rs
+++ b/src/libstd/unicode.rs
@@ -13,26 +13,26 @@
 #[allow(missing_doc)];
 #[allow(non_uppercase_statics)];
 
-pub mod general_category {
 
-    fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
-        use cmp::{Equal, Less, Greater};
-        use vec::ImmutableVector;
-        use option::None;
-        r.bsearch(|&(lo,hi)| {
-            if lo <= c && c <= hi { Equal }
-            else if hi < c { Less }
-            else { Greater }
-        }) != None
-    }
+fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
+    use cmp::{Equal, Less, Greater};
+    use vec::ImmutableVector;
+    use option::None;
+    r.bsearch(|&(lo,hi)| {
+        if lo <= c && c <= hi { Equal }
+        else if hi < c { Less }
+        else { Greater }
+    }) != None
+}
 
 
+pub mod general_category {
     static Cc_table : &'static [(char,char)] = &[
         ('\x00', '\x1f'), ('\x7f', '\x9f')
     ];
 
     pub fn Cc(c: char) -> bool {
-        bsearch_range_table(c, Cc_table)
+        super::bsearch_range_table(c, Cc_table)
     }
 
     static Nd_table : &'static [(char,char)] = &[
@@ -60,7 +60,7 @@ pub mod general_category {
     ];
 
     pub fn Nd(c: char) -> bool {
-        bsearch_range_table(c, Nd_table)
+        super::bsearch_range_table(c, Nd_table)
     }
 
     static Nl_table : &'static [(char,char)] = &[
@@ -73,7 +73,7 @@ pub mod general_category {
     ];
 
     pub fn Nl(c: char) -> bool {
-        bsearch_range_table(c, Nl_table)
+        super::bsearch_range_table(c, Nl_table)
     }
 
     static No_table : &'static [(char,char)] = &[
@@ -101,7 +101,7 @@ pub mod general_category {
     ];
 
     pub fn No(c: char) -> bool {
-        bsearch_range_table(c, No_table)
+        super::bsearch_range_table(c, No_table)
     }
 
 }
@@ -2323,19 +2323,6 @@ pub mod decompose {
 }
 
 pub mod derived_property {
-
-    fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
-        use cmp::{Equal, Less, Greater};
-        use vec::ImmutableVector;
-        use option::None;
-        r.bsearch(|&(lo,hi)| {
-            if lo <= c && c <= hi { Equal }
-            else if hi < c { Less }
-            else { Greater }
-        }) != None
-    }
-
-
     static Alphabetic_table : &'static [(char,char)] = &[
         ('\x41', '\x5a'), ('\x61', '\x7a'),
         ('\xaa', '\xaa'), ('\xb5', '\xb5'),
@@ -2745,7 +2732,7 @@ pub mod derived_property {
     ];
 
     pub fn Alphabetic(c: char) -> bool {
-        bsearch_range_table(c, Alphabetic_table)
+        super::bsearch_range_table(c, Alphabetic_table)
     }
 
     static Lowercase_table : &'static [(char,char)] = &[
@@ -3067,7 +3054,7 @@ pub mod derived_property {
     ];
 
     pub fn Lowercase(c: char) -> bool {
-        bsearch_range_table(c, Lowercase_table)
+        super::bsearch_range_table(c, Lowercase_table)
     }
 
     static Uppercase_table : &'static [(char,char)] = &[
@@ -3379,7 +3366,7 @@ pub mod derived_property {
     ];
 
     pub fn Uppercase(c: char) -> bool {
-        bsearch_range_table(c, Uppercase_table)
+        super::bsearch_range_table(c, Uppercase_table)
     }
 
     static XID_Continue_table : &'static [(char,char)] = &[
@@ -3863,7 +3850,7 @@ pub mod derived_property {
     ];
 
     pub fn XID_Continue(c: char) -> bool {
-        bsearch_range_table(c, XID_Continue_table)
+        super::bsearch_range_table(c, XID_Continue_table)
     }
 
     static XID_Start_table : &'static [(char,char)] = &[
@@ -4147,24 +4134,11 @@ pub mod derived_property {
     ];
 
     pub fn XID_Start(c: char) -> bool {
-        bsearch_range_table(c, XID_Start_table)
+        super::bsearch_range_table(c, XID_Start_table)
     }
 
 }
 pub mod property {
-
-    fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
-        use cmp::{Equal, Less, Greater};
-        use vec::ImmutableVector;
-        use option::None;
-        r.bsearch(|&(lo,hi)| {
-            if lo <= c && c <= hi { Equal }
-            else if hi < c { Less }
-            else { Greater }
-        }) != None
-    }
-
-
     static White_Space_table : &'static [(char,char)] = &[
         ('\x09', '\x0d'), ('\x20', '\x20'),
         ('\x85', '\x85'), ('\xa0', '\xa0'),
@@ -4175,7 +4149,7 @@ pub mod property {
     ];
 
     pub fn White_Space(c: char) -> bool {
-        bsearch_range_table(c, White_Space_table)
+        super::bsearch_range_table(c, White_Space_table)
     }
 
 }
@@ -4184,7 +4158,7 @@ pub mod conversions {
     use cmp::{Equal, Less, Greater};
     use vec::ImmutableVector;
     use tuple::Tuple2;
-    use option::{ Option, Some, None };
+    use option::{Option, Some, None};
 
     pub fn to_lower(c: char) -> char {
         match bsearch_case_table(c, LuLl_table) {