From 7281fb948a48f56e06f9a324d52e70e056071005 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Mon, 10 Jun 2013 16:17:10 +1000 Subject: [PATCH] std: replace str::{any,all}_between with the iterator equivalent. --- src/libextra/rope.rs | 5 ++- src/libstd/str.rs | 60 ------------------------------------ src/libsyntax/parse/lexer.rs | 2 +- 3 files changed, 3 insertions(+), 64 deletions(-) diff --git a/src/libextra/rope.rs b/src/libextra/rope.rs index 1b58aa68f77..9ae8c47ae3c 100644 --- a/src/libextra/rope.rs +++ b/src/libextra/rope.rs @@ -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) }); } diff --git a/src/libstd/str.rs b/src/libstd/str.rs index a7f152a27e5..e68b79575e0 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -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; diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index 04635fdf4e9..2dc8008f8ec 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -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