Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Second stabilisation pass of *::char #20395

Merged
merged 7 commits into from
Jan 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/libcollections/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ mod std {
mod prelude {
// from core.
pub use core::borrow::IntoCow;
pub use core::char::Char;
pub use core::clone::Clone;
pub use core::cmp::{PartialEq, Eq, PartialOrd, Ord};
pub use core::cmp::Ordering::{Less, Equal, Greater};
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use self::RecompositionState::*;
use self::DecompositionType::*;

use core::borrow::{BorrowFrom, ToOwned};
use core::char::Char;
use core::char::CharExt;
use core::clone::Clone;
use core::iter::AdditiveIterator;
use core::iter::{range, Iterator, IteratorExt};
Expand Down
65 changes: 33 additions & 32 deletions src/libcore/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub const MAX: char = '\u{10ffff}';

/// Converts from `u32` to a `char`
#[inline]
#[unstable = "pending decisions about costructors for primitives"]
#[stable]
pub fn from_u32(i: u32) -> Option<char> {
// catch out-of-bounds and surrogates
if (i > MAX as u32) || (i >= 0xD800 && i <= 0xDFFF) {
Expand All @@ -92,7 +92,7 @@ pub fn from_u32(i: u32) -> Option<char> {
/// Panics if given an `radix` > 36.
///
#[inline]
#[unstable = "pending decisions about costructors for primitives"]
#[unstable = "pending integer conventions"]
pub fn from_digit(num: uint, radix: uint) -> Option<char> {
if radix > 36 {
panic!("from_digit: radix is too high (maximum 36)");
Expand All @@ -111,8 +111,8 @@ pub fn from_digit(num: uint, radix: uint) -> Option<char> {
}

/// Basic `char` manipulations.
#[experimental = "trait organization may change"]
pub trait Char {
#[stable]
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
Expand All @@ -126,7 +126,7 @@ pub trait Char {
/// # Panics
///
/// Panics if given a radix > 36.
#[unstable = "pending error conventions"]
#[unstable = "pending integer conventions"]
fn is_digit(self, radix: uint) -> bool;

/// Converts a character to the corresponding digit.
Expand All @@ -140,7 +140,7 @@ pub trait Char {
/// # Panics
///
/// Panics if given a radix outside the range [0..36].
#[unstable = "pending error conventions, trait organization"]
#[unstable = "pending integer conventions"]
fn to_digit(self, radix: uint) -> Option<uint>;

/// Returns an iterator that yields the hexadecimal Unicode escape
Expand All @@ -149,7 +149,7 @@ pub trait Char {
/// All characters are escaped with Rust syntax of the form `\\u{NNNN}`
/// where `NNNN` is the shortest hexadecimal representation of the code
/// point.
#[unstable = "pending error conventions, trait organization"]
#[stable]
fn escape_unicode(self) -> EscapeUnicode;

/// Returns an iterator that yields the 'default' ASCII and
Expand All @@ -164,47 +164,44 @@ pub trait Char {
/// escaped.
/// * Any other chars in the range [0x20,0x7e] are not escaped.
/// * Any other chars are given hex Unicode escapes; see `escape_unicode`.
#[unstable = "pending error conventions, trait organization"]
#[stable]
fn escape_default(self) -> EscapeDefault;

/// Returns the amount of bytes this character would need if encoded in
/// UTF-8.
#[unstable = "pending trait organization"]
#[stable]
fn len_utf8(self) -> uint;

/// Returns the amount of bytes this character would need if encoded in
/// UTF-16.
#[unstable = "pending trait organization"]
#[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 trait organization"]
fn encode_utf8(&self, dst: &mut [u8]) -> Option<uint>;
#[stable]
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 trait organization"]
fn encode_utf16(&self, dst: &mut [u16]) -> Option<uint>;
#[stable]
fn encode_utf16(self, dst: &mut [u16]) -> Option<uint>;
}

#[experimental = "trait is experimental"]
impl Char for char {
#[unstable = "pending trait organization"]
#[stable]
impl CharExt for char {
#[unstable = "pending integer conventions"]
fn is_digit(self, radix: uint) -> bool {
match self.to_digit(radix) {
Some(_) => true,
None => false,
}
self.to_digit(radix).is_some()
}

#[unstable = "pending trait organization"]
#[unstable = "pending integer conventions"]
fn to_digit(self, radix: uint) -> Option<uint> {
if radix > 36 {
panic!("to_digit: radix is too high (maximum 36)");
Expand All @@ -219,12 +216,12 @@ impl Char for char {
else { None }
}

#[unstable = "pending error conventions, trait organization"]
#[stable]
fn escape_unicode(self) -> EscapeUnicode {
EscapeUnicode { c: self, state: EscapeUnicodeState::Backslash }
}

#[unstable = "pending error conventions, trait organization"]
#[stable]
fn escape_default(self) -> EscapeDefault {
let init_state = match self {
'\t' => EscapeDefaultState::Backslash('t'),
Expand All @@ -240,7 +237,7 @@ impl Char for char {
}

#[inline]
#[unstable = "pending trait organization"]
#[stable]
fn len_utf8(self) -> uint {
let code = self as u32;
match () {
Expand All @@ -252,17 +249,17 @@ impl Char for char {
}

#[inline]
#[unstable = "pending trait organization"]
#[stable]
fn len_utf16(self) -> uint {
let ch = self as u32;
if (ch & 0xFFFF_u32) == ch { 1 } else { 2 }
}

#[inline]
#[unstable = "pending error conventions, trait organization"]
fn encode_utf8<'a>(&self, dst: &'a mut [u8]) -> Option<uint> {
#[unstable = "pending decision about Iterator/Writer/Reader"]
fn encode_utf8(self, dst: &mut [u8]) -> Option<uint> {
// Marked #[inline] to allow llvm optimizing it away
let code = *self as u32;
let code = self as u32;
if code < MAX_ONE_B && dst.len() >= 1 {
dst[0] = code as u8;
Some(1)
Expand All @@ -287,10 +284,10 @@ impl Char for char {
}

#[inline]
#[unstable = "pending error conventions, trait organization"]
fn encode_utf16(&self, dst: &mut [u16]) -> Option<uint> {
#[unstable = "pending decision about Iterator/Writer/Reader"]
fn encode_utf16(self, dst: &mut [u16]) -> Option<uint> {
// Marked #[inline] to allow llvm optimizing it away
let mut ch = *self as u32;
let mut ch = self as u32;
if (ch & 0xFFFF_u32) == ch && dst.len() >= 1 {
// The BMP falls through (assuming non-surrogate, as it should)
dst[0] = ch as u16;
Expand All @@ -310,6 +307,7 @@ impl Char for char {
/// An iterator over the characters that represent a `char`, as escaped by
/// Rust's unicode escaping rules.
#[derive(Clone)]
#[stable]
pub struct EscapeUnicode {
c: char,
state: EscapeUnicodeState
Expand All @@ -325,6 +323,7 @@ enum EscapeUnicodeState {
Done,
}

#[stable]
impl Iterator for EscapeUnicode {
type Item = char;

Expand Down Expand Up @@ -370,6 +369,7 @@ impl Iterator for EscapeUnicode {
/// An iterator over the characters that represent a `char`, escaped
/// for maximum portability.
#[derive(Clone)]
#[stable]
pub struct EscapeDefault {
state: EscapeDefaultState
}
Expand All @@ -382,6 +382,7 @@ enum EscapeDefaultState {
Unicode(EscapeUnicode),
}

#[stable]
impl Iterator for EscapeDefault {
type Item = char;

Expand Down
2 changes: 1 addition & 1 deletion src/libcore/fmt/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub use self::SignificantDigits::*;
pub use self::SignFormat::*;

use char;
use char::Char;
use char::CharExt;
use fmt;
use iter::{IteratorExt, range};
use num::{cast, Float, ToPrimitive};
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ impl<'a> Formatter<'a> {
prefix: &str,
buf: &str)
-> Result {
use char::Char;
use char::CharExt;
use fmt::rt::{FlagAlternate, FlagSignPlus, FlagSignAwareZeroPad};

let mut width = buf.len();
Expand Down Expand Up @@ -504,7 +504,7 @@ impl<'a> Formatter<'a> {
fn with_padding<F>(&mut self, padding: uint, default: rt::Alignment, f: F) -> Result where
F: FnOnce(&mut Formatter) -> Result,
{
use char::Char;
use char::CharExt;
let align = match self.align {
rt::AlignUnknown => default,
_ => self.align
Expand Down Expand Up @@ -613,7 +613,7 @@ impl Show for str {

impl Show for char {
fn fmt(&self, f: &mut Formatter) -> Result {
use char::Char;
use char::CharExt;

let mut utf8 = [0u8; 4];
let amt = self.encode_utf8(&mut utf8).unwrap_or(0);
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#![stable]
#![allow(missing_docs)]

use char::Char;
use char::CharExt;
use clone::Clone;
use cmp::{PartialEq, Eq};
use cmp::{PartialOrd, Ord};
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub use mem::drop;

// Reexported types and traits

pub use char::Char;
pub use char::CharExt;
pub use clone::Clone;
pub use cmp::{PartialEq, PartialOrd, Eq, Ord};
pub use iter::{Extend, IteratorExt};
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ use rustc::session::config;
use std::rc::Rc;
use std::u32;
use std::str::Str as StrTrait; // Conflicts with Str variant
use std::char::Char as CharTrait; // Conflicts with Char variant
use std::path::Path as FsPath; // Conflicts with Path struct

use core::DocContext;
Expand Down
3 changes: 1 addition & 2 deletions src/libstd/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ pub use self::FileMode::*;
pub use self::FileAccess::*;
pub use self::IoErrorKind::*;

use char::Char;
use char::CharExt;
use clone::Clone;
use default::Default;
use error::{FromError, Error};
Expand All @@ -248,7 +248,6 @@ use str;
use string::String;
use uint;
use unicode;
use unicode::char::UnicodeChar;
use vec::Vec;

// Reexports
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/num/strconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use self::ExponentFormat::*;
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;
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/path/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use self::PathPrefix::*;

use ascii::AsciiExt;
use c_str::{CString, ToCStr};
use char::CharExt;
use clone::Clone;
use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
use hash;
Expand All @@ -28,7 +29,6 @@ use option::Option::{Some, None};
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};
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/prelude/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// Reexported types and traits

#[stable] #[doc(no_inline)] pub use boxed::Box;
#[stable] #[doc(no_inline)] pub use char::{Char, 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;
Expand Down
12 changes: 5 additions & 7 deletions src/libunicode/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ mod u_str;
// 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)*,
Expand All @@ -58,16 +58,14 @@ mod u_str;
/// 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};
pub use core::char::{from_digit};
pub use core::char::Char;
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 {
Expand Down
2 changes: 1 addition & 1 deletion src/libunicode/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading