Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
98447f52
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,发现更多精彩内容 >>
提交
98447f52
编写于
2月 21, 2012
作者:
K
Kevin Cantu
提交者:
Marijn Haverbeke
2月 23, 2012
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
(core::str) mostly rename len -> len_chars
上级
7a649866
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
54 addition
and
52 deletion
+54
-52
src/cargo/cargo.rs
src/cargo/cargo.rs
+4
-4
src/comp/driver/diagnostic.rs
src/comp/driver/diagnostic.rs
+2
-2
src/comp/syntax/codemap.rs
src/comp/syntax/codemap.rs
+2
-2
src/comp/syntax/ext/qquote.rs
src/comp/syntax/ext/qquote.rs
+1
-1
src/comp/syntax/print/pp.rs
src/comp/syntax/print/pp.rs
+1
-1
src/comp/syntax/print/pprust.rs
src/comp/syntax/print/pprust.rs
+1
-1
src/fuzzer/fuzzer.rs
src/fuzzer/fuzzer.rs
+1
-1
src/libcore/extfmt.rs
src/libcore/extfmt.rs
+3
-3
src/libcore/str.rs
src/libcore/str.rs
+18
-16
src/libstd/fs.rs
src/libstd/fs.rs
+1
-1
src/libstd/getopts.rs
src/libstd/getopts.rs
+1
-1
src/libstd/json.rs
src/libstd/json.rs
+10
-10
src/libstd/rand.rs
src/libstd/rand.rs
+3
-3
src/libstd/rope.rs
src/libstd/rope.rs
+3
-3
src/rustdoc/desc_to_brief_pass.rs
src/rustdoc/desc_to_brief_pass.rs
+1
-1
src/rustdoc/unindent_pass.rs
src/rustdoc/unindent_pass.rs
+1
-1
src/test/run-pass/utf8_chars.rs
src/test/run-pass/utf8_chars.rs
+1
-1
未找到文件。
src/cargo/cargo.rs
浏览文件 @
98447f52
...
...
@@ -174,10 +174,10 @@ fn print(s: str) {
}
fn
rest
(
s
:
str
,
start
:
uint
)
->
str
{
if
(
start
>=
str
::
len
(
s
))
{
if
(
start
>=
str
::
len
_chars
(
s
))
{
""
}
else
{
str
::
slice
(
s
,
start
,
str
::
len
(
s
))
str
::
slice
(
s
,
start
,
str
::
len
_chars
(
s
))
}
}
...
...
@@ -689,7 +689,7 @@ fn cmd_install(c: cargo) unsafe {
alt
str
::
index
(
uuid
,
'/'
)
{
option
::
some
(
idx
)
{
let
source
=
str
::
slice
(
uuid
,
0u
,
idx
);
uuid
=
str
::
slice
(
uuid
,
idx
+
1u
,
str
::
len
(
uuid
));
uuid
=
str
::
slice
(
uuid
,
idx
+
1u
,
str
::
len
_chars
(
uuid
));
install_uuid_specific
(
c
,
wd
,
source
,
uuid
);
}
option
::
none
{
...
...
@@ -701,7 +701,7 @@ fn cmd_install(c: cargo) unsafe {
alt
str
::
index
(
name
,
'/'
)
{
option
::
some
(
idx
)
{
let
source
=
str
::
slice
(
name
,
0u
,
idx
);
name
=
str
::
slice
(
name
,
idx
+
1u
,
str
::
len
(
name
));
name
=
str
::
slice
(
name
,
idx
+
1u
,
str
::
len
_chars
(
name
));
install_named_specific
(
c
,
wd
,
source
,
name
);
}
option
::
none
{
...
...
src/comp/driver/diagnostic.rs
浏览文件 @
98447f52
...
...
@@ -210,7 +210,7 @@ fn highlight_lines(cm: codemap::codemap, sp: span,
if
elided
{
let
last_line
=
display_lines
[
vec
::
len
(
display_lines
)
-
1u
];
let
s
=
#
fmt
[
"%s:%u "
,
fm
.name
,
last_line
+
1u
];
let
indent
=
str
::
len
(
s
);
let
indent
=
str
::
len
_bytes
(
s
);
let
out
=
""
;
while
indent
>
0u
{
out
+=
" "
;
indent
-=
1u
;
}
out
+=
"...
\n
"
;
...
...
@@ -228,7 +228,7 @@ fn highlight_lines(cm: codemap::codemap, sp: span,
while
num
>
0u
{
num
/=
10u
;
digits
+=
1u
;
}
// indent past |name:## | and the 0-offset column location
let
left
=
str
::
len
(
fm
.name
)
+
digits
+
lo
.col
+
3u
;
let
left
=
str
::
len
_bytes
(
fm
.name
)
+
digits
+
lo
.col
+
3u
;
let
s
=
""
;
while
left
>
0u
{
str
::
push_char
(
s
,
' '
);
left
-=
1u
;
}
...
...
src/comp/syntax/codemap.rs
浏览文件 @
98447f52
...
...
@@ -158,9 +158,9 @@ fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines {
fn
get_line
(
fm
:
filemap
,
line
:
int
)
->
str
unsafe
{
let
begin
:
uint
=
fm
.lines
[
line
]
.byte
-
fm
.start_pos.byte
;
let
end
=
alt
str
::
byte_index_from
(
*
fm
.src
,
'\n'
as
u8
,
begin
,
str
::
len
(
*
fm
.src
))
{
str
::
len
_bytes
(
*
fm
.src
))
{
some
(
e
)
{
e
}
none
{
str
::
len
(
*
fm
.src
)
}
none
{
str
::
len
_bytes
(
*
fm
.src
)
}
};
str
::
unsafe
::
slice_bytes
(
*
fm
.src
,
begin
,
end
)
}
...
...
src/comp/syntax/ext/qquote.rs
浏览文件 @
98447f52
...
...
@@ -214,7 +214,7 @@ fn finish<T: qq_helper>
if
(
j
<
g_len
&&
i
==
cx
.gather
[
j
]
.lo
)
{
assert
ch
==
'$'
;
let
repl
=
#
fmt
(
"$%u "
,
j
);
state
=
skip
(
str
::
len
(
repl
));
state
=
skip
(
str
::
len
_chars
(
repl
));
str2
+=
repl
;
}
alt
state
{
...
...
src/comp/syntax/print/pp.rs
浏览文件 @
98447f52
...
...
@@ -491,7 +491,7 @@ fn break_offset(p: printer, n: uint, off: int) {
fn
eof
(
p
:
printer
)
{
p
.pretty_print
(
EOF
);
}
fn
word
(
p
:
printer
,
wrd
:
str
)
{
p
.pretty_print
(
STRING
(
wrd
,
str
::
len
(
wrd
)
as
int
));
p
.pretty_print
(
STRING
(
wrd
,
str
::
len
_bytes
(
wrd
)
as
int
));
}
fn
huge_word
(
p
:
printer
,
wrd
:
str
)
{
...
...
src/comp/syntax/print/pprust.rs
浏览文件 @
98447f52
...
...
@@ -204,7 +204,7 @@ fn head(s: ps, w: str) {
// outer-box is consistent
cbox
(
s
,
indent_unit
);
// head-box is inconsistent
ibox
(
s
,
str
::
len
(
w
)
+
1u
);
ibox
(
s
,
str
::
len
_bytes
(
w
)
+
1u
);
// keyword that starts the head
word_nbsp
(
s
,
w
);
}
...
...
src/fuzzer/fuzzer.rs
浏览文件 @
98447f52
...
...
@@ -287,7 +287,7 @@ fn check_variants_T<T: copy>(
fn
last_part
(
filename
:
str
)
->
str
{
let
ix
=
option
::
get
(
str
::
rindex
(
filename
,
'/'
));
str
::
slice
(
filename
,
ix
+
1u
,
str
::
len
(
filename
)
-
3u
)
str
::
slice
(
filename
,
ix
+
1u
,
str
::
len
_chars
(
filename
)
-
3u
)
}
enum
happiness
{
passed
,
cleanly_rejected
(
str
),
known_bug
(
str
),
failed
(
str
),
}
...
...
src/libcore/extfmt.rs
浏览文件 @
98447f52
...
...
@@ -325,7 +325,7 @@ fn conv_str(cv: conv, s: str) -> str unsafe {
alt
cv
.precision
{
count_implied
{
s
}
count_is
(
max
)
{
if
max
as
uint
<
str
::
len
(
s
)
{
if
max
as
uint
<
str
::
len
_chars
(
s
)
{
str
::
substr
(
s
,
0u
,
max
as
uint
)
}
else
{
s
}
}
...
...
@@ -368,7 +368,7 @@ fn uint_to_str_prec(num: uint, radix: uint, prec: uint) -> str {
""
}
else
{
let
s
=
uint
::
to_str
(
num
,
radix
);
let
len
=
str
::
len
(
s
);
let
len
=
str
::
len
_chars
(
s
);
if
len
<
prec
{
let
diff
=
prec
-
len
;
let
pad
=
str_init_elt
(
diff
,
'0'
);
...
...
@@ -400,7 +400,7 @@ fn pad(cv: conv, s: str, mode: pad_mode) -> str unsafe {
uwidth
=
width
as
uint
;
}
}
let
strlen
=
str
::
len
(
s
);
let
strlen
=
str
::
len
_chars
(
s
);
if
uwidth
<=
strlen
{
ret
s
;
}
let
padchar
=
' '
;
let
diff
=
uwidth
-
strlen
;
...
...
src/libcore/str.rs
浏览文件 @
98447f52
...
...
@@ -86,7 +86,7 @@
is_not_empty
,
is_whitespace
,
len_bytes
,
len_chars
,
len
,
len_chars
,
//
len,
// Misc
// FIXME: perhaps some more of this section shouldn't be exported?
...
...
@@ -529,7 +529,7 @@ fn split(ss: str, sepfn: fn(cc: char)->bool) -> [str] {
}
});
if
len
(
accum
)
>=
0u
||
ends_with_sep
{
if
len
_chars
(
accum
)
>=
0u
||
ends_with_sep
{
vv
+=
[
accum
];
}
...
...
@@ -601,7 +601,7 @@ fn lines_any(ss: str) -> [str] {
*/
fn
words
(
ss
:
str
)
->
[
str
]
{
ret
vec
::
filter
(
split
(
ss
,
{|
cc
|
char
::
is_whitespace
(
cc
)}),
{|
w
|
0u
<
str
::
len
(
w
)});
{|
w
|
0u
<
str
::
len
_chars
(
w
)});
}
/*
...
...
@@ -611,7 +611,7 @@ fn words(ss: str) -> [str] {
*/
fn
windowed
(
nn
:
uint
,
ss
:
str
)
->
[
str
]
{
let
ww
=
[];
let
len
=
str
::
len
(
ss
);
let
len
=
str
::
len
_chars
(
ss
);
assert
1u
<=
nn
;
...
...
@@ -883,7 +883,7 @@ fn byte_index_from(s: str, b: u8, start: uint, end: uint) -> option<uint> {
// (as option some/none)
fn
rindex
(
ss
:
str
,
cc
:
char
)
->
option
<
uint
>
{
let
bii
=
len_bytes
(
ss
);
let
cii
=
len
(
ss
);
let
cii
=
len
_chars
(
ss
);
while
bii
>
0u
{
let
{
ch
,
prev
}
=
char_range_at_reverse
(
ss
,
bii
);
cii
-=
1u
;
...
...
@@ -1008,8 +1008,8 @@ fn starts_with(haystack: str, needle: str) -> bool unsafe {
needle - The string to look for
*/
fn
ends_with
(
haystack
:
str
,
needle
:
str
)
->
bool
{
let
haystack_len
:
uint
=
len
(
haystack
);
let
needle_len
:
uint
=
len
(
needle
);
let
haystack_len
:
uint
=
len
_chars
(
haystack
);
let
needle_len
:
uint
=
len
_chars
(
needle
);
ret
if
needle_len
==
0u
{
true
}
else
if
needle_len
>
haystack_len
{
...
...
@@ -1079,7 +1079,9 @@ fn len(s: str) -> uint {
substr_len_chars
(
s
,
0u
,
len_bytes
(
s
))
}
fn
len_chars
(
s
:
str
)
->
uint
{
len
(
s
)
}
fn
len_chars
(
s
:
str
)
->
uint
{
substr_len_chars
(
s
,
0u
,
len_bytes
(
s
))
}
/*
Section: Misc
...
...
@@ -1529,14 +1531,14 @@ fn test_len() {
assert
(
len_bytes
(
"
\u2620
"
)
==
3u
);
assert
(
len_bytes
(
"
\U0001d11e
"
)
==
4u
);
assert
(
len
(
""
)
==
0u
);
assert
(
len
(
"hello world"
)
==
11u
);
assert
(
len
(
"
\x63
"
)
==
1u
);
assert
(
len
(
"
\xa2
"
)
==
1u
);
assert
(
len
(
"
\u03c0
"
)
==
1u
);
assert
(
len
(
"
\u2620
"
)
==
1u
);
assert
(
len
(
"
\U0001d11e
"
)
==
1u
);
assert
(
len
(
"ประเทศไทย中华Việt Nam"
)
==
19u
);
assert
(
len
_chars
(
""
)
==
0u
);
assert
(
len
_chars
(
"hello world"
)
==
11u
);
assert
(
len
_chars
(
"
\x63
"
)
==
1u
);
assert
(
len
_chars
(
"
\xa2
"
)
==
1u
);
assert
(
len
_chars
(
"
\u03c0
"
)
==
1u
);
assert
(
len
_chars
(
"
\u2620
"
)
==
1u
);
assert
(
len
_chars
(
"
\U0001d11e
"
)
==
1u
);
assert
(
len
_chars
(
"ประเทศไทย中华Việt Nam"
)
==
19u
);
}
#[test]
...
...
src/libstd/fs.rs
浏览文件 @
98447f52
...
...
@@ -45,7 +45,7 @@ fn splitDirnameBasename (pp: path) -> {dirname: str, basename: str} {
}
ret
{
dirname
:
str
::
slice
(
pp
,
0u
,
ii
),
basename
:
str
::
slice
(
pp
,
ii
+
1u
,
str
::
len
(
pp
))};
basename
:
str
::
slice
(
pp
,
ii
+
1u
,
str
::
len
_chars
(
pp
))};
}
/*
...
...
src/libstd/getopts.rs
浏览文件 @
98447f52
...
...
@@ -79,7 +79,7 @@ enum occur { req, optional, multi, }
type
opt
=
{
name
:
name
,
hasarg
:
hasarg
,
occur
:
occur
};
fn
mkname
(
nm
:
str
)
->
name
{
ret
if
str
::
len
(
nm
)
==
1u
{
ret
if
str
::
len
_bytes
(
nm
)
==
1u
{
short
(
str
::
char_at
(
nm
,
0u
))
}
else
{
long
(
nm
)
};
}
...
...
src/libstd/json.rs
浏览文件 @
98447f52
...
...
@@ -70,8 +70,8 @@ fn to_str(j: json) -> str {
}
fn
rest
(
s
:
str
)
->
str
{
assert
(
str
::
len
(
s
)
>=
1u
);
str
::
slice
(
s
,
1u
,
str
::
len
(
s
))
assert
(
str
::
len
_chars
(
s
)
>=
1u
);
str
::
slice
(
s
,
1u
,
str
::
len
_chars
(
s
))
}
fn
from_str_str
(
s
:
str
)
->
(
option
<
json
>
,
str
)
{
...
...
@@ -99,7 +99,7 @@ fn from_str_str(s: str) -> (option<json>, str) {
cont
;
}
else
if
(
c
==
'"'
)
{
ret
(
some
(
string
(
res
)),
str
::
slice
(
s
,
pos
,
str
::
len
(
s
)));
str
::
slice
(
s
,
pos
,
str
::
len
_chars
(
s
)));
}
res
=
res
+
str
::
from_char
(
c
);
}
...
...
@@ -200,12 +200,12 @@ fn from_str_float(s: str) -> (option<json>, str) {
}
'.'
{
break
;
}
_
{
ret
(
some
(
num
(
neg
*
res
)),
str
::
slice
(
s
,
opos
,
str
::
len
(
s
)));
}
str
::
slice
(
s
,
opos
,
str
::
len
_chars
(
s
)));
}
}
}
if
pos
==
len
{
ret
(
some
(
num
(
neg
*
res
)),
str
::
slice
(
s
,
pos
,
str
::
len
(
s
)));
ret
(
some
(
num
(
neg
*
res
)),
str
::
slice
(
s
,
pos
,
str
::
len
_chars
(
s
)));
}
let
dec
=
1
f
;
...
...
@@ -220,17 +220,17 @@ fn from_str_float(s: str) -> (option<json>, str) {
res
+=
(((
c
as
int
)
-
(
'0'
as
int
))
as
float
)
*
dec
;
}
_
{
ret
(
some
(
num
(
neg
*
res
)),
str
::
slice
(
s
,
opos
,
str
::
len
(
s
)));
}
str
::
slice
(
s
,
opos
,
str
::
len
_chars
(
s
)));
}
}
}
ret
(
some
(
num
(
neg
*
res
)),
str
::
slice
(
s
,
pos
,
str
::
len
(
s
)));
ret
(
some
(
num
(
neg
*
res
)),
str
::
slice
(
s
,
pos
,
str
::
len
_chars
(
s
)));
}
fn
from_str_bool
(
s
:
str
)
->
(
option
<
json
>
,
str
)
{
if
(
str
::
starts_with
(
s
,
"true"
))
{
(
some
(
boolean
(
true
)),
str
::
slice
(
s
,
4u
,
str
::
len
(
s
)))
(
some
(
boolean
(
true
)),
str
::
slice
(
s
,
4u
,
str
::
len
_chars
(
s
)))
}
else
if
(
str
::
starts_with
(
s
,
"false"
))
{
(
some
(
boolean
(
false
)),
str
::
slice
(
s
,
5u
,
str
::
len
(
s
)))
(
some
(
boolean
(
false
)),
str
::
slice
(
s
,
5u
,
str
::
len
_chars
(
s
)))
}
else
{
(
none
,
s
)
}
...
...
@@ -238,7 +238,7 @@ fn from_str_bool(s: str) -> (option<json>, str) {
fn
from_str_null
(
s
:
str
)
->
(
option
<
json
>
,
str
)
{
if
(
str
::
starts_with
(
s
,
"null"
))
{
(
some
(
null
),
str
::
slice
(
s
,
4u
,
str
::
len
(
s
)))
(
some
(
null
),
str
::
slice
(
s
,
4u
,
str
::
len
_chars
(
s
)))
}
else
{
(
none
,
s
)
}
...
...
src/libstd/rand.rs
浏览文件 @
98447f52
...
...
@@ -77,7 +77,7 @@ fn gen_str(len: uint) -> str {
let
i
=
0u
;
while
(
i
<
len
)
{
let
n
=
rustrt
::
rand_next
(
**
self
)
as
uint
%
str
::
len
(
charset
);
str
::
len
_bytes
(
charset
);
s
=
s
+
str
::
from_char
(
str
::
char_at
(
charset
,
n
));
i
+=
1u
;
}
...
...
@@ -130,8 +130,8 @@ fn genstr() {
log
(
debug
,
r
.gen_str
(
10u
));
log
(
debug
,
r
.gen_str
(
10u
));
log
(
debug
,
r
.gen_str
(
10u
));
assert
(
str
::
len
(
r
.gen_str
(
10u
))
==
10u
);
assert
(
str
::
len
(
r
.gen_str
(
16u
))
==
16u
);
assert
(
str
::
len
_bytes
(
r
.gen_str
(
10u
))
==
10u
);
assert
(
str
::
len
_bytes
(
r
.gen_str
(
16u
))
==
16u
);
}
}
...
...
src/libstd/rope.rs
浏览文件 @
98447f52
...
...
@@ -1373,7 +1373,7 @@ fn of_string1() {
let
sample
=
@
"0123456789ABCDE"
;
let
r
=
of_str
(
sample
);
assert
char_len
(
r
)
==
str
::
len
(
*
sample
);
assert
char_len
(
r
)
==
str
::
len
_chars
(
*
sample
);
assert
rope_to_string
(
r
)
==
*
sample
;
}
...
...
@@ -1384,7 +1384,7 @@ fn of_string2() {
while
i
<
10
{
*
buf
=
*
buf
+
*
buf
;
i
+=
1
;}
let
sample
=
@*
buf
;
let
r
=
of_str
(
sample
);
assert
char_len
(
r
)
==
str
::
len
(
*
sample
);
assert
char_len
(
r
)
==
str
::
len
_chars
(
*
sample
);
assert
rope_to_string
(
r
)
==
*
sample
;
let
string_iter
=
0u
;
...
...
@@ -1427,7 +1427,7 @@ fn iter1() {
}
}
assert
len
==
str
::
len
(
*
sample
);
assert
len
==
str
::
len
_chars
(
*
sample
);
}
#[test]
...
...
src/rustdoc/desc_to_brief_pass.rs
浏览文件 @
98447f52
...
...
@@ -175,7 +175,7 @@ fn parse_desc(desc: str) -> (option<str>, option<str>) {
if
check
vec
::
is_not_empty
(
paras
)
{
let
maybe_brief
=
vec
::
head
(
paras
);
if
str
::
len
(
maybe_brief
)
<=
max_brief_len
{
if
str
::
len
_bytes
(
maybe_brief
)
<=
max_brief_len
{
let
desc_paras
=
vec
::
tail
(
paras
);
let
desc
=
if
vec
::
is_not_empty
(
desc_paras
)
{
some
(
str
::
connect
(
desc_paras
,
"
\n\n
"
))
...
...
src/rustdoc/unindent_pass.rs
浏览文件 @
98447f52
...
...
@@ -68,7 +68,7 @@ fn unindent(s: str) -> str {
line
}
else
{
assert
str
::
len_bytes
(
line
)
>=
min_indent
;
str
::
slice
(
line
,
min_indent
,
str
::
len
(
line
))
str
::
slice
(
line
,
min_indent
,
str
::
len
_chars
(
line
))
}
};
str
::
connect
(
unindented
,
"
\n
"
)
...
...
src/test/run-pass/utf8_chars.rs
浏览文件 @
98447f52
...
...
@@ -8,7 +8,7 @@ fn main() {
let
s
:
str
=
str
::
from_chars
(
chs
);
assert
(
str
::
len_bytes
(
s
)
==
10u
);
assert
(
str
::
len
(
s
)
==
4u
);
assert
(
str
::
len
_chars
(
s
)
==
4u
);
assert
(
vec
::
len
::
<
char
>
(
str
::
chars
(
s
))
==
4u
);
assert
(
str
::
eq
(
str
::
from_chars
(
str
::
chars
(
s
)),
s
));
assert
(
str
::
char_at
(
s
,
0u
)
==
'e'
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录