Skip to content

Commit b656bfa

Browse files
author
blake2-ppc
committed
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() }
1 parent 518bd07 commit b656bfa

File tree

1 file changed

+0
-40
lines changed

1 file changed

+0
-40
lines changed

src/libstd/str.rs

-40
Original file line numberDiff line numberDiff line change
@@ -907,46 +907,6 @@ pub fn with_capacity(capacity: uint) -> ~str {
907907
}
908908
}
909909

910-
/// As char_len but for a slice of a string
911-
///
912-
/// # Arguments
913-
///
914-
/// * s - A valid string
915-
/// * start - The position inside `s` where to start counting in bytes
916-
/// * end - The position where to stop counting
917-
///
918-
/// # Return value
919-
///
920-
/// The number of Unicode characters in `s` between the given indices.
921-
pub fn count_chars(s: &str, start: uint, end: uint) -> uint {
922-
assert!(s.is_char_boundary(start));
923-
assert!(s.is_char_boundary(end));
924-
let mut i = start;
925-
let mut len = 0u;
926-
while i < end {
927-
let next = s.char_range_at(i).next;
928-
len += 1u;
929-
i = next;
930-
}
931-
return len;
932-
}
933-
934-
/// Counts the number of bytes taken by the first `n` chars in `s`
935-
/// starting from `start`.
936-
pub fn count_bytes<'b>(s: &'b str, start: uint, n: uint) -> uint {
937-
assert!(s.is_char_boundary(start));
938-
let mut end = start;
939-
let mut cnt = n;
940-
let l = s.len();
941-
while cnt > 0u {
942-
assert!(end < l);
943-
let next = s.char_range_at(end).next;
944-
cnt -= 1u;
945-
end = next;
946-
}
947-
end - start
948-
}
949-
950910
// https://tools.ietf.org/html/rfc3629
951911
static UTF8_CHAR_WIDTH: [u8, ..256] = [
952912
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,

0 commit comments

Comments
 (0)