Skip to content

Commit

Permalink
Remove extra space between key and value.
Browse files Browse the repository at this point in the history
1. Extra space removed.
2. Using acc.push_str() instead of str::push_str
3. Update test to reflect representation change.
  • Loading branch information
samebchase committed May 11, 2013
1 parent 3c1e787 commit b8d0ebe
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/libcore/to_str.rs
Expand Up @@ -15,7 +15,9 @@ The `ToStr` trait for converting to strings
*/

use str;
use str::OwnedStr;
use hashmap::HashMap;
use hashmap::HashSet;
use container::Map;
use hash::Hash;
use cmp::Eq;
Expand Down Expand Up @@ -59,13 +61,13 @@ impl<A:ToStr+Hash+Eq, B:ToStr+Hash+Eq> ToStr for HashMap<A, B> {
first = false;
}
else {
str::push_str(&mut acc, ~", ");
acc.push_str(", ");
}
str::push_str(&mut acc, key.to_str());
str::push_str(&mut acc, ~" : ");
str::push_str(&mut acc, value.to_str());
acc.push_str(key.to_str());
acc.push_str(": ");
acc.push_str(value.to_str());
}
str::push_char(&mut acc, '}');
acc.push_char('}');
acc
}
}
Expand All @@ -82,6 +84,7 @@ impl<A:ToStr,B:ToStr> ToStr for (A, B) {
}
}
}

impl<A:ToStr,B:ToStr,C:ToStr> ToStr for (A, B, C) {
#[inline(always)]
fn to_str(&self) -> ~str {
Expand Down Expand Up @@ -185,7 +188,7 @@ mod tests {

let table_str = table.to_str();

assert!(table_str == ~"{1 : 2, 3 : 4}" || table_str == ~"{3 : 4, 1 : 2}");
assert!(table_str == ~"{1: 2, 3: 4}" || table_str == ~"{3: 4, 1: 2}");
assert!(empty.to_str() == ~"{}");
}
}

0 comments on commit b8d0ebe

Please sign in to comment.