Use byte literals in libcore
This commit is contained in:
parent
3fb78e29f4
commit
6df514b061
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
@ -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 }
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user