let line = fi.read_line();
// 2. Split the line into fields ("words").
- let fields = line.word_iter().to_owned_vec();
+ let fields = line.words().to_owned_vec();
// 3. Match the vector of fields against a vector pattern.
match fields {
let fi = FileInput::from_args();
while ! fi.eof() {
let line = fi.read_line();
- let fields = line.word_iter().to_owned_vec();
+ let fields = line.words().to_owned_vec();
match fields {
[a, b] => pairs.push((from_str::<int>(a).unwrap(),
from_str::<int>(b).unwrap())),
let fi = FileInput::from_args();
while ! fi.eof() {
let line = fi.read_line();
- let fields = line.word_iter().to_owned_vec();
+ let fields = line.words().to_owned_vec();
match fields {
[a, b] => pairs.push((from_str::<int>(a).unwrap(),
from_str::<int>(b).unwrap())),
let fi = FileInput::from_args();
while ! fi.eof() {
let line = fi.read_line();
- let fields = line.word_iter().to_owned_vec();
+ let fields = line.words().to_owned_vec();
match fields {
[a, b] => pairs.push((from_str::<int>(a).unwrap(),
from_str::<int>(b).unwrap())),
let fi = FileInput::from_args();
while ! fi.eof() {
let line = fi.read_line();
- let fields = line.word_iter().to_owned_vec();
+ let fields = line.words().to_owned_vec();
match fields {
[a, b] => pairs.push((from_str::<int>(a).unwrap(),
from_str::<int>(b).unwrap())),
let fi = FileInput::from_args();
while ! fi.eof() {
let line = fi.read_line();
- let fields = line.word_iter().to_owned_vec();
+ let fields = line.words().to_owned_vec();
match fields {
[a, b] => pairs.push((from_str::<int>(a).unwrap(),
from_str::<int>(b).unwrap())),
let fi = FileInput::from_args();
while ! fi.eof() {
let line = fi.read_line();
- let fields = line.word_iter().to_owned_vec();
+ let fields = line.words().to_owned_vec();
match fields {
// Delegate parsing ints to helper function that will
fn parse_exec_env(line: &str) -> Option<(~str, ~str)> {
do parse_name_value_directive(line, ~"exec-env").map |nv| {
// nv is either FOO or FOO=BAR
- let mut strs: ~[~str] = nv.splitn_iter('=', 1).map(|s| s.to_owned()).collect();
+ let mut strs: ~[~str] = nv.splitn('=', 1).map(|s| s.to_owned()).collect();
match strs.len() {
1u => (strs.pop(), ~""),
if num_check_lines > 0 {
// Allow check lines to leave parts unspecified (e.g., uninitialized
// bits in the wrong case of an enum) with the notation "[...]".
- let check_fragments: ~[~[&str]] = check_lines.map(|s| s.split_str_iter("[...]").collect());
+ let check_fragments: ~[~[&str]] = check_lines.map(|s| s.split_str("[...]").collect());
// check if each line in props.check_lines appears in the
// output (in order)
let mut i = 0u;
- for line in ProcRes.stdout.line_iter() {
+ for line in ProcRes.stdout.lines() {
let mut rest = line.trim();
let mut first = true;
let mut failed = false;
let mut next_err_idx = 0u;
let mut next_err_pat = &props.error_patterns[next_err_idx];
let mut done = false;
- for line in ProcRes.stderr.line_iter() {
+ for line in ProcRes.stderr.lines() {
if line.contains(*next_err_pat) {
debug!("found error pattern {}", *next_err_pat);
next_err_idx += 1u;
}).collect::<~[~str]>();
fn to_lower( s : &str ) -> ~str {
- let i = s.iter();
+ let i = s.chars();
let c : ~[char] = i.map( |c| {
if c.is_ascii() {
c.to_ascii().to_lower().to_char()
// filename:line1:col1: line2:col2: *warning:* msg
// where line1:col1: is the starting point, line2:col2:
// is the ending point, and * represents ANSI color codes.
- for line in ProcRes.stderr.line_iter() {
+ for line in ProcRes.stderr.lines() {
let mut was_expected = false;
for (i, ee) in expected_errors.iter().enumerate() {
if !found_flags[i] {
fn split_maybe_args(argstr: &Option<~str>) -> ~[~str] {
match *argstr {
Some(ref s) => {
- s.split_iter(' ')
+ s.split(' ')
.filter_map(|s| if s.is_whitespace() {None} else {Some(s.to_owned())})
.collect()
}
let cmdline = make_cmdline("", args.prog, args.args);
// get bare program string
- let mut tvec: ~[~str] = args.prog.split_iter('/').map(|ts| ts.to_owned()).collect();
+ let mut tvec: ~[~str] = args.prog.split('/').map(|ts| ts.to_owned()).collect();
let prog_short = tvec.pop();
// copy to target
Some(~""));
let mut exitcode : int = 0;
- for c in exitcode_out.iter() {
+ for c in exitcode_out.chars() {
if !c.is_digit() { break; }
exitcode = exitcode * 10 + match c {
'0' .. '9' => c as int - ('0' as int),
fn count_extracted_lines(p: &Path) -> uint {
let x = File::open(&p.with_extension("ll")).read_to_end();
let x = str::from_utf8_owned(x);
- x.line_iter().len()
+ x.lines().len()
}
let mut buf: u32 = 0;
let mut modulus = 0;
- let mut it = self.byte_iter().enumerate();
+ let mut it = self.bytes().enumerate();
for (idx, byte) in it {
let val = byte as u32;
}
#[inline]
- pub fn rev_liter<'a>(&'a self) -> Invert<BitvIterator<'a>> {
+ pub fn rev_iter<'a>(&'a self) -> Invert<BitvIterator<'a>> {
self.iter().invert()
}
}
pub fn difference(&self, other: &BitvSet, f: |&uint| -> bool) -> bool {
- for (i, w1, w2) in self.common_iter(other) {
+ for (i, w1, w2) in self.commons(other) {
if !iterate_bits(i, w1 & !w2, |b| f(&b)) {
return false
}
};
/* everything we have that they don't also shows up */
- self.outlier_iter(other).advance(|(mine, i, w)|
+ self.outliers(other).advance(|(mine, i, w)|
!mine || iterate_bits(i, w, |b| f(&b))
)
}
pub fn symmetric_difference(&self, other: &BitvSet, f: |&uint| -> bool)
-> bool {
- for (i, w1, w2) in self.common_iter(other) {
+ for (i, w1, w2) in self.commons(other) {
if !iterate_bits(i, w1 ^ w2, |b| f(&b)) {
return false
}
};
- self.outlier_iter(other).advance(|(_, i, w)| iterate_bits(i, w, |b| f(&b)))
+ self.outliers(other).advance(|(_, i, w)| iterate_bits(i, w, |b| f(&b)))
}
pub fn intersection(&self, other: &BitvSet, f: |&uint| -> bool) -> bool {
- self.common_iter(other).advance(|(i, w1, w2)| iterate_bits(i, w1 & w2, |b| f(&b)))
+ self.commons(other).advance(|(i, w1, w2)| iterate_bits(i, w1 & w2, |b| f(&b)))
}
pub fn union(&self, other: &BitvSet, f: |&uint| -> bool) -> bool {
- for (i, w1, w2) in self.common_iter(other) {
+ for (i, w1, w2) in self.commons(other) {
if !iterate_bits(i, w1 | w2, |b| f(&b)) {
return false
}
};
- self.outlier_iter(other).advance(|(_, i, w)| iterate_bits(i, w, |b| f(&b)))
+ self.outliers(other).advance(|(_, i, w)| iterate_bits(i, w, |b| f(&b)))
}
}
if self.size != other.size {
return false;
}
- for (_, w1, w2) in self.common_iter(other) {
+ for (_, w1, w2) in self.commons(other) {
if w1 != w2 {
return false;
}
}
- for (_, _, w) in self.outlier_iter(other) {
+ for (_, _, w) in self.outliers(other) {
if w != 0 {
return false;
}
}
fn is_subset(&self, other: &BitvSet) -> bool {
- for (_, w1, w2) in self.common_iter(other) {
+ for (_, w1, w2) in self.commons(other) {
if w1 & w2 != w1 {
return false;
}
/* If anything is not ours, then everything is not ours so we're
definitely a subset in that case. Otherwise if there's any stray
ones that 'other' doesn't have, we're not a subset. */
- for (mine, _, w) in self.outlier_iter(other) {
+ for (mine, _, w) in self.outliers(other) {
if !mine {
return true;
} else if w != 0 {
/// both have in common. The three yielded arguments are (bit location,
/// w1, w2) where the bit location is the number of bits offset so far,
/// and w1/w2 are the words coming from the two vectors self, other.
- fn common_iter<'a>(&'a self, other: &'a BitvSet)
+ fn commons<'a>(&'a self, other: &'a BitvSet)
-> Map<'static, ((uint, &'a uint), &'a ~[uint]), (uint, uint, uint),
Zip<Enumerate<vec::VecIterator<'a, uint>>, Repeat<&'a ~[uint]>>> {
let min = num::min(self.bitv.storage.len(), other.bitv.storage.len());
/// The yielded arguments are a `bool`, the bit offset, and a word. The `bool`
/// is true if the word comes from `self`, and `false` if it comes from
/// `other`.
- fn outlier_iter<'a>(&'a self, other: &'a BitvSet)
+ fn outliers<'a>(&'a self, other: &'a BitvSet)
-> Map<'static, ((uint, &'a uint), uint), (bool, uint, uint),
Zip<Enumerate<vec::VecIterator<'a, uint>>, Repeat<uint>>> {
let slen = self.bitv.storage.len();
let mut i_arg = None;
if cur[1] == '-' as u8 {
let tail = cur.slice(2, curlen);
- let tail_eq: ~[&str] = tail.split_iter('=').collect();
+ let tail_eq: ~[&str] = tail.split('=').collect();
if tail_eq.len() <= 1 {
names = ~[Long(tail.to_owned())];
} else {
// Normalize desc to contain words separated by one space character
let mut desc_normalized_whitespace = ~"";
- for word in desc.word_iter() {
+ for word in desc.words() {
desc_normalized_whitespace.push_str(word);
desc_normalized_whitespace.push_char(' ');
}
cont
};
- ss.char_offset_iter().advance(|x| machine(x));
+ ss.char_indices().advance(|x| machine(x));
// Let the automaton 'run out' by supplying trailing whitespace
while cont && match state { B | C => true, A => false } {
let root_len = pat_root.map_default(0u, |p| p.as_vec().len());
let dir_patterns = pattern.slice_from(root_len.min(&pattern.len()))
- .split_terminator_iter(is_sep).map(|s| Pattern::new(s)).to_owned_vec();
+ .split_terminator(is_sep).map(|s| Pattern::new(s)).to_owned_vec();
let todo = list_dir_sorted(&root).move_iter().map(|x|(x,0u)).to_owned_vec();
*/
pub fn new(pattern: &str) -> Pattern {
- let chars = pattern.iter().to_owned_vec();
+ let chars = pattern.chars().to_owned_vec();
let mut tokens = ~[];
let mut i = 0;
*/
pub fn escape(s: &str) -> ~str {
let mut escaped = ~"";
- for c in s.iter() {
+ for c in s.chars() {
match c {
// note that ! does not need escaping because it is only special inside brackets
'?' | '*' | '[' | ']' => {
let pats = ["[a-z123]", "[1a-z23]", "[123a-z]"];
for &p in pats.iter() {
let pat = Pattern::new(p);
- for c in "abcdefghijklmnopqrstuvwxyz".iter() {
+ for c in "abcdefghijklmnopqrstuvwxyz".chars() {
assert!(pat.matches(c.to_str()));
}
- for c in "ABCDEFGHIJKLMNOPQRSTUVWXYZ".iter() {
+ for c in "ABCDEFGHIJKLMNOPQRSTUVWXYZ".chars() {
let options = MatchOptions {case_sensitive: false, .. MatchOptions::new()};
assert!(pat.matches_with(c.to_str(), options));
}
let mut modulus = 0;
let mut buf = 0u8;
- for (idx, byte) in self.byte_iter().enumerate() {
+ for (idx, byte) in self.bytes().enumerate() {
buf <<= 4;
match byte as char {
fn escape_str(s: &str) -> ~str {
let mut escaped = ~"\"";
- for c in s.iter() {
+ for c in s.chars() {
match c {
'"' => escaped.push_str("\\\""),
'\\' => escaped.push_str("\\\\"),
}
fn parse_ident(&mut self, ident: &str, value: Json) -> Result<Json, Error> {
- if ident.iter().all(|c| c == self.next_char()) {
+ if ident.chars().all(|c| c == self.next_char()) {
self.bump();
Ok(value)
} else {
/// Decodes a json value from an `&mut io::Reader`
pub fn from_reader(rdr: &mut io::Reader) -> Result<Json, Error> {
let s = str::from_utf8(rdr.read_to_end());
- let mut parser = Parser(~s.iter());
+ let mut parser = Parser(~s.chars());
parser.parse()
}
/// Decodes a json value from a string
pub fn from_str(s: &str) -> Result<Json, Error> {
- let mut parser = Parser(~s.iter());
+ let mut parser = Parser(~s.chars());
parser.parse()
}
fn read_char(&mut self) -> char {
let s = self.read_str();
{
- let mut it = s.iter();
+ let mut it = s.chars();
match (it.next(), it.next()) {
// exactly one character
(Some(c), None) => return c,
FromStr for Ratio<T> {
/// Parses `numer/denom`.
fn from_str(s: &str) -> Option<Ratio<T>> {
- let split: ~[&str] = s.splitn_iter('/', 1).collect();
+ let split: ~[&str] = s.splitn('/', 1).collect();
if split.len() < 2 {
return None
}
FromStrRadix for Ratio<T> {
/// Parses `numer/denom` where the numbers are in base `radix`.
fn from_str_radix(s: &str, radix: uint) -> Option<Ratio<T>> {
- let split: ~[&str] = s.splitn_iter('/', 1).collect();
+ let split: ~[&str] = s.splitn('/', 1).collect();
if split.len() < 2 {
None
} else {
fn take_ident<T: Iterator<char>>(rdr: &mut T) -> (Identifier, Option<char>) {
let (s,ch) = take_nonempty_prefix(rdr, char::is_alphanumeric);
- if s.iter().all(char::is_digit) {
+ if s.chars().all(char::is_digit) {
match from_str::<uint>(s) {
None => { bad_parse::cond.raise(()); (Numeric(0), ch) },
Some(i) => (Numeric(i), ch)
let s = s.trim();
let mut bad = false;
do bad_parse::cond.trap(|_| { debug!("bad"); bad = true }).inside {
- let v = parse_iter(&mut s.iter());
+ let v = parse_iter(&mut s.chars());
if bad || v.to_str() != s.to_owned() {
None
} else {
}
let names_str = str::from_utf8(file.read_bytes(names_bytes as uint - 1)); // don't read NUL
- let term_names: ~[~str] = names_str.split_iter('|').map(|s| s.to_owned()).collect();
+ let term_names: ~[~str] = names_str.split('|').map(|s| s.to_owned()).collect();
file.read_byte(); // consume NUL
dirs_to_search.push(homedir.unwrap().join(".terminfo"))
}
match getenv("TERMINFO_DIRS") {
- Some(dirs) => for i in dirs.split_iter(':') {
+ Some(dirs) => for i in dirs.split(':') {
if i == "" {
dirs_to_search.push(Path::new("/usr/share/terminfo"));
} else {
match maybestr {
None => None,
Some(s) => {
- match s.split_iter('.').to_owned_vec() {
+ match s.split('.').to_owned_vec() {
[a, b] => match (from_str::<uint>(a), from_str::<uint>(b)) {
(Some(a), Some(b)) => Some((a,b)),
_ => None
pub fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
fn match_str(s: &str, pos: uint, needle: &str) -> bool {
let mut i = pos;
- for ch in needle.byte_iter() {
+ for ch in needle.bytes() {
if s[i] != ch {
return false;
}
/// Return a lazy iterator to the first key-value pair whose key is not less than `k`
/// If all keys in map are less than `k` an empty iterator is returned.
- pub fn lower_bound_iter<'a>(&'a self, k: &K) -> TreeMapIterator<'a, K, V> {
+ pub fn lower_bound<'a>(&'a self, k: &K) -> TreeMapIterator<'a, K, V> {
let mut iter: TreeMapIterator<'a, K, V> = self.iter_for_traversal();
loop {
match iter.node {
/// Return a lazy iterator to the first key-value pair whose key is greater than `k`
/// If all keys in map are not greater than `k` an empty iterator is returned.
- pub fn upper_bound_iter<'a>(&'a self, k: &K) -> TreeMapIterator<'a, K, V> {
+ pub fn upper_bound<'a>(&'a self, k: &K) -> TreeMapIterator<'a, K, V> {
let mut iter: TreeMapIterator<'a, K, V> = self.iter_for_traversal();
loop {
match iter.node {
/// Get a lazy iterator pointing to the first value not less than `v` (greater or equal).
/// If all elements in the set are less than `v` empty iterator is returned.
#[inline]
- pub fn lower_bound_iter<'a>(&'a self, v: &T) -> TreeSetIterator<'a, T> {
- TreeSetIterator{iter: self.map.lower_bound_iter(v)}
+ pub fn lower_bound<'a>(&'a self, v: &T) -> TreeSetIterator<'a, T> {
+ TreeSetIterator{iter: self.map.lower_bound(v)}
}
/// Get a lazy iterator pointing to the first value greater than `v`.
/// If all elements in the set are not greater than `v` empty iterator is returned.
#[inline]
- pub fn upper_bound_iter<'a>(&'a self, v: &T) -> TreeSetIterator<'a, T> {
- TreeSetIterator{iter: self.map.upper_bound_iter(v)}
+ pub fn upper_bound<'a>(&'a self, v: &T) -> TreeSetIterator<'a, T> {
+ TreeSetIterator{iter: self.map.upper_bound(v)}
}
/// Visit the values (in-order) representing the difference
}
for i in range(1, 198) {
- let mut lb_it = m.lower_bound_iter(&i);
+ let mut lb_it = m.lower_bound(&i);
let (&k, &v) = lb_it.next().unwrap();
let lb = i + i % 2;
assert_eq!(lb, k);
assert_eq!(lb * 2, v);
- let mut ub_it = m.upper_bound_iter(&i);
+ let mut ub_it = m.upper_bound(&i);
let (&k, &v) = ub_it.next().unwrap();
let ub = i + 2 - i % 2;
assert_eq!(ub, k);
assert_eq!(ub * 2, v);
}
- let mut end_it = m.lower_bound_iter(&199);
+ let mut end_it = m.lower_bound(&199);
assert_eq!(end_it.next(), None);
}
fn query_from_str(rawquery: &str) -> Query {
let mut query: Query = ~[];
if !rawquery.is_empty() {
- for p in rawquery.split_iter('&') {
+ for p in rawquery.split('&') {
let (k, v) = split_char_first(p, '=');
query.push((decode_component(k), decode_component(v)));
};
// returns the scheme and the rest of the url, or a parsing error
pub fn get_scheme(rawurl: &str) -> Result<(~str, ~str), ~str> {
- for (i,c) in rawurl.iter().enumerate() {
+ for (i,c) in rawurl.chars().enumerate() {
match c {
'A' .. 'Z' | 'a' .. 'z' => continue,
'0' .. '9' | '+' | '-' | '.' => {
let mut begin = 2;
let mut end = len;
- for (i,c) in rawurl.iter().enumerate() {
+ for (i,c) in rawurl.chars().enumerate() {
if i < 2 { continue; } // ignore the leading //
// deal with input class first
Result<(~str, ~str), ~str> {
let len = rawurl.len();
let mut end = len;
- for (i,c) in rawurl.iter().enumerate() {
+ for (i,c) in rawurl.chars().enumerate() {
match c {
'A' .. 'Z' | 'a' .. 'z' | '0' .. '9' | '&' |'\'' | '(' | ')' | '.'
| '@' | ':' | '%' | '/' | '+' | '!' | '*' | ',' | ';' | '='
}
// Make sure all chars are either hex digits or hyphen
- for (i, c) in us.iter().enumerate() {
+ for (i, c) in us.chars().enumerate() {
match c {
'0'..'9' | 'A'..'F' | 'a'..'f' | '-' => {},
_ => return Err(ErrorInvalidCharacter(c, i)),
}
// Split string up by hyphens into groups
- let hex_groups: ~[&str] = us.split_str_iter("-").collect();
+ let hex_groups: ~[&str] = us.split_str("-").collect();
// Get the length of each group
let group_lens: ~[uint] = hex_groups.iter().map(|&v| v.len()).collect();
// At this point, we know we have a valid hex string, without hyphens
assert!(vs.len() == 32);
- assert!(vs.iter().all(|c| c.is_digit_radix(16)));
+ assert!(vs.chars().all(|c| c.is_digit_radix(16)));
// Allocate output UUID buffer
let mut ub = [0u8, ..16];
let s = uuid1.to_simple_str();
assert!(s.len() == 32);
- assert!(s.iter().all(|c| c.is_digit_radix(16)));
+ assert!(s.chars().all(|c| c.is_digit_radix(16)));
}
#[test]
let s = uuid1.to_str();
assert!(s.len() == 32);
- assert!(s.iter().all(|c| c.is_digit_radix(16)));
+ assert!(s.chars().all(|c| c.is_digit_radix(16)));
}
#[test]
let s = uuid1.to_hyphenated_str();
assert!(s.len() == 36);
- assert!(s.iter().all(|c| c.is_digit_radix(16) || c == '-'));
+ assert!(s.chars().all(|c| c.is_digit_radix(16) || c == '-'));
}
#[test]
assert!(ss.starts_with("urn:uuid:"));
assert!(s.len() == 36);
- assert!(s.iter().all(|c| c.is_digit_radix(16) || c == '-'));
+ assert!(s.chars().all(|c| c.is_digit_radix(16) || c == '-'));
}
#[test]
let hs = uuid1.to_hyphenated_str();
let ss = uuid1.to_str();
- let hsn = str::from_chars(hs.iter().filter(|&c| c != '-').collect::<~[char]>());
+ let hsn = str::from_chars(hs.chars().filter(|&c| c != '-').collect::<~[char]>());
assert!(hsn == ss);
}
// gas accepts the following characters in symbols: a-z, A-Z, 0-9, ., _, $
pub fn sanitize(s: &str) -> ~str {
let mut result = ~"";
- for c in s.iter() {
+ for c in s.chars() {
match c {
// Escape these with $ sequences
'@' => result.push_str("$SP$"),
use back::rpath::{get_absolute_rpath, get_install_prefix_rpath};
use back::rpath::{minimize_rpaths, rpaths_to_flags, get_rpath_relative_to_output};
- use driver::session;
use syntax::abi;
#[test]
}).move_iter().collect();
let linker = matches.opt_str("linker");
let linker_args = matches.opt_strs("link-args").flat_map( |a| {
- a.split_iter(' ').map(|arg| arg.to_owned()).collect()
+ a.split(' ').map(|arg| arg.to_owned()).collect()
});
let cfg = parse_cfgspecs(matches.opt_strs("cfg"), demitter);
let custom_passes = match matches.opt_str("passes") {
None => ~[],
Some(s) => {
- s.split_iter(|c: char| c == ' ' || c == ',').map(|s| {
+ s.split(|c: char| c == ' ' || c == ',').map(|s| {
s.trim().to_owned()
}).collect()
}
let llvm_args = match matches.opt_str("llvm-args") {
None => ~[],
Some(s) => {
- s.split_iter(|c: char| c == ' ' || c == ',').map(|s| {
+ s.split(|c: char| c == ' ' || c == ',').map(|s| {
s.trim().to_owned()
}).collect()
}
}
pub fn add_used_link_args(cstore: &mut CStore, args: &str) {
- for s in args.split_iter(' ') {
+ for s in args.split(' ') {
cstore.used_link_args.push(s.to_managed());
}
}
let mut env_rust_path: ~[Path] = match get_rust_path() {
Some(env_path) => {
let env_path_components: ~[&str] =
- env_path.split_str_iter(PATH_ENTRY_SEPARATOR).collect();
+ env_path.split_str(PATH_ENTRY_SEPARATOR).collect();
env_path_components.map(|&s| Path::new(s))
}
None => ~[]
// check for lowercase letters rather than non-uppercase
// ones (some scripts don't have a concept of
// upper/lowercase)
- if s.iter().any(|c| c.is_lowercase()) {
+ if s.chars().any(|c| c.is_lowercase()) {
cx.span_lint(non_uppercase_statics, it.span,
"static constant should have an uppercase identifier");
}
// last identifier alone is right choice for this lint.
let ident = path.segments.last().identifier;
let s = cx.tcx.sess.str_of(ident);
- if s.iter().any(|c| c.is_lowercase()) {
+ if s.chars().any(|c| c.is_lowercase()) {
cx.span_lint(non_uppercase_pattern_statics, path.span,
"static constant in pattern should be all caps");
}
// This requires that atomic intrinsics follow a specific naming pattern:
// "atomic_<operation>[_<ordering>], and no ordering means SeqCst
if name.starts_with("atomic_") {
- let split : ~[&str] = name.split_iter('_').collect();
+ let split : ~[&str] = name.split('_').collect();
assert!(split.len() >= 2, "Atomic intrinsic not correct format");
let order = if split.len() == 2 {
lib::llvm::SequentiallyConsistent
let nm = ccx.tcx.sess.str_of(it.ident);
let name = nm.as_slice();
let (n_tps, inputs, output) = if name.starts_with("atomic_") {
- let split : ~[&str] = name.split_iter('_').collect();
+ let split : ~[&str] = name.split('_').collect();
assert!(split.len() >= 2, "Atomic intrinsic not correct format");
//We only care about the operation here
// characters to escape: http://stackoverflow.com/questions/7381974
let pile_o_bits = s.as_slice();
let mut last = 0;
- for (i, ch) in s.byte_iter().enumerate() {
+ for (i, ch) in s.bytes().enumerate() {
match ch as char {
'<' | '>' | '&' | '\'' | '"' => {
fmt.buf.write(pile_o_bits.slice(last, i).as_bytes());
fn clean_srcpath(src: &[u8], f: &fn(&str)) {
let p = Path::new(src);
if p.as_vec() != bytes!(".") {
- for c in p.str_component_iter().map(|x|x.unwrap()) {
+ for c in p.str_components().map(|x|x.unwrap()) {
if ".." == c {
f("up");
} else {
impl<'self> fmt::Default for Source<'self> {
fn fmt(s: &Source<'self>, fmt: &mut fmt::Formatter) {
- let lines = s.line_iter().len();
+ let lines = s.lines().len();
let mut cols = 0;
let mut tmp = lines;
while tmp > 0 {
default_passes = false;
}
clean::NameValue(~"passes", ref value) => {
- for pass in value.word_iter() {
+ for pass in value.words() {
passes.push(pass.to_owned());
}
}
clean::NameValue(~"plugins", ref value) => {
- for p in value.word_iter() {
+ for p in value.words() {
plugins.push(p.to_owned());
}
}
}
pub fn unindent(s: &str) -> ~str {
- let lines = s.any_line_iter().collect::<~[&str]>();
+ let lines = s.lines_any().collect::<~[&str]>();
let mut saw_first_line = false;
let mut saw_second_line = false;
let min_indent = do lines.iter().fold(uint::max_value) |min_indent, line| {
} else {
saw_first_line = true;
let mut spaces = 0;
- do line.iter().all |char| {
+ do line.chars().all |char| {
// Only comparing against space because I wouldn't
// know what to do with mixed whitespace chars
if char == ' ' {
for path in files.iter() {
if path.extension_str() == Some(os::consts::DLL_EXTENSION) {
let stuff : &str = path.filestem_str().expect("has_library: weird path");
- let mut stuff2 = stuff.split_str_iter(&"-");
+ let mut stuff2 = stuff.split_str("-");
let stuff3: ~[&str] = stuff2.collect();
// argh
let chars_to_drop = os::consts::DLL_PREFIX.len();
[sysroot.as_str().unwrap().to_owned(), ~"configs"]);
debug!("run_custom: second pkg command did {:?}", output.status);
// Run the configs() function to get the configs
- let cfgs = str::from_utf8_slice(output.output).word_iter()
+ let cfgs = str::from_utf8_slice(output.output).words()
.map(|w| w.to_owned()).collect();
(cfgs, output.status)
}
self.short_name.as_bytes() != self.path.as_vec()
}
- pub fn prefixes_iter(&self) -> Prefixes {
- prefixes_iter(&self.path)
+ pub fn prefixes(&self) -> Prefixes {
+ prefixes(&self.path)
}
// This is the workcache function name for the *installed*
}
}
-pub fn prefixes_iter(p: &Path) -> Prefixes {
+pub fn prefixes(p: &Path) -> Prefixes {
Prefixes {
- components: p.str_component_iter().map(|x|x.unwrap().to_owned()).to_owned_vec(),
+ components: p.str_components().map(|x|x.unwrap().to_owned()).to_owned_vec(),
remaining: ~[]
}
}
None => {
// See if any of the prefixes of this package ID form a valid package ID
// That is, is this a package ID that points into the middle of a workspace?
- for (prefix, suffix) in id.prefixes_iter() {
+ for (prefix, suffix) in id.prefixes() {
let package_id = PkgId::new(prefix.as_str().unwrap());
let path = build_dir.join(&package_id.path);
debug!("in loop: checking if {} is a directory", path.display());
|| d.is_ancestor_of(&versionize(&id.path, &id.version)) {
// Strip off the package ID
source_workspace = d.clone();
- for _ in id.path.component_iter() {
+ for _ in id.path.components() {
source_workspace.pop();
}
// Strip off the src/ part
Some(local.clone())
}
DirToUse(clone_target) => {
- if pkgid.path.component_iter().nth(1).is_none() {
+ if pkgid.path.components().nth(1).is_none() {
// If a non-URL, don't bother trying to fetch
return None;
}
}
pub fn push_crate(cs: &mut ~[Crate], prefix: uint, p: &Path) {
- let mut it = p.component_iter().peekable();
+ let mut it = p.components().peekable();
if prefix > 0 {
it.nth(prefix-1); // skip elements
}
pub fn find_crates_with_filter(&mut self, filter: &fn(&str) -> bool) {
use conditions::missing_pkg_files::cond;
- let prefix = self.start_dir.component_iter().len();
+ let prefix = self.start_dir.components().len();
debug!("Matching against {}", self.id.short_name);
for pth in fs::walk_dir(&self.start_dir) {
let maybe_known_crate_set = match pth.filename_str() {
let mut result = ~[];
let p_output = command_line_test(args, &os::getcwd());
let test_output = str::from_utf8(p_output.output);
- for s in test_output.split_iter('\n') {
+ for s in test_output.split('\n') {
result.push(s.to_owned());
}
result
Success(r) => r
};
let test_output = str::from_utf8(p_output.output);
- for s in test_output.split_iter('\n') {
+ for s in test_output.split('\n') {
result.push(s.to_owned());
}
result
cfgs: &[~str],
opt: session::OptLevel,
what: OutputType) -> Option<Path> {
- assert!(in_file.component_iter().nth(1).is_some());
+ assert!(in_file.components().nth(1).is_some());
let input = driver::file_input(in_file.clone());
debug!("compile_input: {} / {:?}", in_file.display(), what);
// tjc: by default, use the package ID name as the link name
let mut output = None;
let output_text = str::from_utf8(outp.output);
- for l in output_text.line_iter() {
+ for l in output_text.lines() {
if !l.is_whitespace() {
output = Some(l);
}
~"tag", ~"-l"]);
let output_text = str::from_utf8(outp.output);
debug!("Full output: ( {} ) [{:?}]", output_text, outp.status);
- for l in output_text.line_iter() {
+ for l in output_text.lines() {
debug!("A line of output: {}", l);
if !l.is_whitespace() {
output = Some(l);
let s = s.trim();
debug!("Attempting to parse: {}", s);
let mut parse_state = Start;
- for c in s.iter() {
+ for c in s.chars() {
if char::is_digit(c) {
parse_state = SawDigit;
}
/// Just an approximation
fn is_url_like(p: &Path) -> bool {
// check if there are more than 2 /-separated components
- p.as_vec().split_iter(|b| *b == '/' as u8).nth(2).is_some()
+ p.as_vec().split(|b| *b == '/' as u8).nth(2).is_some()
}
/// If s is of the form foo#bar, where bar is a valid version
/// Otherwise, return None.
pub fn split_version<'a>(s: &'a str) -> Option<(&'a str, Version)> {
// Check for extra '#' characters separately
- if s.split_iter('#').len() > 2 {
+ if s.split('#').len() > 2 {
return None;
}
split_version_general(s, '#')
#[inline]
fn is_ascii(&self) -> bool {
- self.byte_iter().all(|b| b.is_ascii())
+ self.bytes().all(|b| b.is_ascii())
}
}
#[inline]
unsafe fn str_copy_map_bytes(string: &str, map: &'static [u8]) -> ~str {
- let bytes = string.byte_iter().map(|b| map[b]).to_owned_vec();
+ let bytes = string.bytes().map(|b| map[b]).to_owned_vec();
str::raw::from_utf8_owned(bytes)
}
assert_eq!('`'.to_ascii().to_upper().to_char(), '`');
assert_eq!('{'.to_ascii().to_upper().to_char(), '{');
- assert!("banana".iter().all(|c| c.is_ascii()));
- assert!(!"ประเทศไทย中华Việt Nam".iter().all(|c| c.is_ascii()));
+ assert!("banana".chars().all(|c| c.is_ascii()));
+ assert!(!"ประเทศไทย中华Việt Nam".chars().all(|c| c.is_ascii()));
}
#[test]
pub fn new<'a>(s: &'a str) -> Parser<'a> {
Parser {
input: s,
- cur: s.char_offset_iter(),
+ cur: s.char_indices(),
depth: 0,
}
}
}
/// Visit the values representing the difference
- pub fn difference_iter<'a>(&'a self, other: &'a HashSet<T>) -> SetAlgebraIter<'a, T> {
+ pub fn difference<'a>(&'a self, other: &'a HashSet<T>) -> SetAlgebraIter<'a, T> {
Repeat::new(other)
.zip(self.iter())
.filter_map(|(other, elt)| {
}
/// Visit the values representing the symmetric difference
- pub fn symmetric_difference_iter<'a>(&'a self, other: &'a HashSet<T>)
+ pub fn symmetric_difference<'a>(&'a self, other: &'a HashSet<T>)
-> Chain<SetAlgebraIter<'a, T>, SetAlgebraIter<'a, T>> {
- self.difference_iter(other).chain(other.difference_iter(self))
+ self.difference(other).chain(other.difference(self))
}
/// Visit the values representing the intersection
- pub fn intersection_iter<'a>(&'a self, other: &'a HashSet<T>)
+ pub fn intersection<'a>(&'a self, other: &'a HashSet<T>)
-> SetAlgebraIter<'a, T> {
Repeat::new(other)
.zip(self.iter())
}
/// Visit the values representing the union
- pub fn union_iter<'a>(&'a self, other: &'a HashSet<T>)
+ pub fn union<'a>(&'a self, other: &'a HashSet<T>)
-> Chain<HashSetIterator<'a, T>, SetAlgebraIter<'a, T>> {
- self.iter().chain(other.difference_iter(self))
+ self.iter().chain(other.difference(self))
}
}
let mut i = 0;
let expected = [3, 5, 11, 77];
- for x in a.intersection_iter(&b) {
+ for x in a.intersection(&b) {
assert!(expected.contains(x));
i += 1
}
let mut i = 0;
let expected = [1, 5, 11];
- for x in a.difference_iter(&b) {
+ for x in a.difference(&b) {
assert!(expected.contains(x));
i += 1
}
let mut i = 0;
let expected = [-2, 1, 5, 11, 14, 22];
- for x in a.symmetric_difference_iter(&b) {
+ for x in a.symmetric_difference(&b) {
assert!(expected.contains(x));
i += 1
}
let mut i = 0;
let expected = [-2, 1, 3, 5, 9, 11, 13, 16, 19, 24];
- for x in a.union_iter(&b) {
+ for x in a.union(&b) {
assert!(expected.contains(x));
i += 1
}
* Pull the lines of a file into a vector of strings
- let lines = File::open("message.txt").line_iter().to_vec();
+ let lines = File::open("message.txt").lines().to_vec();
* Make an simple HTTP request
return cmd;
fn append_arg(cmd: &mut ~str, arg: &str) {
- let quote = arg.iter().any(|c| c == ' ' || c == '\t');
+ let quote = arg.chars().any(|c| c == ' ' || c == '\t');
if quote {
cmd.push_char('"');
}
fn env_convert(input: ~[~str]) -> ~[(~str, ~str)] {
let mut pairs = ~[];
for p in input.iter() {
- let vs: ~[&str] = p.splitn_iter('=', 1).collect();
+ let vs: ~[&str] = p.splitn('=', 1).collect();
debug!("splitting: len: {}", vs.len());
assert_eq!(vs.len(), 2);
pairs.push((vs[0].to_owned(), vs[1].to_owned()));
Both `PosixPath` and `WindowsPath` implement a trait `GenericPath`, which
contains the set of methods that behave the same for both paths. They each also
implement some methods that could not be expressed in `GenericPath`, yet behave
-identically for both path flavors, such as `.component_iter()`.
+identically for both path flavors, such as `.components()`.
The three main design goals of this module are 1) to avoid unnecessary
allocation, 2) to behave the same regardless of which flavor of path is being
if self.is_absolute() != other.is_absolute() {
false
} else {
- let mut ita = self.component_iter();
- let mut itb = other.component_iter();
+ let mut ita = self.components();
+ let mut itb = other.components();
if bytes!(".") == self.repr {
return itb.next() != Some(bytes!(".."));
}
None
}
} else {
- let mut ita = self.component_iter();
- let mut itb = base.component_iter();
+ let mut ita = self.components();
+ let mut itb = base.components();
let mut comps = ~[];
loop {
match (ita.next(), itb.next()) {
fn ends_with_path(&self, child: &Path) -> bool {
if !child.is_relative() { return false; }
- let mut selfit = self.rev_component_iter();
- let mut childit = child.rev_component_iter();
+ let mut selfit = self.rev_components();
+ let mut childit = child.rev_components();
loop {
match (selfit.next(), childit.next()) {
(Some(a), Some(b)) => if a != b { return false; },
/// Does not distinguish between absolute and relative paths, e.g.
/// /a/b/c and a/b/c yield the same set of components.
/// A path of "/" yields no components. A path of "." yields one component.
- pub fn component_iter<'a>(&'a self) -> ComponentIter<'a> {
+ pub fn components<'a>(&'a self) -> ComponentIter<'a> {
let v = if self.repr[0] == sep_byte {
self.repr.slice_from(1)
} else { self.repr.as_slice() };
- let mut ret = v.split_iter(is_sep_byte);
+ let mut ret = v.split(is_sep_byte);
if v.is_empty() {
// consume the empty "" component
ret.next();
}
/// Returns an iterator that yields each component of the path in reverse.
- /// See component_iter() for details.
- pub fn rev_component_iter<'a>(&'a self) -> RevComponentIter<'a> {
+ /// See components() for details.
+ pub fn rev_components<'a>(&'a self) -> RevComponentIter<'a> {
let v = if self.repr[0] == sep_byte {
self.repr.slice_from(1)
} else { self.repr.as_slice() };
- let mut ret = v.rsplit_iter(is_sep_byte);
+ let mut ret = v.rsplit(is_sep_byte);
if v.is_empty() {
// consume the empty "" component
ret.next();
}
/// Returns an iterator that yields each component of the path as Option<&str>.
- /// See component_iter() for details.
- pub fn str_component_iter<'a>(&'a self) -> StrComponentIter<'a> {
- self.component_iter().map(str::from_utf8_slice_opt)
+ /// See components() for details.
+ pub fn str_components<'a>(&'a self) -> StrComponentIter<'a> {
+ self.components().map(str::from_utf8_slice_opt)
}
/// Returns an iterator that yields each component of the path in reverse as Option<&str>.
- /// See component_iter() for details.
- pub fn rev_str_component_iter<'a>(&'a self) -> RevStrComponentIter<'a> {
- self.rev_component_iter().map(str::from_utf8_slice_opt)
+ /// See components() for details.
+ pub fn rev_str_components<'a>(&'a self) -> RevStrComponentIter<'a> {
+ self.rev_components().map(str::from_utf8_slice_opt)
}
}
let mut comps: ~[&'a [u8]] = ~[];
let mut n_up = 0u;
let mut changed = false;
- for comp in v.split_iter(is_sep_byte) {
+ for comp in v.split(is_sep_byte) {
if comp.is_empty() { changed = true }
else if comp == bytes!(".") { changed = true }
else if comp == bytes!("..") {
}
#[test]
- fn test_component_iter() {
+ fn test_components_iter() {
macro_rules! t(
(s: $path:expr, $exp:expr) => (
{
let path = Path::new($path);
- let comps = path.component_iter().to_owned_vec();
+ let comps = path.components().to_owned_vec();
let exp: &[&str] = $exp;
let exps = exp.iter().map(|x| x.as_bytes()).to_owned_vec();
- assert!(comps == exps, "component_iter: Expected {:?}, found {:?}",
+ assert!(comps == exps, "components: Expected {:?}, found {:?}",
comps, exps);
- let comps = path.rev_component_iter().to_owned_vec();
+ let comps = path.rev_components().to_owned_vec();
let exps = exps.move_rev_iter().to_owned_vec();
- assert!(comps == exps, "rev_component_iter: Expected {:?}, found {:?}",
+ assert!(comps == exps, "rev_components: Expected {:?}, found {:?}",
comps, exps);
}
);
(v: [$($arg:expr),+], [$([$($exp:expr),*]),*]) => (
{
let path = Path::new(b!($($arg),+));
- let comps = path.component_iter().to_owned_vec();
+ let comps = path.components().to_owned_vec();
let exp: &[&[u8]] = [$(b!($($exp),*)),*];
- assert!(comps.as_slice() == exp, "component_iter: Expected {:?}, found {:?}",
+ assert!(comps.as_slice() == exp, "components: Expected {:?}, found {:?}",
comps.as_slice(), exp);
- let comps = path.rev_component_iter().to_owned_vec();
+ let comps = path.rev_components().to_owned_vec();
let exp = exp.rev_iter().map(|&x|x).to_owned_vec();
assert!(comps.as_slice() == exp,
- "rev_component_iter: Expected {:?}, found {:?}",
+ "rev_components: Expected {:?}, found {:?}",
comps.as_slice(), exp);
}
)
}
#[test]
- fn test_str_component_iter() {
+ fn test_str_components() {
macro_rules! t(
(v: [$($arg:expr),+], $exp:expr) => (
{
let path = Path::new(b!($($arg),+));
- let comps = path.str_component_iter().to_owned_vec();
+ let comps = path.str_components().to_owned_vec();
let exp: &[Option<&str>] = $exp;
assert!(comps.as_slice() == exp,
- "str_component_iter: Expected {:?}, found {:?}",
+ "str_components: Expected {:?}, found {:?}",
comps.as_slice(), exp);
- let comps = path.rev_str_component_iter().to_owned_vec();
+ let comps = path.rev_str_components().to_owned_vec();
let exp = exp.rev_iter().map(|&x|x).to_owned_vec();
assert!(comps.as_slice() == exp,
- "rev_str_component_iter: Expected {:?}, found {:?}",
+ "rev_str_components: Expected {:?}, found {:?}",
comps.as_slice(), exp);
}
)
t!(v: ["a/b/c"], [Some("a"), Some("b"), Some("c")]);
t!(v: ["/", 0xff, "/a/", 0x80], [None, Some("a"), None]);
t!(v: ["../../foo", 0xcd, "bar"], [Some(".."), Some(".."), None]);
- // str_component_iter is a wrapper around component_iter, so no need to do
+ // str_components is a wrapper around components, so no need to do
// the full set of tests
}
}
is_vol_relative(self) != is_vol_relative(other) {
false
} else {
- let mut ita = self.str_component_iter().map(|x|x.unwrap());
- let mut itb = other.str_component_iter().map(|x|x.unwrap());
+ let mut ita = self.str_components().map(|x|x.unwrap());
+ let mut itb = other.str_components().map(|x|x.unwrap());
if "." == self.repr {
return itb.next() != Some("..");
}
None
}
} else {
- let mut ita = self.str_component_iter().map(|x|x.unwrap());
- let mut itb = base.str_component_iter().map(|x|x.unwrap());
+ let mut ita = self.str_components().map(|x|x.unwrap());
+ let mut itb = base.str_components().map(|x|x.unwrap());
let mut comps = ~[];
let a_verb = is_verbatim(self);
fn ends_with_path(&self, child: &Path) -> bool {
if !child.is_relative() { return false; }
- let mut selfit = self.str_component_iter().invert();
- let mut childit = child.str_component_iter().invert();
+ let mut selfit = self.str_components().invert();
+ let mut childit = child.str_components().invert();
loop {
match (selfit.next(), childit.next()) {
(Some(a), Some(b)) => if a != b { return false; },
/// \a\b\c and a\b\c.
/// Does not distinguish between absolute and cwd-relative paths, e.g.
/// C:\foo and C:foo.
- pub fn str_component_iter<'a>(&'a self) -> StrComponentIter<'a> {
+ pub fn str_components<'a>(&'a self) -> StrComponentIter<'a> {
let s = match self.prefix {
Some(_) => {
let plen = self.prefix_len();
None if self.repr[0] == sep as u8 => self.repr.slice_from(1),
None => self.repr.as_slice()
};
- let ret = s.split_terminator_iter(sep).map(Some);
+ let ret = s.split_terminator(sep).map(Some);
ret
}
/// Returns an iterator that yields each component of the path in reverse as an Option<&str>
- /// See str_component_iter() for details.
- pub fn rev_str_component_iter<'a>(&'a self) -> RevStrComponentIter<'a> {
- self.str_component_iter().invert()
+ /// See str_components() for details.
+ pub fn rev_str_components<'a>(&'a self) -> RevStrComponentIter<'a> {
+ self.str_components().invert()
}
/// Returns an iterator that yields each component of the path in turn as a &[u8].
- /// See str_component_iter() for details.
- pub fn component_iter<'a>(&'a self) -> ComponentIter<'a> {
+ /// See str_components() for details.
+ pub fn components<'a>(&'a self) -> ComponentIter<'a> {
fn convert<'a>(x: Option<&'a str>) -> &'a [u8] {
#[inline];
x.unwrap().as_bytes()
}
- self.str_component_iter().map(convert)
+ self.str_components().map(convert)
}
/// Returns an iterator that yields each component of the path in reverse as a &[u8].
- /// See str_component_iter() for details.
- pub fn rev_component_iter<'a>(&'a self) -> RevComponentIter<'a> {
+ /// See str_components() for details.
+ pub fn rev_components<'a>(&'a self) -> RevComponentIter<'a> {
fn convert<'a>(x: Option<&'a str>) -> &'a [u8] {
#[inline];
x.unwrap().as_bytes()
}
- self.rev_str_component_iter().map(convert)
+ self.rev_str_components().map(convert)
}
fn equiv_prefix(&self, other: &Path) -> bool {
let mut comps: ~[&'a str] = ~[];
let mut n_up = 0u;
let mut changed = false;
- for comp in s_.split_iter(f) {
+ for comp in s_.split(f) {
if comp.is_empty() { changed = true }
else if comp == "." { changed = true }
else if comp == ".." {
}
#[test]
- fn test_str_component_iter() {
+ fn test_str_components() {
macro_rules! t(
(s: $path:expr, $exp:expr) => (
{
let path = Path::new($path);
- let comps = path.str_component_iter().map(|x|x.unwrap()).to_owned_vec();
+ let comps = path.str_components().map(|x|x.unwrap()).to_owned_vec();
let exp: &[&str] = $exp;
assert!(comps.as_slice() == exp,
- "str_component_iter: Expected {:?}, found {:?}",
+ "str_components: Expected {:?}, found {:?}",
comps.as_slice(), exp);
- let comps = path.rev_str_component_iter().map(|x|x.unwrap()).to_owned_vec();
+ let comps = path.rev_str_components().map(|x|x.unwrap()).to_owned_vec();
let exp = exp.rev_iter().map(|&x|x).to_owned_vec();
assert!(comps.as_slice() == exp,
- "rev_str_component_iter: Expected {:?}, found {:?}",
+ "rev_str_components: Expected {:?}, found {:?}",
comps.as_slice(), exp);
}
);
(v: [$($arg:expr),+], $exp:expr) => (
{
let path = Path::new(b!($($arg),+));
- let comps = path.str_component_iter().map(|x|x.unwrap()).to_owned_vec();
+ let comps = path.str_components().map(|x|x.unwrap()).to_owned_vec();
let exp: &[&str] = $exp;
assert!(comps.as_slice() == exp,
- "str_component_iter: Expected {:?}, found {:?}",
+ "str_components: Expected {:?}, found {:?}",
comps.as_slice(), exp);
- let comps = path.rev_str_component_iter().map(|x|x.unwrap()).to_owned_vec();
+ let comps = path.rev_str_components().map(|x|x.unwrap()).to_owned_vec();
let exp = exp.rev_iter().map(|&x|x).to_owned_vec();
assert!(comps.as_slice() == exp,
- "rev_str_component_iter: Expected {:?}, found {:?}",
+ "rev_str_components: Expected {:?}, found {:?}",
comps.as_slice(), exp);
}
)
}
#[test]
- fn test_component_iter() {
+ fn test_components_iter() {
macro_rules! t(
(s: $path:expr, $exp:expr) => (
{
let path = Path::new($path);
- let comps = path.component_iter().to_owned_vec();
+ let comps = path.components().to_owned_vec();
let exp: &[&[u8]] = $exp;
- assert!(comps.as_slice() == exp, "component_iter: Expected {:?}, found {:?}",
+ assert!(comps.as_slice() == exp, "components: Expected {:?}, found {:?}",
comps.as_slice(), exp);
- let comps = path.rev_component_iter().to_owned_vec();
+ let comps = path.rev_components().to_owned_vec();
let exp = exp.rev_iter().map(|&x|x).to_owned_vec();
assert!(comps.as_slice() == exp,
- "rev_component_iter: Expected {:?}, found {:?}",
+ "rev_components: Expected {:?}, found {:?}",
comps.as_slice(), exp);
}
)
t!(s: "a\\b\\c", [b!("a"), b!("b"), b!("c")]);
t!(s: ".", [b!(".")]);
- // since this is really a wrapper around str_component_iter, those tests suffice
+ // since this is really a wrapper around str_components, those tests suffice
}
}
pub fn write_escaped_slice(&mut self, slice: &str) {
self.writer.write(['"' as u8]);
- for ch in slice.iter() {
+ for ch in slice.chars() {
self.write_escaped_char(ch, true);
}
self.writer.write(['"' as u8]);
use rt::local::Local;
use rt::task;
use rt::task::Task;
-use str::{OwnedStr, StrSlice};
+use str::OwnedStr;
use str;
use uint;
use unstable::raw;
/// Also supports string log levels of error, warn, info, and debug
fn parse_logging_spec(spec: ~str) -> ~[LogDirective]{
let mut dirs = ~[];
- for s in spec.split_iter(',') {
- let parts: ~[&str] = s.split_iter('=').collect();
+ for s in spec.split(',') {
+ let parts: ~[&str] = s.split('=').collect();
let mut log_level;
let mut name = Some(parts[0].to_owned());
match parts.len() {
pub fn abort(msg: &str) -> ! {
let msg = if !msg.is_empty() { msg } else { "aborted" };
- let hash = msg.iter().fold(0, |accum, val| accum + (val as uint) );
+ let hash = msg.chars().fold(0, |accum, val| accum + (val as uint) );
let quote = match hash % 10 {
0 => "
It was from the artists and poets that the pertinent answers came, and I
let mut next_split = None;
if self.only_ascii {
- for (idx, byte) in self.string.byte_iter().enumerate() {
+ for (idx, byte) in self.string.bytes().enumerate() {
if self.sep.matches(byte as char) && byte < 128u8 {
next_split = Some((idx, idx + 1));
break;
}
}
} else {
- for (idx, ch) in self.string.char_offset_iter() {
+ for (idx, ch) in self.string.char_indices() {
if self.sep.matches(ch) {
next_split = Some((idx, self.string.char_range_at(idx).next));
break;
let mut next_split = None;
if self.only_ascii {
- for (idx, byte) in self.string.byte_iter().enumerate().invert() {
+ for (idx, byte) in self.string.bytes().enumerate().invert() {
if self.sep.matches(byte as char) && byte < 128u8 {
next_split = Some((idx, idx + 1));
break;
}
}
} else {
- for (idx, ch) in self.string.char_offset_rev_iter() {
+ for (idx, ch) in self.string.char_indices_rev() {
if self.sep.matches(ch) {
next_split = Some((idx, self.string.char_range_at(idx).next));
break;
pub fn replace(s: &str, from: &str, to: &str) -> ~str {
let mut result = ~"";
let mut last_end = 0;
- for (start, end) in s.matches_index_iter(from) {
+ for (start, end) in s.match_indices(from) {
result.push_str(unsafe{raw::slice_bytes(s, last_end, start)});
result.push_str(to);
last_end = end;
impl<'self> TotalOrd for &'self str {
#[inline]
fn cmp(&self, other: & &'self str) -> Ordering {
- for (s_b, o_b) in self.byte_iter().zip(other.byte_iter()) {
+ for (s_b, o_b) in self.bytes().zip(other.bytes()) {
match s_b.cmp(&o_b) {
Greater => return Greater,
Less => return Less,
/// # Example
///
/// ```rust
- /// let v: ~[char] = "abc åäö".iter().collect();
+ /// let v: ~[char] = "abc åäö".chars().collect();
/// assert_eq!(v, ~['a', 'b', 'c', ' ', 'å', 'ä', 'ö']);
/// ```
- fn iter(&self) -> CharIterator<'self>;
+ fn chars(&self) -> CharIterator<'self>;
/// An iterator over the characters of `self`, in reverse order.
- fn rev_iter(&self) -> CharRevIterator<'self>;
+ fn chars_rev(&self) -> CharRevIterator<'self>;
/// An iterator over the bytes of `self`
- fn byte_iter(&self) -> ByteIterator<'self>;
+ fn bytes(&self) -> ByteIterator<'self>;
/// An iterator over the bytes of `self`, in reverse order
- fn byte_rev_iter(&self) -> ByteRevIterator<'self>;
+ fn bytes_rev(&self) -> ByteRevIterator<'self>;
/// An iterator over the characters of `self` and their byte offsets.
- fn char_offset_iter(&self) -> CharOffsetIterator<'self>;
+ fn char_indices(&self) -> CharOffsetIterator<'self>;
/// An iterator over the characters of `self` and their byte offsets,
/// in reverse order.
- fn char_offset_rev_iter(&self) -> CharOffsetRevIterator<'self>;
+ fn char_indices_rev(&self) -> CharOffsetRevIterator<'self>;
/// An iterator over substrings of `self`, separated by characters
/// matched by `sep`.
/// # Example
///
/// ```rust
- /// let v: ~[&str] = "Mary had a little lamb".split_iter(' ').collect();
+ /// let v: ~[&str] = "Mary had a little lamb".split(' ').collect();
/// assert_eq!(v, ~["Mary", "had", "a", "little", "lamb"]);
///
- /// let v: ~[&str] = "abc1def2ghi".split_iter(|c: char| c.is_digit()).collect();
+ /// let v: ~[&str] = "abc1def2ghi".split(|c: char| c.is_digit()).collect();
/// assert_eq!(v, ~["abc", "def", "ghi"]);
/// ```
- fn split_iter<Sep: CharEq>(&self, sep: Sep) -> CharSplitIterator<'self, Sep>;
+ fn split<Sep: CharEq>(&self, sep: Sep) -> CharSplitIterator<'self, Sep>;
/// An iterator over substrings of `self`, separated by characters
/// matched by `sep`, restricted to splitting at most `count`
/// times.
- fn splitn_iter<Sep: CharEq>(&self, sep: Sep, count: uint) -> CharSplitNIterator<'self, Sep>;
+ fn splitn<Sep: CharEq>(&self, sep: Sep, count: uint) -> CharSplitNIterator<'self, Sep>;
/// An iterator over substrings of `self`, separated by characters
/// matched by `sep`.
///
- /// Equivalent to `split_iter`, except that the trailing substring
+ /// Equivalent to `split`, except that the trailing substring
/// is skipped if empty (terminator semantics).
///
/// # Example
///
/// ```rust
- /// let v: ~[&str] = "A.B.".split_terminator_iter('.').collect();
+ /// let v: ~[&str] = "A.B.".split_terminator('.').collect();
/// assert_eq!(v, ~["A", "B"]);
/// ```
- fn split_terminator_iter<Sep: CharEq>(&self, sep: Sep) -> CharSplitIterator<'self, Sep>;
+ fn split_terminator<Sep: CharEq>(&self, sep: Sep) -> CharSplitIterator<'self, Sep>;
/// An iterator over substrings of `self`, separated by characters
/// matched by `sep`, in reverse order
/// # Example
///
/// ```rust
- /// let v: ~[&str] = "Mary had a little lamb".rsplit_iter(' ').collect();
+ /// let v: ~[&str] = "Mary had a little lamb".rsplit(' ').collect();
/// assert_eq!(v, ~["lamb", "little", "a", "had", "Mary"]);
/// ```
- fn rsplit_iter<Sep: CharEq>(&self, sep: Sep) -> CharRSplitIterator<'self, Sep>;
+ fn rsplit<Sep: CharEq>(&self, sep: Sep) -> CharRSplitIterator<'self, Sep>;
/// An iterator over substrings of `self`, separated by characters
/// matched by `sep`, starting from the end of the string.
/// Restricted to splitting at most `count` times.
- fn rsplitn_iter<Sep: CharEq>(&self, sep: Sep, count: uint) -> CharSplitNIterator<'self, Sep>;
+ fn rsplitn<Sep: CharEq>(&self, sep: Sep, count: uint) -> CharSplitNIterator<'self, Sep>;
/// An iterator over the start and end indices of each match of
/// `sep` within `self`.
- fn matches_index_iter(&self, sep: &'self str) -> MatchesIndexIterator<'self>;
+ fn match_indices(&self, sep: &'self str) -> MatchesIndexIterator<'self>;
/// An iterator over the substrings of `self` separated by `sep`.
///
/// # Example
///
/// ```rust
- /// let v: ~[&str] = "abcXXXabcYYYabc".split_str_iter("abc").collect()
+ /// let v: ~[&str] = "abcXXXabcYYYabc".split_str("abc").collect()
/// assert_eq!(v, ["", "XXX", "YYY", ""]);
/// ```
- fn split_str_iter(&self, &'self str) -> StrSplitIterator<'self>;
+ fn split_str(&self, &'self str) -> StrSplitIterator<'self>;
/// An iterator over the lines of a string (subsequences separated
/// by `\n`).
- fn line_iter(&self) -> CharSplitIterator<'self, char>;
+ fn lines(&self) -> CharSplitIterator<'self, char>;
/// An iterator over the lines of a string, separated by either
/// `\n` or (`\r\n`).
- fn any_line_iter(&self) -> AnyLineIterator<'self>;
+ fn lines_any(&self) -> AnyLineIterator<'self>;
/// An iterator over the words of a string (subsequences separated
/// by any sequence of whitespace).
- fn word_iter(&self) -> WordIterator<'self>;
+ fn words(&self) -> WordIterator<'self>;
/// An Iterator over the string in Unicode Normalization Form D (canonical decomposition)
- fn nfd_iter(&self) -> NormalizationIterator<'self>;
+ fn nfd_chars(&self) -> NormalizationIterator<'self>;
/// An Iterator over the string in Unicode Normalization Form KD (compatibility decomposition)
- fn nfkd_iter(&self) -> NormalizationIterator<'self>;
+ fn nfkd_chars(&self) -> NormalizationIterator<'self>;
/// Returns true if the string contains only whitespace
///
/// ```rust
/// let string = "a\nb\nc";
/// let mut lines = ~[];
- /// for line in string.line_iter() { lines.push(line) }
+ /// for line in string.lines() { lines.push(line) }
///
/// assert!(string.subslice_offset(lines[0]) == 0); // &"a"
/// assert!(string.subslice_offset(lines[1]) == 2); // &"b"
}
#[inline]
- fn iter(&self) -> CharIterator<'self> {
+ fn chars(&self) -> CharIterator<'self> {
CharIterator{string: *self}
}
#[inline]
- fn rev_iter(&self) -> CharRevIterator<'self> {
- self.iter().invert()
+ fn chars_rev(&self) -> CharRevIterator<'self> {
+ self.chars().invert()
}
#[inline]
- fn byte_iter(&self) -> ByteIterator<'self> {
+ fn bytes(&self) -> ByteIterator<'self> {
self.as_bytes().iter().map(|&b| b)
}
#[inline]
- fn byte_rev_iter(&self) -> ByteRevIterator<'self> {
- self.byte_iter().invert()
+ fn bytes_rev(&self) -> ByteRevIterator<'self> {
+ self.bytes().invert()
}
#[inline]
- fn char_offset_iter(&self) -> CharOffsetIterator<'self> {
- CharOffsetIterator{string: *self, iter: self.iter()}
+ fn char_indices(&self) -> CharOffsetIterator<'self> {
+ CharOffsetIterator{string: *self, iter: self.chars()}
}
#[inline]
- fn char_offset_rev_iter(&self) -> CharOffsetRevIterator<'self> {
- self.char_offset_iter().invert()
+ fn char_indices_rev(&self) -> CharOffsetRevIterator<'self> {
+ self.char_indices().invert()
}
#[inline]
- fn split_iter<Sep: CharEq>(&self, sep: Sep) -> CharSplitIterator<'self, Sep> {
+ fn split<Sep: CharEq>(&self, sep: Sep) -> CharSplitIterator<'self, Sep> {
CharSplitIterator {
string: *self,
only_ascii: sep.only_ascii(),
}
#[inline]
- fn splitn_iter<Sep: CharEq>(&self, sep: Sep, count: uint)
+ fn splitn<Sep: CharEq>(&self, sep: Sep, count: uint)
-> CharSplitNIterator<'self, Sep> {
CharSplitNIterator {
- iter: self.split_iter(sep),
+ iter: self.split(sep),
count: count,
invert: false,
}
}
#[inline]
- fn split_terminator_iter<Sep: CharEq>(&self, sep: Sep)
+ fn split_terminator<Sep: CharEq>(&self, sep: Sep)
-> CharSplitIterator<'self, Sep> {
CharSplitIterator {
allow_trailing_empty: false,
- ..self.split_iter(sep)
+ ..self.split(sep)
}
}
#[inline]
- fn rsplit_iter<Sep: CharEq>(&self, sep: Sep) -> CharRSplitIterator<'self, Sep> {
- self.split_iter(sep).invert()
+ fn rsplit<Sep: CharEq>(&self, sep: Sep) -> CharRSplitIterator<'self, Sep> {
+ self.split(sep).invert()
}
#[inline]
- fn rsplitn_iter<Sep: CharEq>(&self, sep: Sep, count: uint)
+ fn rsplitn<Sep: CharEq>(&self, sep: Sep, count: uint)
-> CharSplitNIterator<'self, Sep> {
CharSplitNIterator {
- iter: self.split_iter(sep),
+ iter: self.split(sep),
count: count,
invert: true,
}
}
#[inline]
- fn matches_index_iter(&self, sep: &'self str) -> MatchesIndexIterator<'self> {
+ fn match_indices(&self, sep: &'self str) -> MatchesIndexIterator<'self> {
assert!(!sep.is_empty())
MatchesIndexIterator {
haystack: *self,
}
#[inline]
- fn split_str_iter(&self, sep: &'self str) -> StrSplitIterator<'self> {
+ fn split_str(&self, sep: &'self str) -> StrSplitIterator<'self> {
StrSplitIterator {
- it: self.matches_index_iter(sep),
+ it: self.match_indices(sep),
last_end: 0,
finished: false
}
}
#[inline]
- fn line_iter(&self) -> CharSplitIterator<'self, char> {
- self.split_terminator_iter('\n')
+ fn lines(&self) -> CharSplitIterator<'self, char> {
+ self.split_terminator('\n')
}
- fn any_line_iter(&self) -> AnyLineIterator<'self> {
- do self.line_iter().map |line| {
+ fn lines_any(&self) -> AnyLineIterator<'self> {
+ do self.lines().map |line| {
let l = line.len();
if l > 0 && line[l - 1] == '\r' as u8 { line.slice(0, l - 1) }
else { line }
}
#[inline]
- fn word_iter(&self) -> WordIterator<'self> {
- self.split_iter(char::is_whitespace).filter(|s| !s.is_empty())
+ fn words(&self) -> WordIterator<'self> {
+ self.split(char::is_whitespace).filter(|s| !s.is_empty())
}
#[inline]
- fn nfd_iter(&self) -> NormalizationIterator<'self> {
+ fn nfd_chars(&self) -> NormalizationIterator<'self> {
NormalizationIterator {
- iter: self.iter(),
+ iter: self.chars(),
buffer: ~[],
sorted: false,
kind: NFD
}
#[inline]
- fn nfkd_iter(&self) -> NormalizationIterator<'self> {
+ fn nfkd_chars(&self) -> NormalizationIterator<'self> {
NormalizationIterator {
- iter: self.iter(),
+ iter: self.chars(),
buffer: ~[],
sorted: false,
kind: NFKD
}
#[inline]
- fn is_whitespace(&self) -> bool { self.iter().all(char::is_whitespace) }
+ fn is_whitespace(&self) -> bool { self.chars().all(char::is_whitespace) }
#[inline]
- fn is_alphanumeric(&self) -> bool { self.iter().all(char::is_alphanumeric) }
+ fn is_alphanumeric(&self) -> bool { self.chars().all(char::is_alphanumeric) }
#[inline]
- fn char_len(&self) -> uint { self.iter().len() }
+ fn char_len(&self) -> uint { self.chars().len() }
#[inline]
fn slice(&self, begin: uint, end: uint) -> &'self str {
// This could be even more efficient by not decoding,
// only finding the char boundaries
- for (idx, _) in self.char_offset_iter() {
+ for (idx, _) in self.char_indices() {
if count == begin { begin_byte = Some(idx); }
if count == end { end_byte = Some(idx); break; }
count += 1;
fn escape_default(&self) -> ~str {
let mut out: ~str = ~"";
out.reserve_at_least(self.len());
- for c in self.iter() {
+ for c in self.chars() {
do c.escape_default |c| {
out.push_char(c);
}
fn escape_unicode(&self) -> ~str {
let mut out: ~str = ~"";
out.reserve_at_least(self.len());
- for c in self.iter() {
+ for c in self.chars() {
do c.escape_unicode |c| {
out.push_char(c);
}
fn replace(&self, from: &str, to: &str) -> ~str {
let mut result = ~"";
let mut last_end = 0;
- for (start, end) in self.matches_index_iter(from) {
+ for (start, end) in self.match_indices(from) {
result.push_str(unsafe{raw::slice_bytes(*self, last_end, start)});
result.push_str(to);
last_end = end;
fn to_utf16(&self) -> ~[u16] {
let mut u = ~[];
- for ch in self.iter() {
+ for ch in self.chars() {
// Arithmetic with u32 literals is easier on the eyes than chars.
let mut ch = ch as u32;
fn find<C: CharEq>(&self, search: C) -> Option<uint> {
if search.only_ascii() {
- self.byte_iter().position(|b| search.matches(b as char))
+ self.bytes().position(|b| search.matches(b as char))
} else {
- for (index, c) in self.char_offset_iter() {
+ for (index, c) in self.char_indices() {
if search.matches(c) { return Some(index); }
}
None
fn rfind<C: CharEq>(&self, search: C) -> Option<uint> {
if search.only_ascii() {
- self.byte_iter().rposition(|b| search.matches(b as char))
+ self.bytes().rposition(|b| search.matches(b as char))
} else {
- for (index, c) in self.char_offset_rev_iter() {
+ for (index, c) in self.char_indices_rev() {
if search.matches(c) { return Some(index); }
}
None
if needle.is_empty() {
Some(0)
} else {
- self.matches_index_iter(needle)
+ self.match_indices(needle)
.next()
.map(|(start, _end)| start)
}
let mut dcol = vec::from_fn(tlen + 1, |x| x);
- for (i, sc) in self.iter().enumerate() {
+ for (i, sc) in self.chars().enumerate() {
let mut current = i;
dcol[0] = current + 1;
- for (j, tc) in t.iter().enumerate() {
+ for (j, tc) in t.chars().enumerate() {
let next = dcol[j + 1];
#[test]
fn test_collect() {
let empty = ~"";
- let s: ~str = empty.iter().collect();
+ let s: ~str = empty.chars().collect();
assert_eq!(empty, s);
let data = ~"ประเทศไทย中";
- let s: ~str = data.iter().collect();
+ let s: ~str = data.chars().collect();
assert_eq!(data, s);
}
let data = ~"ประเทศไทย中";
let mut cpy = data.clone();
let other = "abc";
- let mut it = other.iter();
+ let mut it = other.chars();
cpy.extend(&mut it);
assert_eq!(cpy, data + other);
}
let string = "a\nb\nc";
let mut lines = ~[];
- for line in string.line_iter() { lines.push(line) }
+ for line in string.lines() { lines.push(line) }
assert_eq!(string.subslice_offset(lines[0]), 0);
assert_eq!(string.subslice_offset(lines[1]), 2);
assert_eq!(string.subslice_offset(lines[2]), 4);
let v = ~['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m'];
let mut pos = 0;
- let mut it = s.iter();
+ let mut it = s.chars();
for c in it {
assert_eq!(c, v[pos]);
let v = ~['m', 'a', 'N', ' ', 't', 'ệ','i','V','华','中','ย','ท','ไ','ศ'];
let mut pos = 0;
- let mut it = s.rev_iter();
+ let mut it = s.chars_rev();
for c in it {
assert_eq!(c, v[pos]);
#[test]
fn test_iterator_clone() {
let s = "ศไทย中华Việt Nam";
- let mut it = s.iter();
+ let mut it = s.chars();
it.next();
assert!(it.zip(it.clone()).all(|(x,y)| x == y));
}
#[test]
- fn test_byte_iterator() {
+ fn test_bytesator() {
let s = ~"ศไทย中华Việt Nam";
let v = [
224, 184, 168, 224, 185, 132, 224, 184, 151, 224, 184, 162, 228,
];
let mut pos = 0;
- for b in s.byte_iter() {
+ for b in s.bytes() {
assert_eq!(b, v[pos]);
pos += 1;
}
}
#[test]
- fn test_byte_rev_iterator() {
+ fn test_bytes_revator() {
let s = ~"ศไทย中华Việt Nam";
let v = [
224, 184, 168, 224, 185, 132, 224, 184, 151, 224, 184, 162, 228,
];
let mut pos = v.len();
- for b in s.byte_rev_iter() {
+ for b in s.bytes_rev() {
pos -= 1;
assert_eq!(b, v[pos]);
}
}
#[test]
- fn test_char_offset_iterator() {
+ fn test_char_indicesator() {
use iter::*;
let s = "ศไทย中华Việt Nam";
let p = [0, 3, 6, 9, 12, 15, 18, 19, 20, 23, 24, 25, 26, 27];
let v = ['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m'];
let mut pos = 0;
- let mut it = s.char_offset_iter();
+ let mut it = s.char_indices();
for c in it {
assert_eq!(c, (p[pos], v[pos]));
}
#[test]
- fn test_char_offset_rev_iterator() {
+ fn test_char_indices_revator() {
use iter::*;
let s = "ศไทย中华Việt Nam";
let p = [27, 26, 25, 24, 23, 20, 19, 18, 15, 12, 9, 6, 3, 0];
let v = ['m', 'a', 'N', ' ', 't', 'ệ','i','V','华','中','ย','ท','ไ','ศ'];
let mut pos = 0;
- let mut it = s.char_offset_rev_iter();
+ let mut it = s.char_indices_rev();
for c in it {
assert_eq!(c, (p[pos], v[pos]));
fn test_split_char_iterator() {
let data = "\nMäry häd ä little lämb\nLittle lämb\n";
- let split: ~[&str] = data.split_iter(' ').collect();
+ let split: ~[&str] = data.split(' ').collect();
assert_eq!( split, ~["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]);
- let mut rsplit: ~[&str] = data.rsplit_iter(' ').collect();
+ let mut rsplit: ~[&str] = data.rsplit(' ').collect();
rsplit.reverse();
assert_eq!(rsplit, ~["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]);
- let split: ~[&str] = data.split_iter(|c: char| c == ' ').collect();
+ let split: ~[&str] = data.split(|c: char| c == ' ').collect();
assert_eq!( split, ~["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]);
- let mut rsplit: ~[&str] = data.rsplit_iter(|c: char| c == ' ').collect();
+ let mut rsplit: ~[&str] = data.rsplit(|c: char| c == ' ').collect();
rsplit.reverse();
assert_eq!(rsplit, ~["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]);
// Unicode
- let split: ~[&str] = data.split_iter('ä').collect();
+ let split: ~[&str] = data.split('ä').collect();
assert_eq!( split, ~["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]);
- let mut rsplit: ~[&str] = data.rsplit_iter('ä').collect();
+ let mut rsplit: ~[&str] = data.rsplit('ä').collect();
rsplit.reverse();
assert_eq!(rsplit, ~["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]);
- let split: ~[&str] = data.split_iter(|c: char| c == 'ä').collect();
+ let split: ~[&str] = data.split(|c: char| c == 'ä').collect();
assert_eq!( split, ~["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]);
- let mut rsplit: ~[&str] = data.rsplit_iter(|c: char| c == 'ä').collect();
+ let mut rsplit: ~[&str] = data.rsplit(|c: char| c == 'ä').collect();
rsplit.reverse();
assert_eq!(rsplit, ~["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]);
}
fn test_splitn_char_iterator() {
let data = "\nMäry häd ä little lämb\nLittle lämb\n";
- let split: ~[&str] = data.splitn_iter(' ', 3).collect();
+ let split: ~[&str] = data.splitn(' ', 3).collect();
assert_eq!(split, ~["\nMäry", "häd", "ä", "little lämb\nLittle lämb\n"]);
- let split: ~[&str] = data.splitn_iter(|c: char| c == ' ', 3).collect();
+ let split: ~[&str] = data.splitn(|c: char| c == ' ', 3).collect();
assert_eq!(split, ~["\nMäry", "häd", "ä", "little lämb\nLittle lämb\n"]);
// Unicode
- let split: ~[&str] = data.splitn_iter('ä', 3).collect();
+ let split: ~[&str] = data.splitn('ä', 3).collect();
assert_eq!(split, ~["\nM", "ry h", "d ", " little lämb\nLittle lämb\n"]);
- let split: ~[&str] = data.splitn_iter(|c: char| c == 'ä', 3).collect();
+ let split: ~[&str] = data.splitn(|c: char| c == 'ä', 3).collect();
assert_eq!(split, ~["\nM", "ry h", "d ", " little lämb\nLittle lämb\n"]);
}
fn test_rsplitn_char_iterator() {
let data = "\nMäry häd ä little lämb\nLittle lämb\n";
- let mut split: ~[&str] = data.rsplitn_iter(' ', 3).collect();
+ let mut split: ~[&str] = data.rsplitn(' ', 3).collect();
split.reverse();
assert_eq!(split, ~["\nMäry häd ä", "little", "lämb\nLittle", "lämb\n"]);
- let mut split: ~[&str] = data.rsplitn_iter(|c: char| c == ' ', 3).collect();
+ let mut split: ~[&str] = data.rsplitn(|c: char| c == ' ', 3).collect();
split.reverse();
assert_eq!(split, ~["\nMäry häd ä", "little", "lämb\nLittle", "lämb\n"]);
// Unicode
- let mut split: ~[&str] = data.rsplitn_iter('ä', 3).collect();
+ let mut split: ~[&str] = data.rsplitn('ä', 3).collect();
split.reverse();
assert_eq!(split, ~["\nMäry häd ", " little l", "mb\nLittle l", "mb\n"]);
- let mut split: ~[&str] = data.rsplitn_iter(|c: char| c == 'ä', 3).collect();
+ let mut split: ~[&str] = data.rsplitn(|c: char| c == 'ä', 3).collect();
split.reverse();
assert_eq!(split, ~["\nMäry häd ", " little l", "mb\nLittle l", "mb\n"]);
}
fn test_split_char_iterator_no_trailing() {
let data = "\nMäry häd ä little lämb\nLittle lämb\n";
- let split: ~[&str] = data.split_iter('\n').collect();
+ let split: ~[&str] = data.split('\n').collect();
assert_eq!(split, ~["", "Märy häd ä little lämb", "Little lämb", ""]);
- let split: ~[&str] = data.split_terminator_iter('\n').collect();
+ let split: ~[&str] = data.split_terminator('\n').collect();
assert_eq!(split, ~["", "Märy häd ä little lämb", "Little lämb"]);
}
fn test_rev_split_char_iterator_no_trailing() {
let data = "\nMäry häd ä little lämb\nLittle lämb\n";
- let mut split: ~[&str] = data.split_iter('\n').invert().collect();
+ let mut split: ~[&str] = data.split('\n').invert().collect();
split.reverse();
assert_eq!(split, ~["", "Märy häd ä little lämb", "Little lämb", ""]);
- let mut split: ~[&str] = data.split_terminator_iter('\n').invert().collect();
+ let mut split: ~[&str] = data.split_terminator('\n').invert().collect();
split.reverse();
assert_eq!(split, ~["", "Märy häd ä little lämb", "Little lämb"]);
}
#[test]
- fn test_word_iter() {
+ fn test_words() {
let data = "\n \tMäry häd\tä little lämb\nLittle lämb\n";
- let words: ~[&str] = data.word_iter().collect();
+ let words: ~[&str] = data.words().collect();
assert_eq!(words, ~["Märy", "häd", "ä", "little", "lämb", "Little", "lämb"])
}
#[test]
- fn test_nfd_iter() {
- assert_eq!("abc".nfd_iter().collect::<~str>(), ~"abc");
- assert_eq!("\u1e0b\u01c4".nfd_iter().collect::<~str>(), ~"d\u0307\u01c4");
- assert_eq!("\u2026".nfd_iter().collect::<~str>(), ~"\u2026");
- assert_eq!("\u2126".nfd_iter().collect::<~str>(), ~"\u03a9");
- assert_eq!("\u1e0b\u0323".nfd_iter().collect::<~str>(), ~"d\u0323\u0307");
- assert_eq!("\u1e0d\u0307".nfd_iter().collect::<~str>(), ~"d\u0323\u0307");
- assert_eq!("a\u0301".nfd_iter().collect::<~str>(), ~"a\u0301");
- assert_eq!("\u0301a".nfd_iter().collect::<~str>(), ~"\u0301a");
- assert_eq!("\ud4db".nfd_iter().collect::<~str>(), ~"\u1111\u1171\u11b6");
- assert_eq!("\uac1c".nfd_iter().collect::<~str>(), ~"\u1100\u1162");
+ fn test_nfd_chars() {
+ assert_eq!("abc".nfd_chars().collect::<~str>(), ~"abc");
+ assert_eq!("\u1e0b\u01c4".nfd_chars().collect::<~str>(), ~"d\u0307\u01c4");
+ assert_eq!("\u2026".nfd_chars().collect::<~str>(), ~"\u2026");
+ assert_eq!("\u2126".nfd_chars().collect::<~str>(), ~"\u03a9");
+ assert_eq!("\u1e0b\u0323".nfd_chars().collect::<~str>(), ~"d\u0323\u0307");
+ assert_eq!("\u1e0d\u0307".nfd_chars().collect::<~str>(), ~"d\u0323\u0307");
+ assert_eq!("a\u0301".nfd_chars().collect::<~str>(), ~"a\u0301");
+ assert_eq!("\u0301a".nfd_chars().collect::<~str>(), ~"\u0301a");
+ assert_eq!("\ud4db".nfd_chars().collect::<~str>(), ~"\u1111\u1171\u11b6");
+ assert_eq!("\uac1c".nfd_chars().collect::<~str>(), ~"\u1100\u1162");
}
#[test]
- fn test_nfkd_iter() {
- assert_eq!("abc".nfkd_iter().collect::<~str>(), ~"abc");
- assert_eq!("\u1e0b\u01c4".nfkd_iter().collect::<~str>(), ~"d\u0307DZ\u030c");
- assert_eq!("\u2026".nfkd_iter().collect::<~str>(), ~"...");
- assert_eq!("\u2126".nfkd_iter().collect::<~str>(), ~"\u03a9");
- assert_eq!("\u1e0b\u0323".nfkd_iter().collect::<~str>(), ~"d\u0323\u0307");
- assert_eq!("\u1e0d\u0307".nfkd_iter().collect::<~str>(), ~"d\u0323\u0307");
- assert_eq!("a\u0301".nfkd_iter().collect::<~str>(), ~"a\u0301");
- assert_eq!("\u0301a".nfkd_iter().collect::<~str>(), ~"\u0301a");
- assert_eq!("\ud4db".nfkd_iter().collect::<~str>(), ~"\u1111\u1171\u11b6");
- assert_eq!("\uac1c".nfkd_iter().collect::<~str>(), ~"\u1100\u1162");
+ fn test_nfkd_chars() {
+ assert_eq!("abc".nfkd_chars().collect::<~str>(), ~"abc");
+ assert_eq!("\u1e0b\u01c4".nfkd_chars().collect::<~str>(), ~"d\u0307DZ\u030c");
+ assert_eq!("\u2026".nfkd_chars().collect::<~str>(), ~"...");
+ assert_eq!("\u2126".nfkd_chars().collect::<~str>(), ~"\u03a9");
+ assert_eq!("\u1e0b\u0323".nfkd_chars().collect::<~str>(), ~"d\u0323\u0307");
+ assert_eq!("\u1e0d\u0307".nfkd_chars().collect::<~str>(), ~"d\u0323\u0307");
+ assert_eq!("a\u0301".nfkd_chars().collect::<~str>(), ~"a\u0301");
+ assert_eq!("\u0301a".nfkd_chars().collect::<~str>(), ~"\u0301a");
+ assert_eq!("\ud4db".nfkd_chars().collect::<~str>(), ~"\u1111\u1171\u11b6");
+ assert_eq!("\uac1c".nfkd_chars().collect::<~str>(), ~"\u1100\u1162");
}
#[test]
- fn test_line_iter() {
+ fn test_lines() {
let data = "\nMäry häd ä little lämb\n\nLittle lämb\n";
- let lines: ~[&str] = data.line_iter().collect();
+ let lines: ~[&str] = data.lines().collect();
assert_eq!(lines, ~["", "Märy häd ä little lämb", "", "Little lämb"]);
let data = "\nMäry häd ä little lämb\n\nLittle lämb"; // no trailing \n
- let lines: ~[&str] = data.line_iter().collect();
+ let lines: ~[&str] = data.lines().collect();
assert_eq!(lines, ~["", "Märy häd ä little lämb", "", "Little lämb"]);
}
#[test]
- fn test_split_str_iterator() {
+ fn test_split_strator() {
fn t<'a>(s: &str, sep: &'a str, u: ~[&str]) {
- let v: ~[&str] = s.split_str_iter(sep).collect();
+ let v: ~[&str] = s.split_str(sep).collect();
assert_eq!(v, u);
}
t("--1233345--", "12345", ~["--1233345--"]);
let len = s.char_len();
do bh.iter {
- assert_eq!(s.iter().len(), len);
+ assert_eq!(s.chars().len(), len);
}
}
let len = s.char_len();
do bh.iter {
- assert_eq!(s.iter().len(), len);
+ assert_eq!(s.chars().len(), len);
}
}
let len = s.char_len();
do bh.iter {
- assert_eq!(s.rev_iter().len(), len);
+ assert_eq!(s.chars_rev().len(), len);
}
}
#[bench]
- fn char_offset_iterator(bh: &mut BenchHarness) {
+ fn char_indicesator(bh: &mut BenchHarness) {
let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb";
let len = s.char_len();
do bh.iter {
- assert_eq!(s.char_offset_iter().len(), len);
+ assert_eq!(s.char_indices().len(), len);
}
}
#[bench]
- fn char_offset_iterator_rev(bh: &mut BenchHarness) {
+ fn char_indicesator_rev(bh: &mut BenchHarness) {
let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb";
let len = s.char_len();
do bh.iter {
- assert_eq!(s.char_offset_rev_iter().len(), len);
+ assert_eq!(s.char_indices_rev().len(), len);
}
}
#[bench]
- fn split_iter_unicode_ascii(bh: &mut BenchHarness) {
+ fn split_unicode_ascii(bh: &mut BenchHarness) {
let s = "ประเทศไทย中华Việt Namประเทศไทย中华Việt Nam";
do bh.iter {
- assert_eq!(s.split_iter('V').len(), 3);
+ assert_eq!(s.split('V').len(), 3);
}
}
#[bench]
- fn split_iter_unicode_not_ascii(bh: &mut BenchHarness) {
+ fn split_unicode_not_ascii(bh: &mut BenchHarness) {
struct NotAscii(char);
impl CharEq for NotAscii {
fn matches(&self, c: char) -> bool {
let s = "ประเทศไทย中华Việt Namประเทศไทย中华Việt Nam";
do bh.iter {
- assert_eq!(s.split_iter(NotAscii('V')).len(), 3);
+ assert_eq!(s.split(NotAscii('V')).len(), 3);
}
}
#[bench]
- fn split_iter_ascii(bh: &mut BenchHarness) {
+ fn split_ascii(bh: &mut BenchHarness) {
let s = "Mary had a little lamb, Little lamb, little-lamb.";
- let len = s.split_iter(' ').len();
+ let len = s.split(' ').len();
do bh.iter {
- assert_eq!(s.split_iter(' ').len(), len);
+ assert_eq!(s.split(' ').len(), len);
}
}
#[bench]
- fn split_iter_not_ascii(bh: &mut BenchHarness) {
+ fn split_not_ascii(bh: &mut BenchHarness) {
struct NotAscii(char);
impl CharEq for NotAscii {
#[inline]
fn only_ascii(&self) -> bool { false }
}
let s = "Mary had a little lamb, Little lamb, little-lamb.";
- let len = s.split_iter(' ').len();
+ let len = s.split(' ').len();
do bh.iter {
- assert_eq!(s.split_iter(NotAscii(' ')).len(), len);
+ assert_eq!(s.split(NotAscii(' ')).len(), len);
}
}
#[bench]
- fn split_iter_extern_fn(bh: &mut BenchHarness) {
+ fn split_extern_fn(bh: &mut BenchHarness) {
let s = "Mary had a little lamb, Little lamb, little-lamb.";
- let len = s.split_iter(' ').len();
+ let len = s.split(' ').len();
fn pred(c: char) -> bool { c == ' ' }
do bh.iter {
- assert_eq!(s.split_iter(pred).len(), len);
+ assert_eq!(s.split(pred).len(), len);
}
}
#[bench]
- fn split_iter_closure(bh: &mut BenchHarness) {
+ fn split_closure(bh: &mut BenchHarness) {
let s = "Mary had a little lamb, Little lamb, little-lamb.";
- let len = s.split_iter(' ').len();
+ let len = s.split(' ').len();
do bh.iter {
- assert_eq!(s.split_iter(|c: char| c == ' ').len(), len);
+ assert_eq!(s.split(|c: char| c == ' ').len(), len);
}
}
#[bench]
- fn split_iter_slice(bh: &mut BenchHarness) {
+ fn split_slice(bh: &mut BenchHarness) {
let s = "Mary had a little lamb, Little lamb, little-lamb.";
- let len = s.split_iter(' ').len();
+ let len = s.split(' ').len();
do bh.iter {
- assert_eq!(s.split_iter(&[' ']).len(), len);
+ assert_eq!(s.split(&[' ']).len(), len);
}
}
// If `upper` is true then returns upper_bound else returns lower_bound.
#[inline]
- fn bound_iter<'a>(&'a self, key: uint, upper: bool) -> TrieMapIterator<'a, T> {
+ fn bound<'a>(&'a self, key: uint, upper: bool) -> TrieMapIterator<'a, T> {
let mut node: &'a TrieNode<T> = &self.root;
let mut idx = 0;
let mut it = TrieMapIterator {
/// Get an iterator pointing to the first key-value pair whose key is not less than `key`.
/// If all keys in the map are less than `key` an empty iterator is returned.
- pub fn lower_bound_iter<'a>(&'a self, key: uint) -> TrieMapIterator<'a, T> {
- self.bound_iter(key, false)
+ pub fn lower_bound<'a>(&'a self, key: uint) -> TrieMapIterator<'a, T> {
+ self.bound(key, false)
}
/// Get an iterator pointing to the first key-value pair whose key is greater than `key`.
/// If all keys in the map are not greater than `key` an empty iterator is returned.
- pub fn upper_bound_iter<'a>(&'a self, key: uint) -> TrieMapIterator<'a, T> {
- self.bound_iter(key, true)
+ pub fn upper_bound<'a>(&'a self, key: uint) -> TrieMapIterator<'a, T> {
+ self.bound(key, true)
}
}
/// Get an iterator pointing to the first value that is not less than `val`.
/// If all values in the set are less than `val` an empty iterator is returned.
- pub fn lower_bound_iter<'a>(&'a self, val: uint) -> TrieSetIterator<'a> {
- TrieSetIterator{iter: self.map.lower_bound_iter(val)}
+ pub fn lower_bound<'a>(&'a self, val: uint) -> TrieSetIterator<'a> {
+ TrieSetIterator{iter: self.map.lower_bound(val)}
}
/// Get an iterator pointing to the first value that key is greater than `val`.
/// If all values in the set are not greater than `val` an empty iterator is returned.
- pub fn upper_bound_iter<'a>(&'a self, val: uint) -> TrieSetIterator<'a> {
- TrieSetIterator{iter: self.map.upper_bound_iter(val)}
+ pub fn upper_bound<'a>(&'a self, val: uint) -> TrieSetIterator<'a> {
+ TrieSetIterator{iter: self.map.upper_bound(val)}
}
}
}
#[test]
- fn test_bound_iter() {
+ fn test_bound() {
let empty_map : TrieMap<uint> = TrieMap::new();
- assert_eq!(empty_map.lower_bound_iter(0).next(), None);
- assert_eq!(empty_map.upper_bound_iter(0).next(), None);
+ assert_eq!(empty_map.lower_bound(0).next(), None);
+ assert_eq!(empty_map.upper_bound(0).next(), None);
let last = 999u;
let step = 3u;
}
for i in range(0u, last - step) {
- let mut lb = map.lower_bound_iter(i);
- let mut ub = map.upper_bound_iter(i);
+ let mut lb = map.lower_bound(i);
+ let mut ub = map.upper_bound(i);
let next_key = i - i % step + step;
let next_pair = (next_key, &value);
if (i % step == 0) {
assert_eq!(ub.next(), Some(next_pair));
}
- let mut lb = map.lower_bound_iter(last - step);
+ let mut lb = map.lower_bound(last - step);
assert_eq!(lb.next(), Some((last - step, &value)));
- let mut ub = map.upper_bound_iter(last - step);
+ let mut ub = map.upper_bound(last - step);
assert_eq!(ub.next(), None);
for i in range(last - step + 1, last) {
- let mut lb = map.lower_bound_iter(i);
+ let mut lb = map.lower_bound(i);
assert_eq!(lb.next(), None);
- let mut ub = map.upper_bound_iter(i);
+ let mut ub = map.upper_bound(i);
assert_eq!(ub.next(), None);
}
}
fn rev_iter(self) -> RevIterator<'self, T>;
/// Returns an iterator over the subslices of the vector which are
/// separated by elements that match `pred`.
- fn split_iter(self, pred: &'self fn(&T) -> bool) -> SplitIterator<'self, T>;
+ fn split(self, pred: &'self fn(&T) -> bool) -> SplitIterator<'self, T>;
/// Returns an iterator over the subslices of the vector which are
/// separated by elements that match `pred`, limited to splitting
/// at most `n` times.
- fn splitn_iter(self, n: uint, pred: &'self fn(&T) -> bool) -> SplitIterator<'self, T>;
+ fn splitn(self, n: uint, pred: &'self fn(&T) -> bool) -> SplitIterator<'self, T>;
/// Returns an iterator over the subslices of the vector which are
/// separated by elements that match `pred`. This starts at the
/// end of the vector and works backwards.
- fn rsplit_iter(self, pred: &'self fn(&T) -> bool) -> RSplitIterator<'self, T>;
+ fn rsplit(self, pred: &'self fn(&T) -> bool) -> RSplitIterator<'self, T>;
/// Returns an iterator over the subslices of the vector which are
/// separated by elements that match `pred` limited to splitting
/// at most `n` times. This starts at the end of the vector and
/// works backwards.
- fn rsplitn_iter(self, n: uint, pred: &'self fn(&T) -> bool) -> RSplitIterator<'self, T>;
+ fn rsplitn(self, n: uint, pred: &'self fn(&T) -> bool) -> RSplitIterator<'self, T>;
/**
* Returns an iterator over all contiguous windows of length
*
* ```rust
* let v = &[1,2,3,4];
- * for win in v.window_iter() {
+ * for win in v.windows(2) {
* println!("{:?}", win);
* }
* ```
*
*/
- fn window_iter(self, size: uint) -> WindowIter<'self, T>;
+ fn windows(self, size: uint) -> WindowIter<'self, T>;
/**
*
* Returns an iterator over `size` elements of the vector at a
*
* ```rust
* let v = &[1,2,3,4,5];
- * for win in v.chunk_iter() {
+ * for win in v.chunks(2) {
* println!("{:?}", win);
* }
* ```
*
*/
- fn chunk_iter(self, size: uint) -> ChunkIter<'self, T>;
+ fn chunks(self, size: uint) -> ChunkIter<'self, T>;
/// Returns the element of a vector at the given index, or `None` if the
/// index is out of bounds
}
#[inline]
- fn split_iter(self, pred: &'self fn(&T) -> bool) -> SplitIterator<'self, T> {
- self.splitn_iter(uint::max_value, pred)
+ fn split(self, pred: &'self fn(&T) -> bool) -> SplitIterator<'self, T> {
+ self.splitn(uint::max_value, pred)
}
+
#[inline]
- fn splitn_iter(self, n: uint, pred: &'self fn(&T) -> bool) -> SplitIterator<'self, T> {
+ fn splitn(self, n: uint, pred: &'self fn(&T) -> bool) -> SplitIterator<'self, T> {
SplitIterator {
v: self,
n: n,
finished: false
}
}
+
#[inline]
- fn rsplit_iter(self, pred: &'self fn(&T) -> bool) -> RSplitIterator<'self, T> {
- self.rsplitn_iter(uint::max_value, pred)
+ fn rsplit(self, pred: &'self fn(&T) -> bool) -> RSplitIterator<'self, T> {
+ self.rsplitn(uint::max_value, pred)
}
+
#[inline]
- fn rsplitn_iter(self, n: uint, pred: &'self fn(&T) -> bool) -> RSplitIterator<'self, T> {
+ fn rsplitn(self, n: uint, pred: &'self fn(&T) -> bool) -> RSplitIterator<'self, T> {
RSplitIterator {
v: self,
n: n,
}
}
- fn window_iter(self, size: uint) -> WindowIter<'self, T> {
+ #[inline]
+ fn windows(self, size: uint) -> WindowIter<'self, T> {
assert!(size != 0);
WindowIter { v: self, size: size }
}
- fn chunk_iter(self, size: uint) -> ChunkIter<'self, T> {
+ #[inline]
+ fn chunks(self, size: uint) -> ChunkIter<'self, T> {
assert!(size != 0);
ChunkIter { v: self, size: size }
}
/// Create an iterator that yields every possible permutation of the
/// vector in succession.
- fn permutations_iter(self) -> Permutations<T>;
+ fn permutations(self) -> Permutations<T>;
}
impl<'self,T:Clone> ImmutableCopyableVector<T> for &'self [T] {
(*self.unsafe_ref(index)).clone()
}
- fn permutations_iter(self) -> Permutations<T> {
+ fn permutations(self) -> Permutations<T> {
Permutations{
swaps: ElementSwaps::new(self.len()),
v: self.to_owned(),
use hashmap;
{
let v: [int, ..0] = [];
- let mut it = v.permutations_iter();
+ let mut it = v.permutations();
assert_eq!(it.next(), None);
}
{
let v = [~"Hello"];
- let mut it = v.permutations_iter();
+ let mut it = v.permutations();
assert_eq!(it.next(), None);
}
{
let v = [1, 2, 3];
- let mut it = v.permutations_iter();
+ let mut it = v.permutations();
assert_eq!(it.next(), Some(~[1,2,3]));
assert_eq!(it.next(), Some(~[1,3,2]));
assert_eq!(it.next(), Some(~[3,1,2]));
// check that we have N! unique permutations
let mut set = hashmap::HashSet::new();
let v = ['A', 'B', 'C', 'D', 'E', 'F'];
- for perm in v.permutations_iter() {
+ for perm in v.permutations() {
set.insert(perm);
}
assert_eq!(set.len(), 2 * 3 * 4 * 5 * 6);
fn test_permute_fail() {
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
let mut i = 0;
- for _ in v.permutations_iter() {
+ for _ in v.permutations() {
if i == 2 {
fail!()
}
}
#[test]
- fn test_split_iterator() {
+ fn test_splitator() {
let xs = &[1i,2,3,4,5];
- assert_eq!(xs.split_iter(|x| *x % 2 == 0).collect::<~[&[int]]>(),
+ assert_eq!(xs.split(|x| *x % 2 == 0).collect::<~[&[int]]>(),
~[&[1], &[3], &[5]]);
- assert_eq!(xs.split_iter(|x| *x == 1).collect::<~[&[int]]>(),
+ assert_eq!(xs.split(|x| *x == 1).collect::<~[&[int]]>(),
~[&[], &[2,3,4,5]]);
- assert_eq!(xs.split_iter(|x| *x == 5).collect::<~[&[int]]>(),
+ assert_eq!(xs.split(|x| *x == 5).collect::<~[&[int]]>(),
~[&[1,2,3,4], &[]]);
- assert_eq!(xs.split_iter(|x| *x == 10).collect::<~[&[int]]>(),
+ assert_eq!(xs.split(|x| *x == 10).collect::<~[&[int]]>(),
~[&[1,2,3,4,5]]);
- assert_eq!(xs.split_iter(|_| true).collect::<~[&[int]]>(),
+ assert_eq!(xs.split(|_| true).collect::<~[&[int]]>(),
~[&[], &[], &[], &[], &[], &[]]);
let xs: &[int] = &[];
- assert_eq!(xs.split_iter(|x| *x == 5).collect::<~[&[int]]>(), ~[&[]]);
+ assert_eq!(xs.split(|x| *x == 5).collect::<~[&[int]]>(), ~[&[]]);
}
#[test]
- fn test_splitn_iterator() {
+ fn test_splitnator() {
let xs = &[1i,2,3,4,5];
- assert_eq!(xs.splitn_iter(0, |x| *x % 2 == 0).collect::<~[&[int]]>(),
+ assert_eq!(xs.splitn(0, |x| *x % 2 == 0).collect::<~[&[int]]>(),
~[&[1,2,3,4,5]]);
- assert_eq!(xs.splitn_iter(1, |x| *x % 2 == 0).collect::<~[&[int]]>(),
+ assert_eq!(xs.splitn(1, |x| *x % 2 == 0).collect::<~[&[int]]>(),
~[&[1], &[3,4,5]]);
- assert_eq!(xs.splitn_iter(3, |_| true).collect::<~[&[int]]>(),
+ assert_eq!(xs.splitn(3, |_| true).collect::<~[&[int]]>(),
~[&[], &[], &[], &[4,5]]);
let xs: &[int] = &[];
- assert_eq!(xs.splitn_iter(1, |x| *x == 5).collect::<~[&[int]]>(), ~[&[]]);
+ assert_eq!(xs.splitn(1, |x| *x == 5).collect::<~[&[int]]>(), ~[&[]]);
}
#[test]
- fn test_rsplit_iterator() {
+ fn test_rsplitator() {
let xs = &[1i,2,3,4,5];
- assert_eq!(xs.rsplit_iter(|x| *x % 2 == 0).collect::<~[&[int]]>(),
+ assert_eq!(xs.rsplit(|x| *x % 2 == 0).collect::<~[&[int]]>(),
~[&[5], &[3], &[1]]);
- assert_eq!(xs.rsplit_iter(|x| *x == 1).collect::<~[&[int]]>(),
+ assert_eq!(xs.rsplit(|x| *x == 1).collect::<~[&[int]]>(),
~[&[2,3,4,5], &[]]);
- assert_eq!(xs.rsplit_iter(|x| *x == 5).collect::<~[&[int]]>(),
+ assert_eq!(xs.rsplit(|x| *x == 5).collect::<~[&[int]]>(),
~[&[], &[1,2,3,4]]);
- assert_eq!(xs.rsplit_iter(|x| *x == 10).collect::<~[&[int]]>(),
+ assert_eq!(xs.rsplit(|x| *x == 10).collect::<~[&[int]]>(),
~[&[1,2,3,4,5]]);
let xs: &[int] = &[];
- assert_eq!(xs.rsplit_iter(|x| *x == 5).collect::<~[&[int]]>(), ~[&[]]);
+ assert_eq!(xs.rsplit(|x| *x == 5).collect::<~[&[int]]>(), ~[&[]]);
}
#[test]
- fn test_rsplitn_iterator() {
+ fn test_rsplitnator() {
let xs = &[1,2,3,4,5];
- assert_eq!(xs.rsplitn_iter(0, |x| *x % 2 == 0).collect::<~[&[int]]>(),
+ assert_eq!(xs.rsplitn(0, |x| *x % 2 == 0).collect::<~[&[int]]>(),
~[&[1,2,3,4,5]]);
- assert_eq!(xs.rsplitn_iter(1, |x| *x % 2 == 0).collect::<~[&[int]]>(),
+ assert_eq!(xs.rsplitn(1, |x| *x % 2 == 0).collect::<~[&[int]]>(),
~[&[5], &[1,2,3]]);
- assert_eq!(xs.rsplitn_iter(3, |_| true).collect::<~[&[int]]>(),
+ assert_eq!(xs.rsplitn(3, |_| true).collect::<~[&[int]]>(),
~[&[], &[], &[], &[1,2]]);
let xs: &[int] = &[];
- assert_eq!(xs.rsplitn_iter(1, |x| *x == 5).collect::<~[&[int]]>(), ~[&[]]);
+ assert_eq!(xs.rsplitn(1, |x| *x == 5).collect::<~[&[int]]>(), ~[&[]]);
}
#[test]
- fn test_window_iterator() {
+ fn test_windowsator() {
let v = &[1i,2,3,4];
- assert_eq!(v.window_iter(2).collect::<~[&[int]]>(), ~[&[1,2], &[2,3], &[3,4]]);
- assert_eq!(v.window_iter(3).collect::<~[&[int]]>(), ~[&[1i,2,3], &[2,3,4]]);
- assert!(v.window_iter(6).next().is_none());
+ assert_eq!(v.windows(2).collect::<~[&[int]]>(), ~[&[1,2], &[2,3], &[3,4]]);
+ assert_eq!(v.windows(3).collect::<~[&[int]]>(), ~[&[1i,2,3], &[2,3,4]]);
+ assert!(v.windows(6).next().is_none());
}
#[test]
#[should_fail]
- fn test_window_iterator_0() {
+ fn test_windowsator_0() {
let v = &[1i,2,3,4];
- let _it = v.window_iter(0);
+ let _it = v.windows(0);
}
#[test]
- fn test_chunk_iterator() {
+ fn test_chunksator() {
let v = &[1i,2,3,4,5];
- assert_eq!(v.chunk_iter(2).collect::<~[&[int]]>(), ~[&[1i,2], &[3,4], &[5]]);
- assert_eq!(v.chunk_iter(3).collect::<~[&[int]]>(), ~[&[1i,2,3], &[4,5]]);
- assert_eq!(v.chunk_iter(6).collect::<~[&[int]]>(), ~[&[1i,2,3,4,5]]);
+ assert_eq!(v.chunks(2).collect::<~[&[int]]>(), ~[&[1i,2], &[3,4], &[5]]);
+ assert_eq!(v.chunks(3).collect::<~[&[int]]>(), ~[&[1i,2,3], &[4,5]]);
+ assert_eq!(v.chunks(6).collect::<~[&[int]]>(), ~[&[1i,2,3,4,5]]);
- assert_eq!(v.chunk_iter(2).invert().collect::<~[&[int]]>(), ~[&[5i], &[3,4], &[1,2]]);
- let it = v.chunk_iter(2);
+ assert_eq!(v.chunks(2).invert().collect::<~[&[int]]>(), ~[&[5i], &[3,4], &[1,2]]);
+ let it = v.chunks(2);
assert_eq!(it.indexable(), 3);
assert_eq!(it.idx(0).unwrap(), &[1,2]);
assert_eq!(it.idx(1).unwrap(), &[3,4]);
#[test]
#[should_fail]
- fn test_chunk_iterator_0() {
+ fn test_chunksator_0() {
let v = &[1i,2,3,4];
- let _it = v.chunk_iter(0);
+ let _it = v.chunks(0);
}
#[test]
ast::ExprLit(lit) => match lit.node {
// string literal, push each byte to vector expression
ast::lit_str(s, _) => {
- for byte in s.byte_iter() {
+ for byte in s.bytes() {
bytes.push(cx.expr_u8(expr.span, byte));
}
}
let mut i = 0u;
let mut j = lines.len();
// first line of all-stars should be omitted
- if lines.len() > 0 && lines[0].iter().all(|c| c == '*') {
+ if lines.len() > 0 && lines[0].chars().all(|c| c == '*') {
i += 1;
}
while i < j && lines[i].trim().is_empty() {
i += 1;
}
// like the first, a last line of all stars should be omitted
- if j > i && lines[j - 1].iter().skip(1).all(|c| c == '*') {
+ if j > i && lines[j - 1].chars().skip(1).all(|c| c == '*') {
j -= 1;
}
while j > i && lines[j - 1].trim().is_empty() {
let mut can_trim = true;
let mut first = true;
for line in lines.iter() {
- for (j, c) in line.iter().enumerate() {
+ for (j, c) in line.chars().enumerate() {
if j > i || !"* \t".contains_char(c) {
can_trim = false;
break;
if comment.starts_with("/*") {
let lines = comment.slice(3u, comment.len() - 2u)
- .any_line_iter()
+ .lines_any()
.map(|s| s.to_owned())
.collect::<~[~str]>();
pub fn is_line_non_doc_comment(s: &str) -> bool {
let s = s.trim_right();
- s.len() > 3 && s.iter().all(|ch| ch == '/')
+ s.len() > 3 && s.chars().all(|ch| ch == '/')
}
// PRECONDITION: rdr.curr is not whitespace
pub fn is_block_non_doc_comment(s: &str) -> bool {
assert!(s.len() >= 1u);
- s.slice(1u, s.len() - 1u).iter().all(|ch| ch == '*')
+ s.slice(1u, s.len() - 1u).chars().all(|ch| ch == '*')
}
// might return a sugared-doc-attr
self.bump();
let the_string = ident_to_str(&s);
let mut abis = AbiSet::empty();
- for word in the_string.word_iter() {
+ for word in the_string.words() {
match abi::lookup(word) {
Some(abi) => {
if abis.contains(abi) {
let mut cur_piece = ~[];
for dy in range(0, 10) {
for dx in range(0, 5) {
- let masks =
+ let masks =
trans.iter()
.filter_map(|t| mask(dy, dx, id, *t))
.collect();
// Prints a solution in ~str form.
fn print_sol(sol: &str) {
- for (i, c) in sol.iter().enumerate() {
+ for (i, c) in sol.chars().enumerate() {
if (i) % 5 == 0 {println("");}
if (i + 5) % 10 == 0 {print(" ");}
print!("{} ", c);
// reverse order, i.e. the board rotated by half a turn.
data.nb += 2;
let sol1 = to_utf8(raw_sol);
- let sol2: ~str = sol1.iter().invert().collect();
+ let sol2: ~str = sol1.chars().invert().collect();
if data.nb == 2 {
data.min = sol1.clone();
let line = match reader.read_line() {
Some(ln) => ln, None => break
};
- let comps: ~[&str] = line.trim().split_iter(',').collect();
+ let comps: ~[&str] = line.trim().split(',').collect();
if comps.len() == 3u {
let row = from_str::<uint>(comps[0]).unwrap() as u8;
assert_eq!(y, 6);
let s = ~"hello there";
let mut i: int = 0;
- for c in s.byte_iter() {
+ for c in s.bytes() {
if i == 0 { assert!((c == 'h' as u8)); }
if i == 1 { assert!((c == 'e' as u8)); }
if i == 2 { assert!((c == 'l' as u8)); }
let all_nuls4 = "\x00\u0000\0\U00000000";
// sizes for two should suffice
- assert_eq!(all_nuls1.len(), 4);
+ assert_eq!(all_nuls1.len(), 4);
assert_eq!(all_nuls2.len(), 4);
// string equality should pass between the strings
assert_eq!(all_nuls1, all_nuls2);
assert_eq!(all_nuls2, all_nuls3);
assert_eq!(all_nuls3, all_nuls4);
-
+
// all extracted characters in all_nuls are equivalent to each other
- for c1 in all_nuls1.iter()
+ for c1 in all_nuls1.chars()
{
- for c2 in all_nuls1.iter()
+ for c2 in all_nuls1.chars()
{
assert_eq!(c1,c2);
}
}
-
+
// testing equality between explicit character literals
assert_eq!('\0', '\x00');
assert_eq!('\u0000', '\x00');
fn check_str_eq(a: ~str, b: ~str) {
let mut i: int = 0;
- for ab in a.byte_iter() {
+ for ab in a.bytes() {
info!("{}", i);
info!("{}", ab);
let bb: u8 = b[i];
// Chars of 1, 2, 3, and 4 bytes
let chs: ~[char] = ~['e', 'é', '€', '\U00010000'];
let s: ~str = str::from_chars(chs);
- let schs: ~[char] = s.iter().collect();
+ let schs: ~[char] = s.chars().collect();
assert!(s.len() == 10u);
assert!(s.char_len() == 4u);