/// The offset is guaranteed to be in bounds of the slice in question, and
/// the byte at the specified offset was the first invalid byte in the
/// sequence detected.
/// The offset is guaranteed to be in bounds of the slice in question, and
/// the byte at the specified offset was the first invalid byte in the
/// sequence detected.
let (len, _) = self.iter.size_hint();
(len.saturating_add(3) / 4, Some(len))
}
let (len, _) = self.iter.size_hint();
(len.saturating_add(3) / 4, Some(len))
}
#[derive(Clone)]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct CharIndices<'a> {
#[derive(Clone)]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct CharIndices<'a> {
iter: Chars<'a>,
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Iterator for CharIndices<'a> {
iter: Chars<'a>,
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Iterator for CharIndices<'a> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> DoubleEndedIterator for CharIndices<'a> {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> DoubleEndedIterator for CharIndices<'a> {
#[inline]
struct CharSplitsN<'a, Sep> {
iter: CharSplits<'a, Sep>,
/// The number of splits remaining
struct CharSplitsN<'a, Sep> {
iter: CharSplits<'a, Sep>,
/// The number of splits remaining
- fn next(&mut self, haystack: &[u8], needle: &[u8]) -> Option<(uint, uint)> {
+ fn next(&mut self, haystack: &[u8], needle: &[u8]) -> Option<(usize, usize)> {
while self.position + needle.len() <= haystack.len() {
if &haystack[self.position .. self.position + needle.len()] == needle {
let match_pos = self.position;
while self.position + needle.len() <= haystack.len() {
if &haystack[self.position .. self.position + needle.len()] == needle {
let match_pos = self.position;
// This isn't in the original algorithm, as far as I'm aware.
let byteset = needle.iter()
// This isn't in the original algorithm, as far as I'm aware.
let byteset = needle.iter()
// A particularly readable explanation of what's going on here can be found
// in Crochemore and Rytter's book "Text Algorithms", ch 13. Specifically
// A particularly readable explanation of what's going on here can be found
// in Crochemore and Rytter's book "Text Algorithms", ch 13. Specifically
// How far we can jump when we encounter a mismatch is all based on the fact
// that (u, v) is a critical factorization for the needle.
#[inline]
// How far we can jump when we encounter a mismatch is all based on the fact
// that (u, v) is a critical factorization for the needle.
#[inline]
- fn next(&mut self, haystack: &[u8], needle: &[u8], long_period: bool) -> Option<(uint, uint)> {
+ fn next(&mut self, haystack: &[u8], needle: &[u8], long_period: bool)
+ -> Option<(usize, usize)> {
// Quickly skip by large portions unrelated to our substring
if (self.byteset >>
((haystack[self.position + needle.len() - 1] & 0x3f)
// Quickly skip by large portions unrelated to our substring
if (self.byteset >>
((haystack[self.position + needle.len() - 1] & 0x3f)
// Specifically, returns (i, p), where i is the starting index of v in some
// critical factorization (u, v) and p = period(v)
#[inline]
// Specifically, returns (i, p), where i is the starting index of v in some
// critical factorization (u, v) and p = period(v)
#[inline]
let mut left = -1; // Corresponds to i in the paper
let mut right = 0; // Corresponds to j in the paper
let mut offset = 1; // Corresponds to k in the paper
let mut left = -1; // Corresponds to i in the paper
let mut right = 0; // Corresponds to j in the paper
let mut offset = 1; // Corresponds to k in the paper
#[unstable(feature = "core", reason = "type may be removed")]
pub struct SplitStr<'a> {
it: MatchIndices<'a>,
#[unstable(feature = "core", reason = "type may be removed")]
pub struct SplitStr<'a> {
it: MatchIndices<'a>,
finished: bool
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Iterator for MatchIndices<'a> {
finished: bool
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Iterator for MatchIndices<'a> {
/// to compare &[u8] byte slices that are not necessarily valid UTF-8.
#[inline]
fn eq_slice_(a: &str, b: &str) -> bool {
/// to compare &[u8] byte slices that are not necessarily valid UTF-8.
#[inline]
fn eq_slice_(a: &str, b: &str) -> bool {
a.len() == b.len() && unsafe {
memcmp(a.as_ptr() as *const i8,
b.as_ptr() as *const i8,
a.len() == b.len() && unsafe {
memcmp(a.as_ptr() as *const i8,
b.as_ptr() as *const i8,
// ASCII characters are always valid, so only large
// bytes need more examination.
if first >= 128 {
// ASCII characters are always valid, so only large
// bytes need more examination.
if first >= 128 {
// is_char_boundary checks that the index is in [0, .len()]
if index.start <= index.end &&
self.is_char_boundary(index.start) &&
// is_char_boundary checks that the index is in [0, .len()]
if index.start <= index.end &&
self.is_char_boundary(index.start) &&
/// Panics when `end` does not point to a valid character, or is
/// out of bounds.
#[stable(feature = "rust1", since = "1.0.0")]
/// Panics when `end` does not point to a valid character, or is
/// out of bounds.
#[stable(feature = "rust1", since = "1.0.0")]
// is_char_boundary checks that the index is in [0, .len()]
if self.is_char_boundary(index.end) {
unsafe { self.slice_unchecked(0, index.end) }
// is_char_boundary checks that the index is in [0, .len()]
if self.is_char_boundary(index.end) {
unsafe { self.slice_unchecked(0, index.end) }
/// Panics when `begin` does not point to a valid character, or is
/// out of bounds.
#[stable(feature = "rust1", since = "1.0.0")]
/// Panics when `begin` does not point to a valid character, or is
/// out of bounds.
#[stable(feature = "rust1", since = "1.0.0")]
// is_char_boundary checks that the index is in [0, .len()]
if self.is_char_boundary(index.start) {
unsafe { self.slice_unchecked(index.start, self.len()) }
// is_char_boundary checks that the index is in [0, .len()]
if self.is_char_boundary(index.start) {
unsafe { self.slice_unchecked(index.start, self.len()) }
fn bytes<'a>(&'a self) -> Bytes<'a>;
fn char_indices<'a>(&'a self) -> CharIndices<'a>;
fn split<'a, P: CharEq>(&'a self, pat: P) -> Split<'a, P>;
fn bytes<'a>(&'a self) -> Bytes<'a>;
fn char_indices<'a>(&'a self) -> CharIndices<'a>;
fn split<'a, P: CharEq>(&'a self, pat: P) -> Split<'a, P>;
- fn splitn<'a, P: CharEq>(&'a self, count: uint, pat: P) -> SplitN<'a, P>;
+ fn splitn<'a, P: CharEq>(&'a self, count: usize, pat: P) -> SplitN<'a, P>;
fn split_terminator<'a, P: CharEq>(&'a self, pat: P) -> SplitTerminator<'a, P>;
fn split_terminator<'a, P: CharEq>(&'a self, pat: P) -> SplitTerminator<'a, P>;
- fn rsplitn<'a, P: CharEq>(&'a self, count: uint, pat: P) -> RSplitN<'a, P>;
+ fn rsplitn<'a, P: CharEq>(&'a self, count: usize, pat: P) -> RSplitN<'a, P>;
fn match_indices<'a>(&'a self, sep: &'a str) -> MatchIndices<'a>;
fn split_str<'a>(&'a self, pat: &'a str) -> SplitStr<'a>;
fn lines<'a>(&'a self) -> Lines<'a>;
fn lines_any<'a>(&'a self) -> LinesAny<'a>;
fn match_indices<'a>(&'a self, sep: &'a str) -> MatchIndices<'a>;
fn split_str<'a>(&'a self, pat: &'a str) -> SplitStr<'a>;
fn lines<'a>(&'a self) -> Lines<'a>;
fn lines_any<'a>(&'a self) -> LinesAny<'a>;
- fn char_len(&self) -> uint;
- fn slice_chars<'a>(&'a self, begin: uint, end: uint) -> &'a str;
- unsafe fn slice_unchecked<'a>(&'a self, begin: uint, end: uint) -> &'a str;
+ fn char_len(&self) -> usize;
+ fn slice_chars<'a>(&'a self, begin: usize, end: usize) -> &'a str;
+ unsafe fn slice_unchecked<'a>(&'a self, begin: usize, end: usize) -> &'a str;
fn starts_with(&self, pat: &str) -> bool;
fn ends_with(&self, pat: &str) -> bool;
fn trim_matches<'a, P: CharEq>(&'a self, pat: P) -> &'a str;
fn trim_left_matches<'a, P: CharEq>(&'a self, pat: P) -> &'a str;
fn trim_right_matches<'a, P: CharEq>(&'a self, pat: P) -> &'a str;
fn starts_with(&self, pat: &str) -> bool;
fn ends_with(&self, pat: &str) -> bool;
fn trim_matches<'a, P: CharEq>(&'a self, pat: P) -> &'a str;
fn trim_left_matches<'a, P: CharEq>(&'a self, pat: P) -> &'a str;
fn trim_right_matches<'a, P: CharEq>(&'a self, pat: P) -> &'a str;
- fn is_char_boundary(&self, index: uint) -> bool;
- fn char_range_at(&self, start: uint) -> CharRange;
- fn char_range_at_reverse(&self, start: uint) -> CharRange;
- fn char_at(&self, i: uint) -> char;
- fn char_at_reverse(&self, i: uint) -> char;
+ fn is_char_boundary(&self, index: usize) -> bool;
+ fn char_range_at(&self, start: usize) -> CharRange;
+ fn char_range_at_reverse(&self, start: usize) -> CharRange;
+ fn char_at(&self, i: usize) -> char;
+ fn char_at_reverse(&self, i: usize) -> char;
- fn find<P: CharEq>(&self, pat: P) -> Option<uint>;
- fn rfind<P: CharEq>(&self, pat: P) -> Option<uint>;
- fn find_str(&self, pat: &str) -> Option<uint>;
+ fn find<P: CharEq>(&self, pat: P) -> Option<usize>;
+ fn rfind<P: CharEq>(&self, pat: P) -> Option<usize>;
+ fn find_str(&self, pat: &str) -> Option<usize>;
fn is_empty(&self) -> bool;
fn parse<T: FromStr>(&self) -> Result<T, T::Err>;
}
#[inline(never)]
fn is_empty(&self) -> bool;
fn parse<T: FromStr>(&self) -> Result<T, T::Err>;
}
#[inline(never)]
let (c, n) = char_range_at_raw(self.as_bytes(), i);
CharRange { ch: unsafe { mem::transmute(c) }, next: n }
}
#[inline]
let (c, n) = char_range_at_raw(self.as_bytes(), i);
CharRange { ch: unsafe { mem::transmute(c) }, next: n }
}
#[inline]
// while there is a previous byte == 10......
while i > 0 && s.as_bytes()[i] & !CONT_MASK == TAG_CONT_U8 {
i -= 1;
}
let mut val = s.as_bytes()[i] as u32;
// while there is a previous byte == 10......
while i > 0 && s.as_bytes()[i] & !CONT_MASK == TAG_CONT_U8 {
i -= 1;
}
let mut val = s.as_bytes()[i] as u32;
- fn subslice_offset(&self, inner: &str) -> uint {
- let a_start = self.as_ptr() as uint;
+ fn subslice_offset(&self, inner: &str) -> usize {
+ let a_start = self.as_ptr() as usize;
if bytes[i] < 128u8 {
return (bytes[i] as u32, i + 1);
}
// Multibyte case is a fn to allow char_range_at to inline cleanly
if bytes[i] < 128u8 {
return (bytes[i] as u32, i + 1);
}
// Multibyte case is a fn to allow char_range_at to inline cleanly