about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2013-06-11 21:46:40 +1000
committerHuon Wilson <dbau.pp+github@gmail.com>2013-06-12 12:21:04 +1000
commit9e60e2e297cb28ec4812fd3ed6124f44ff28c642 (patch)
treea02ba6fc7a9ddd8214a370a649d355a1b52d0c97 /src
parent12750c88931f707e63f2ec19396710bf70a39ae8 (diff)
downloadrust-9e60e2e297cb28ec4812fd3ed6124f44ff28c642.tar.gz
rust-9e60e2e297cb28ec4812fd3ed6124f44ff28c642.zip
std: convert str::replace to a method.
Diffstat (limited to 'src')
-rw-r--r--src/compiletest/runtest.rs6
-rw-r--r--src/libextra/rope.rs1
-rw-r--r--src/libextra/terminfo/searcher.rs2
-rw-r--r--src/librustc/driver/driver.rs3
-rw-r--r--src/librustc/middle/lint.rs3
-rw-r--r--src/librustc/middle/trans/build.rs4
-rw-r--r--src/librustc/rustc.rc2
-rw-r--r--src/librustdoc/desc_to_brief_pass.rs2
-rw-r--r--src/librustdoc/escape_pass.rs2
-rw-r--r--src/librustdoc/markdown_index_pass.rs36
-rw-r--r--src/librustdoc/markdown_pass.rs2
-rw-r--r--src/librustpkg/package_path.rs2
-rw-r--r--src/libstd/str.rs66
13 files changed, 64 insertions, 67 deletions
diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs
index 6b4f1420c56..c9208478128 100644
--- a/src/compiletest/runtest.rs
+++ b/src/compiletest/runtest.rs
@@ -171,8 +171,8 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
     if props.pp_exact.is_some() {
         // Now we have to care about line endings
         let cr = ~"\r";
-        actual = str::replace(actual, cr, "");
-        expected = str::replace(expected, cr, "");
+        actual = actual.replace(cr, "");
+        expected = expected.replace(cr, "");
     }
 
     compare_source(expected, actual);
