summary refs log tree commit diff
path: root/src/libextra
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2013-06-09 23:10:50 +1000
committerHuon Wilson <dbau.pp+github@gmail.com>2013-06-10 23:02:54 +1000
commit1e8982bdb26208d9d9ed4cdcbcd21cc9ef35bd46 (patch)
tree54f03a318e14bcdbdb56e01b3c80d00a9db87a17 /src/libextra
parent2ff6b298c5f23f48aa993fced41b6e29e446b7ce (diff)
downloadrust-1e8982bdb26208d9d9ed4cdcbcd21cc9ef35bd46.tar.gz
rust-1e8982bdb26208d9d9ed4cdcbcd21cc9ef35bd46.zip
std: replace str::each_split* with an iterator
Diffstat (limited to 'src/libextra')
-rw-r--r--src/libextra/fileinput.rs5
-rw-r--r--src/libextra/getopts.rs10
-rw-r--r--src/libextra/net_ip.rs15
-rw-r--r--src/libextra/net_url.rs2
-rw-r--r--src/libextra/num/rational.rs15
-rw-r--r--src/libextra/terminfo/parser/compiled.rs6
-rw-r--r--src/libextra/terminfo/searcher.rs5
7 files changed, 21 insertions, 37 deletions
diff --git a/src/libextra/fileinput.rs b/src/libextra/fileinput.rs
index 16082732715..add857ca9ed 100644
--- a/src/libextra/fileinput.rs
+++ b/src/libextra/fileinput.rs
@@ -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);
diff --git a/src/libextra/getopts.rs b/src/libextra/getopts.rs
index 2bc0a8ef6b0..af026473a1b 100644
--- a/src/libextra/getopts.rs
+++ b/src/libextra/getopts.rs
@@ -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(' ');
             }
diff --git a/src/libextra/net_ip.rs b/src/libextra/net_ip.rs
index ddbf09e40eb..760fc7485e0 100644
--- a/src/libextra/net_ip.rs
+++ b/src/libextra/net_ip.rs
@@ -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) {
diff --git a/src/libextra/net_url.rs b/src/libextra/net_url.rs
index f26019d9282..f7e86b00d23 100644
--- a/src/libextra/net_url.rs
+++ b/src/libextra/net_url.rs
@@ -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)));
         };
diff --git a/src/libextra/num/rational.rs b/src/libextra/num/rational.rs
index 1a8ab75b3dd..08fbb8aacc9 100644
--- a/src/libextra/num/rational.rs
+++ b/src/libextra/num/rational.rs
@@ -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| {
diff --git a/src/libextra/terminfo/parser/compiled.rs b/src/libextra/terminfo/parser/compiled.rs
index 61c68c27fe5..690596e6248 100644
--- a/src/libextra/terminfo/parser/compiled.rs
+++ b/src/libextra/terminfo/parser/compiled.rs
@@ -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
 
diff --git a/src/libextra/terminfo/searcher.rs b/src/libextra/terminfo/searcher.rs
index d6577cf3b94..d109bb12e02 100644
--- a/src/libextra/terminfo/searcher.rs
+++ b/src/libextra/terminfo/searcher.rs
@@ -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 {