Skip to content

Commit aa113c6

Browse files
committed
auto merge of #19741 : alexcrichton/rust/stabilize-str, r=aturon
This commit starts out by consolidating all `str` extension traits into one `StrExt` trait to be included in the prelude. This means that `UnicodeStrPrelude`, `StrPrelude`, and `StrAllocating` have all been merged into one `StrExt` exported by the standard library. Some functionality is currently duplicated with the `StrExt` present in libcore. This commit also currently avoids any methods which require any form of pattern to operate. These functions will be stabilized via a separate RFC. Next, stability of methods and structures are as follows: Stable * from_utf8_unchecked * CowString - after moving to std::string * StrExt::as_bytes * StrExt::as_ptr * StrExt::bytes/Bytes - also made a struct instead of a typedef * StrExt::char_indices/CharIndices - CharOffsets was renamed * StrExt::chars/Chars * StrExt::is_empty * StrExt::len * StrExt::lines/Lines * StrExt::lines_any/LinesAny * StrExt::slice_unchecked * StrExt::trim * StrExt::trim_left * StrExt::trim_right * StrExt::words/Words - also made a struct instead of a typedef Unstable * from_utf8 - the error type was changed to a `Result`, but the error type has yet to prove itself * from_c_str - this function will be handled by the c_str RFC * FromStr - this trait will have an associated error type eventually * StrExt::escape_default - needs iterators at least, unsure if it should make the cut * StrExt::escape_unicode - needs iterators at least, unsure if it should make the cut * StrExt::slice_chars - this function has yet to prove itself * StrExt::slice_shift_char - awaiting conventions about slicing and shifting * StrExt::graphemes/Graphemes - this functionality may only be in libunicode * StrExt::grapheme_indices/GraphemeIndices - this functionality may only be in libunicode * StrExt::width - this functionality may only be in libunicode * StrExt::utf16_units - this functionality may only be in libunicode * StrExt::nfd_chars - this functionality may only be in libunicode * StrExt::nfkd_chars - this functionality may only be in libunicode * StrExt::nfc_chars - this functionality may only be in libunicode * StrExt::nfkc_chars - this functionality may only be in libunicode * StrExt::is_char_boundary - naming is uncertain with container conventions * StrExt::char_range_at - naming is uncertain with container conventions * StrExt::char_range_at_reverse - naming is uncertain with container conventions * StrExt::char_at - naming is uncertain with container conventions * StrExt::char_at_reverse - naming is uncertain with container conventions * StrVector::concat - this functionality may be replaced with iterators, but it's not certain at this time * StrVector::connect - as with concat, may be deprecated in favor of iterators Deprecated * StrAllocating and UnicodeStrPrelude have been merged into StrExit * eq_slice - compiler implementation detail * from_str - use the inherent parse() method * is_utf8 - call from_utf8 instead * replace - call the method instead * truncate_utf16_at_nul - this is an implementation detail of windows and does not need to be exposed. * utf8_char_width - moved to libunicode * utf16_items - moved to libunicode * is_utf16 - moved to libunicode * Utf16Items - moved to libunicode * Utf16Item - moved to libunicode * Utf16Encoder - moved to libunicode * AnyLines - renamed to LinesAny and made a struct * SendStr - use CowString<'static> instead * str::raw - all functionality is deprecated * StrExt::into_string - call to_string() instead * StrExt::repeat - use iterators instead * StrExt::char_len - use .chars().count() instead * StrExt::is_alphanumeric - use .chars().all(..) * StrExt::is_whitespace - use .chars().all(..) Pending deprecation -- while slicing syntax is being worked out, these methods are all #[unstable] * Str - while currently used for generic programming, this trait will be replaced with one of [], deref coercions, or a generic conversion trait. * StrExt::slice - use slicing syntax instead * StrExt::slice_to - use slicing syntax instead * StrExt::slice_from - use slicing syntax instead * StrExt::lev_distance - deprecated with no replacement Awaiting stabilization due to patterns and/or matching * StrExt::contains * StrExt::contains_char * StrExt::split * StrExt::splitn * StrExt::split_terminator * StrExt::rsplitn * StrExt::match_indices * StrExt::split_str * StrExt::starts_with * StrExt::ends_with * StrExt::trim_chars * StrExt::trim_left_chars * StrExt::trim_right_chars * StrExt::find * StrExt::rfind * StrExt::find_str * StrExt::subslice_offset
2 parents 34d6800 + 082bfde commit aa113c6

