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.
This commit is contained in:
Brian Anderson 2012-03-16 15:29:24 -07:00
parent 1680ccce1e
commit 9e9f4a6240
2 changed files with 4 additions and 15 deletions

View File

@ -373,7 +373,7 @@ mod rt {
let len = str::char_len(s);
if len < prec {
let diff = prec - len;
let pad = str::init_elt(diff, '0');
let pad = str::from_chars(vec::from_elem(diff, '0'));
pad + s
} else { s }
};
@ -398,7 +398,7 @@ mod rt {
let mut padchar = ' ';
let diff = uwidth - strlen;
if have_flag(cv.flags, flag_left_justify) {
let padstr = str::init_elt(diff, padchar);
let padstr = str::from_chars(vec::from_elem(diff, padchar));
ret s + padstr;
}
let {might_zero_pad, signed} = alt mode {
@ -418,7 +418,7 @@ mod rt {
false
}
};
let padstr = str::init_elt(diff, padchar);
let padstr = str::from_chars(vec::from_elem(diff, padchar));
// This is completely heinous. If we have a signed value then
// potentially rip apart the intermediate result and insert some
// zeros. It may make sense to convert zero padding to a precision
@ -427,7 +427,7 @@ mod rt {
if signed && zero_padding && str::len(s) > 0u {
let head = str::shift_char(s);
if head == '+' || head == '-' || head == ' ' {
let headstr = str::init_elt(1u, head);
let headstr = str::from_chars(vec::from_elem(1u, head));
ret headstr + padstr + s;
}
else {

View File

@ -20,7 +20,6 @@ export
push_char,
concat,
connect,
init_elt,
// Reinterpretation
as_bytes,
@ -241,16 +240,6 @@ fn connect(v: [str], sep: str) -> str {
ret s;
}
#[doc = "Returns a string of <n_elts> repetitions of <c>, which must be \
UTF-8"]
fn init_elt(n_elts: uint, c: char) -> str {
let mut rslt = "";
uint::range(0u, n_elts) {|_i|
push_char(rslt, c);
}
rslt
}
/*
Section: Adding to and removing from a string
*/