diff options
| author | nham <hamann.nick@gmail.com> | 2014-08-06 02:30:17 -0400 |
|---|---|---|
| committer | nham <hamann.nick@gmail.com> | 2014-08-06 02:30:17 -0400 |
| commit | 6df514b06123c7361730ac8ece999b2265b2f4ef (patch) | |
| tree | 1e32fac3e288cc3afd519bc528a38e161b9f6270 /src | |
| parent | 3fb78e29f4ae9b3e5bb19bf5a740375e90b01ceb (diff) | |
| download | rust-6df514b06123c7361730ac8ece999b2265b2f4ef.tar.gz rust-6df514b06123c7361730ac8ece999b2265b2f4ef.zip | |
Use byte literals in libcore
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/fmt/float.rs | 18 | ||||
| -rw-r--r-- | src/libcore/fmt/num.rs | 18 | ||||
| -rw-r--r-- | src/libcore/str.rs | 2 |
3 files changed, 19 insertions, 19 deletions
diff --git a/src/libcore/fmt/float.rs b/src/libcore/fmt/float.rs index 386fc28119a..88702e59e30 100644 --- a/src/libcore/fmt/float.rs +++ b/src/libcore/fmt/float.rs @@ -198,11 +198,11 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>( // Decide what sign to put in front match sign { SignNeg | SignAll if neg => { - buf[end] = '-' as u8; + buf[end] = b'-'; end += 1; } SignAll => { - buf[end] = '+' as u8; + buf[end] = b'+'; end += 1; } _ => () @@ -218,7 +218,7 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>( // Now emit the fractional part, if any deccum = num.fract(); if deccum != _0 || (limit_digits && exact && digit_count > 0) { - buf[end] = '.' as u8; + buf[end] = b'.'; end += 1; let mut dig = 0u; @@ -269,8 +269,8 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>( // If reached left end of number, have to // insert additional digit: if i < 0 - || buf[i as uint] == '-' as u8 - || buf[i as uint] == '+' as u8 { + || buf[i as uint] == b'-' + || buf[i as uint] == b'+' { for j in range(i as uint + 1, end).rev() { buf[j + 1] = buf[j]; } @@ -280,7 +280,7 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>( } // Skip the '.' - if buf[i as uint] == '.' as u8 { i -= 1; continue; } + if buf[i as uint] == b'.' { i -= 1; continue; } // Either increment the digit, // or set to 0 if max and carry the 1. @@ -306,14 +306,14 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>( let mut i = buf_max_i; // discover trailing zeros of fractional part - while i > start_fractional_digits && buf[i] == '0' as u8 { + while i > start_fractional_digits && buf[i] == b'0' { i -= 1; } // Only attempt to truncate digits if buf has fractional digits if i >= start_fractional_digits { // If buf ends with '.', cut that too. - if buf[i] == '.' as u8 { i -= 1 } + if buf[i] == b'.' { i -= 1 } // only resize buf if we actually remove digits if i < buf_max_i { @@ -323,7 +323,7 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>( } // If exact and trailing '.', just cut that else { let max_i = end - 1; - if buf[max_i] == '.' as u8 { + if buf[max_i] == b'.' { end = max_i; } } diff --git a/src/libcore/fmt/num.rs b/src/libcore/fmt/num.rs index 2ed32b3388f..99920dc7881 100644 --- a/src/libcore/fmt/num.rs +++ b/src/libcore/fmt/num.rs @@ -104,13 +104,13 @@ macro_rules! radix { } } -radix!(Binary, 2, "0b", x @ 0 .. 2 => '0' as u8 + x) -radix!(Octal, 8, "0o", x @ 0 .. 7 => '0' as u8 + x) -radix!(Decimal, 10, "", x @ 0 .. 9 => '0' as u8 + x) -radix!(LowerHex, 16, "0x", x @ 0 .. 9 => '0' as u8 + x, - x @ 10 ..15 => 'a' as u8 + (x - 10)) -radix!(UpperHex, 16, "0x", x @ 0 .. 9 => '0' as u8 + x, - x @ 10 ..15 => 'A' as u8 + (x - 10)) +radix!(Binary, 2, "0b", x @ 0 .. 2 => b'0' + x) +radix!(Octal, 8, "0o", x @ 0 .. 7 => b'0' + x) +radix!(Decimal, 10, "", x @ 0 .. 9 => b'0' + x) +radix!(LowerHex, 16, "0x", x @ 0 .. 9 => b'0' + x, + x @ 10 ..15 => b'a' + (x - 10)) +radix!(UpperHex, 16, "0x", x @ 0 .. 9 => b'0' + x, + x @ 10 ..15 => b'A' + (x - 10)) /// A radix with in the range of `2..36`. #[deriving(Clone, PartialEq)] @@ -129,8 +129,8 @@ impl GenericRadix for Radix { fn base(&self) -> u8 { self.base } fn digit(&self, x: u8) -> u8 { match x { - x @ 0 ..9 => '0' as u8 + x, - x if x < self.base() => 'a' as u8 + (x - 10), + x @ 0 ..9 => b'0' + x, + x if x < self.base() => b'a' + (x - 10), x => fail!("number not in the range 0..{}: {}", self.base() - 1, x), } } diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 2ba51eb98fc..5eb46368790 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -1755,7 +1755,7 @@ impl<'a> StrSlice<'a> for &'a str { fn lines_any(&self) -> AnyLines<'a> { self.lines().map(|line| { let l = line.len(); - if l > 0 && line.as_bytes()[l - 1] == '\r' as u8 { line.slice(0, l - 1) } + if l > 0 && line.as_bytes()[l - 1] == b'\r' { line.slice(0, l - 1) } else { line } }) } |
