]> git.lizzy.rs Git - rust.git/commitdiff
auto merge of #8857 : blake2-ppc/rust/std-str-remove, r=thestinger
authorbors <bors@rust-lang.org>
Fri, 30 Aug 2013 11:40:47 +0000 (04:40 -0700)
committerbors <bors@rust-lang.org>
Fri, 30 Aug 2013 11:40:47 +0000 (04:40 -0700)
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()
}

1  2 
src/libstd/str.rs

diff --combined src/libstd/str.rs
index feca2db670594144a9a85504d0c36e3fae162b71,f70204d0274ace583e72aab9528e53758de0c7e3..3265c470e904fcb1f5aa1b2c7b780867c66d55be
@@@ -21,7 -21,7 +21,7 @@@ use char
  use char::Char;
  use clone::{Clone, DeepClone};
  use container::{Container, Mutable};
 -use iter::Times;
 +use num::Times;
  use iterator::{Iterator, FromIterator, Extendable};
  use iterator::{Filter, AdditiveIterator, Map};
  use iterator::{Invert, DoubleEndedIterator};
@@@ -907,46 -907,6 +907,6 @@@ pub fn with_capacity(capacity: uint) -
      }
  }
  
- /// As char_len but for a slice of a string
- ///
- /// # Arguments
- ///
- /// * s - A valid string
- /// * start - The position inside `s` where to start counting in bytes
- /// * end - The position where to stop counting
- ///
- /// # Return value
- ///
- /// The number of Unicode characters in `s` between the given indices.
- pub fn count_chars(s: &str, start: uint, end: uint) -> uint {
-     assert!(s.is_char_boundary(start));
-     assert!(s.is_char_boundary(end));
-     let mut i = start;
-     let mut len = 0u;
-     while i < end {
-         let next = s.char_range_at(i).next;
-         len += 1u;
-         i = next;
-     }
-     return len;
- }
- /// Counts the number of bytes taken by the first `n` chars in `s`
- /// starting from `start`.
- pub fn count_bytes<'b>(s: &'b str, start: uint, n: uint) -> uint {
-     assert!(s.is_char_boundary(start));
-     let mut end = start;
-     let mut cnt = n;
-     let l = s.len();
-     while cnt > 0u {
-         assert!(end < l);
-         let next = s.char_range_at(end).next;
-         cnt -= 1u;
-         end = next;
-     }
-     end - start
- }
  // https://tools.ietf.org/html/rfc3629
  static UTF8_CHAR_WIDTH: [u8, ..256] = [
  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,