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

std: Stabilize more of the char module #23126

Merged
merged 1 commit into from
Mar 11, 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
1 change: 0 additions & 1 deletion src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#![feature(unboxed_closures)]
#![feature(std_misc)]
#![feature(test)]
#![feature(unicode)]
#![feature(core)]
#![feature(path)]
#![feature(io)]
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn parse_expected(last_nonfollow_error: Option<uint>,
let letters = line[kind_start..].chars();
let kind = letters.skip_while(|c| c.is_whitespace())
.take_while(|c| !c.is_whitespace())
.map(|c| c.to_lowercase())
.flat_map(|c| c.to_lowercase())
.collect::<String>();
let letters = line[kind_start..].chars();
let msg = letters.skip_while(|c| c.is_whitespace())
Expand Down
79 changes: 55 additions & 24 deletions src/libcollections/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@

//! Unicode string manipulation (the [`str`](../primitive.str.html) type).
//!
//! Rust's [`str`](../primitive.str.html) type is one of the core primitive types of the
//! language. `&str` is the borrowed string type. This type of string can only be created
//! from other strings, unless it is a `&'static str` (see below). It is not possible to
//! move out of borrowed strings because they are owned elsewhere.
//! Rust's [`str`](../primitive.str.html) type is one of the core primitive
//! types of the language. `&str` is the borrowed string type. This type of
//! string can only be created from other strings, unless it is a `&'static str`
//! (see below). It is not possible to move out of borrowed strings because they
//! are owned elsewhere.
//!
//! Basic operations are implemented directly by the compiler, but more advanced operations are
//! defined on the [`StrExt`](trait.StrExt.html) trait.
//! Basic operations are implemented directly by the compiler, but more advanced
//! operations are defined on the [`StrExt`](trait.StrExt.html) trait.
//!
//! # Examples
//!
Expand All @@ -28,8 +29,9 @@
//! let s = "Hello, world.";
//! ```
//!
//! This `&str` is a `&'static str`, which is the type of string literals. They're `'static`
//! because literals are available for the entire lifetime of the program.
//! This `&str` is a `&'static str`, which is the type of string literals.
//! They're `'static` because literals are available for the entire lifetime of
//! the program.
//!
//! You can get a non-`'static` `&str` by taking a slice of a `String`:
//!
Expand All @@ -40,29 +42,30 @@
//!
//! # Representation
//!
//! Rust's string type, `str`, is a sequence of Unicode scalar values encoded as a stream of UTF-8
//! bytes. All [strings](../../reference.html#literals) are guaranteed to be validly encoded UTF-8
//! sequences. Additionally, strings are not null-terminated and can thus contain null bytes.
//! Rust's string type, `str`, is a sequence of Unicode scalar values encoded as
//! a stream of UTF-8 bytes. All [strings](../../reference.html#literals) are
//! guaranteed to be validly encoded UTF-8 sequences. Additionally, strings are
//! not null-terminated and can thus contain null bytes.
//!
//! The actual representation of `str`s have direct mappings to slices: `&str` is the same as
//! `&[u8]`.
//! The actual representation of `str`s have direct mappings to slices: `&str`
//! is the same as `&[u8]`.

#![doc(primitive = "str")]
#![stable(feature = "rust1", since = "1.0.0")]

use self::RecompositionState::*;
use self::DecompositionType::*;

use core::char::CharExt;
use core::clone::Clone;
use core::iter::AdditiveIterator;
use core::iter::{Iterator, IteratorExt};
use core::iter::{Iterator, IteratorExt, Extend};
use core::ops::Index;
use core::ops::RangeFull;
use core::option::Option::{self, Some, None};
use core::result::Result;
use core::slice::AsSlice;
use core::str as core_str;
use unicode::char::CharExt;
use unicode::str::{UnicodeStr, Utf16Encoder};

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

/// Returns a slice of the string from the character range [`begin`..`end`).
///
/// That is, start at the `begin`-th code point of the string and continue to the `end`-th code
/// point. This does not detect or handle edge cases such as leaving a combining character as
/// the first code point of the string.
/// That is, start at the `begin`-th code point of the string and continue
/// to the `end`-th code point. This does not detect or handle edge cases
/// such as leaving a combining character as the first code point of the
/// string.
///
/// Due to the design of UTF-8, this operation is `O(end)`. See `slice`, `slice_to` and
/// `slice_from` for `O(1)` variants that use byte indices rather than code point indices.
/// Due to the design of UTF-8, this operation is `O(end)`. See `slice`,
/// `slice_to` and `slice_from` for `O(1)` variants that use byte indices
/// rather than code point indices.
///
/// # Panics
///
/// Panics if `begin` > `end` or the either `begin` or `end` are beyond the last character of
/// the string.
/// Panics if `begin` > `end` or the either `begin` or `end` are beyond the
/// last character of the string.
///
/// # Examples
///
Expand All @@ -868,8 +873,8 @@ pub trait StrExt: Index<RangeFull, Output = str> {
///
/// # Unsafety
///
/// Caller must check both UTF-8 character boundaries and the boundaries of the entire slice as
/// well.
/// Caller must check both UTF-8 character boundaries and the boundaries of
/// the entire slice as well.
///
/// # Examples
///
Expand Down Expand Up @@ -1506,6 +1511,32 @@ pub trait StrExt: Index<RangeFull, Output = str> {
fn trim_right(&self) -> &str {
UnicodeStr::trim_right(&self[..])
}

/// Returns the lowercase equivalent of this string.
///
/// # Examples
///
/// let s = "HELLO";
/// assert_eq!(s.to_lowercase(), "hello");
#[unstable(feature = "collections")]
fn to_lowercase(&self) -> String {
let mut s = String::with_capacity(self.len());
s.extend(self[..].chars().flat_map(|c| c.to_lowercase()));
return s;
}

/// Returns the uppercase equivalent of this string.
///
/// # Examples
///
/// let s = "hello";
/// assert_eq!(s.to_uppercase(), "HELLO");
#[unstable(feature = "collections")]
fn to_uppercase(&self) -> String {
let mut s = String::with_capacity(self.len());
s.extend(self[..].chars().flat_map(|c| c.to_uppercase()));
return s;
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
Loading