提交 685a434e 编写于 作者: K Kevin Cantu 提交者: Brian Anderson

Rename str::loop_chars to str::all,

rename str::loop_chars_sub to str::substr_all, and
propagate this change to std::rope and rustdoc's calls to these
上级 be9129f5
......@@ -60,7 +60,6 @@
hash,
// Iterating through strings
loop_chars,
all,
any,
map,
......@@ -94,7 +93,7 @@
utf8_char_width,
char_range_at,
char_at,
loop_chars_sub,
substr_all,
escape_char,
as_buf,
//buf,
......@@ -741,7 +740,7 @@ fn replace(s: str, from: str, to: str) : is_not_empty(from) -> str {
*/
fn escape(s: str) -> str {
let r = "";
loop_chars(s, { |c| r += escape_char(c); true });
all(s, { |c| r += escape_char(c); true });
r
}
......@@ -781,37 +780,14 @@ fn hash(&&s: str) -> uint {
Section: Iterating through strings
*/
/*
Function: loop_chars
Loop through a string, char by char
Parameters:
s - A string to traverse. It may be empty.
it - A block to execute with each consecutive character of `s`.
Return `true` to continue, `false` to stop.
Returns:
`true` If execution proceeded correctly, `false` if it was interrupted,
that is if `it` returned `false` at any point.
FIXME: rename to 'chars_loop' (change? currently a synonym to 'all')
*/
fn loop_chars(s: str, it: fn(char) -> bool) -> bool{
ret loop_chars_sub(s, 0u, byte_len(s), it);
}
/*
Function: all
Return true if a predicate matches all characters or
if the string contains no characters
// FIXME: a synonym to loop_chars
*/
fn all(ss: str, ff: fn(char) -> bool) -> bool {
str::loop_chars(ss, ff)
fn all(s: str, it: fn(char) -> bool) -> bool{
ret substr_all(s, 0u, byte_len(s), it);
}
/*
......@@ -1054,7 +1030,7 @@ fn is_ascii(s: str) -> bool {
Returns true if the string contains only whitespace
*/
fn is_whitespace(s: str) -> bool {
ret loop_chars(s, char::is_whitespace);
ret all(s, char::is_whitespace);
}
/*
......@@ -1270,7 +1246,7 @@ fn char_range_at(s: str, i: uint) -> {ch: char, next: uint} {
fn char_at(s: str, i: uint) -> char { ret char_range_at(s, i).ch; }
/*
Function: loop_chars_sub
Function: substr_all
Loop through a substring, char by char
......@@ -1290,10 +1266,8 @@ fn char_range_at(s: str, i: uint) -> {ch: char, next: uint} {
- This function does not check whether the substring is valid.
- This function fails if `byte_offset` or `byte_len` do not
represent valid positions inside `s`
FIXME: rename to 'substr_all'
*/
fn loop_chars_sub(s: str, byte_offset: uint, byte_len: uint,
fn substr_all(s: str, byte_offset: uint, byte_len: uint,
it: fn(char) -> bool) -> bool {
let i = byte_offset;
let result = true;
......
......@@ -1137,7 +1137,7 @@ fn cmp(a: @node, b: @node) -> int {
fn loop_chars(node: @node, it: fn(char) -> bool) -> bool {
ret loop_leaves(node, {|leaf|
ret str::loop_chars_sub(*leaf.content,
ret str::substr_all(*leaf.content,
leaf.byte_offset,
leaf.byte_len, it)
})
......@@ -1494,4 +1494,4 @@ fn concat1() {
assert eq(r, r2);
}
}
\ No newline at end of file
}
......@@ -47,7 +47,7 @@ fn unindent(s: str) -> str {
} else {
saw_first_line = true;
let spaces = 0u;
str::loop_chars(line) {|char|
str::all(line) {|char|
// Only comparing against space because I wouldn't
// know what to do with mixed whitespace chars
if char == ' ' {
......@@ -117,4 +117,4 @@ fn should_not_ignore_first_line_indent_in_a_single_line_para() {
let s = "line1\n\n line2";
let r = unindent(s);
assert r == "line1\n\n line2";
}
\ No newline at end of file
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册