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
This commit is contained in:
parent
be9129f556
commit
685a434e0a
@ -60,7 +60,6 @@ export
|
||||
hash,
|
||||
|
||||
// Iterating through strings
|
||||
loop_chars,
|
||||
all,
|
||||
any,
|
||||
map,
|
||||
@ -94,7 +93,7 @@ export
|
||||
utf8_char_width,
|
||||
char_range_at,
|
||||
char_at,
|
||||
loop_chars_sub,
|
||||
substr_all,
|
||||
escape_char,
|
||||
as_buf,
|
||||
//buf,
|
||||
@ -741,7 +740,7 @@ Escapes special characters inside the string, making it safe for transfer.
|
||||
*/
|
||||
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 @@ Function: is_whitespace
|
||||
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 @@ Pluck a character out of a string
|
||||
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 @@ Safety note:
|
||||
- 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 @@ mod node {
|
||||
|
||||
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 @@ mod tests {
|
||||
|
||||
assert eq(r, r2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user