mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-28 09:44:08 +00:00
std: replace str::{any,all}_between with the iterator equivalent.
This commit is contained in:
parent
0cfc08d81e
commit
7281fb948a
@ -37,6 +37,7 @@
|
||||
|
||||
use core::prelude::*;
|
||||
|
||||
use core::iterator::IteratorUtil;
|
||||
use core::str;
|
||||
use core::uint;
|
||||
use core::vec;
|
||||
@ -1079,9 +1080,7 @@ pub mod node {
|
||||
|
||||
pub fn loop_chars(node: @Node, it: &fn(c: char) -> bool) -> bool {
|
||||
return loop_leaves(node,|leaf| {
|
||||
str::all_between(*leaf.content,
|
||||
leaf.byte_offset,
|
||||
leaf.byte_len, it)
|
||||
leaf.content.slice(leaf.byte_offset, leaf.byte_len).iter().all(it)
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1623,66 +1623,6 @@ pub fn char_at_reverse(s: &str, i: uint) -> char {
|
||||
char_range_at_reverse(s, i).ch
|
||||
}
|
||||
|
||||
/**
|
||||
* Loop through a substring, char by char
|
||||
*
|
||||
* # Safety note
|
||||
*
|
||||
* * This function does not check whether the substring is valid.
|
||||
* * This function fails if `start` or `end` do not
|
||||
* represent valid positions inside `s`
|
||||
*
|
||||
* # Arguments
|
||||
*
|
||||
* * s - A string to traverse. It may be empty.
|
||||
* * start - The byte offset at which to start in the string.
|
||||
* * end - The end of the range to traverse
|
||||
* * it - A block to execute with each consecutive character of `s`.
|
||||
* Return `true` to continue, `false` to stop.
|
||||
*
|
||||
* # Return value
|
||||
*
|
||||
* `true` If execution proceeded correctly, `false` if it was interrupted,
|
||||
* that is if `it` returned `false` at any point.
|
||||
*/
|
||||
pub fn all_between(s: &str, start: uint, end: uint,
|
||||
it: &fn(char) -> bool) -> bool {
|
||||
assert!(is_char_boundary(s, start));
|
||||
let mut i = start;
|
||||
while i < end {
|
||||
let CharRange {ch, next} = char_range_at(s, i);
|
||||
if !it(ch) { return false; }
|
||||
i = next;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loop through a substring, char by char
|
||||
*
|
||||
* # Safety note
|
||||
*
|
||||
* * This function does not check whether the substring is valid.
|
||||
* * This function fails if `start` or `end` do not
|
||||
* represent valid positions inside `s`
|
||||
*
|
||||
* # Arguments
|
||||
*
|
||||
* * s - A string to traverse. It may be empty.
|
||||
* * start - The byte offset at which to start in the string.
|
||||
* * end - The end of the range to traverse
|
||||
* * it - A block to execute with each consecutive character of `s`.
|
||||
* Return `true` to continue, `false` to stop.
|
||||
*
|
||||
* # Return value
|
||||
*
|
||||
* `true` if `it` returns `true` for any character
|
||||
*/
|
||||
pub fn any_between(s: &str, start: uint, end: uint,
|
||||
it: &fn(char) -> bool) -> bool {
|
||||
!all_between(s, start, end, |c| !it(c))
|
||||
}
|
||||
|
||||
// UTF-8 tags and ranges
|
||||
static tag_cont_u8: u8 = 128u8;
|
||||
static tag_cont: uint = 128u;
|
||||
|
@ -307,7 +307,7 @@ fn consume_any_line_comment(rdr: @mut StringReader)
|
||||
|
||||
pub fn is_block_non_doc_comment(s: &str) -> bool {
|
||||
assert!(s.len() >= 1u);
|
||||
str::all_between(s, 1u, s.len() - 1u, |ch| ch == '*')
|
||||
s.slice(1u, s.len() - 1u).iter().all(|ch| ch == '*')
|
||||
}
|
||||
|
||||
// might return a sugared-doc-attr
|
||||
|
Loading…
Reference in New Issue
Block a user