Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
9e60e2e2
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,发现更多精彩内容 >>
提交
9e60e2e2
编写于
6月 11, 2013
作者:
H
Huon Wilson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
std: convert str::replace to a method.
上级
12750c88
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
64 addition
and
67 deletion
+64
-67
src/compiletest/runtest.rs
src/compiletest/runtest.rs
+3
-3
src/libextra/rope.rs
src/libextra/rope.rs
+0
-1
src/libextra/terminfo/searcher.rs
src/libextra/terminfo/searcher.rs
+1
-1
src/librustc/driver/driver.rs
src/librustc/driver/driver.rs
+1
-2
src/librustc/middle/lint.rs
src/librustc/middle/lint.rs
+1
-2
src/librustc/middle/trans/build.rs
src/librustc/middle/trans/build.rs
+2
-2
src/librustc/rustc.rc
src/librustc/rustc.rc
+1
-1
src/librustdoc/desc_to_brief_pass.rs
src/librustdoc/desc_to_brief_pass.rs
+1
-1
src/librustdoc/escape_pass.rs
src/librustdoc/escape_pass.rs
+1
-1
src/librustdoc/markdown_index_pass.rs
src/librustdoc/markdown_index_pass.rs
+18
-18
src/librustdoc/markdown_pass.rs
src/librustdoc/markdown_pass.rs
+1
-1
src/librustpkg/package_path.rs
src/librustpkg/package_path.rs
+1
-1
src/libstd/str.rs
src/libstd/str.rs
+33
-33
未找到文件。
src/compiletest/runtest.rs
浏览文件 @
9e60e2e2
...
...
@@ -171,8 +171,8 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
if
props
.pp_exact
.is_some
()
{
// Now we have to care about line endings
let
cr
=
~
"
\r
"
;
actual
=
str
::
replace
(
actual
,
cr
,
""
);
expected
=
str
::
replace
(
expected
,
cr
,
""
);
actual
=
actual
.replace
(
cr
,
""
);
expected
=
expected
.replace
(
cr
,
""
);
}
compare_source
(
expected
,
actual
);
...
...
@@ -238,7 +238,7 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) {
// do not optimize debuginfo tests
let
mut
config
=
match
config
.rustcflags
{
Some
(
ref
flags
)
=>
config
{
rustcflags
:
Some
(
str
::
replace
(
*
flags
,
"-O"
,
""
)),
rustcflags
:
Some
(
flags
.replace
(
"-O"
,
""
)),
..
copy
*
config
},
None
=>
copy
*
config
...
...
src/libextra/rope.rs
浏览文件 @
9e60e2e2
...
...
@@ -564,7 +564,6 @@ pub mod node {
use
rope
::
node
;
use
core
::
cast
;
use
core
::
str
;
use
core
::
uint
;
use
core
::
vec
;
...
...
src/libextra/terminfo/searcher.rs
浏览文件 @
9e60e2e2
...
...
@@ -12,7 +12,7 @@
/// Does not support hashed database, only filesystem!
use
core
::
prelude
::
*
;
use
core
::{
os
};
use
core
::{
os
,
str
};
use
core
::
os
::
getenv
;
use
core
::
io
::{
file_reader
,
Reader
};
use
core
::
iterator
::
IteratorUtil
;
...
...
src/librustc/driver/driver.rs
浏览文件 @
9e60e2e2
...
...
@@ -29,7 +29,6 @@
use
core
::
int
;
use
core
::
io
;
use
core
::
os
;
use
core
::
str
;
use
core
::
vec
;
use
extra
::
getopts
::
groups
::{
optopt
,
optmulti
,
optflag
,
optflagopt
};
use
extra
::
getopts
::{
opt_present
};
...
...
@@ -595,7 +594,7 @@ pub fn build_session_options(binary: @~str,
let
flags
=
vec
::
append
(
getopts
::
opt_strs
(
matches
,
level_short
),
getopts
::
opt_strs
(
matches
,
level_name
));
for
flags
.each
|
lint_name
|
{
let
lint_name
=
str
::
replace
(
*
lint_name
,
"-"
,
"_"
);
let
lint_name
=
lint_name
.replace
(
"-"
,
"_"
);
match
lint_dict
.find
(
&
lint_name
)
{
None
=>
{
early_error
(
demitter
,
fmt!
(
"unknown %s flag: %s"
,
...
...
src/librustc/middle/lint.rs
浏览文件 @
9e60e2e2
...
...
@@ -23,7 +23,6 @@
use
core
::
i32
;
use
core
::
i64
;
use
core
::
i8
;
use
core
::
str
;
use
core
::
u16
;
use
core
::
u32
;
use
core
::
u64
;
...
...
@@ -375,7 +374,7 @@ fn span_lint(&self, lint: lint, span: span, msg: &str) {
fmt!
(
"%s [-%c %s%s]"
,
msg
,
match
level
{
warn
=>
'W'
,
deny
=>
'D'
,
forbid
=>
'F'
,
allow
=>
fail!
()
},
s
tr
::
replace
(
self
.lint_to_str
(
lint
),
"_"
,
"-"
),
},
s
elf
.lint_to_str
(
lint
)
.replace
(
"_"
,
"-"
),
if
src
==
Default
{
" (default)"
}
else
{
""
})
},
Node
(
src
)
=>
{
...
...
src/librustc/middle/trans/build.rs
浏览文件 @
9e60e2e2
...
...
@@ -885,9 +885,9 @@ pub fn add_comment(bcx: block, text: &str) {
unsafe
{
let
ccx
=
bcx
.ccx
();
if
ccx
.sess
.asm_comments
()
{
let
sanitized
=
str
::
replace
(
text
,
"$"
,
""
);
let
sanitized
=
text
.replace
(
"$"
,
""
);
let
comment_text
=
~
"# "
+
s
tr
::
replace
(
sanitized
,
"
\n
"
,
"
\n\t
# "
);
s
anitized
.replace
(
"
\n
"
,
"
\n\t
# "
);
let
asm
=
str
::
as_c_str
(
comment_text
,
|
c
|
{
str
::
as_c_str
(
""
,
|
e
|
{
count_insn
(
bcx
,
"inlineasm"
);
...
...
src/librustc/rustc.rc
浏览文件 @
9e60e2e2
...
...
@@ -209,7 +209,7 @@ Available lint options:
io::println(fmt!(" %s %7.7s %s\n",
padded(max_key, "----"), "-------", "-------"));
for lint_dict.each |k, v| {
let k =
str::replace(*k,
"_", "-");
let k =
k.replace(
"_", "-");
io::println(fmt!(" %s %7.7s %s",
padded(max_key, k),
match v.default {
...
...
src/librustdoc/desc_to_brief_pass.rs
浏览文件 @
9e60e2e2
...
...
@@ -108,7 +108,7 @@ fn first_sentence(s: ~str) -> Option<~str> {
let
paras
=
paragraphs
(
s
);
if
!
paras
.is_empty
()
{
let
first_para
=
paras
.head
();
Some
(
str
::
replace
(
first_sentence_
(
*
first_para
),
"
\n
"
,
" "
))
Some
(
first_sentence_
(
*
first_para
)
.replace
(
"
\n
"
,
" "
))
}
else
{
None
}
...
...
src/librustdoc/escape_pass.rs
浏览文件 @
9e60e2e2
...
...
@@ -20,7 +20,7 @@ pub fn mk_pass() -> Pass {
}
fn
escape
(
s
:
&
str
)
->
~
str
{
s
tr
::
replace
(
s
,
"
\\
"
,
"
\\\\
"
)
s
.replace
(
"
\\
"
,
"
\\\\
"
)
}
#[test]
...
...
src/librustdoc/markdown_index_pass.rs
浏览文件 @
9e60e2e2
...
...
@@ -128,24 +128,24 @@ pub fn pandoc_header_id(header: &str) -> ~str {
return
header
;
fn
remove_formatting
(
s
:
&
str
)
->
~
str
{
s
tr
::
replace
(
s
,
"`"
,
""
)
s
.replace
(
"`"
,
""
)
}
fn
remove_punctuation
(
s
:
&
str
)
->
~
str
{
let
s
=
s
tr
::
replace
(
s
,
"<"
,
""
);
let
s
=
s
tr
::
replace
(
s
,
">"
,
""
);
let
s
=
s
tr
::
replace
(
s
,
"["
,
""
);
let
s
=
s
tr
::
replace
(
s
,
"]"
,
""
);
let
s
=
s
tr
::
replace
(
s
,
"("
,
""
);
let
s
=
s
tr
::
replace
(
s
,
")"
,
""
);
let
s
=
s
tr
::
replace
(
s
,
"@~"
,
""
);
let
s
=
s
tr
::
replace
(
s
,
"~"
,
""
);
let
s
=
s
tr
::
replace
(
s
,
"/"
,
""
);
let
s
=
s
tr
::
replace
(
s
,
":"
,
""
);
let
s
=
s
tr
::
replace
(
s
,
"&"
,
""
);
let
s
=
s
tr
::
replace
(
s
,
"^"
,
""
);
let
s
=
s
tr
::
replace
(
s
,
","
,
""
);
let
s
=
s
tr
::
replace
(
s
,
"'"
,
""
);
let
s
=
s
tr
::
replace
(
s
,
"+"
,
""
);
let
s
=
s
.replace
(
"<"
,
""
);
let
s
=
s
.replace
(
">"
,
""
);
let
s
=
s
.replace
(
"["
,
""
);
let
s
=
s
.replace
(
"]"
,
""
);
let
s
=
s
.replace
(
"("
,
""
);
let
s
=
s
.replace
(
")"
,
""
);
let
s
=
s
.replace
(
"@~"
,
""
);
let
s
=
s
.replace
(
"~"
,
""
);
let
s
=
s
.replace
(
"/"
,
""
);
let
s
=
s
.replace
(
":"
,
""
);
let
s
=
s
.replace
(
"&"
,
""
);
let
s
=
s
.replace
(
"^"
,
""
);
let
s
=
s
.replace
(
","
,
""
);
let
s
=
s
.replace
(
"'"
,
""
);
let
s
=
s
.replace
(
"+"
,
""
);
return
s
;
}
fn
replace_with_hyphens
(
s
:
&
str
)
->
~
str
{
...
...
@@ -153,8 +153,8 @@ fn replace_with_hyphens(s: &str) -> ~str {
// XXX: Hacky implementation here that only covers
// one or two spaces.
let
s
=
s
.trim
();
let
s
=
s
tr
::
replace
(
s
,
" "
,
"-"
);
let
s
=
s
tr
::
replace
(
s
,
" "
,
"-"
);
let
s
=
s
.replace
(
" "
,
"-"
);
let
s
=
s
.replace
(
" "
,
"-"
);
return
s
;
}
// FIXME: #4318 Instead of to_ascii and to_str_ascii, could use
...
...
src/librustdoc/markdown_pass.rs
浏览文件 @
9e60e2e2
...
...
@@ -114,7 +114,7 @@ fn make_title(page: doc::Page) -> ~str {
}
};
let
title
=
markdown_pass
::
header_text
(
item
);
let
title
=
str
::
replace
(
title
,
"`"
,
""
);
let
title
=
title
.replace
(
"`"
,
""
);
return
title
;
}
...
...
src/librustpkg/package_path.rs
浏览文件 @
9e60e2e2
...
...
@@ -32,7 +32,7 @@ pub fn normalize(p_: RemotePath) -> LocalPath {
match
p
.filestem
()
{
None
=>
LocalPath
(
p
),
Some
(
st
)
=>
{
let
replaced
=
st
r
::
replace
(
st
,
"-"
,
"_"
);
let
replaced
=
st
.replace
(
"-"
,
"_"
);
if
replaced
!=
st
{
LocalPath
(
p
.with_filestem
(
replaced
))
}
...
...
src/libstd/str.rs
浏览文件 @
9e60e2e2
...
...
@@ -581,30 +581,6 @@ enum LengthLimit {
return
cont
;
}
/**
* Replace all occurrences of one string with another
*
* # Arguments
*
* * s - The string containing substrings to replace
* * from - The string to replace
* * to - The replacement string
*
* # Return value
*
* The original string with all occurances of `from` replaced with `to`
*/
pub
fn
replace
(
s
:
&
str
,
from
:
&
str
,
to
:
&
str
)
->
~
str
{
let
mut
(
result
,
last_end
)
=
(
~
""
,
0
);
for
s
.matches_index_iter
(
from
)
.advance
|(
start
,
end
)|
{
result
.push_str
(
unsafe
{
raw
::
slice_bytes
(
s
,
last_end
,
start
)});
result
.push_str
(
to
);
last_end
=
end
;
}
result
.push_str
(
unsafe
{
raw
::
slice_bytes
(
s
,
last_end
,
s
.len
())});
result
}
/*
Section: Comparing strings
*/
...
...
@@ -1349,6 +1325,7 @@ fn split_options_iter<Sep: CharEq>(&self, sep: Sep, count: uint, allow_trailing_
fn
trim_chars
(
&
self
,
chars_to_trim
:
&
[
char
])
->
&
'self
str
;
fn
trim_left_chars
(
&
self
,
chars_to_trim
:
&
[
char
])
->
&
'self
str
;
fn
trim_right_chars
(
&
self
,
chars_to_trim
:
&
[
char
])
->
&
'self
str
;
fn
replace
(
&
self
,
from
:
&
str
,
to
:
&
str
)
->
~
str
;
fn
to_owned
(
&
self
)
->
~
str
;
fn
to_managed
(
&
self
)
->
@
str
;
fn
is_char_boundary
(
&
self
,
index
:
uint
)
->
bool
;
...
...
@@ -1694,6 +1671,29 @@ fn trim_right_chars(&self, chars_to_trim: &[char]) -> &'self str {
}
}
/**
* Replace all occurrences of one string with another
*
* # Arguments
*
* * from - The string to replace
* * to - The replacement string
*
* # Return value
*
* The original string with all occurances of `from` replaced with `to`
*/
pub
fn
replace
(
&
self
,
from
:
&
str
,
to
:
&
str
)
->
~
str
{
let
mut
(
result
,
last_end
)
=
(
~
""
,
0
);
for
self
.matches_index_iter
(
from
)
.advance
|(
start
,
end
)|
{
result
.push_str
(
unsafe
{
raw
::
slice_bytes
(
*
self
,
last_end
,
start
)});
result
.push_str
(
to
);
last_end
=
end
;
}
result
.push_str
(
unsafe
{
raw
::
slice_bytes
(
*
self
,
last_end
,
self
.len
())});
result
}
/// Copy a slice into a new unique str
#[inline]
fn
to_owned
(
&
self
)
->
~
str
{
...
...
@@ -2592,13 +2592,13 @@ fn test_is_empty() {
#[test]
fn
test_replace
()
{
let
a
=
"a"
;
assert_eq!
(
replace
(
""
,
a
,
"b"
),
~
""
);
assert_eq!
(
replace
(
"a"
,
a
,
"b"
),
~
"b"
);
assert_eq!
(
replace
(
"ab"
,
a
,
"b"
),
~
"bb"
);
assert_eq!
(
""
.replace
(
a
,
"b"
),
~
""
);
assert_eq!
(
"a"
.replace
(
a
,
"b"
),
~
"b"
);
assert_eq!
(
"ab"
.replace
(
a
,
"b"
),
~
"bb"
);
let
test
=
"test"
;
assert
!
(
replace
(
" test test "
,
test
,
"toast"
)
==
assert
!
(
" test test "
.replace
(
test
,
"toast"
)
==
~
" toast toast "
);
assert_eq!
(
replace
(
" test test "
,
test
,
""
),
~
" "
);
assert_eq!
(
" test test "
.replace
(
test
,
""
),
~
" "
);
}
#[test]
...
...
@@ -2608,7 +2608,7 @@ fn test_replace_2a() {
let
a
=
~
"ประเ"
;
let
A
=
~
"دولة الكويتทศไทย中华"
;
assert_eq!
(
replace
(
data
,
a
,
repl
),
A
);
assert_eq!
(
data
.replace
(
a
,
repl
),
A
);
}
#[test]
...
...
@@ -2618,7 +2618,7 @@ fn test_replace_2b() {
let
b
=
~
"ะเ"
;
let
B
=
~
"ปรدولة الكويتทศไทย中华"
;
assert_eq!
(
replace
(
data
,
b
,
repl
),
B
);
assert_eq!
(
data
.replace
(
b
,
repl
),
B
);
}
#[test]
...
...
@@ -2628,7 +2628,7 @@ fn test_replace_2c() {
let
c
=
~
"中华"
;
let
C
=
~
"ประเทศไทยدولة الكويت"
;
assert_eq!
(
replace
(
data
,
c
,
repl
),
C
);
assert_eq!
(
data
.replace
(
c
,
repl
),
C
);
}
#[test]
...
...
@@ -2637,7 +2637,7 @@ fn test_replace_2d() {
let
repl
=
~
"دولة الكويت"
;
let
d
=
~
"ไท华"
;
assert_eq!
(
replace
(
data
,
d
,
repl
),
data
);
assert_eq!
(
data
.replace
(
d
,
repl
),
data
);
}
#[test]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录