diff --git a/src/compiletest/compiletest.rc b/src/compiletest/compiletest.rc index 7a0622d059d..e832534b227 100644 --- a/src/compiletest/compiletest.rc +++ b/src/compiletest/compiletest.rc @@ -231,11 +231,11 @@ pub fn is_test(config: &config, testfile: &Path) -> bool { let mut valid = false; for valid_extensions.each |ext| { - if str::ends_with(name, *ext) { valid = true; } + if name.ends_with(*ext) { valid = true; } } for invalid_prefixes.each |pre| { - if str::starts_with(name, *pre) { valid = false; } + if name.starts_with(*pre) { valid = false; } } return valid; diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs index d8562d725a7..87f5f4bd3fa 100644 --- a/src/compiletest/header.rs +++ b/src/compiletest/header.rs @@ -112,7 +112,7 @@ fn iter_header(testfile: &Path, it: &fn(~str) -> bool) -> bool { // Assume that any directives will be found before the first // module or function. This doesn't seem to be an optimization // with a warm page cache. Maybe with a cold one. - if str::starts_with(ln, "fn") || str::starts_with(ln, "mod") { + if ln.starts_with("fn") || ln.starts_with("mod") { return false; } else { if !(it(ln)) { return false; } } } diff --git a/src/compiletest/procsrv.rs b/src/compiletest/procsrv.rs index f86ab2c9093..87188100f4c 100644 --- a/src/compiletest/procsrv.rs +++ b/src/compiletest/procsrv.rs @@ -28,7 +28,7 @@ fn target_env(lib_path: &str, prog: &str) -> ~[(~str,~str)] { if k == ~"PATH" { (~"PATH", v + ";" + lib_path + ";" + aux_path) } else { (k,v) } }; - if str::ends_with(prog, "rustc.exe") { + if prog.ends_with("rustc.exe") { env.push((~"RUST_THREADS", ~"1")); } return env; diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 16190f69549..7159e51e3b6 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -364,7 +364,7 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError], if !found_flags[i] { debug!("prefix=%s ee.kind=%s ee.msg=%s line=%s", prefixes[i], ee.kind, ee.msg, line); - if (str::starts_with(line, prefixes[i]) && + if (line.starts_with(prefixes[i]) && line.contains(ee.kind) && line.contains(ee.msg)) { found_flags[i] = true; diff --git a/src/libextra/net_url.rs b/src/libextra/net_url.rs index 46e76a7a399..c85a866a04a 100644 --- a/src/libextra/net_url.rs +++ b/src/libextra/net_url.rs @@ -394,7 +394,7 @@ enum Input { // returns userinfo, host, port, and unparsed part, or an error fn get_authority(rawurl: &str) -> Result<(Option, ~str, Option<~str>, ~str), ~str> { - if !str::starts_with(rawurl, "//") { + if !raw_url.starts_with("//") { // there is no authority. return Ok((None, ~"", None, rawurl.to_str())); } @@ -579,7 +579,7 @@ fn get_path(rawurl: &str, authority: bool) -> } if authority { - if end != 0 && !str::starts_with(rawurl, "/") { + if end != 0 && !rawurl.starts_with("/") { return Err(~"Non-empty path must begin with\ '/' in presence of authority."); } @@ -592,8 +592,8 @@ fn get_path(rawurl: &str, authority: bool) -> // returns the parsed query and the fragment, if present fn get_query_fragment(rawurl: &str) -> Result<(Query, Option<~str>), ~str> { - if !str::starts_with(rawurl, "?") { - if str::starts_with(rawurl, "#") { + if !rawurl.starts_with("?") { + if rawurl.starts_with("#") { let f = decode_component(rawurl.slice( 1, rawurl.len())); diff --git a/src/libextra/tempfile.rs b/src/libextra/tempfile.rs index 98c57838072..c239e65e2d9 100644 --- a/src/libextra/tempfile.rs +++ b/src/libextra/tempfile.rs @@ -42,7 +42,7 @@ mod tests { fn test_mkdtemp() { let p = mkdtemp(&Path("."), "foobar").unwrap(); os::remove_dir(&p); - assert!(str::ends_with(p.to_str(), "foobar")); + assert!(p.to_str().ends_with("foobar")); } // Ideally these would be in core::os but then core would need diff --git a/src/librustc/back/rpath.rs b/src/librustc/back/rpath.rs index a84cb2cdbe1..5e5e0067afa 100644 --- a/src/librustc/back/rpath.rs +++ b/src/librustc/back/rpath.rs @@ -240,7 +240,7 @@ fn test_prefix_rpath() { debug!("test_prefix_path: %s vs. %s", res.to_str(), d.to_str()); - assert!(str::ends_with(res.to_str(), d.to_str())); + assert!(res.to_str().ends_with(d.to_str())); } #[test] diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index bc863fb363f..ce93cad73b6 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -244,7 +244,7 @@ fn get_cache(cx: @CrateContext) -> metadata_cache { } fn get_file_path_and_dir(work_dir: &str, full_path: &str) -> (~str, ~str) { - (if str::starts_with(full_path, work_dir) { + (if full_path.starts_with(work_dir) { full_path.slice(work_dir.len() + 1u, full_path.len()).to_owned() } else { diff --git a/src/librustdoc/desc_to_brief_pass.rs b/src/librustdoc/desc_to_brief_pass.rs index 0f4ade0551d..13ad47e34b8 100644 --- a/src/librustdoc/desc_to_brief_pass.rs +++ b/src/librustdoc/desc_to_brief_pass.rs @@ -134,7 +134,7 @@ fn first_sentence_(s: &str) -> ~str { str::to_owned(s.slice(0, idx - 1)) } _ => { - if str::ends_with(s, ".") { + if s.ends_with(".") { str::to_owned(s) } else { str::to_owned(s) diff --git a/src/librustdoc/sectionalize_pass.rs b/src/librustdoc/sectionalize_pass.rs index ddc1b7dfe21..8716f823848 100644 --- a/src/librustdoc/sectionalize_pass.rs +++ b/src/librustdoc/sectionalize_pass.rs @@ -153,7 +153,7 @@ fn sectionalize(desc: Option<~str>) -> (Option<~str>, ~[doc::Section]) { } fn parse_header(line: ~str) -> Option<~str> { - if str::starts_with(line, "# ") { + if line.starts_with("# ") { Some(line.slice(2u, line.len()).to_owned()) } else { None diff --git a/src/libstd/io.rs b/src/libstd/io.rs index 7f3af79e27c..409882c5cfe 100644 --- a/src/libstd/io.rs +++ b/src/libstd/io.rs @@ -1979,7 +1979,7 @@ fn test_write_empty() { fn file_writer_bad_name() { match io::file_writer(&Path("?/?"), []) { result::Err(e) => { - assert!(str::starts_with(e, "error opening")); + assert!(e.starts_with("error opening")); } result::Ok(_) => fail!() } @@ -1989,7 +1989,7 @@ fn file_writer_bad_name() { fn buffered_file_writer_bad_name() { match io::buffered_file_writer(&Path("?/?")) { result::Err(e) => { - assert!(str::starts_with(e, "error opening")); + assert!(e.starts_with("error opening")); } result::Ok(_) => fail!() } diff --git a/src/libstd/str.rs b/src/libstd/str.rs index f525c34cc47..03169a167b3 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -977,36 +977,6 @@ fn match_at<'a,'b>(haystack: &'a str, needle: &'b str, at: uint) -> bool { } -/** - * Returns true if one string starts with another - * - * # Arguments - * - * * haystack - The string to look in - * * needle - The string to look for - */ -pub fn starts_with<'a,'b>(haystack: &'a str, needle: &'b str) -> bool { - let (haystack_len, needle_len) = (haystack.len(), needle.len()); - if needle_len == 0u { true } - else if needle_len > haystack_len { false } - else { match_at(haystack, needle, 0u) } -} - -/** - * Returns true if one string ends with another - * - * # Arguments - * - * * haystack - The string to look in - * * needle - The string to look for - */ -pub fn ends_with<'a,'b>(haystack: &'a str, needle: &'b str) -> bool { - let (haystack_len, needle_len) = (haystack.len(), needle.len()); - if needle_len == 0u { true } - else if needle_len > haystack_len { false } - else { match_at(haystack, needle, haystack_len - needle_len) } -} - /* Section: String properties */ @@ -1600,7 +1570,7 @@ fn split_options_iter(&self, sep: Sep, count: uint, allow_trailing_ fn slice(&self, begin: uint, end: uint) -> &'self str; fn slice_from(&self, begin: uint) -> &'self str; fn slice_to(&self, end: uint) -> &'self str; - fn starts_with<'a>(&self, needle: &'a str) -> bool; + fn starts_with(&self, needle: &str) -> bool; fn substr(&self, begin: uint, n: uint) -> &'self str; fn escape_default(&self) -> ~str; fn escape_unicode(&self) -> ~str; @@ -1770,12 +1740,6 @@ fn word_iter(&self) -> WordIterator<'self> { self.split_iter(char::is_whitespace).filter(|s| !s.is_empty()) } - - /// Returns true if one string ends with another - #[inline] - fn ends_with(&self, needle: &str) -> bool { - ends_with(*self, needle) - } /// Returns true if the string has length 0 #[inline] fn is_empty(&self) -> bool { self.len() == 0 } @@ -1831,11 +1795,21 @@ fn slice_from(&self, begin: uint) -> &'self str { fn slice_to(&self, end: uint) -> &'self str { self.slice(0, end) } - /// Checks if `needle` is a prefix of the string. - #[inline] + /// Returns true if `needle` is a prefix of the string. fn starts_with<'a>(&self, needle: &'a str) -> bool { - starts_with(*self, needle) + let (self_len, needle_len) = (self.len(), needle.len()); + if needle_len == 0u { true } + else if needle_len > self_len { false } + else { match_at(*self, needle, 0u) } } + /// Returns true if `needle` is a suffix of the string. + pub fn ends_with(&self, needle: &str) -> bool { + let (self_len, needle_len) = (self.len(), needle.len()); + if needle_len == 0u { true } + else if needle_len > self_len { false } + else { match_at(*self, needle, self_len - needle_len) } + } + /** * Take a substring of another. * @@ -2591,20 +2565,20 @@ fn half_a_million_letter_a() -> ~str { #[test] fn test_starts_with() { - assert!((starts_with("", ""))); - assert!((starts_with("abc", ""))); - assert!((starts_with("abc", "a"))); - assert!((!starts_with("a", "abc"))); - assert!((!starts_with("", "abc"))); + assert!(("".starts_with(""))); + assert!(("abc".starts_with(""))); + assert!(("abc".starts_with("a"))); + assert!((!"a".starts_with("abc"))); + assert!((!"".starts_with("abc"))); } #[test] fn test_ends_with() { - assert!((ends_with("", ""))); - assert!((ends_with("abc", ""))); - assert!((ends_with("abc", "c"))); - assert!((!ends_with("a", "abc"))); - assert!((!ends_with("", "abc"))); + assert!(("".ends_with(""))); + assert!(("abc".ends_with(""))); + assert!(("abc".ends_with("c"))); + assert!((!"a".ends_with("abc"))); + assert!((!"".ends_with("abc"))); } #[test]