Skip to content

Commit 2fb8b7b

Browse files
committed
auto merge of #13440 : huonw/rust/strbuf, r=alexcrichton
libstd: Implement `StrBuf`, a new string buffer type like `Vec`, and port all code over to use it. Rebased & tests-fixed version of rust-lang/rust#13269
2 parents 04c24e2 + 389699d commit 2fb8b7b

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

lib.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ use std::io::{File, ChanReader, ChanWriter};
5959
use std::io;
6060
use std::os;
6161
use std::str;
62+
use std::strbuf::StrBuf;
6263
use std::task;
6364

6465
// to be used by rustc to compile tests in libtest
@@ -99,13 +100,19 @@ enum NamePadding { PadNone, PadOnLeft, PadOnRight }
99100
impl TestDesc {
100101
fn padded_name(&self, column_count: uint, align: NamePadding) -> ~str {
101102
use std::num::Saturating;
102-
let name = self.name.to_str();
103+
let mut name = StrBuf::from_str(self.name.to_str());
103104
let fill = column_count.saturating_sub(name.len());
104-
let pad = " ".repeat(fill);
105+
let mut pad = StrBuf::from_owned_str(" ".repeat(fill));
105106
match align {
106-
PadNone => name,
107-
PadOnLeft => pad.append(name),
108-
PadOnRight => name.append(pad),
107+
PadNone => name.into_owned(),
108+
PadOnLeft => {
109+
pad.push_str(name.as_slice());
110+
pad.into_owned()
111+
}
112+
PadOnRight => {
113+
name.push_str(pad.as_slice());
114+
name.into_owned()
115+
}
109116
}
110117
}
111118
}
@@ -543,7 +550,7 @@ impl<T: Writer> ConsoleTestState<T> {
543550
pub fn write_failures(&mut self) -> io::IoResult<()> {
544551
try!(self.write_plain("\nfailures:\n"));
545552
let mut failures = Vec::new();
546-
let mut fail_out = ~"";
553+
let mut fail_out = StrBuf::new();
547554
for &(ref f, ref stdout) in self.failures.iter() {
548555
failures.push(f.name.to_str());
549556
if stdout.len() > 0 {
@@ -556,7 +563,7 @@ impl<T: Writer> ConsoleTestState<T> {
556563
}
557564
if fail_out.len() > 0 {
558565
try!(self.write_plain("\n"));
559-
try!(self.write_plain(fail_out));
566+
try!(self.write_plain(fail_out.as_slice()));
560567
}
561568

562569
try!(self.write_plain("\nfailures:\n"));

0 commit comments

Comments
 (0)