File tree

201 files changed

+3594
-3248
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

201 files changed

+3594
-3248
lines changed

src/compiletest/compiletest.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ pub fn parse_config(args: Vec<String> ) -> Config {
152152
matches.opt_str("ratchet-metrics").map(|s| Path::new(s)),
153153
ratchet_noise_percent:
154154
matches.opt_str("ratchet-noise-percent")
155-
.and_then(|s| from_str::<f64>(s.as_slice())),
155+
.and_then(|s| s.as_slice().parse::<f64>()),
156156
runtool: matches.opt_str("runtool"),
157157
host_rustcflags: matches.opt_str("host-rustcflags"),
158158
target_rustcflags: matches.opt_str("target-rustcflags"),
@@ -190,9 +190,7 @@ pub fn log_config(config: &Config) {
190190
logv(c, format!("filter: {}",
191191
opt_str(&config.filter
192192
.as_ref()
193-
.map(|re| {
194-
re.to_string().into_string()
195-
}))));
193+
.map(|re| re.to_string()))));
196194
logv(c, format!("runtool: {}", opt_str(&config.runtool)));
197195
logv(c, format!("host-rustcflags: {}",
198196
opt_str(&config.host_rustcflags)));

src/compiletest/header.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,8 @@ pub fn gdb_version_to_int(version_string: &str) -> int {
351351
panic!("{}", error_string);
352352
}
353353

354-
let major: int = from_str(components[0]).expect(error_string);
355-
let minor: int = from_str(components[1]).expect(error_string);
354+
let major: int = components[0].parse().expect(error_string);
355+
let minor: int = components[1].parse().expect(error_string);
356356

357357
return major * 1000 + minor;
358358
}
@@ -362,6 +362,6 @@ pub fn lldb_version_to_int(version_string: &str) -> int {
362362
"Encountered LLDB version string with unexpected format: {}",
363363
version_string);
364364
let error_string = error_string.as_slice();
365-
let major: int = from_str(version_string).expect(error_string);
365+
let major: int = version_string.parse().expect(error_string);
366366
return major;
367367
}

