Skip to content

Commit ea0bb06

Browse files
committed
---
yaml --- r: 14220 b: refs/heads/try c: e0af23b h: refs/heads/master v: v3
1 parent bda27b9 commit ea0bb06

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
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: 50360873f8f7abbe7232cdd8f89d5ce691711acc
5+
refs/heads/try: e0af23b664a1307fe376f2638bb7a69f04e2ac1c
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/fuzzer/fuzzer.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,9 @@ fn check_variants_T<T: copy>(
283283
}
284284
}
285285

286-
fn last_part(filename: str) -> str unsafe {
287-
let ix = str::rindex_byte(filename, 47u8 /* '/' */);
288-
assert ix >= 0;
289-
str::unsafe::slice_bytes(filename, ix as uint + 1u, str::byte_len(filename) - 3u)
286+
fn last_part(filename: str) -> str {
287+
let ix = option::get(str::rindex(filename, '/'));
288+
str::slice(filename, ix + 1u, str::char_len(filename) - 3u)
290289
}
291290

292291
enum happiness { passed, cleanly_rejected(str), known_bug(str), failed(str), }

branches/try/src/libstd/fs.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ A path or fragment of a filesystem path
3232
*/
3333
type path = str;
3434

35+
fn splitDirnameBasename (pp: path) -> {dirname: str, basename: str} {
36+
let ii;
37+
alt str::rindex(pp, os_fs::path_sep) {
38+
option::some(xx) { ii = xx; }
39+
option::none {
40+
alt str::rindex(pp, os_fs::alt_path_sep) {
41+
option::some(xx) { ii = xx; }
42+
option::none { ret {dirname: ".", basename: pp}; }
43+
}
44+
}
45+
}
46+
47+
ret {dirname: str::slice(pp, 0u, ii),
48+
basename: str::slice(pp, ii + 1u, str::char_len(pp))};
49+
}
50+
3551
/*
3652
Function: dirname
3753
@@ -43,13 +59,8 @@ The dirname of "/usr/share" will be "/usr", but the dirname of
4359
4460
If the path is not prefixed with a directory, then "." is returned.
4561
*/
46-
fn dirname(p: path) -> path unsafe {
47-
let i: int = str::rindex_byte(p, os_fs::path_sep as u8);
48-
if i == -1 {
49-
i = str::rindex_byte(p, os_fs::alt_path_sep as u8);
50-
if i == -1 { ret "."; }
51-
}
52-
ret str::unsafe::slice_bytes(p, 0u, i as uint);
62+
fn dirname(pp: path) -> path {
63+
ret splitDirnameBasename(pp).dirname;
5364
}
5465

5566
/*
@@ -63,18 +74,10 @@ path separators in the path then the returned path is identical to
6374
the provided path. If an empty path is provided or the path ends
6475
with a path separator then an empty path is returned.
6576
*/
66-
fn basename(p: path) -> path unsafe {
67-
let i: int = str::rindex_byte(p, os_fs::path_sep as u8);
68-
if i == -1 {
69-
i = str::rindex_byte(p, os_fs::alt_path_sep as u8);
70-
if i == -1 { ret p; }
71-
}
72-
let len = str::byte_len(p);
73-
if (i + 1) as uint >= len { ret p; }
74-
ret str::unsafe::slice_bytes(p, (i + 1) as uint, len);
77+
fn basename(pp: path) -> path {
78+
ret splitDirnameBasename(pp).basename;
7579
}
7680

77-
7881
// FIXME: Need some typestate to avoid bounds check when len(pre) == 0
7982
/*
8083
Function: connect

0 commit comments

Comments
 (0)