Skip to content

Commit 0f6a0b5

Browse files
committed
std: Stabilize more of the char module
This commit performs another pass over the `std::char` module for stabilization. Some minor cleanup is performed such as migrating documentation from libcore to libunicode (where the `std`-facing trait resides) as well as a slight reorganiation in libunicode itself. Otherwise, the stability modifications made are: * `char::from_digit` is now stable * `CharExt::is_digit` is now stable * `CharExt::to_digit` is now stable * `CharExt::to_{lower,upper}case` are now stable after being modified to return an iterator over characters. While the implementation today has not changed this should allow us to implement the full set of case conversions in unicode where some characters can map to multiple when doing an upper or lower case mapping. * `StrExt::to_{lower,upper}case` was added as unstable for a convenience of not having to worry about characters expanding to more characters when you just want the whole string to get into upper or lower case. This is a breaking change due to the change in the signatures of the `CharExt::to_{upper,lower}case` methods. Code can be updated to use functions like `flat_map` or `collect` to handle the difference. [breaking-change]
1 parent 2574009 commit 0f6a0b5

File tree

14 files changed

+333
-389
lines changed

14 files changed

+333
-389
lines changed

src/compiletest/compiletest.rs

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#![feature(unboxed_closures)]
2020
#![feature(std_misc)]
2121
#![feature(test)]
22-
#![feature(unicode)]
2322
#![feature(core)]
2423
#![feature(path)]
2524
#![feature(io)]

