std: replace str::substr with the method.
This commit is contained in:
@@ -83,9 +83,9 @@ pub fn of_str(str: @~str) -> Rope {
|
|||||||
*
|
*
|
||||||
* # Return value
|
* # Return value
|
||||||
*
|
*
|
||||||
* A rope representing the same string as `str::substr(str, byte_offset,
|
* A rope representing the same string as `str.substr(byte_offset,
|
||||||
* byte_len)`. Depending on `byte_len`, this rope may be empty, flat or
|
* byte_len)`. Depending on `byte_len`, this rope may be empty, flat
|
||||||
* complex.
|
* or complex.
|
||||||
*
|
*
|
||||||
* # Performance note
|
* # Performance note
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -2684,11 +2684,11 @@ impl Resolver {
|
|||||||
match self.idents_to_str(module_path).rfind(':') {
|
match self.idents_to_str(module_path).rfind(':') {
|
||||||
Some(idx) => {
|
Some(idx) => {
|
||||||
self.session.span_err(span, fmt!("unresolved import: could not find `%s` \
|
self.session.span_err(span, fmt!("unresolved import: could not find `%s` \
|
||||||
in `%s`", str::substr(mpath, idx,
|
in `%s`", mpath.substr(idx,
|
||||||
mpath.len() - idx),
|
mpath.len() - idx),
|
||||||
// idx - 1 to account for the extra
|
// idx - 1 to account for the extra
|
||||||
// colon
|
// colon
|
||||||
str::substr(mpath, 0, idx - 1)));
|
mpath.substr(0, idx - 1)));
|
||||||
},
|
},
|
||||||
None => (),
|
None => (),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -432,16 +432,6 @@ pub fn byte_slice_no_callback<'a>(s: &'a str) -> &'a [u8] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Take a substring of another.
|
|
||||||
*
|
|
||||||
* Returns a slice pointing at `n` characters starting from byte offset
|
|
||||||
* `begin`.
|
|
||||||
*/
|
|
||||||
pub fn substr<'a>(s: &'a str, begin: uint, n: uint) -> &'a str {
|
|
||||||
s.slice(begin, begin + count_bytes(s, begin, n))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Something that can be used to compare against a character
|
/// Something that can be used to compare against a character
|
||||||
pub trait CharEq {
|
pub trait CharEq {
|
||||||
/// Determine if the splitter should split at the given character
|
/// Determine if the splitter should split at the given character
|
||||||
@@ -1854,7 +1844,7 @@ impl<'self> StrSlice<'self> for &'self str {
|
|||||||
*/
|
*/
|
||||||
#[inline]
|
#[inline]
|
||||||
fn substr(&self, begin: uint, n: uint) -> &'self str {
|
fn substr(&self, begin: uint, n: uint) -> &'self str {
|
||||||
substr(*self, begin, n)
|
s.slice(begin, begin + count_bytes(s, begin, n))
|
||||||
}
|
}
|
||||||
/// Escape each char in `s` with char::escape_default.
|
/// Escape each char in `s` with char::escape_default.
|
||||||
#[inline]
|
#[inline]
|
||||||
@@ -2516,11 +2506,11 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_substr() {
|
fn test_substr() {
|
||||||
fn t(a: &str, b: &str, start: int) {
|
fn t(a: &str, b: &str, start: int) {
|
||||||
assert_eq!(substr(a, start as uint, b.len()), b);
|
assert_eq!(a.substr(start as uint, b.len()), b);
|
||||||
}
|
}
|
||||||
t("hello", "llo", 2);
|
t("hello", "llo", 2);
|
||||||
t("hello", "el", 1);
|
t("hello", "el", 1);
|
||||||
assert_eq!("ะเทศไท", substr("ประเทศไทย中华Việt Nam", 6u, 6u));
|
assert_eq!("ะเทศไท", "ประเทศไทย中华Việt Nam".substr(6u, 6u));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user