Skip to content

Commit b874ce2

Browse files
committed
---
yaml --- r: 113081 b: refs/heads/try c: 4b3017c h: refs/heads/master i: 113079: b71a693 v: v3
1 parent 383174f commit b874ce2

File tree

2 files changed

+86
-92
lines changed

2 files changed

+86
-92
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: abdacecdf86b4b5a4f432560445a24e1c5f4751b
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 922c420fcd4dfbfc7e3bce4dd20d9b17a20b39f3
5-
refs/heads/try: bd6be3ed60180b659bf5decbcdd654a3a1e4c5da
5+
refs/heads/try: 4b3017c79877bf34cdb0d708de68d88936f95950
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libstd/str.rs

Lines changed: 85 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ use option::{None, Option, Some};
9292
use ptr;
9393
use from_str::FromStr;
9494
use slice;
95-
use slice::{OwnedVector, ImmutableVector, MutableVector};
95+
use slice::{OwnedVector, ImmutableVector, MutableVector, CloneableVector};
9696
use slice::{Vector};
9797
use vec::Vec;
9898
use default::Default;
@@ -1343,16 +1343,14 @@ pub mod raw {
13431343
use raw::Slice;
13441344
use slice::{MutableVector, ImmutableVector, OwnedVector, Vector};
13451345
use str::{is_utf8, StrSlice};
1346-
use vec::Vec;
13471346

13481347
/// Create a Rust string from a *u8 buffer of the given length
13491348
pub unsafe fn from_buf_len(buf: *u8, len: uint) -> ~str {
1350-
let mut v = Vec::with_capacity(len);
1351-
ptr::copy_memory(v.as_mut_ptr(), buf, len);
1352-
v.set_len(len);
1353-
1354-
assert!(is_utf8(v.as_slice()));
1355-
::cast::transmute(v.move_iter().collect::<~[u8]>())
1349+
let v = Slice { data: buf, len: len };
1350+
let bytes: &[u8] = ::cast::transmute(v);
1351+
assert!(is_utf8(bytes));
1352+
let s: &str = ::cast::transmute(bytes);
1353+
s.to_owned()
13561354
}
13571355

13581356
#[lang="strdup_uniq"]
@@ -2041,7 +2039,7 @@ pub trait StrSlice<'a> {
20412039
fn to_owned(&self) -> ~str;
20422040

20432041
/// Converts to a vector of `u16` encoded as UTF-16.
2044-
fn to_utf16(&self) -> ~[u16];
2042+
fn to_utf16(&self) -> Vec<u16>;
20452043

20462044
/// Check that `index`-th byte lies at the start and/or end of a
20472045
/// UTF-8 code point sequence.
@@ -2545,24 +2543,19 @@ impl<'a> StrSlice<'a> for &'a str {
25452543

25462544
#[inline]
25472545
fn to_owned(&self) -> ~str {
2548-
let len = self.len();
25492546
unsafe {
2550-
let mut v = Vec::with_capacity(len);
2551-
2552-
ptr::copy_memory(v.as_mut_ptr(), self.as_ptr(), len);
2553-
v.set_len(len);
2554-
::cast::transmute(v.move_iter().collect::<~[u8]>())
2547+
::cast::transmute(self.as_bytes().to_owned())
25552548
}
25562549
}
25572550

2558-
fn to_utf16(&self) -> ~[u16] {
2551+
fn to_utf16(&self) -> Vec<u16> {
25592552
let mut u = Vec::new();;
25602553
for ch in self.chars() {
25612554
let mut buf = [0u16, ..2];
25622555
let n = ch.encode_utf16(buf /* as mut slice! */);
25632556
u.push_all(buf.slice_to(n));
25642557
}
2565-
u.move_iter().collect()
2558+
u
25662559
}
25672560

25682561
#[inline]
@@ -3393,7 +3386,8 @@ mod tests {
33933386
assert_eq!(a.subslice_offset(c), 0);
33943387

33953388
let string = "a\nb\nc";
3396-
let lines: ~[&str] = string.lines().collect();
3389+
let lines: Vec<&str> = string.lines().collect();
3390+
let lines = lines.as_slice();
33973391
assert_eq!(string.subslice_offset(lines[0]), 0);
33983392
assert_eq!(string.subslice_offset(lines[1]), 2);
33993393
assert_eq!(string.subslice_offset(lines[2]), 4);
@@ -3456,21 +3450,21 @@ mod tests {
34563450
fn test_utf16() {
34573451
let pairs =
34583452
[("𐍅𐌿𐌻𐍆𐌹𐌻𐌰\n".to_owned(),
3459-
box [0xd800_u16, 0xdf45_u16, 0xd800_u16, 0xdf3f_u16,
3453+
vec![0xd800_u16, 0xdf45_u16, 0xd800_u16, 0xdf3f_u16,
34603454
0xd800_u16, 0xdf3b_u16, 0xd800_u16, 0xdf46_u16,
34613455
0xd800_u16, 0xdf39_u16, 0xd800_u16, 0xdf3b_u16,
34623456
0xd800_u16, 0xdf30_u16, 0x000a_u16]),
34633457

34643458
("𐐒𐑉𐐮𐑀𐐲𐑋 𐐏𐐲𐑍\n".to_owned(),
3465-
box [0xd801_u16, 0xdc12_u16, 0xd801_u16,
3459+
vec![0xd801_u16, 0xdc12_u16, 0xd801_u16,
34663460
0xdc49_u16, 0xd801_u16, 0xdc2e_u16, 0xd801_u16,
34673461
0xdc40_u16, 0xd801_u16, 0xdc32_u16, 0xd801_u16,
34683462
0xdc4b_u16, 0x0020_u16, 0xd801_u16, 0xdc0f_u16,
34693463
0xd801_u16, 0xdc32_u16, 0xd801_u16, 0xdc4d_u16,
34703464
0x000a_u16]),
34713465

34723466
("𐌀𐌖𐌋𐌄𐌑𐌉·𐌌𐌄𐌕𐌄𐌋𐌉𐌑\n".to_owned(),
3473-
box [0xd800_u16, 0xdf00_u16, 0xd800_u16, 0xdf16_u16,
3467+
vec![0xd800_u16, 0xdf00_u16, 0xd800_u16, 0xdf16_u16,
34743468
0xd800_u16, 0xdf0b_u16, 0xd800_u16, 0xdf04_u16,
34753469
0xd800_u16, 0xdf11_u16, 0xd800_u16, 0xdf09_u16,
34763470
0x00b7_u16, 0xd800_u16, 0xdf0c_u16, 0xd800_u16,
@@ -3479,7 +3473,7 @@ mod tests {
34793473
0xdf09_u16, 0xd800_u16, 0xdf11_u16, 0x000a_u16 ]),
34803474

34813475
("𐒋𐒘𐒈𐒑𐒛𐒒 𐒕𐒓 𐒈𐒚𐒍 𐒏𐒜𐒒𐒖𐒆 𐒕𐒆\n".to_owned(),
3482-
box [0xd801_u16, 0xdc8b_u16, 0xd801_u16, 0xdc98_u16,
3476+
vec![0xd801_u16, 0xdc8b_u16, 0xd801_u16, 0xdc98_u16,
34833477
0xd801_u16, 0xdc88_u16, 0xd801_u16, 0xdc91_u16,
34843478
0xd801_u16, 0xdc9b_u16, 0xd801_u16, 0xdc92_u16,
34853479
0x0020_u16, 0xd801_u16, 0xdc95_u16, 0xd801_u16,
@@ -3492,18 +3486,18 @@ mod tests {
34923486
0x000a_u16 ]),
34933487
// Issue #12318, even-numbered non-BMP planes
34943488
("\U00020000".to_owned(),
3495-
box [0xD840, 0xDC00])];
3489+
vec![0xD840, 0xDC00])];
34963490

34973491
for p in pairs.iter() {
34983492
let (s, u) = (*p).clone();
3499-
assert!(is_utf16(u));
3493+
assert!(is_utf16(u.as_slice()));
35003494
assert_eq!(s.to_utf16(), u);
35013495

3502-
assert_eq!(from_utf16(u).unwrap(), s);
3503-
assert_eq!(from_utf16_lossy(u), s);
3496+
assert_eq!(from_utf16(u.as_slice()).unwrap(), s);
3497+
assert_eq!(from_utf16_lossy(u.as_slice()), s);
35043498

3505-
assert_eq!(from_utf16(s.to_utf16()).unwrap(), s);
3506-
assert_eq!(from_utf16(u).unwrap().to_utf16(), u);
3499+
assert_eq!(from_utf16(s.to_utf16().as_slice()).unwrap(), s);
3500+
assert_eq!(from_utf16(u.as_slice()).unwrap().to_utf16(), u);
35073501
}
35083502
}
35093503

@@ -3760,105 +3754,105 @@ mod tests {
37603754
fn test_split_char_iterator() {
37613755
let data = "\nMäry häd ä little lämb\nLittle lämb\n";
37623756

3763-
let split: ~[&str] = data.split(' ').collect();
3764-
assert_eq!( split, box ["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]);
3757+
let split: Vec<&str> = data.split(' ').collect();
3758+
assert_eq!( split, vec!["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]);
37653759

3766-
let mut rsplit: ~[&str] = data.split(' ').rev().collect();
3760+
let mut rsplit: Vec<&str> = data.split(' ').rev().collect();
37673761
rsplit.reverse();
3768-
assert_eq!(rsplit, box ["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]);
3762+
assert_eq!(rsplit, vec!["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]);
37693763

3770-
let split: ~[&str] = data.split(|c: char| c == ' ').collect();
3771-
assert_eq!( split, box ["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]);
3764+
let split: Vec<&str> = data.split(|c: char| c == ' ').collect();
3765+
assert_eq!( split, vec!["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]);
37723766

3773-
let mut rsplit: ~[&str] = data.split(|c: char| c == ' ').rev().collect();
3767+
let mut rsplit: Vec<&str> = data.split(|c: char| c == ' ').rev().collect();
37743768
rsplit.reverse();
3775-
assert_eq!(rsplit, box ["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]);
3769+
assert_eq!(rsplit, vec!["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]);
37763770

37773771
// Unicode
3778-
let split: ~[&str] = data.split('ä').collect();
3779-
assert_eq!( split, box ["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]);
3772+
let split: Vec<&str> = data.split('ä').collect();
3773+
assert_eq!( split, vec!["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]);
37803774

3781-
let mut rsplit: ~[&str] = data.split('ä').rev().collect();
3775+
let mut rsplit: Vec<&str> = data.split('ä').rev().collect();
37823776
rsplit.reverse();
3783-
assert_eq!(rsplit, box ["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]);
3777+
assert_eq!(rsplit, vec!["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]);
37843778

3785-
let split: ~[&str] = data.split(|c: char| c == 'ä').collect();
3786-
assert_eq!( split, box ["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]);
3779+
let split: Vec<&str> = data.split(|c: char| c == 'ä').collect();
3780+
assert_eq!( split, vec!["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]);
37873781

3788-
let mut rsplit: ~[&str] = data.split(|c: char| c == 'ä').rev().collect();
3782+
let mut rsplit: Vec<&str> = data.split(|c: char| c == 'ä').rev().collect();
37893783
rsplit.reverse();
3790-
assert_eq!(rsplit, box ["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]);
3784+
assert_eq!(rsplit, vec!["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]);
37913785
}
37923786

37933787
#[test]
37943788
fn test_splitn_char_iterator() {
37953789
let data = "\nMäry häd ä little lämb\nLittle lämb\n";
37963790

3797-
let split: ~[&str] = data.splitn(' ', 3).collect();
3798-
assert_eq!(split, box ["\nMäry", "häd", "ä", "little lämb\nLittle lämb\n"]);
3791+
let split: Vec<&str> = data.splitn(' ', 3).collect();
3792+
assert_eq!(split, vec!["\nMäry", "häd", "ä", "little lämb\nLittle lämb\n"]);
37993793

3800-
let split: ~[&str] = data.splitn(|c: char| c == ' ', 3).collect();
3801-
assert_eq!(split, box ["\nMäry", "häd", "ä", "little lämb\nLittle lämb\n"]);
3794+
let split: Vec<&str> = data.splitn(|c: char| c == ' ', 3).collect();
3795+
assert_eq!(split, vec!["\nMäry", "häd", "ä", "little lämb\nLittle lämb\n"]);
38023796

38033797
// Unicode
3804-
let split: ~[&str] = data.splitn('ä', 3).collect();
3805-
assert_eq!(split, box ["\nM", "ry h", "d ", " little lämb\nLittle lämb\n"]);
3798+
let split: Vec<&str> = data.splitn('ä', 3).collect();
3799+
assert_eq!(split, vec!["\nM", "ry h", "d ", " little lämb\nLittle lämb\n"]);
38063800

3807-
let split: ~[&str] = data.splitn(|c: char| c == 'ä', 3).collect();
3808-
assert_eq!(split, box ["\nM", "ry h", "d ", " little lämb\nLittle lämb\n"]);
3801+
let split: Vec<&str> = data.splitn(|c: char| c == 'ä', 3).collect();
3802+
assert_eq!(split, vec!["\nM", "ry h", "d ", " little lämb\nLittle lämb\n"]);
38093803
}
38103804

38113805
#[test]
38123806
fn test_rsplitn_char_iterator() {
38133807
let data = "\nMäry häd ä little lämb\nLittle lämb\n";
38143808

3815-
let mut split: ~[&str] = data.rsplitn(' ', 3).collect();
3809+
let mut split: Vec<&str> = data.rsplitn(' ', 3).collect();
38163810
split.reverse();
3817-
assert_eq!(split, box ["\nMäry häd ä", "little", "lämb\nLittle", "lämb\n"]);
3811+
assert_eq!(split, vec!["\nMäry häd ä", "little", "lämb\nLittle", "lämb\n"]);
38183812

3819-
let mut split: ~[&str] = data.rsplitn(|c: char| c == ' ', 3).collect();
3813+
let mut split: Vec<&str> = data.rsplitn(|c: char| c == ' ', 3).collect();
38203814
split.reverse();
3821-
assert_eq!(split, box ["\nMäry häd ä", "little", "lämb\nLittle", "lämb\n"]);
3815+
assert_eq!(split, vec!["\nMäry häd ä", "little", "lämb\nLittle", "lämb\n"]);
38223816

38233817
// Unicode
3824-
let mut split: ~[&str] = data.rsplitn('ä', 3).collect();
3818+
let mut split: Vec<&str> = data.rsplitn('ä', 3).collect();
38253819
split.reverse();
3826-
assert_eq!(split, box ["\nMäry häd ", " little l", "mb\nLittle l", "mb\n"]);
3820+
assert_eq!(split, vec!["\nMäry häd ", " little l", "mb\nLittle l", "mb\n"]);
38273821

3828-
let mut split: ~[&str] = data.rsplitn(|c: char| c == 'ä', 3).collect();
3822+
let mut split: Vec<&str> = data.rsplitn(|c: char| c == 'ä', 3).collect();
38293823
split.reverse();
3830-
assert_eq!(split, box ["\nMäry häd ", " little l", "mb\nLittle l", "mb\n"]);
3824+
assert_eq!(split, vec!["\nMäry häd ", " little l", "mb\nLittle l", "mb\n"]);
38313825
}
38323826

38333827
#[test]
38343828
fn test_split_char_iterator_no_trailing() {
38353829
let data = "\nMäry häd ä little lämb\nLittle lämb\n";
38363830

3837-
let split: ~[&str] = data.split('\n').collect();
3838-
assert_eq!(split, box ["", "Märy häd ä little lämb", "Little lämb", ""]);
3831+
let split: Vec<&str> = data.split('\n').collect();
3832+
assert_eq!(split, vec!["", "Märy häd ä little lämb", "Little lämb", ""]);
38393833

3840-
let split: ~[&str] = data.split_terminator('\n').collect();
3841-
assert_eq!(split, box ["", "Märy häd ä little lämb", "Little lämb"]);
3834+
let split: Vec<&str> = data.split_terminator('\n').collect();
3835+
assert_eq!(split, vec!["", "Märy häd ä little lämb", "Little lämb"]);
38423836
}
38433837

38443838
#[test]
38453839
fn test_rev_split_char_iterator_no_trailing() {
38463840
let data = "\nMäry häd ä little lämb\nLittle lämb\n";
38473841

3848-
let mut split: ~[&str] = data.split('\n').rev().collect();
3842+
let mut split: Vec<&str> = data.split('\n').rev().collect();
38493843
split.reverse();
3850-
assert_eq!(split, box ["", "Märy häd ä little lämb", "Little lämb", ""]);
3844+
assert_eq!(split, vec!["", "Märy häd ä little lämb", "Little lämb", ""]);
38513845

3852-
let mut split: ~[&str] = data.split_terminator('\n').rev().collect();
3846+
let mut split: Vec<&str> = data.split_terminator('\n').rev().collect();
38533847
split.reverse();
3854-
assert_eq!(split, box ["", "Märy häd ä little lämb", "Little lämb"]);
3848+
assert_eq!(split, vec!["", "Märy häd ä little lämb", "Little lämb"]);
38553849
}
38563850

38573851
#[test]
38583852
fn test_words() {
38593853
let data = "\n \tMäry häd\tä little lämb\nLittle lämb\n";
3860-
let words: ~[&str] = data.words().collect();
3861-
assert_eq!(words, box ["Märy", "häd", "ä", "little", "lämb", "Little", "lämb"])
3854+
let words: Vec<&str> = data.words().collect();
3855+
assert_eq!(words, vec!["Märy", "häd", "ä", "little", "lämb", "Little", "lämb"])
38623856
}
38633857

38643858
#[test]
@@ -3892,34 +3886,34 @@ mod tests {
38923886
#[test]
38933887
fn test_lines() {
38943888
let data = "\nMäry häd ä little lämb\n\nLittle lämb\n";
3895-
let lines: ~[&str] = data.lines().collect();
3896-
assert_eq!(lines, box ["", "Märy häd ä little lämb", "", "Little lämb"]);
3889+
let lines: Vec<&str> = data.lines().collect();
3890+
assert_eq!(lines, vec!["", "Märy häd ä little lämb", "", "Little lämb"]);
38973891

38983892
let data = "\nMäry häd ä little lämb\n\nLittle lämb"; // no trailing \n
3899-
let lines: ~[&str] = data.lines().collect();
3900-
assert_eq!(lines, box ["", "Märy häd ä little lämb", "", "Little lämb"]);
3893+
let lines: Vec<&str> = data.lines().collect();
3894+
assert_eq!(lines, vec!["", "Märy häd ä little lämb", "", "Little lämb"]);
39013895
}
39023896

39033897
#[test]
39043898
fn test_split_strator() {
3905-
fn t<'a>(s: &str, sep: &'a str, u: ~[&str]) {
3906-
let v: ~[&str] = s.split_str(sep).collect();
3907-
assert_eq!(v, u);
3899+
fn t(s: &str, sep: &str, u: &[&str]) {
3900+
let v: Vec<&str> = s.split_str(sep).collect();
3901+
assert_eq!(v.as_slice(), u.as_slice());
39083902
}
3909-
t("--1233345--", "12345", box ["--1233345--"]);
3910-
t("abc::hello::there", "::", box ["abc", "hello", "there"]);
3911-
t("::hello::there", "::", box ["", "hello", "there"]);
3912-
t("hello::there::", "::", box ["hello", "there", ""]);
3913-
t("::hello::there::", "::", box ["", "hello", "there", ""]);
3914-
t("ประเทศไทย中华Việt Nam", "中华", box ["ประเทศไทย", "Việt Nam"]);
3915-
t("zzXXXzzYYYzz", "zz", box ["", "XXX", "YYY", ""]);
3916-
t("zzXXXzYYYz", "XXX", box ["zz", "zYYYz"]);
3917-
t(".XXX.YYY.", ".", box ["", "XXX", "YYY", ""]);
3918-
t("", ".", box [""]);
3919-
t("zz", "zz", box ["",""]);
3920-
t("ok", "z", box ["ok"]);
3921-
t("zzz", "zz", box ["","z"]);
3922-
t("zzzzz", "zz", box ["","","z"]);
3903+
t("--1233345--", "12345", ["--1233345--"]);
3904+
t("abc::hello::there", "::", ["abc", "hello", "there"]);
3905+
t("::hello::there", "::", ["", "hello", "there"]);
3906+
t("hello::there::", "::", ["hello", "there", ""]);
3907+
t("::hello::there::", "::", ["", "hello", "there", ""]);
3908+
t("ประเทศไทย中华Việt Nam", "中华", ["ประเทศไทย", "Việt Nam"]);
3909+
t("zzXXXzzYYYzz", "zz", ["", "XXX", "YYY", ""]);
3910+
t("zzXXXzYYYz", "XXX", ["zz", "zYYYz"]);
3911+
t(".XXX.YYY.", ".", ["", "XXX", "YYY", ""]);
3912+
t("", ".", [""]);
3913+
t("zz", "zz", ["",""]);
3914+
t("ok", "z", ["ok"]);
3915+
t("zzz", "zz", ["","z"]);
3916+
t("zzzzz", "zz", ["","","z"]);
39233917
}
39243918

39253919
#[test]

0 commit comments

Comments
 (0)