std: remove substr & str::count_*, methodise char_len, implement slice_chars.

The confusing mixture of byte index and character count meant that every
use of .substr was incorrect; replaced by slice_chars which only uses
character indices. The old behaviour of `.substr(start, n)` can be emulated
via `.slice_from(start).slice_chars(0, n)`.
This commit is contained in:
Huon Wilson 2013-06-11 21:37:22 +10:00
parent 9fff8c6eba
commit 3ac00a9489
10 changed files with 76 additions and 104 deletions

View file

@ -325,7 +325,7 @@ pub mod ct {
'o' => TyOctal,
'f' => TyFloat,
'?' => TyPoly,
_ => err(~"unknown type in conversion: " + s.substr(i, 1))
_ => err(fmt!("unknown type in conversion: %c", s.char_at(i)))
};
Parsed::new(t, i + 1)
@ -546,7 +546,7 @@ pub mod rt {
// displayed
let unpadded = match cv.precision {
CountImplied => s,
CountIs(max) => if (max as uint) < str::char_len(s) {
CountIs(max) => if (max as uint) < s.char_len() {
s.slice(0, max as uint)
} else {
s
@ -584,7 +584,7 @@ pub mod rt {
~""
} else {
let s = uint::to_str_radix(num, radix);
let len = str::char_len(s);
let len = s.char_len();
if len < prec {
let diff = prec - len;
let pad = str::from_chars(vec::from_elem(diff, '0'));
@ -614,7 +614,7 @@ pub mod rt {
}
CountIs(width) => { width as uint }
};
let strlen = str::char_len(s) + headsize;
let strlen = s.char_len() + headsize;
if uwidth <= strlen {
for head.iter().advance |&c| {
buf.push_char(c);