src/compiletest/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn parse_expected(last_nonfollow_error: Option<uint>,
7171
let letters = line[kind_start..].chars();
7272
let kind = letters.skip_while(|c| c.is_whitespace())
7373
.take_while(|c| !c.is_whitespace())
74-
.map(|c| c.to_lowercase())
74+
.flat_map(|c| c.to_lowercase())
7575
.collect::<String>();
7676
let letters = line[kind_start..].chars();
7777
let msg = letters.skip_while(|c| c.is_whitespace())

src/libcollections/str.rs

+55-24
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212

1313
//! Unicode string manipulation (the [`str`](../primitive.str.html) type).
1414
//!
15-
//! Rust's [`str`](../primitive.str.html) type is one of the core primitive types of the
16-
//! language. `&str` is the borrowed string type. This type of string can only be created
17-
//! from other strings, unless it is a `&'static str` (see below). It is not possible to
18-
//! move out of borrowed strings because they are owned elsewhere.
15+
//! Rust's [`str`](../primitive.str.html) type is one of the core primitive
16+
//! types of the language. `&str` is the borrowed string type. This type of
17+
//! string can only be created from other strings, unless it is a `&'static str`
18+
//! (see below). It is not possible to move out of borrowed strings because they
19+
//! are owned elsewhere.
1920
//!
20-
//! Basic operations are implemented directly by the compiler, but more advanced operations are
21-
//! defined on the [`StrExt`](trait.StrExt.html) trait.
21+
//! Basic operations are implemented directly by the compiler, but more advanced
22+
//! operations are defined on the [`StrExt`](trait.StrExt.html) trait.
2223
//!
2324
//! # Examples
2425
//!
@@ -28,8 +29,9 @@
2829
//! let s = "Hello, world.";
2930
//! ```
3031
//!
31-
//! This `&str` is a `&'static str`, which is the type of string literals. They're `'static`
32-
//! because literals are available for the entire lifetime of the program.
32+
//! This `&str` is a `&'static str`, which is the type of string literals.
33+
//! They're `'static` because literals are available for the entire lifetime of
34+
//! the program.
3335
//!
3436
//! You can get a non-`'static` `&str` by taking a slice of a `String`:
3537
//!
@@ -40,29 +42,30 @@
4042
//!
4143
//! # Representation
4244
//!
43-
//! Rust's string type, `str`, is a sequence of Unicode scalar values encoded as a stream of UTF-8
44-
//! bytes. All [strings](../../reference.html#literals) are guaranteed to be validly encoded UTF-8
45-
//! sequences. Additionally, strings are not null-terminated and can thus contain null bytes.
45+
//! Rust's string type, `str`, is a sequence of Unicode scalar values encoded as
46+
//! a stream of UTF-8 bytes. All [strings](../../reference.html#literals) are
47+
//! guaranteed to be validly encoded UTF-8 sequences. Additionally, strings are
48+
//! not null-terminated and can thus contain null bytes.
4649
//!
47-
//! The actual representation of `str`s have direct mappings to slices: `&str` is the same as
48-
//! `&[u8]`.
50+
//! The actual representation of `str`s have direct mappings to slices: `&str`
51+
//! is the same as `&[u8]`.
4952
5053
#![doc(primitive = "str")]
5154
#![stable(feature = "rust1", since = "1.0.0")]
5255

5356
use self::RecompositionState::*;
5457
use self::DecompositionType::*;
5558

56-
use core::char::CharExt;
5759
use core::clone::Clone;
5860
use core::iter::AdditiveIterator;
59-
use core::iter::{Iterator, IteratorExt};
61+
use core::iter::{Iterator, IteratorExt, Extend};
6062
use core::ops::Index;
6163
use core::ops::RangeFull;
6264
use core::option::Option::{self, Some, None};
6365
use core::result::Result;
6466
use core::slice::AsSlice;
6567
use core::str as core_str;
68+
use unicode::char::CharExt;
6669
use unicode::str::{UnicodeStr, Utf16Encoder};
6770

6871
use vec_deque::VecDeque;
@@ -836,17 +839,19 @@ pub trait StrExt: Index<RangeFull, Output = str> {
836839

837840
/// Returns a slice of the string from the character range [`begin`..`end`).
838841
///
839-
/// That is, start at the `begin`-th code point of the string and continue to the `end`-th code
840-
/// point. This does not detect or handle edge cases such as leaving a combining character as
841-
/// the first code point of the string.
842+
/// That is, start at the `begin`-th code point of the string and continue
843+
/// to the `end`-th code point. This does not detect or handle edge cases
844+
/// such as leaving a combining character as the first code point of the
845+
/// string.
842846
///
843-
/// Due to the design of UTF-8, this operation is `O(end)`. See `slice`, `slice_to` and
844-
/// `slice_from` for `O(1)` variants that use byte indices rather than code point indices.
847+
/// Due to the design of UTF-8, this operation is `O(end)`. See `slice`,
848+
/// `slice_to` and `slice_from` for `O(1)` variants that use byte indices
849+
/// rather than code point indices.
845850
///
846851
/// # Panics
847852
///
848-
/// Panics if `begin` > `end` or the either `begin` or `end` are beyond the last character of
849-
/// the string.
853+
/// Panics if `begin` > `end` or the either `begin` or `end` are beyond the
854+
/// last character of the string.
850855
///
851856
/// # Examples
852857
///
@@ -868,8 +873,8 @@ pub trait StrExt: Index<RangeFull, Output = str> {
868873
///
869874
/// # Unsafety
870875
///
871-
/// Caller must check both UTF-8 character boundaries and the boundaries of the entire slice as
872-
/// well.
876+
/// Caller must check both UTF-8 character boundaries and the boundaries of
877+
/// the entire slice as well.
873878
///
874879
/// # Examples
875880
///
@@ -1506,6 +1511,32 @@ pub trait StrExt: Index<RangeFull, Output = str> {
15061511
fn trim_right(&self) -> &str {
15071512
UnicodeStr::trim_right(&self[..])
15081513
}
1514+
1515+
/// Returns the lowercase equivalent of this string.
1516+
///
1517+
/// # Examples
1518+
///
1519+
/// let s = "HELLO";
1520+
/// assert_eq!(s.to_lowercase(), "hello");
1521+
#[unstable(feature = "collections")]
1522+
fn to_lowercase(&self) -> String {
1523+
let mut s = String::with_capacity(self.len());
1524+
s.extend(self[..].chars().flat_map(|c| c.to_lowercase()));
1525+
return s;
1526+
}
1527+
1528+
/// Returns the uppercase equivalent of this string.
1529+
///
1530+
/// # Examples
1531+
///
1532+
/// let s = "hello";
1533+
/// assert_eq!(s.to_uppercase(), "HELLO");
1534+
#[unstable(feature = "collections")]
1535+
fn to_uppercase(&self) -> String {
1536+
let mut s = String::with_capacity(self.len());
1537+
s.extend(self[..].chars().flat_map(|c| c.to_uppercase()));
1538+
return s;
1539+
}
15091540
}
15101541

15111542
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)