diff --git a/doc/rust.md b/doc/rust.md index b1eb5521b39..0173f61e730 100644 --- a/doc/rust.md +++ b/doc/rust.md @@ -802,7 +802,7 @@ An example of `use` declarations: ~~~~ use core::float::sin; -use core::str::{slice, to_upper}; +use core::str::{slice, contains}; use core::option::Some; fn main() { @@ -813,8 +813,8 @@ fn main() { info!(Some(1.0)); // Equivalent to - // 'info!(core::str::to_upper(core::str::slice("foo", 0, 1)));' - info!(to_upper(slice("foo", 0, 1))); + // 'info!(core::str::contains(core::str::slice("foo", 0, 1), "oo"));' + info!(contains(slice("foo", 0, 1), "oo")); } ~~~~ diff --git a/src/compiletest/errors.rs b/src/compiletest/errors.rs index bc9d694328b..3aa88523a87 100644 --- a/src/compiletest/errors.rs +++ b/src/compiletest/errors.rs @@ -51,9 +51,10 @@ fn parse_expected(line_num: uint, line: ~str) -> ~[ExpectedError] { let start_kind = idx; while idx < len && line[idx] != (' ' as u8) { idx += 1u; } - // FIXME: 4318 Instead of to_str_ascii, could use - // to_str_consume to not do a unneccessary copy. - let kind = str::slice(line, start_kind, idx).to_ascii().to_lower().to_str_ascii(); + // FIXME: #4318 Instead of to_ascii and to_str_ascii, could use + // to_ascii_consume and to_str_consume to not do a unnecessary copy. + let kind = str::slice(line, start_kind, idx); + let kind = kind.to_ascii().to_lower().to_str_ascii(); // Extract msg: while idx < len && line[idx] == (' ' as u8) { idx += 1u; } diff --git a/src/libcore/path.rs b/src/libcore/path.rs index 2c75bf98eb0..edc61299af9 100644 --- a/src/libcore/path.rs +++ b/src/libcore/path.rs @@ -19,6 +19,7 @@ use libc; use option::{None, Option, Some}; use str; use to_str::ToStr; +use ascii::{AsciiCast, AsciiStr}; #[deriving(Clone, Eq)] pub struct WindowsPath { @@ -753,8 +754,8 @@ impl GenericPath for WindowsPath { fn is_restricted(&self) -> bool { match self.filestem() { Some(stem) => { - // FIXME: 4318 Instead of to_str_ascii, could use - // to_str_consume to not do a unneccessary copy. + // FIXME: #4318 Instead of to_ascii and to_str_ascii, could use + // to_ascii_consume and to_str_consume to not do a unnecessary copy. match stem.to_ascii().to_lower().to_str_ascii() { ~"con" | ~"aux" | ~"com1" | ~"com2" | ~"com3" | ~"com4" | ~"lpt1" | ~"lpt2" | ~"lpt3" | ~"prn" | ~"nul" => true, @@ -812,8 +813,8 @@ impl GenericPath for WindowsPath { device: match self.device { None => None, - // FIXME: 4318 Instead of to_str_ascii, could use - // to_str_consume to not do a unneccessary copy. + // FIXME: #4318 Instead of to_ascii and to_str_ascii, could use + // to_ascii_consume and to_str_consume to not do a unnecessary copy. Some(ref device) => Some(device.to_ascii().to_upper().to_str_ascii()) }, is_absolute: self.is_absolute, diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 9ac36198c6a..92c965256ce 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -27,7 +27,6 @@ use option::{None, Option, Some}; use iterator::Iterator; use ptr; use str; -use u8; use uint; use vec; use to_str::ToStr; diff --git a/src/libcore/str/ascii.rs b/src/libcore/str/ascii.rs index 7c7f49fed47..9180c995ca2 100644 --- a/src/libcore/str/ascii.rs +++ b/src/libcore/str/ascii.rs @@ -199,6 +199,7 @@ impl ToStrConsume for ~[Ascii] { #[cfg(test)] mod tests { use super::*; + use str; macro_rules! v2ascii ( ( [$($e:expr),*]) => ( [$(Ascii{chr:$e}),*]); diff --git a/src/libcore/unstable/extfmt.rs b/src/libcore/unstable/extfmt.rs index aefc527219e..b812be5575a 100644 --- a/src/libcore/unstable/extfmt.rs +++ b/src/libcore/unstable/extfmt.rs @@ -521,9 +521,12 @@ pub mod rt { TyDefault => uint_to_str_prec(u, 10, prec), TyHexLower => uint_to_str_prec(u, 16, prec), - // FIXME: 4318 Instead of to_str_ascii, could use - // to_str_consume to not do a unneccessary copy. - TyHexUpper => uint_to_str_prec(u, 16, prec).to_ascii().to_upper().to_str_ascii(), + // FIXME: #4318 Instead of to_ascii and to_str_ascii, could use + // to_ascii_consume and to_str_consume to not do a unnecessary copy. + TyHexUpper => { + let s = uint_to_str_prec(u, 16, prec); + s.to_ascii().to_upper().to_str_ascii() + } TyBits => uint_to_str_prec(u, 2, prec), TyOctal => uint_to_str_prec(u, 8, prec) }; diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 3c587b3e9d0..f33bb878ee4 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -547,9 +547,10 @@ pub fn build_session_options(binary: @~str, for lint_levels.each |level| { let level_name = lint::level_to_str(*level); - // FIXME: 4318 Instead of to_str_ascii, could use - // to_str_consume to not do a unneccessary copy. - let level_short = level_name.substr(0,1).to_ascii().to_upper().to_str_ascii(); + // FIXME: #4318 Instead of to_ascii and to_str_ascii, could use + // to_ascii_consume and to_str_consume to not do a unnecessary copy. + let level_short = level_name.substr(0,1); + let level_short = level_short.to_ascii().to_upper().to_str_ascii(); let flags = vec::append(getopts::opt_strs(matches, level_short), getopts::opt_strs(matches, level_name)); for flags.each |lint_name| { diff --git a/src/librustdoc/markdown_index_pass.rs b/src/librustdoc/markdown_index_pass.rs index 4c86fc0fb6a..631c86b74f1 100644 --- a/src/librustdoc/markdown_index_pass.rs +++ b/src/librustdoc/markdown_index_pass.rs @@ -157,8 +157,8 @@ pub fn pandoc_header_id(header: &str) -> ~str { let s = str::replace(s, ~" ", ~"-"); return s; } - // FIXME: 4318 Instead of to_str_ascii, could use - // to_str_consume to not do a unneccessary copy. + // FIXME: #4318 Instead of to_ascii and to_str_ascii, could use + // to_ascii_consume and to_str_consume to not do a unnecessary copy. fn convert_to_lowercase(s: &str) -> ~str { s.to_ascii().to_lower().to_str_ascii() } fn remove_up_to_first_letter(s: &str) -> ~str { s.to_str() } fn maybe_use_section_id(s: &str) -> ~str { s.to_str() } diff --git a/src/libstd/sort.rs b/src/libstd/sort.rs index 8be3e1e6a62..cc002bc8305 100644 --- a/src/libstd/sort.rs +++ b/src/libstd/sort.rs @@ -885,8 +885,8 @@ mod tests { // tjc: funny that we have to use parens fn ile(x: &(&'static str), y: &(&'static str)) -> bool { - // FIXME: 4318 Instead of to_str_ascii, could use - // to_str_consume to not do a unneccessary copy. + // FIXME: #4318 Instead of to_ascii and to_str_ascii, could use + // to_ascii_consume and to_str_consume to not do a unnecessary copy. // (Actually, could just remove the to_str_* call, but needs an deriving(Ord) on // Ascii) let x = x.to_ascii().to_lower().to_str_ascii(); diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index c8b13a6e27f..4c8c984cd07 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -59,7 +59,10 @@ fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str { for pairs_sorted.each |kv| { let (k,v) = copy *kv; unsafe { - buffer += (fmt!("%s %0.3f\n", str::to_upper(str::raw::from_bytes(k)), v)); + let b = str::raw::from_bytes(k); + // FIXME: #4318 Instead of to_ascii and to_str_ascii, could use + // to_ascii_consume and to_str_consume to not do a unnecessary copy. + buffer += (fmt!("%s %0.3f\n", b.to_ascii().to_upper().to_str_ascii(), v)); } } @@ -68,7 +71,9 @@ fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str { // given a map, search for the frequency of a pattern fn find(mm: &HashMap<~[u8], uint>, key: ~str) -> uint { - match mm.find(&str::to_bytes(str::to_lower(key))) { + // FIXME: #4318 Instead of to_ascii and to_str_ascii, could use + // to_ascii_consume and to_str_consume to not do a unnecessary copy. + match mm.find(&str::to_bytes(key.to_ascii().to_lower().to_str_ascii())) { option::None => { return 0u; } option::Some(&num) => { return num; } }