Skip to content

Commit 9e9f4a6

Browse files
committed
core: Remove str::init_elt
This was added based on my FIXME, but I no longer believe it has a place in core::str, partly because it doesn't follow current naming conventions, and partly because it can be immitated with a one liner using str::from_chars and vec::from_elem. I have replaced the existing uses with said one-liner.
1 parent 1680ccc commit 9e9f4a6

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed

src/libcore/extfmt.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ mod rt {
373373
let len = str::char_len(s);
374374
if len < prec {
375375
let diff = prec - len;
376-
let pad = str::init_elt(diff, '0');
376+
let pad = str::from_chars(vec::from_elem(diff, '0'));
377377
pad + s
378378
} else { s }
379379
};
@@ -398,7 +398,7 @@ mod rt {
398398
let mut padchar = ' ';
399399
let diff = uwidth - strlen;
400400
if have_flag(cv.flags, flag_left_justify) {
401-
let padstr = str::init_elt(diff, padchar);
401+
let padstr = str::from_chars(vec::from_elem(diff, padchar));
402402
ret s + padstr;
403403
}
404404
let {might_zero_pad, signed} = alt mode {
@@ -418,7 +418,7 @@ mod rt {
418418
false
419419
}
420420
};
421-
let padstr = str::init_elt(diff, padchar);
421+
let padstr = str::from_chars(vec::from_elem(diff, padchar));
422422
// This is completely heinous. If we have a signed value then
423423
// potentially rip apart the intermediate result and insert some
424424
// zeros. It may make sense to convert zero padding to a precision
@@ -427,7 +427,7 @@ mod rt {
427427
if signed && zero_padding && str::len(s) > 0u {
428428
let head = str::shift_char(s);
429429
if head == '+' || head == '-' || head == ' ' {
430-
let headstr = str::init_elt(1u, head);
430+
let headstr = str::from_chars(vec::from_elem(1u, head));
431431
ret headstr + padstr + s;
432432
}
433433
else {

src/libcore/str.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export
2020
push_char,
2121
concat,
2222
connect,
23-
init_elt,
2423

2524
// Reinterpretation
2625
as_bytes,
@@ -241,16 +240,6 @@ fn connect(v: [str], sep: str) -> str {
241240
ret s;
242241
}
243242

244-
#[doc = "Returns a string of <n_elts> repetitions of <c>, which must be \
245-
UTF-8"]
246-
fn init_elt(n_elts: uint, c: char) -> str {
247-
let mut rslt = "";
248-
uint::range(0u, n_elts) {|_i|
249-
push_char(rslt, c);
250-
}
251-
rslt
252-
}
253-
254243
/*
255244
Section: Adding to and removing from a string
256245
*/

0 commit comments

Comments
 (0)