Skip to content

Commit

Permalink
Remove core::num::strconv
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanzab committed Nov 16, 2014
1 parent 29bc9c6 commit 68bd495
Show file tree
Hide file tree
Showing 6 changed files with 282 additions and 411 deletions.
64 changes: 3 additions & 61 deletions src/libcore/num/f32.rs
Expand Up @@ -16,10 +16,8 @@

use intrinsics;
use mem;
use num::{FPNormal, FPCategory, FPZero, FPSubnormal, FPInfinite, FPNaN};
use num::{Float, FromStrRadix};
use num::strconv;
use str::FromStr;
use num::{Float, FPNormal, FPCategory, FPZero, FPSubnormal, FPInfinite, FPNaN};
use num::from_str_radix;
use option::Option;

pub const RADIX: uint = 2u;
Expand Down Expand Up @@ -431,61 +429,5 @@ impl Float for f32 {
#[allow(missing_docs)]
#[deprecated="Use `FromStrRadix::from_str_radix(src, 16)`"]
pub fn from_str_hex(src: &str) -> Option<f32> {
strconv::from_str_radix_float(src, 16)
}

impl FromStr for f32 {
/// Convert a string in base 10 to a float.
/// Accepts an optional decimal exponent.
///
/// This function accepts strings such as
///
/// * '3.14'
/// * '+3.14', equivalent to '3.14'
/// * '-3.14'
/// * '2.5E10', or equivalently, '2.5e10'
/// * '2.5E-10'
/// * '.' (understood as 0)
/// * '5.'
/// * '.5', or, equivalently, '0.5'
/// * '+inf', 'inf', '-inf', 'NaN'
///
/// Leading and trailing whitespace represent an error.
///
/// # Arguments
///
/// * src - A string
///
/// # Return value
///
/// `None` if the string did not represent a valid number. Otherwise,
/// `Some(n)` where `n` is the floating-point number represented by `src`.
#[inline]
fn from_str(src: &str) -> Option<f32> {
strconv::from_str_radix_float(src, 10u)
}
}

impl FromStrRadix for f32 {
/// Convert a string in a given base to a float.
///
/// Due to possible conflicts, this function does **not** accept
/// the special values `inf`, `-inf`, `+inf` and `NaN`, **nor**
/// does it recognize exponents of any kind.
///
/// Leading and trailing whitespace represent an error.
///
/// # Arguments
///
/// * src - A string
/// * radix - The base to use. Must lie in the range [2 .. 36]
///
/// # Return value
///
/// `None` if the string did not represent a valid number. Otherwise,
/// `Some(n)` where `n` is the floating-point number represented by `src`.
#[inline]
fn from_str_radix(src: &str, radix: uint) -> Option<f32> {
strconv::from_str_radix_float(src, radix)
}
from_str_radix(src, 16)
}
59 changes: 3 additions & 56 deletions src/libcore/num/f64.rs
Expand Up @@ -16,10 +16,8 @@

use intrinsics;
use mem;
use num::{FPNormal, FPCategory, FPZero, FPSubnormal, FPInfinite, FPNaN};
use num::{Float, FromStrRadix};
use num::strconv;
use str::FromStr;
use num::{Float, FPNormal, FPCategory, FPZero, FPSubnormal, FPInfinite, FPNaN};
use num::from_str_radix;
use option::Option;

// FIXME(#5527): These constants should be deprecated once associated
Expand Down Expand Up @@ -437,56 +435,5 @@ impl Float for f64 {
#[allow(missing_docs)]
#[deprecated="Use `FromStrRadix::from_str_radix(src, 16)`"]
pub fn from_str_hex(src: &str) -> Option<f64> {
strconv::from_str_radix_float(src, 16)
}

impl FromStr for f64 {
/// Convert a string in base 10 to a float.
/// Accepts an optional decimal exponent.
///
/// This function accepts strings such as:
///
/// * '3.14'
/// * '-3.14'
/// * '2.5E10', or equivalently, '2.5e10'
/// * '2.5E-10'
/// * '.' (understood as 0)
/// * '5.'
/// * '.5', or, equivalently, '0.5'
/// * inf', '-inf', 'NaN'
///
/// Leading and trailing whitespace represent an error.
///
/// # Arguments
///
/// * src - A string
///
/// # Return value
///
/// `none` if the string did not represent a valid number. Otherwise,
/// `Some(n)` where `n` is the floating-point number represented by `src`.
#[inline]
fn from_str(src: &str) -> Option<f64> {
strconv::from_str_radix_float(src, 10u)
}
}

impl FromStrRadix for f64 {
/// Convert a string in a given base to a float.
///
/// Leading and trailing whitespace represent an error.
///
/// # Arguments
///
/// * src - A string
/// * radix - The base to use. Must lie in the range [2 .. 36]
///
/// # Return value
///
/// `None` if the string did not represent a valid number. Otherwise,
/// `Some(n)` where `n` is the floating-point number represented by `src`.
#[inline]
fn from_str_radix(src: &str, radix: uint) -> Option<f64> {
strconv::from_str_radix_float(src, radix)
}
from_str_radix(src, 16)
}
16 changes: 0 additions & 16 deletions src/libcore/num/int_macros.rs
Expand Up @@ -32,20 +32,4 @@ pub const MIN: $T = (-1 as $T) << (BITS - 1);
#[unstable]
pub const MAX: $T = !MIN;

#[experimental = "might need to return Result"]
impl ::str::FromStr for $T {
#[inline]
fn from_str(s: &str) -> ::option::Option<$T> {
::num::strconv::from_str_radix_int(s, 10)
}
}

#[experimental = "might need to return Result"]
impl ::num::FromStrRadix for $T {
#[inline]
fn from_str_radix(s: &str, radix: uint) -> ::option::Option<$T> {
::num::strconv::from_str_radix_int(s, radix)
}
}

))

0 comments on commit 68bd495

Please sign in to comment.