Skip to content

Commit 1f732ef

Browse files
committed
auto merge of #20395 : huonw/rust/char-stab-2, r=aturon
cc #19260 The casing transformations are left unstable (it is highly likely to be better to adopt the proper non-1-to-1 case mappings, per #20333) as are `is_xid_*`. I've got a little todo list in the last commit of things I thought about/was told about that I haven't yet handled (I'd also like some feedback).
2 parents ed22606 + 990a79f commit 1f732ef

File tree

16 files changed

+181
-64
lines changed

16 files changed

+181
-64
lines changed

src/libcollections/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ mod std {
103103
mod prelude {
104104
// from core.
105105
pub use core::borrow::IntoCow;
106-
pub use core::char::Char;
107106
pub use core::clone::Clone;
108107
pub use core::cmp::{PartialEq, Eq, PartialOrd, Ord};
109108
pub use core::cmp::Ordering::{Less, Equal, Greater};
@@ -127,7 +126,7 @@ mod prelude {
127126

128127
// from other crates.
129128
pub use alloc::boxed::Box;
130-
pub use unicode::char::UnicodeChar;
129+
pub use unicode::char::CharExt;
131130

132131
// from collections.
133132
pub use slice::SliceConcatExt;

src/libcollections/str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ use self::RecompositionState::*;
5555
use self::DecompositionType::*;
5656

5757
use core::borrow::{BorrowFrom, ToOwned};
58-
use core::char::Char;
58+
use core::char::CharExt;
5959
use core::clone::Clone;
6060
use core::iter::AdditiveIterator;
6161
use core::iter::{range, Iterator, IteratorExt};

src/libcore/char.rs

+33-32
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub const MAX: char = '\u{10ffff}';
6969

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

113113
/// Basic `char` manipulations.
114-
#[experimental = "trait organization may change"]
115-
pub trait Char {
114+
#[stable]
115+
pub trait CharExt {
116116
/// Checks if a `char` parses as a numeric digit in the given radix.
117117
///
118118
/// Compared to `is_numeric()`, this function only recognizes the characters
@@ -126,7 +126,7 @@ pub trait Char {
126126
/// # Panics
127127
///
128128
/// Panics if given a radix > 36.
129-
#[unstable = "pending error conventions"]
129+
#[unstable = "pending integer conventions"]
130130
fn is_digit(self, radix: uint) -> bool;
131131

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

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

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

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

175175
/// Returns the amount of bytes this character would need if encoded in
176176
/// UTF-16.
177-
#[unstable = "pending trait organization"]
177+
#[stable]
178178
fn len_utf16(self) -> uint;
179179

180180
/// Encodes this character as UTF-8 into the provided byte buffer,
181181
/// and then returns the number of bytes written.
182182
///
183183
/// If the buffer is not large enough, nothing will be written into it
184184
/// and a `None` will be returned.
185-
#[unstable = "pending trait organization"]
186-
fn encode_utf8(&self, dst: &mut [u8]) -> Option<uint>;
185+
#[stable]
186+
fn encode_utf8(self, dst: &mut [u8]) -> Option<uint>;
187187

188188
/// Encodes this character as UTF-16 into the provided `u16` buffer,
189189
/// and then returns the number of `u16`s written.
190190
///
191191
/// If the buffer is not large enough, nothing will be written into it
192192
/// and a `None` will be returned.
193-
#[unstable = "pending trait organization"]
194-
fn encode_utf16(&self, dst: &mut [u16]) -> Option<uint>;
193+
#[stable]
194+
fn encode_utf16(self, dst: &mut [u16]) -> Option<uint>;
195195
}
196196

197-
#[experimental = "trait is experimental"]
198-
impl Char for char {
199-
#[unstable = "pending trait organization"]
197+
#[stable]
198+
impl CharExt for char {
199+
#[unstable = "pending integer conventions"]
200200
fn is_digit(self, radix: uint) -> bool {
201-
match self.to_digit(radix) {
202-
Some(_) => true,
203-
None => false,
204-
}
201+
self.to_digit(radix).is_some()
205202
}
206203

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

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

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

242239
#[inline]
243-
#[unstable = "pending trait organization"]
240+
#[stable]
244241
fn len_utf8(self) -> uint {
245242
let code = self as u32;
246243
match () {
@@ -252,17 +249,17 @@ impl Char for char {
252249
}
253250

254251
#[inline]
255-
#[unstable = "pending trait organization"]
252+
#[stable]
256253
fn len_utf16(self) -> uint {
257254
let ch = self as u32;
258255
if (ch & 0xFFFF_u32) == ch { 1 } else { 2 }
259256
}
260257

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

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

326+
#[stable]
328327
impl Iterator for EscapeUnicode {
329328
type Item = char;
330329

@@ -370,6 +369,7 @@ impl Iterator for EscapeUnicode {
370369
/// An iterator over the characters that represent a `char`, escaped
371370
/// for maximum portability.
372371
#[derive(Clone)]
372+
#[stable]
373373
pub struct EscapeDefault {
374374
state: EscapeDefaultState
375375
}
@@ -382,6 +382,7 @@ enum EscapeDefaultState {
382382
Unicode(EscapeUnicode),
383383
}
384384

385+
#[stable]
385386
impl Iterator for EscapeDefault {
386387
type Item = char;
387388

src/libcore/fmt/float.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub use self::SignificantDigits::*;
1515
pub use self::SignFormat::*;
1616

1717
use char;
18-
use char::Char;
18+
use char::CharExt;
1919
use fmt;
2020
use iter::{IteratorExt, range};
2121
use num::{cast, Float, ToPrimitive};

src/libcore/fmt/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ impl<'a> Formatter<'a> {
388388
prefix: &str,
389389
buf: &str)
390390
-> Result {
391-
use char::Char;
391+
use char::CharExt;
392392
use fmt::rt::{FlagAlternate, FlagSignPlus, FlagSignAwareZeroPad};
393393

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

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

618618
let mut utf8 = [0u8; 4];
619619
let amt = self.encode_utf8(&mut utf8).unwrap_or(0);

src/libcore/num/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#![stable]
1616
#![allow(missing_docs)]
1717

18-
use char::Char;
18+
use char::CharExt;
1919
use clone::Clone;
2020
use cmp::{PartialEq, Eq};
2121
use cmp::{PartialOrd, Ord};

src/libcore/prelude.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub use mem::drop;
3838

3939
// Reexported types and traits
4040

41-
pub use char::Char;
41+
pub use char::CharExt;
4242
pub use clone::Clone;
4343
pub use cmp::{PartialEq, PartialOrd, Eq, Ord};
4444
pub use iter::{Extend, IteratorExt};

src/librustdoc/clean/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ use rustc::session::config;
5050
use std::rc::Rc;
5151
use std::u32;
5252
use std::str::Str as StrTrait; // Conflicts with Str variant
53-
use std::char::Char as CharTrait; // Conflicts with Char variant
5453
use std::path::Path as FsPath; // Conflicts with Path struct
5554

5655
use core::DocContext;

src/libstd/io/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ pub use self::FileMode::*;
225225
pub use self::FileAccess::*;
226226
pub use self::IoErrorKind::*;
227227

228-
use char::Char;
228+
use char::CharExt;
229229
use clone::Clone;
230230
use default::Default;
231231
use error::{FromError, Error};
@@ -248,7 +248,6 @@ use str;
248248
use string::String;
249249
use uint;
250250
use unicode;
251-
use unicode::char::UnicodeChar;
252251
use vec::Vec;
253252

254253
// Reexports

src/libstd/num/strconv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use self::ExponentFormat::*;
1616
use self::SignificantDigits::*;
1717
use self::SignFormat::*;
1818

19-
use char::{self, Char};
19+
use char::{self, CharExt};
2020
use num::{self, Int, Float, ToPrimitive};
2121
use num::FpCategory as Fp;
2222
use ops::FnMut;

src/libstd/path/windows.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use self::PathPrefix::*;
1616

1717
use ascii::AsciiExt;
1818
use c_str::{CString, ToCStr};
19+
use char::CharExt;
1920
use clone::Clone;
2021
use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
2122
use hash;
@@ -28,7 +29,6 @@ use option::Option::{Some, None};
2829
use slice::{SliceExt, SliceConcatExt};
2930
use str::{SplitTerminator, FromStr, StrExt};
3031
use string::{String, ToString};
31-
use unicode::char::UnicodeChar;
3232
use vec::Vec;
3333

3434
use super::{contains_nul, BytesContainer, GenericPath, GenericPathUnsafe};

src/libstd/prelude/v1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
// Reexported types and traits
2323

2424
#[stable] #[doc(no_inline)] pub use boxed::Box;
25-
#[stable] #[doc(no_inline)] pub use char::{Char, UnicodeChar};
25+
#[stable] #[doc(no_inline)] pub use char::CharExt;
2626
#[stable] #[doc(no_inline)] pub use clone::Clone;
2727
#[stable] #[doc(no_inline)] pub use cmp::{PartialEq, PartialOrd, Eq, Ord};
2828
#[stable] #[doc(no_inline)] pub use iter::CloneIteratorExt;

src/libunicode/lib.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ mod u_str;
4444
// re-export char so that std et al see it correctly
4545
/// Character manipulation (`char` type, Unicode Scalar Value)
4646
///
47-
/// This module provides the `Char` and `UnicodeChar` traits, as well as their
48-
/// implementation for the primitive `char` type, in order to allow basic character
49-
/// manipulation.
47+
/// This module provides the `CharExt` trait, as well as its
48+
/// implementation for the primitive `char` type, in order to allow
49+
/// basic character manipulation.
5050
///
5151
/// A `char` actually represents a
5252
/// *[Unicode Scalar Value](http://www.unicode.org/glossary/#unicode_scalar_value)*,
@@ -58,16 +58,14 @@ mod u_str;
5858
/// however the converse is not always true due to the above range limits
5959
/// and, as such, should be performed via the `from_u32` function..
6060
pub mod char {
61-
pub use core::char::{MAX, from_u32};
62-
pub use core::char::{from_digit};
63-
pub use core::char::Char;
61+
pub use core::char::{MAX, from_u32, from_digit};
6462

6563
pub use normalize::{decompose_canonical, decompose_compatible, compose};
6664

6765
pub use tables::normalization::canonical_combining_class;
6866
pub use tables::UNICODE_VERSION;
6967

70-
pub use u_char::UnicodeChar;
68+
pub use u_char::CharExt;
7169
}
7270

7371
pub mod str {

src/libunicode/tables.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#![allow(missing_docs, non_upper_case_globals, non_snake_case)]
1414

1515
/// The version of [Unicode](http://www.unicode.org/)
16-
/// that the `UnicodeChar` and `UnicodeStrPrelude` traits are based on.
16+
/// that the unicode parts of `CharExt` and `UnicodeStrPrelude` traits are based on.
1717
pub const UNICODE_VERSION: (uint, uint, uint) = (7, 0, 0);
1818

1919
fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {

0 commit comments

Comments
 (0)