Skip to content

Commit

Permalink
core: Mark remaining Char methods unstable
Browse files Browse the repository at this point in the history
The `Char` trait itself may go away in favor of primitive inherent
methods. Still some questions about whether the preconditions are
following the final error handling conventions.
  • Loading branch information
brson committed Nov 21, 2014
1 parent 95c3f61 commit b577e4c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/libcore/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ pub trait Char {
/// # Failure
///
/// Fails if given a radix > 36.
#[unstable = "pending error conventions"]
fn is_digit(&self, radix: uint) -> bool;

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

/// Converts a number to the character representing it.
Expand All @@ -307,6 +309,7 @@ pub trait Char {
/// * Characters in [0,0xff] get 2-digit escapes: `\\xNN`
/// * Characters in [0x100,0xffff] get 4-digit escapes: `\\uNNNN`.
/// * Characters above 0x10000 get 8-digit escapes: `\\UNNNNNNNN`.
#[unstable = "pending error conventions, trait organization"]
fn escape_unicode(&self, f: |char|);

/// Returns a 'default' ASCII and C++11-like literal escape of a
Expand All @@ -321,6 +324,7 @@ 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"]
fn escape_default(&self, f: |char|);

/// Returns the amount of bytes this character would need if encoded in
Expand All @@ -330,24 +334,28 @@ pub trait Char {

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

/// Returns the amount of bytes this character would need if encoded in
/// UTF-16.
#[unstable = "pending trait organization"]
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>;

/// 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>;
}

Expand All @@ -356,8 +364,10 @@ impl Char for char {
#[deprecated = "use is_digit"]
fn is_digit_radix(&self, radix: uint) -> bool { is_digit_radix(*self, radix) }

#[unstable = "pending trait organization"]
fn is_digit(&self, radix: uint) -> bool { is_digit_radix(*self, radix) }

#[unstable = "pending trait organization"]
fn to_digit(&self, radix: uint) -> Option<uint> { to_digit(*self, radix) }

#[deprecated = "use the char::from_digit free function"]
Expand All @@ -367,24 +377,29 @@ impl Char for char {
#[deprecated = "use the char::from_u32 free function"]
fn from_u32(i: u32) -> Option<char> { from_u32(i) }

#[unstable = "pending error conventions, trait organization"]
fn escape_unicode(&self, f: |char|) { escape_unicode(*self, f) }

#[unstable = "pending error conventions, trait organization"]
fn escape_default(&self, f: |char|) { escape_default(*self, f) }

#[inline]
#[deprecated = "use len_utf8"]
fn len_utf8_bytes(&self) -> uint { len_utf8_bytes(*self) }

#[inline]
#[unstable = "pending trait organization"]
fn len_utf8(&self) -> uint { len_utf8_bytes(*self) }

#[inline]
#[unstable = "pending trait organization"]
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> {
// Marked #[inline] to allow llvm optimizing it away
let code = *self as u32;
Expand Down Expand Up @@ -412,6 +427,7 @@ impl Char for char {
}

#[inline]
#[unstable = "pending error conventions, trait organization"]
fn encode_utf16(&self, dst: &mut [u16]) -> Option<uint> {
// Marked #[inline] to allow llvm optimizing it away
let mut ch = *self as u32;
Expand Down

0 comments on commit b577e4c

Please sign in to comment.