Skip to content

Commit 838191c

Browse files
committed
std: replace str::{starts,ends}_with with the method.
1 parent 248b6e3 commit 838191c

File tree

12 files changed

+40
-66
lines changed

12 files changed

+40
-66
lines changed

src/compiletest/compiletest.rc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,11 @@ pub fn is_test(config: &config, testfile: &Path) -> bool {
231231
let mut valid = false;
232232

233233
for valid_extensions.each |ext| {
234-
if str::ends_with(name, *ext) { valid = true; }
234+
if name.ends_with(*ext) { valid = true; }
235235
}
236236

237237
for invalid_prefixes.each |pre| {
238-
if str::starts_with(name, *pre) { valid = false; }
238+
if name.starts_with(*pre) { valid = false; }
239239
}
240240

241241
return valid;

src/compiletest/header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ fn iter_header(testfile: &Path, it: &fn(~str) -> bool) -> bool {
112112
// Assume that any directives will be found before the first
113113
// module or function. This doesn't seem to be an optimization
114114
// with a warm page cache. Maybe with a cold one.
115-
if str::starts_with(ln, "fn") || str::starts_with(ln, "mod") {
115+
if ln.starts_with("fn") || ln.starts_with("mod") {
116116
return false;
117117
} else { if !(it(ln)) { return false; } }
118118
}

src/compiletest/procsrv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn target_env(lib_path: &str, prog: &str) -> ~[(~str,~str)] {
2828
if k == ~"PATH" { (~"PATH", v + ";" + lib_path + ";" + aux_path) }
2929
else { (k,v) }
3030
};
31-
if str::ends_with(prog, "rustc.exe") {
31+
if prog.ends_with("rustc.exe") {
3232
env.push((~"RUST_THREADS", ~"1"));
3333
}
3434
return env;

src/compiletest/runtest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError],
364364
if !found_flags[i] {
365365
debug!("prefix=%s ee.kind=%s ee.msg=%s line=%s",
366366
prefixes[i], ee.kind, ee.msg, line);
367-
if (str::starts_with(line, prefixes[i]) &&
367+
if (line.starts_with(prefixes[i]) &&
368368
line.contains(ee.kind) &&
369369
line.contains(ee.msg)) {
370370
found_flags[i] = true;

src/libextra/net_url.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ enum Input {
394394
// returns userinfo, host, port, and unparsed part, or an error
395395
fn get_authority(rawurl: &str) ->
396396
Result<(Option<UserInfo>, ~str, Option<~str>, ~str), ~str> {
397-
if !str::starts_with(rawurl, "//") {
397+
if !raw_url.starts_with("//") {
398398
// there is no authority.
399399
return Ok((None, ~"", None, rawurl.to_str()));
400400
}
@@ -579,7 +579,7 @@ fn get_path(rawurl: &str, authority: bool) ->
579579
}
580580

581581
if authority {
582-
if end != 0 && !str::starts_with(rawurl, "/") {
582+
if end != 0 && !rawurl.starts_with("/") {
583583
return Err(~"Non-empty path must begin with\
584584
'/' in presence of authority.");
585585
}
@@ -592,8 +592,8 @@ fn get_path(rawurl: &str, authority: bool) ->
592592
// returns the parsed query and the fragment, if present
593593
fn get_query_fragment(rawurl: &str) ->
594594
Result<(Query, Option<~str>), ~str> {
595-
if !str::starts_with(rawurl, "?") {
596-
if str::starts_with(rawurl, "#") {
595+
if !rawurl.starts_with("?") {
596+
if rawurl.starts_with("#") {
597597
let f = decode_component(rawurl.slice(
598598
1,
599599
rawurl.len()));

src/libextra/tempfile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ mod tests {
4242
fn test_mkdtemp() {
4343
let p = mkdtemp(&Path("."), "foobar").unwrap();
4444
os::remove_dir(&p);
45-
assert!(str::ends_with(p.to_str(), "foobar"));
45+
assert!(p.to_str().ends_with("foobar"));
4646
}
4747

4848
// Ideally these would be in core::os but then core would need

src/librustc/back/rpath.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ mod test {
240240
debug!("test_prefix_path: %s vs. %s",
241241
res.to_str(),
242242
d.to_str());
243-
assert!(str::ends_with(res.to_str(), d.to_str()));
243+
assert!(res.to_str().ends_with(d.to_str()));
244244
}
245245
246246
#[test]

src/librustc/middle/trans/debuginfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ fn get_cache(cx: @CrateContext) -> metadata_cache {
244244
}
245245

246246
fn get_file_path_and_dir(work_dir: &str, full_path: &str) -> (~str, ~str) {
247-
(if str::starts_with(full_path, work_dir) {
247+
(if full_path.starts_with(work_dir) {
248248
full_path.slice(work_dir.len() + 1u,
249249
full_path.len()).to_owned()
250250
} else {

src/librustdoc/desc_to_brief_pass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ fn first_sentence_(s: &str) -> ~str {
134134
str::to_owned(s.slice(0, idx - 1))
135135
}
136136
_ => {
137-
if str::ends_with(s, ".") {
137+
if s.ends_with(".") {
138138
str::to_owned(s)
139139
} else {
140140
str::to_owned(s)

src/librustdoc/sectionalize_pass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ fn sectionalize(desc: Option<~str>) -> (Option<~str>, ~[doc::Section]) {
153153
}
154154

155155
fn parse_header(line: ~str) -> Option<~str> {
156-
if str::starts_with(line, "# ") {
156+
if line.starts_with("# ") {
157157
Some(line.slice(2u, line.len()).to_owned())
158158
} else {
159159
None

src/libstd/io.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,7 +1979,7 @@ mod tests {
19791979
fn file_writer_bad_name() {
19801980
match io::file_writer(&Path("?/?"), []) {
19811981
result::Err(e) => {
1982-
assert!(str::starts_with(e, "error opening"));
1982+
assert!(e.starts_with("error opening"));
19831983
}
19841984
result::Ok(_) => fail!()
19851985
}
@@ -1989,7 +1989,7 @@ mod tests {
19891989
fn buffered_file_writer_bad_name() {
19901990
match io::buffered_file_writer(&Path("?/?")) {
19911991
result::Err(e) => {
1992-
assert!(str::starts_with(e, "error opening"));
1992+
assert!(e.starts_with("error opening"));
19931993
}
19941994
result::Ok(_) => fail!()
19951995
}

src/libstd/str.rs

Lines changed: 24 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -977,36 +977,6 @@ fn match_at<'a,'b>(haystack: &'a str, needle: &'b str, at: uint) -> bool {
977977
}
978978

979979

980-
/**
981-
* Returns true if one string starts with another
982-
*
983-
* # Arguments
984-
*
985-
* * haystack - The string to look in
986-
* * needle - The string to look for
987-
*/
988-
pub fn starts_with<'a,'b>(haystack: &'a str, needle: &'b str) -> bool {
989-
let (haystack_len, needle_len) = (haystack.len(), needle.len());
990-
if needle_len == 0u { true }
991-
else if needle_len > haystack_len { false }
992-
else { match_at(haystack, needle, 0u) }
993-
}
994-
995-
/**
996-
* Returns true if one string ends with another
997-
*
998-
* # Arguments
999-
*
1000-
* * haystack - The string to look in
1001-
* * needle - The string to look for
1002-
*/
1003-
pub fn ends_with<'a,'b>(haystack: &'a str, needle: &'b str) -> bool {
1004-
let (haystack_len, needle_len) = (haystack.len(), needle.len());
1005-
if needle_len == 0u { true }
1006-
else if needle_len > haystack_len { false }
1007-
else { match_at(haystack, needle, haystack_len - needle_len) }
1008-
}
1009-
1010980
/*
1011981
Section: String properties
1012982
*/
@@ -1600,7 +1570,7 @@ pub trait StrSlice<'self> {
16001570
fn slice(&self, begin: uint, end: uint) -> &'self str;
16011571
fn slice_from(&self, begin: uint) -> &'self str;
16021572
fn slice_to(&self, end: uint) -> &'self str;
1603-
fn starts_with<'a>(&self, needle: &'a str) -> bool;
1573+
fn starts_with(&self, needle: &str) -> bool;
16041574
fn substr(&self, begin: uint, n: uint) -> &'self str;
16051575
fn escape_default(&self) -> ~str;
16061576
fn escape_unicode(&self) -> ~str;
@@ -1770,12 +1740,6 @@ impl<'self> StrSlice<'self> for &'self str {
17701740
self.split_iter(char::is_whitespace).filter(|s| !s.is_empty())
17711741
}
17721742
1773-
1774-
/// Returns true if one string ends with another
1775-
#[inline]
1776-
fn ends_with(&self, needle: &str) -> bool {
1777-
ends_with(*self, needle)
1778-
}
17791743
/// Returns true if the string has length 0
17801744
#[inline]
17811745
fn is_empty(&self) -> bool { self.len() == 0 }
@@ -1831,11 +1795,21 @@ impl<'self> StrSlice<'self> for &'self str {
18311795
fn slice_to(&self, end: uint) -> &'self str {
18321796
self.slice(0, end)
18331797
}
1834-
/// Checks if `needle` is a prefix of the string.
1835-
#[inline]
1798+
/// Returns true if `needle` is a prefix of the string.
18361799
fn starts_with<'a>(&self, needle: &'a str) -> bool {
1837-
starts_with(*self, needle)
1800+
let (self_len, needle_len) = (self.len(), needle.len());
1801+
if needle_len == 0u { true }
1802+
else if needle_len > self_len { false }
1803+
else { match_at(*self, needle, 0u) }
18381804
}
1805+
/// Returns true if `needle` is a suffix of the string.
1806+
pub fn ends_with(&self, needle: &str) -> bool {
1807+
let (self_len, needle_len) = (self.len(), needle.len());
1808+
if needle_len == 0u { true }
1809+
else if needle_len > self_len { false }
1810+
else { match_at(*self, needle, self_len - needle_len) }
1811+
}
1812+
18391813
/**
18401814
* Take a substring of another.
18411815
*
@@ -2591,20 +2565,20 @@ mod tests {
25912565
25922566
#[test]
25932567
fn test_starts_with() {
2594-
assert!((starts_with("", "")));
2595-
assert!((starts_with("abc", "")));
2596-
assert!((starts_with("abc", "a")));
2597-
assert!((!starts_with("a", "abc")));
2598-
assert!((!starts_with("", "abc")));
2568+
assert!(("".starts_with("")));
2569+
assert!(("abc".starts_with("")));
2570+
assert!(("abc".starts_with("a")));
2571+
assert!((!"a".starts_with("abc")));
2572+
assert!((!"".starts_with("abc")));
25992573
}
26002574
26012575
#[test]
26022576
fn test_ends_with() {
2603-
assert!((ends_with("", "")));
2604-
assert!((ends_with("abc", "")));
2605-
assert!((ends_with("abc", "c")));
2606-
assert!((!ends_with("a", "abc")));
2607-
assert!((!ends_with("", "abc")));
2577+
assert!(("".ends_with("")));
2578+
assert!(("abc".ends_with("")));
2579+
assert!(("abc".ends_with("c")));
2580+
assert!((!"a".ends_with("abc")));
2581+
assert!((!"".ends_with("abc")));
26082582
}
26092583
26102584
#[test]

0 commit comments

Comments
 (0)