Skip to content

Commit 09f53fd

Browse files
committed
Audit integer types in libunicode, libcore/(char, str) and libstd/ascii
1 parent df54632 commit 09f53fd

File tree

8 files changed

+141
-140
lines changed

8 files changed

+141
-140
lines changed

src/etc/unicode.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ def emit_conversions_module(f, lowerupper, upperlower):
366366
}
367367
}
368368
369-
fn bsearch_case_table(c: char, table: &'static [(char, char)]) -> Option<uint> {
369+
fn bsearch_case_table(c: char, table: &'static [(char, char)]) -> Option<usize> {
370370
match table.binary_search(|&(key, _)| {
371371
if c == key { Equal }
372372
else if key < c { Less }
@@ -449,13 +449,13 @@ def emit_charwidth_module(f, width_table):
449449
""")
450450

451451
f.write("""
452-
pub fn width(c: char, is_cjk: bool) -> Option<uint> {
453-
match c as uint {
452+
pub fn width(c: char, is_cjk: bool) -> Option<usize> {
453+
match c as usize {
454454
_c @ 0 => Some(0), // null is zero width
455455
cu if cu < 0x20 => None, // control sequences have no width
456456
cu if cu < 0x7F => Some(1), // ASCII
457457
cu if cu < 0xA0 => None, // more control sequences
458-
_ => Some(bsearch_range_value_table(c, is_cjk, charwidth_table) as uint)
458+
_ => Some(bsearch_range_value_table(c, is_cjk, charwidth_table) as usize)
459459
}
460460
}
461461
@@ -610,7 +610,7 @@ def optimize_width_table(wtable):
610610
rf.write("""
611611
/// The version of [Unicode](http://www.unicode.org/)
612612
/// that the `UnicodeChar` and `UnicodeStrPrelude` traits are based on.
613-
pub const UNICODE_VERSION: (uint, uint, uint) = (%s, %s, %s);
613+
pub const UNICODE_VERSION: (u64, u64, u64) = (%s, %s, %s);
614614
""" % unicode_version)
615615
(canon_decomp, compat_decomp, gencats, combines,
616616
lowerupper, upperlower) = load_unicode_data("UnicodeData.txt")

src/libcore/char.rs

+21-21
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,16 @@ pub fn from_u32(i: u32) -> Option<char> {
119119
/// ```
120120
#[inline]
121121
#[unstable(feature = "core", reason = "pending integer conventions")]
122-
pub fn from_digit(num: uint, radix: uint) -> Option<char> {
122+
pub fn from_digit(num: u32, radix: u32) -> Option<char> {
123123
if radix > 36 {
124124
panic!("from_digit: radix is too high (maximum 36)");
125125
}
126126
if num < radix {
127127
unsafe {
128128
if num < 10 {
129-
Some(transmute(('0' as uint + num) as u32))
129+
Some(transmute('0' as u32 + num))
130130
} else {
131-
Some(transmute(('a' as uint + num - 10) as u32))
131+
Some(transmute('a' as u32 + num - 10))
132132
}
133133
}
134134
} else {
@@ -164,7 +164,7 @@ pub trait CharExt {
164164
/// ```
165165
#[unstable(feature = "core",
166166
reason = "pending integer conventions")]
167-
fn is_digit(self, radix: uint) -> bool;
167+
fn is_digit(self, radix: u32) -> bool;
168168

169169
/// Converts a character to the corresponding digit.
170170
///
@@ -189,7 +189,7 @@ pub trait CharExt {
189189
/// ```
190190
#[unstable(feature = "core",
191191
reason = "pending integer conventions")]
192-
fn to_digit(self, radix: uint) -> Option<uint>;
192+
fn to_digit(self, radix: u32) -> Option<u32>;
193193

194194
/// Returns an iterator that yields the hexadecimal Unicode escape of a character, as `char`s.
195195
///
@@ -275,7 +275,7 @@ pub trait CharExt {
275275
/// assert_eq!(n, 2);
276276
/// ```
277277
#[stable(feature = "rust1", since = "1.0.0")]
278-
fn len_utf8(self) -> uint;
278+
fn len_utf8(self) -> usize;
279279

280280
/// Returns the number of bytes this character would need if encoded in UTF-16.
281281
///
@@ -287,7 +287,7 @@ pub trait CharExt {
287287
/// assert_eq!(n, 1);
288288
/// ```
289289
#[stable(feature = "rust1", since = "1.0.0")]
290-
fn len_utf16(self) -> uint;
290+
fn len_utf16(self) -> usize;
291291

292292
/// Encodes this character as UTF-8 into the provided byte buffer, and then returns the number
293293
/// of bytes written.
@@ -317,7 +317,7 @@ pub trait CharExt {
317317
/// assert_eq!(result, None);
318318
/// ```
319319
#[stable(feature = "rust1", since = "1.0.0")]
320-
fn encode_utf8(self, dst: &mut [u8]) -> Option<uint>;
320+
fn encode_utf8(self, dst: &mut [u8]) -> Option<usize>;
321321

322322
/// Encodes this character as UTF-16 into the provided `u16` buffer, and then returns the
323323
/// number of `u16`s written.
@@ -347,27 +347,27 @@ pub trait CharExt {
347347
/// assert_eq!(result, None);
348348
/// ```
349349
#[stable(feature = "rust1", since = "1.0.0")]
350-
fn encode_utf16(self, dst: &mut [u16]) -> Option<uint>;
350+
fn encode_utf16(self, dst: &mut [u16]) -> Option<usize>;
351351
}
352352

353353
#[stable(feature = "rust1", since = "1.0.0")]
354354
impl CharExt for char {
355355
#[unstable(feature = "core",
356356
reason = "pending integer conventions")]
357-
fn is_digit(self, radix: uint) -> bool {
357+
fn is_digit(self, radix: u32) -> bool {
358358
self.to_digit(radix).is_some()
359359
}
360360

361361
#[unstable(feature = "core",
362362
reason = "pending integer conventions")]
363-
fn to_digit(self, radix: uint) -> Option<uint> {
363+
fn to_digit(self, radix: u32) -> Option<u32> {
364364
if radix > 36 {
365365
panic!("to_digit: radix is too high (maximum 36)");
366366
}
367367
let val = match self {
368-
'0' ... '9' => self as uint - ('0' as uint),
369-
'a' ... 'z' => self as uint + 10 - ('a' as uint),
370-
'A' ... 'Z' => self as uint + 10 - ('A' as uint),
368+
'0' ... '9' => self as u32 - '0' as u32,
369+
'a' ... 'z' => self as u32 - 'a' as u32 + 10,
370+
'A' ... 'Z' => self as u32 - 'A' as u32 + 10,
371371
_ => return None,
372372
};
373373
if val < radix { Some(val) }
@@ -396,7 +396,7 @@ impl CharExt for char {
396396

397397
#[inline]
398398
#[stable(feature = "rust1", since = "1.0.0")]
399-
fn len_utf8(self) -> uint {
399+
fn len_utf8(self) -> usize {
400400
let code = self as u32;
401401
match () {
402402
_ if code < MAX_ONE_B => 1,
@@ -408,22 +408,22 @@ impl CharExt for char {
408408

409409
#[inline]
410410
#[stable(feature = "rust1", since = "1.0.0")]
411-
fn len_utf16(self) -> uint {
411+
fn len_utf16(self) -> usize {
412412
let ch = self as u32;
413413
if (ch & 0xFFFF_u32) == ch { 1 } else { 2 }
414414
}
415415

416416
#[inline]
417417
#[unstable(feature = "core",
418418
reason = "pending decision about Iterator/Writer/Reader")]
419-
fn encode_utf8(self, dst: &mut [u8]) -> Option<uint> {
419+
fn encode_utf8(self, dst: &mut [u8]) -> Option<usize> {
420420
encode_utf8_raw(self as u32, dst)
421421
}
422422

423423
#[inline]
424424
#[unstable(feature = "core",
425425
reason = "pending decision about Iterator/Writer/Reader")]
426-
fn encode_utf16(self, dst: &mut [u16]) -> Option<uint> {
426+
fn encode_utf16(self, dst: &mut [u16]) -> Option<usize> {
427427
encode_utf16_raw(self as u32, dst)
428428
}
429429
}
@@ -435,7 +435,7 @@ impl CharExt for char {
435435
/// and a `None` will be returned.
436436
#[inline]
437437
#[unstable(feature = "core")]
438-
pub fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> Option<uint> {
438+
pub fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> Option<usize> {
439439
// Marked #[inline] to allow llvm optimizing it away
440440
if code < MAX_ONE_B && dst.len() >= 1 {
441441
dst[0] = code as u8;
@@ -467,7 +467,7 @@ pub fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> Option<uint> {
467467
/// and a `None` will be returned.
468468
#[inline]
469469
#[unstable(feature = "core")]
470-
pub fn encode_utf16_raw(mut ch: u32, dst: &mut [u16]) -> Option<uint> {
470+
pub fn encode_utf16_raw(mut ch: u32, dst: &mut [u16]) -> Option<usize> {
471471
// Marked #[inline] to allow llvm optimizing it away
472472
if (ch & 0xFFFF_u32) == ch && dst.len() >= 1 {
473473
// The BMP falls through (assuming non-surrogate, as it should)
@@ -499,7 +499,7 @@ enum EscapeUnicodeState {
499499
Backslash,
500500
Type,
501501
LeftBrace,
502-
Value(uint),
502+
Value(usize),
503503
RightBrace,
504504
Done,
505505
}

0 commit comments

Comments
 (0)