*/
pub fn usage(brief: &str, opts: &[OptGroup]) -> ~str {
- let desc_sep = ~"\n" + str::repeat(" ", 24);
+ let desc_sep = ~"\n" + " ".repeat(24);
let rows = vec::map(opts, |optref| {
let OptGroup{short_name: short_name,
hasarg: hasarg,
_} = copy *optref;
- let mut row = str::repeat(" ", 4);
+ let mut row = " ".repeat(4);
// short option
row += match short_name.len() {
// here we just need to indent the start of the description
let rowlen = row.len();
row += if rowlen < 24 {
- str::repeat(" ", 24 - rowlen)
+ " ".repeat(24 - rowlen)
} else {
copy desc_sep
};
}
}
-/// Given a string, make a new string with repeated copies of it
-pub fn repeat(ss: &str, nn: uint) -> ~str {
- do as_buf(ss) |buf, len| {
- let mut ret = ~"";
- // ignore the NULL terminator
- let len = len - 1;
- ret.reserve(nn * len);
-
- unsafe {
- do as_buf(ret) |rbuf, _len| {
- let mut rbuf = ::cast::transmute_mut_unsafe(rbuf);
-
- for nn.times {
- ptr::copy_memory(rbuf, buf, len);
- rbuf = rbuf.offset(len);
- }
- }
- raw::set_len(&mut ret, nn * len);
- }
- ret
- }
-}
-
/*
Section: Adding to and removing from a string
*/
fn find<C: CharEq>(&self, search: C) -> Option<uint>;
fn rfind<C: CharEq>(&self, search: C) -> Option<uint>;
fn find_str(&self, &str) -> Option<uint>;
+
+ fn repeat(&self, nn: uint) -> ~str;
}
/// Extension methods for strings
.map_consume(|(start, _end)| start)
}
}
+
+ /// Given a string, make a new string with repeated copies of it.
+ fn repeat(&self, nn: uint) -> ~str {
+ do as_buf(*self) |buf, len| {
+ let mut ret = ~"";
+ // ignore the NULL terminator
+ let len = len - 1;
+ ret.reserve(nn * len);
+
+ unsafe {
+ do as_buf(ret) |rbuf, _len| {
+ let mut rbuf = ::cast::transmute_mut_unsafe(rbuf);
+
+ for nn.times {
+ ptr::copy_memory(rbuf, buf, len);
+ rbuf = rbuf.offset(len);
+ }
+ }
+ raw::set_len(&mut ret, nn * len);
+ }
+ ret
+ }
+ }
}
#[allow(missing_doc)]
#[test]
fn test_repeat() {
- assert_eq!(repeat("x", 4), ~"xxxx");
- assert_eq!(repeat("hi", 4), ~"hihihihi");
- assert_eq!(repeat("ไท华", 3), ~"ไท华ไท华ไท华");
- assert_eq!(repeat("", 4), ~"");
- assert_eq!(repeat("hi", 0), ~"");
+ assert_eq!("x".repeat(4), ~"xxxx");
+ assert_eq!("hi".repeat(4), ~"hihihihi");
+ assert_eq!("ไท华".repeat(3), ~"ไท华ไท华ไท华");
+ assert_eq!("".repeat(4), ~"");
+ assert_eq!("hi".repeat(0), ~"");
}
#[test]