Skip to content

Commit c82e59d

Browse files
committed
std::ascii: Use u8 methods rather than the maps directly.
1 parent 3a6ccdc commit c82e59d

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

src/libstd/ascii.rs

+14-16
Original file line numberDiff line numberDiff line change
@@ -108,22 +108,20 @@ impl AsciiExt<Vec<u8>> for [u8] {
108108

109109
#[inline]
110110
fn to_ascii_uppercase(&self) -> Vec<u8> {
111-
self.iter().map(|&byte| ASCII_UPPER_MAP[byte as uint]).collect()
111+
self.iter().map(|b| b.to_ascii_uppercase()).collect()
112112
}
113113

114114
#[inline]
115115
fn to_ascii_lowercase(&self) -> Vec<u8> {
116-
self.iter().map(|&byte| ASCII_LOWER_MAP[byte as uint]).collect()
116+
self.iter().map(|b| b.to_ascii_lowercase()).collect()
117117
}
118118

119119
#[inline]
120120
fn eq_ignore_ascii_case(&self, other: &[u8]) -> bool {
121121
self.len() == other.len() &&
122-
self.iter().zip(other.iter()).all(
123-
|(byte_self, byte_other)| {
124-
ASCII_LOWER_MAP[*byte_self as uint] ==
125-
ASCII_LOWER_MAP[*byte_other as uint]
126-
})
122+
self.iter().zip(other.iter()).all(|(a, b)| {
123+
a.eq_ignore_ascii_case(b)
124+
})
127125
}
128126
}
129127

@@ -132,15 +130,15 @@ impl OwnedAsciiExt for Vec<u8> {
132130
#[inline]
133131
fn into_ascii_uppercase(mut self) -> Vec<u8> {
134132
for byte in self.iter_mut() {
135-
*byte = ASCII_UPPER_MAP[*byte as uint];
133+
*byte = byte.to_ascii_uppercase();
136134
}
137135
self
138136
}
139137

140138
#[inline]
141139
fn into_ascii_lowercase(mut self) -> Vec<u8> {
142140
for byte in self.iter_mut() {
143-
*byte = ASCII_LOWER_MAP[*byte as uint];
141+
*byte = byte.to_ascii_lowercase();
144142
}
145143
self
146144
}
@@ -155,17 +153,17 @@ impl AsciiExt for u8 {
155153

156154
#[inline]
157155
fn to_ascii_uppercase(&self) -> u8 {
158-
ASCII_UPPER_MAP[*self as uint]
156+
ASCII_UPPERCASE_MAP[*self as uint]
159157
}
160158

161159
#[inline]
162160
fn to_ascii_lowercase(&self) -> u8 {
163-
ASCII_LOWER_MAP[*self as uint]
161+
ASCII_LOWERCASE_MAP[*self as uint]
164162
}
165163

166164
#[inline]
167165
fn eq_ignore_ascii_case(&self, other: &u8) -> bool {
168-
ASCII_LOWER_MAP[*self as uint] == ASCII_LOWER_MAP[*other as uint]
166+
self.to_ascii_lowercase() == other.to_ascii_lowercase()
169167
}
170168
}
171169

@@ -179,7 +177,7 @@ impl AsciiExt for char {
179177
#[inline]
180178
fn to_ascii_uppercase(&self) -> char {
181179
if self.is_ascii() {
182-
ASCII_UPPER_MAP[*self as uint] as char
180+
(*self as u8).to_ascii_uppercase() as char
183181
} else {
184182
*self
185183
}
@@ -188,7 +186,7 @@ impl AsciiExt for char {
188186
#[inline]
189187
fn to_ascii_lowercase(&self) -> char {
190188
if self.is_ascii() {
191-
ASCII_UPPER_MAP[*self as uint] as char
189+
(*self as u8).to_ascii_lowercase() as char
192190
} else {
193191
*self
194192
}
@@ -236,7 +234,7 @@ pub fn escape_default<F>(c: u8, mut f: F) where
236234
}
237235
}
238236

239-
static ASCII_LOWER_MAP: [u8, ..256] = [
237+
static ASCII_LOWERCASE_MAP: [u8, ..256] = [
240238
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
241239
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
242240
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
@@ -275,7 +273,7 @@ static ASCII_LOWER_MAP: [u8, ..256] = [
275273
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
276274
];
277275

278-
static ASCII_UPPER_MAP: [u8, ..256] = [
276+
static ASCII_UPPERCASE_MAP: [u8, ..256] = [
279277
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
280278
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
281279
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,

0 commit comments

Comments
 (0)