Skip to content

Commit a73030b

Browse files
committed
---
yaml --- r: 160510 b: refs/heads/auto c: 5928f6c h: refs/heads/master v: v3
1 parent 282f29f commit a73030b

File tree

7 files changed

+76
-66
lines changed

7 files changed

+76
-66
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: b577e4c8d8abfccb82269855701e1e8f10dff9ff
13+
refs/heads/auto: 5928f6c8b672b7569bc9349dda94cdde0a8a3117
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/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"]

branches/auto/src/libcore/fmt/float.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub use self::SignificantDigits::*;
1515
pub use self::SignFormat::*;
1616

1717
use char;
18+
use char::Char;
1819
use fmt;
1920
use iter::{range, DoubleEndedIterator};
2021
use num::{Float, FPNaN, FPInfinite, ToPrimitive};
@@ -222,7 +223,7 @@ pub fn float_to_str_bytes_common<T: Float, U>(
222223
// round the remaining ones.
223224
if limit_digits && dig == digit_count {
224225
let ascii2value = |chr: u8| {
225-
char::to_digit(chr as char, radix).unwrap()
226+
(chr as char).to_digit(radix).unwrap()
226227
};
227228
let value2ascii = |val: uint| {
228229
char::from_digit(val, radix).unwrap() as u8

branches/auto/src/libfmt_macros/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ impl<'a> Parser<'a> {
411411
loop {
412412
match self.cur.clone().next() {
413413
Some((_, c)) => {
414-
match char::to_digit(c, 10) {
414+
match c.to_digit(10) {
415415
Some(i) => {
416416
cur = cur * 10 + i;
417417
found = true;

branches/auto/src/libstd/num/strconv.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub use self::SignificantDigits::*;
1717
pub use self::SignFormat::*;
1818

1919
use char;
20+
use char::Char;
2021
use num;
2122
use num::{Int, Float, FPNaN, FPInfinite, ToPrimitive};
2223
use slice::{SlicePrelude, CloneSliceAllocPrelude};
@@ -320,7 +321,7 @@ pub fn float_to_str_bytes_common<T: Float>(
320321
// round the remaining ones.
321322
if limit_digits && dig == digit_count {
322323
let ascii2value = |chr: u8| {
323-
char::to_digit(chr as char, radix).unwrap()
324+
(chr as char).to_digit(radix).unwrap()
324325
};
325326
let value2ascii = |val: uint| {
326327
char::from_digit(val, radix).unwrap() as u8

branches/auto/src/libsyntax/parse/lexer/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ impl<'a> StringReader<'a> {
645645
loop {
646646
let c = self.curr;
647647
if c == Some('_') { debug!("skipping a _"); self.bump(); continue; }
648-
match c.and_then(|cc| char::to_digit(cc, radix)) {
648+
match c.and_then(|cc| cc.to_digit(radix)) {
649649
Some(_) => {
650650
debug!("{} in scan_digits", c);
651651
len += 1;
@@ -677,7 +677,7 @@ impl<'a> StringReader<'a> {
677677
return token::Integer(self.name_from(start_bpos));
678678
}
679679
}
680-
} else if c.is_digit_radix(10) {
680+
} else if c.is_digit(10) {
681681
num_digits = self.scan_digits(10) + 1;
682682
} else {
683683
num_digits = 0;
@@ -696,7 +696,7 @@ impl<'a> StringReader<'a> {
696696
// might have stuff after the ., and if it does, it needs to start
697697
// with a number
698698
self.bump();
699-
if self.curr.unwrap_or('\0').is_digit_radix(10) {
699+
if self.curr.unwrap_or('\0').is_digit(10) {
700700
self.scan_digits(10);
701701
self.scan_float_exponent();
702702
}

branches/auto/src/libterm/terminfo/parm.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ pub use self::Param::*;
1414
use self::States::*;
1515
use self::FormatState::*;
1616
use self::FormatOp::*;
17-
18-
use std::char;
1917
use std::mem::replace;
2018

2119
#[deriving(PartialEq)]
@@ -298,7 +296,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
298296
},
299297
PushParam => {
300298
// params are 1-indexed
301-
stack.push(mparams[match char::to_digit(cur, 10) {
299+
stack.push(mparams[match cur.to_digit(10) {
302300
Some(d) => d - 1,
303301
None => return Err("bad param number".to_string())
304302
}].clone());

0 commit comments

Comments
 (0)