diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2014-05-16 10:45:16 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2014-05-22 14:42:01 -0700 |
| commit | 36195eb91f15975fed7555a3aa52807ecd5698a1 (patch) | |
| tree | d0e99310be4a24e76b8d6b13f05ec79c1f89b6ba /src/libstd/num | |
| parent | e402e75f4eb79af09b9451f0f232f994b3e2c998 (diff) | |
| download | rust-36195eb91f15975fed7555a3aa52807ecd5698a1.tar.gz rust-36195eb91f15975fed7555a3aa52807ecd5698a1.zip | |
libstd: Remove `~str` from all `libstd` modules except `fmt` and `str`.
Diffstat (limited to 'src/libstd/num')
| -rw-r--r-- | src/libstd/num/f32.rs | 17 | ||||
| -rw-r--r-- | src/libstd/num/f64.rs | 17 | ||||
| -rw-r--r-- | src/libstd/num/i16.rs | 1 | ||||
| -rw-r--r-- | src/libstd/num/i32.rs | 1 | ||||
| -rw-r--r-- | src/libstd/num/i64.rs | 1 | ||||
| -rw-r--r-- | src/libstd/num/i8.rs | 1 | ||||
| -rw-r--r-- | src/libstd/num/int.rs | 1 | ||||
| -rw-r--r-- | src/libstd/num/int_macros.rs | 30 | ||||
| -rw-r--r-- | src/libstd/num/mod.rs | 5 | ||||
| -rw-r--r-- | src/libstd/num/strconv.rs | 8 | ||||
| -rw-r--r-- | src/libstd/num/u16.rs | 1 | ||||
| -rw-r--r-- | src/libstd/num/u32.rs | 1 | ||||
| -rw-r--r-- | src/libstd/num/u64.rs | 1 | ||||
| -rw-r--r-- | src/libstd/num/u8.rs | 1 | ||||
| -rw-r--r-- | src/libstd/num/uint.rs | 1 | ||||
| -rw-r--r-- | src/libstd/num/uint_macros.rs | 34 |
16 files changed, 67 insertions, 54 deletions
diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs index e9ea0df2a7b..66d93c230a5 100644 --- a/src/libstd/num/f32.rs +++ b/src/libstd/num/f32.rs @@ -20,6 +20,7 @@ use intrinsics; use libc::c_int; use num::strconv; use num; +use strbuf::StrBuf; 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}; @@ -242,7 +243,7 @@ impl FloatMath for f32 { /// /// * num - The float value #[inline] -pub fn to_str(num: f32) -> ~str { +pub fn to_str(num: f32) -> StrBuf { let (r, _) = strconv::float_to_str_common( num, 10u, true, strconv::SignNeg, strconv::DigAll, strconv::ExpNone, false); r @@ -254,7 +255,7 @@ pub fn to_str(num: f32) -> ~str { /// /// * num - The float value #[inline] -pub fn to_str_hex(num: f32) -> ~str { +pub fn to_str_hex(num: f32) -> StrBuf { let (r, _) = strconv::float_to_str_common( num, 16u, true, strconv::SignNeg, strconv::DigAll, strconv::ExpNone, false); r @@ -268,7 +269,7 @@ pub fn to_str_hex(num: f32) -> ~str { /// * num - The float value /// * radix - The base to use #[inline] -pub fn to_str_radix_special(num: f32, rdx: uint) -> (~str, bool) { +pub fn to_str_radix_special(num: f32, rdx: uint) -> (StrBuf, bool) { strconv::float_to_str_common(num, rdx, true, strconv::SignNeg, strconv::DigAll, strconv::ExpNone, false) } @@ -281,7 +282,7 @@ pub fn to_str_radix_special(num: f32, rdx: uint) -> (~str, bool) { /// * num - The float value /// * digits - The number of significant digits #[inline] -pub fn to_str_exact(num: f32, dig: uint) -> ~str { +pub fn to_str_exact(num: f32, dig: uint) -> StrBuf { let (r, _) = strconv::float_to_str_common( num, 10u, true, strconv::SignNeg, strconv::DigExact(dig), strconv::ExpNone, false); r @@ -295,7 +296,7 @@ pub fn to_str_exact(num: f32, dig: uint) -> ~str { /// * num - The float value /// * digits - The number of significant digits #[inline] -pub fn to_str_digits(num: f32, dig: uint) -> ~str { +pub fn to_str_digits(num: f32, dig: uint) -> StrBuf { let (r, _) = strconv::float_to_str_common( num, 10u, true, strconv::SignNeg, strconv::DigMax(dig), strconv::ExpNone, false); r @@ -310,7 +311,7 @@ pub fn to_str_digits(num: f32, dig: uint) -> ~str { /// * 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) -> ~str { +pub fn to_str_exp_exact(num: f32, dig: uint, upper: bool) -> StrBuf { let (r, _) = strconv::float_to_str_common( num, 10u, true, strconv::SignNeg, strconv::DigExact(dig), strconv::ExpDec, upper); r @@ -325,7 +326,7 @@ pub fn to_str_exp_exact(num: f32, dig: uint, upper: bool) -> ~str { /// * 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) -> ~str { +pub fn to_str_exp_digits(num: f32, dig: uint, upper: bool) -> StrBuf { let (r, _) = strconv::float_to_str_common( num, 10u, true, strconv::SignNeg, strconv::DigMax(dig), strconv::ExpDec, upper); r @@ -345,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) -> ~str { + fn to_str_radix(&self, rdx: uint) -> StrBuf { 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 869a275b1d4..be4e4dc0d66 100644 --- a/src/libstd/num/f64.rs +++ b/src/libstd/num/f64.rs @@ -19,6 +19,7 @@ use intrinsics; use libc::c_int; use num::strconv; use num; +use strbuf::StrBuf; 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}; @@ -250,7 +251,7 @@ impl FloatMath for f64 { /// /// * num - The float value #[inline] -pub fn to_str(num: f64) -> ~str { +pub fn to_str(num: f64) -> StrBuf { let (r, _) = strconv::float_to_str_common( num, 10u, true, strconv::SignNeg, strconv::DigAll, strconv::ExpNone, false); r @@ -262,7 +263,7 @@ pub fn to_str(num: f64) -> ~str { /// /// * num - The float value #[inline] -pub fn to_str_hex(num: f64) -> ~str { +pub fn to_str_hex(num: f64) -> StrBuf { let (r, _) = strconv::float_to_str_common( num, 16u, true, strconv::SignNeg, strconv::DigAll, strconv::ExpNone, false); r @@ -276,7 +277,7 @@ pub fn to_str_hex(num: f64) -> ~str { /// * num - The float value /// * radix - The base to use #[inline] -pub fn to_str_radix_special(num: f64, rdx: uint) -> (~str, bool) { +pub fn to_str_radix_special(num: f64, rdx: uint) -> (StrBuf, bool) { strconv::float_to_str_common(num, rdx, true, strconv::SignNeg, strconv::DigAll, strconv::ExpNone, false) } @@ -289,7 +290,7 @@ pub fn to_str_radix_special(num: f64, rdx: uint) -> (~str, bool) { /// * num - The float value /// * digits - The number of significant digits #[inline] -pub fn to_str_exact(num: f64, dig: uint) -> ~str { +pub fn to_str_exact(num: f64, dig: uint) -> StrBuf { let (r, _) = strconv::float_to_str_common( num, 10u, true, strconv::SignNeg, strconv::DigExact(dig), strconv::ExpNone, false); r @@ -303,7 +304,7 @@ pub fn to_str_exact(num: f64, dig: uint) -> ~str { /// * num - The float value /// * digits - The number of significant digits #[inline] -pub fn to_str_digits(num: f64, dig: uint) -> ~str { +pub fn to_str_digits(num: f64, dig: uint) -> StrBuf { let (r, _) = strconv::float_to_str_common( num, 10u, true, strconv::SignNeg, strconv::DigMax(dig), strconv::ExpNone, false); r @@ -318,7 +319,7 @@ pub fn to_str_digits(num: f64, dig: uint) -> ~str { /// * 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) -> ~str { +pub fn to_str_exp_exact(num: f64, dig: uint, upper: bool) -> StrBuf { let (r, _) = strconv::float_to_str_common( num, 10u, true, strconv::SignNeg, strconv::DigExact(dig), strconv::ExpDec, upper); r @@ -333,7 +334,7 @@ pub fn to_str_exp_exact(num: f64, dig: uint, upper: bool) -> ~str { /// * 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) -> ~str { +pub fn to_str_exp_digits(num: f64, dig: uint, upper: bool) -> StrBuf { let (r, _) = strconv::float_to_str_common( num, 10u, true, strconv::SignNeg, strconv::DigMax(dig), strconv::ExpDec, upper); r @@ -353,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) -> ~str { + fn to_str_radix(&self, rdx: uint) -> StrBuf { 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 396037d0dba..7d08c181e9e 100644 --- a/src/libstd/num/i16.rs +++ b/src/libstd/num/i16.rs @@ -15,6 +15,7 @@ use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; use slice::ImmutableVector; +use strbuf::StrBuf; pub use core::i16::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/i32.rs b/src/libstd/num/i32.rs index 5640e82d077..2504d3f5766 100644 --- a/src/libstd/num/i32.rs +++ b/src/libstd/num/i32.rs @@ -15,6 +15,7 @@ use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; use slice::ImmutableVector; +use strbuf::StrBuf; pub use core::i32::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/i64.rs b/src/libstd/num/i64.rs index 40245691e34..7fc6a091dfc 100644 --- a/src/libstd/num/i64.rs +++ b/src/libstd/num/i64.rs @@ -15,6 +15,7 @@ use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; use slice::ImmutableVector; +use strbuf::StrBuf; pub use core::i64::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/i8.rs b/src/libstd/num/i8.rs index 7ddddd893e2..a39a6ced077 100644 --- a/src/libstd/num/i8.rs +++ b/src/libstd/num/i8.rs @@ -15,6 +15,7 @@ use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; use slice::ImmutableVector; +use strbuf::StrBuf; pub use core::i8::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/int.rs b/src/libstd/num/int.rs index dc4d80601b7..2a23a35be6d 100644 --- a/src/libstd/num/int.rs +++ b/src/libstd/num/int.rs @@ -15,6 +15,7 @@ use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; use slice::ImmutableVector; +use strbuf::StrBuf; 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 ddff42f68db..31a0edfbc38 100644 --- a/src/libstd/num/int_macros.rs +++ b/src/libstd/num/int_macros.rs @@ -77,8 +77,8 @@ 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) -> ~str { - format!("{}", ::fmt::radix(*self, radix as u8)) + fn to_str_radix(&self, radix: uint) -> StrBuf { + format_strbuf!("{}", ::fmt::radix(*self, radix as u8)) } } @@ -136,39 +136,39 @@ mod tests { #[test] fn test_to_str() { - assert_eq!((0 as $T).to_str_radix(10u), "0".to_owned()); - assert_eq!((1 as $T).to_str_radix(10u), "1".to_owned()); - assert_eq!((-1 as $T).to_str_radix(10u), "-1".to_owned()); - assert_eq!((127 as $T).to_str_radix(16u), "7f".to_owned()); - assert_eq!((100 as $T).to_str_radix(10u), "100".to_owned()); + assert_eq!((0 as $T).to_str_radix(10u), "0".to_strbuf()); + assert_eq!((1 as $T).to_str_radix(10u), "1".to_strbuf()); + assert_eq!((-1 as $T).to_str_radix(10u), "-1".to_strbuf()); + assert_eq!((127 as $T).to_str_radix(16u), "7f".to_strbuf()); + assert_eq!((100 as $T).to_str_radix(10u), "100".to_strbuf()); } #[test] fn test_int_to_str_overflow() { let mut i8_val: i8 = 127_i8; - assert_eq!(i8_val.to_str(), "127".to_owned()); + assert_eq!(i8_val.to_str(), "127".to_strbuf()); i8_val += 1 as i8; - assert_eq!(i8_val.to_str(), "-128".to_owned()); + assert_eq!(i8_val.to_str(), "-128".to_strbuf()); let mut i16_val: i16 = 32_767_i16; - assert_eq!(i16_val.to_str(), "32767".to_owned()); + assert_eq!(i16_val.to_str(), "32767".to_strbuf()); i16_val += 1 as i16; - assert_eq!(i16_val.to_str(), "-32768".to_owned()); + assert_eq!(i16_val.to_str(), "-32768".to_strbuf()); let mut i32_val: i32 = 2_147_483_647_i32; - assert_eq!(i32_val.to_str(), "2147483647".to_owned()); + assert_eq!(i32_val.to_str(), "2147483647".to_strbuf()); i32_val += 1 as i32; - assert_eq!(i32_val.to_str(), "-2147483648".to_owned()); + assert_eq!(i32_val.to_str(), "-2147483648".to_strbuf()); let mut i64_val: i64 = 9_223_372_036_854_775_807_i64; - assert_eq!(i64_val.to_str(), "9223372036854775807".to_owned()); + assert_eq!(i64_val.to_str(), "9223372036854775807".to_strbuf()); i64_val += 1 as i64; - assert_eq!(i64_val.to_str(), "-9223372036854775808".to_owned()); + assert_eq!(i64_val.to_str(), "-9223372036854775808".to_strbuf()); } #[test] diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index 40167718236..c1d6bbb492d 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -15,7 +15,8 @@ #![allow(missing_doc)] -use option::{Option}; +use option::Option; +use strbuf::StrBuf; #[cfg(test)] use fmt::Show; @@ -111,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) -> ~str; + fn to_str_radix(&self, radix: uint) -> StrBuf; } /// 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 e58872b8395..795534dc283 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -19,9 +19,9 @@ use num::{Float, FPNaN, FPInfinite, ToPrimitive}; use num; use ops::{Add, Sub, Mul, Div, Rem, Neg}; use option::{None, Option, Some}; -use slice::{CloneableVector, ImmutableVector, MutableVector}; +use slice::{ImmutableVector, MutableVector}; use std::cmp::{Ord, Eq}; -use str::{StrAllocating, StrSlice}; +use str::StrSlice; use strbuf::StrBuf; use vec::Vec; @@ -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 - ) -> (~str, bool) { + ) -> (StrBuf, bool) { let (bytes, special) = float_to_str_bytes_common(num, radix, negative_zero, sign, digits, exp_format, exp_capital); - (StrBuf::from_utf8(bytes).unwrap().into_owned(), special) + (StrBuf::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 65ac46af5aa..6d68af99890 100644 --- a/src/libstd/num/u16.rs +++ b/src/libstd/num/u16.rs @@ -15,6 +15,7 @@ use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; use slice::ImmutableVector; +use strbuf::StrBuf; pub use core::u16::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/u32.rs b/src/libstd/num/u32.rs index d549e4d0d63..130ca2c4855 100644 --- a/src/libstd/num/u32.rs +++ b/src/libstd/num/u32.rs @@ -15,6 +15,7 @@ use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; use slice::ImmutableVector; +use strbuf::StrBuf; pub use core::u32::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/u64.rs b/src/libstd/num/u64.rs index 3773e56f4d1..559fcf6e7d1 100644 --- a/src/libstd/num/u64.rs +++ b/src/libstd/num/u64.rs @@ -15,6 +15,7 @@ use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; use slice::ImmutableVector; +use strbuf::StrBuf; pub use core::u64::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/u8.rs b/src/libstd/num/u8.rs index 372e38d6652..f855c8c4951 100644 --- a/src/libstd/num/u8.rs +++ b/src/libstd/num/u8.rs @@ -15,6 +15,7 @@ use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; use slice::ImmutableVector; +use strbuf::StrBuf; pub use core::u8::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/uint.rs b/src/libstd/num/uint.rs index c419276fa24..f651cf72cca 100644 --- a/src/libstd/num/uint.rs +++ b/src/libstd/num/uint.rs @@ -15,6 +15,7 @@ use num::{ToStrRadix, FromStrRadix}; use num::strconv; use option::Option; use slice::ImmutableVector; +use strbuf::StrBuf; 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 7977c647606..ba329065a6e 100644 --- a/src/libstd/num/uint_macros.rs +++ b/src/libstd/num/uint_macros.rs @@ -78,8 +78,8 @@ 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) -> ~str { - format!("{}", ::fmt::radix(*self, radix as u8)) + fn to_str_radix(&self, radix: uint) -> StrBuf { + format_strbuf!("{}", ::fmt::radix(*self, radix as u8)) } } @@ -94,13 +94,13 @@ mod tests { #[test] pub fn test_to_str() { - assert_eq!((0 as $T).to_str_radix(10u), "0".to_owned()); - assert_eq!((1 as $T).to_str_radix(10u), "1".to_owned()); - assert_eq!((2 as $T).to_str_radix(10u), "2".to_owned()); - assert_eq!((11 as $T).to_str_radix(10u), "11".to_owned()); - assert_eq!((11 as $T).to_str_radix(16u), "b".to_owned()); - assert_eq!((255 as $T).to_str_radix(16u), "ff".to_owned()); - assert_eq!((0xff as $T).to_str_radix(10u), "255".to_owned()); + assert_eq!((0 as $T).to_str_radix(10u), "0".to_strbuf()); + assert_eq!((1 as $T).to_str_radix(10u), "1".to_strbuf()); + assert_eq!((2 as $T).to_str_radix(10u), "2".to_strbuf()); + assert_eq!((11 as $T).to_str_radix(10u), "11".to_strbuf()); + assert_eq!((11 as $T).to_str_radix(16u), "b".to_strbuf()); + assert_eq!((255 as $T).to_str_radix(16u), "ff".to_strbuf()); + assert_eq!((0xff as $T).to_str_radix(10u), "255".to_strbuf()); } #[test] @@ -133,28 +133,28 @@ mod tests { #[test] fn test_uint_to_str_overflow() { let mut u8_val: u8 = 255_u8; - assert_eq!(u8_val.to_str(), "255".to_owned()); + assert_eq!(u8_val.to_str(), "255".to_strbuf()); u8_val += 1 as u8; - assert_eq!(u8_val.to_str(), "0".to_owned()); + assert_eq!(u8_val.to_str(), "0".to_strbuf()); let mut u16_val: u16 = 65_535_u16; - assert_eq!(u16_val.to_str(), "65535".to_owned()); + assert_eq!(u16_val.to_str(), "65535".to_strbuf()); u16_val += 1 as u16; - assert_eq!(u16_val.to_str(), "0".to_owned()); + assert_eq!(u16_val.to_str(), "0".to_strbuf()); let mut u32_val: u32 = 4_294_967_295_u32; - assert_eq!(u32_val.to_str(), "4294967295".to_owned()); + assert_eq!(u32_val.to_str(), "4294967295".to_strbuf()); u32_val += 1 as u32; - assert_eq!(u32_val.to_str(), "0".to_owned()); + assert_eq!(u32_val.to_str(), "0".to_strbuf()); let mut u64_val: u64 = 18_446_744_073_709_551_615_u64; - assert_eq!(u64_val.to_str(), "18446744073709551615".to_owned()); + assert_eq!(u64_val.to_str(), "18446744073709551615".to_strbuf()); u64_val += 1 as u64; - assert_eq!(u64_val.to_str(), "0".to_owned()); + assert_eq!(u64_val.to_str(), "0".to_strbuf()); } #[test] |
