Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
6d22a805
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6d22a805
编写于
8月 29, 2012
作者:
G
Graydon Hoare
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Replace core::path with contents of core::path2. Back to one path module.
上级
cb8ecd79
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
480 addition
and
985 deletion
+480
-985
src/libcore/core.rc
src/libcore/core.rc
+1
-2
src/libcore/core.rs
src/libcore/core.rs
+4
-4
src/libcore/os.rs
src/libcore/os.rs
+1
-1
src/libcore/path.rs
src/libcore/path.rs
+474
-401
src/libcore/path2.rs
src/libcore/path2.rs
+0
-577
未找到文件。
src/libcore/core.rc
浏览文件 @
6d22a805
...
...
@@ -54,7 +54,7 @@ export send_map;
export hash;
export cmp;
export num;
export path
, path2
;
export path;
export managed;
export flate;
...
...
@@ -254,7 +254,6 @@ mod libc;
mod os;
#[warn(non_camel_case_types)]
mod path;
mod path2;
#[warn(non_camel_case_types)]
mod rand;
#[warn(non_camel_case_types)]
...
...
src/libcore/core.rs
浏览文件 @
6d22a805
...
...
@@ -10,10 +10,10 @@
import
result
::{
Result
,
Ok
,
Err
};
import
Path
=
path
2
::
Path
;
import
GenericPath
=
path
2
::
GenericPath
;
import
WindowsPath
=
path
2
::
WindowsPath
;
import
PosixPath
=
path
2
::
PosixPath
;
import
Path
=
path
::
Path
;
import
GenericPath
=
path
::
GenericPath
;
import
WindowsPath
=
path
::
WindowsPath
;
import
PosixPath
=
path
::
PosixPath
;
import
tuple
::{
TupleOps
,
ExtendedTupleOps
};
import
str
::{
StrSlice
,
UniqueStr
};
...
...
src/libcore/os.rs
浏览文件 @
6d22a805
...
...
@@ -914,7 +914,7 @@ fn test_env_setenv() {
#[test]
fn
test
()
{
assert
(
!
path
::
path_is_absolute
(
~
"test-path"
)
);
assert
(
!
Path
(
"test-path"
)
.is_absolute
);
log
(
debug
,
~
"Current working directory: "
+
getcwd
()
.to_str
());
...
...
src/libcore/path.rs
浏览文件 @
6d22a805
此差异已折叠。
点击以展开。
src/libcore/path2.rs
已删除
100644 → 0
浏览文件 @
cb8ecd79
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)]
;
#[forbid(deprecated_pattern)]
;
struct
WindowsPath
{
host
:
Option
<~
str
>
;
device
:
Option
<~
str
>
;
is_absolute
:
bool
;
components
:
~
[
~
str
];
}
struct
PosixPath
{
is_absolute
:
bool
;
components
:
~
[
~
str
];
}
trait
GenericPath
{
static
pure
fn
from_str
((
&
str
))
->
self
;
pure
fn
dirname
()
->
~
str
;
pure
fn
filename
()
->
Option
<~
str
>
;
pure
fn
filestem
()
->
Option
<~
str
>
;
pure
fn
filetype
()
->
Option
<~
str
>
;
pure
fn
with_dirname
((
&
str
))
->
self
;
pure
fn
with_filename
((
&
str
))
->
self
;
pure
fn
with_filestem
((
&
str
))
->
self
;
pure
fn
with_filetype
((
&
str
))
->
self
;
pure
fn
push
((
&
str
))
->
self
;
pure
fn
push_rel
((
&
self
))
->
self
;
pure
fn
push_many
((
&
[
~
str
]))
->
self
;
pure
fn
pop
()
->
self
;
}
#[cfg(windows)]
type
Path
=
WindowsPath
;
#[cfg(windows)]
pure
fn
Path
(
s
:
&
str
)
->
Path
{
from_str
::
<
WindowsPath
>
(
s
)
}
#[cfg(unix)]
type
Path
=
PosixPath
;
#[cfg(unix)]
pure
fn
Path
(
s
:
&
str
)
->
Path
{
from_str
::
<
PosixPath
>
(
s
)
}
impl
PosixPath
:
ToStr
{
fn
to_str
()
->
~
str
{
let
mut
s
=
~
""
;
if
self
.is_absolute
{
s
+=
"/"
;
}
s
+
str
::
connect
(
self
.components
,
"/"
)
}
}
// FIXME (#3227): when default methods in traits are working, de-duplicate
// PosixPath and WindowsPath, most of their methods are common.
impl
PosixPath
:
GenericPath
{
static
pure
fn
from_str
(
s
:
&
str
)
->
PosixPath
{
let
mut
components
=
str
::
split_nonempty
(
s
,
|
c
|
c
==
'/'
);
let
is_absolute
=
(
s
.len
()
!=
0
&&
s
[
0
]
==
'/'
as
u8
);
return
PosixPath
{
is_absolute
:
is_absolute
,
components
:
normalize
(
components
)
}
}
pure
fn
dirname
()
->
~
str
{
unchecked
{
let
s
=
self
.dir_path
()
.to_str
();
if
s
.len
()
==
0
{
~
"."
}
else
{
s
}
}
}
pure
fn
filename
()
->
Option
<~
str
>
{
match
self
.components
.len
()
{
0
=>
None
,
n
=>
Some
(
copy
self
.components
[
n
-
1
])
}
}
pure
fn
filestem
()
->
Option
<~
str
>
{
match
self
.filename
()
{
None
=>
None
,
Some
(
ref
f
)
=>
{
match
str
::
rfind_char
(
*
f
,
'.'
)
{
Some
(
p
)
=>
Some
(
f
.slice
(
0
,
p
)),
None
=>
Some
(
copy
*
f
)
}
}
}
}
pure
fn
filetype
()
->
Option
<~
str
>
{
match
self
.filename
()
{
None
=>
None
,
Some
(
ref
f
)
=>
{
match
str
::
rfind_char
(
*
f
,
'.'
)
{
Some
(
p
)
if
p
+
1
<
f
.len
()
=>
Some
(
f
.slice
(
p
+
1
,
f
.len
())),
_
=>
None
}
}
}
}
pure
fn
with_dirname
(
d
:
&
str
)
->
PosixPath
{
let
dpath
=
from_str
::
<
PosixPath
>
(
d
);
match
self
.filename
()
{
Some
(
ref
f
)
=>
dpath
.push
(
*
f
),
None
=>
dpath
}
}
pure
fn
with_filename
(
f
:
&
str
)
->
PosixPath
{
unchecked
{
assert
!
str
::
any
(
f
,
|
c
|
windows
::
is_sep
(
c
as
u8
));
self
.dir_path
()
.push
(
f
)
}
}
pure
fn
with_filestem
(
s
:
&
str
)
->
PosixPath
{
match
self
.filetype
()
{
None
=>
self
.with_filename
(
s
),
Some
(
ref
t
)
=>
self
.with_filename
(
str
::
from_slice
(
s
)
+
"."
+
*
t
)
}
}
pure
fn
with_filetype
(
t
:
&
str
)
->
PosixPath
{
if
t
.len
()
==
0
{
match
self
.filestem
()
{
None
=>
copy
self
,
Some
(
s
)
=>
self
.with_filename
(
s
)
}
}
else
{
let
t
=
~
"."
+
str
::
from_slice
(
t
);
match
self
.filestem
()
{
None
=>
self
.with_filename
(
t
),
Some
(
ref
s
)
=>
self
.with_filename
(
*
s
+
t
)
}
}
}
pure
fn
dir_path
()
->
PosixPath
{
if
self
.components
.len
()
!=
0
{
self
.pop
()
}
else
{
copy
self
}
}
pure
fn
file_path
()
->
PosixPath
{
let
cs
=
match
self
.filename
()
{
None
=>
~
[],
Some
(
ref
f
)
=>
~
[
copy
*
f
]
};
return
PosixPath
{
is_absolute
:
false
,
components
:
cs
}
}
pure
fn
push_rel
(
other
:
&
PosixPath
)
->
PosixPath
{
assert
!
other
.is_absolute
;
self
.push_many
(
other
.components
)
}
pure
fn
push_many
(
cs
:
&
[
~
str
])
->
PosixPath
{
return
PosixPath
{
components
:
normalize
(
self
.components
+
cs
),
..
self
}
}
pure
fn
push
(
s
:
&
str
)
->
PosixPath
{
let
mut
cs
=
self
.components
;
unchecked
{
vec
::
push
(
cs
,
move
str
::
from_slice
(
s
));
}
cs
=
normalize
(
cs
);
return
PosixPath
{
components
:
move
cs
,
..
self
}
}
pure
fn
pop
()
->
PosixPath
{
let
mut
cs
=
copy
self
.components
;
if
cs
.len
()
!=
0
{
unchecked
{
vec
::
pop
(
cs
);
}
}
return
PosixPath
{
components
:
move
cs
,
..
self
}
}
}
impl
WindowsPath
:
ToStr
{
fn
to_str
()
->
~
str
{
let
mut
s
=
~
""
;
match
self
.host
{
Some
(
h
)
=>
{
s
+=
"
\\\\
"
;
s
+=
h
;
}
None
=>
{
}
}
match
self
.device
{
Some
(
d
)
=>
{
s
+=
d
;
s
+=
":"
;
}
None
=>
{
}
}
if
self
.is_absolute
{
s
+=
"
\\
"
;
}
s
+
str
::
connect
(
self
.components
,
"
\\
"
)
}
}
impl
WindowsPath
:
GenericPath
{
static
pure
fn
from_str
(
s
:
&
str
)
->
WindowsPath
{
let
host
;
let
device
;
let
rest
;
match
windows
::
extract_drive_prefix
(
s
)
{
Some
((
ref
d
,
ref
r
))
=>
{
host
=
None
;
device
=
Some
(
copy
*
d
);
rest
=
copy
*
r
;
}
None
=>
{
match
windows
::
extract_unc_prefix
(
s
)
{
Some
((
ref
h
,
ref
r
))
=>
{
host
=
Some
(
copy
*
h
);
device
=
None
;
rest
=
copy
*
r
;
}
None
=>
{
host
=
None
;
device
=
None
;
rest
=
str
::
from_slice
(
s
);
}
}
}
}
let
mut
components
=
str
::
split_nonempty
(
rest
,
|
c
|
windows
::
is_sep
(
c
as
u8
));
let
is_absolute
=
(
rest
.len
()
!=
0
&&
windows
::
is_sep
(
rest
[
0
]));
return
WindowsPath
{
host
:
host
,
device
:
device
,
is_absolute
:
is_absolute
,
components
:
normalize
(
components
)
}
}
pure
fn
dirname
()
->
~
str
{
unchecked
{
let
s
=
self
.dir_path
()
.to_str
();
if
s
.len
()
==
0
{
~
"."
}
else
{
s
}
}
}
pure
fn
filename
()
->
Option
<~
str
>
{
match
self
.components
.len
()
{
0
=>
None
,
n
=>
Some
(
copy
self
.components
[
n
-
1
])
}
}
pure
fn
filestem
()
->
Option
<~
str
>
{
match
self
.filename
()
{
None
=>
None
,
Some
(
ref
f
)
=>
{
match
str
::
rfind_char
(
*
f
,
'.'
)
{
Some
(
p
)
=>
Some
(
f
.slice
(
0
,
p
)),
None
=>
Some
(
copy
*
f
)
}
}
}
}
pure
fn
filetype
()
->
Option
<~
str
>
{
match
self
.filename
()
{
None
=>
None
,
Some
(
ref
f
)
=>
{
match
str
::
rfind_char
(
*
f
,
'.'
)
{
Some
(
p
)
if
p
+
1
<
f
.len
()
=>
Some
(
f
.slice
(
p
+
1
,
f
.len
())),
_
=>
None
}
}
}
}
pure
fn
with_dirname
(
d
:
&
str
)
->
WindowsPath
{
let
dpath
=
from_str
::
<
WindowsPath
>
(
d
);
match
self
.filename
()
{
Some
(
ref
f
)
=>
dpath
.push
(
*
f
),
None
=>
dpath
}
}
pure
fn
with_filename
(
f
:
&
str
)
->
WindowsPath
{
assert
!
str
::
any
(
f
,
|
c
|
windows
::
is_sep
(
c
as
u8
));
self
.dir_path
()
.push
(
f
)
}
pure
fn
with_filestem
(
s
:
&
str
)
->
WindowsPath
{
match
self
.filetype
()
{
None
=>
self
.with_filename
(
s
),
Some
(
ref
t
)
=>
self
.with_filename
(
str
::
from_slice
(
s
)
+
"."
+
*
t
)
}
}
pure
fn
with_filetype
(
t
:
&
str
)
->
WindowsPath
{
if
t
.len
()
==
0
{
match
self
.filestem
()
{
None
=>
copy
self
,
Some
(
s
)
=>
self
.with_filename
(
s
)
}
}
else
{
let
t
=
~
"."
+
str
::
from_slice
(
t
);
match
self
.filestem
()
{
None
=>
self
.with_filename
(
t
),
Some
(
ref
s
)
=>
self
.with_filename
(
*
s
+
t
)
}
}
}
pure
fn
dir_path
()
->
WindowsPath
{
if
self
.components
.len
()
!=
0
{
self
.pop
()
}
else
{
copy
self
}
}
pure
fn
file_path
()
->
WindowsPath
{
let
cs
=
match
self
.filename
()
{
None
=>
~
[],
Some
(
ref
f
)
=>
~
[
copy
*
f
]
};
return
WindowsPath
{
host
:
None
,
device
:
None
,
is_absolute
:
false
,
components
:
cs
}
}
pure
fn
push_rel
(
other
:
&
WindowsPath
)
->
WindowsPath
{
assert
!
other
.is_absolute
;
self
.push_many
(
other
.components
)
}
pure
fn
push_many
(
cs
:
&
[
~
str
])
->
WindowsPath
{
return
WindowsPath
{
components
:
normalize
(
self
.components
+
cs
),
..
self
}
}
pure
fn
push
(
s
:
&
str
)
->
WindowsPath
{
let
mut
cs
=
self
.components
;
unchecked
{
vec
::
push
(
cs
,
move
str
::
from_slice
(
s
));
}
cs
=
normalize
(
cs
);
return
WindowsPath
{
components
:
move
cs
,
..
self
}
}
pure
fn
pop
()
->
WindowsPath
{
let
mut
cs
=
copy
self
.components
;
if
cs
.len
()
!=
0
{
unchecked
{
vec
::
pop
(
cs
);
}
}
return
WindowsPath
{
components
:
move
cs
,
..
self
}
}
}
pure
fn
normalize
(
components
:
&
[
~
str
])
->
~
[
~
str
]
{
let
mut
cs
=
~
[];
unchecked
{
for
components
.each
|
c
|
{
unchecked
{
if
c
==
~
"."
&&
components
.len
()
>
1
{
again
;
}
if
c
==
~
".."
&&
cs
.len
()
!=
0
{
vec
::
pop
(
cs
);
again
;
}
vec
::
push
(
cs
,
copy
c
);
}
}
}
cs
}
mod
posix
{
#[test]
fn
test_posix_paths
()
{
fn
mk
(
s
:
&
str
)
->
PosixPath
{
from_str
::
<
PosixPath
>
(
s
)
}
fn
t
(
wp
:
&
PosixPath
,
s
:
&
str
)
{
let
ss
=
wp
.to_str
();
let
sss
=
str
::
from_slice
(
s
);
if
(
ss
!=
sss
)
{
debug!
(
"got %s"
,
ss
);
debug!
(
"expected %s"
,
sss
);
assert
ss
==
sss
;
}
}
t
(
&
(
mk
(
"hi"
)),
"hi"
);
t
(
&
(
mk
(
"/lib"
)),
"/lib"
);
t
(
&
(
mk
(
"hi/there"
)),
"hi/there"
);
t
(
&
(
mk
(
"hi/there.txt"
)),
"hi/there.txt"
);
t
(
&
(
mk
(
"hi/there.txt"
)),
"hi/there.txt"
);
t
(
&
(
mk
(
"hi/there.txt"
)
.with_filetype
(
""
)),
"hi/there"
);
t
(
&
(
mk
(
"/a/b/c/there.txt"
)
.with_dirname
(
"hi"
)),
"hi/there.txt"
);
t
(
&
(
mk
(
"hi/there.txt"
)
.with_dirname
(
"."
)),
"there.txt"
);
t
(
&
(
mk
(
"a/b/../c/././/../foo.txt/"
)),
"a/foo.txt"
);
t
(
&
(
mk
(
"a/b/c"
)
.push
(
".."
)),
"a/b"
);
t
(
&
(
mk
(
"there.txt"
)
.with_filetype
(
"o"
)),
"there.o"
);
t
(
&
(
mk
(
"hi/there.txt"
)
.with_filetype
(
"o"
)),
"hi/there.o"
);
t
(
&
(
mk
(
"hi/there.txt"
)
.with_filetype
(
"o"
)
.with_dirname
(
"/usr/lib"
)),
"/usr/lib/there.o"
);
t
(
&
(
mk
(
"hi/there.txt"
)
.with_filetype
(
"o"
)
.with_dirname
(
"/usr/lib/"
)),
"/usr/lib/there.o"
);
t
(
&
(
mk
(
"hi/there.txt"
)
.with_filetype
(
"o"
)
.with_dirname
(
"/usr//lib//"
)),
"/usr/lib/there.o"
);
t
(
&
(
mk
(
"/usr/bin/rust"
)
.push_many
([
~
"lib"
,
~
"thingy.so"
])
.with_filestem
(
"librustc"
)),
"/usr/bin/rust/lib/librustc.so"
);
}
}
// Various windows helpers, and tests for the impl.
mod
windows
{
#[inline(always)]
pure
fn
is_sep
(
u
:
u8
)
->
bool
{
u
==
'/'
as
u8
||
u
==
'\\'
as
u8
}
pure
fn
extract_unc_prefix
(
s
:
&
str
)
->
Option
<
(
~
str
,
~
str
)
>
{
if
(
s
.len
()
>
1
&&
s
[
0
]
==
'\\'
as
u8
&&
s
[
1
]
==
'\\'
as
u8
)
{
let
mut
i
=
2
;
while
i
<
s
.len
()
{
if
s
[
i
]
==
'\\'
as
u8
{
let
pre
=
s
.slice
(
2
,
i
);
let
rest
=
s
.slice
(
i
,
s
.len
());
return
Some
((
pre
,
rest
));
}
i
+=
1
;
}
}
None
}
pure
fn
extract_drive_prefix
(
s
:
&
str
)
->
Option
<
(
~
str
,
~
str
)
>
{
unchecked
{
if
(
s
.len
()
>
1
&&
libc
::
isalpha
(
s
[
0
]
as
libc
::
c_int
)
!=
0
&&
s
[
1
]
==
':'
as
u8
)
{
let
rest
=
if
s
.len
()
==
2
{
~
""
}
else
{
s
.slice
(
2
,
s
.len
())
};
return
Some
((
s
.slice
(
0
,
1
),
rest
));
}
None
}
}
#[test]
fn
test_extract_unc_prefixes
()
{
assert
extract_unc_prefix
(
"
\\\\
"
)
.is_none
();
assert
extract_unc_prefix
(
"
\\\\
hi"
)
.is_none
();
assert
extract_unc_prefix
(
"
\\\\
hi
\\
"
)
==
Some
((
~
"hi"
,
~
"
\\
"
));
assert
extract_unc_prefix
(
"
\\\\
hi
\\
there"
)
==
Some
((
~
"hi"
,
~
"
\\
there"
));
assert
extract_unc_prefix
(
"
\\\\
hi
\\
there
\\
friends.txt"
)
==
Some
((
~
"hi"
,
~
"
\\
there
\\
friends.txt"
));
}
#[test]
fn
test_extract_drive_prefixes
()
{
assert
extract_drive_prefix
(
"c"
)
.is_none
();
assert
extract_drive_prefix
(
"c:"
)
==
Some
((
~
"c"
,
~
""
));
assert
extract_drive_prefix
(
"d:"
)
==
Some
((
~
"d"
,
~
""
));
assert
extract_drive_prefix
(
"z:"
)
==
Some
((
~
"z"
,
~
""
));
assert
extract_drive_prefix
(
"c:
\\
hi"
)
==
Some
((
~
"c"
,
~
"
\\
hi"
));
assert
extract_drive_prefix
(
"d:hi"
)
==
Some
((
~
"d"
,
~
"hi"
));
assert
extract_drive_prefix
(
"c:hi
\\
there.txt"
)
==
Some
((
~
"c"
,
~
"hi
\\
there.txt"
));
assert
extract_drive_prefix
(
"c:
\\
hi
\\
there.txt"
)
==
Some
((
~
"c"
,
~
"
\\
hi
\\
there.txt"
));
}
#[test]
fn
test_windows_paths
()
{
fn
mk
(
s
:
&
str
)
->
WindowsPath
{
from_str
::
<
WindowsPath
>
(
s
)
}
fn
t
(
wp
:
&
WindowsPath
,
s
:
&
str
)
{
let
ss
=
wp
.to_str
();
let
sss
=
str
::
from_slice
(
s
);
if
(
ss
!=
sss
)
{
debug!
(
"got %s"
,
ss
);
debug!
(
"expected %s"
,
sss
);
assert
ss
==
sss
;
}
}
t
(
&
(
mk
(
"hi"
)),
"hi"
);
t
(
&
(
mk
(
"hi/there"
)),
"hi
\\
there"
);
t
(
&
(
mk
(
"hi/there.txt"
)),
"hi
\\
there.txt"
);
t
(
&
(
mk
(
"there.txt"
)
.with_filetype
(
"o"
)),
"there.o"
);
t
(
&
(
mk
(
"hi/there.txt"
)
.with_filetype
(
"o"
)),
"hi
\\
there.o"
);
t
(
&
(
mk
(
"hi/there.txt"
)
.with_filetype
(
"o"
)
.with_dirname
(
"c:
\\
program files A"
)),
"c:
\\
program files A
\\
there.o"
);
t
(
&
(
mk
(
"hi/there.txt"
)
.with_filetype
(
"o"
)
.with_dirname
(
"c:
\\
program files B
\\
"
)),
"c:
\\
program files B
\\
there.o"
);
t
(
&
(
mk
(
"hi/there.txt"
)
.with_filetype
(
"o"
)
.with_dirname
(
"c:
\\
program files C
\\
/"
)),
"c:
\\
program files C
\\
there.o"
);
t
(
&
(
mk
(
"c:
\\
program files (x86)
\\
rust"
)
.push_many
([
~
"lib"
,
~
"thingy.dll"
])
.with_filename
(
"librustc.dll"
)),
"c:
\\
program files (x86)
\\
rust
\\
lib
\\
librustc.dll"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录