Skip to content

Commit cfb9cba

Browse files
committed
Convert str::from_chars, to_chars to ivecs
1 parent 878fbac commit cfb9cba

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/lib/str.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ fn from_char(ch: char) -> str {
241241
ret buf;
242242
}
243243

244-
fn from_chars(chs: vec[char]) -> str {
244+
fn from_chars(chs: &[char]) -> str {
245245
let buf = "";
246246
for ch: char in chs { push_utf8_bytes(buf, ch); }
247247
ret buf;
@@ -300,13 +300,13 @@ fn char_len(s: str) -> uint {
300300
ret len;
301301
}
302302

303-
fn to_chars(s: str) -> vec[char] {
304-
let buf: vec[char] = [];
303+
fn to_chars(s: str) -> [char] {
304+
let buf: [char] = ~[];
305305
let i = 0u;
306306
let len = byte_len(s);
307307
while i < len {
308308
let cur = char_range_at(s, i);
309-
vec::push[char](buf, cur.ch);
309+
buf += ~[cur.ch];
310310
i = cur.next;
311311
}
312312
ret buf;
@@ -524,13 +524,13 @@ fn replace(s: str, from: str, to: str) : is_not_empty(from) -> str {
524524

525525
// FIXME: Also not efficient
526526
fn char_slice(s: &str, begin: uint, end: uint) -> str {
527-
from_chars(vec::slice(to_chars(s), begin, end))
527+
from_chars(ivec::slice(to_chars(s), begin, end))
528528
}
529529

530530
fn trim_left(s: &str) -> str {
531-
fn count_whities(s: &vec[char]) -> uint {
531+
fn count_whities(s: &[char]) -> uint {
532532
let i = 0u;
533-
while i < vec::len(s) {
533+
while i < ivec::len(s) {
534534
if !char::is_whitespace(s.(i)) {
535535
break;
536536
}
@@ -540,12 +540,12 @@ fn trim_left(s: &str) -> str {
540540
}
541541
let chars = to_chars(s);
542542
let whities = count_whities(chars);
543-
ret from_chars(vec::slice(chars, whities, vec::len(chars)));
543+
ret from_chars(ivec::slice(chars, whities, ivec::len(chars)));
544544
}
545545

546546
fn trim_right(s: &str) -> str {
547-
fn count_whities(s: &vec[char]) -> uint {
548-
let i = vec::len(s);
547+
fn count_whities(s: &[char]) -> uint {
548+
let i = ivec::len(s);
549549
while 0u < i {
550550
if !char::is_whitespace(s.(i - 1u)) {
551551
break;
@@ -556,7 +556,7 @@ fn trim_right(s: &str) -> str {
556556
}
557557
let chars = to_chars(s);
558558
let whities = count_whities(chars);
559-
ret from_chars(vec::slice(chars, 0u, whities));
559+
ret from_chars(ivec::slice(chars, 0u, whities));
560560
}
561561

562562
fn trim(s: &str) -> str {

src/test/run-pass/utf8_chars.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
use std;
22
import std::str;
3-
import std::vec;
43
import std::io;
54
import std::ivec;
65

76
fn main() {
87
// Chars of 1, 2, 3, and 4 bytes
9-
let chs: vec[char] = ['e', 'é', '€', 0x10000 as char];
8+
let chs: [char] = ~['e', 'é', '€', 0x10000 as char];
109
let s: str = str::from_chars(chs);
1110

1211
assert (str::byte_len(s) == 10u);
1312
assert (str::char_len(s) == 4u);
14-
assert (vec::len[char](str::to_chars(s)) == 4u);
13+
assert (ivec::len[char](str::to_chars(s)) == 4u);
1514
assert (str::eq(str::from_chars(str::to_chars(s)), s));
1615
assert (str::char_at(s, 0u) == 'e');
1716
assert (str::char_at(s, 1u) == 'é');

0 commit comments

Comments
 (0)