Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
1b957c09
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,发现更多精彩内容 >>
提交
1b957c09
编写于
2月 23, 2012
作者:
K
Kevin Cantu
提交者:
Marijn Haverbeke
2月 23, 2012
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
(core::str) replace uses of unsafe::slice_bytes; replace find[_from]_bytes with find[_from]
上级
cec05348
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
64 addition
and
64 deletion
+64
-64
src/comp/back/link.rs
src/comp/back/link.rs
+3
-3
src/comp/middle/trans/debuginfo.rs
src/comp/middle/trans/debuginfo.rs
+1
-1
src/comp/syntax/codemap.rs
src/comp/syntax/codemap.rs
+1
-1
src/comp/syntax/parse/lexer.rs
src/comp/syntax/parse/lexer.rs
+2
-2
src/comp/util/ppaux.rs
src/comp/util/ppaux.rs
+1
-1
src/compiletest/errors.rs
src/compiletest/errors.rs
+3
-3
src/compiletest/header.rs
src/compiletest/header.rs
+2
-2
src/libcore/extfmt.rs
src/libcore/extfmt.rs
+4
-4
src/libcore/str.rs
src/libcore/str.rs
+40
-40
src/libstd/getopts.rs
src/libstd/getopts.rs
+1
-1
src/libstd/rope.rs
src/libstd/rope.rs
+1
-1
src/libstd/sha1.rs
src/libstd/sha1.rs
+1
-1
src/rustdoc/markdown_pass.rs
src/rustdoc/markdown_pass.rs
+4
-4
未找到文件。
src/comp/back/link.rs
浏览文件 @
1b957c09
...
...
@@ -478,7 +478,7 @@ fn crate_meta_vers(sess: session, _crate: ast::crate,
}
fn
truncated_sha1_result
(
sha
:
sha1
)
->
str
unsafe
{
ret
str
::
unsafe
::
slice_bytes
(
sha
.result_str
(),
0u
,
16u
);
ret
str
::
slice
(
sha
.result_str
(),
0u
,
16u
);
}
...
...
@@ -567,12 +567,12 @@ fn link_binary(sess: session,
// Converts a library file name into a cc -l argument
fn
unlib
(
config
:
@
session
::
config
,
filename
:
str
)
->
str
unsafe
{
let
rmlib
=
fn
@
(
filename
:
str
)
->
str
{
let
found
=
str
::
find
_bytes
(
filename
,
"lib"
);
let
found
=
str
::
find
(
filename
,
"lib"
);
if
config
.os
==
session
::
os_macos
||
(
config
.os
==
session
::
os_linux
||
config
.os
==
session
::
os_freebsd
)
&&
option
::
is_some
(
found
)
&&
option
::
get
(
found
)
==
0u
{
ret
str
::
unsafe
::
slice_bytes
(
filename
,
3u
,
ret
str
::
slice
(
filename
,
3u
,
str
::
len_bytes
(
filename
));
}
else
{
ret
filename
;
}
};
...
...
src/comp/middle/trans/debuginfo.rs
浏览文件 @
1b957c09
...
...
@@ -167,7 +167,7 @@ fn create_compile_unit(cx: crate_ctxt, full_path: str)
let
work_dir
=
cx
.sess.working_dir
;
let
file_path
=
if
str
::
starts_with
(
full_path
,
work_dir
)
{
str
::
unsafe
::
slice_bytes
(
full_path
,
str
::
len_bytes
(
work_dir
),
str
::
slice
(
full_path
,
str
::
len_bytes
(
work_dir
),
str
::
len_bytes
(
full_path
))
}
else
{
full_path
...
...
src/comp/syntax/codemap.rs
浏览文件 @
1b957c09
...
...
@@ -162,7 +162,7 @@ fn get_line(fm: filemap, line: int) -> str unsafe {
some
(
e
)
{
e
}
none
{
str
::
len_bytes
(
*
fm
.src
)
}
};
str
::
unsafe
::
slice_bytes
(
*
fm
.src
,
begin
,
end
)
str
::
slice
(
*
fm
.src
,
begin
,
end
)
}
fn
lookup_byte_offset
(
cm
:
codemap
::
codemap
,
chpos
:
uint
)
...
...
src/comp/syntax/parse/lexer.rs
浏览文件 @
1b957c09
...
...
@@ -24,7 +24,7 @@ fn is_eof() -> bool { self.curr == -1 as char }
fn
get_str_from
(
start
:
uint
)
->
str
unsafe
{
// I'm pretty skeptical about this subtraction. What if there's a
// multi-byte character before the mark?
ret
str
::
unsafe
::
slice_bytes
(
*
self
.src
,
start
-
1u
,
self
.pos
-
1u
);
ret
str
::
slice
(
*
self
.src
,
start
-
1u
,
self
.pos
-
1u
);
}
fn
next
()
->
char
{
if
self
.pos
<
self
.len
{
...
...
@@ -611,7 +611,7 @@ fn trim_whitespace_prefix_and_push_line(&lines: [str],
let
s1
;
if
all_whitespace
(
s
,
0u
,
col
)
{
if
col
<
str
::
len_bytes
(
s
)
{
s1
=
str
::
unsafe
::
slice_bytes
(
s
,
col
,
str
::
len_bytes
(
s
));
s1
=
str
::
slice
(
s
,
col
,
str
::
len_bytes
(
s
));
}
else
{
s1
=
""
;
}
}
else
{
s1
=
s
;
}
log
(
debug
,
"pushing line: "
+
s1
);
...
...
src/comp/util/ppaux.rs
浏览文件 @
1b957c09
...
...
@@ -131,7 +131,7 @@ fn parameterized(cx: ctxt, base: str, tps: [ty::t]) -> str {
fn
ty_to_short_str
(
cx
:
ctxt
,
typ
:
t
)
->
str
unsafe
{
let
s
=
encoder
::
encoded_ty
(
cx
,
typ
);
if
str
::
len_bytes
(
s
)
>=
32u
{
s
=
str
::
unsafe
::
slice_bytes
(
s
,
0u
,
32u
);
}
if
str
::
len_bytes
(
s
)
>=
32u
{
s
=
str
::
slice
(
s
,
0u
,
32u
);
}
ret
s
;
}
...
...
src/compiletest/errors.rs
浏览文件 @
1b957c09
...
...
@@ -25,7 +25,7 @@ fn load_errors(testfile: str) -> [expected_error] {
fn
parse_expected
(
line_num
:
uint
,
line
:
str
)
->
[
expected_error
]
unsafe
{
let
error_tag
=
"//!"
;
let
idx
;
alt
str
::
find
_bytes
(
line
,
error_tag
)
{
alt
str
::
find
(
line
,
error_tag
)
{
option
::
none
{
ret
[];
}
option
::
some
(
nn
)
{
idx
=
(
nn
as
uint
)
+
str
::
len_bytes
(
error_tag
);
}
}
...
...
@@ -43,11 +43,11 @@ fn parse_expected(line_num: uint, line: str) -> [expected_error] unsafe {
while
idx
<
len
&&
line
[
idx
]
==
(
' '
as
u8
)
{
idx
+=
1u
;
}
let
start_kind
=
idx
;
while
idx
<
len
&&
line
[
idx
]
!=
(
' '
as
u8
)
{
idx
+=
1u
;
}
let
kind
=
str
::
to_lower
(
str
::
unsafe
::
slice_bytes
(
line
,
start_kind
,
idx
));
let
kind
=
str
::
to_lower
(
str
::
slice
(
line
,
start_kind
,
idx
));
// Extract msg:
while
idx
<
len
&&
line
[
idx
]
==
(
' '
as
u8
)
{
idx
+=
1u
;
}
let
msg
=
str
::
unsafe
::
slice_bytes
(
line
,
idx
,
len
);
let
msg
=
str
::
slice
(
line
,
idx
,
len
);
#
debug
(
"line=%u kind=%s msg=%s"
,
line_num
-
adjust_line
,
kind
,
msg
);
...
...
src/compiletest/header.rs
浏览文件 @
1b957c09
...
...
@@ -106,10 +106,10 @@ fn parse_name_directive(line: str, directive: str) -> bool {
fn
parse_name_value_directive
(
line
:
str
,
directive
:
str
)
->
option
<
str
>
unsafe
{
let
keycolon
=
directive
+
":"
;
alt
str
::
find
_bytes
(
line
,
keycolon
)
{
alt
str
::
find
(
line
,
keycolon
)
{
option
::
some
(
colon
)
{
let
value
=
str
::
unsafe
::
slice_bytes
(
line
,
str
::
slice
(
line
,
colon
+
str
::
len_bytes
(
keycolon
),
str
::
len_bytes
(
line
));
#
debug
(
"%s: %s"
,
directive
,
value
);
...
...
src/libcore/extfmt.rs
浏览文件 @
1b957c09
...
...
@@ -93,13 +93,13 @@ fn flush_buf(buf: str, &pieces: [piece]) -> str {
}
let
i
=
0u
;
while
i
<
lim
{
let
curr
=
str
::
unsafe
::
slice_bytes
(
s
,
i
,
i
+
1u
);
let
curr
=
str
::
slice
(
s
,
i
,
i
+
1u
);
if
str
::
eq
(
curr
,
"%"
)
{
i
+=
1u
;
if
i
>=
lim
{
error
(
"unterminated conversion at end of string"
);
}
let
curr2
=
str
::
unsafe
::
slice_bytes
(
s
,
i
,
i
+
1u
);
let
curr2
=
str
::
slice
(
s
,
i
,
i
+
1u
);
if
str
::
eq
(
curr2
,
"%"
)
{
buf
+=
curr2
;
i
+=
1u
;
...
...
@@ -225,7 +225,7 @@ fn parse_precision(s: str, i: uint, lim: uint) ->
fn
parse_type
(
s
:
str
,
i
:
uint
,
lim
:
uint
,
error
:
error_fn
)
->
{
ty
:
ty
,
next
:
uint
}
unsafe
{
if
i
>=
lim
{
error
(
"missing type in conversion"
);
}
let
tstr
=
str
::
unsafe
::
slice_bytes
(
s
,
i
,
i
+
1u
);
let
tstr
=
str
::
slice
(
s
,
i
,
i
+
1u
);
// TODO: Do we really want two signed types here?
// How important is it to be printf compatible?
let
t
=
...
...
@@ -439,7 +439,7 @@ fn have_precision(cv: conv) -> bool {
let
headstr
=
str
::
from_bytes
([
head
]);
// FIXME: not UTF-8 safe
let
bytelen
=
str
::
len_bytes
(
s
);
let
numpart
=
str
::
unsafe
::
slice_bytes
(
s
,
1u
,
bytelen
);
let
numpart
=
str
::
slice
(
s
,
1u
,
bytelen
);
ret
headstr
+
padstr
+
numpart
;
}
}
...
...
src/libcore/str.rs
浏览文件 @
1b957c09
...
...
@@ -75,9 +75,9 @@
index_from
,
rindex
,
//rindex_chars,
find
,
find_from
,
find_chars
,
find_bytes
,
find_from_bytes
,
contains
,
starts_with
,
ends_with
,
...
...
@@ -385,7 +385,7 @@ fn chars(s: str) -> [char] {
/*
Function: substr
Take a substring of another. Returns a string containing `len`
char
s
Take a substring of another. Returns a string containing `len`
byte
s
starting at char offset `begin`.
Failure:
...
...
@@ -393,7 +393,7 @@ fn chars(s: str) -> [char] {
If `begin` + `len` is is greater than the char length of the string
*/
fn
substr
(
s
:
str
,
begin
:
uint
,
len
:
uint
)
->
str
{
ret
slice
_chars
(
s
,
begin
,
begin
+
len
);
ret
slice
(
s
,
begin
,
begin
+
len
);
}
// Function: slice
...
...
@@ -696,7 +696,7 @@ fn replace(s: str, from: str, to: str) -> str unsafe {
from
,
to
);
}
else
{
let
idx
;
alt
find
_bytes
(
s
,
from
)
{
alt
find
(
s
,
from
)
{
some
(
x
)
{
idx
=
x
;
}
none
{
ret
s
;
}
}
...
...
@@ -977,21 +977,21 @@ fn rindex_chars(ss: str, cc: char) -> option<uint> {
ret
none
;
}
//Function: find
_bytes
//Function: find
//
// Find the byte position of the first instance of one string
// within another, or return option::none
fn
find
_bytes
(
haystack
:
str
,
needle
:
str
)
->
option
<
uint
>
{
find_from
_bytes
(
haystack
,
needle
,
0u
,
len_bytes
(
haystack
))
fn
find
(
haystack
:
str
,
needle
:
str
)
->
option
<
uint
>
{
find_from
(
haystack
,
needle
,
0u
,
len_bytes
(
haystack
))
}
//Function: find_from
_bytes
//Function: find_from
//
// Find the byte position of the first instance of one string
// within another, or return option::none
//
// FIXME: Boyer-Moore should be significantly faster
fn
find_from
_bytes
(
haystack
:
str
,
needle
:
str
,
start
:
uint
,
end
:
uint
)
fn
find_from
(
haystack
:
str
,
needle
:
str
,
start
:
uint
,
end
:
uint
)
->
option
<
uint
>
{
assert
end
<=
len_bytes
(
haystack
);
...
...
@@ -1020,7 +1020,7 @@ fn match_at(haystack: str, needle: str, ii: uint) -> bool {
// Find the char position of the first instance of one string
// within another, or return option::none
fn
find_chars
(
haystack
:
str
,
needle
:
str
)
->
option
<
uint
>
{
alt
find
_bytes
(
haystack
,
needle
)
{
alt
find
(
haystack
,
needle
)
{
none
{
ret
none
;
}
some
(
nn
)
{
ret
some
(
b2c_pos
(
haystack
,
nn
));
}
}
...
...
@@ -1056,7 +1056,7 @@ fn b2c_pos(ss: str, bpos: uint) -> uint {
needle - The string to look for
*/
fn
contains
(
haystack
:
str
,
needle
:
str
)
->
bool
{
option
::
is_some
(
find
_bytes
(
haystack
,
needle
))
option
::
is_some
(
find
(
haystack
,
needle
))
}
/*
...
...
@@ -1479,8 +1479,8 @@ mod unsafe {
export
from_bytes
,
from_byte
,
slice_bytes
,
slice_bytes_safe_range
,
slice_bytes
,
// FIXME: stop exporting
slice_bytes_safe_range
,
// FIXME: stop exporting
push_byte
,
push_bytes
,
// note: wasn't exported
pop_byte
,
...
...
@@ -1840,45 +1840,45 @@ fn test_words () {
}
#[test]
fn
test_find
_bytes
()
{
fn
test_find
()
{
// byte positions
assert
(
find
_bytes
(
"banana"
,
"apple pie"
)
==
none
);
assert
(
find
_bytes
(
""
,
""
)
==
some
(
0u
));
assert
(
find
(
"banana"
,
"apple pie"
)
==
none
);
assert
(
find
(
""
,
""
)
==
some
(
0u
));
let
data
=
"ประเทศไทย中华Việt Nam"
;
assert
(
find
_bytes
(
data
,
""
)
==
some
(
0u
));
assert
(
find
_bytes
(
data
,
"ประเ"
)
==
some
(
0u
));
assert
(
find
_bytes
(
data
,
"ะเ"
)
==
some
(
6u
));
assert
(
find
_bytes
(
data
,
"中华"
)
==
some
(
27u
));
assert
(
find
_bytes
(
data
,
"ไท华"
)
==
none
);
assert
(
find
(
data
,
""
)
==
some
(
0u
));
assert
(
find
(
data
,
"ประเ"
)
==
some
(
0u
));
assert
(
find
(
data
,
"ะเ"
)
==
some
(
6u
));
assert
(
find
(
data
,
"中华"
)
==
some
(
27u
));
assert
(
find
(
data
,
"ไท华"
)
==
none
);
}
#[test]
fn
test_find_from
_bytes
()
{
fn
test_find_from
()
{
// byte positions
assert
(
find_from
_bytes
(
""
,
""
,
0u
,
0u
)
==
some
(
0u
));
assert
(
find_from
(
""
,
""
,
0u
,
0u
)
==
some
(
0u
));
let
data
=
"abcabc"
;
assert
find_from
_bytes
(
data
,
"ab"
,
0u
,
6u
)
==
some
(
0u
);
assert
find_from
_bytes
(
data
,
"ab"
,
2u
,
6u
)
==
some
(
3u
);
assert
find_from
_bytes
(
data
,
"ab"
,
2u
,
4u
)
==
none
;
assert
find_from
(
data
,
"ab"
,
0u
,
6u
)
==
some
(
0u
);
assert
find_from
(
data
,
"ab"
,
2u
,
6u
)
==
some
(
3u
);
assert
find_from
(
data
,
"ab"
,
2u
,
4u
)
==
none
;
let
data
=
"ประเทศไทย中华Việt Nam"
;
data
+=
data
;
assert
find_from
_bytes
(
data
,
""
,
0u
,
43u
)
==
some
(
0u
);
assert
find_from
_bytes
(
data
,
""
,
6u
,
43u
)
==
some
(
6u
);
assert
find_from
(
data
,
""
,
0u
,
43u
)
==
some
(
0u
);
assert
find_from
(
data
,
""
,
6u
,
43u
)
==
some
(
6u
);
assert
find_from
_bytes
(
data
,
"ประ"
,
0u
,
43u
)
==
some
(
0u
);
assert
find_from
_bytes
(
data
,
"ทศไ"
,
0u
,
43u
)
==
some
(
12u
);
assert
find_from
_bytes
(
data
,
"ย中"
,
0u
,
43u
)
==
some
(
24u
);
assert
find_from
_bytes
(
data
,
"iệt"
,
0u
,
43u
)
==
some
(
34u
);
assert
find_from
_bytes
(
data
,
"Nam"
,
0u
,
43u
)
==
some
(
40u
);
assert
find_from
(
data
,
"ประ"
,
0u
,
43u
)
==
some
(
0u
);
assert
find_from
(
data
,
"ทศไ"
,
0u
,
43u
)
==
some
(
12u
);
assert
find_from
(
data
,
"ย中"
,
0u
,
43u
)
==
some
(
24u
);
assert
find_from
(
data
,
"iệt"
,
0u
,
43u
)
==
some
(
34u
);
assert
find_from
(
data
,
"Nam"
,
0u
,
43u
)
==
some
(
40u
);
assert
find_from
_bytes
(
data
,
"ประ"
,
43u
,
86u
)
==
some
(
43u
);
assert
find_from
_bytes
(
data
,
"ทศไ"
,
43u
,
86u
)
==
some
(
55u
);
assert
find_from
_bytes
(
data
,
"ย中"
,
43u
,
86u
)
==
some
(
67u
);
assert
find_from
_bytes
(
data
,
"iệt"
,
43u
,
86u
)
==
some
(
77u
);
assert
find_from
_bytes
(
data
,
"Nam"
,
43u
,
86u
)
==
some
(
83u
);
assert
find_from
(
data
,
"ประ"
,
43u
,
86u
)
==
some
(
43u
);
assert
find_from
(
data
,
"ทศไ"
,
43u
,
86u
)
==
some
(
55u
);
assert
find_from
(
data
,
"ย中"
,
43u
,
86u
)
==
some
(
67u
);
assert
find_from
(
data
,
"iệt"
,
43u
,
86u
)
==
some
(
77u
);
assert
find_from
(
data
,
"Nam"
,
43u
,
86u
)
==
some
(
83u
);
}
#[test]
...
...
@@ -1912,7 +1912,7 @@ fn t(a: str, b: str, start: int) {
t
(
"hello"
,
"el"
,
1
);
assert
"ะเทศไท"
==
substr
(
"ประเทศไทย中华Việt Nam"
,
2u
,
6
u
);
==
substr
(
"ประเทศไทย中华Việt Nam"
,
6u
,
18
u
);
}
#[test]
...
...
src/libstd/getopts.rs
浏览文件 @
1b957c09
...
...
@@ -229,7 +229,7 @@ fn getopts(args: [str], opts: [opt]) -> result unsafe {
let
names
;
let
i_arg
=
option
::
none
::
<
str
>
;
if
cur
[
1
]
==
'-'
as
u8
{
let
tail
=
str
::
unsafe
::
slice_bytes
(
cur
,
2u
,
curlen
);
let
tail
=
str
::
slice
(
cur
,
2u
,
curlen
);
let
tail_eq
=
str
::
splitn_char
(
tail
,
'='
,
1u
);
if
vec
::
len
(
tail_eq
)
<=
1u
{
names
=
[
long
(
tail
)];
...
...
src/libstd/rope.rs
浏览文件 @
1b957c09
...
...
@@ -1345,7 +1345,7 @@ fn rope_to_string(r: rope) -> str {
fn
aux
(
str
:
@
mutable
str
,
node
:
@
node
::
node
)
unsafe
{
alt
(
*
node
)
{
node
::
leaf
(
x
)
{
*
str
+=
str
::
unsafe
::
slice_bytes
(
*
str
+=
str
::
slice
(
*
x
.content
,
x
.byte_offset
,
x
.byte_offset
+
x
.byte_len
);
}
...
...
src/libstd/sha1.rs
浏览文件 @
1b957c09
...
...
@@ -372,7 +372,7 @@ fn check_vec_eq(v0: [u8], v1: [u8]) {
let
left
=
len
;
while
left
>
0u
{
let
take
=
(
left
+
1u
)
/
2u
;
sh
.input_str
(
str
::
unsafe
::
slice_bytes
(
t
.input
,
len
-
left
,
sh
.input_str
(
str
::
slice
(
t
.input
,
len
-
left
,
take
+
len
-
left
));
left
=
left
-
take
;
}
...
...
src/rustdoc/markdown_pass.rs
浏览文件 @
1b957c09
...
...
@@ -56,10 +56,10 @@ mod c { }\
fn d() { }"
);
let
idx_a
=
option
::
get
(
str
::
find
_bytes
(
markdown
,
"# Module `a`"
));
let
idx_b
=
option
::
get
(
str
::
find
_bytes
(
markdown
,
"## Function `b`"
));
let
idx_c
=
option
::
get
(
str
::
find
_bytes
(
markdown
,
"# Module `c`"
));
let
idx_d
=
option
::
get
(
str
::
find
_bytes
(
markdown
,
"## Function `d`"
));
let
idx_a
=
option
::
get
(
str
::
find
(
markdown
,
"# Module `a`"
));
let
idx_b
=
option
::
get
(
str
::
find
(
markdown
,
"## Function `b`"
));
let
idx_c
=
option
::
get
(
str
::
find
(
markdown
,
"# Module `c`"
));
let
idx_d
=
option
::
get
(
str
::
find
(
markdown
,
"## Function `d`"
));
assert
idx_b
<
idx_d
;
assert
idx_d
<
idx_a
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录