diff options
| author | Richo Healey <richo@psych0tik.net> | 2014-05-22 16:57:53 -0700 |
|---|---|---|
| committer | Richo Healey <richo@psych0tik.net> | 2014-05-24 21:48:10 -0700 |
| commit | 553074506ecd139eb961fb91eb33ad9fd0183acb (patch) | |
| tree | 01682cf8147183250713acf5e8a77265aab7153c /src/libstd | |
| parent | bbb70cdd9cd982922cf7390459d53bde409699ae (diff) | |
| download | rust-553074506ecd139eb961fb91eb33ad9fd0183acb.tar.gz rust-553074506ecd139eb961fb91eb33ad9fd0183acb.zip | |
core: rename strbuf::StrBuf to string::String
[breaking-change]
Diffstat (limited to 'src/libstd')
38 files changed, 286 insertions, 286 deletions
diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index 83667fb5181..61e3f1a14bb 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -18,7 +18,7 @@ use option::{Option, Some, None}; use slice::{ImmutableVector, MutableVector, Vector}; use str::{OwnedStr, Str, StrAllocating, StrSlice}; use str; -use strbuf::StrBuf; +use string::String; use to_str::{IntoStr}; use vec::Vec; @@ -290,7 +290,7 @@ impl OwnedAsciiCast for ~[u8] { } } -impl OwnedAsciiCast for StrBuf { +impl OwnedAsciiCast for String { #[inline] fn is_ascii(&self) -> bool { self.as_slice().is_ascii() @@ -355,7 +355,7 @@ impl<'a> AsciiStr for &'a [Ascii] { impl IntoStr for ~[Ascii] { #[inline] - fn into_str(self) -> StrBuf { + fn into_str(self) -> String { let vector: Vec<Ascii> = self.as_slice().iter().map(|x| *x).collect(); vector.into_str() } @@ -363,7 +363,7 @@ impl IntoStr for ~[Ascii] { impl IntoStr for Vec<Ascii> { #[inline] - fn into_str(self) -> StrBuf { + fn into_str(self) -> String { unsafe { let s: &str = mem::transmute(self.as_slice()); s.to_strbuf() @@ -388,12 +388,12 @@ pub trait OwnedStrAsciiExt { /// Convert the string to ASCII upper case: /// ASCII letters 'a' to 'z' are mapped to 'A' to 'Z', /// but non-ASCII letters are unchanged. - fn into_ascii_upper(self) -> StrBuf; + fn into_ascii_upper(self) -> String; /// Convert the string to ASCII lower case: /// ASCII letters 'A' to 'Z' are mapped to 'a' to 'z', /// but non-ASCII letters are unchanged. - fn into_ascii_lower(self) -> StrBuf; + fn into_ascii_lower(self) -> String; } /// Extension methods for ASCII-subset only operations on string slices @@ -401,12 +401,12 @@ pub trait StrAsciiExt { /// Makes a copy of the string in ASCII upper case: /// ASCII letters 'a' to 'z' are mapped to 'A' to 'Z', /// but non-ASCII letters are unchanged. - fn to_ascii_upper(&self) -> StrBuf; + fn to_ascii_upper(&self) -> String; /// Makes a copy of the string in ASCII lower case: /// ASCII letters 'A' to 'Z' are mapped to 'a' to 'z', /// but non-ASCII letters are unchanged. - fn to_ascii_lower(&self) -> StrBuf; + fn to_ascii_lower(&self) -> String; /// Check that two strings are an ASCII case-insensitive match. /// Same as `to_ascii_lower(a) == to_ascii_lower(b)`, @@ -416,12 +416,12 @@ pub trait StrAsciiExt { impl<'a> StrAsciiExt for &'a str { #[inline] - fn to_ascii_upper(&self) -> StrBuf { + fn to_ascii_upper(&self) -> String { unsafe { str_copy_map_bytes(*self, ASCII_UPPER_MAP) } } #[inline] - fn to_ascii_lower(&self) -> StrBuf { + fn to_ascii_lower(&self) -> String { unsafe { str_copy_map_bytes(*self, ASCII_LOWER_MAP) } } @@ -436,20 +436,20 @@ impl<'a> StrAsciiExt for &'a str { } } -impl OwnedStrAsciiExt for StrBuf { +impl OwnedStrAsciiExt for String { #[inline] - fn into_ascii_upper(self) -> StrBuf { + fn into_ascii_upper(self) -> String { unsafe { str_map_bytes(self, ASCII_UPPER_MAP) } } #[inline] - fn into_ascii_lower(self) -> StrBuf { + fn into_ascii_lower(self) -> String { unsafe { str_map_bytes(self, ASCII_LOWER_MAP) } } } #[inline] -unsafe fn str_map_bytes(string: StrBuf, map: &'static [u8]) -> StrBuf { +unsafe fn str_map_bytes(string: String, map: &'static [u8]) -> String { let mut bytes = string.into_bytes(); for b in bytes.mut_iter() { @@ -460,7 +460,7 @@ unsafe fn str_map_bytes(string: StrBuf, map: &'static [u8]) -> StrBuf { } #[inline] -unsafe fn str_copy_map_bytes(string: &str, map: &'static [u8]) -> StrBuf { +unsafe fn str_copy_map_bytes(string: &str, map: &'static [u8]) -> String { let mut s = string.to_strbuf(); for b in s.as_mut_bytes().mut_iter() { *b = map[*b as uint]; diff --git a/src/libstd/c_str.rs b/src/libstd/c_str.rs index fbb812d3fb3..029f7162b42 100644 --- a/src/libstd/c_str.rs +++ b/src/libstd/c_str.rs @@ -82,7 +82,7 @@ use slice::{ImmutableVector, MutableVector}; use slice; use str::StrSlice; use str; -use strbuf::StrBuf; +use string::String; /// The representation of a C String. /// @@ -296,7 +296,7 @@ pub trait ToCStr { // FIXME (#12938): Until DST lands, we cannot decompose &str into & // and str, so we cannot usefully take ToCStr arguments by reference // (without forcing an additional & around &str). So we are instead -// temporarily adding an instance for ~str and StrBuf, so that we can +// temporarily adding an instance for ~str and String, so that we can // take ToCStr as owned. When DST lands, the string instances should // be revisted, and arguments bound by ToCStr should be passed by // reference. @@ -323,7 +323,7 @@ impl<'a> ToCStr for &'a str { } } -impl ToCStr for StrBuf { +impl ToCStr for String { #[inline] fn to_c_str(&self) -> CString { self.as_bytes().to_c_str() diff --git a/src/libstd/fmt.rs b/src/libstd/fmt.rs index db23a5f1720..0952652498a 100644 --- a/src/libstd/fmt.rs +++ b/src/libstd/fmt.rs @@ -27,7 +27,7 @@ general case. The `format!` macro is intended to be familiar to those coming from C's printf/fprintf functions or Python's `str.format` function. In its current -revision, the `format!` macro returns a `StrBuf` type which is the result of +revision, the `format!` macro returns a `String` type which is the result of the formatting. In the future it will also be able to pass in a stream to format arguments directly while performing minimal allocations. @@ -282,7 +282,7 @@ use std::io; # #[allow(unused_must_use)] # fn main() { -format_args!(fmt::format, "this returns {}", "StrBuf"); +format_args!(fmt::format, "this returns {}", "String"); let some_writer: &mut io::Writer = &mut io::stdout(); format_args!(|args| { write!(some_writer, "{}", args) }, "print with a {}", "closure"); @@ -490,7 +490,7 @@ use repr; use result::{Ok, Err}; use str::{Str, StrAllocating}; use str; -use strbuf::StrBuf; +use string; use slice::Vector; pub use core::fmt::{Formatter, Result, FormatWriter, Show, rt}; @@ -545,14 +545,14 @@ pub trait Poly { /// let s = format_args!(fmt::format, "Hello, {}!", "world"); /// assert_eq!(s, "Hello, world!".to_owned()); /// ``` -pub fn format(args: &Arguments) -> StrBuf{ +pub fn format(args: &Arguments) -> string::String{ let mut output = io::MemWriter::new(); let _ = write!(&mut output, "{}", args); str::from_utf8(output.unwrap().as_slice()).unwrap().into_strbuf() } /// Temporary transition utility -pub fn format_strbuf(args: &Arguments) -> StrBuf { +pub fn format_strbuf(args: &Arguments) -> string::String { let mut output = io::MemWriter::new(); let _ = write!(&mut output, "{}", args); str::from_utf8(output.unwrap().as_slice()).unwrap().into_strbuf() diff --git a/src/libstd/hash/mod.rs b/src/libstd/hash/mod.rs index fd8ce3fdbee..6ab65809a3c 100644 --- a/src/libstd/hash/mod.rs +++ b/src/libstd/hash/mod.rs @@ -23,7 +23,7 @@ * #[deriving(Hash)] * struct Person { * id: uint, - * name: StrBuf, + * name: String, * phone: u64, * } * @@ -43,7 +43,7 @@ * * struct Person { * id: uint, - * name: StrBuf, + * name: String, * phone: u64, * } * diff --git a/src/libstd/hash/sip.rs b/src/libstd/hash/sip.rs index d7dae94cf16..90767908612 100644 --- a/src/libstd/hash/sip.rs +++ b/src/libstd/hash/sip.rs @@ -363,7 +363,7 @@ mod tests { use num::ToStrRadix; use option::{Some, None}; use str::Str; - use strbuf::StrBuf; + use string::String; use slice::{Vector, ImmutableVector}; use self::test::Bencher; @@ -458,8 +458,8 @@ mod tests { let mut state_inc = SipState::new_with_keys(k0, k1); let mut state_full = SipState::new_with_keys(k0, k1); - fn to_hex_str(r: &[u8, ..8]) -> StrBuf { - let mut s = StrBuf::new(); + fn to_hex_str(r: &[u8, ..8]) -> String { + let mut s = String::new(); for b in r.iter() { s.push_str((*b as uint).to_str_radix(16u).as_slice()); } @@ -478,9 +478,9 @@ mod tests { ] } - fn result_str(h: u64) -> StrBuf { + fn result_str(h: u64) -> String { let r = result_bytes(h); - let mut s = StrBuf::new(); + let mut s = String::new(); for b in r.iter() { s.push_str((*b as uint).to_str_radix(16u).as_slice()); } diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 0d71c3de76c..c22bc92fb65 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -76,7 +76,7 @@ Some examples of obvious things you might want to do let path = Path::new("message.txt"); let mut file = BufferedReader::new(File::open(&path)); - let lines: Vec<StrBuf> = file.lines().map(|x| x.unwrap()).collect(); + let lines: Vec<String> = file.lines().map(|x| x.unwrap()).collect(); ``` * Make a simple TCP client connection and request @@ -228,7 +228,7 @@ use result::{Ok, Err, Result}; use slice::{Vector, MutableVector, ImmutableVector}; use str::{StrSlice, StrAllocating}; use str; -use strbuf::StrBuf; +use string::String; use uint; use vec::Vec; @@ -293,7 +293,7 @@ pub struct IoError { /// A human-readable description about the error pub desc: &'static str, /// Detailed information about this error, not always available - pub detail: Option<StrBuf> + pub detail: Option<String> } impl IoError { @@ -632,7 +632,7 @@ pub trait Reader { /// This function returns all of the same errors as `read_to_end` with an /// additional error if the reader's contents are not a valid sequence of /// UTF-8 bytes. - fn read_to_str(&mut self) -> IoResult<StrBuf> { + fn read_to_str(&mut self) -> IoResult<String> { self.read_to_end().and_then(|s| { match str::from_utf8(s.as_slice()) { Some(s) => Ok(s.to_strbuf()), @@ -1244,8 +1244,8 @@ pub struct Lines<'r, T> { buffer: &'r mut T, } -impl<'r, T: Buffer> Iterator<IoResult<StrBuf>> for Lines<'r, T> { - fn next(&mut self) -> Option<IoResult<StrBuf>> { +impl<'r, T: Buffer> Iterator<IoResult<String>> for Lines<'r, T> { + fn next(&mut self) -> Option<IoResult<String>> { match self.buffer.read_line() { Ok(x) => Some(Ok(x)), Err(IoError { kind: EndOfFile, ..}) => None, @@ -1330,7 +1330,7 @@ pub trait Buffer: Reader { /// /// Additionally, this function can fail if the line of input read is not a /// valid UTF-8 sequence of bytes. - fn read_line(&mut self) -> IoResult<StrBuf> { + fn read_line(&mut self) -> IoResult<String> { self.read_until('\n' as u8).and_then(|line| match str::from_utf8(line.as_slice()) { Some(s) => Ok(s.to_strbuf()), diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index d2a83dd840d..468bf5551b3 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -583,11 +583,11 @@ mod tests { } }) - pub fn read_all(input: &mut Reader) -> StrBuf { + pub fn read_all(input: &mut Reader) -> String { input.read_to_str().unwrap() } - pub fn run_output(cmd: Command) -> StrBuf { + pub fn run_output(cmd: Command) -> String { let p = cmd.spawn(); assert!(p.is_ok()); let mut p = p.unwrap(); diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index ca70fd162b7..0d42e1743f5 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -49,7 +49,7 @@ //! `&str`, a UTF-8 string, is a built-in type, and the standard library //! defines methods for it on a variety of traits in the //! [`str`](str/index.html) module. Rust strings are immutable; -//! use the `StrBuf` type defined in [`strbuf`](strbuf/index.html) +//! use the `String` type defined in [`strbuf`](strbuf/index.html) //! for a mutable string builder. //! //! For converting to strings use the [`format!`](fmt/index.html) @@ -206,7 +206,7 @@ pub mod prelude; pub mod slice; pub mod vec; pub mod str; -pub mod strbuf; +pub mod string; pub mod ascii; @@ -285,5 +285,5 @@ mod std { // The test runner requires std::slice::Vector, so re-export std::slice just for it. #[cfg(test)] pub use slice; - #[cfg(test)] pub use strbuf; + #[cfg(test)] pub use string; } diff --git a/src/libstd/local_data.rs b/src/libstd/local_data.rs index 2c7e16cf18b..2412e18bf62 100644 --- a/src/libstd/local_data.rs +++ b/src/libstd/local_data.rs @@ -276,7 +276,7 @@ mod tests { #[test] fn test_tls_multitask() { - static my_key: Key<StrBuf> = &Key; + static my_key: Key<String> = &Key; my_key.replace(Some("parent data".to_strbuf())); task::spawn(proc() { // TLS shouldn't carry over. @@ -294,7 +294,7 @@ mod tests { #[test] fn test_tls_overwrite() { - static my_key: Key<StrBuf> = &Key; + static my_key: Key<String> = &Key; my_key.replace(Some("first data".to_strbuf())); my_key.replace(Some("next data".to_strbuf())); // Shouldn't leak. assert!(my_key.get().unwrap().as_slice() == "next data"); @@ -302,7 +302,7 @@ mod tests { #[test] fn test_tls_pop() { - static my_key: Key<StrBuf> = &Key; + static my_key: Key<String> = &Key; my_key.replace(Some("weasel".to_strbuf())); assert!(my_key.replace(None).unwrap() == "weasel".to_strbuf()); // Pop must remove the data from the map. @@ -317,7 +317,7 @@ mod tests { // to get recorded as something within a rust stack segment. Then a // subsequent upcall (esp. for logging, think vsnprintf) would run on // a stack smaller than 1 MB. - static my_key: Key<StrBuf> = &Key; + static my_key: Key<String> = &Key; task::spawn(proc() { my_key.replace(Some("hax".to_strbuf())); }); @@ -325,7 +325,7 @@ mod tests { #[test] fn test_tls_multiple_types() { - static str_key: Key<StrBuf> = &Key; + static str_key: Key<String> = &Key; static box_key: Key<@()> = &Key; static int_key: Key<int> = &Key; task::spawn(proc() { @@ -337,7 +337,7 @@ mod tests { #[test] fn test_tls_overwrite_multiple_types() { - static str_key: Key<StrBuf> = &Key; + static str_key: Key<String> = &Key; static box_key: Key<@()> = &Key; static int_key: Key<int> = &Key; task::spawn(proc() { @@ -356,7 +356,7 @@ mod tests { #[test] #[should_fail] fn test_tls_cleanup_on_failure() { - static str_key: Key<StrBuf> = &Key; + static str_key: Key<String> = &Key; static box_key: Key<@()> = &Key; static int_key: Key<int> = &Key; str_key.replace(Some("parent data".to_strbuf())); diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs index 66d93c230a5..b7bd3705bf2 100644 --- a/src/libstd/num/f32.rs +++ b/src/libstd/num/f32.rs @@ -20,7 +20,7 @@ use intrinsics; use libc::c_int; use num::strconv; use num; -use strbuf::StrBuf; +use string::String; pub use core::f32::{RADIX, MANTISSA_DIGITS, DIGITS, EPSILON, MIN_VALUE}; pub use core::f32::{MIN_POS_VALUE, MAX_VALUE, MIN_EXP, MAX_EXP, MIN_10_EXP}; @@ -243,7 +243,7 @@ impl FloatMath for f32 { /// /// * num - The float value #[inline] -pub fn to_str(num: f32) -> StrBuf { +pub fn to_str(num: f32) -> String { let (r, _) = strconv::float_to_str_common( num, 10u, true, strconv::SignNeg, strconv::DigAll, strconv::ExpNone, false); r @@ -255,7 +255,7 @@ pub fn to_str(num: f32) -> StrBuf { /// /// * num - The float value #[inline] -pub fn to_str_hex(num: f32) -> StrBuf { +pub fn to_str_hex(num: f32) -> String { let (r, _) = strconv::float_to_str_common( num, 16u, true, strconv::SignNeg, strconv::DigAll, strconv::ExpNone, false); r @@ -269,7 +269,7 @@ pub fn to_str_hex(num: f32) -> StrBuf { /// * num - The float value /// * radix - The base to use #[inline] -pub fn to_str_radix_special(num: f32, rdx: uint) -> (StrBuf, bool) { +pub fn to_str_radix_special(num: f32, rdx: uint) -> (String, bool) { strconv::float_to_str_common(num, rdx, true, strconv::SignNeg, strconv::DigAll, strconv::ExpNone, false) } @@ -282,7 +282,7 @@ pub fn to_str_radix_special(num: f32, rdx: uint) -> (StrBuf, bool) { /// * num - The float value /// * digits - The number of significant digits #[inline] -pub fn to_str_exact(num: f32, dig: uint) -> StrBuf { +pub fn to_str_exact(num: f32, dig: uint) -> String { let (r, _) = strconv::float_to_str_common( num, 10u, true, strconv::SignNeg, strconv::DigExact(dig), strconv::ExpNone, false); r @@ -296,7 +296,7 @@ pub fn to_str_exact(num: f32, dig: uint) -> StrBuf { /// * num - The float value /// * digits - The number of significant digits #[inline] -pub fn to_str_digits(num: f32, dig: uint) -> StrBuf { +pub fn to_str_digits(num: f32, dig: uint) -> String { let (r, _) = strconv::float_to_str_common( num, 10u, true, strconv::SignNeg, strconv::DigMax(dig), strconv::ExpNone, false); r @@ -311,7 +311,7 @@ pub fn to_str_digits(num: f32, dig: uint) -> StrBuf { /// * digits - The number of digits after the decimal point /// * upper - Use `E` instead of `e` for the exponent sign #[inline] -pub fn to_str_exp_exact(num: f32, dig: uint, upper: bool) -> StrBuf { +pub fn to_str_exp_exact(num: f32, dig: uint, upper: bool) -> String { let (r, _) = strconv::float_to_str_common( num, 10u, true, strconv::SignNeg, strconv::DigExact(dig), strconv::ExpDec, upper); r @@ -326,7 +326,7 @@ pub fn to_str_exp_exact(num: f32, dig: uint, upper: bool) -> StrBuf { /// * digits - The number of digits after the decimal point /// * upper - Use `E` instead of `e` for the exponent sign #[inline] -pub fn to_str_exp_digits(num: f32, dig: uint, upper: bool) -> StrBuf { +pub fn to_str_exp_digits(num: f32, dig: uint, upper: bool) -> String { let (r, _) = strconv::float_to_str_common( num, 10u, true, strconv::SignNeg, strconv::DigMax(dig), strconv::ExpDec, upper); r @@ -346,7 +346,7 @@ impl num::ToStrRadix for f32 { /// possible misinterpretation of the result at higher bases. If those values /// are expected, use `to_str_radix_special()` instead. #[inline] - fn to_str_radix(&self, rdx: uint) -> StrBuf { + fn to_str_radix(&self, rdx: uint) -> String { let (r, special) = strconv::float_to_str_common( *self, rdx, true, strconv::SignNeg, strconv::DigAll, strconv::ExpNone, false); if special { fail!("number has a special value, \ diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs index be4e4dc0d66..e7b29c733ec 100644 --- a/src/libstd/num/f64.rs +++ b/src/libstd/num/f64.rs @@ -19,7 +19,7 @@ use intrinsics; use libc::c_int; use num::strconv; use num; -use strbuf::StrBuf; +use string::String; pub use core::f64::{RADIX, MANTISSA_DIGITS, DIGITS, EPSILON, MIN_VALUE}; pub use core::f64::{MIN_POS_VALUE, MAX_VALUE, MIN_EXP, MAX_EXP, MIN_10_EXP}; @@ -251,7 +251,7 @@ impl FloatMath for f64 { /// /// * num - The float value #[inline] -pub fn to_str(num: f64) -> StrBuf { +pub fn to_str(num: f64) -> String { let (r, _) = strconv::float_to_str_common( num, 10u, true, strconv::SignNeg, strconv::DigAll, strconv::ExpNone, false); r @@ -263,7 +263,7 @@ pub fn to_str(num: f64) -> StrBuf { /// /// * num - The float value #[inline] -pub fn to_str_hex(num: f64) -> StrBuf { +pub fn to_str_hex(num: f64) -> String { let (r, _) = strconv::float_to_str_common( num, 16u, true, strconv::SignNeg, strconv::DigAll, strconv::ExpNone, false); r @@ -277,7 +277,7 @@ pub fn to_str_hex(num: f64) -> StrBuf { /// * num - The float value /// * radix - The base to use #[inline] -pub fn to_str_radix_special(num: f64, rdx: uint) -> (StrBuf, bool) { +pub fn to_str_radix_special(num: f64, rdx: uint) -> (String, bool) { strconv::float_to_str_common(num, rdx, true, strconv::SignNeg, strconv::DigAll, strconv::ExpNone, false) } @@ -290,7 +290,7 @@ pub fn to_str_radix_special(num: f64, rdx: uint) -> (StrBuf, bool) { /// * num - The float value /// * digits - The number of significant digits #[inline] -pub fn to_str_exact(num: f64, dig: uint) -> StrBuf { +pub fn to_str_exact(num: f64, dig: uint) -> String { let (r, _) = strconv::float_to_str_common( num, 10u, true, strconv::SignNeg, strconv::DigExact(dig), strconv::ExpNone, false); r @@ -304,7 +304,7 @@ pub fn to_str_exact(num: f64, dig: uint) -> StrBuf { /// * num - The float value /// * digits - The number of significant digits #[inline] -pub fn to_str_digits(num: f64, dig: uint) -> StrBuf { +pub fn to_str_digits(num: f64, dig: uint) -> String { let (r, _) = strconv::float_to_str_common( num, 10u, true, strconv::SignNeg, strconv::DigMax(dig), strconv::ExpNone, false); r @@ -319,7 +319,7 @@ pub fn to_str_digits(num: f64, dig: uint) -> StrBuf { /// * digits - The number of digits after the decimal point /// * upper - Use `E` instead of `e` for the exponent sign #[inline] -pub fn to_str_exp_exact(num: f64, dig: uint, upper: bool) -> StrBuf { +pub fn to_str_exp_exact(num: f64, dig: uint, upper: bool) -> String { let (r, _) = strconv::float_to_str_common( num, 10u, true, strconv::SignNeg, strconv::DigExact(dig), strconv::ExpDec, upper); r @@ -334,7 +334,7 @@ pub fn to_str_exp_exact(num: f64, dig: uint, upper: bool) -> StrBuf { /// * digits - The number of digits after the decimal point /// * upper - Use `E` instead of `e` for the exponent sign #[inline] -pub fn to_str_exp_digits(num: f64, dig: uint, upper: bool) -> StrBuf { +pub fn to_str_exp_digits(num: f64, dig: uint, upper: bool) -> String { let (r, _) = strconv::float_to_str_common( num, 10u, true, strconv::SignNeg, strconv::DigMax(dig), strconv::ExpDec, upper); r @@ -354,7 +354,7 @@ impl num::ToStrRadix for f64 { /// possible misinterpretation of the result at higher bases. If those values /// are expected, use `to_str_radix_special()` instead. #[inline] - fn to_str_radix(&self, rdx: uint) -> StrBuf { + fn to_str_radix(&self, rdx: uint) -> String { let (r, special) = strconv::float_to_str_common( *self, rdx, true, strconv::SignNeg, strconv::DigAll, strconv::ExpNone, false); if special { fail!("number has a special value, \ diff --git a/src/libstd/num/i16.rs b/src/libstd/num/i16.rs index 7d08c181e9e..e0c5d93f28a 100644 --- a/src/libstd/num/i16.rs +++ b/src/libstd/num/i16.rs @@ -15,7 +15,7 @@ use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; use slice::ImmutableVector; -use strbuf::StrBuf; +use string::String; pub use core::i16::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/i32.rs b/src/libstd/num/i32.rs index 2504d3f5766..6938689f47d 100644 --- a/src/libstd/num/i32.rs +++ b/src/libstd/num/i32.rs @@ -15,7 +15,7 @@ use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; use slice::ImmutableVector; -use strbuf::StrBuf; +use string::String; pub use core::i32::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/i64.rs b/src/libstd/num/i64.rs index 7fc6a091dfc..4be43876105 100644 --- a/src/libstd/num/i64.rs +++ b/src/libstd/num/i64.rs @@ -15,7 +15,7 @@ use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; use slice::ImmutableVector; -use strbuf::StrBuf; +use string::String; pub use core::i64::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/i8.rs b/src/libstd/num/i8.rs index a39a6ced077..b0459ca46f1 100644 --- a/src/libstd/num/i8.rs +++ b/src/libstd/num/i8.rs @@ -15,7 +15,7 @@ use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; use slice::ImmutableVector; -use strbuf::StrBuf; +use string::String; pub use core::i8::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/int.rs b/src/libstd/num/int.rs index 2a23a35be6d..774b0d7d8cf 100644 --- a/src/libstd/num/int.rs +++ b/src/libstd/num/int.rs @@ -15,7 +15,7 @@ use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; use slice::ImmutableVector; -use strbuf::StrBuf; +use string::String; pub use core::int::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/int_macros.rs b/src/libstd/num/int_macros.rs index 31a0edfbc38..4456c8124ba 100644 --- a/src/libstd/num/int_macros.rs +++ b/src/libstd/num/int_macros.rs @@ -77,7 +77,7 @@ pub fn to_str_bytes<U>(n: $T, radix: uint, f: |v: &[u8]| -> U) -> U { impl ToStrRadix for $T { /// Convert to a string in a given base. #[inline] - fn to_str_radix(&self, radix: uint) -> StrBuf { + fn to_str_radix(&self, radix: uint) -> String { format_strbuf!("{}", ::fmt::radix(*self, radix as u8)) } } diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index c1d6bbb492d..9700f8c9970 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -16,7 +16,7 @@ #![allow(missing_doc)] use option::Option; -use strbuf::StrBuf; +use string::String; #[cfg(test)] use fmt::Show; @@ -112,7 +112,7 @@ pub trait FloatMath: Float { /// A generic trait for converting a value to a string with a radix (base) pub trait ToStrRadix { - fn to_str_radix(&self, radix: uint) -> StrBuf; + fn to_str_radix(&self, radix: uint) -> String; } /// A generic trait for converting a string with a radix (base) to a value diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index 795534dc283..1efe83217f4 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -22,7 +22,7 @@ use option::{None, Option, Some}; use slice::{ImmutableVector, MutableVector}; use std::cmp::{Ord, Eq}; use str::StrSlice; -use strbuf::StrBuf; +use string::String; use vec::Vec; /// A flag that specifies whether to use exponential (scientific) notation. @@ -496,10 +496,10 @@ pub fn float_to_str_common<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Float+ Div<T,T>+Neg<T>+Rem<T,T>+Mul<T,T>>( num: T, radix: uint, negative_zero: bool, sign: SignFormat, digits: SignificantDigits, exp_format: ExponentFormat, exp_capital: bool - ) -> (StrBuf, bool) { + ) -> (String, bool) { let (bytes, special) = float_to_str_bytes_common(num, radix, negative_zero, sign, digits, exp_format, exp_capital); - (StrBuf::from_utf8(bytes).unwrap(), special) + (String::from_utf8(bytes).unwrap(), special) } // Some constants for from_str_bytes_common's input validation, diff --git a/src/libstd/num/u16.rs b/src/libstd/num/u16.rs index 6d68af99890..5200fbd7a3b 100644 --- a/src/libstd/num/u16.rs +++ b/src/libstd/num/u16.rs @@ -15,7 +15,7 @@ use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; use slice::ImmutableVector; -use strbuf::StrBuf; +use string::String; pub use core::u16::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/u32.rs b/src/libstd/num/u32.rs index 130ca2c4855..18cdb9e7e87 100644 --- a/src/libstd/num/u32.rs +++ b/src/libstd/num/u32.rs @@ -15,7 +15,7 @@ use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; use slice::ImmutableVector; -use strbuf::StrBuf; +use string::String; pub use core::u32::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/u64.rs b/src/libstd/num/u64.rs index 559fcf6e7d1..7c17d2cd0bd 100644 --- a/src/libstd/num/u64.rs +++ b/src/libstd/num/u64.rs @@ -15,7 +15,7 @@ use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; use slice::ImmutableVector; -use strbuf::StrBuf; +use string::String; pub use core::u64::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/u8.rs b/src/libstd/num/u8.rs index f855c8c4951..05d86fba40e 100644 --- a/src/libstd/num/u8.rs +++ b/src/libstd/num/u8.rs @@ -15,7 +15,7 @@ use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; use slice::ImmutableVector; -use strbuf::StrBuf; +use string::String; pub use core::u8::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/uint.rs b/src/libstd/num/uint.rs index f651cf72cca..ac38f740931 100644 --- a/src/libstd/num/uint.rs +++ b/src/libstd/num/uint.rs @@ -15,7 +15,7 @@ use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; use slice::ImmutableVector; -use strbuf::StrBuf; +use string::String; pub use core::uint::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs index ba329065a6e..e59e638faa9 100644 --- a/src/libstd/num/uint_macros.rs +++ b/src/libstd/num/uint_macros.rs @@ -78,7 +78,7 @@ pub fn to_str_bytes<U>(n: $T, radix: uint, f: |v: &[u8]| -> U) -> U { impl ToStrRadix for $T { /// Convert to a string in a given base. #[inline] - fn to_str_radix(&self, radix: uint) -> StrBuf { + fn to_str_radix(&self, radix: uint) -> String { format_strbuf!("{}", ::fmt::radix(*self, radix as u8)) } } diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 21903f6b6b8..00e5574c86d 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -44,7 +44,7 @@ use result::{Err, Ok, Result}; use slice::{Vector, ImmutableVector, MutableVector, OwnedVector}; use str::{Str, StrSlice, StrAllocating}; use str; -use strbuf::StrBuf; +use string::String; use sync::atomics::{AtomicInt, INIT_ATOMIC_INT, SeqCst}; use vec::Vec; @@ -104,13 +104,13 @@ pub mod win32 { use option; use os::TMPBUF_SZ; use slice::{MutableVector, ImmutableVector}; - use strbuf::StrBuf; + use string::String; use str::{StrSlice, StrAllocating}; use str; use vec::Vec; pub fn fill_utf16_buf_and_decode(f: |*mut u16, DWORD| -> DWORD) - -> Option<StrBuf> { + -> Option<String> { unsafe { let mut n = TMPBUF_SZ as DWORD; @@ -176,7 +176,7 @@ fn with_env_lock<T>(f: || -> T) -> T { /// /// Invalid UTF-8 bytes are replaced with \uFFFD. See `str::from_utf8_lossy()` /// for details. -pub fn env() -> Vec<(StrBuf,StrBuf)> { +pub fn env() -> Vec<(String,String)> { env_as_bytes().move_iter().map(|(k,v)| { let k = str::from_utf8_lossy(k.as_slice()).to_strbuf(); let v = str::from_utf8_lossy(v.as_slice()).to_strbuf(); @@ -276,7 +276,7 @@ pub fn env_as_bytes() -> Vec<(Vec<u8>,Vec<u8>)> { /// # Failure /// /// Fails if `n` has any interior NULs. -pub fn getenv(n: &str) -> Option<StrBuf> { +pub fn getenv(n: &str) -> Option<String> { getenv_as_bytes(n).map(|v| str::from_utf8_lossy(v.as_slice()).to_strbuf()) } @@ -306,7 +306,7 @@ pub fn getenv_as_bytes(n: &str) -> Option<Vec<u8>> { #[cfg(windows)] /// Fetches the environment variable `n` from the current process, returning /// None if the variable isn't set. -pub fn getenv(n: &str) -> Option<StrBuf> { +pub fn getenv(n: &str) -> Option<String> { unsafe { with_env_lock(|| { use os::win32::{as_utf16_p, fill_utf16_buf_and_decode}; @@ -436,7 +436,7 @@ pub fn pipe() -> Pipe { } /// Returns the proper dll filename for the given basename of a file. -pub fn dll_filename(base: &str) -> StrBuf { +pub fn dll_filename(base: &str) -> String { format_strbuf!("{}{}{}", consts::DLL_PREFIX, base, consts::DLL_SUFFIX) } @@ -692,11 +692,11 @@ pub fn errno() -> uint { } /// Return the string corresponding to an `errno()` value of `errnum`. -pub fn error_string(errnum: uint) -> StrBuf { +pub fn error_string(errnum: uint) -> String { return strerror(errnum); #[cfg(unix)] - fn strerror(errnum: uint) -> StrBuf { + fn strerror(errnum: uint) -> String { #[cfg(target_os = "macos")] #[cfg(target_os = "android")] #[cfg(target_os = "freebsd")] @@ -741,7 +741,7 @@ pub fn error_string(errnum: uint) -> StrBuf { } #[cfg(windows)] - fn strerror(errnum: uint) -> StrBuf { + fn strerror(errnum: uint) -> String { use libc::types::os::arch::extra::DWORD; use libc::types::os::arch::extra::LPWSTR; use libc::types::os::arch::extra::LPVOID; @@ -793,7 +793,7 @@ pub fn error_string(errnum: uint) -> StrBuf { } /// Get a string representing the platform-dependent last error -pub fn last_os_error() -> StrBuf { +pub fn last_os_error() -> String { error_string(errno() as uint) } @@ -856,7 +856,7 @@ fn real_args_as_bytes() -> Vec<Vec<u8>> { } #[cfg(not(windows))] -fn real_args() -> Vec<StrBuf> { +fn real_args() -> Vec<String> { real_args_as_bytes().move_iter() .map(|v| { str::from_utf8_lossy(v.as_slice()).into_strbuf() @@ -864,7 +864,7 @@ fn real_args() -> Vec<StrBuf> { } #[cfg(windows)] -fn real_args() -> Vec<StrBuf> { +fn real_args() -> Vec<String> { use slice; use option::Expect; @@ -919,13 +919,13 @@ extern "system" { /// The arguments are interpreted as utf-8, with invalid bytes replaced with \uFFFD. /// See `str::from_utf8_lossy` for details. #[cfg(not(test))] -pub fn args() -> Vec<StrBuf> { +pub fn args() -> Vec<String> { real_args() } #[cfg(test)] #[allow(missing_doc)] -pub fn args() -> ::realstd::vec::Vec<::realstd::strbuf::StrBuf> { +pub fn args() -> ::realstd::vec::Vec<::realstd::string::String> { ::realstd::os::args() } @@ -1524,7 +1524,7 @@ mod tests { assert!(a.len() >= 1); } - fn make_rand_name() -> StrBuf { + fn make_rand_name() -> String { let mut rng = rand::task_rng(); let n = format_strbuf!("TEST{}", rng.gen_ascii_str(10u).as_slice()); assert!(getenv(n.as_slice()).is_none()); diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index dc483133e3c..681b19a2d1a 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -73,7 +73,7 @@ use iter::Iterator; use option::{Option, None, Some}; use str; use str::{MaybeOwned, Str, StrSlice, from_utf8_lossy}; -use strbuf::StrBuf; +use string::String; use slice::Vector; use slice::{ImmutableEqVector, ImmutableVector}; use vec::Vec; @@ -507,7 +507,7 @@ impl<'a> BytesContainer for &'a str { fn is_str(_: Option<&'a str>) -> bool { true } } -impl BytesContainer for StrBuf { +impl BytesContainer for String { #[inline] fn container_as_bytes<'a>(&'a self) -> &'a [u8] { self.as_bytes() @@ -517,7 +517,7 @@ impl BytesContainer for StrBuf { Some(self.as_slice()) } #[inline] - fn is_str(_: Option<StrBuf>) -> bool { true } + fn is_str(_: Option<String>) -> bool { true } } impl<'a> BytesContainer for &'a [u8] { diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 485c2b8a0d2..763883a159f 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -22,7 +22,7 @@ use mem; use option::{Option, Some, None}; use slice::{Vector, OwnedVector, ImmutableVector}; use str::{CharSplits, Str, StrAllocating, StrVector, StrSlice}; -use strbuf::StrBuf; +use string::String; use vec::Vec; use super::{contains_nul, BytesContainer, GenericPath, GenericPathUnsafe}; @@ -74,7 +74,7 @@ pub type Components<'a> = Map<'a, Option<&'a str>, &'a [u8], // preserved by the data structure; let the Windows API error out on them. #[deriving(Clone)] pub struct Path { - repr: StrBuf, // assumed to never be empty + repr: String, // assumed to never be empty prefix: Option<PathPrefix>, sepidx: Option<uint> // index of the final separator in the non-prefix portion of repr } @@ -194,7 +194,7 @@ impl GenericPathUnsafe for Path { let filename = filename.container_as_str().unwrap(); match self.sepidx_or_prefix_len() { None if ".." == self.repr.as_slice() => { - let mut s = StrBuf::with_capacity(3 + filename.len()); + let mut s = String::with_capacity(3 + filename.len()); s.push_str(".."); s.push_char(SEP); s.push_str(filename); @@ -204,20 +204,20 @@ impl GenericPathUnsafe for Path { self.update_normalized(filename); } Some((_,idxa,end)) if self.repr.as_slice().slice(idxa,end) == ".." => { - let mut s = StrBuf::with_capacity(end + 1 + filename.len()); + let mut s = String::with_capacity(end + 1 + filename.len()); s.push_str(self.repr.as_slice().slice_to(end)); s.push_char(SEP); s.push_str(filename); self.update_normalized(s); } Some((idxb,idxa,_)) if self.prefix == Some(DiskPrefix) && idxa == self.prefix_len() => { - let mut s = StrBuf::with_capacity(idxb + filename.len()); + let mut s = String::with_capacity(idxb + filename.len()); s.push_str(self.repr.as_slice().slice_to(idxb)); s.push_str(filename); self.update_normalized(s); } Some((idxb,_,_)) => { - let mut s = StrBuf::with_capacity(idxb + 1 + filename.len()); + let mut s = String::with_capacity(idxb + 1 + filename.len()); s.push_str(self.repr.as_slice().slice_to(idxb)); s.push_char(SEP); s.push_str(filename); @@ -261,7 +261,7 @@ impl GenericPathUnsafe for Path { let newpath = Path::normalize__(path, prefix); me.repr = match newpath { Some(p) => p, - None => StrBuf::from_str(path) + None => String::from_str(path) }; me.prefix = prefix; me.update_sepidx(); @@ -272,7 +272,7 @@ impl GenericPathUnsafe for Path { let path_ = if is_verbatim(me) { Path::normalize__(path, None) } else { None }; let pathlen = path_.as_ref().map_or(path.len(), |p| p.len()); - let mut s = StrBuf::with_capacity(me.repr.len() + 1 + pathlen); + let mut s = String::with_capacity(me.repr.len() + 1 + pathlen); s.push_str(me.repr.as_slice()); let plen = me.prefix_len(); // if me is "C:" we don't want to add a path separator @@ -424,7 +424,7 @@ impl GenericPath for Path { match self.sepidx_or_prefix_len() { None if "." == self.repr.as_slice() => false, None => { - self.repr = StrBuf::from_str("."); + self.repr = String::from_str("."); self.sepidx = None; true } @@ -687,7 +687,7 @@ impl Path { } } - fn normalize_<S: StrAllocating>(s: S) -> (Option<PathPrefix>, StrBuf) { + fn normalize_<S: StrAllocating>(s: S) -> (Option<PathPrefix>, String) { // make borrowck happy let (prefix, val) = { let prefix = parse_prefix(s.as_slice()); @@ -700,13 +700,13 @@ impl Path { }) } - fn normalize__(s: &str, prefix: Option<PathPrefix>) -> Option<StrBuf> { + fn normalize__(s: &str, prefix: Option<PathPrefix>) -> Option<String> { if prefix_is_verbatim(prefix) { // don't do any normalization match prefix { Some(VerbatimUNCPrefix(x, 0)) if s.len() == 8 + x => { // the server component has no trailing '\' - let mut s = StrBuf::from_str(s); + let mut s = String::from_str(s); s.push_char(SEP); Some(s) } @@ -735,7 +735,7 @@ impl Path { match prefix.unwrap() { DiskPrefix => { let len = prefix_len(prefix) + is_abs as uint; - let mut s = StrBuf::from_str(s.slice_to(len)); + let mut s = String::from_str(s.slice_to(len)); unsafe { let v = s.as_mut_vec(); *v.get_mut(0) = v.get(0) @@ -753,7 +753,7 @@ impl Path { } VerbatimDiskPrefix => { let len = prefix_len(prefix) + is_abs as uint; - let mut s = StrBuf::from_str(s.slice_to(len)); + let mut s = String::from_str(s.slice_to(len)); unsafe { let v = s.as_mut_vec(); *v.get_mut(4) = v.get(4).to_ascii().to_upper().to_byte(); @@ -763,18 +763,18 @@ impl Path { _ => { let plen = prefix_len(prefix); if s.len() > plen { - Some(StrBuf::from_str(s.slice_to(plen))) + Some(String::from_str(s.slice_to(plen))) } else { None } } } } else if is_abs && comps.is_empty() { - Some(StrBuf::from_char(1, SEP)) + Some(String::from_char(1, SEP)) } else { let prefix_ = s.slice_to(prefix_len(prefix)); let n = prefix_.len() + if is_abs { comps.len() } else { comps.len() - 1} + comps.iter().map(|v| v.len()).sum(); - let mut s = StrBuf::with_capacity(n); + let mut s = String::with_capacity(n); match prefix { Some(DiskPrefix) => { s.push_char(prefix_[0].to_ascii().to_upper().to_char()); diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index bd367293db8..8d028a7a96a 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -80,7 +80,7 @@ pub use slice::{CloneableVector, ImmutableCloneableVector, MutableCloneableVecto pub use slice::{ImmutableVector, MutableVector}; pub use slice::{ImmutableEqVector, ImmutableTotalOrdVector, MutableTotalOrdVector}; pub use slice::{Vector, VectorVector, OwnedVector, MutableVectorAllocating}; -pub use strbuf::StrBuf; +pub use string::String; pub use vec::Vec; // Reexported runtime types diff --git a/src/libstd/repr.rs b/src/libstd/repr.rs index 8da906d8521..d800232d3b8 100644 --- a/src/libstd/repr.rs +++ b/src/libstd/repr.rs @@ -30,7 +30,7 @@ use reflect; use result::{Ok, Err}; use slice::Vector; use str::{Str, StrSlice}; -use strbuf::StrBuf; +use string::String; use to_str::ToStr; use vec::Vec; @@ -602,7 +602,7 @@ pub fn write_repr<T>(writer: &mut io::Writer, object: &T) -> io::IoResult<()> { } } -pub fn repr_to_str<T>(t: &T) -> StrBuf { +pub fn repr_to_str<T>(t: &T) -> String { use str; use str::StrAllocating; use io; diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index 3e61f3ff236..cd59de8899a 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -420,10 +420,10 @@ mod test { #[test] fn tls() { - local_data_key!(key: @StrBuf) + local_data_key!(key: @String) key.replace(Some(@"data".to_strbuf())); assert_eq!(key.get().unwrap().as_slice(), "data"); - local_data_key!(key2: @StrBuf) + local_data_key!(key2: @String) key2.replace(Some(@"data".to_strbuf())); assert_eq!(key2.get().unwrap().as_slice(), "data"); } diff --git a/src/libstd/rt/unwind.rs b/src/libstd/rt/unwind.rs index 8f2df831196..be05bfceaac 100644 --- a/src/libstd/rt/unwind.rs +++ b/src/libstd/rt/unwind.rs @@ -71,7 +71,7 @@ use rt::backtrace; use rt::local::Local; use rt::task::Task; use str::Str; -use strbuf::StrBuf; +use string::String; use task::TaskResult; use uw = rt::libunwind; @@ -389,7 +389,7 @@ fn begin_unwind_inner(msg: Box<Any:Send>, { let msg_s = match msg.as_ref::<&'static str>() { Some(s) => *s, - None => match msg.as_ref::<StrBuf>() { + None => match msg.as_ref::<String>() { Some(s) => s.as_slice(), None => "Box<Any>", } diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 0eced707944..d68ed099a4a 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -79,7 +79,7 @@ use option::{None, Option, Some}; use result::Result; use slice::Vector; use slice::{ImmutableVector, MutableVector, CloneableVector}; -use strbuf::StrBuf; +use string::String; use vec::Vec; pub use core::str::{from_utf8, CharEq, Chars, CharOffsets}; @@ -98,8 +98,8 @@ Section: Creating a string /// /// Returns `Err` with the original vector if the vector contains invalid /// UTF-8. -pub fn from_utf8_owned(vv: Vec<u8>) -> Result<StrBuf, Vec<u8>> { - StrBuf::from_utf8(vv) +pub fn from_utf8_owned(vv: Vec<u8>) -> Result<String, Vec<u8>> { + String::from_utf8(vv) } /// Convert a byte to a UTF-8 string @@ -107,42 +107,42 @@ pub fn from_utf8_owned(vv: Vec<u8>) -> Result<StrBuf, Vec<u8>> { /// # Failure /// /// Fails if invalid UTF-8 -pub fn from_byte(b: u8) -> StrBuf { +pub fn from_byte(b: u8) -> String { assert!(b < 128u8); - StrBuf::from_char(1, b as char) + String::from_char(1, b as char) } /// Convert a char to a string -pub fn from_char(ch: char) -> StrBuf { - let mut buf = StrBuf::new(); +pub fn from_char(ch: char) -> String { + let mut buf = String::new(); buf.push_char(ch); buf } /// Convert a vector of chars to a string -pub fn from_chars(chs: &[char]) -> StrBuf { +pub fn from_chars(chs: &[char]) -> String { chs.iter().map(|c| *c).collect() } /// Methods for vectors of strings pub trait StrVector { /// Concatenate a vector of strings. - fn concat(&self) -> StrBuf; + fn concat(&self) -> String; /// Concatenate a vector of strings, placing a given separator between each. - fn connect(&self, sep: &str) -> StrBuf; + fn connect(&self, sep: &str) -> String; } impl<'a, S: Str> StrVector for &'a [S] { - fn concat(&self) -> StrBuf { + fn concat(&self) -> String { if self.is_empty() { - return StrBuf::new(); + return String::new(); } // `len` calculation may overflow but push_str but will check boundaries let len = self.iter().map(|s| s.as_slice().len()).sum(); - let mut result = StrBuf::with_capacity(len); + let mut result = String::with_capacity(len); for s in self.iter() { result.push_str(s.as_slice()) @@ -151,9 +151,9 @@ impl<'a, S: Str> StrVector for &'a [S] { result } - fn connect(&self, sep: &str) -> StrBuf { + fn connect(&self, sep: &str) -> String { if self.is_empty() { - return StrBuf::new(); + return String::new(); } // concat is faster @@ -165,7 +165,7 @@ impl<'a, S: Str> StrVector for &'a [S] { // `len` calculation may overflow but push_str but will check boundaries let len = sep.len() * (self.len() - 1) + self.iter().map(|s| s.as_slice().len()).sum(); - let mut result = StrBuf::with_capacity(len); + let mut result = String::with_capacity(len); let mut first = true; for s in self.iter() { @@ -182,12 +182,12 @@ impl<'a, S: Str> StrVector for &'a [S] { impl<'a, S: Str> StrVector for Vec<S> { #[inline] - fn concat(&self) -> StrBuf { + fn concat(&self) -> String { self.as_slice().concat() } #[inline] - fn connect(&self, sep: &str) -> StrBuf { + fn connect(&self, sep: &str) -> String { self.as_slice().connect(sep) } } @@ -303,8 +303,8 @@ impl<'a> Iterator<char> for Decompositions<'a> { /// # Return value /// /// The original string with all occurrences of `from` replaced with `to` -pub fn replace(s: &str, from: &str, to: &str) -> StrBuf { - let mut result = StrBuf::new(); +pub fn replace(s: &str, from: &str, to: &str) -> String { + let mut result = String::new(); let mut last_end = 0; for (start, end) in s.match_indices(from) { result.push_str(unsafe{raw::slice_bytes(s, last_end, start)}); @@ -336,8 +336,8 @@ Section: Misc /// v[4] = 0xD800; /// assert_eq!(str::from_utf16(v), None); /// ``` -pub fn from_utf16(v: &[u16]) -> Option<StrBuf> { - let mut s = StrBuf::with_capacity(v.len() / 2); +pub fn from_utf16(v: &[u16]) -> Option<String> { + let mut s = String::with_capacity(v.len() / 2); for c in utf16_items(v) { match c { ScalarValue(c) => s.push_char(c), @@ -362,7 +362,7 @@ pub fn from_utf16(v: &[u16]) -> Option<StrBuf> { /// assert_eq!(str::from_utf16_lossy(v), /// "𝄞mus\uFFFDic\uFFFD".to_owned()); /// ``` -pub fn from_utf16_lossy(v: &[u16]) -> StrBuf { +pub fn from_utf16_lossy(v: &[u16]) -> String { utf16_items(v).map(|c| c.to_char_lossy()).collect() } @@ -409,7 +409,7 @@ pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> MaybeOwned<'a> { } } - let mut res = StrBuf::with_capacity(total); + let mut res = String::with_capacity(total); if i > 0 { unsafe { @@ -509,14 +509,14 @@ pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> MaybeOwned<'a> { Section: MaybeOwned */ -/// A MaybeOwned is a string that can hold either a StrBuf or a &str. +/// A MaybeOwned is a string that can hold either a String or a &str. /// This can be useful as an optimization when an allocation is sometimes /// needed but not always. pub enum MaybeOwned<'a> { /// A borrowed string Slice(&'a str), /// An owned string - Owned(StrBuf) + Owned(String) } /// SendStr is a specialization of `MaybeOwned` to be sendable @@ -548,7 +548,7 @@ pub trait IntoMaybeOwned<'a> { fn into_maybe_owned(self) -> MaybeOwned<'a>; } -impl<'a> IntoMaybeOwned<'a> for StrBuf { +impl<'a> IntoMaybeOwned<'a> for String { #[inline] fn into_maybe_owned(self) -> MaybeOwned<'a> { Owned(self) @@ -607,7 +607,7 @@ impl<'a> Str for MaybeOwned<'a> { impl<'a> StrAllocating for MaybeOwned<'a> { #[inline] - fn into_owned(self) -> StrBuf { + fn into_owned(self) -> String { match self { Slice(s) => s.to_owned(), Owned(s) => s @@ -661,15 +661,15 @@ pub mod raw { use libc; use mem; use raw::Slice; - use strbuf::StrBuf; + use string::String; use vec::Vec; pub use core::str::raw::{from_utf8, c_str_to_static_slice, slice_bytes}; pub use core::str::raw::{slice_unchecked}; /// Create a Rust string from a *u8 buffer of the given length - pub unsafe fn from_buf_len(buf: *u8, len: uint) -> StrBuf { - let mut result = StrBuf::new(); + pub unsafe fn from_buf_len(buf: *u8, len: uint) -> String { + let mut result = String::new(); result.push_bytes(mem::transmute(Slice { data: buf, len: len, @@ -678,8 +678,8 @@ pub mod raw { } /// Create a Rust string from a null-terminated C string - pub unsafe fn from_c_str(c_string: *libc::c_char) -> StrBuf { - let mut buf = StrBuf::new(); + pub unsafe fn from_c_str(c_string: *libc::c_char) -> String { + let mut buf = String::new(); buf.push_bytes(CString::new(c_string, false).as_bytes_no_nul()); buf } @@ -687,12 +687,12 @@ pub mod raw { /// Converts an owned vector of bytes to a new owned string. This assumes /// that the utf-8-ness of the vector has already been validated #[inline] - pub unsafe fn from_utf8_owned(v: Vec<u8>) -> StrBuf { + pub unsafe fn from_utf8_owned(v: Vec<u8>) -> String { mem::transmute(v) } /// Converts a byte to a string. - pub unsafe fn from_byte(u: u8) -> StrBuf { + pub unsafe fn from_byte(u: u8) -> String { from_utf8_owned(vec![u]) } @@ -721,25 +721,25 @@ Section: Trait implementations /// Any string that can be represented as a slice pub trait StrAllocating: Str { - /// Convert `self` into a `StrBuf`, not making a copy if possible. - fn into_owned(self) -> StrBuf; + /// Convert `self` into a `String`, not making a copy if possible. + fn into_owned(self) -> String; - /// Convert `self` into a `StrBuf`. + /// Convert `self` into a `String`. #[inline] - fn to_strbuf(&self) -> StrBuf { - StrBuf::from_str(self.as_slice()) + fn to_strbuf(&self) -> String { + String::from_str(self.as_slice()) } - /// Convert `self` into a `StrBuf`, not making a copy if possible. + /// Convert `self` into a `String`, not making a copy if possible. #[inline] - fn into_strbuf(self) -> StrBuf { + fn into_strbuf(self) -> String { self.into_owned() } /// Escape each char in `s` with `char::escape_default`. - fn escape_default(&self) -> StrBuf { + fn escape_default(&self) -> String { let me = self.as_slice(); - let mut out = StrBuf::with_capacity(me.len()); + let mut out = String::with_capacity(me.len()); for c in me.chars() { c.escape_default(|c| out.push_char(c)); } @@ -747,9 +747,9 @@ pub trait StrAllocating: Str { } /// Escape each char in `s` with `char::escape_unicode`. - fn escape_unicode(&self) -> StrBuf { + fn escape_unicode(&self) -> String { let me = self.as_slice(); - let mut out = StrBuf::with_capacity(me.len()); + let mut out = String::with_capacity(me.len()); for c in me.chars() { c.escape_unicode(|c| out.push_char(c)); } @@ -780,9 +780,9 @@ pub trait StrAllocating: Str { /// // not found, so no change. /// assert_eq!(s.replace("cookie monster", "little lamb"), s); /// ``` - fn replace(&self, from: &str, to: &str) -> StrBuf { + fn replace(&self, from: &str, to: &str) -> String { let me = self.as_slice(); - let mut result = StrBuf::new(); + let mut result = String::new(); let mut last_end = 0; for (start, end) in me.match_indices(from) { result.push_str(unsafe{raw::slice_bytes(me, last_end, start)}); @@ -793,9 +793,9 @@ pub trait StrAllocating: Str { result } - /// Copy a slice into a new `StrBuf`. + /// Copy a slice into a new `String`. #[inline] - fn to_owned(&self) -> StrBuf { + fn to_owned(&self) -> String { use slice::Vector; unsafe { @@ -816,9 +816,9 @@ pub trait StrAllocating: Str { } /// Given a string, make a new string with repeated copies of it. - fn repeat(&self, nn: uint) -> StrBuf { + fn repeat(&self, nn: uint) -> String { let me = self.as_slice(); - let mut ret = StrBuf::with_capacity(nn * me.len()); + let mut ret = String::with_capacity(nn * me.len()); for _ in range(0, nn) { ret.push_str(me); } @@ -887,7 +887,7 @@ pub trait StrAllocating: Str { impl<'a> StrAllocating for &'a str { #[inline] - fn into_owned(self) -> StrBuf { + fn into_owned(self) -> String { self.to_owned() } } @@ -900,18 +900,18 @@ pub trait OwnedStr { fn into_bytes(self) -> Vec<u8>; /// Pushes the given string onto this string, returning the concatenation of the two strings. - fn append(self, rhs: &str) -> StrBuf; + fn append(self, rhs: &str) -> String; } -impl OwnedStr for StrBuf { +impl OwnedStr for String { #[inline] fn into_bytes(self) -> Vec<u8> { unsafe { mem::transmute(self) } } #[inline] - fn append(self, rhs: &str) -> StrBuf { - let mut new_str = StrBuf::from_owned_str(self); + fn append(self, rhs: &str) -> String { + let mut new_str = String::from_owned_str(self); new_str.push_str(rhs); new_str } @@ -923,7 +923,7 @@ mod tests { use default::Default; use prelude::*; use str::*; - use strbuf::StrBuf; + use string::String; #[test] fn test_eq_slice() { @@ -983,10 +983,10 @@ mod tests { #[test] fn test_collect() { let empty = "".to_owned(); - let s: StrBuf = empty.as_slice().chars().collect(); + let s: String = empty.as_slice().chars().collect(); assert_eq!(empty, s); let data = "ประเทศไทย中".to_owned(); - let s: StrBuf = data.as_slice().chars().collect(); + let s: String = data.as_slice().chars().collect(); assert_eq!(data, s); } @@ -1043,25 +1043,25 @@ mod tests { #[test] fn test_concat() { - fn t(v: &[StrBuf], s: &str) { + fn t(v: &[String], s: &str) { assert_eq!(v.concat(), s.to_str().into_owned()); } t(["you".to_owned(), "know".to_owned(), "I'm".to_owned(), "no".to_owned(), "good".to_owned()], "youknowI'mnogood"); - let v: &[StrBuf] = []; + let v: &[String] = []; t(v, ""); t(["hi".to_owned()], "hi"); } #[test] fn test_connect() { - fn t(v: &[StrBuf], sep: &str, s: &str) { + fn t(v: &[String], sep: &str, s: &str) { assert_eq!(v.connect(sep), s.to_str().into_owned()); } t(["you".to_owned(), "know".to_owned(), "I'm".to_owned(), "no".to_owned(), "good".to_owned()], " ", "you know I'm no good"); - let v: &[StrBuf] = []; + let v: &[String] = []; t(v, " ", ""); t(["hi".to_owned()], " ", "hi"); } @@ -1102,18 +1102,18 @@ mod tests { assert_eq!("ab", unsafe {raw::slice_bytes("abc", 0, 2)}); assert_eq!("bc", unsafe {raw::slice_bytes("abc", 1, 3)}); assert_eq!("", unsafe {raw::slice_bytes("abc", 1, 1)}); - fn a_million_letter_a() -> StrBuf { + fn a_million_letter_a() -> String { let mut i = 0; - let mut rs = StrBuf::new(); + let mut rs = String::new(); while i < 100000 { rs.push_str("aaaaaaaaaa"); i += 1; } rs } - fn half_a_million_letter_a() -> StrBuf { + fn half_a_million_letter_a() -> String { let mut i = 0; - let mut rs = StrBuf::new(); + let mut rs = String::new(); while i < 100000 { rs.push_str("aaaaa"); i += 1; @@ -1219,18 +1219,18 @@ mod tests { assert_eq!("", data.slice(3, 3)); assert_eq!("华", data.slice(30, 33)); - fn a_million_letter_X() -> StrBuf { + fn a_million_letter_X() -> String { let mut i = 0; - let mut rs = StrBuf::new(); + let mut rs = String::new(); while i < 100000 { rs.push_str("华华华华华华华华华华"); i += 1; } rs } - fn half_a_million_letter_X() -> StrBuf { + fn half_a_million_letter_X() -> String { let mut i = 0; - let mut rs = StrBuf::new(); + let mut rs = String::new(); while i < 100000 { rs.push_str("华华华华华"); i += 1; @@ -1532,10 +1532,10 @@ mod tests { #[test] fn vec_str_conversions() { - let s1: StrBuf = "All mimsy were the borogoves".to_strbuf(); + let s1: String = "All mimsy were the borogoves".to_strbuf(); let v: Vec<u8> = Vec::from_slice(s1.as_bytes()); - let s2: StrBuf = from_utf8(v.as_slice()).unwrap().to_strbuf(); + let s2: String = from_utf8(v.as_slice()).unwrap().to_strbuf(); let mut i: uint = 0u; let n1: uint = s1.len(); let n2: uint = v.len(); @@ -1967,30 +1967,30 @@ mod tests { #[test] fn test_nfd_chars() { - assert_eq!("abc".nfd_chars().collect::<StrBuf>(), "abc".to_strbuf()); - assert_eq!("\u1e0b\u01c4".nfd_chars().collect::<StrBuf>(), "d\u0307\u01c4".to_strbuf()); - assert_eq!("\u2026".nfd_chars().collect::<StrBuf>(), "\u2026".to_strbuf()); - assert_eq!("\u2126".nfd_chars().collect::<StrBuf>(), "\u03a9".to_strbuf()); - assert_eq!("\u1e0b\u0323".nfd_chars().collect::<StrBuf>(), "d\u0323\u0307".to_strbuf()); - assert_eq!("\u1e0d\u0307".nfd_chars().collect::<StrBuf>(), "d\u0323\u0307".to_strbuf()); - assert_eq!("a\u0301".nfd_chars().collect::<StrBuf>(), "a\u0301".to_strbuf()); - assert_eq!("\u0301a".nfd_chars().collect::<StrBuf>(), "\u0301a".to_strbuf()); - assert_eq!("\ud4db".nfd_chars().collect::<StrBuf>(), "\u1111\u1171\u11b6".to_strbuf()); - assert_eq!("\uac1c".nfd_chars().collect::<StrBuf>(), "\u1100\u1162".to_strbuf()); + assert_eq!("abc".nfd_chars().collect::<String>(), "abc".to_strbuf()); + assert_eq!("\u1e0b\u01c4".nfd_chars().collect::<String>(), "d\u0307\u01c4".to_strbuf()); + assert_eq!("\u2026".nfd_chars().collect::<String>(), "\u2026".to_strbuf()); + assert_eq!("\u2126".nfd_chars().collect::<String>(), "\u03a9".to_strbuf()); + assert_eq!("\u1e0b\u0323".nfd_chars().collect::<String>(), "d\u0323\u0307".to_strbuf()); + assert_eq!("\u1e0d\u0307".nfd_chars().collect::<String>(), "d\u0323\u0307".to_strbuf()); + assert_eq!("a\u0301".nfd_chars().collect::<String>(), "a\u0301".to_strbuf()); + assert_eq!("\u0301a".nfd_chars().collect::<String>(), "\u0301a".to_strbuf()); + assert_eq!("\ud4db".nfd_chars().collect::<String>(), "\u1111\u1171\u11b6".to_strbuf()); + assert_eq!("\uac1c".nfd_chars().collect::<String>(), "\u1100\u1162".to_strbuf()); } #[test] fn test_nfkd_chars() { - assert_eq!("abc".nfkd_chars().collect::<StrBuf>(), "abc".to_strbuf()); - assert_eq!("\u1e0b\u01c4".nfkd_chars().collect::<StrBuf>(), "d\u0307DZ\u030c".to_strbuf()); - assert_eq!("\u2026".nfkd_chars().collect::<StrBuf>(), "...".to_strbuf()); - assert_eq!("\u2126".nfkd_chars().collect::<StrBuf>(), "\u03a9".to_strbuf()); - assert_eq!("\u1e0b\u0323".nfkd_chars().collect::<StrBuf>(), "d\u0323\u0307".to_strbuf()); - assert_eq!("\u1e0d\u0307".nfkd_chars().collect::<StrBuf>(), "d\u0323\u0307".to_strbuf()); - assert_eq!("a\u0301".nfkd_chars().collect::<StrBuf>(), "a\u0301".to_strbuf()); - assert_eq!("\u0301a".nfkd_chars().collect::<StrBuf>(), "\u0301a".to_strbuf()); - assert_eq!("\ud4db".nfkd_chars().collect::<StrBuf>(), "\u1111\u1171\u11b6".to_strbuf()); - assert_eq!("\uac1c".nfkd_chars().collect::<StrBuf>(), "\u1100\u1162".to_strbuf()); + assert_eq!("abc".nfkd_chars().collect::<String>(), "abc".to_strbuf()); + assert_eq!("\u1e0b\u01c4".nfkd_chars().collect::<String>(), "d\u0307DZ\u030c".to_strbuf()); + assert_eq!("\u2026".nfkd_chars().collect::<String>(), "...".to_strbuf()); + assert_eq!("\u2126".nfkd_chars().collect::<String>(), "\u03a9".to_strbuf()); + assert_eq!("\u1e0b\u0323".nfkd_chars().collect::<String>(), "d\u0323\u0307".to_strbuf()); + assert_eq!("\u1e0d\u0307".nfkd_chars().collect::<String>(), "d\u0323\u0307".to_strbuf()); + assert_eq!("a\u0301".nfkd_chars().collect::<String>(), "a\u0301".to_strbuf()); + assert_eq!("\u0301a".nfkd_chars().collect::<String>(), "\u0301a".to_strbuf()); + assert_eq!("\ud4db".nfkd_chars().collect::<String>(), "\u1111\u1171\u11b6".to_strbuf()); + assert_eq!("\uac1c".nfkd_chars().collect::<String>(), "\u1100\u1162".to_strbuf()); } #[test] @@ -2035,7 +2035,7 @@ mod tests { } t::<&str>(); - t::<StrBuf>(); + t::<String>(); } #[test] @@ -2110,7 +2110,7 @@ mod tests { #[test] fn test_from_str() { - let owned: Option<StrBuf> = from_str("string"); + let owned: Option<String> = from_str("string"); assert_eq!(owned, Some("string".to_strbuf())); } diff --git a/src/libstd/strbuf.rs b/src/libstd/string.rs index dd462ff5ab5..f4d1e2a1858 100644 --- a/src/libstd/strbuf.rs +++ b/src/libstd/string.rs @@ -31,46 +31,46 @@ use vec::Vec; /// A growable string stored as a UTF-8 encoded buffer. #[deriving(Clone, Eq, Ord, TotalEq, TotalOrd)] -pub struct StrBuf { +pub struct String { vec: Vec<u8>, } -impl StrBuf { +impl String { /// Creates a new string buffer initialized with the empty string. #[inline] - pub fn new() -> StrBuf { - StrBuf { + pub fn new() -> String { + String { vec: Vec::new(), } } /// Creates a new string buffer with the given capacity. #[inline] - pub fn with_capacity(capacity: uint) -> StrBuf { - StrBuf { + pub fn with_capacity(capacity: uint) -> String { + String { vec: Vec::with_capacity(capacity), } } /// Creates a new string buffer from length, capacity, and a pointer. #[inline] - pub unsafe fn from_raw_parts(length: uint, capacity: uint, ptr: *mut u8) -> StrBuf { - StrBuf { + pub unsafe fn from_raw_parts(length: uint, capacity: uint, ptr: *mut u8) -> String { + String { vec: Vec::from_raw_parts(length, capacity, ptr), } } /// Creates a new string buffer from the given string. #[inline] - pub fn from_str(string: &str) -> StrBuf { - StrBuf { + pub fn from_str(string: &str) -> String { + String { vec: Vec::from_slice(string.as_bytes()) } } /// Creates a new string buffer from the given owned string, taking care not to copy it. #[inline] - pub fn from_owned_str(string: StrBuf) -> StrBuf { + pub fn from_owned_str(string: String) -> String { string } @@ -80,9 +80,9 @@ impl StrBuf { /// Returns `Err` with the original vector if the vector contains invalid /// UTF-8. #[inline] - pub fn from_utf8(vec: Vec<u8>) -> Result<StrBuf, Vec<u8>> { + pub fn from_utf8(vec: Vec<u8>) -> Result<String, Vec<u8>> { if str::is_utf8(vec.as_slice()) { - Ok(StrBuf { vec: vec }) + Ok(String { vec: vec }) } else { Err(vec) } @@ -97,19 +97,19 @@ impl StrBuf { /// Pushes the given string onto this buffer; then, returns `self` so that it can be used /// again. #[inline] - pub fn append(mut self, second: &str) -> StrBuf { + pub fn append(mut self, second: &str) -> String { self.push_str(second); self } /// Creates a string buffer by repeating a character `length` times. #[inline] - pub fn from_char(length: uint, ch: char) -> StrBuf { + pub fn from_char(length: uint, ch: char) -> String { if length == 0 { - return StrBuf::new() + return String::new() } - let mut buf = StrBuf::new(); + let mut buf = String::new(); buf.push_char(ch); let size = buf.len() * length; buf.reserve(size); @@ -281,29 +281,29 @@ impl StrBuf { } } -impl Container for StrBuf { +impl Container for String { #[inline] fn len(&self) -> uint { self.vec.len() } } -impl Mutable for StrBuf { +impl Mutable for String { #[inline] fn clear(&mut self) { self.vec.clear() } } -impl FromIterator<char> for StrBuf { - fn from_iter<I:Iterator<char>>(iterator: I) -> StrBuf { - let mut buf = StrBuf::new(); +impl FromIterator<char> for String { + fn from_iter<I:Iterator<char>>(iterator: I) -> String { + let mut buf = String::new(); buf.extend(iterator); buf } } -impl Extendable<char> for StrBuf { +impl Extendable<char> for String { fn extend<I:Iterator<char>>(&mut self, mut iterator: I) { for ch in iterator { self.push_char(ch) @@ -311,7 +311,7 @@ impl Extendable<char> for StrBuf { } } -impl Str for StrBuf { +impl Str for String { #[inline] fn as_slice<'a>(&'a self) -> &'a str { unsafe { @@ -320,47 +320,47 @@ impl Str for StrBuf { } } -impl StrAllocating for StrBuf { +impl StrAllocating for String { #[inline] - fn into_owned(self) -> StrBuf { + fn into_owned(self) -> String { self } #[inline] - fn into_strbuf(self) -> StrBuf { + fn into_strbuf(self) -> String { self } } -impl Default for StrBuf { - fn default() -> StrBuf { - StrBuf::new() +impl Default for String { + fn default() -> String { + String::new() } } -impl fmt::Show for StrBuf { +impl fmt::Show for String { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.as_slice().fmt(f) } } -impl<H:Writer> ::hash::Hash<H> for StrBuf { +impl<H:Writer> ::hash::Hash<H> for String { #[inline] fn hash(&self, hasher: &mut H) { self.as_slice().hash(hasher) } } -impl<'a, S: Str> Equiv<S> for StrBuf { +impl<'a, S: Str> Equiv<S> for String { #[inline] fn equiv(&self, other: &S) -> bool { self.as_slice() == other.as_slice() } } -impl FromStr for StrBuf { +impl FromStr for String { #[inline] - fn from_str(s: &str) -> Option<StrBuf> { + fn from_str(s: &str) -> Option<String> { Some(s.to_strbuf()) } } @@ -371,12 +371,12 @@ mod tests { use container::{Container, Mutable}; use self::test::Bencher; use str::{Str, StrSlice}; - use super::StrBuf; + use super::String; #[bench] fn bench_with_capacity(b: &mut Bencher) { b.iter(|| { - StrBuf::with_capacity(100) + String::with_capacity(100) }); } @@ -384,14 +384,14 @@ mod tests { fn bench_push_str(b: &mut Bencher) { let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb"; b.iter(|| { - let mut r = StrBuf::new(); + let mut r = String::new(); r.push_str(s); }); } #[test] fn test_push_bytes() { - let mut s = StrBuf::from_str("ABC"); + let mut s = String::from_str("ABC"); unsafe { s.push_bytes([ 'D' as u8 ]); } @@ -400,7 +400,7 @@ mod tests { #[test] fn test_push_str() { - let mut s = StrBuf::new(); + let mut s = String::new(); s.push_str(""); assert_eq!(s.as_slice().slice_from(0), ""); s.push_str("abc"); @@ -411,7 +411,7 @@ mod tests { #[test] fn test_push_char() { - let mut data = StrBuf::from_str("ประเทศไทย中"); + let mut data = String::from_str("ประเทศไทย中"); data.push_char('华'); data.push_char('b'); // 1 byte data.push_char('¢'); // 2 byte @@ -422,7 +422,7 @@ mod tests { #[test] fn test_pop_char() { - let mut data = StrBuf::from_str("ประเทศไทย中华b¢€𤭢"); + let mut data = String::from_str("ประเทศไทย中华b¢€𤭢"); assert_eq!(data.pop_char().unwrap(), '𤭢'); // 4 bytes assert_eq!(data.pop_char().unwrap(), '€'); // 3 bytes assert_eq!(data.pop_char().unwrap(), '¢'); // 2 bytes @@ -433,7 +433,7 @@ mod tests { #[test] fn test_shift_char() { - let mut data = StrBuf::from_str("𤭢€¢b华ประเทศไทย中"); + let mut data = String::from_str("𤭢€¢b华ประเทศไทย中"); assert_eq!(data.shift_char().unwrap(), '𤭢'); // 4 bytes assert_eq!(data.shift_char().unwrap(), '€'); // 3 bytes assert_eq!(data.shift_char().unwrap(), '¢'); // 2 bytes @@ -444,7 +444,7 @@ mod tests { #[test] fn test_str_truncate() { - let mut s = StrBuf::from_str("12345"); + let mut s = String::from_str("12345"); s.truncate(5); assert_eq!(s.as_slice(), "12345"); s.truncate(3); @@ -452,7 +452,7 @@ mod tests { s.truncate(0); assert_eq!(s.as_slice(), ""); - let mut s = StrBuf::from_str("12345"); + let mut s = String::from_str("12345"); let p = s.as_slice().as_ptr(); s.truncate(3); s.push_str("6"); @@ -463,20 +463,20 @@ mod tests { #[test] #[should_fail] fn test_str_truncate_invalid_len() { - let mut s = StrBuf::from_str("12345"); + let mut s = String::from_str("12345"); s.truncate(6); } #[test] #[should_fail] fn test_str_truncate_split_codepoint() { - let mut s = StrBuf::from_str("\u00FC"); // ü + let mut s = String::from_str("\u00FC"); // ü s.truncate(1); } #[test] fn test_str_clear() { - let mut s = StrBuf::from_str("12345"); + let mut s = String::from_str("12345"); s.clear(); assert_eq!(s.len(), 0); assert_eq!(s.as_slice(), ""); diff --git a/src/libstd/task.rs b/src/libstd/task.rs index 314f659550d..078883aac13 100644 --- a/src/libstd/task.rs +++ b/src/libstd/task.rs @@ -51,7 +51,7 @@ use str::{Str, SendStr, IntoMaybeOwned}; #[cfg(test)] use owned::AnyOwnExt; #[cfg(test)] use result; #[cfg(test)] use str::StrAllocating; -#[cfg(test)] use strbuf::StrBuf; +#[cfg(test)] use string::String; /// Indicates the manner in which a task exited. /// @@ -500,7 +500,7 @@ fn test_try_fail_message_owned_str() { fail!("owned string".to_strbuf()); }) { Err(e) => { - type T = StrBuf; + type T = String; assert!(e.is::<T>()); assert_eq!(*e.move::<T>().unwrap(), "owned string".to_strbuf()); } diff --git a/src/libstd/to_str.rs b/src/libstd/to_str.rs index fbc4227e726..afc71ab88d9 100644 --- a/src/libstd/to_str.rs +++ b/src/libstd/to_str.rs @@ -15,22 +15,22 @@ The `ToStr` trait for converting to strings */ use fmt; -use strbuf::StrBuf; +use string::String; /// A generic trait for converting a value to a string pub trait ToStr { /// Converts the value of `self` to an owned string - fn to_str(&self) -> StrBuf; + fn to_str(&self) -> String; } /// Trait for converting a type to a string, consuming it in the process. pub trait IntoStr { /// Consume and convert to a string. - fn into_str(self) -> StrBuf; + fn into_str(self) -> String; } impl<T: fmt::Show> ToStr for T { - fn to_str(&self) -> StrBuf { + fn to_str(&self) -> String { format_strbuf!("{}", *self) } } diff --git a/src/libstd/unstable/dynamic_lib.rs b/src/libstd/unstable/dynamic_lib.rs index 8e85283ee55..6302ab39dd8 100644 --- a/src/libstd/unstable/dynamic_lib.rs +++ b/src/libstd/unstable/dynamic_lib.rs @@ -27,7 +27,7 @@ use path::{Path,GenericPath}; use result::*; use slice::{Vector,ImmutableVector}; use str; -use strbuf::StrBuf; +use string::String; use vec::Vec; pub struct DynamicLibrary { handle: *u8} @@ -57,7 +57,7 @@ impl DynamicLibrary { /// Lazily open a dynamic library. When passed None it gives a /// handle to the calling process pub fn open<T: ToCStr>(filename: Option<T>) - -> Result<DynamicLibrary, StrBuf> { + -> Result<DynamicLibrary, String> { unsafe { let mut filename = filename; let maybe_library = dl::check_for_errors_in(|| { @@ -131,7 +131,7 @@ impl DynamicLibrary { } /// Access the value at the symbol of the dynamic library - pub unsafe fn symbol<T>(&self, symbol: &str) -> Result<T, StrBuf> { + pub unsafe fn symbol<T>(&self, symbol: &str) -> Result<T, String> { // This function should have a lifetime constraint of 'a on // T but that feature is still unimplemented @@ -211,7 +211,7 @@ pub mod dl { use ptr; use result::*; use str::StrAllocating; - use strbuf::StrBuf; + use string::String; pub unsafe fn open_external<T: ToCStr>(filename: T) -> *u8 { filename.with_c_str(|raw_name| { @@ -223,7 +223,7 @@ pub mod dl { dlopen(ptr::null(), Lazy as libc::c_int) as *u8 } - pub fn check_for_errors_in<T>(f: || -> T) -> Result<T, StrBuf> { + pub fn check_for_errors_in<T>(f: || -> T) -> Result<T, String> { use unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT}; static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT; unsafe { @@ -276,7 +276,7 @@ pub mod dl { use os; use ptr; use result::{Ok, Err, Result}; - use strbuf::StrBuf; + use string::String; use str; use c_str::ToCStr; @@ -295,7 +295,7 @@ pub mod dl { handle as *u8 } - pub fn check_for_errors_in<T>(f: || -> T) -> Result<T, StrBuf> { + pub fn check_for_errors_in<T>(f: || -> T) -> Result<T, String> { unsafe { SetLastError(0); diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 1776b6fbe6e..3c1e83e1b54 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -671,7 +671,7 @@ impl<T> Vec<T> { /// ```rust /// let v = vec!("a".to_owned(), "b".to_owned()); /// for s in v.move_iter() { - /// // s has type StrBuf, not &StrBuf + /// // s has type String, not &String /// println!("{}", s); /// } /// ``` @@ -1850,7 +1850,7 @@ mod tests { assert_eq!(b.as_slice(), &[]); let a = vec!["one".to_strbuf(), "two".to_strbuf()]; - let b: ~[StrBuf] = FromVec::from_vec(a); + let b: ~[String] = FromVec::from_vec(a); assert_eq!(b.as_slice(), &["one".to_strbuf(), "two".to_strbuf()]); struct Foo { |
