Skip to content

Commit b73f801

Browse files
committed
int/uint parse_buf => parse_bytes (#3444)
1 parent 651e63c commit b73f801

File tree

7 files changed

+46
-46
lines changed

7 files changed

+46
-46
lines changed

src/libcore/int-template.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export is_nonpositive, is_nonnegative;
1616
export range;
1717
export compl;
1818
export abs;
19-
export parse_buf, from_str, to_str, to_str_bytes, str;
19+
export parse_bytes, from_str, to_str, to_str_bytes, str;
2020
export num, ord, eq, times, timesi;
2121
export bits, bytes;
2222

@@ -137,7 +137,7 @@ impl T: iter::TimesIx {
137137
* * buf - A byte buffer
138138
* * radix - The base of the number
139139
*/
140-
fn parse_buf(buf: &[u8], radix: uint) -> Option<T> {
140+
fn parse_bytes(buf: &[u8], radix: uint) -> Option<T> {
141141
if vec::len(buf) == 0u { return None; }
142142
let mut i = vec::len(buf) - 1u;
143143
let mut start = 0u;
@@ -160,7 +160,7 @@ fn parse_buf(buf: &[u8], radix: uint) -> Option<T> {
160160
}
161161

162162
/// Parse a string to an int
163-
fn from_str(s: &str) -> Option<T> { parse_buf(str::to_bytes(s), 10u) }
163+
fn from_str(s: &str) -> Option<T> { parse_bytes(str::to_bytes(s), 10u) }
164164

165165
impl T : FromStr {
166166
static fn from_str(s: &str) -> Option<T> { from_str(s) }
@@ -209,28 +209,28 @@ fn test_from_str() {
209209
// FIXME: Has alignment issues on windows and 32-bit linux (#2609)
210210
#[test]
211211
#[ignore]
212-
fn test_parse_buf() {
212+
fn test_parse_bytes() {
213213
use str::to_bytes;
214-
assert parse_buf(to_bytes(~"123"), 10u) == Some(123 as T);
215-
assert parse_buf(to_bytes(~"1001"), 2u) == Some(9 as T);
216-
assert parse_buf(to_bytes(~"123"), 8u) == Some(83 as T);
217-
assert parse_buf(to_bytes(~"123"), 16u) == Some(291 as T);
218-
assert parse_buf(to_bytes(~"ffff"), 16u) == Some(65535 as T);
219-
assert parse_buf(to_bytes(~"FFFF"), 16u) == Some(65535 as T);
220-
assert parse_buf(to_bytes(~"z"), 36u) == Some(35 as T);
221-
assert parse_buf(to_bytes(~"Z"), 36u) == Some(35 as T);
222-
223-
assert parse_buf(to_bytes(~"-123"), 10u) == Some(-123 as T);
224-
assert parse_buf(to_bytes(~"-1001"), 2u) == Some(-9 as T);
225-
assert parse_buf(to_bytes(~"-123"), 8u) == Some(-83 as T);
226-
assert parse_buf(to_bytes(~"-123"), 16u) == Some(-291 as T);
227-
assert parse_buf(to_bytes(~"-ffff"), 16u) == Some(-65535 as T);
228-
assert parse_buf(to_bytes(~"-FFFF"), 16u) == Some(-65535 as T);
229-
assert parse_buf(to_bytes(~"-z"), 36u) == Some(-35 as T);
230-
assert parse_buf(to_bytes(~"-Z"), 36u) == Some(-35 as T);
231-
232-
assert parse_buf(to_bytes(~"Z"), 35u).is_none();
233-
assert parse_buf(to_bytes(~"-9"), 2u).is_none();
214+
assert parse_bytes(to_bytes(~"123"), 10u) == Some(123 as T);
215+
assert parse_bytes(to_bytes(~"1001"), 2u) == Some(9 as T);
216+
assert parse_bytes(to_bytes(~"123"), 8u) == Some(83 as T);
217+
assert parse_bytes(to_bytes(~"123"), 16u) == Some(291 as T);
218+
assert parse_bytes(to_bytes(~"ffff"), 16u) == Some(65535 as T);
219+
assert parse_bytes(to_bytes(~"FFFF"), 16u) == Some(65535 as T);
220+
assert parse_bytes(to_bytes(~"z"), 36u) == Some(35 as T);
221+
assert parse_bytes(to_bytes(~"Z"), 36u) == Some(35 as T);
222+
223+
assert parse_bytes(to_bytes(~"-123"), 10u) == Some(-123 as T);
224+
assert parse_bytes(to_bytes(~"-1001"), 2u) == Some(-9 as T);
225+
assert parse_bytes(to_bytes(~"-123"), 8u) == Some(-83 as T);
226+
assert parse_bytes(to_bytes(~"-123"), 16u) == Some(-291 as T);
227+
assert parse_bytes(to_bytes(~"-ffff"), 16u) == Some(-65535 as T);
228+
assert parse_bytes(to_bytes(~"-FFFF"), 16u) == Some(-65535 as T);
229+
assert parse_bytes(to_bytes(~"-z"), 36u) == Some(-35 as T);
230+
assert parse_bytes(to_bytes(~"-Z"), 36u) == Some(-35 as T);
231+
232+
assert parse_bytes(to_bytes(~"Z"), 35u).is_none();
233+
assert parse_bytes(to_bytes(~"-9"), 2u).is_none();
234234
}
235235

236236
#[test]

src/libcore/result.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pure fn to_either<T: Copy, U: Copy>(res: Result<U, T>) -> Either<T, U> {
9494
* Example:
9595
*
9696
* let res = chain(read_file(file)) { |buf|
97-
* ok(parse_buf(buf))
97+
* ok(parse_bytes(buf))
9898
* }
9999
*/
100100
fn chain<T, U: Copy, V: Copy>(res: Result<T, V>, op: fn(T) -> Result<U, V>)
@@ -170,7 +170,7 @@ fn iter_err<T, E>(res: Result<T, E>, f: fn(E)) {
170170
* Example:
171171
*
172172
* let res = map(read_file(file)) { |buf|
173-
* parse_buf(buf)
173+
* parse_bytes(buf)
174174
* }
175175
*/
176176
fn map<T, E: Copy, U: Copy>(res: Result<T, E>, op: fn(T) -> U)

src/libcore/uint-template.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export is_nonpositive, is_nonnegative;
1515
export range;
1616
export compl;
1717
export to_str, to_str_bytes;
18-
export from_str, from_str_radix, str, parse_buf;
18+
export from_str, from_str_radix, str, parse_bytes;
1919
export num, ord, eq, times, timesi;
2020
export bits, bytes;
2121

@@ -126,7 +126,7 @@ impl T: iter::TimesIx {
126126
*
127127
* `buf` must not be empty
128128
*/
129-
fn parse_buf(buf: &[const u8], radix: uint) -> Option<T> {
129+
fn parse_bytes(buf: &[const u8], radix: uint) -> Option<T> {
130130
if vec::len(buf) == 0u { return None; }
131131
let mut i = vec::len(buf) - 1u;
132132
let mut power = 1u as T;
@@ -143,7 +143,7 @@ fn parse_buf(buf: &[const u8], radix: uint) -> Option<T> {
143143
}
144144

145145
/// Parse a string to an int
146-
fn from_str(s: &str) -> Option<T> { parse_buf(str::to_bytes(s), 10u) }
146+
fn from_str(s: &str) -> Option<T> { parse_bytes(str::to_bytes(s), 10u) }
147147

148148
impl T : FromStr {
149149
static fn from_str(s: &str) -> Option<T> { from_str(s) }
@@ -275,17 +275,17 @@ fn test_from_str() {
275275

276276
#[test]
277277
#[ignore]
278-
fn test_parse_buf() {
278+
fn test_parse_bytes() {
279279
use str::to_bytes;
280-
assert parse_buf(to_bytes(~"123"), 10u) == Some(123u as T);
281-
assert parse_buf(to_bytes(~"1001"), 2u) == Some(9u as T);
282-
assert parse_buf(to_bytes(~"123"), 8u) == Some(83u as T);
283-
assert parse_buf(to_bytes(~"123"), 16u) == Some(291u as T);
284-
assert parse_buf(to_bytes(~"ffff"), 16u) == Some(65535u as T);
285-
assert parse_buf(to_bytes(~"z"), 36u) == Some(35u as T);
286-
287-
assert parse_buf(to_bytes(~"Z"), 10u).is_none();
288-
assert parse_buf(to_bytes(~"_"), 2u).is_none();
280+
assert parse_bytes(to_bytes(~"123"), 10u) == Some(123u as T);
281+
assert parse_bytes(to_bytes(~"1001"), 2u) == Some(9u as T);
282+
assert parse_bytes(to_bytes(~"123"), 8u) == Some(83u as T);
283+
assert parse_bytes(to_bytes(~"123"), 16u) == Some(291u as T);
284+
assert parse_bytes(to_bytes(~"ffff"), 16u) == Some(65535u as T);
285+
assert parse_bytes(to_bytes(~"z"), 36u) == Some(35u as T);
286+
287+
assert parse_bytes(to_bytes(~"Z"), 10u).is_none();
288+
assert parse_bytes(to_bytes(~"_"), 2u).is_none();
289289
}
290290

291291
#[test]

src/libstd/net_url.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ fn decode_inner(s: &str, full_url: bool) -> ~str {
116116
match rdr.read_char() {
117117
'%' => {
118118
let bytes = rdr.read_bytes(2u);
119-
let ch = uint::parse_buf(bytes, 16u).get() as char;
119+
let ch = uint::parse_bytes(bytes, 16u).get() as char;
120120

121121
if full_url {
122122
// Only decode some characters:
@@ -241,7 +241,7 @@ fn decode_form_urlencoded(s: ~[u8]) ->
241241
ch => {
242242
let ch = match ch {
243243
'%' => {
244-
uint::parse_buf(rdr.read_bytes(2u), 16u).get() as char
244+
uint::parse_bytes(rdr.read_bytes(2u), 16u).get() as char
245245
}
246246
'+' => ' ',
247247
ch => ch

src/rustc/metadata/decoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ fn field_mutability(d: ebml::Doc) -> ast::class_mutability {
205205

206206
fn variant_disr_val(d: ebml::Doc) -> Option<int> {
207207
do option::chain(ebml::maybe_get_doc(d, tag_disr_val)) |val_doc| {
208-
int::parse_buf(ebml::doc_data(val_doc), 10u)
208+
int::parse_bytes(ebml::doc_data(val_doc), 10u)
209209
}
210210
}
211211

src/rustc/metadata/tydecode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,12 +440,12 @@ fn parse_def_id(buf: &[u8]) -> ast::def_id {
440440
let crate_part = vec::view(buf, 0u, colon_idx);
441441
let def_part = vec::view(buf, colon_idx + 1u, len);
442442

443-
let crate_num = match uint::parse_buf(crate_part, 10u) {
443+
let crate_num = match uint::parse_bytes(crate_part, 10u) {
444444
Some(cn) => cn as int,
445445
None => fail (fmt!("internal error: parse_def_id: crate number \
446446
expected, but found %?", crate_part))
447447
};
448-
let def_num = match uint::parse_buf(def_part, 10u) {
448+
let def_num = match uint::parse_bytes(def_part, 10u) {
449449
Some(dn) => dn as int,
450450
None => fail (fmt!("internal error: parse_def_id: id expected, but \
451451
found %?", def_part))

src/test/bench/shootout-pfib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ fn main(args: ~[~str]) {
9393
if opts.stress {
9494
stress(2);
9595
} else {
96-
let max = option::get(uint::parse_buf(str::to_bytes(args[1]),
97-
10u)) as int;
96+
let max = option::get(uint::parse_bytes(str::to_bytes(args[1]),
97+
10u)) as int;
9898

9999
let num_trials = 10;
100100

0 commit comments

Comments
 (0)