about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKevin Cantu <me@kevincantu.org>2012-02-01 04:20:21 -0800
committerBrian Anderson <banderson@mozilla.com>2012-02-01 21:56:53 -0800
commit8f367ebfeb4f0b897b386f5c74c4f329fb8cbd54 (patch)
tree9796d775541b468b23646f034b028225c9cbce72
parent01c01f68afc58bc9a7a4d4b85805925d45a39ec7 (diff)
downloadrust-8f367ebfeb4f0b897b386f5c74c4f329fb8cbd54.tar.gz
rust-8f367ebfeb4f0b897b386f5c74c4f329fb8cbd54.zip
Rename (again) str::unsafe::slice -> str::unsafe::slice_bytes and
str::unsafe::safe_slice -> str::unsafe::slice_bytes_safe_range
-rw-r--r--src/cargo/cargo.rs8
-rw-r--r--src/comp/back/link.rs2
-rw-r--r--src/comp/middle/debuginfo.rs2
-rw-r--r--src/comp/syntax/codemap.rs4
-rw-r--r--src/comp/syntax/parse/lexer.rs4
-rw-r--r--src/compiletest/errors.rs4
-rw-r--r--src/compiletest/header.rs2
-rw-r--r--src/fuzzer/fuzzer.rs2
-rw-r--r--src/libcore/str.rs72
-rw-r--r--src/libstd/fs.rs2
-rw-r--r--src/libstd/getopts.rs7
-rw-r--r--src/test/compile-fail/fn-constraint.rs2
-rw-r--r--src/test/compile-fail/no-constraint-prop.rs2
-rw-r--r--src/test/run-fail/fn-constraint.rs2
-rw-r--r--src/test/run-pass/constraint-prop-expr-move.rs2
-rw-r--r--src/test/run-pass/constraint-prop-move.rs2
-rw-r--r--src/test/run-pass/constraint-prop-swap.rs2
-rw-r--r--src/test/run-pass/constraint-prop.rs2
-rw-r--r--src/test/run-pass/fn-constraint.rs2
19 files changed, 39 insertions, 86 deletions
diff --git a/src/cargo/cargo.rs b/src/cargo/cargo.rs
index 87e8be75787..0aef3ff9e13 100644
--- a/src/cargo/cargo.rs
+++ b/src/cargo/cargo.rs
@@ -596,8 +596,8 @@ fn cmd_install(c: cargo, argv: [str]) unsafe {
         let uuid = rest(target, 5u);
         let idx = str::index(uuid, '/' as u8);
         if idx != -1 {
-            let source = str::unsafe::slice(uuid, 0u, idx as uint);
-            uuid = str::unsafe::slice(uuid, idx as uint + 1u,
+            let source = str::unsafe::slice_bytes(uuid, 0u, idx as uint);
+            uuid = str::unsafe::slice_bytes(uuid, idx as uint + 1u,
                                       str::byte_len(uuid));
             install_uuid_specific(c, wd, source, uuid);
         } else {
@@ -607,8 +607,8 @@ fn cmd_install(c: cargo, argv: [str]) unsafe {
         let name = target;
         let idx = str::index(name, '/' as u8);
         if idx != -1 {
-            let source = str::unsafe::slice(name, 0u, idx as uint);
-            name = str::unsafe::slice(name, idx as uint + 1u,
+            let source = str::unsafe::slice_bytes(name, 0u, idx as uint);
+            name = str::unsafe::slice_bytes(name, idx as uint + 1u,
                                       str::byte_len(name));
             install_named_specific(c, wd, source, name);
         } else {
diff --git a/src/comp/back/link.rs b/src/comp/back/link.rs
index fee4356cadb..0052cdd352a 100644
--- a/src/comp/back/link.rs
+++ b/src/comp/back/link.rs
@@ -570,7 +570,7 @@ fn link_binary(sess: session,
                 (config.os == session::os_linux ||
                  config.os == session::os_freebsd) &&
                 str::find(filename, "lib") == 0 {
-                ret str::unsafe::slice(filename, 3u,
+                ret str::unsafe::slice_bytes(filename, 3u,
                                str::byte_len(filename));
             } else { ret filename; }
         };
diff --git a/src/comp/middle/debuginfo.rs b/src/comp/middle/debuginfo.rs
index b674af49b26..8732fa784a5 100644
--- a/src/comp/middle/debuginfo.rs
+++ b/src/comp/middle/debuginfo.rs
@@ -168,7 +168,7 @@ fn create_compile_unit(cx: @crate_ctxt, full_path: str)
 
     let work_dir = cx.sess.working_dir;
     let file_path = if str::starts_with(full_path, work_dir) {
-        str::unsafe::slice(full_path, str::byte_len(work_dir),
+        str::unsafe::slice_bytes(full_path, str::byte_len(work_dir),
                    str::byte_len(full_path))
     } else {
         full_path
diff --git a/src/comp/syntax/codemap.rs b/src/comp/syntax/codemap.rs
index eab92ab6ae9..eb6d1fd1d9d 100644
--- a/src/comp/syntax/codemap.rs
+++ b/src/comp/syntax/codemap.rs
@@ -118,11 +118,11 @@ fn get_line(fm: filemap, line: int) -> str unsafe {
         // parsed. If we just slice the rest of the string, we'll print out
         // the remainder of the file, which is undesirable.
         end = str::byte_len(*fm.src);
-        let rest = str::unsafe::slice(*fm.src, begin, end);
+        let rest = str::unsafe::slice_bytes(*fm.src, begin, end);
         let newline = str::index(rest, '\n' as u8);
         if newline != -1 { end = begin + (newline as uint); }
     }
-    ret str::unsafe::slice(*fm.src, begin, end);
+    ret str::unsafe::slice_bytes(*fm.src, begin, end);
 }
 
 fn get_filemap(cm: codemap, filename: str) -> filemap {
diff --git a/src/comp/syntax/parse/lexer.rs b/src/comp/syntax/parse/lexer.rs
index 30dacd27d4e..4d7ee27eb9d 100644
--- a/src/comp/syntax/parse/lexer.rs
+++ b/src/comp/syntax/parse/lexer.rs
@@ -27,7 +27,7 @@ impl reader for reader {
     fn get_str_from(start: uint) -> str unsafe {
         // I'm pretty skeptical about this subtraction. What if there's a
         // multi-byte character before the mark?
-        ret str::unsafe::slice(*self.src, start - 1u, self.pos - 1u);
+        ret str::unsafe::slice_bytes(*self.src, start - 1u, self.pos - 1u);
     }
     fn next() -> char {
         if self.pos < self.len {
@@ -584,7 +584,7 @@ fn trim_whitespace_prefix_and_push_line(&lines: [str],
     let s1;
     if all_whitespace(s, 0u, col) {
         if col < str::byte_len(s) {
-            s1 = str::unsafe::slice(s, col, str::byte_len(s));
+            s1 = str::unsafe::slice_bytes(s, col, str::byte_len(s));
         } else { s1 = ""; }
     } else { s1 = s; }
     log(debug, "pushing line: " + s1);
diff --git a/src/compiletest/errors.rs b/src/compiletest/errors.rs
index 014419a2aeb..3703badf527 100644
--- a/src/compiletest/errors.rs
+++ b/src/compiletest/errors.rs
@@ -41,11 +41,11 @@ fn parse_expected(line_num: uint, line: str) -> [expected_error] unsafe {
     while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
     let start_kind = idx;
     while idx < len && line[idx] != (' ' as u8) { idx += 1u; }
-    let kind = str::to_lower(str::unsafe::slice(line, start_kind, idx));
+    let kind = str::to_lower(str::unsafe::slice_bytes(line, start_kind, idx));
 
     // Extract msg:
     while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
-    let msg = str::unsafe::slice(line, idx, len);
+    let msg = str::unsafe::slice_bytes(line, idx, len);
 
     #debug("line=%u kind=%s msg=%s", line_num - adjust_line, kind, msg);
 
diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs
index 0f666528210..e09861141c4 100644
--- a/src/compiletest/header.rs
+++ b/src/compiletest/header.rs
@@ -109,7 +109,7 @@ fn parse_name_value_directive(line: str,
     if str::find(line, keycolon) >= 0 {
         let colon = str::find(line, keycolon) as uint;
         let value =
-            str::unsafe::slice(line, colon + str::byte_len(keycolon),
+            str::unsafe::slice_bytes(line, colon + str::byte_len(keycolon),
                        str::byte_len(line));
         #debug("%s: %s", directive,  value);
         option::some(value)
diff --git a/src/fuzzer/fuzzer.rs b/src/fuzzer/fuzzer.rs
index a6b1c13943a..a5cfb8db3f7 100644
--- a/src/fuzzer/fuzzer.rs
+++ b/src/fuzzer/fuzzer.rs
@@ -286,7 +286,7 @@ fn check_variants_T<T: copy>(
 fn last_part(filename: str) -> str unsafe {
   let ix = str::rindex(filename, 47u8 /* '/' */);
   assert ix >= 0;
-  str::unsafe::slice(filename, ix as uint + 1u, str::byte_len(filename) - 3u)
+  str::unsafe::slice_bytes(filename, ix as uint + 1u, str::byte_len(filename) - 3u)
 }
 
 enum happiness { passed, cleanly_rejected(str), known_bug(str), failed(str), }
diff --git a/src/libcore/str.rs b/src/libcore/str.rs
index 456e28c6ad8..742d31fea3e 100644
--- a/src/libcore/str.rs
+++ b/src/libcore/str.rs
@@ -38,8 +38,6 @@ export
    chars,
    substr,
    char_slice,
-   //slice,
-   //safe_slice,
    split,
    splitn,
    split_str,
@@ -425,7 +423,7 @@ Failure:
 If `begin` + `len` is is greater than the byte length of the string
 */
 fn substr(s: str, begin: uint, len: uint) -> str unsafe {
-    ret unsafe::slice(s, begin, begin + len);
+    ret unsafe::slice_bytes(s, begin, begin + len);
 }
 
 /*
@@ -447,48 +445,6 @@ fn char_slice(s: str, begin: uint, end: uint) -> str {
 }
 
 /*
-Function: slice
-
-Takes a bytewise slice from a string. Returns the substring from
-[`begin`..`end`).
-
-This function is not unicode-safe.
-
-Failure:
-
-- If begin is greater than end.
-- If end is greater than the length of the string.
-
-FIXME: rename to slice_byte or slice_byte_unsafe
-*/
-fn slice(s: str, begin: uint, end: uint) -> str unsafe {
-    // FIXME: Typestate precondition
-    assert (begin <= end);
-    assert (end <= byte_len(s));
-
-    let v: [u8] = ::unsafe::reinterpret_cast(s);
-    let v2 = vec::slice(v, begin, end);
-    ::unsafe::leak(v);
-    v2 += [0u8];
-    let s2: str = ::unsafe::reinterpret_cast(v2);
-    ::unsafe::leak(v2);
-    ret s2;
-}
-
-/*
-Function: safe_slice
-
-FIXME: make sure char_slice / slice / byte_slice
-       have these preconditions and assertions
-FIXME: this shouldn't be mistaken for a UTF-8 safe slice
-*/
-fn safe_slice(s: str, begin: uint, end: uint) : uint::le(begin, end) -> str {
-    // would need some magic to make this a precondition
-    assert (end <= byte_len(s));
-    ret slice(s, begin, end);
-}
-
-/*
 Function: split
 
 Split a string at each occurance of a given separator
@@ -712,7 +668,7 @@ fn replace(s: str, from: str, to: str) : is_not_empty(from) -> str unsafe {
     if byte_len(s) == 0u {
         ret "";
     } else if starts_with(s, from) {
-        ret to + replace(unsafe::slice(s, byte_len(from), byte_len(s)),
+        ret to + replace(unsafe::slice_bytes(s, byte_len(from), byte_len(s)),
                                        from, to);
     } else {
         let idx = find(s, from);
@@ -1348,8 +1304,8 @@ mod unsafe {
       // UNSAFE
       from_bytes,
       from_byte,
-      slice,
-      safe_slice;
+      slice_bytes,
+      slice_bytes_safe_range;
 
    // Function: unsafe::from_bytes
    //
@@ -1371,19 +1327,15 @@ mod unsafe {
    /*
    Function: slice
 
-   Takes a bytewise slice from a string. Returns the substring from
-   [`begin`..`end`).
-
-   This function is not unicode-safe.
+   Takes a bytewise (not UTF-8) slice from a string.
+   Returns the substring from [`begin`..`end`).
 
    Failure:
 
    - If begin is greater than end.
    - If end is greater than the length of the string.
-
-   FIXME: rename to byte_slice
    */
-   unsafe fn slice(s: str, begin: uint, end: uint) -> str unsafe {
+   unsafe fn slice_bytes(s: str, begin: uint, end: uint) -> str unsafe {
        // FIXME: Typestate precondition
        assert (begin <= end);
        assert (end <= byte_len(s));
@@ -1398,15 +1350,15 @@ mod unsafe {
    }
 
    /*
-   Function: safe_slice
+   Function: slice_bytes_safe_range
 
-   FIXME: rename to safe_range_byte_slice
+   Like slice_bytes, with a precondition
    */
-   unsafe fn safe_slice(s: str, begin: uint, end: uint)
+   unsafe fn slice_bytes_safe_range(s: str, begin: uint, end: uint)
        : uint::le(begin, end) -> str {
        // would need some magic to make this a precondition
        assert (end <= byte_len(s));
-       ret slice(s, begin, end);
+       ret slice_bytes(s, begin, end);
    }
 
 }
@@ -1653,7 +1605,7 @@ mod tests {
             ret rs;
         }
         assert (eq(half_a_million_letter_a(),
-                        unsafe::slice(a_million_letter_a(), 0u, 500000u)));
+               unsafe::slice_bytes(a_million_letter_a(), 0u, 500000u)));
     }
 
     #[test]
diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs
index 26a9931a0cb..1e5c9657d1e 100644
--- a/src/libstd/fs.rs
+++ b/src/libstd/fs.rs
@@ -71,7 +71,7 @@ fn basename(p: path) -> path unsafe {
     }
     let len = str::byte_len(p);
     if i + 1 as uint >= len { ret p; }
-    ret str::unsafe::slice(p, i + 1 as uint, len);
+    ret str::unsafe::slice_bytes(p, i + 1 as uint, len);
 }
 
 
diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs
index 5510dd3231a..bc96cb65efa 100644
--- a/src/libstd/getopts.rs
+++ b/src/libstd/getopts.rs
@@ -229,14 +229,15 @@ fn getopts(args: [str], opts: [opt]) -> result unsafe {
             let names;
             let i_arg = option::none::<str>;
             if cur[1] == '-' as u8 {
-                let tail = str::unsafe::slice(cur, 2u, curlen);
+                let tail = str::unsafe::slice_bytes(cur, 2u, curlen);
                 let eq = str::index(tail, '=' as u8);
                 if eq == -1 {
                     names = [long(tail)];
                 } else {
-                    names = [long(str::unsafe::slice(tail, 0u, eq as uint))];
+                    names =
+                        [long(str::unsafe::slice_bytes(tail,0u,eq as uint))];
                     i_arg =
-                        option::some::<str>(str::unsafe::slice(tail,
+                        option::some::<str>(str::unsafe::slice_bytes(tail,
                                                        (eq as uint) + 1u,
                                                        curlen - 2u));
                 }
diff --git a/src/test/compile-fail/fn-constraint.rs b/src/test/compile-fail/fn-constraint.rs
index fadec3f9730..b8a4a164c7e 100644
--- a/src/test/compile-fail/fn-constraint.rs
+++ b/src/test/compile-fail/fn-constraint.rs
@@ -5,5 +5,5 @@ import str::*;
 fn main() unsafe {
     let a: uint = 4u;
     let b: uint = 1u;
-    log(error, str::unsafe::safe_slice("kitties", a, b));
+    log(error, str::unsafe::slice_bytes_safe_range("kitties", a, b));
 }
diff --git a/src/test/compile-fail/no-constraint-prop.rs b/src/test/compile-fail/no-constraint-prop.rs
index 78f3a3cf40c..ae5a024863b 100644
--- a/src/test/compile-fail/no-constraint-prop.rs
+++ b/src/test/compile-fail/no-constraint-prop.rs
@@ -16,5 +16,5 @@ fn main() unsafe {
     // the next statement, since it's not true in the
     // prestate.
     let d <- a;
-    log(debug, str::unsafe::safe_slice("kitties", b, d));
+    log(debug, str::unsafe::slice_bytes_safe_range("kitties", b, d));
 }
diff --git a/src/test/run-fail/fn-constraint.rs b/src/test/run-fail/fn-constraint.rs
index 9d9974abf71..5277b1bc6e1 100644
--- a/src/test/run-fail/fn-constraint.rs
+++ b/src/test/run-fail/fn-constraint.rs
@@ -7,5 +7,5 @@ fn main() unsafe {
     let a: uint = 4u;
     let b: uint = 1u;
     check (le(a, b));
-    log(error, str::unsafe::safe_slice("kitties", a, b));
+    log(error, str::unsafe::slice_bytes_safe_range("kitties", a, b));
 }
diff --git a/src/test/run-pass/constraint-prop-expr-move.rs b/src/test/run-pass/constraint-prop-expr-move.rs
index 105e84e9fdf..1f8e6f69b27 100644
--- a/src/test/run-pass/constraint-prop-expr-move.rs
+++ b/src/test/run-pass/constraint-prop-expr-move.rs
@@ -8,5 +8,5 @@ fn main() unsafe {
     let c: uint = 17u;
     check (le(a, b));
     c <- a;
-    log(debug, str::unsafe::safe_slice("kitties", c, b));
+    log(debug, str::unsafe::slice_bytes_safe_range("kitties", c, b));
 }
diff --git a/src/test/run-pass/constraint-prop-move.rs b/src/test/run-pass/constraint-prop-move.rs
index 0cc748e2c83..12124e8801f 100644
--- a/src/test/run-pass/constraint-prop-move.rs
+++ b/src/test/run-pass/constraint-prop-move.rs
@@ -7,5 +7,5 @@ fn main() unsafe {
     let b: uint = 4u;
     check (le(a, b));
     let c <- a;
-    log(debug, str::unsafe::safe_slice("kitties", c, b));
+    log(debug, str::unsafe::slice_bytes_safe_range("kitties", c, b));
 }
diff --git a/src/test/run-pass/constraint-prop-swap.rs b/src/test/run-pass/constraint-prop-swap.rs
index d7eb9fbf066..6c9af246dbd 100644
--- a/src/test/run-pass/constraint-prop-swap.rs
+++ b/src/test/run-pass/constraint-prop-swap.rs
@@ -7,5 +7,5 @@ fn main() unsafe {
     let b: uint = 1u;
     check (le(b, a));
     b <-> a;
-    log(debug, str::unsafe::safe_slice("kitties", a, b));
+    log(debug, str::unsafe::slice_bytes_safe_range("kitties", a, b));
 }
diff --git a/src/test/run-pass/constraint-prop.rs b/src/test/run-pass/constraint-prop.rs
index 53c9a3bd965..62cee45c958 100644
--- a/src/test/run-pass/constraint-prop.rs
+++ b/src/test/run-pass/constraint-prop.rs
@@ -7,5 +7,5 @@ fn main() unsafe {
     let b: uint = 4u;
     check (le(a, b));
     let c = b;
-    log(debug, str::unsafe::safe_slice("kitties", a, c));
+    log(debug, str::unsafe::slice_bytes_safe_range("kitties", a, c));
 }
diff --git a/src/test/run-pass/fn-constraint.rs b/src/test/run-pass/fn-constraint.rs
index 11383faed3f..2d5e28f209c 100644
--- a/src/test/run-pass/fn-constraint.rs
+++ b/src/test/run-pass/fn-constraint.rs
@@ -6,5 +6,5 @@ fn main() unsafe {
     let a: uint = 1u;
     let b: uint = 4u;
     check (le(a, b));
-    log(debug, str::unsafe::safe_slice("kitties", a, b));
+    log(debug, str::unsafe::slice_bytes_safe_range("kitties", a, b));
 }