]> git.lizzy.rs Git - rust.git/commitdiff
unicode: Add stability attributes to u_char
authorBrian Anderson <banderson@mozilla.com>
Mon, 3 Nov 2014 18:22:34 +0000 (10:22 -0800)
committerBrian Anderson <banderson@mozilla.com>
Fri, 21 Nov 2014 21:18:08 +0000 (13:18 -0800)
Free functions deprecated. UnicodeChar experimental pending
final decisions about prelude.

src/libfmt_macros/lib.rs
src/libgetopts/lib.rs
src/librustc_trans/back/link.rs
src/librustdoc/test.rs
src/libsyntax/parse/lexer/mod.rs
src/libunicode/u_char.rs
src/libunicode/u_str.rs

index 134819ad0275709535e6fb62484c6d4b0fa9a2d7..ed86ad52bb5d4d8089df5fc6fa432db276bd5d41 100644 (file)
@@ -26,7 +26,6 @@
 pub use self::Flag::*;
 pub use self::Count::*;
 
-use std::char;
 use std::str;
 use std::string;
 
@@ -221,7 +220,7 @@ fn must_consume(&mut self, c: char) {
     fn ws(&mut self) {
         loop {
             match self.cur.clone().next() {
-                Some((_, c)) if char::is_whitespace(c) => { self.cur.next(); }
+                Some((_, c)) if c.is_whitespace() => { self.cur.next(); }
                 Some(..) | None => { return }
             }
         }
@@ -261,7 +260,7 @@ fn position(&mut self) -> Position<'a> {
             Some(i) => { ArgumentIs(i) }
             None => {
                 match self.cur.clone().next() {
-                    Some((_, c)) if char::is_alphabetic(c) => {
+                    Some((_, c)) if c.is_alphabetic() => {
                         ArgumentNamed(self.word())
                     }
                     _ => ArgumentNext
@@ -384,7 +383,7 @@ fn count(&mut self) -> Count<'a> {
     /// characters.
     fn word(&mut self) -> &'a str {
         let start = match self.cur.clone().next() {
-            Some((pos, c)) if char::is_XID_start(c) => {
+            Some((pos, c)) if c.is_XID_start() => {
                 self.cur.next();
                 pos
             }
@@ -393,7 +392,7 @@ fn word(&mut self) -> &'a str {
         let mut end;
         loop {
             match self.cur.clone().next() {
-                Some((_, c)) if char::is_XID_continue(c) => {
+                Some((_, c)) if c.is_XID_continue() => {
                     self.cur.next();
                 }
                 Some((pos, _)) => { end = pos; break }
index c4d712cb673620f24a64eeecbf6e41a1db9b3801..a182f582b5f34bcd54d0aec013f5933f114e736d 100644 (file)
@@ -886,7 +886,7 @@ fn each_split_within<'a>(ss: &'a str, lim: uint, it: |&'a str| -> bool)
     }
 
     let machine: |&mut bool, (uint, char)| -> bool = |cont, (i, c)| {
-        let whitespace = if ::std::char::is_whitespace(c) { Ws }       else { Cr };
+        let whitespace = if c.is_whitespace() { Ws }       else { Cr };
         let limit      = if (i - slice_start + 1) <= lim  { UnderLim } else { OverLim };
 
         state = match (state, whitespace, limit) {
index 6a8074b99585cacfa97d4a684e30122fa186f82b..db9ebac163c737a85a86cf9a940942e6bfc72c0d 100644 (file)
@@ -27,7 +27,6 @@
 use util::ppaux;
 use util::sha2::{Digest, Sha256};
 
-use std::char;
 use std::io::fs::PathExtensions;
 use std::io::{fs, TempDir, Command};
 use std::io;
@@ -272,7 +271,7 @@ pub fn sanitize(s: &str) -> String {
     // Underscore-qualify anything that didn't start as an ident.
     if result.len() > 0u &&
         result.as_bytes()[0] != '_' as u8 &&
-        ! char::is_XID_start(result.as_bytes()[0] as char) {
+        ! (result.as_bytes()[0] as char).is_XID_start() {
         return format!("_{}", result.as_slice());
     }
 
index 2dc1bcf776eb8d74c12bef9cc6d65592e7ff962d..63007cf15c651da3e9363edfac647f536ab53820 100644 (file)
@@ -9,7 +9,6 @@
 // except according to those terms.
 
 use std::cell::RefCell;
-use std::char;
 use std::dynamic_lib::DynamicLibrary;
 use std::io::{Command, TempDir};
 use std::io;
@@ -300,8 +299,8 @@ pub fn register_header(&mut self, name: &str, level: u32) {
             // we use these headings as test names, so it's good if
             // they're valid identifiers.
             let name = name.chars().enumerate().map(|(i, c)| {
-                    if (i == 0 && char::is_XID_start(c)) ||
-                        (i != 0 && char::is_XID_continue(c)) {
+                    if (i == 0 && c.is_XID_start()) ||
+                        (i != 0 && c.is_XID_continue()) {
                         c
                     } else {
                         '_'
index 4c759cfc4fd0abbd6ea5820b7e05ffa06176c180..9b3e25c5851c9a10f94dfc59025312d2782dd65d 100644 (file)
@@ -1385,7 +1385,7 @@ fn ident_start(c: Option<char>) -> bool {
     (c >= 'a' && c <= 'z')
         || (c >= 'A' && c <= 'Z')
         || c == '_'
-        || (c > '\x7f' && char::is_XID_start(c))
+        || (c > '\x7f' && c.is_XID_start())
 }
 
 fn ident_continue(c: Option<char>) -> bool {
@@ -1395,7 +1395,7 @@ fn ident_continue(c: Option<char>) -> bool {
         || (c >= 'A' && c <= 'Z')
         || (c >= '0' && c <= '9')
         || c == '_'
-        || (c > '\x7f' && char::is_XID_continue(c))
+        || (c > '\x7f' && c.is_XID_continue())
 }
 
 #[cfg(test)]
index 1e81916a2c6e0bb221faee3cb2298e7b40c969ae..f347ab6a21e22098ffe30e017965e9de7d02d144 100644 (file)
 
 /// Returns whether the specified `char` is considered a Unicode alphabetic
 /// code point
+#[deprecated = "use UnicodeChar::is_alphabetic"]
 pub fn is_alphabetic(c: char) -> bool {
-    match c {
-        'a' ... 'z' | 'A' ... 'Z' => true,
-        c if c > '\x7f' => derived_property::Alphabetic(c),
-        _ => false
-    }
+    c.is_alphabetic()
 }
 
 /// Returns whether the specified `char` satisfies the 'XID_Start' Unicode property
@@ -34,6 +31,7 @@ pub fn is_alphabetic(c: char) -> bool {
 /// [UAX #31](http://unicode.org/reports/tr31/#NFKC_Modifications),
 /// mostly similar to ID_Start but modified for closure under NFKx.
 #[allow(non_snake_case)]
+#[deprecated = "use UnicodeChar::is_XID_start"]
 pub fn is_XID_start(c: char) -> bool    { derived_property::XID_Start(c) }
 
 /// Returns whether the specified `char` satisfies the 'XID_Continue' Unicode property
@@ -42,6 +40,7 @@ pub fn is_XID_start(c: char) -> bool    { derived_property::XID_Start(c) }
 /// [UAX #31](http://unicode.org/reports/tr31/#NFKC_Modifications),
 /// mostly similar to 'ID_Continue' but modified for closure under NFKx.
 #[allow(non_snake_case)]
+#[deprecated = "use UnicodeChar::is_XID_continue"]
 pub fn is_XID_continue(c: char) -> bool { derived_property::XID_Continue(c) }
 
 ///
@@ -50,12 +49,9 @@ pub fn is_XID_continue(c: char) -> bool { derived_property::XID_Continue(c) }
 /// This is defined according to the terms of the Unicode Derived Core Property 'Lowercase'.
 ///
 #[inline]
+#[deprecated = "use UnicodeChar::is_lowercase"]
 pub fn is_lowercase(c: char) -> bool {
-    match c {
-        'a' ... 'z' => true,
-        c if c > '\x7f' => derived_property::Lowercase(c),
-        _ => false
-    }
+    c.is_lowercase()
 }
 
 ///
@@ -64,12 +60,9 @@ pub fn is_lowercase(c: char) -> bool {
 /// This is defined according to the terms of the Unicode Derived Core Property 'Uppercase'.
 ///
 #[inline]
+#[deprecated = "use UnicodeChar::is_uppercase"]
 pub fn is_uppercase(c: char) -> bool {
-    match c {
-        'A' ... 'Z' => true,
-        c if c > '\x7f' => derived_property::Uppercase(c),
-        _ => false
-    }
+    c.is_uppercase()
 }
 
 ///
@@ -78,12 +71,9 @@ pub fn is_uppercase(c: char) -> bool {
 /// Whitespace is defined in terms of the Unicode Property 'White_Space'.
 ///
 #[inline]
+#[deprecated = "use UnicodeChar::is_whitespace"]
 pub fn is_whitespace(c: char) -> bool {
-    match c {
-        ' ' | '\x09' ... '\x0d' => true,
-        c if c > '\x7f' => property::White_Space(c),
-        _ => false
-    }
+    c.is_whitespace()
 }
 
 ///
@@ -93,9 +83,9 @@ pub fn is_whitespace(c: char) -> bool {
 /// 'Nd', 'Nl', 'No' and the Derived Core Property 'Alphabetic'.
 ///
 #[inline]
+#[deprecated = "use UnicodeChar::is_alphanumeric"]
 pub fn is_alphanumeric(c: char) -> bool {
-    is_alphabetic(c)
-        || is_digit(c)
+    c.is_alphanumeric()
 }
 
 ///
@@ -105,16 +95,14 @@ pub fn is_alphanumeric(c: char) -> bool {
 /// 'Cc'.
 ///
 #[inline]
+#[deprecated = "use UnicodeChar::is_control"]
 pub fn is_control(c: char) -> bool { general_category::Cc(c) }
 
 /// Indicates whether the `char` is numeric (Nd, Nl, or No)
 #[inline]
+#[deprecated = "use UnicodeChar::is_numeric"]
 pub fn is_digit(c: char) -> bool {
-    match c {
-        '0' ... '9' => true,
-        c if c > '\x7f' => general_category::N(c),
-        _ => false
-    }
+    c.is_numeric()
 }
 
 /// Convert a char to its uppercase equivalent
@@ -132,6 +120,7 @@ pub fn is_digit(c: char) -> bool {
 ///
 /// Returns the char itself if no conversion was made
 #[inline]
+#[deprecated = "use UnicodeChar::to_uppercase"]
 pub fn to_uppercase(c: char) -> char {
     conversions::to_upper(c)
 }
@@ -145,6 +134,7 @@ pub fn to_uppercase(c: char) -> char {
 ///
 /// Returns the char itself if no conversion if possible
 #[inline]
+#[deprecated = "use UnicodeChar::to_lowercase"]
 pub fn to_lowercase(c: char) -> char {
     conversions::to_lower(c)
 }
@@ -158,11 +148,13 @@ pub fn to_lowercase(c: char) -> char {
 /// [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/)
 /// recommends that these characters be treated as 1 column (i.e.,
 /// `is_cjk` = `false`) if the context cannot be reliably determined.
+#[deprecated = "use UnicodeChar::width"]
 pub fn width(c: char, is_cjk: bool) -> Option<uint> {
     charwidth::width(c, is_cjk)
 }
 
 /// Useful functions for Unicode characters.
+#[experimental = "pending prelude organization"]
 pub trait UnicodeChar {
     /// Returns whether the specified character is considered a Unicode
     /// alphabetic code point.
@@ -265,29 +257,62 @@ pub trait UnicodeChar {
     fn width(self, is_cjk: bool) -> Option<uint>;
 }
 
+#[experimental = "pending prelude organization"]
 impl UnicodeChar for char {
-    fn is_alphabetic(self) -> bool { is_alphabetic(self) }
+    fn is_alphabetic(self) -> bool {
+        match self {
+            'a' ... 'z' | 'A' ... 'Z' => true,
+            c if c > '\x7f' => derived_property::Alphabetic(c),
+            _ => false
+        }
+    }
 
-    fn is_XID_start(self) -> bool { is_XID_start(self) }
+    fn is_XID_start(self) -> bool { derived_property::XID_Start(self) }
 
-    fn is_XID_continue(self) -> bool { is_XID_continue(self) }
+    fn is_XID_continue(self) -> bool { derived_property::XID_Continue(self) }
 
-    fn is_lowercase(self) -> bool { is_lowercase(self) }
+    fn is_lowercase(self) -> bool {
+        match self {
+            'a' ... 'z' => true,
+            c if c > '\x7f' => derived_property::Lowercase(c),
+            _ => false
+        }
+    }
 
-    fn is_uppercase(self) -> bool { is_uppercase(self) }
+    fn is_uppercase(self) -> bool {
+        match self {
+            'A' ... 'Z' => true,
+            c if c > '\x7f' => derived_property::Uppercase(c),
+            _ => false
+        }
+    }
 
-    fn is_whitespace(self) -> bool { is_whitespace(self) }
+    fn is_whitespace(self) -> bool {
+        match self {
+            ' ' | '\x09' ... '\x0d' => true,
+            c if c > '\x7f' => property::White_Space(c),
+            _ => false
+        }
+    }
 
-    fn is_alphanumeric(self) -> bool { is_alphanumeric(self) }
+    fn is_alphanumeric(self) -> bool {
+        self.is_alphabetic() || self.is_numeric()
+    }
 
-    fn is_control(self) -> bool { is_control(self) }
+    fn is_control(self) -> bool { general_category::Cc(self) }
 
-    fn is_numeric(self) -> bool { is_digit(self) }
+    fn is_numeric(self) -> bool {
+        match self {
+            '0' ... '9' => true,
+            c if c > '\x7f' => general_category::N(c),
+            _ => false
+        }
+    }
 
-    fn to_lowercase(self) -> char { to_lowercase(self) }
+    fn to_lowercase(self) -> char { conversions::to_lower(self) }
 
-    fn to_uppercase(self) -> char { to_uppercase(self) }
+    fn to_uppercase(self) -> char { conversions::to_upper(self) }
 
     #[experimental = "needs expert opinion. is_cjk flag stands out as ugly"]
-    fn width(self, is_cjk: bool) -> Option<uint> { width(self, is_cjk) }
+    fn width(self, is_cjk: bool) -> Option<uint> { charwidth::width(self, is_cjk) }
 }
index 99c1ce503cc4d82eba3836e8c8dac0d71e581863..56b1f0907d5a4c4c4338042f23d87fc092316936 100644 (file)
 use core::kinds::Sized;
 use core::option::{Option, None, Some};
 use core::str::{CharSplits, StrPrelude};
-use u_char;
 use u_char::UnicodeChar;
 use tables::grapheme::GraphemeCat;
 
 /// An iterator over the words of a string, separated by a sequence of whitespace
+/// FIXME: This should be opaque
 pub type Words<'a> =
-    Filter<'a, &'a str, CharSplits<'a, extern "Rust" fn(char) -> bool>>;
+    Filter<'a, &'a str, CharSplits<'a, |char|:'a -> bool>>;
 
 /// Methods for Unicode string slices
 pub trait UnicodeStrPrelude for Sized? {
@@ -143,14 +143,15 @@ fn grapheme_indices(&self, is_extended: bool) -> GraphemeIndices {
 
     #[inline]
     fn words(&self) -> Words {
-        self.split(u_char::is_whitespace).filter(|s| !s.is_empty())
+        let f = |c: char| c.is_whitespace();
+        self.split(f).filter(|s| !s.is_empty())
     }
 
     #[inline]
-    fn is_whitespace(&self) -> bool { self.chars().all(u_char::is_whitespace) }
+    fn is_whitespace(&self) -> bool { self.chars().all(|c| c.is_whitespace()) }
 
     #[inline]
-    fn is_alphanumeric(&self) -> bool { self.chars().all(u_char::is_alphanumeric) }
+    fn is_alphanumeric(&self) -> bool { self.chars().all(|c| c.is_alphanumeric()) }
 
     #[inline]
     fn width(&self, is_cjk: bool) -> uint {
@@ -164,12 +165,12 @@ fn trim(&self) -> &str {
 
     #[inline]
     fn trim_left(&self) -> &str {
-        self.trim_left_chars(u_char::is_whitespace)
+        self.trim_left_chars(|c: char| c.is_whitespace())
     }
 
     #[inline]
     fn trim_right(&self) -> &str {
-        self.trim_right_chars(u_char::is_whitespace)
+        self.trim_right_chars(|c: char| c.is_whitespace())
     }
 }