about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorJesse Jones <jesse9jones@gmail.com>2012-11-17 10:13:11 -0800
committerBrian Anderson <banderson@mozilla.com>2012-11-18 13:25:26 -0800
commit6d99a2f8a99baedab90fb8bd6cb6e1507fad736b (patch)
tree543df1adb01550cf549166c515312cf04c168b24 /src/libcore
parent15989ecb139a4ee4a53e6657fd4fc8cee9d729de (diff)
Made more stuff pure.
escape functions in char, io.with_str_reader, base64 and md5sum, cell.empty_cell
and is_empty.
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/char.rs12
-rw-r--r--src/libcore/io.rs2
2 files changed, 8 insertions, 6 deletions
diff --git a/src/libcore/char.rs b/src/libcore/char.rs
index b76571864e0..802aaf12bdd 100644
--- a/src/libcore/char.rs
+++ b/src/libcore/char.rs
@@ -126,16 +126,18 @@ pub pure fn to_digit(c: char, radix: uint) -> Option<uint> {
  *   - chars in [0x100,0xffff] get 4-digit escapes: `\\uNNNN`
  *   - chars above 0x10000 get 8-digit escapes: `\\UNNNNNNNN`
  */
-pub fn escape_unicode(c: char) -> ~str {
+pub pure fn escape_unicode(c: char) -> ~str {
     let s = u32::to_str(c as u32, 16u);
     let (c, pad) = (if c <= '\xff' { ('x', 2u) }
                     else if c <= '\uffff' { ('u', 4u) }
                     else { ('U', 8u) });
     assert str::len(s) <= pad;
     let mut out = ~"\\";
-    str::push_str(&mut out, str::from_char(c));
-    for uint::range(str::len(s), pad) |_i| { str::push_str(&mut out, ~"0"); }
-    str::push_str(&mut out, s);
+    unsafe {
+        str::push_str(&mut out, str::from_char(c));
+        for uint::range(str::len(s), pad) |_i| { str::push_str(&mut out, ~"0"); }
+        str::push_str(&mut out, s);
+    }
     move out
 }
 
@@ -151,7 +153,7 @@ pub fn escape_unicode(c: char) -> ~str {
  *   - Any other chars in the range [0x20,0x7e] are not escaped.
  *   - Any other chars are given hex unicode escapes; see `escape_unicode`.
  */
-pub fn escape_default(c: char) -> ~str {
+pub pure fn escape_default(c: char) -> ~str {
     match c {
       '\t' => ~"\\t",
       '\r' => ~"\\r",
diff --git a/src/libcore/io.rs b/src/libcore/io.rs
index 4629878b4b7..535ab883581 100644
--- a/src/libcore/io.rs
+++ b/src/libcore/io.rs
@@ -512,7 +512,7 @@ pub pure fn with_bytes_reader<t>(bytes: &[u8], f: fn(Reader) -> t) -> t {
     f(BytesReader { bytes: bytes, pos: 0u } as Reader)
 }
 
-pub fn with_str_reader<T>(s: &str, f: fn(Reader) -> T) -> T {
+pub pure fn with_str_reader<T>(s: &str, f: fn(Reader) -> T) -> T {
     str::byte_slice(s, |bytes| with_bytes_reader(bytes, f))
 }