Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
dd748079
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,发现更多精彩内容 >>
提交
dd748079
编写于
4月 23, 2013
作者:
M
Marvin Löbel
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Removed ascii functions from other modules
Replaced str::to_lowercase and str::to_uppercase
上级
e26f992d
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
43 addition
and
89 deletion
+43
-89
src/compiletest/errors.rs
src/compiletest/errors.rs
+4
-1
src/libcore/char.rs
src/libcore/char.rs
+2
-14
src/libcore/num/uint-template/u8.rs
src/libcore/num/uint-template/u8.rs
+0
-7
src/libcore/path.rs
src/libcore/path.rs
+7
-2
src/libcore/str.rs
src/libcore/str.rs
+0
-59
src/libcore/str/ascii.rs
src/libcore/str/ascii.rs
+12
-0
src/libcore/unstable/extfmt.rs
src/libcore/unstable/extfmt.rs
+4
-1
src/librustc/driver/driver.rs
src/librustc/driver/driver.rs
+4
-1
src/librustdoc/markdown_index_pass.rs
src/librustdoc/markdown_index_pass.rs
+3
-1
src/libstd/semver.rs
src/libstd/semver.rs
+1
-1
src/libstd/sort.rs
src/libstd/sort.rs
+6
-2
未找到文件。
src/compiletest/errors.rs
浏览文件 @
dd748079
...
...
@@ -50,7 +50,10 @@ fn parse_expected(line_num: uint, line: ~str) -> ~[ExpectedError] {
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
::
slice
(
line
,
start_kind
,
idx
)
.to_owned
());
// FIXME: 4318 Instead of to_str_ascii, could use
// to_str_consume to not do a unneccessary copy.
let
kind
=
str
::
slice
(
line
,
start_kind
,
idx
)
.to_ascii
()
.to_lower
()
.to_str_ascii
();
// Extract msg:
while
idx
<
len
&&
line
[
idx
]
==
(
' '
as
u8
)
{
idx
+=
1u
;
}
...
...
src/libcore/char.rs
浏览文件 @
dd748079
...
...
@@ -100,12 +100,6 @@ pub fn is_alphanumeric(c: char) -> bool {
unicode
::
general_category
::
No
(
c
);
}
/// Indicates whether the character is an ASCII character
#[inline(always)]
pub
fn
is_ascii
(
c
:
char
)
->
bool
{
c
-
(
'\x7F'
&
c
)
==
'\x00'
}
/// Indicates whether the character is numeric (Nd, Nl, or No)
#[inline(always)]
pub
fn
is_digit
(
c
:
char
)
->
bool
{
...
...
@@ -116,7 +110,7 @@ pub fn is_digit(c: char) -> bool {
/**
* Checks if a character parses as a numeric digit in the given radix.
* Compared to `is_digit()`, this function only recognizes the
ascii
* Compared to `is_digit()`, this function only recognizes the
* characters `0-9`, `a-z` and `A-Z`.
*
* Returns `true` if `c` is a valid digit under `radix`, and `false`
...
...
@@ -163,7 +157,7 @@ pub fn to_digit(c: char, radix: uint) -> Option<uint> {
}
/**
* Converts a number to the
ascii
character representing it.
* Converts a number to the character representing it.
*
* Returns `Some(char)` if `num` represents one digit under `radix`,
* using one character of `0-9` or `a-z`, or `None` if it doesn't.
...
...
@@ -316,12 +310,6 @@ fn test_to_digit() {
assert
!
(
to_digit
(
'$'
,
36u
)
.is_none
());
}
#[test]
fn
test_is_ascii
()
{
assert
!
(
str
::
all
(
~
"banana"
,
is_ascii
));
assert
!
(
!
str
::
all
(
~
"ประเทศไทย中华Việt Nam"
,
is_ascii
));
}
#[test]
fn
test_is_digit
()
{
assert
!
(
is_digit
(
'2'
));
...
...
src/libcore/num/uint-template/u8.rs
浏览文件 @
dd748079
...
...
@@ -10,16 +10,9 @@
//! Operations and constants for `u8`
pub
use
self
::
inst
::
is_ascii
;
mod
inst
{
pub
type
T
=
u8
;
#[allow(non_camel_case_types)]
pub
type
T_SIGNED
=
i8
;
pub
static
bits
:
uint
=
8
;
// Type-specific functions here. These must be reexported by the
// parent module so that they appear in core::u8 and not core::u8::u8;
pub
fn
is_ascii
(
x
:
T
)
->
bool
{
return
0
as
T
==
x
&
128
as
T
;
}
}
src/libcore/path.rs
浏览文件 @
dd748079
...
...
@@ -753,7 +753,9 @@ fn unsafe_join(&self, other: &WindowsPath) -> WindowsPath {
fn
is_restricted
(
&
self
)
->
bool
{
match
self
.filestem
()
{
Some
(
stem
)
=>
{
match
stem
.to_lower
()
{
// FIXME: 4318 Instead of to_str_ascii, could use
// to_str_consume to not do a unneccessary copy.
match
stem
.to_ascii
()
.to_lower
()
.to_str_ascii
()
{
~
"con"
|
~
"aux"
|
~
"com1"
|
~
"com2"
|
~
"com3"
|
~
"com4"
|
~
"lpt1"
|
~
"lpt2"
|
~
"lpt3"
|
~
"prn"
|
~
"nul"
=>
true
,
_
=>
false
...
...
@@ -809,7 +811,10 @@ fn normalize(&self) -> WindowsPath {
host
:
copy
self
.host
,
device
:
match
self
.device
{
None
=>
None
,
Some
(
ref
device
)
=>
Some
(
device
.to_upper
())
// FIXME: 4318 Instead of to_str_ascii, could use
// to_str_consume to not do a unneccessary copy.
Some
(
ref
device
)
=>
Some
(
device
.to_ascii
()
.to_upper
()
.to_str_ascii
())
},
is_absolute
:
self
.is_absolute
,
components
:
normalize
(
self
.components
)
...
...
src/libcore/str.rs
浏览文件 @
dd748079
...
...
@@ -787,22 +787,6 @@ enum LengthLimit {
}
}
/// Convert a string to lowercase. ASCII only
pub
fn
to_lower
(
s
:
&
str
)
->
~
str
{
do
map
(
s
)
|
c
|
{
assert
!
(
char
::
is_ascii
(
c
));
(
unsafe
{
libc
::
tolower
(
c
as
libc
::
c_char
)})
as
char
}
}
/// Convert a string to uppercase. ASCII only
pub
fn
to_upper
(
s
:
&
str
)
->
~
str
{
do
map
(
s
)
|
c
|
{
assert
!
(
char
::
is_ascii
(
c
));
(
unsafe
{
libc
::
toupper
(
c
as
libc
::
c_char
)})
as
char
}
}
/**
* Replace all occurrences of one string with another
*
...
...
@@ -1610,13 +1594,6 @@ pub fn ends_with<'a,'b>(haystack: &'a str, needle: &'b str) -> bool {
Section: String properties
*/
/// Determines if a string contains only ASCII characters
pub
fn
is_ascii
(
s
:
&
str
)
->
bool
{
let
mut
i
:
uint
=
len
(
s
);
while
i
>
0u
{
i
-=
1u
;
if
!
u8
::
is_ascii
(
s
[
i
])
{
return
false
;
}
}
return
true
;
}
/// Returns true if the string has length 0
pub
fn
is_empty
(
s
:
&
str
)
->
bool
{
len
(
s
)
==
0u
}
...
...
@@ -2403,8 +2380,6 @@ pub trait StrSlice<'self> {
fn
each_split_str
<
'a
>
(
&
self
,
sep
:
&
'a
str
,
it
:
&
fn
(
&
'self
str
)
->
bool
);
fn
starts_with
<
'a
>
(
&
self
,
needle
:
&
'a
str
)
->
bool
;
fn
substr
(
&
self
,
begin
:
uint
,
n
:
uint
)
->
&
'self
str
;
fn
to_lower
(
&
self
)
->
~
str
;
fn
to_upper
(
&
self
)
->
~
str
;
fn
escape_default
(
&
self
)
->
~
str
;
fn
escape_unicode
(
&
self
)
->
~
str
;
fn
trim
(
&
self
)
->
&
'self
str
;
...
...
@@ -2565,12 +2540,6 @@ fn starts_with<'a>(&self, needle: &'a str) -> bool {
fn
substr
(
&
self
,
begin
:
uint
,
n
:
uint
)
->
&
'self
str
{
substr
(
*
self
,
begin
,
n
)
}
/// Convert a string to lowercase
#[inline]
fn
to_lower
(
&
self
)
->
~
str
{
to_lower
(
*
self
)
}
/// Convert a string to uppercase
#[inline]
fn
to_upper
(
&
self
)
->
~
str
{
to_upper
(
*
self
)
}
/// Escape each char in `s` with char::escape_default.
#[inline]
fn
escape_default
(
&
self
)
->
~
str
{
escape_default
(
*
self
)
}
...
...
@@ -3084,27 +3053,6 @@ fn test_repeat() {
assert
!
(
repeat
(
~
"hi"
,
0
)
==
~
""
);
}
#[test]
fn
test_to_upper
()
{
// libc::toupper, and hence str::to_upper
// are culturally insensitive: they only work for ASCII
// (see Issue #1347)
let
unicode
=
~
""
;
//"\u65e5\u672c"; // uncomment once non-ASCII works
let
input
=
~
"abcDEF"
+
unicode
+
~
"xyz:.;"
;
let
expected
=
~
"ABCDEF"
+
unicode
+
~
"XYZ:.;"
;
let
actual
=
to_upper
(
input
);
assert
!
(
expected
==
actual
);
}
#[test]
fn
test_to_lower
()
{
// libc::tolower, and hence str::to_lower
// are culturally insensitive: they only work for ASCII
// (see Issue #1347)
assert
!
(
~
""
==
to_lower
(
""
));
assert
!
(
~
"ymca"
==
to_lower
(
"YMCA"
));
}
#[test]
fn
test_unsafe_slice
()
{
assert
!
(
"ab"
==
unsafe
{
raw
::
slice_bytes
(
"abc"
,
0
,
2
)});
...
...
@@ -3337,13 +3285,6 @@ fn test_is_whitespace() {
assert
!
((
!
is_whitespace
(
~
" _ "
)));
}
#[test]
fn
test_is_ascii
()
{
assert
!
((
is_ascii
(
~
""
)));
assert
!
((
is_ascii
(
~
"a"
)));
assert
!
((
!
is_ascii
(
~
"
\u2009
"
)));
}
#[test]
fn
test_shift_byte
()
{
let
mut
s
=
~
"ABC"
;
...
...
src/libcore/str/ascii.rs
浏览文件 @
dd748079
...
...
@@ -221,6 +221,9 @@ fn test_ascii() {
assert_eq!
(
'['
.to_ascii
()
.to_lower
()
.to_char
(),
'['
);
assert_eq!
(
'`'
.to_ascii
()
.to_upper
()
.to_char
(),
'`'
);
assert_eq!
(
'{'
.to_ascii
()
.to_upper
()
.to_char
(),
'{'
);
assert
!
(
str
::
all
(
~
"banana"
,
|
c
|
c
.is_ascii
()));
assert
!
(
!
str
::
all
(
~
"ประเทศไทย中华Việt Nam"
,
|
c
|
c
.is_ascii
()));
}
#[test]
...
...
@@ -234,6 +237,15 @@ fn test_ascii_vec() {
assert_eq!
(
"abCDef&?#"
.to_ascii
()
.to_lower
()
.to_str_ascii
(),
~
"abcdef&?#"
);
assert_eq!
(
"abCDef&?#"
.to_ascii
()
.to_upper
()
.to_str_ascii
(),
~
"ABCDEF&?#"
);
assert_eq!
(
""
.to_ascii
()
.to_lower
()
.to_str_ascii
(),
~
""
);
assert_eq!
(
"YMCA"
.to_ascii
()
.to_lower
()
.to_str_ascii
(),
~
"ymca"
);
assert_eq!
(
"abcDEFxyz:.;"
.to_ascii
()
.to_upper
()
.to_str_ascii
(),
~
"ABCDEFXYZ:.;"
);
assert
!
(
""
.is_ascii
());
assert
!
(
"a"
.is_ascii
());
assert
!
(
!
"
\u2009
"
.is_ascii
());
}
#[test]
...
...
src/libcore/unstable/extfmt.rs
浏览文件 @
dd748079
...
...
@@ -520,7 +520,10 @@ pub fn conv_uint(cv: Conv, u: uint, buf: &mut ~str) {
match
cv
.ty
{
TyDefault
=>
uint_to_str_prec
(
u
,
10
,
prec
),
TyHexLower
=>
uint_to_str_prec
(
u
,
16
,
prec
),
TyHexUpper
=>
str
::
to_upper
(
uint_to_str_prec
(
u
,
16
,
prec
)),
// FIXME: 4318 Instead of to_str_ascii, could use
// to_str_consume to not do a unneccessary copy.
TyHexUpper
=>
uint_to_str_prec
(
u
,
16
,
prec
)
.to_ascii
()
.to_upper
()
.to_str_ascii
(),
TyBits
=>
uint_to_str_prec
(
u
,
2
,
prec
),
TyOctal
=>
uint_to_str_prec
(
u
,
8
,
prec
)
};
...
...
src/librustc/driver/driver.rs
浏览文件 @
dd748079
...
...
@@ -546,7 +546,10 @@ pub fn build_session_options(binary: @~str,
let
lint_dict
=
lint
::
get_lint_dict
();
for
lint_levels
.each
|
level
|
{
let
level_name
=
lint
::
level_to_str
(
*
level
);
let
level_short
=
level_name
.substr
(
0
,
1
)
.to_upper
();
// FIXME: 4318 Instead of to_str_ascii, could use
// to_str_consume to not do a unneccessary copy.
let
level_short
=
level_name
.substr
(
0
,
1
)
.to_ascii
()
.to_upper
()
.to_str_ascii
();
let
flags
=
vec
::
append
(
getopts
::
opt_strs
(
matches
,
level_short
),
getopts
::
opt_strs
(
matches
,
level_name
));
for
flags
.each
|
lint_name
|
{
...
...
src/librustdoc/markdown_index_pass.rs
浏览文件 @
dd748079
...
...
@@ -157,7 +157,9 @@ fn replace_with_hyphens(s: &str) -> ~str {
let
s
=
str
::
replace
(
s
,
~
" "
,
~
"-"
);
return
s
;
}
fn
convert_to_lowercase
(
s
:
&
str
)
->
~
str
{
str
::
to_lower
(
s
)
}
// FIXME: 4318 Instead of to_str_ascii, could use
// to_str_consume to not do a unneccessary copy.
fn
convert_to_lowercase
(
s
:
&
str
)
->
~
str
{
s
.to_ascii
()
.to_lower
()
.to_str_ascii
()
}
fn
remove_up_to_first_letter
(
s
:
&
str
)
->
~
str
{
s
.to_str
()
}
fn
maybe_use_section_id
(
s
:
&
str
)
->
~
str
{
s
.to_str
()
}
}
...
...
src/libstd/semver.rs
浏览文件 @
dd748079
...
...
@@ -220,7 +220,7 @@ fn parse_reader(rdr: @io::Reader) -> Version {
pub
fn
parse
(
s
:
&
str
)
->
Option
<
Version
>
{
if
!
str
::
is_ascii
(
s
)
{
if
!
s
.is_ascii
(
)
{
return
None
;
}
let
s
=
s
.trim
();
...
...
src/libstd/sort.rs
浏览文件 @
dd748079
...
...
@@ -885,8 +885,12 @@ fn test_merge_sort_stability() {
// tjc: funny that we have to use parens
fn
ile
(
x
:
&
(
&
'static
str
),
y
:
&
(
&
'static
str
))
->
bool
{
let
x
=
x
.to_lower
();
let
y
=
y
.to_lower
();
// FIXME: 4318 Instead of to_str_ascii, could use
// to_str_consume to not do a unneccessary copy.
// (Actually, could just remove the to_str_* call, but needs an deriving(Ord) on
// Ascii)
let
x
=
x
.to_ascii
()
.to_lower
()
.to_str_ascii
();
let
y
=
y
.to_ascii
()
.to_lower
()
.to_str_ascii
();
x
<=
y
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录