std: replace str::each_split* with an iterator
This commit is contained in:
parent
2ff6b298c5
commit
1e8982bdb2
19 changed files with 270 additions and 516 deletions
|
|
@ -416,7 +416,6 @@ mod test {
|
|||
|
||||
use core::iterator::IteratorUtil;
|
||||
use core::io;
|
||||
use core::str;
|
||||
use core::uint;
|
||||
use core::vec;
|
||||
|
||||
|
|
@ -527,9 +526,7 @@ mod test {
|
|||
}
|
||||
|
||||
for input_vec_state(filenames) |line, state| {
|
||||
let nums = do vec::build |p| {
|
||||
for str::each_split_char(line, ' ') |s| { p(s.to_owned()); }
|
||||
};
|
||||
let nums: ~[&str] = line.split_iter(' ').collect();
|
||||
let file_num = uint::from_str(nums[0]).get();
|
||||
let line_num = uint::from_str(nums[1]).get();
|
||||
assert_eq!(line_num, state.line_num_file);
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@
|
|||
|
||||
use core::prelude::*;
|
||||
|
||||
use core::iterator::IteratorUtil;
|
||||
use core::cmp::Eq;
|
||||
use core::result::{Err, Ok};
|
||||
use core::result;
|
||||
|
|
@ -247,14 +248,13 @@ pub fn getopts(args: &[~str], opts: &[Opt]) -> Result {
|
|||
let mut i_arg = None;
|
||||
if cur[1] == '-' as u8 {
|
||||
let tail = str::slice(cur, 2, curlen);
|
||||
let mut tail_eq = ~[];
|
||||
for str::each_splitn_char(tail, '=', 1) |s| { tail_eq.push(s.to_owned()) }
|
||||
let tail_eq: ~[&str] = tail.split_iter('=').collect();
|
||||
if tail_eq.len() <= 1 {
|
||||
names = ~[Long(tail.to_owned())];
|
||||
} else {
|
||||
names =
|
||||
~[Long(copy tail_eq[0])];
|
||||
i_arg = Some(copy tail_eq[1]);
|
||||
~[Long(tail_eq[0].to_owned())];
|
||||
i_arg = Some(tail_eq[1].to_owned());
|
||||
}
|
||||
} else {
|
||||
let mut j = 1;
|
||||
|
|
@ -635,7 +635,7 @@ pub mod groups {
|
|||
|
||||
// Normalize desc to contain words separated by one space character
|
||||
let mut desc_normalized_whitespace = ~"";
|
||||
for str::each_word(desc) |word| {
|
||||
for desc.word_iter().advance |word| {
|
||||
desc_normalized_whitespace.push_str(word);
|
||||
desc_normalized_whitespace.push_char(' ');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
use core::prelude::*;
|
||||
|
||||
use core::iterator::IteratorUtil;
|
||||
use core::libc;
|
||||
use core::comm::{stream, SharedChan};
|
||||
use core::ptr;
|
||||
|
|
@ -158,9 +159,7 @@ pub mod v4 {
|
|||
|
||||
use core::cast::transmute;
|
||||
use core::result;
|
||||
use core::str;
|
||||
use core::uint;
|
||||
use core::vec;
|
||||
|
||||
/**
|
||||
* Convert a str to `ip_addr`
|
||||
|
|
@ -199,14 +198,12 @@ pub mod v4 {
|
|||
}
|
||||
}
|
||||
pub fn parse_to_ipv4_rep(ip: &str) -> result::Result<Ipv4Rep, ~str> {
|
||||
let mut parts = ~[];
|
||||
for str::each_split_char(ip, '.') |s| { parts.push(s.to_owned()) }
|
||||
let parts = vec::map(parts, |s| {
|
||||
match uint::from_str(*s) {
|
||||
Some(n) if n <= 255 => n,
|
||||
_ => 256
|
||||
let parts: ~[uint] = ip.split_iter('.').transform(|s| {
|
||||
match uint::from_str(s) {
|
||||
Some(n) if n <= 255 => n,
|
||||
_ => 256
|
||||
}
|
||||
});
|
||||
}).collect();
|
||||
if parts.len() != 4 {
|
||||
Err(fmt!("'%s' doesn't have 4 parts", ip))
|
||||
} else if parts.contains(&256) {
|
||||
|
|
|
|||
|
|
@ -334,7 +334,7 @@ fn userinfo_to_str(userinfo: &UserInfo) -> ~str {
|
|||
fn query_from_str(rawquery: &str) -> Query {
|
||||
let mut query: Query = ~[];
|
||||
if str::len(rawquery) != 0 {
|
||||
for str::each_split_char(rawquery, '&') |p| {
|
||||
for rawquery.split_iter('&').advance |p| {
|
||||
let (k, v) = split_char_first(p, '=');
|
||||
query.push((decode_component(k), decode_component(v)));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -12,11 +12,10 @@
|
|||
|
||||
use core::prelude::*;
|
||||
|
||||
use core::iterator::IteratorUtil;
|
||||
use core::cmp;
|
||||
use core::from_str::FromStr;
|
||||
use core::num::{Zero,One,ToStrRadix,FromStrRadix,Round};
|
||||
use core::str;
|
||||
use core::vec;
|
||||
use super::bigint::BigInt;
|
||||
|
||||
/// Represents the ratio between 2 numbers.
|
||||
|
|
@ -252,11 +251,7 @@ impl<T: FromStr + Clone + Integer + Ord>
|
|||
FromStr for Ratio<T> {
|
||||
/// Parses `numer/denom`.
|
||||
fn from_str(s: &str) -> Option<Ratio<T>> {
|
||||
let split = vec::build(|push| {
|
||||
for str::each_splitn_char(s, '/', 1) |s| {
|
||||
push(s.to_owned());
|
||||
}
|
||||
});
|
||||
let split: ~[&str] = s.splitn_iter('/', 1).collect();
|
||||
if split.len() < 2 { return None; }
|
||||
do FromStr::from_str::<T>(split[0]).chain |a| {
|
||||
do FromStr::from_str::<T>(split[1]).chain |b| {
|
||||
|
|
@ -269,11 +264,7 @@ impl<T: FromStrRadix + Clone + Integer + Ord>
|
|||
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 = vec::build(|push| {
|
||||
for str::each_splitn_char(s, '/', 1) |s| {
|
||||
push(s.to_owned());
|
||||
}
|
||||
});
|
||||
let split: ~[&str] = s.splitn_iter('/', 1).collect();
|
||||
if split.len() < 2 { None }
|
||||
else {
|
||||
do FromStrRadix::from_str_radix::<T>(split[0], radix).chain |a| {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ use core::prelude::*;
|
|||
|
||||
use core::{vec, int, str};
|
||||
use core::io::Reader;
|
||||
use core::iterator::IteratorUtil;
|
||||
use core::hashmap::HashMap;
|
||||
use super::super::TermInfo;
|
||||
|
||||
|
|
@ -212,11 +213,8 @@ pub fn parse(file: @Reader, longnames: bool) -> Result<~TermInfo, ~str> {
|
|||
return Err(~"incompatible file: more string offsets than expected");
|
||||
}
|
||||
|
||||
let mut term_names: ~[~str] = vec::with_capacity(2);
|
||||
let names_str = str::from_bytes(file.read_bytes(names_bytes as uint - 1)); // don't read NUL
|
||||
for names_str.each_split_char('|') |s| {
|
||||
term_names.push(s.to_owned());
|
||||
}
|
||||
let term_names: ~[~str] = names_str.split_iter('|').transform(|s| s.to_owned()).collect();
|
||||
|
||||
file.read_byte(); // consume NUL
|
||||
|
||||
|
|
|
|||
|
|
@ -12,9 +12,10 @@
|
|||
/// Does not support hashed database, only filesystem!
|
||||
|
||||
use core::prelude::*;
|
||||
use core::{os, str};
|
||||
use core::{os};
|
||||
use core::os::getenv;
|
||||
use core::io::{file_reader, Reader};
|
||||
use core::iterator::IteratorUtil;
|
||||
use path = core::path::Path;
|
||||
|
||||
/// Return path to database entry for `term`
|
||||
|
|
@ -36,7 +37,7 @@ pub fn get_dbpath_for_term(term: &str) -> Option<~path> {
|
|||
dirs_to_search.push(homedir.unwrap().push(".terminfo")); // ncurses compatability
|
||||
}
|
||||
match getenv("TERMINFO_DIRS") {
|
||||
Some(dirs) => for str::each_split_char(dirs, ':') |i| {
|
||||
Some(dirs) => for dirs.split_iter(':').advance |i| {
|
||||
if i == "" {
|
||||
dirs_to_search.push(path("/usr/share/terminfo"));
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue