Merge remote-tracking branch 'Dretch/prettydocs'
Conflicts: src/compiletest/errors.rs src/libsyntax/parse/attr.rs src/libsyntax/parse/comments.rs src/test/compile-fail/ambig_impl_unify.rs src/test/compile-fail/assign-super.rs src/test/compile-fail/bad-for-loop.rs src/test/compile-fail/bad-var-env-capture-in-block-arg.rs src/test/compile-fail/block-arg-as-stmt-with-value.rs src/test/compile-fail/borrowck-assign-comp-idx.rs src/test/compile-fail/borrowck-lend-flow.rs src/test/compile-fail/borrowck-loan-blocks-move-cc.rs src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs src/test/compile-fail/borrowck-loan-rcvr.rs src/test/compile-fail/borrowck-loan-vec-content.rs src/test/compile-fail/borrowck-mut-vec-as-imm-slice-bad.rs src/test/compile-fail/cap-clause-with-stack-closure.rs src/test/compile-fail/do1.rs src/test/compile-fail/do2.rs src/test/compile-fail/empty-vec-trailing-comma.rs src/test/compile-fail/evec-subtyping.rs src/test/compile-fail/issue-1896.rs src/test/compile-fail/issue-2149.rs src/test/compile-fail/issue-2150.rs src/test/compile-fail/issue-2487-b.rs src/test/compile-fail/kindck-implicit-close-over-mut-var.rs src/test/compile-fail/liveness-issue-2163.rs src/test/compile-fail/liveness-use-in-index-lvalue.rs src/test/compile-fail/no-reuse-move-arc.rs src/test/compile-fail/no-send-res-ports.rs src/test/compile-fail/non-const.rs src/test/compile-fail/pure-higher-order.rs src/test/compile-fail/pure-loop-body.rs src/test/compile-fail/regions-addr-of-upvar-self.rs src/test/compile-fail/regions-escape-loop-via-vec.rs src/test/compile-fail/regions-scoping.rs src/test/compile-fail/seq-args.rs src/test/compile-fail/tstate-unsat-in-called-fn-expr.rs src/test/compile-fail/tstate-unsat-in-fn-expr.rs src/test/compile-fail/vec-add.rs src/test/compile-fail/vec-concat-bug.rs src/test/compile-fail/vector-no-ann.rs
This commit is contained in:
commit
569467eb0d
268 changed files with 1051 additions and 656 deletions
|
@ -58,8 +58,8 @@ export
|
|||
all, any,
|
||||
all_between, any_between,
|
||||
map,
|
||||
each,
|
||||
each_char,
|
||||
each, eachi,
|
||||
each_char, each_chari,
|
||||
bytes_iter,
|
||||
chars_iter,
|
||||
split_char_iter,
|
||||
|
@ -73,7 +73,7 @@ export
|
|||
find_char, find_char_from, find_char_between,
|
||||
rfind_char, rfind_char_from, rfind_char_between,
|
||||
find_str, find_str_from, find_str_between,
|
||||
contains,
|
||||
contains, contains_char,
|
||||
starts_with,
|
||||
ends_with,
|
||||
|
||||
|
@ -672,9 +672,15 @@ pure fn bytes_iter(ss: str/&, it: fn(u8)) {
|
|||
#[doc = "Iterate over the bytes in a string"]
|
||||
#[inline(always)]
|
||||
pure fn each(s: str/&, it: fn(u8) -> bool) {
|
||||
eachi(s, |_i, b| it(b) )
|
||||
}
|
||||
|
||||
#[doc = "Iterate over the bytes in a string, with indices"]
|
||||
#[inline(always)]
|
||||
pure fn eachi(s: str/&, it: fn(uint, u8) -> bool) {
|
||||
let mut i = 0u, l = len(s);
|
||||
while (i < l) {
|
||||
if !it(s[i]) { break; }
|
||||
if !it(i, s[i]) { break; }
|
||||
i += 1u;
|
||||
}
|
||||
}
|
||||
|
@ -682,12 +688,19 @@ pure fn each(s: str/&, it: fn(u8) -> bool) {
|
|||
#[doc = "Iterates over the chars in a string"]
|
||||
#[inline(always)]
|
||||
pure fn each_char(s: str/&, it: fn(char) -> bool) {
|
||||
let mut pos = 0u;
|
||||
each_chari(s, |_i, c| it(c))
|
||||
}
|
||||
|
||||
#[doc = "Iterates over the chars in a string, with indices"]
|
||||
#[inline(always)]
|
||||
pure fn each_chari(s: str/&, it: fn(uint, char) -> bool) {
|
||||
let mut pos = 0u, ch_pos = 0u;
|
||||
let len = len(s);
|
||||
while pos < len {
|
||||
let {ch, next} = char_range_at(s, pos);
|
||||
pos = next;
|
||||
if !it(ch) { break; }
|
||||
if !it(ch_pos, ch) { break; }
|
||||
ch_pos += 1u;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1146,6 +1159,18 @@ pure fn contains(haystack: str/&a, needle: str/&b) -> bool {
|
|||
option::is_some(find_str(haystack, needle))
|
||||
}
|
||||
|
||||
#[doc = "
|
||||
Returns true if a string contains a char.
|
||||
|
||||
# Arguments
|
||||
|
||||
* haystack - The string to look in
|
||||
* needle - The char to look for
|
||||
"]
|
||||
pure fn contains_char(haystack: str/&, needle: char) -> bool {
|
||||
option::is_some(find_char(haystack, needle))
|
||||
}
|
||||
|
||||
#[doc = "
|
||||
Returns true if one string starts with another
|
||||
|
||||
|
@ -1879,12 +1904,21 @@ impl extensions/& for str/& {
|
|||
#[doc = "Returns true if one string contains another"]
|
||||
#[inline]
|
||||
fn contains(needle: str/&a) -> bool { contains(self, needle) }
|
||||
#[doc = "Returns true if a string contains a char"]
|
||||
#[inline]
|
||||
fn contains_char(needle: char) -> bool { contains_char(self, needle) }
|
||||
#[doc = "Iterate over the bytes in a string"]
|
||||
#[inline]
|
||||
fn each(it: fn(u8) -> bool) { each(self, it) }
|
||||
#[doc = "Iterate over the bytes in a string, with indices"]
|
||||
#[inline]
|
||||
fn eachi(it: fn(uint, u8) -> bool) { eachi(self, it) }
|
||||
#[doc = "Iterate over the chars in a string"]
|
||||
#[inline]
|
||||
fn each_char(it: fn(char) -> bool) { each_char(self, it) }
|
||||
#[doc = "Iterate over the chars in a string, with indices"]
|
||||
#[inline]
|
||||
fn each_chari(it: fn(uint, char) -> bool) { each_chari(self, it) }
|
||||
#[doc = "Returns true if one string ends with another"]
|
||||
#[inline]
|
||||
fn ends_with(needle: str/&) -> bool { ends_with(self, needle) }
|
||||
|
@ -2644,6 +2678,14 @@ mod tests {
|
|||
assert !contains(data, "ไท华");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_contains_char() {
|
||||
assert contains_char("abc", 'b');
|
||||
assert contains_char("a", 'a');
|
||||
assert !contains_char("abc", 'd');
|
||||
assert !contains_char("", 'a');
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_chars_iter() {
|
||||
let mut i = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue