about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/io.rs7
-rw-r--r--src/libstd/num/int_macros.rs3
-rw-r--r--src/libstd/num/uint_macros.rs3
-rw-r--r--src/libstd/rand.rs3
-rw-r--r--src/libstd/rand/distributions.rs3
-rw-r--r--src/libstd/rt/io/extensions.rs7
-rw-r--r--src/libstd/str.rs70
-rw-r--r--src/libstd/task/spawn.rs4
-rw-r--r--src/libstd/to_str.rs17
-rw-r--r--src/libstd/vec.rs9
10 files changed, 107 insertions, 19 deletions
diff --git a/src/libstd/io.rs b/src/libstd/io.rs
index 36920bd2488..59ac58a514f 100644
--- a/src/libstd/io.rs
+++ b/src/libstd/io.rs
@@ -771,7 +771,9 @@ impl<T:Reader> ReaderUtil for T {
     fn read_le_uint_n(&self, nbytes: uint) -> u64 {
         assert!(nbytes > 0 && nbytes <= 8);
 
-        let mut (val, pos, i) = (0u64, 0, nbytes);
+        let mut val = 0u64;
+        let mut pos = 0;
+        let mut i = nbytes;
         while i > 0 {
             val += (self.read_u8() as u64) << pos;
             pos += 8;
@@ -787,7 +789,8 @@ impl<T:Reader> ReaderUtil for T {
     fn read_be_uint_n(&self, nbytes: uint) -> u64 {
         assert!(nbytes > 0 && nbytes <= 8);
 
-        let mut (val, i) = (0u64, nbytes);
+        let mut val = 0u64;
+        let mut i = nbytes;
         while i > 0 {
             i -= 1;
             val += (self.read_u8() as u64) << i * 8;
diff --git a/src/libstd/num/int_macros.rs b/src/libstd/num/int_macros.rs
index 74ec46ccfcd..845152f8552 100644
--- a/src/libstd/num/int_macros.rs
+++ b/src/libstd/num/int_macros.rs
@@ -400,7 +400,8 @@ impl Integer for $T {
     #[inline]
     fn gcd(&self, other: &$T) -> $T {
         // Use Euclid's algorithm
-        let mut (m, n) = (*self, *other);
+        let mut m = *self;
+        let mut n = *other;
         while m != 0 {
             let temp = m;
             m = n % temp;
diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs
index 52f620f97ce..0dabe7fafa8 100644
--- a/src/libstd/num/uint_macros.rs
+++ b/src/libstd/num/uint_macros.rs
@@ -237,7 +237,8 @@ impl Integer for $T {
     #[inline]
     fn gcd(&self, other: &$T) -> $T {
         // Use Euclid's algorithm
-        let mut (m, n) = (*self, *other);
+        let mut m = *self;
+        let mut n = *other;
         while m != 0 {
             let temp = m;
             m = n % temp;
diff --git a/src/libstd/rand.rs b/src/libstd/rand.rs
index ea4a9059e72..8a6c05ce6e2 100644
--- a/src/libstd/rand.rs
+++ b/src/libstd/rand.rs
@@ -720,7 +720,8 @@ impl IsaacRng {
     fn isaac(&mut self) {
         self.c += 1;
         // abbreviations
-        let mut (a, b) = (self.a, self.b + self.c);
+        let mut a = self.a;
+        let mut b = self.b + self.c;
 
         static midpoint: uint = RAND_SIZE as uint / 2;
 
diff --git a/src/libstd/rand/distributions.rs b/src/libstd/rand/distributions.rs
index 6f4f1a34977..e8dad2fc5e8 100644
--- a/src/libstd/rand/distributions.rs
+++ b/src/libstd/rand/distributions.rs
@@ -89,7 +89,8 @@ impl Rand for StandardNormal {
             // do-while, so the condition should be true on the first
             // run, they get overwritten anyway (0 < 1, so these are
             // good).
-            let mut (x, y) = (1.0, 0.0);
+            let mut x = 1.0;
+            let mut y = 0.0;
 
             // XXX infinities?
             while -2.0*y < x * x {
diff --git a/src/libstd/rt/io/extensions.rs b/src/libstd/rt/io/extensions.rs
index 1f82a9cd963..c6654e9dabe 100644
--- a/src/libstd/rt/io/extensions.rs
+++ b/src/libstd/rt/io/extensions.rs
@@ -343,7 +343,9 @@ impl<T: Reader> ReaderByteConversions for T {
     fn read_le_uint_n(&mut self, nbytes: uint) -> u64 {
         assert!(nbytes > 0 && nbytes <= 8);
 
-        let mut (val, pos, i) = (0u64, 0, nbytes);
+        let mut val = 0u64;
+        let mut pos = 0;
+        let mut i = nbytes;
         while i > 0 {
             val += (self.read_u8() as u64) << pos;
             pos += 8;
@@ -359,7 +361,8 @@ impl<T: Reader> ReaderByteConversions for T {
     fn read_be_uint_n(&mut self, nbytes: uint) -> u64 {
         assert!(nbytes > 0 && nbytes <= 8);
 
-        let mut (val, i) = (0u64, nbytes);
+        let mut val = 0u64;
+        let mut i = nbytes;
         while i > 0 {
             i -= 1;
             val += (self.read_u8() as u64) << i * 8;
diff --git a/src/libstd/str.rs b/src/libstd/str.rs
index f8c8ffdbe35..78538d09938 100644
--- a/src/libstd/str.rs
+++ b/src/libstd/str.rs
@@ -473,6 +473,31 @@ pub fn each_split_within<'a>(ss: &'a str,
     return cont;
 }
 
+/**
+ * Replace all occurrences of one string with another
+ *
+ * # Arguments
+ *
+ * * s - The string containing substrings to replace
+ * * from - The string to replace
+ * * to - The replacement string
+ *
+ * # Return value
+ *
+ * The original string with all occurances of `from` replaced with `to`
+ */
+pub fn replace(s: &str, from: &str, to: &str) -> ~str {
+    let mut result = ~"";
+    let mut last_end = 0;
+    for s.matches_index_iter(from).advance |(start, end)| {
+        result.push_str(unsafe{raw::slice_bytes(s, last_end, start)});
+        result.push_str(to);
+        last_end = end;
+    }
+    result.push_str(unsafe{raw::slice_bytes(s, last_end, s.len())});
+    result
+}
+
 /*
 Section: Comparing strings
 */
@@ -631,6 +656,48 @@ pub fn with_capacity(capacity: uint) -> ~str {
     buf
 }
 
+/**
+ * As char_len but for a slice of a string
+ *
+ * # Arguments
+ *
+ * * s - A valid string
+ * * start - The position inside `s` where to start counting in bytes
+ * * end - The position where to stop counting
+ *
+ * # Return value
+ *
+ * The number of Unicode characters in `s` between the given indices.
+ */
+pub fn count_chars(s: &str, start: uint, end: uint) -> uint {
+    assert!(s.is_char_boundary(start));
+    assert!(s.is_char_boundary(end));
+    let mut i = start;
+    let mut len = 0u;
+    while i < end {
+        let next = s.char_range_at(i).next;
+        len += 1u;
+        i = next;
+    }
+    return len;
+}
+
+/// Counts the number of bytes taken by the first `n` chars in `s`
+/// starting from `start`.
+pub fn count_bytes<'b>(s: &'b str, start: uint, n: uint) -> uint {
+    assert!(is_char_boundary(s, start));
+    let mut end = start;
+    let mut cnt = n;
+    let l = s.len();
+    while cnt > 0u {
+        assert!(end < l);
+        let next = s.char_range_at(end).next;
+        cnt -= 1u;
+        end = next;
+    }
+    end - start
+}
+
 /// Given a first byte, determine how many bytes are in this UTF-8 character
 pub fn utf8_char_width(b: u8) -> uint {
     let byte: uint = b as uint;
@@ -737,7 +804,8 @@ pub mod raw {
 
     /// Create a Rust string from a null-terminated *u8 buffer
     pub unsafe fn from_buf(buf: *u8) -> ~str {
-        let mut (curr, i) = (buf, 0u);
+        let mut curr = buf;
+        let mut i = 0u;
         while *curr != 0u8 {
             i += 1u;
             curr = ptr::offset(buf, i);
diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs
index 95fc53c1b55..da3dc6b2a2e 100644
--- a/src/libstd/task/spawn.rs
+++ b/src/libstd/task/spawn.rs
@@ -636,7 +636,9 @@ fn spawn_raw_oldsched(mut opts: TaskOpts, f: ~fn()) {
         let child_data = Cell::new((notify_chan, child_arc, ancestors));
         let result: ~fn() = || {
             // Agh. Get move-mode items into the closure. FIXME (#2829)
-            let mut (notify_chan, child_arc, ancestors) = child_data.take();
+            let (notify_chan, child_arc, ancestors) = child_data.take();
+            let mut child_arc = child_arc;
+            let mut ancestors = ancestors;
             // Child task runs this code.
 
             // Even if the below code fails to kick the child off, we must
diff --git a/src/libstd/to_str.rs b/src/libstd/to_str.rs
index ea0e212b14f..dcd02744cf9 100644
--- a/src/libstd/to_str.rs
+++ b/src/libstd/to_str.rs
@@ -53,8 +53,9 @@ impl<A:ToStr> ToStr for (A,) {
 impl<A:ToStr+Hash+Eq, B:ToStr+Hash+Eq> ToStr for HashMap<A, B> {
     #[inline]
     fn to_str(&self) -> ~str {
-        let mut (acc, first) = (~"{", true);
-        for self.iter().advance |(key, value)| {
+        let mut acc = ~"{";
+        let mut first = true;
+        for self.iter().advance |key, value| {
             if first {
                 first = false;
             }
@@ -73,7 +74,8 @@ impl<A:ToStr+Hash+Eq, B:ToStr+Hash+Eq> ToStr for HashMap<A, B> {
 impl<A:ToStr+Hash+Eq> ToStr for HashSet<A> {
     #[inline]
     fn to_str(&self) -> ~str {
-        let mut (acc, first) = (~"{", true);
+        let mut acc = ~"{";
+        let mut first = true;
         for self.iter().advance |element| {
             if first {
                 first = false;
@@ -121,7 +123,8 @@ impl<A:ToStr,B:ToStr,C:ToStr> ToStr for (A, B, C) {
 impl<'self,A:ToStr> ToStr for &'self [A] {
     #[inline]
     fn to_str(&self) -> ~str {
-        let mut (acc, first) = (~"[", true);
+        let mut acc = ~"[";
+        let mut first = true;
         for self.iter().advance |elt| {
             if first {
                 first = false;
@@ -139,7 +142,8 @@ impl<'self,A:ToStr> ToStr for &'self [A] {
 impl<A:ToStr> ToStr for ~[A] {
     #[inline]
     fn to_str(&self) -> ~str {
-        let mut (acc, first) = (~"[", true);
+        let mut acc = ~"[";
+        let mut first = true;
         for self.iter().advance |elt| {
             if first {
                 first = false;
@@ -157,7 +161,8 @@ impl<A:ToStr> ToStr for ~[A] {
 impl<A:ToStr> ToStr for @[A] {
     #[inline]
     fn to_str(&self) -> ~str {
-        let mut (acc, first) = (~"[", true);
+        let mut acc = ~"[";
+        let mut first = true;
         for self.iter().advance |elt| {
             if first {
                 first = false;
diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs
index 8cbd9309cc6..aa4d632a482 100644
--- a/src/libstd/vec.rs
+++ b/src/libstd/vec.rs
@@ -348,7 +348,8 @@ pub fn consume_reverse<T>(mut v: ~[T], f: &fn(uint, v: T)) {
 pub fn dedup<T:Eq>(v: &mut ~[T]) {
     unsafe {
         if v.len() < 1 { return; }
-        let mut (last_written, next_to_read) = (0, 1);
+        let mut last_written = 0;
+        let mut next_to_read = 1;
         do as_const_buf(*v) |p, ln| {
             // We have a mutable reference to v, so we can make arbitrary
             // changes. (cf. push and pop)
@@ -798,7 +799,8 @@ pub fn bsearch_elem<T:TotalOrd>(v: &[T], x: &T) -> Option<uint> {
  * Convert a vector of pairs into a pair of vectors, by reference. As unzip().
  */
 pub fn unzip_slice<T:Copy,U:Copy>(v: &[(T, U)]) -> (~[T], ~[U]) {
-    let mut (ts, us) = (~[], ~[]);
+    let mut ts = ~[];
+    let mut us = ~[];
     for v.iter().advance |p| {
         let (t, u) = copy *p;
         ts.push(t);
@@ -816,7 +818,8 @@ pub fn unzip_slice<T:Copy,U:Copy>(v: &[(T, U)]) -> (~[T], ~[U]) {
  * of the i-th tuple of the input vector.
  */
 pub fn unzip<T,U>(v: ~[(T, U)]) -> (~[T], ~[U]) {
-    let mut (ts, us) = (~[], ~[]);
+    let mut ts = ~[];
+    let mut us = ~[];
     do consume(v) |_i, p| {
         let (t, u) = p;
         ts.push(t);