src/compiletest/runtest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ fn split_maybe_args(argstr: &Option<String>) -> Vec<String> {
13611361
s.as_slice()
13621362
.split(' ')
13631363
.filter_map(|s| {
1364-
if s.is_whitespace() {
1364+
if s.chars().all(|c| c.is_whitespace()) {
13651365
None
13661366
} else {
13671367
Some(s.to_string())

src/doc/guide.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -2257,10 +2257,10 @@ a function for that:
22572257
let input = io::stdin().read_line()
22582258
.ok()
22592259
.expect("Failed to read line");
2260-
let input_num: Option<uint> = from_str(input.as_slice());
2260+
let input_num: Option<uint> = input.parse();
22612261
```
22622262
2263-
The `from_str` function takes in a `&str` value and converts it into something.
2263+
The `parse` function takes in a `&str` value and converts it into something.
22642264
We tell it what kind of something with a type hint. Remember our type hint with
22652265
`random()`? It looked like this:
22662266
@@ -2279,8 +2279,8 @@ In this case, we say `x` is a `uint` explicitly, so Rust is able to properly
22792279
tell `random()` what to generate. In a similar fashion, both of these work:
22802280
22812281
```{rust,ignore}
2282-
let input_num = from_str::<uint>("5"); // input_num: Option<uint>
2283-
let input_num: Option<uint> = from_str("5"); // input_num: Option<uint>
2282+
let input_num = "5".parse::<uint>(); // input_num: Option<uint>
2283+
let input_num: Option<uint> = "5".parse(); // input_num: Option<uint>
22842284
```
22852285
22862286
Anyway, with us now converting our input to a number, our code looks like this:
@@ -2301,7 +2301,7 @@ fn main() {
23012301
let input = io::stdin().read_line()
23022302
.ok()
23032303
.expect("Failed to read line");
2304-
let input_num: Option<uint> = from_str(input.as_slice());
2304+
let input_num: Option<uint> = input.parse();
23052305

23062306
println!("You guessed: {}", input_num);
23072307

@@ -2350,7 +2350,7 @@ fn main() {
23502350
let input = io::stdin().read_line()
23512351
.ok()
23522352
.expect("Failed to read line");
2353-
let input_num: Option<uint> = from_str(input.as_slice());
2353+
let input_num: Option<uint> = input.parse();
23542354
23552355
let num = match input_num {
23562356
Some(num) => num,
@@ -2395,7 +2395,7 @@ Uh, what? But we did!
23952395
23962396
... actually, we didn't. See, when you get a line of input from `stdin()`,
23972397
you get all the input. Including the `\n` character from you pressing Enter.
2398-
Therefore, `from_str()` sees the string `"5\n"` and says "nope, that's not a
2398+
Therefore, `parse()` sees the string `"5\n"` and says "nope, that's not a
23992399
number; there's non-number stuff in there!" Luckily for us, `&str`s have an easy
24002400
method we can use defined on them: `trim()`. One small modification, and our
24012401
code looks like this:
@@ -2416,7 +2416,7 @@ fn main() {
24162416
let input = io::stdin().read_line()
24172417
.ok()
24182418
.expect("Failed to read line");
2419-
let input_num: Option<uint> = from_str(input.as_slice().trim());
2419+
let input_num: Option<uint> = input.trim().parse();
24202420
24212421
let num = match input_num {
24222422
Some(num) => num,
@@ -2491,7 +2491,7 @@ fn main() {
24912491
let input = io::stdin().read_line()
24922492
.ok()
24932493
.expect("Failed to read line");
2494-
let input_num: Option<uint> = from_str(input.as_slice().trim());
2494+
let input_num: Option<uint> = input.trim().parse();
24952495

24962496
let num = match input_num {
24972497
Some(num) => num,
@@ -2566,7 +2566,7 @@ fn main() {
25662566
let input = io::stdin().read_line()
25672567
.ok()
25682568
.expect("Failed to read line");
2569-
let input_num: Option<uint> = from_str(input.as_slice().trim());
2569+
let input_num: Option<uint> = input.trim().parse();
25702570
25712571
let num = match input_num {
25722572
Some(num) => num,
@@ -2621,7 +2621,7 @@ fn main() {
26212621
let input = io::stdin().read_line()
26222622
.ok()
26232623
.expect("Failed to read line");
2624-
let input_num: Option<uint> = from_str(input.as_slice().trim());
2624+
let input_num: Option<uint> = input.trim().parse();
26252625
26262626
let num = match input_num {
26272627
Some(num) => num,
@@ -2697,7 +2697,7 @@ fn main() {
26972697
let input = io::stdin().read_line()
26982698
.ok()
26992699
.expect("Failed to read line");
2700-
let input_num: Option<uint> = from_str(input.as_slice().trim());
2700+
let input_num: Option<uint> = input.trim().parse();
27012701
27022702
let num = match input_num {
27032703
Some(num) => num,

src/doc/reference.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3177,7 +3177,7 @@ Some examples of call expressions:
31773177
# fn add(x: int, y: int) -> int { 0 }
31783178
31793179
let x: int = add(1, 2);
3180-
let pi: Option<f32> = from_str("3.14");
3180+
let pi: Option<f32> = "3.14".parse();
31813181
```
31823182

31833183
### Lambda expressions

src/libcollections/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ mod prelude {
121121
// in core and collections (may differ).
122122
pub use slice::{PartialEqSliceExt, OrdSliceExt};
123123
pub use slice::{AsSlice, SliceExt};
124-
pub use str::{from_str, Str, StrPrelude};
124+
pub use str::{from_str, Str};
125125

126126
// from other crates.
127127
pub use alloc::boxed::Box;
128128
pub use unicode::char::UnicodeChar;
129129

130130
// from collections.
131131
pub use slice::{CloneSliceExt, VectorVector};
132-
pub use str::{IntoMaybeOwned, UnicodeStrPrelude, StrAllocating, StrVector};
132+
pub use str::{IntoMaybeOwned, StrVector};
133133
pub use string::{String, ToString};
134134
pub use vec::Vec;
135135
}

0 commit comments

Comments
 (0)