]> git.lizzy.rs Git - rust.git/commitdiff
Merge `UnicodeChar` and `CharExt`.
authorHuon Wilson <dbau.pp+github@gmail.com>
Tue, 30 Dec 2014 02:58:31 +0000 (13:58 +1100)
committerHuon Wilson <dbau.pp+github@gmail.com>
Mon, 5 Jan 2015 01:30:51 +0000 (12:30 +1100)
This "reexports" all the functionality of `core::char::CharExt` as
methods on `unicode::u_char::UnicodeChar` (renamed to `CharExt`).

Imports may need to be updated (one now just imports
`unicode::CharExt`, or `std::char::CharExt` rather than two traits from
either), so this is a

[breaking-change]

src/libcollections/lib.rs
src/libstd/io/mod.rs
src/libstd/num/strconv.rs
src/libstd/path/windows.rs
src/libstd/prelude/v1.rs
src/libunicode/lib.rs
src/libunicode/tables.rs
src/libunicode/u_char.rs
src/libunicode/u_str.rs

index bf3b35b4f6817a86eedb7533dc2f02582fd344b3..db2367950387b4a125d74446770a90fb07e6dc35 100644 (file)
@@ -103,7 +103,6 @@ mod std {
 mod prelude {
     // from core.
     pub use core::borrow::IntoCow;
-    pub use core::char::CharExt;
     pub use core::clone::Clone;
     pub use core::cmp::{PartialEq, Eq, PartialOrd, Ord};
     pub use core::cmp::Ordering::{Less, Equal, Greater};
@@ -127,7 +126,7 @@ mod prelude {
 
     // from other crates.
     pub use alloc::boxed::Box;
-    pub use unicode::char::UnicodeChar;
+    pub use unicode::char::CharExt;
 
     // from collections.
     pub use slice::SliceConcatExt;
index 51bf206f70e9f55dbb6bb5ccb3f7afbaf7639507..3fa0b5645c5288fba7b0ccc61a802ac7b20e88d8 100644 (file)
 use string::String;
 use uint;
 use unicode;
-use unicode::char::UnicodeChar;
 use vec::Vec;
 
 // Reexports
index 20dd70f0faab2ff756a6a3c8c757731ab77cdc9d..67fe599ecd6bfcbfe588a06620d64748fa16bd8a 100644 (file)
@@ -16,7 +16,7 @@
 use self::SignificantDigits::*;
 use self::SignFormat::*;
 
-use char::{self, Char};
+use char::{self, CharExt};
 use num::{self, Int, Float, ToPrimitive};
 use num::FpCategory as Fp;
 use ops::FnMut;
index aae8d6cadefb22935ae2e876548392cf11593b7e..cf8bc0e6242b312752e0ac621563ead9f994d2a5 100644 (file)
@@ -16,6 +16,7 @@
 
 use ascii::AsciiExt;
 use c_str::{CString, ToCStr};
+use char::CharExt;
 use clone::Clone;
 use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
 use hash;
@@ -28,7 +29,6 @@
 use slice::{SliceExt, SliceConcatExt};
 use str::{SplitTerminator, FromStr, StrExt};
 use string::{String, ToString};
-use unicode::char::UnicodeChar;
 use vec::Vec;
 
 use super::{contains_nul, BytesContainer, GenericPath, GenericPathUnsafe};
index eda20fc7d603fc54b43fe9f31a733a7884d7faca..f6bdcd53dff24c29dd68528d1f45ebbb427e051f 100644 (file)
@@ -22,7 +22,7 @@
 // Reexported types and traits
 
 #[stable] #[doc(no_inline)] pub use boxed::Box;
-#[stable] #[doc(no_inline)] pub use char::{CharExt, UnicodeChar};
+#[stable] #[doc(no_inline)] pub use char::CharExt;
 #[stable] #[doc(no_inline)] pub use clone::Clone;
 #[stable] #[doc(no_inline)] pub use cmp::{PartialEq, PartialOrd, Eq, Ord};
 #[stable] #[doc(no_inline)] pub use iter::CloneIteratorExt;
index 170700fb4d5fe207dddcd65137f216de87be5249..a3884d0c86e1de78a708508117d6a611e598b3c1 100644 (file)
@@ -44,9 +44,9 @@
 // re-export char so that std et al see it correctly
 /// Character manipulation (`char` type, Unicode Scalar Value)
 ///
-/// This module  provides the `Char` and `UnicodeChar` traits, as well as their
-/// implementation for the primitive `char` type, in order to allow basic character
-/// manipulation.
+/// This module provides the `CharExt` trait, as well as its
+/// implementation for the primitive `char` type, in order to allow
+/// basic character manipulation.
 ///
 /// A `char` actually represents a
 /// *[Unicode Scalar Value](http://www.unicode.org/glossary/#unicode_scalar_value)*,
 /// however the converse is not always true due to the above range limits
 /// and, as such, should be performed via the `from_u32` function..
 pub mod char {
-    pub use core::char::{MAX, from_u32, from_digit, CharExt};
+    pub use core::char::{MAX, from_u32, from_digit};
 
     pub use normalize::{decompose_canonical, decompose_compatible, compose};
 
     pub use tables::normalization::canonical_combining_class;
     pub use tables::UNICODE_VERSION;
 
-    pub use u_char::UnicodeChar;
+    pub use u_char::CharExt;
 }
 
 pub mod str {
index e3550810010b5db482919b044769810602100445..c755ea93184028fb9f068c2a0b83a902ddbd1752 100644 (file)
@@ -13,7 +13,7 @@
 #![allow(missing_docs, non_upper_case_globals, non_snake_case)]
 
 /// The version of [Unicode](http://www.unicode.org/)
-/// that the `UnicodeChar` and `UnicodeStrPrelude` traits are based on.
+/// that the unicode parts of `CharExt` and `UnicodeStrPrelude` traits are based on.
 pub const UNICODE_VERSION: (uint, uint, uint) = (7, 0, 0);
 
 fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
index 9c356801604dd44fd95c671eb127f511c526255d..c1abfd4e189987a5b8df329278ed34c43d5597f7 100644 (file)
@@ -8,17 +8,99 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-//! Unicode-intensive `char` methods.
+//! Unicode-intensive `char` methods along with the `core` methods.
 //!
 //! These methods implement functionality for `char` that requires knowledge of
 //! Unicode definitions, including normalization, categorization, and display information.
 
+use core::char;
+use core::char::CharExt as C;
 use core::option::Option;
 use tables::{derived_property, property, general_category, conversions, charwidth};
 
-/// Useful functions for Unicode characters.
+/// Functionality for manipulating `char`.
 #[experimental = "pending prelude organization"]
-pub trait UnicodeChar {
+pub trait CharExt {
+    /// Checks if a `char` parses as a numeric digit in the given radix.
+    ///
+    /// Compared to `is_numeric()`, this function only recognizes the characters
+    /// `0-9`, `a-z` and `A-Z`.
+    ///
+    /// # Return value
+    ///
+    /// Returns `true` if `c` is a valid digit under `radix`, and `false`
+    /// otherwise.
+    ///
+    /// # Panics
+    ///
+    /// Panics if given a radix > 36.
+    #[unstable = "pending integer conventions"]
+    fn is_digit(self, radix: uint) -> bool;
+
+    /// Converts a character to the corresponding digit.
+    ///
+    /// # Return value
+    ///
+    /// If `c` is between '0' and '9', the corresponding value between 0 and
+    /// 9. If `c` is 'a' or 'A', 10. If `c` is 'b' or 'B', 11, etc. Returns
+    /// none if the character does not refer to a digit in the given radix.
+    ///
+    /// # Panics
+    ///
+    /// Panics if given a radix outside the range [0..36].
+    #[unstable = "pending integer conventions"]
+    fn to_digit(self, radix: uint) -> Option<uint>;
+
+    /// Returns an iterator that yields the hexadecimal Unicode escape
+    /// of a character, as `char`s.
+    ///
+    /// All characters are escaped with Rust syntax of the form `\\u{NNNN}`
+    /// where `NNNN` is the shortest hexadecimal representation of the code
+    /// point.
+    #[stable]
+    fn escape_unicode(self) -> char::EscapeUnicode;
+
+    /// Returns an iterator that yields the 'default' ASCII and
+    /// C++11-like literal escape of a character, as `char`s.
+    ///
+    /// The default is chosen with a bias toward producing literals that are
+    /// legal in a variety of languages, including C++11 and similar C-family
+    /// languages. The exact rules are:
+    ///
+    /// * Tab, CR and LF are escaped as '\t', '\r' and '\n' respectively.
+    /// * Single-quote, double-quote and backslash chars are backslash-
+    ///   escaped.
+    /// * Any other chars in the range [0x20,0x7e] are not escaped.
+    /// * Any other chars are given hex Unicode escapes; see `escape_unicode`.
+    #[stable]
+    fn escape_default(self) -> char::EscapeDefault;
+
+    /// Returns the amount of bytes this character would need if encoded in
+    /// UTF-8.
+    #[stable]
+    fn len_utf8(self) -> uint;
+
+    /// Returns the amount of bytes this character would need if encoded in
+    /// UTF-16.
+    #[stable]
+    fn len_utf16(self) -> uint;
+
+    /// Encodes this character as UTF-8 into the provided byte buffer,
+    /// and then returns the number of bytes written.
+    ///
+    /// If the buffer is not large enough, nothing will be written into it
+    /// and a `None` will be returned.
+    #[unstable = "pending decision about Iterator/Writer/Reader"]
+    fn encode_utf8(self, dst: &mut [u8]) -> Option<uint>;
+
+    /// Encodes this character as UTF-16 into the provided `u16` buffer,
+    /// and then returns the number of `u16`s written.
+    ///
+    /// If the buffer is not large enough, nothing will be written into it
+    /// and a `None` will be returned.
+    #[unstable = "pending decision about Iterator/Writer/Reader"]
+    fn encode_utf16(self, dst: &mut [u16]) -> Option<uint>;
+
     /// Returns whether the specified character is considered a Unicode
     /// alphabetic code point.
     fn is_alphabetic(self) -> bool;
@@ -118,7 +200,24 @@ pub trait UnicodeChar {
 }
 
 #[experimental = "pending prelude organization"]
-impl UnicodeChar for char {
+impl CharExt for char {
+    #[unstable = "pending integer conventions"]
+    fn is_digit(self, radix: uint) -> bool { C::is_digit(self, radix) }
+    #[unstable = "pending integer conventions"]
+    fn to_digit(self, radix: uint) -> Option<uint> { C::to_digit(self, radix) }
+    #[stable]
+    fn escape_unicode(self) -> char::EscapeUnicode { C::escape_unicode(self) }
+    #[stable]
+    fn escape_default(self) -> char::EscapeDefault { C::escape_default(self) }
+    #[stable]
+    fn len_utf8(self) -> uint { C::len_utf8(self) }
+    #[stable]
+    fn len_utf16(self) -> uint { C::len_utf16(self) }
+    #[unstable = "pending decision about Iterator/Writer/Reader"]
+    fn encode_utf8(self, dst: &mut [u8]) -> Option<uint> { C::encode_utf8(self, dst) }
+    #[unstable = "pending decision about Iterator/Writer/Reader"]
+    fn encode_utf16(self, dst: &mut [u16]) -> Option<uint> { C::encode_utf16(self, dst) }
+
     fn is_alphabetic(self) -> bool {
         match self {
             'a' ... 'z' | 'A' ... 'Z' => true,
index 1b0c4171134ed03631ab2a1b394adcfc5e603d9c..90949437774f107c3f1aa463af994ed7f2ce9170 100644 (file)
@@ -13,7 +13,7 @@
 //! Unicode-intensive string manipulations.
 //!
 //! This module provides functionality to `str` that requires the Unicode methods provided by the
-//! UnicodeChar trait.
+//! unicode parts of the CharExt trait.
 
 use self::GraphemeState::*;
 use core::prelude::*;
@@ -26,7 +26,7 @@
 use core::slice;
 use core::str::Split;
 
-use u_char::UnicodeChar;
+use u_char::CharExt as UCharExt; // conflicts with core::prelude::CharExt
 use tables::grapheme::GraphemeCat;
 
 /// An iterator over the words of a string, separated by a sequence of whitespace
@@ -529,7 +529,7 @@ fn next(&mut self) -> Option<u16> {
 
         let mut buf = [0u16; 2];
         self.chars.next().map(|ch| {
-            let n = ch.encode_utf16(buf.as_mut_slice()).unwrap_or(0);
+            let n = CharExt::encode_utf16(ch, buf.as_mut_slice()).unwrap_or(0);
             if n == 2 { self.extra = buf[1]; }
             buf[0]
         })