Skip to content

Commit 6df514b

Browse files
committed
Use byte literals in libcore
1 parent 3fb78e2 commit 6df514b

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

src/libcore/fmt/float.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,11 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>(
198198
// Decide what sign to put in front
199199
match sign {
200200
SignNeg | SignAll if neg => {
201-
buf[end] = '-' as u8;
201+
buf[end] = b'-';
202202
end += 1;
203203
}
204204
SignAll => {
205-
buf[end] = '+' as u8;
205+
buf[end] = b'+';
206206
end += 1;
207207
}
208208
_ => ()
@@ -218,7 +218,7 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>(
218218
// Now emit the fractional part, if any
219219
deccum = num.fract();
220220
if deccum != _0 || (limit_digits && exact && digit_count > 0) {
221-
buf[end] = '.' as u8;
221+
buf[end] = b'.';
222222
end += 1;
223223
let mut dig = 0u;
224224

@@ -269,8 +269,8 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>(
269269
// If reached left end of number, have to
270270
// insert additional digit:
271271
if i < 0
272-
|| buf[i as uint] == '-' as u8
273-
|| buf[i as uint] == '+' as u8 {
272+
|| buf[i as uint] == b'-'
273+
|| buf[i as uint] == b'+' {
274274
for j in range(i as uint + 1, end).rev() {
275275
buf[j + 1] = buf[j];
276276
}
@@ -280,7 +280,7 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>(
280280
}
281281

282282
// Skip the '.'
283-
if buf[i as uint] == '.' as u8 { i -= 1; continue; }
283+
if buf[i as uint] == b'.' { i -= 1; continue; }
284284

285285
// Either increment the digit,
286286
// 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>(
306306
let mut i = buf_max_i;
307307

308308
// discover trailing zeros of fractional part
309-
while i > start_fractional_digits && buf[i] == '0' as u8 {
309+
while i > start_fractional_digits && buf[i] == b'0' {
310310
i -= 1;
311311
}
312312

313313
// Only attempt to truncate digits if buf has fractional digits
314314
if i >= start_fractional_digits {
315315
// If buf ends with '.', cut that too.
316-
if buf[i] == '.' as u8 { i -= 1 }
316+
if buf[i] == b'.' { i -= 1 }
317317

318318
// only resize buf if we actually remove digits
319319
if i < buf_max_i {
@@ -323,7 +323,7 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>(
323323
} // If exact and trailing '.', just cut that
324324
else {
325325
let max_i = end - 1;
326-
if buf[max_i] == '.' as u8 {
326+
if buf[max_i] == b'.' {
327327
end = max_i;
328328
}
329329
}

src/libcore/fmt/num.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,13 @@ macro_rules! radix {
104104
}
105105
}
106106

107-
radix!(Binary, 2, "0b", x @ 0 .. 2 => '0' as u8 + x)
108-
radix!(Octal, 8, "0o", x @ 0 .. 7 => '0' as u8 + x)
109-
radix!(Decimal, 10, "", x @ 0 .. 9 => '0' as u8 + x)
110-
radix!(LowerHex, 16, "0x", x @ 0 .. 9 => '0' as u8 + x,
111-
x @ 10 ..15 => 'a' as u8 + (x - 10))
112-
radix!(UpperHex, 16, "0x", x @ 0 .. 9 => '0' as u8 + x,
113-
x @ 10 ..15 => 'A' as u8 + (x - 10))
107+
radix!(Binary, 2, "0b", x @ 0 .. 2 => b'0' + x)
108+
radix!(Octal, 8, "0o", x @ 0 .. 7 => b'0' + x)
109+
radix!(Decimal, 10, "", x @ 0 .. 9 => b'0' + x)
110+
radix!(LowerHex, 16, "0x", x @ 0 .. 9 => b'0' + x,
111+
x @ 10 ..15 => b'a' + (x - 10))
112+
radix!(UpperHex, 16, "0x", x @ 0 .. 9 => b'0' + x,
113+
x @ 10 ..15 => b'A' + (x - 10))
114114

115115
/// A radix with in the range of `2..36`.
116116
#[deriving(Clone, PartialEq)]
@@ -129,8 +129,8 @@ impl GenericRadix for Radix {
129129
fn base(&self) -> u8 { self.base }
130130
fn digit(&self, x: u8) -> u8 {
131131
match x {
132-
x @ 0 ..9 => '0' as u8 + x,
133-
x if x < self.base() => 'a' as u8 + (x - 10),
132+
x @ 0 ..9 => b'0' + x,
133+
x if x < self.base() => b'a' + (x - 10),
134134
x => fail!("number not in the range 0..{}: {}", self.base() - 1, x),
135135
}
136136
}

src/libcore/str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1755,7 +1755,7 @@ impl<'a> StrSlice<'a> for &'a str {
17551755
fn lines_any(&self) -> AnyLines<'a> {
17561756
self.lines().map(|line| {
17571757
let l = line.len();
1758-
if l > 0 && line.as_bytes()[l - 1] == '\r' as u8 { line.slice(0, l - 1) }
1758+
if l > 0 && line.as_bytes()[l - 1] == b'\r' { line.slice(0, l - 1) }
17591759
else { line }
17601760
})
17611761
}

0 commit comments

Comments
 (0)