Skip to content

Commit ddbd4e0

Browse files
committed
Fix various deprecation warnings from char changes
1 parent f635aa8 commit ddbd4e0

File tree

6 files changed

+74
-64
lines changed

6 files changed

+74
-64
lines changed

src/libcore/char.rs

Lines changed: 66 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,7 @@ pub fn from_u32(i: u32) -> Option<char> {
100100
#[inline]
101101
#[deprecated = "use the Char::is_digit method"]
102102
pub fn is_digit_radix(c: char, radix: uint) -> bool {
103-
match to_digit(c, radix) {
104-
Some(_) => true,
105-
None => false,
106-
}
103+
c.is_digit(radix)
107104
}
108105

109106
///
@@ -123,17 +120,7 @@ pub fn is_digit_radix(c: char, radix: uint) -> bool {
123120
#[inline]
124121
#[deprecated = "use the Char::to_digit method"]
125122
pub fn to_digit(c: char, radix: uint) -> Option<uint> {
126-
if radix > 36 {
127-
panic!("to_digit: radix is too high (maximum 36)");
128-
}
129-
let val = match c {
130-
'0' ... '9' => c as uint - ('0' as uint),
131-
'a' ... 'z' => c as uint + 10u - ('a' as uint),
132-
'A' ... 'Z' => c as uint + 10u - ('A' as uint),
133-
_ => return None,
134-
};
135-
if val < radix { Some(val) }
136-
else { None }
123+
c.to_digit(radix)
137124
}
138125

139126
///
@@ -178,23 +165,7 @@ pub fn from_digit(num: uint, radix: uint) -> Option<char> {
178165
///
179166
#[deprecated = "use the Char::escape_unicode method"]
180167
pub fn escape_unicode(c: char, f: |char|) {
181-
// avoid calling str::to_str_radix because we don't really need to allocate
182-
// here.
183-
f('\\');
184-
let pad = match () {
185-
_ if c <= '\x7f' => { f('x'); 2 }
186-
_ if c <= '\uffff' => { f('u'); 4 }
187-
_ => { f('U'); 8 }
188-
};
189-
for offset in range_step::<i32>(4 * (pad - 1), -1, -4) {
190-
let offset = offset as uint;
191-
unsafe {
192-
match ((c as i32) >> offset) & 0xf {
193-
i @ 0 ... 9 => { f(transmute('0' as i32 + i)); }
194-
i => { f(transmute('a' as i32 + (i - 10))); }
195-
}
196-
}
197-
}
168+
c.escape_unicode(f)
198169
}
199170

200171
///
@@ -211,29 +182,14 @@ pub fn escape_unicode(c: char, f: |char|) {
211182
///
212183
#[deprecated = "use the Char::escape_default method"]
213184
pub fn escape_default(c: char, f: |char|) {
214-
match c {
215-
'\t' => { f('\\'); f('t'); }
216-
'\r' => { f('\\'); f('r'); }
217-
'\n' => { f('\\'); f('n'); }
218-
'\\' => { f('\\'); f('\\'); }
219-
'\'' => { f('\\'); f('\''); }
220-
'"' => { f('\\'); f('"'); }
221-
'\x20' ... '\x7e' => { f(c); }
222-
_ => c.escape_unicode(f),
223-
}
185+
c.escape_default(f)
224186
}
225187

226188
/// Returns the amount of bytes this `char` would need if encoded in UTF-8
227189
#[inline]
228190
#[deprecated = "use the Char::len_utf8 method"]
229191
pub fn len_utf8_bytes(c: char) -> uint {
230-
let code = c as u32;
231-
match () {
232-
_ if code < MAX_ONE_B => 1u,
233-
_ if code < MAX_TWO_B => 2u,
234-
_ if code < MAX_THREE_B => 3u,
235-
_ => 4u,
236-
}
192+
c.len_utf8()
237193
}
238194

239195
/// Basic `char` manipulations.
@@ -362,13 +318,30 @@ pub trait Char {
362318
#[experimental = "trait is experimental"]
363319
impl Char for char {
364320
#[deprecated = "use is_digit"]
365-
fn is_digit_radix(&self, radix: uint) -> bool { is_digit_radix(*self, radix) }
321+
fn is_digit_radix(&self, radix: uint) -> bool { self.is_digit(radix) }
366322

367323
#[unstable = "pending trait organization"]
368-
fn is_digit(&self, radix: uint) -> bool { is_digit_radix(*self, radix) }
324+
fn is_digit(&self, radix: uint) -> bool {
325+
match self.to_digit(radix) {
326+
Some(_) => true,
327+
None => false,
328+
}
329+
}
369330

370331
#[unstable = "pending trait organization"]
371-
fn to_digit(&self, radix: uint) -> Option<uint> { to_digit(*self, radix) }
332+
fn to_digit(&self, radix: uint) -> Option<uint> {
333+
if radix > 36 {
334+
panic!("to_digit: radix is too high (maximum 36)");
335+
}
336+
let val = match *self {
337+
'0' ... '9' => *self as uint - ('0' as uint),
338+
'a' ... 'z' => *self as uint + 10u - ('a' as uint),
339+
'A' ... 'Z' => *self as uint + 10u - ('A' as uint),
340+
_ => return None,
341+
};
342+
if val < radix { Some(val) }
343+
else { None }
344+
}
372345

373346
#[deprecated = "use the char::from_digit free function"]
374347
fn from_digit(num: uint, radix: uint) -> Option<char> { from_digit(num, radix) }
@@ -378,18 +351,55 @@ impl Char for char {
378351
fn from_u32(i: u32) -> Option<char> { from_u32(i) }
379352

380353
#[unstable = "pending error conventions, trait organization"]
381-
fn escape_unicode(&self, f: |char|) { escape_unicode(*self, f) }
354+
fn escape_unicode(&self, f: |char|) {
355+
// avoid calling str::to_str_radix because we don't really need to allocate
356+
// here.
357+
f('\\');
358+
let pad = match () {
359+
_ if *self <= '\xff' => { f('x'); 2 }
360+
_ if *self <= '\uffff' => { f('u'); 4 }
361+
_ => { f('U'); 8 }
362+
};
363+
for offset in range_step::<i32>(4 * (pad - 1), -1, -4) {
364+
let offset = offset as uint;
365+
unsafe {
366+
match ((*self as i32) >> offset) & 0xf {
367+
i @ 0 ... 9 => { f(transmute('0' as i32 + i)); }
368+
i => { f(transmute('a' as i32 + (i - 10))); }
369+
}
370+
}
371+
}
372+
}
382373

383374
#[unstable = "pending error conventions, trait organization"]
384-
fn escape_default(&self, f: |char|) { escape_default(*self, f) }
375+
fn escape_default(&self, f: |char|) {
376+
match *self {
377+
'\t' => { f('\\'); f('t'); }
378+
'\r' => { f('\\'); f('r'); }
379+
'\n' => { f('\\'); f('n'); }
380+
'\\' => { f('\\'); f('\\'); }
381+
'\'' => { f('\\'); f('\''); }
382+
'"' => { f('\\'); f('"'); }
383+
'\x20' ... '\x7e' => { f(*self); }
384+
_ => self.escape_unicode(f),
385+
}
386+
}
385387

386388
#[inline]
387389
#[deprecated = "use len_utf8"]
388-
fn len_utf8_bytes(&self) -> uint { len_utf8_bytes(*self) }
390+
fn len_utf8_bytes(&self) -> uint { self.len_utf8() }
389391

390392
#[inline]
391393
#[unstable = "pending trait organization"]
392-
fn len_utf8(&self) -> uint { len_utf8_bytes(*self) }
394+
fn len_utf8(&self) -> uint {
395+
let code = *self as u32;
396+
match () {
397+
_ if code < MAX_ONE_B => 1u,
398+
_ if code < MAX_TWO_B => 2u,
399+
_ if code < MAX_THREE_B => 3u,
400+
_ => 4u,
401+
}
402+
}
393403

394404
#[inline]
395405
#[unstable = "pending trait organization"]

src/libcore/fmt/float.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#![allow(missing_docs)]
1212

1313
use char;
14+
use char::Char;
1415
use fmt;
1516
use iter::{range, DoubleEndedIterator};
1617
use num::{Float, FPNaN, FPInfinite, ToPrimitive, Primitive};
@@ -218,7 +219,7 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>(
218219
// round the remaining ones.
219220
if limit_digits && dig == digit_count {
220221
let ascii2value = |chr: u8| {
221-
char::to_digit(chr as char, radix).unwrap()
222+
(chr as char).to_digit(radix).unwrap()
222223
};
223224
let value2ascii = |val: uint| {
224225
char::from_digit(val, radix).unwrap() as u8

src/libfmt_macros/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ impl<'a> Parser<'a> {
406406
loop {
407407
match self.cur.clone().next() {
408408
Some((_, c)) => {
409-
match char::to_digit(c, 10) {
409+
match c.to_digit(10) {
410410
Some(i) => {
411411
cur = cur * 10 + i;
412412
found = true;

src/libstd/num/strconv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ pub fn float_to_str_bytes_common<T: Float>(
321321
// round the remaining ones.
322322
if limit_digits && dig == digit_count {
323323
let ascii2value = |chr: u8| {
324-
char::to_digit(chr as char, radix).unwrap()
324+
(chr as char).to_digit(radix).unwrap()
325325
};
326326
let value2ascii = |val: uint| {
327327
char::from_digit(val, radix).unwrap() as u8

src/libsyntax/parse/lexer/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ impl<'a> StringReader<'a> {
626626
loop {
627627
let c = self.curr;
628628
if c == Some('_') { debug!("skipping a _"); self.bump(); continue; }
629-
match c.and_then(|cc| char::to_digit(cc, radix)) {
629+
match c.and_then(|cc| cc.to_digit(radix)) {
630630
Some(_) => {
631631
debug!("{} in scan_digits", c);
632632
len += 1;
@@ -668,7 +668,7 @@ impl<'a> StringReader<'a> {
668668
return token::LitInteger(self.name_from(start_bpos));
669669
}
670670
}
671-
} else if c.is_digit_radix(10) {
671+
} else if c.is_digit(10) {
672672
num_digits = self.scan_digits(10) + 1;
673673
} else {
674674
num_digits = 0;
@@ -689,7 +689,7 @@ impl<'a> StringReader<'a> {
689689
// might have stuff after the ., and if it does, it needs to start
690690
// with a number
691691
self.bump();
692-
if self.curr.unwrap_or('\0').is_digit_radix(10) {
692+
if self.curr.unwrap_or('\0').is_digit(10) {
693693
self.scan_digits(10);
694694
self.scan_float_exponent();
695695
self.scan_float_suffix();

src/libterm/terminfo/parm.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
//! Parameterized string expansion
1212
13-
use std::char;
1413
use std::mem::replace;
1514

1615
#[deriving(PartialEq)]
@@ -293,7 +292,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
293292
},
294293
PushParam => {
295294
// params are 1-indexed
296-
stack.push(mparams[match char::to_digit(cur, 10) {
295+
stack.push(mparams[match cur.to_digit(10) {
297296
Some(d) => d - 1,
298297
None => return Err("bad param number".to_string())
299298
}].clone());

0 commit comments

Comments
 (0)