std: remove str::contains in favour of the method
This commit is contained in:
parent
017450a611
commit
a64e886e3c
11
doc/rust.md
11
doc/rust.md
@ -802,20 +802,15 @@ Use declarations support a number of convenient shortcuts:
|
||||
An example of `use` declarations:
|
||||
|
||||
~~~~
|
||||
use std::float::sin;
|
||||
use std::str::{from_chars, contains};
|
||||
use std::float::{sin, pow};
|
||||
use std::option::Some;
|
||||
|
||||
fn main() {
|
||||
// Equivalent to 'info!(std::float::sin(1.0));'
|
||||
info!(sin(1.0));
|
||||
// Equivalent to 'info!(std::float::pow(std::float::sin(1.0), 2.0));'
|
||||
info!(pow(sin(1.0), 2.0));
|
||||
|
||||
// Equivalent to 'info!(std::option::Some(1.0));'
|
||||
info!(Some(1.0));
|
||||
|
||||
// Equivalent to
|
||||
// 'info!(std::str::contains(std::str::from_chars(&['f','o','o']), "oo"));'
|
||||
info!(contains(from_chars(&['f','o','o']), "oo"));
|
||||
}
|
||||
~~~~
|
||||
|
||||
|
@ -169,7 +169,7 @@ fn parse_pp_exact(line: &str, testfile: &Path) -> Option<Path> {
|
||||
}
|
||||
|
||||
fn parse_name_directive(line: &str, directive: &str) -> bool {
|
||||
str::contains(line, directive)
|
||||
line.contains(directive)
|
||||
}
|
||||
|
||||
fn parse_name_value_directive(line: &str,
|
||||
|
@ -309,7 +309,7 @@ fn check_error_patterns(props: &TestProps,
|
||||
let mut next_err_pat = &props.error_patterns[next_err_idx];
|
||||
let mut done = false;
|
||||
for ProcRes.stderr.line_iter().advance |line| {
|
||||
if str::contains(line, *next_err_pat) {
|
||||
if line.contains(*next_err_pat) {
|
||||
debug!("found error pattern %s", *next_err_pat);
|
||||
next_err_idx += 1u;
|
||||
if next_err_idx == props.error_patterns.len() {
|
||||
@ -365,8 +365,8 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError],
|
||||
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]) &&
|
||||
str::contains(line, ee.kind) &&
|
||||
str::contains(line, ee.msg)) {
|
||||
line.contains(ee.kind) &&
|
||||
line.contains(ee.msg)) {
|
||||
found_flags[i] = true;
|
||||
was_expected = true;
|
||||
break;
|
||||
@ -375,7 +375,7 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError],
|
||||
}
|
||||
|
||||
// ignore this msg which gets printed at the end
|
||||
if str::contains(line, "aborting due to") {
|
||||
if line.contains("aborting due to") {
|
||||
was_expected = true;
|
||||
}
|
||||
|
||||
|
@ -1597,8 +1597,8 @@ mod test {
|
||||
expected_req, actual_req);
|
||||
debug!("RESP: expected: '%s' actual: '%s'",
|
||||
expected_resp, actual_resp);
|
||||
assert!(str::contains(actual_req, expected_req));
|
||||
assert!(str::contains(actual_resp, expected_resp));
|
||||
assert!(actual_req.contains(expected_req));
|
||||
assert!(actual_resp.contains(expected_resp));
|
||||
}
|
||||
pub fn impl_gl_tcp_ipv4_get_peer_addr() {
|
||||
let hl_loop = &uv::global_loop::get();
|
||||
@ -1765,8 +1765,8 @@ mod test {
|
||||
expected_req, actual_req);
|
||||
debug!("RESP: expected: '%s' actual: '%s'",
|
||||
expected_resp, actual_resp);
|
||||
assert!(str::contains(actual_req, expected_req));
|
||||
assert!(str::contains(actual_resp, expected_resp));
|
||||
assert!(actual_req.contains(expected_req));
|
||||
assert!(actual_resp.contains(expected_resp));
|
||||
}
|
||||
|
||||
pub fn impl_tcp_socket_impl_reader_handles_eof() {
|
||||
|
@ -514,7 +514,7 @@ pub fn filter_tests(
|
||||
|
||||
fn filter_fn(test: TestDescAndFn, filter_str: &str) ->
|
||||
Option<TestDescAndFn> {
|
||||
if str::contains(test.desc.name.to_str(), filter_str) {
|
||||
if test.desc.name.to_str().contains(filter_str) {
|
||||
return option::Some(test);
|
||||
} else { return option::None; }
|
||||
}
|
||||
|
@ -1480,7 +1480,7 @@ mod test {
|
||||
|
||||
let server_kill_msg = copy (*client_data).server_kill_msg;
|
||||
let write_req = (*client_data).server_write_req;
|
||||
if str::contains(request_str, server_kill_msg) {
|
||||
if request_str.contains(server_kill_msg) {
|
||||
debug!(~"SERVER: client req contains kill_msg!");
|
||||
debug!(~"SERVER: sending response to client");
|
||||
read_stop(client_stream_ptr);
|
||||
@ -1753,8 +1753,8 @@ mod test {
|
||||
let msg_from_client = server_port.recv();
|
||||
let msg_from_server = client_port.recv();
|
||||
|
||||
assert!(str::contains(msg_from_client, kill_server_msg));
|
||||
assert!(str::contains(msg_from_server, server_resp_msg));
|
||||
assert!(msg_from_client.contains(kill_server_msg));
|
||||
assert!(msg_from_server.contains(server_resp_msg));
|
||||
}
|
||||
|
||||
// FIXME don't run on fbsd or linux 32 bit(#2064)
|
||||
|
@ -57,7 +57,7 @@ pub fn write_file(filename: &Path, content: &str) {
|
||||
}
|
||||
|
||||
pub fn contains(haystack: &str, needle: &str) -> bool {
|
||||
str::contains(haystack, needle)
|
||||
haystack.contains(needle)
|
||||
}
|
||||
|
||||
pub fn find_rust_files(files: &mut ~[Path], path: &Path) {
|
||||
|
@ -465,33 +465,33 @@ pub fn pretty_print_input(sess: Session, cfg: ast::crate_cfg, input: &input,
|
||||
}
|
||||
|
||||
pub fn get_os(triple: &str) -> Option<session::os> {
|
||||
if str::contains(triple, "win32") ||
|
||||
str::contains(triple, "mingw32") {
|
||||
if triple.contains("win32") ||
|
||||
triple.contains("mingw32") {
|
||||
Some(session::os_win32)
|
||||
} else if str::contains(triple, "darwin") {
|
||||
} else if triple.contains("darwin") {
|
||||
Some(session::os_macos)
|
||||
} else if str::contains(triple, "android") {
|
||||
} else if triple.contains("android") {
|
||||
Some(session::os_android)
|
||||
} else if str::contains(triple, "linux") {
|
||||
} else if triple.contains("linux") {
|
||||
Some(session::os_linux)
|
||||
} else if str::contains(triple, "freebsd") {
|
||||
} else if triple.contains("freebsd") {
|
||||
Some(session::os_freebsd)
|
||||
} else { None }
|
||||
}
|
||||
|
||||
pub fn get_arch(triple: &str) -> Option<abi::Architecture> {
|
||||
if str::contains(triple, "i386") ||
|
||||
str::contains(triple, "i486") ||
|
||||
str::contains(triple, "i586") ||
|
||||
str::contains(triple, "i686") ||
|
||||
str::contains(triple, "i786") {
|
||||
if triple.contains("i386") ||
|
||||
triple.contains("i486") ||
|
||||
triple.contains("i586") ||
|
||||
triple.contains("i686") ||
|
||||
triple.contains("i786") {
|
||||
Some(abi::X86)
|
||||
} else if str::contains(triple, "x86_64") {
|
||||
} else if triple.contains("x86_64") {
|
||||
Some(abi::X86_64)
|
||||
} else if str::contains(triple, "arm") ||
|
||||
str::contains(triple, "xscale") {
|
||||
} else if triple.contains("arm") ||
|
||||
triple.contains("xscale") {
|
||||
Some(abi::Arm)
|
||||
} else if str::contains(triple, "mips") {
|
||||
} else if triple.contains("mips") {
|
||||
Some(abi::Mips)
|
||||
} else { None }
|
||||
}
|
||||
|
@ -3099,7 +3099,7 @@ impl Resolver {
|
||||
let import_count = imports.len();
|
||||
if index != import_count {
|
||||
let sn = self.session.codemap.span_to_snippet(imports[index].span);
|
||||
if str::contains(sn, "::") {
|
||||
if sn.contains("::") {
|
||||
self.session.span_err(imports[index].span, "unresolved import");
|
||||
} else {
|
||||
let err = fmt!("unresolved import (maybe you meant `%s::*`?)",
|
||||
|
@ -607,13 +607,13 @@ mod test {
|
||||
#[test]
|
||||
fn write_markdown_should_write_mod_headers() {
|
||||
let markdown = render(~"mod moo { }");
|
||||
assert!(str::contains(markdown, "# Module `moo`"));
|
||||
assert!(markdown.contains("# Module `moo`"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_leave_blank_line_after_header() {
|
||||
let markdown = render(~"mod morp { }");
|
||||
assert!(str::contains(markdown, "Module `morp`\n\n"));
|
||||
assert!(markdown.contains("Module `morp`\n\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -669,10 +669,10 @@ mod test {
|
||||
let (page, markdown) = po.recv();
|
||||
match page {
|
||||
doc::CratePage(_) => {
|
||||
assert!(str::contains(markdown, "% Crate core"));
|
||||
assert!(markdown.contains("% Crate core"));
|
||||
}
|
||||
doc::ItemPage(_) => {
|
||||
assert!(str::contains(markdown, "% Module a"));
|
||||
assert!(markdown.contains("% Module a"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -681,7 +681,7 @@ mod test {
|
||||
#[test]
|
||||
fn should_write_full_path_to_mod() {
|
||||
let markdown = render(~"mod a { mod b { mod c { } } }");
|
||||
assert!(str::contains(markdown, "# Module `a::b::c`"));
|
||||
assert!(markdown.contains("# Module `a::b::c`"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -692,21 +692,20 @@ mod test {
|
||||
Body\"]\
|
||||
mod a {
|
||||
}");
|
||||
assert!(str::contains(markdown, "#### Header\n\nBody\n\n"));
|
||||
assert!(markdown.contains("#### Header\n\nBody\n\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_write_crate_description() {
|
||||
let markdown = render(~"#[doc = \"this is the crate\"];");
|
||||
assert!(str::contains(markdown, "this is the crate"));
|
||||
assert!(markdown.contains("this is the crate"));
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn should_write_index() {
|
||||
let markdown = render(~"mod a { } mod b { }");
|
||||
assert!(str::contains(
|
||||
markdown,
|
||||
assert!(markdown.contains(
|
||||
"\n\n* [Module `a`](#module-a)\n\
|
||||
* [Module `b`](#module-b)\n\n"
|
||||
));
|
||||
@ -715,20 +714,19 @@ mod test {
|
||||
#[test]
|
||||
fn should_write_index_brief() {
|
||||
let markdown = render(~"#[doc = \"test\"] mod a { }");
|
||||
assert!(str::contains(markdown, "(#module-a) - test\n"));
|
||||
assert!(markdown.contains("(#module-a) - test\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_not_write_index_if_no_entries() {
|
||||
let markdown = render(~"");
|
||||
assert!(!str::contains(markdown, "\n\n\n"));
|
||||
assert!(!markdown.contains("\n\n\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_write_index_for_foreign_mods() {
|
||||
let markdown = render(~"extern { fn a(); }");
|
||||
assert!(str::contains(
|
||||
markdown,
|
||||
assert!(markdown.contains(
|
||||
"\n\n* [Function `a`](#function-a)\n\n"
|
||||
));
|
||||
}
|
||||
@ -737,32 +735,32 @@ mod test {
|
||||
fn should_write_foreign_fns() {
|
||||
let markdown = render(
|
||||
~"extern { #[doc = \"test\"] fn a(); }");
|
||||
assert!(str::contains(markdown, "test"));
|
||||
assert!(markdown.contains("test"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_write_foreign_fn_headers() {
|
||||
let markdown = render(
|
||||
~"extern { #[doc = \"test\"] fn a(); }");
|
||||
assert!(str::contains(markdown, "## Function `a`"));
|
||||
assert!(markdown.contains("## Function `a`"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn write_markdown_should_write_function_header() {
|
||||
let markdown = render(~"fn func() { }");
|
||||
assert!(str::contains(markdown, "## Function `func`"));
|
||||
assert!(markdown.contains("## Function `func`"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_write_the_function_signature() {
|
||||
let markdown = render(~"#[doc = \"f\"] fn a() { }");
|
||||
assert!(str::contains(markdown, "\n fn a()\n"));
|
||||
assert!(markdown.contains("\n fn a()\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_insert_blank_line_after_fn_signature() {
|
||||
let markdown = render(~"#[doc = \"f\"] fn a() { }");
|
||||
assert!(str::contains(markdown, "fn a()\n\n"));
|
||||
assert!(markdown.contains("fn a()\n\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -783,19 +781,19 @@ mod test {
|
||||
]
|
||||
};
|
||||
let markdown = write_markdown_str(doc);
|
||||
assert!(str::contains(markdown, " line 1\n line 2"));
|
||||
assert!(markdown.contains(" line 1\n line 2"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_leave_blank_line_between_fn_header_and_sig() {
|
||||
let markdown = render(~"fn a() { }");
|
||||
assert!(str::contains(markdown, "Function `a`\n\n fn a()"));
|
||||
assert!(markdown.contains("Function `a`\n\n fn a()"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_write_const_header() {
|
||||
let markdown = render(~"static a: bool = true;");
|
||||
assert!(str::contains(markdown, "## Const `a`\n\n"));
|
||||
assert!(markdown.contains("## Const `a`\n\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -803,19 +801,19 @@ mod test {
|
||||
let markdown = render(
|
||||
~"#[doc = \"b\"]\
|
||||
static a: bool = true;");
|
||||
assert!(str::contains(markdown, "\n\nb\n\n"));
|
||||
assert!(markdown.contains("\n\nb\n\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_write_enum_header() {
|
||||
let markdown = render(~"enum a { b }");
|
||||
assert!(str::contains(markdown, "## Enum `a`\n\n"));
|
||||
assert!(markdown.contains("## Enum `a`\n\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_write_enum_description() {
|
||||
let markdown = render(~"#[doc = \"b\"] enum a { b }");
|
||||
assert!(str::contains(markdown, "\n\nb\n\n"));
|
||||
assert!(markdown.contains("\n\nb\n\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -824,8 +822,7 @@ mod test {
|
||||
~"enum a { \
|
||||
#[doc = \"test\"] b, \
|
||||
#[doc = \"test\"] c }");
|
||||
assert!(str::contains(
|
||||
markdown,
|
||||
assert!(markdown.contains(
|
||||
"\n\n#### Variants\n\
|
||||
\n\
|
||||
\n* `b` - test\
|
||||
@ -836,8 +833,7 @@ mod test {
|
||||
#[test]
|
||||
fn should_write_variant_list_without_descs() {
|
||||
let markdown = render(~"enum a { b, c }");
|
||||
assert!(str::contains(
|
||||
markdown,
|
||||
assert!(markdown.contains(
|
||||
"\n\n#### Variants\n\
|
||||
\n\
|
||||
\n* `b`\
|
||||
@ -849,8 +845,7 @@ mod test {
|
||||
fn should_write_variant_list_with_indent() {
|
||||
let markdown = render(
|
||||
~"enum a { #[doc = \"line 1\\n\\nline 2\"] b, c }");
|
||||
assert!(str::contains(
|
||||
markdown,
|
||||
assert!(markdown.contains(
|
||||
"\n\n#### Variants\n\
|
||||
\n\
|
||||
\n* `b` - line 1\
|
||||
@ -863,8 +858,7 @@ mod test {
|
||||
#[test]
|
||||
fn should_write_variant_list_with_signatures() {
|
||||
let markdown = render(~"enum a { b(int), #[doc = \"a\"] c(int) }");
|
||||
assert!(str::contains(
|
||||
markdown,
|
||||
assert!(markdown.contains(
|
||||
"\n\n#### Variants\n\
|
||||
\n\
|
||||
\n* `b(int)`\
|
||||
@ -875,43 +869,43 @@ mod test {
|
||||
#[test]
|
||||
fn should_write_trait_header() {
|
||||
let markdown = render(~"trait i { fn a(); }");
|
||||
assert!(str::contains(markdown, "## Trait `i`"));
|
||||
assert!(markdown.contains("## Trait `i`"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_write_trait_desc() {
|
||||
let markdown = render(~"#[doc = \"desc\"] trait i { fn a(); }");
|
||||
assert!(str::contains(markdown, "desc"));
|
||||
assert!(markdown.contains("desc"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_write_trait_method_header() {
|
||||
let markdown = render(~"trait i { fn a(); }");
|
||||
assert!(str::contains(markdown, "### Method `a`"));
|
||||
assert!(markdown.contains("### Method `a`"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_write_trait_method_signature() {
|
||||
let markdown = render(~"trait i { fn a(&self); }");
|
||||
assert!(str::contains(markdown, "\n fn a(&self)"));
|
||||
assert!(markdown.contains("\n fn a(&self)"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_write_impl_header() {
|
||||
let markdown = render(~"impl int { fn a() { } }");
|
||||
assert!(str::contains(markdown, "## Implementation for `int`"));
|
||||
assert!(markdown.contains("## Implementation for `int`"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_write_impl_header_with_bounds() {
|
||||
let markdown = render(~"impl <T> int<T> { }");
|
||||
assert!(str::contains(markdown, "## Implementation for `int<T>` where `<T>`"));
|
||||
assert!(markdown.contains("## Implementation for `int<T>` where `<T>`"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_write_impl_header_with_trait() {
|
||||
let markdown = render(~"impl j for int { fn a() { } }");
|
||||
assert!(str::contains(markdown,
|
||||
assert!(markdown.contains(
|
||||
"## Implementation of `j` for `int`"));
|
||||
}
|
||||
|
||||
@ -919,45 +913,45 @@ mod test {
|
||||
fn should_write_impl_desc() {
|
||||
let markdown = render(
|
||||
~"#[doc = \"desc\"] impl int { fn a() { } }");
|
||||
assert!(str::contains(markdown, "desc"));
|
||||
assert!(markdown.contains("desc"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_write_impl_method_header() {
|
||||
let markdown = render(
|
||||
~"impl int { fn a() { } }");
|
||||
assert!(str::contains(markdown, "### Method `a`"));
|
||||
assert!(markdown.contains("### Method `a`"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_write_impl_method_signature() {
|
||||
let markdown = render(
|
||||
~"impl int { fn a(&mut self) { } }");
|
||||
assert!(str::contains(markdown, "\n fn a(&mut self)"));
|
||||
assert!(markdown.contains("\n fn a(&mut self)"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_write_type_header() {
|
||||
let markdown = render(~"type t = int;");
|
||||
assert!(str::contains(markdown, "## Type `t`"));
|
||||
assert!(markdown.contains("## Type `t`"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_write_type_desc() {
|
||||
let markdown = render(
|
||||
~"#[doc = \"desc\"] type t = int;");
|
||||
assert!(str::contains(markdown, "\n\ndesc\n\n"));
|
||||
assert!(markdown.contains("\n\ndesc\n\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_write_type_signature() {
|
||||
let markdown = render(~"type t = int;");
|
||||
assert!(str::contains(markdown, "\n\n type t = int\n\n"));
|
||||
assert!(markdown.contains("\n\n type t = int\n\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_put_struct_header() {
|
||||
let markdown = render(~"struct S { field: () }");
|
||||
assert!(str::contains(markdown, "## Struct `S`\n\n"));
|
||||
assert!(markdown.contains("## Struct `S`\n\n"));
|
||||
}
|
||||
}
|
||||
|
@ -191,9 +191,7 @@ mod test {
|
||||
Body\"]\
|
||||
mod a {
|
||||
}");
|
||||
assert!(str::contains(
|
||||
doc.cratemod().mods()[0].item.sections[0].header,
|
||||
"Header"));
|
||||
assert!(doc.cratemod().mods()[0].item.sections[0].header.contains("Header"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -204,9 +202,7 @@ mod test {
|
||||
Body\"]\
|
||||
mod a {
|
||||
}");
|
||||
assert!(str::contains(
|
||||
doc.cratemod().mods()[0].item.sections[0].body,
|
||||
"Body"));
|
||||
assert!(doc.cratemod().mods()[0].item.sections[0].body.contains("Body"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -229,12 +225,8 @@ mod test {
|
||||
Body\"]\
|
||||
mod a {
|
||||
}");
|
||||
assert!(!str::contains(
|
||||
doc.cratemod().mods()[0].desc().get(),
|
||||
"Header"));
|
||||
assert!(!str::contains(
|
||||
doc.cratemod().mods()[0].desc().get(),
|
||||
"Body"));
|
||||
assert!(!doc.cratemod().mods()[0].desc().get().contains("Header"));
|
||||
assert!(!doc.cratemod().mods()[0].desc().get().contains("Body"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1167,30 +1167,6 @@ fn match_at<'a,'b>(haystack: &'a str, needle: &'b str, at: uint) -> bool {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if one string contains another
|
||||
*
|
||||
* # Arguments
|
||||
*
|
||||
* * haystack - The string to look in
|
||||
* * needle - The string to look for
|
||||
*/
|
||||
pub fn contains<'a,'b>(haystack: &'a str, needle: &'b str) -> bool {
|
||||
haystack.find_str(needle).is_some()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if a string contains a char.
|
||||
*
|
||||
* # Arguments
|
||||
*
|
||||
* * haystack - The string to look in
|
||||
* * needle - The char to look for
|
||||
*/
|
||||
pub fn contains_char(haystack: &str, needle: char) -> bool {
|
||||
haystack.find(needle).is_some()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if one string starts with another
|
||||
*
|
||||
@ -2019,15 +1995,27 @@ pub trait StrSlice<'self> {
|
||||
|
||||
/// Extension methods for strings
|
||||
impl<'self> StrSlice<'self> for &'self str {
|
||||
/// Returns true if one string contains another
|
||||
/**
|
||||
* Returns true if one string contains another
|
||||
*
|
||||
* # Arguments
|
||||
*
|
||||
* * needle - The string to look for
|
||||
*/
|
||||
#[inline]
|
||||
fn contains<'a>(&self, needle: &'a str) -> bool {
|
||||
contains(*self, needle)
|
||||
self.find_str(needle).is_some()
|
||||
}
|
||||
/// Returns true if a string contains a char
|
||||
/**
|
||||
* Returns true if a string contains a char.
|
||||
*
|
||||
* # Arguments
|
||||
*
|
||||
* * needle - The char to look for
|
||||
*/
|
||||
#[inline]
|
||||
fn contains_char(&self, needle: char) -> bool {
|
||||
contains_char(*self, needle)
|
||||
self.find(needle).is_some()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -3060,19 +3048,19 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_contains() {
|
||||
assert!(contains("abcde", "bcd"));
|
||||
assert!(contains("abcde", "abcd"));
|
||||
assert!(contains("abcde", "bcde"));
|
||||
assert!(contains("abcde", ""));
|
||||
assert!(contains("", ""));
|
||||
assert!(!contains("abcde", "def"));
|
||||
assert!(!contains("", "a"));
|
||||
assert!("abcde".contains("bcd"));
|
||||
assert!("abcde".contains("abcd"));
|
||||
assert!("abcde".contains("bcde"));
|
||||
assert!("abcde".contains(""));
|
||||
assert!("".contains(""));
|
||||
assert!(!"abcde".contains("def"));
|
||||
assert!(!"".contains("a"));
|
||||
|
||||
let data = ~"ประเทศไทย中华Việt Nam";
|
||||
assert!(contains(data, "ประเ"));
|
||||
assert!(contains(data, "ะเ"));
|
||||
assert!(contains(data, "中华"));
|
||||
assert!(!contains(data, "ไท华"));
|
||||
assert!(data.contains("ประเ"));
|
||||
assert!(data.contains("ะเ"));
|
||||
assert!(data.contains("中华"));
|
||||
assert!(!data.contains("ไท华"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user