@@ -238,7 +238,7 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) {
     // do not optimize debuginfo tests
     let mut config = match config.rustcflags {
         Some(ref flags) => config {
-            rustcflags: Some(str::replace(*flags, "-O", "")),
+            rustcflags: Some(flags.replace("-O", "")),
             .. copy *config
         },
         None => copy *config
diff --git a/src/libextra/rope.rs b/src/libextra/rope.rs
index 0856c256c5b..099b257380b 100644
--- a/src/libextra/rope.rs
+++ b/src/libextra/rope.rs
@@ -564,7 +564,6 @@ pub mod node {
     use rope::node;
 
     use core::cast;
-    use core::str;
     use core::uint;
     use core::vec;
 
diff --git a/src/libextra/terminfo/searcher.rs b/src/libextra/terminfo/searcher.rs
index 48a3e1e9c69..1ef410252ab 100644
--- a/src/libextra/terminfo/searcher.rs
+++ b/src/libextra/terminfo/searcher.rs
@@ -12,7 +12,7 @@
 /// Does not support hashed database, only filesystem!
 
 use core::prelude::*;
-use core::{os};
+use core::{os, str};
 use core::os::getenv;
 use core::io::{file_reader, Reader};
 use core::iterator::IteratorUtil;
diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs
index 7a631b5fc68..4b7ab6fdfc1 100644
--- a/src/librustc/driver/driver.rs
+++ b/src/librustc/driver/driver.rs
@@ -29,7 +29,6 @@ use core::hashmap::HashMap;
 use core::int;
 use core::io;
 use core::os;
-use core::str;
 use core::vec;
 use extra::getopts::groups::{optopt, optmulti, optflag, optflagopt};
 use extra::getopts::{opt_present};
@@ -595,7 +594,7 @@ pub fn build_session_options(binary: @~str,
         let flags = vec::append(getopts::opt_strs(matches, level_short),
                                 getopts::opt_strs(matches, level_name));
         for flags.each |lint_name| {
-            let lint_name = str::replace(*lint_name, "-", "_");
+            let lint_name = lint_name.replace("-", "_");
             match lint_dict.find(&lint_name) {
               None => {
                 early_error(demitter, fmt!("unknown %s flag: %s",
diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs
index 007970067b3..733453be359 100644
--- a/src/librustc/middle/lint.rs
+++ b/src/librustc/middle/lint.rs
@@ -23,7 +23,6 @@ use core::i16;
 use core::i32;
 use core::i64;
 use core::i8;
-use core::str;
 use core::u16;
 use core::u32;
 use core::u64;
@@ -375,7 +374,7 @@ impl Context {
                 fmt!("%s [-%c %s%s]", msg, match level {
                         warn => 'W', deny => 'D', forbid => 'F',
                         allow => fail!()
-                    }, str::replace(self.lint_to_str(lint), "_", "-"),
+                    }, self.lint_to_str(lint).replace("_", "-"),
                     if src == Default { " (default)" } else { "" })
             },
             Node(src) => {
diff --git a/src/librustc/middle/trans/build.rs b/src/librustc/middle/trans/build.rs
index 25aa59b852d..af108451810 100644
--- a/src/librustc/middle/trans/build.rs
+++ b/src/librustc/middle/trans/build.rs
@@ -885,9 +885,9 @@ pub fn add_comment(bcx: block, text: &str) {
     unsafe {
         let ccx = bcx.ccx();
         if ccx.sess.asm_comments() {
-            let sanitized = str::replace(text, "$", "");
+            let sanitized = text.replace("$", "");
             let comment_text = ~"# " +
-                str::replace(sanitized, "\n", "\n\t# ");
+                sanitized.replace("\n", "\n\t# ");
             let asm = str::as_c_str(comment_text, |c| {
                 str::as_c_str("", |e| {
                     count_insn(bcx, "inlineasm");
diff --git a/src/librustc/rustc.rc b/src/librustc/rustc.rc
index adb0f43e2d7..ff19893daad 100644
--- a/src/librustc/rustc.rc
+++ b/src/librustc/rustc.rc
@@ -209,7 +209,7 @@ Available lint options:
     io::println(fmt!("    %s  %7.7s  %s\n",
                      padded(max_key, "----"), "-------", "-------"));
     for lint_dict.each |k, v| {
-        let k = str::replace(*k, "_", "-");
+        let k = k.replace("_", "-");
         io::println(fmt!("    %s  %7.7s  %s",
                          padded(max_key, k),
                          match v.default {
diff --git a/src/librustdoc/desc_to_brief_pass.rs b/src/librustdoc/desc_to_brief_pass.rs
index 5fec0882a0a..c116ccd6986 100644
--- a/src/librustdoc/desc_to_brief_pass.rs
+++ b/src/librustdoc/desc_to_brief_pass.rs
@@ -108,7 +108,7 @@ fn first_sentence(s: ~str) -> Option<~str> {
     let paras = paragraphs(s);
     if !paras.is_empty() {
         let first_para = paras.head();
-        Some(str::replace(first_sentence_(*first_para), "\n", " "))
+        Some(first_sentence_(*first_para).replace("\n", " "))
     } else {
         None
     }
diff --git a/src/librustdoc/escape_pass.rs b/src/librustdoc/escape_pass.rs
index 045e916b110..ef07bdfca16 100644
--- a/src/librustdoc/escape_pass.rs
+++ b/src/librustdoc/escape_pass.rs
@@ -20,7 +20,7 @@ pub fn mk_pass() -> Pass {
 }
 
 fn escape(s: &str) -> ~str {
-    str::replace(s, "\\", "\\\\")
+    s.replace("\\", "\\\\")
 }
 
 #[test]
diff --git a/src/librustdoc/markdown_index_pass.rs b/src/librustdoc/markdown_index_pass.rs
index 36eb5e77ad6..e7def3ebb9b 100644
--- a/src/librustdoc/markdown_index_pass.rs
+++ b/src/librustdoc/markdown_index_pass.rs
@@ -128,24 +128,24 @@ pub fn pandoc_header_id(header: &str) -> ~str {
     return header;
 
     fn remove_formatting(s: &str) -> ~str {
-        str::replace(s, "`", "")
+        s.replace("`", "")
     }
     fn remove_punctuation(s: &str) -> ~str {
-        let s = str::replace(s, "<", "");
-        let s = str::replace(s, ">", "");
-        let s = str::replace(s, "[", "");
-        let s = str::replace(s, "]", "");
-        let s = str::replace(s, "(", "");
-        let s = str::replace(s, ")", "");
-        let s = str::replace(s, "@~", "");
-        let s = str::replace(s, "~", "");
-        let s = str::replace(s, "/", "");
-        let s = str::replace(s, ":", "");
-        let s = str::replace(s, "&", "");
-        let s = str::replace(s, "^", "");
-        let s = str::replace(s, ",", "");
-        let s = str::replace(s, "'", "");
-        let s = str::replace(s, "+", "");
+        let s = s.replace("<", "");
+        let s = s.replace(">", "");
+        let s = s.replace("[", "");
+        let s = s.replace("]", "");
+        let s = s.replace("(", "");
+        let s = s.replace(")", "");
+        let s = s.replace("@~", "");
+        let s = s.replace("~", "");
+        let s = s.replace("/", "");
+        let s = s.replace(":", "");
+        let s = s.replace("&", "");
+        let s = s.replace("^", "");
+        let s = s.replace(",", "");
+        let s = s.replace("'", "");
+        let s = s.replace("+", "");
         return s;
     }
     fn replace_with_hyphens(s: &str) -> ~str {
@@ -153,8 +153,8 @@ pub fn pandoc_header_id(header: &str) -> ~str {
         // XXX: Hacky implementation here that only covers
         // one or two spaces.
         let s = s.trim();
-        let s = str::replace(s, "  ", "-");
-        let s = str::replace(s, " ", "-");
+        let s = s.replace("  ", "-");
+        let s = s.replace(" ", "-");
         return s;
     }
     // FIXME: #4318 Instead of to_ascii and to_str_ascii, could use
diff --git a/src/librustdoc/markdown_pass.rs b/src/librustdoc/markdown_pass.rs
index b6917f527a1..6f480d18770 100644
--- a/src/librustdoc/markdown_pass.rs
+++ b/src/librustdoc/markdown_pass.rs
@@ -114,7 +114,7 @@ fn make_title(page: doc::Page) -> ~str {
         }
     };
     let title = markdown_pass::header_text(item);
-    let title = str::replace(title, "`", "");
+    let title = title.replace("`", "");
     return title;
 }
 
diff --git a/src/librustpkg/package_path.rs b/src/librustpkg/package_path.rs
index 98ff2751545..0216b032a6d 100644
--- a/src/librustpkg/package_path.rs
+++ b/src/librustpkg/package_path.rs
@@ -32,7 +32,7 @@ pub fn normalize(p_: RemotePath) -> LocalPath {
     match p.filestem() {
         None => LocalPath(p),
         Some(st) => {
-            let replaced = str::replace(st, "-", "_");
+            let replaced = st.replace("-", "_");
             if replaced != st {
                 LocalPath(p.with_filestem(replaced))
             }
diff --git a/src/libstd/str.rs b/src/libstd/str.rs
index fdcca339f9b..0891f177433 100644
--- a/src/libstd/str.rs
+++ b/src/libstd/str.rs
@@ -581,30 +581,6 @@ pub fn each_split_within<'a>(ss: &'a str,
     return cont;
 }
 
-/**
- * Replace all occurrences of one string with another
- *
- * # Arguments
- *
- * * s - The string containing substrings to replace
- * * from - The string to replace
- * * to - The replacement string
- *
- * # Return value
- *
- * The original string with all occurances of `from` replaced with `to`
- */
-pub fn replace(s: &str, from: &str, to: &str) -> ~str {
-    let mut (result, last_end) = (~"", 0);
-    for s.matches_index_iter(from).advance |(start, end)| {
-        result.push_str(unsafe{raw::slice_bytes(s, last_end, start)});
-        result.push_str(to);
-        last_end = end;
-    }
-    result.push_str(unsafe{raw::slice_bytes(s, last_end, s.len())});
-    result
-}
-
 /*
 Section: Comparing strings
 */
@@ -1349,6 +1325,7 @@ pub trait StrSlice<'self> {
     fn trim_chars(&self, chars_to_trim: &[char]) -> &'self str;
     fn trim_left_chars(&self, chars_to_trim: &[char]) -> &'self str;
     fn trim_right_chars(&self, chars_to_trim: &[char]) -> &'self str;
+    fn replace(&self, from: &str, to: &str) -> ~str;
     fn to_owned(&self) -> ~str;
     fn to_managed(&self) -> @str;
     fn is_char_boundary(&self, index: uint) -> bool;
@@ -1694,6 +1671,29 @@ impl<'self> StrSlice<'self> for &'self str {
         }
     }
 
+    /**
+     * Replace all occurrences of one string with another
+     *
+     * # Arguments
+     *
+     * * from - The string to replace
+     * * to - The replacement string
+     *
+     * # Return value
+     *
+     * The original string with all occurances of `from` replaced with `to`
+     */
+    pub fn replace(&self, from: &str, to: &str) -> ~str {
+        let mut (result, last_end) = (~"", 0);
+        for self.matches_index_iter(from).advance |(start, end)| {
+            result.push_str(unsafe{raw::slice_bytes(*self, last_end, start)});
+            result.push_str(to);
+            last_end = end;
+        }
+        result.push_str(unsafe{raw::slice_bytes(*self, last_end, self.len())});
+        result
+    }
+
     /// Copy a slice into a new unique str
     #[inline]
     fn to_owned(&self) -> ~str {
@@ -2592,13 +2592,13 @@ mod tests {
     #[test]
     fn test_replace() {
         let a = "a";
-        assert_eq!(replace("", a, "b"), ~"");
-        assert_eq!(replace("a", a, "b"), ~"b");
-        assert_eq!(replace("ab", a, "b"), ~"bb");
+        assert_eq!("".replace(a, "b"), ~"");
+        assert_eq!("a".replace(a, "b"), ~"b");
+        assert_eq!("ab".replace(a, "b"), ~"bb");
         let test = "test";
-        assert!(replace(" test test ", test, "toast") ==
+        assert!(" test test ".replace(test, "toast") ==
             ~" toast toast ");
-        assert_eq!(replace(" test test ", test, ""), ~"   ");
+        assert_eq!(" test test ".replace(test, ""), ~"   ");
     }
 
     #[test]
@@ -2608,7 +2608,7 @@ mod tests {
 
         let a = ~"ประเ";
         let A = ~"دولة الكويتทศไทย中华";
-        assert_eq!(replace(data, a, repl), A);
+        assert_eq!(data.replace(a, repl), A);
     }
 
     #[test]
@@ -2618,7 +2618,7 @@ mod tests {
 
         let b = ~"ะเ";
         let B = ~"ปรدولة الكويتทศไทย中华";
-        assert_eq!(replace(data, b,   repl), B);
+        assert_eq!(data.replace(b,   repl), B);
     }
 
     #[test]
@@ -2628,7 +2628,7 @@ mod tests {
 
         let c = ~"中华";
         let C = ~"ประเทศไทยدولة الكويت";
-        assert_eq!(replace(data, c, repl), C);
+        assert_eq!(data.replace(c, repl), C);
     }
 
     #[test]
@@ -2637,7 +2637,7 @@ mod tests {
         let repl = ~"دولة الكويت";
 
         let d = ~"ไท华";
-        assert_eq!(replace(data, d, repl), data);
+        assert_eq!(data.replace(d, repl), data);
     }
 
     #[test]