Skip to content

Commit 2e3cabc

Browse files
committed
---
yaml --- r: 14260 b: refs/heads/try c: c818674 h: refs/heads/master v: v3
1 parent fe9175c commit 2e3cabc

File tree

10 files changed

+61
-46
lines changed

10 files changed

+61
-46
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 748b63f63f4fb2ac8583900adb5a283990be276b
5+
refs/heads/try: c81867474a2cac8fcb646390ae5f3782dda45aae
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/comp/back/link.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,11 @@ fn link_binary(sess: session,
568568
// Converts a library file name into a cc -l argument
569569
fn unlib(config: @session::config, filename: str) -> str unsafe {
570570
let rmlib = fn@(filename: str) -> str {
571+
let found = str::find_bytes(filename, "lib");
571572
if config.os == session::os_macos ||
572573
(config.os == session::os_linux ||
573574
config.os == session::os_freebsd) &&
574-
str::find(filename, "lib") == 0 {
575+
option::is_some(found) && option::get(found) == 0u {
575576
ret str::unsafe::slice_bytes(filename, 3u,
576577
str::len_bytes(filename));
577578
} else { ret filename; }

branches/try/src/comp/driver/driver.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -269,28 +269,28 @@ fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: str,
269269
}
270270

271271
fn get_os(triple: str) -> option<session::os> {
272-
ret if str::find(triple, "win32") >= 0 ||
273-
str::find(triple, "mingw32") >= 0 {
272+
ret if str::contains(triple, "win32") ||
273+
str::contains(triple, "mingw32") {
274274
some(session::os_win32)
275-
} else if str::find(triple, "darwin") >= 0 {
275+
} else if str::contains(triple, "darwin") {
276276
some(session::os_macos)
277-
} else if str::find(triple, "linux") >= 0 {
277+
} else if str::contains(triple, "linux") {
278278
some(session::os_linux)
279-
} else if str::find(triple, "freebsd") >= 0 {
279+
} else if str::contains(triple, "freebsd") {
280280
some(session::os_freebsd)
281281
} else { none };
282282
}
283283

284284
fn get_arch(triple: str) -> option<session::arch> {
285-
ret if str::find(triple, "i386") >= 0 || str::find(triple, "i486") >= 0 ||
286-
str::find(triple, "i586") >= 0 ||
287-
str::find(triple, "i686") >= 0 ||
288-
str::find(triple, "i786") >= 0 {
285+
ret if str::contains(triple, "i386") || str::contains(triple, "i486") ||
286+
str::contains(triple, "i586") ||
287+
str::contains(triple, "i686") ||
288+
str::contains(triple, "i786") {
289289
some(session::arch_x86)
290-
} else if str::find(triple, "x86_64") >= 0 {
290+
} else if str::contains(triple, "x86_64") {
291291
some(session::arch_x86_64)
292-
} else if str::find(triple, "arm") >= 0 ||
293-
str::find(triple, "xscale") >= 0 {
292+
} else if str::contains(triple, "arm") ||
293+
str::contains(triple, "xscale") {
294294
some(session::arch_arm)
295295
} else { none };
296296
}

branches/try/src/compiletest/errors.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ fn load_errors(testfile: str) -> [expected_error] {
2424

2525
fn parse_expected(line_num: uint, line: str) -> [expected_error] unsafe {
2626
let error_tag = "//!";
27-
let idx0 = str::find(line, error_tag);
28-
if idx0 < 0 { ret []; }
29-
let idx = (idx0 as uint) + str::len_bytes(error_tag);
27+
let idx;
28+
alt str::find_bytes(line, error_tag) {
29+
option::none { ret []; }
30+
option::some(nn) { idx = (nn as uint) + str::len_bytes(error_tag); }
31+
}
3032

3133
// "//!^^^ kind msg" denotes a message expected
3234
// three lines above current line:

branches/try/src/compiletest/header.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,21 @@ fn parse_pp_exact(line: str, testfile: str) -> option<str> {
100100
}
101101

102102
fn parse_name_directive(line: str, directive: str) -> bool {
103-
str::find(line, directive) >= 0
103+
str::contains(line, directive)
104104
}
105105

106106
fn parse_name_value_directive(line: str,
107107
directive: str) -> option<str> unsafe {
108108
let keycolon = directive + ":";
109-
if str::find(line, keycolon) >= 0 {
110-
let colon = str::find(line, keycolon) as uint;
111-
let value =
112-
str::unsafe::slice_bytes(line, colon + str::len_bytes(keycolon),
113-
str::len_bytes(line));
114-
#debug("%s: %s", directive, value);
115-
option::some(value)
116-
} else { option::none }
109+
alt str::find_bytes(line, keycolon) {
110+
option::some(colon) {
111+
let value =
112+
str::unsafe::slice_bytes(line,
113+
colon + str::len_bytes(keycolon),
114+
str::len_bytes(line));
115+
#debug("%s: %s", directive, value);
116+
option::some(value)
117+
}
118+
option::none { option::none }
119+
}
117120
}

branches/try/src/compiletest/runtest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ fn check_error_patterns(props: test_props,
199199
let next_err_idx = 0u;
200200
let next_err_pat = props.error_patterns[next_err_idx];
201201
for line: str in str::split_byte(procres.stderr, '\n' as u8) {
202-
if str::find(line, next_err_pat) > 0 {
202+
if str::contains(line, next_err_pat) {
203203
#debug("found error pattern %s", next_err_pat);
204204
next_err_idx += 1u;
205205
if next_err_idx == vec::len(props.error_patterns) {

branches/try/src/fuzzer/fuzzer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn write_file(filename: str, content: str) {
1616
}
1717

1818
fn contains(haystack: str, needle: str) -> bool {
19-
str::find(haystack, needle) != -1
19+
str::contains(haystack, needle)
2020
}
2121

2222
fn find_rust_files(&files: [str], path: str) {

branches/try/src/libcore/str.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ export
6969
// Searching
7070
index,
7171
rindex,
72-
find,
72+
//find,
73+
find_bytes,
74+
find_chars,
7375
contains,
7476
starts_with,
7577
ends_with,
@@ -663,9 +665,10 @@ fn replace(s: str, from: str, to: str) : is_not_empty(from) -> str unsafe {
663665
unsafe::slice_bytes(s, len_bytes(from), len_bytes(s)),
664666
from, to);
665667
} else {
666-
let idx = find(s, from);
667-
if idx == -1 {
668-
ret s;
668+
let idx;
669+
alt find_bytes(s, from) {
670+
option::some(x) { idx = x; }
671+
option::none { ret s; }
669672
}
670673
let before = unsafe::slice_bytes(s, 0u, idx as uint);
671674
let after = unsafe::slice_bytes(s, idx as uint + len_bytes(from),
@@ -916,9 +919,16 @@ fn find(haystack: str, needle: str) -> int {
916919
// FIXME: rename find_chars -> find,
917920
// find -> find_bytes
918921
fn find_chars(hay: str, pin: str) -> option<uint> {
922+
alt find_bytes(hay, pin) {
923+
option::none { ret option::none; }
924+
option::some(nn) { ret option::some(b2c_pos(hay, nn)); }
925+
}
926+
}
927+
928+
fn find_bytes(hay: str, pin: str) -> option<uint> {
919929
alt find(hay, pin) {
920930
-1 { ret option::none; }
921-
n { ret option::some(b2c_pos(hay, n as uint)); }
931+
nn { ret option::some(nn as uint); }
922932
}
923933
}
924934

@@ -952,7 +962,7 @@ haystack - The string to look in
952962
needle - The string to look for
953963
*/
954964
fn contains(haystack: str, needle: str) -> bool {
955-
0 <= find(haystack, needle)
965+
option::is_some(find_bytes(haystack, needle))
956966
}
957967

958968
/*
@@ -1730,7 +1740,7 @@ mod tests {
17301740
}
17311741

17321742
#[test]
1733-
fn test_find() {
1743+
fn test_find_bytes() {
17341744
fn t(haystack: str, needle: str, i: int) {
17351745
let j: int = find(haystack, needle);
17361746
log(debug, "searched for " + needle);
@@ -1743,12 +1753,11 @@ mod tests {
17431753
t("this is a simple", "simple", 10);
17441754
t("this", "simple", -1);
17451755

1746-
// FIXME: return option<char> position instead
17471756
let data = "ประเทศไทย中华Việt Nam";
1748-
assert (find(data, "ประเ") == 0);
1749-
assert (find(data, "ะเ") == 6); // byte position
1750-
assert (find(data, "中华") == 27); // byte position
1751-
assert (find(data, "ไท华") == -1);
1757+
assert (find_bytes(data, "ประเ") == option::some( 0u));
1758+
assert (find_bytes(data, "ะเ") == option::some( 6u));
1759+
assert (find_bytes(data, "中华") == option::some(27u));
1760+
assert (find_bytes(data, "ไท华") == option::none);
17521761
}
17531762

17541763
#[test]

branches/try/src/libstd/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ fn filter_tests(opts: test_opts,
258258

259259
fn filter_fn(test: test_desc, filter_str: str) ->
260260
option<test_desc> {
261-
if str::find(test.name, filter_str) >= 0 {
261+
if str::contains(test.name, filter_str) {
262262
ret option::some(test);
263263
} else { ret option::none; }
264264
}

branches/try/src/rustdoc/markdown_pass.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ fn should_write_modules_last() {
5656
fn d() { }"
5757
);
5858

59-
let idx_a = str::find(markdown, "# Module `a`");
60-
let idx_b = str::find(markdown, "## Function `b`");
61-
let idx_c = str::find(markdown, "# Module `c`");
62-
let idx_d = str::find(markdown, "## Function `d`");
59+
let idx_a = option::get(str::find_bytes(markdown, "# Module `a`"));
60+
let idx_b = option::get(str::find_bytes(markdown, "## Function `b`"));
61+
let idx_c = option::get(str::find_bytes(markdown, "# Module `c`"));
62+
let idx_d = option::get(str::find_bytes(markdown, "## Function `d`"));
6363

6464
assert idx_b < idx_d;
6565
assert idx_d < idx_a;
@@ -854,4 +854,4 @@ mod test {
854854
let markdown = render("mod morp { }");
855855
assert str::contains(markdown, "Module `morp`\n\n");
856856
}
857-
}
857+
}

0 commit comments

Comments
 (0)