]> git.lizzy.rs Git - rust.git/commitdiff
std: replace str::substr with the method.
authorHuon Wilson <dbau.pp+github@gmail.com>
Mon, 10 Jun 2013 14:52:43 +0000 (00:52 +1000)
committerHuon Wilson <dbau.pp+github@gmail.com>
Mon, 10 Jun 2013 14:52:47 +0000 (00:52 +1000)
src/libextra/rope.rs
src/librustc/middle/resolve.rs
src/libstd/str.rs

index 24cbf1b3f4aa8356937a69dbef9a42847543abeb..f23a4433289e08806047b4e8084fdfa515f4b96f 100644 (file)
@@ -83,9 +83,9 @@ pub fn of_str(str: @~str) -> Rope {
  *
  * # Return value
  *
- * A rope representing the same string as `str::substr(str, byte_offset,
- * byte_len)`.  Depending on `byte_len`, this rope may be empty, flat or
- * complex.
+ * A rope representing the same string as `str.substr(byte_offset,
+ * byte_len)`.  Depending on `byte_len`, this rope may be empty, flat
+ * or complex.
  *
  * # Performance note
  *
index 0f3a6c7629f1bbb44722fb5d5340f254727783e5..96838c32266a844e4cda1ddf28eedfe25a9f6385 100644 (file)
@@ -2684,11 +2684,11 @@ pub fn resolve_module_path(@mut self,
                 match self.idents_to_str(module_path).rfind(':') {
                     Some(idx) => {
                         self.session.span_err(span, fmt!("unresolved import: could not find `%s` \
-                                                         in `%s`", str::substr(mpath, idx,
-                                                                               mpath.len() - idx),
+                                                         in `%s`", mpath.substr(idx,
+                                                                                mpath.len() - idx),
                                                          // idx - 1 to account for the extra
                                                          // colon
-                                                         str::substr(mpath, 0, idx - 1)));
+                                                         mpath.substr(0, idx - 1)));
                     },
                     None => (),
                 };
index 8967b447fd7f9971277d263a2d4f21f79b618be4..f525c34cc472100da783d2be11964172ca60e914 100644 (file)
@@ -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
 pub trait CharEq {
     /// Determine if the splitter should split at the given character
@@ -1854,7 +1844,7 @@ fn starts_with<'a>(&self, needle: &'a str) -> bool {
      */
     #[inline]
     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.
     #[inline]
@@ -2516,11 +2506,11 @@ fn test_find_str() {
     #[test]
     fn test_substr() {
         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", "el", 1);
-        assert_eq!("ะเทศไท", substr("ประเทศไทย中华Việt Nam", 6u, 6u));
+        assert_eq!("ะเทศไท", "ประเทศไทย中华Việt Nam".substr(6u, 6u));
     }
 
     #[test]