]> git.lizzy.rs Git - rust.git/commit
std::str: Remove functions count_chars, count_bytes
authorblake2-ppc <blake2-ppc>
Thu, 29 Aug 2013 13:21:05 +0000 (15:21 +0200)
committerblake2-ppc <blake2-ppc>
Thu, 29 Aug 2013 13:51:39 +0000 (15:51 +0200)
commitb656bfaaa96dd8d242e6045e7e38b355992aca31
tree7ef98fddff583e4242363955a3b945c6ff074245
parent518bd073b4b41a5cca0892c1a7878a7b16836db1
std::str: Remove functions count_chars, count_bytes

These are very easy to replace with methods on string slices, basically
`.char_len()` and `.len()`.

These are the replacement implementations I did to clean these
functions up, but seeing this I propose removal:

/// ...
pub fn count_chars(s: &str, begin: uint, end: uint) -> uint {
    // .slice() checks the char boundaries
    s.slice(begin, end).char_len()
}

/// Counts the number of bytes taken by the first `n` chars in `s`
/// starting from byte index `begin`.
///
/// Fails if there are less than `n` chars past `begin`
pub fn count_bytes<'b>(s: &'b str, begin: uint, n: uint) -> uint {
    s.slice_from(begin).slice_chars(0, n).len()
}
src/libstd/str.rs