diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2013-06-11 13:10:37 +1000 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2013-06-12 12:21:04 +1000 |
| commit | efc71a8bdb28fba88d0cc8916b33838bf43b3a8d (patch) | |
| tree | ad0086d4319facd8da21583e19a952a01250bbbd /src/test | |
| parent | ba4a4778cc17c64c33a891a0d2565a1fb04ddffc (diff) | |
std: unify the str -> [u8] functions as 3 methods: .as_bytes() and .as_bytes_with_null[_consume]().
The first acts on &str and is not nul-terminated, the last two act on strings that are always null terminated (&'static str, ~str and @str).
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/bench/shootout-fasta-redux.rs | 2 | ||||
| -rw-r--r-- | src/test/bench/shootout-k-nucleotide-pipes.rs | 7 | ||||
| -rw-r--r-- | src/test/bench/shootout-k-nucleotide.rs | 3 | ||||
| -rw-r--r-- | src/test/bench/shootout-pfib.rs | 3 | ||||
| -rw-r--r-- | src/test/run-pass/foreign-fn-linkname.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/hashmap-memory.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/issue-1696.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/utf8_chars.rs | 2 |
8 files changed, 11 insertions, 12 deletions
diff --git a/src/test/bench/shootout-fasta-redux.rs b/src/test/bench/shootout-fasta-redux.rs index bc1685a1092..3d5fc01afa6 100644 --- a/src/test/bench/shootout-fasta-redux.rs +++ b/src/test/bench/shootout-fasta-redux.rs @@ -93,7 +93,7 @@ impl RepeatFasta { let stdout = self.stdout; let alu_len = self.alu.len(); let mut buf = vec::from_elem(alu_len + LINE_LEN, 0u8); - let alu: &[u8] = str::byte_slice_no_callback(self.alu); + let alu: &[u8] = self.alu.as_bytes_with_null(); copy_memory(buf, alu, alu_len); copy_memory(vec::mut_slice(buf, alu_len, buf.len()), diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index 9ba9b9759fd..b7969fb0552 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -81,7 +81,8 @@ fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str { fn find(mm: &HashMap<~[u8], uint>, key: ~str) -> uint { // FIXME: #4318 Instead of to_ascii and to_str_ascii, could use // to_ascii_consume and to_str_consume to not do a unnecessary copy. - match mm.find(&str::to_bytes(key.to_ascii().to_lower().to_str_ascii())) { + let key = key.to_ascii().to_lower().to_str_ascii(); + match mm.find_equiv(&key.as_bytes()) { option::None => { return 0u; } option::Some(&num) => { return num; } } @@ -208,10 +209,10 @@ fn main() { // process the sequence for k-mers (_, true) => { - let line_bytes = str::to_bytes(line); + let line_bytes = line.as_bytes(); for sizes.eachi |ii, _sz| { - let mut lb = copy line_bytes; + let mut lb = line_bytes.to_owned(); to_child[ii].send(lb); } } diff --git a/src/test/bench/shootout-k-nucleotide.rs b/src/test/bench/shootout-k-nucleotide.rs index a70e0730073..646b9788f70 100644 --- a/src/test/bench/shootout-k-nucleotide.rs +++ b/src/test/bench/shootout-k-nucleotide.rs @@ -218,8 +218,7 @@ fn read_stdin() -> ~[u8] { fstat(fileno(stdin), &mut st); let mut buf = vec::from_elem(st.st_size as uint, 0); - let header = str::byte_slice_no_callback(">THREE"); - let header = vec::slice(header, 0, 6); + let header = ">THREE".as_bytes(); { let mut window: &mut [u8] = buf; diff --git a/src/test/bench/shootout-pfib.rs b/src/test/bench/shootout-pfib.rs index 0a093d87a15..b869aa0e342 100644 --- a/src/test/bench/shootout-pfib.rs +++ b/src/test/bench/shootout-pfib.rs @@ -111,8 +111,7 @@ fn main() { if opts.stress { stress(2); } else { - let max = uint::parse_bytes(str::to_bytes(args[1]), - 10u).get() as int; + let max = uint::parse_bytes(args[1].as_bytes(), 10u).get() as int; let num_trials = 10; diff --git a/src/test/run-pass/foreign-fn-linkname.rs b/src/test/run-pass/foreign-fn-linkname.rs index 27b0c903791..36ac10915c0 100644 --- a/src/test/run-pass/foreign-fn-linkname.rs +++ b/src/test/run-pass/foreign-fn-linkname.rs @@ -26,7 +26,7 @@ mod libc { fn strlen(str: ~str) -> uint { unsafe { // C string is terminated with a zero - let bytes = str::to_bytes(str) + ~[0u8]; + let bytes = str.as_bytes_with_null_consume(); return libc::my_strlen(vec::raw::to_ptr(bytes)); } } diff --git a/src/test/run-pass/hashmap-memory.rs b/src/test/run-pass/hashmap-memory.rs index e7317031332..eae2f507c51 100644 --- a/src/test/run-pass/hashmap-memory.rs +++ b/src/test/run-pass/hashmap-memory.rs @@ -48,7 +48,7 @@ mod map_reduce { } let (pp, cc) = stream(); error!("sending find_reducer"); - ctrl.send(find_reducer(str::to_bytes(key), cc)); + ctrl.send(find_reducer(key.as_bytes().to_owned(), cc)); error!("receiving"); let c = pp.recv(); error!(c); diff --git a/src/test/run-pass/issue-1696.rs b/src/test/run-pass/issue-1696.rs index 62088e013be..103679a13ef 100644 --- a/src/test/run-pass/issue-1696.rs +++ b/src/test/run-pass/issue-1696.rs @@ -15,6 +15,6 @@ use std::str; pub fn main() { let mut m = HashMap::new(); - m.insert(str::to_bytes(~"foo"), str::to_bytes(~"bar")); + m.insert("foo".as_bytes().to_owned(), "bar".as_bytes().to_owned()); error!(m); } diff --git a/src/test/run-pass/utf8_chars.rs b/src/test/run-pass/utf8_chars.rs index 477f06a2be1..11f0d59c700 100644 --- a/src/test/run-pass/utf8_chars.rs +++ b/src/test/run-pass/utf8_chars.rs @@ -27,7 +27,7 @@ pub fn main() { assert!(s.char_at(0u) == 'e'); assert!(s.char_at(1u) == 'é'); - assert!((str::is_utf8(str::to_bytes(s)))); + assert!((str::is_utf8(s.as_bytes()))); assert!((!str::is_utf8(~[0x80_u8]))); assert!((!str::is_utf8(~[0xc0_u8]))); assert!((!str::is_utf8(~[0xc0_u8, 0x10_u8]))); |
