Skip to content

Commit

Permalink
Audit integer types in libunicode, libcore/(char, str) and libstd/ascii
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Feb 14, 2015
1 parent df54632 commit 09f53fd
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 140 deletions.
10 changes: 5 additions & 5 deletions src/etc/unicode.py
Expand Up @@ -366,7 +366,7 @@ def emit_conversions_module(f, lowerupper, upperlower):
}
}
fn bsearch_case_table(c: char, table: &'static [(char, char)]) -> Option<uint> {
fn bsearch_case_table(c: char, table: &'static [(char, char)]) -> Option<usize> {
match table.binary_search(|&(key, _)| {
if c == key { Equal }
else if key < c { Less }
Expand Down Expand Up @@ -449,13 +449,13 @@ def emit_charwidth_module(f, width_table):
""")

f.write("""
pub fn width(c: char, is_cjk: bool) -> Option<uint> {
match c as uint {
pub fn width(c: char, is_cjk: bool) -> Option<usize> {
match c as usize {
_c @ 0 => Some(0), // null is zero width
cu if cu < 0x20 => None, // control sequences have no width
cu if cu < 0x7F => Some(1), // ASCII
cu if cu < 0xA0 => None, // more control sequences
_ => Some(bsearch_range_value_table(c, is_cjk, charwidth_table) as uint)
_ => Some(bsearch_range_value_table(c, is_cjk, charwidth_table) as usize)
}
}
Expand Down Expand Up @@ -610,7 +610,7 @@ def optimize_width_table(wtable):
rf.write("""
/// The version of [Unicode](http://www.unicode.org/)
/// that the `UnicodeChar` and `UnicodeStrPrelude` traits are based on.
pub const UNICODE_VERSION: (uint, uint, uint) = (%s, %s, %s);
pub const UNICODE_VERSION: (u64, u64, u64) = (%s, %s, %s);
""" % unicode_version)
(canon_decomp, compat_decomp, gencats, combines,
lowerupper, upperlower) = load_unicode_data("UnicodeData.txt")
Expand Down
42 changes: 21 additions & 21 deletions src/libcore/char.rs
Expand Up @@ -119,16 +119,16 @@ pub fn from_u32(i: u32) -> Option<char> {
/// ```
#[inline]
#[unstable(feature = "core", reason = "pending integer conventions")]
pub fn from_digit(num: uint, radix: uint) -> Option<char> {
pub fn from_digit(num: u32, radix: u32) -> Option<char> {
if radix > 36 {
panic!("from_digit: radix is too high (maximum 36)");
}
if num < radix {
unsafe {
if num < 10 {
Some(transmute(('0' as uint + num) as u32))
Some(transmute('0' as u32 + num))
} else {
Some(transmute(('a' as uint + num - 10) as u32))
Some(transmute('a' as u32 + num - 10))
}
}
} else {
Expand Down Expand Up @@ -164,7 +164,7 @@ pub trait CharExt {
/// ```
#[unstable(feature = "core",
reason = "pending integer conventions")]
fn is_digit(self, radix: uint) -> bool;
fn is_digit(self, radix: u32) -> bool;

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

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

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

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

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

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

#[unstable(feature = "core",
reason = "pending integer conventions")]
fn to_digit(self, radix: uint) -> Option<uint> {
fn to_digit(self, radix: u32) -> Option<u32> {
if radix > 36 {
panic!("to_digit: radix is too high (maximum 36)");
}
let val = match self {
'0' ... '9' => self as uint - ('0' as uint),
'a' ... 'z' => self as uint + 10 - ('a' as uint),
'A' ... 'Z' => self as uint + 10 - ('A' as uint),
'0' ... '9' => self as u32 - '0' as u32,
'a' ... 'z' => self as u32 - 'a' as u32 + 10,
'A' ... 'Z' => self as u32 - 'A' as u32 + 10,
_ => return None,
};
if val < radix { Some(val) }
Expand Down Expand Up @@ -396,7 +396,7 @@ impl CharExt for char {

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

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

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

#[inline]
#[unstable(feature = "core",
reason = "pending decision about Iterator/Writer/Reader")]
fn encode_utf16(self, dst: &mut [u16]) -> Option<uint> {
fn encode_utf16(self, dst: &mut [u16]) -> Option<usize> {
encode_utf16_raw(self as u32, dst)
}
}
Expand All @@ -435,7 +435,7 @@ impl CharExt for char {
/// and a `None` will be returned.
#[inline]
#[unstable(feature = "core")]
pub fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> Option<uint> {
pub fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> Option<usize> {
// Marked #[inline] to allow llvm optimizing it away
if code < MAX_ONE_B && dst.len() >= 1 {
dst[0] = code as u8;
Expand Down Expand Up @@ -467,7 +467,7 @@ pub fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> Option<uint> {
/// and a `None` will be returned.
#[inline]
#[unstable(feature = "core")]
pub fn encode_utf16_raw(mut ch: u32, dst: &mut [u16]) -> Option<uint> {
pub fn encode_utf16_raw(mut ch: u32, dst: &mut [u16]) -> Option<usize> {
// Marked #[inline] to allow llvm optimizing it away
if (ch & 0xFFFF_u32) == ch && dst.len() >= 1 {
// The BMP falls through (assuming non-surrogate, as it should)
Expand Down Expand Up @@ -499,7 +499,7 @@ enum EscapeUnicodeState {
Backslash,
Type,
LeftBrace,
Value(uint),
Value(usize),
RightBrace,
Done,
}
Expand Down

0 comments on commit 09f53fd

Please sign in to comment.