/// # use regex::Captures; fn main() {
/// let re = regex!(r"([^,\s]+),\s+(\S+)");
/// let result = re.replace("Springsteen, Bruce", |caps: &Captures| {
- /// format_strbuf!("{} {}", caps.at(2), caps.at(1))
+ /// format!("{} {}", caps.at(2), caps.at(1))
/// });
/// assert_eq!(result.as_slice(), "Bruce Springsteen");
/// # }
impl<'t> Replacer for &'t str {
fn reg_replace<'a>(&'a mut self, caps: &Captures) -> MaybeOwned<'a> {
- Owned(caps.expand(*self).into_owned())
+ Owned(caps.expand(*self))
}
}
impl<'a> Replacer for |&Captures|: 'a -> String {
fn reg_replace<'r>(&'r mut self, caps: &Captures) -> MaybeOwned<'r> {
- Owned((*self)(caps).into_owned())
+ Owned((*self)(caps))
}
}
let re = Regex::new(r"(^|[^$]|\b)\$(\w+)").unwrap();
let text = re.replace_all(text, |refs: &Captures| -> String {
let (pre, name) = (refs.at(1), refs.at(2));
- format_strbuf!("{}{}",
- pre,
- match from_str::<uint>(name.as_slice()) {
+ format!("{}{}", pre,
+ match from_str::<uint>(name.as_slice()) {
None => self.name(name).to_string(),
Some(i) => self.at(i).to_string(),
})
use option::{None, Option, Some};
use result::Result;
use slice::Vector;
- use slice::{ImmutableVector, MutableVector, CloneableVector};
+ use slice::{ImmutableVector, MutableVector};
use string::String;
use vec::Vec;
res.push_bytes(v.slice(subseqidx, total))
};
}
- Owned(res.into_owned())
+ Owned(res.into_string())
}
/*
impl<'a> StrAllocating for MaybeOwned<'a> {
#[inline]
- fn into_owned(self) -> String {
+ fn into_string(self) -> String {
match self {
Slice(s) => s.to_string(),
Owned(s) => s
/// Any string that can be represented as a slice
pub trait StrAllocating: Str {
/// Convert `self` into a `String`, not making a copy if possible.
- fn into_owned(self) -> String;
+ fn into_string(self) -> String;
/// Convert `self` into a `String`.
#[inline]
String::from_str(self.as_slice())
}
- /// Convert `self` into a `String`, not making a copy if possible.
- #[inline]
- fn into_string(self) -> String {
- self.into_owned()
+ #[allow(missing_doc)]
+ #[deprecated = "replaced by .into_string()"]
+ fn into_owned(self) -> String {
+ self.into_string()
}
/// Escape each char in `s` with `char::escape_default`.
impl<'a> StrAllocating for &'a str {
#[inline]
- fn into_owned(self) -> String {
+ fn into_string(self) -> String {
self.to_string()
}
}
#[test]
fn test_concat() {
fn t(v: &[String], s: &str) {
- assert_eq!(v.concat(), s.to_str().into_owned());
+ assert_eq!(v.concat(), s.to_str().into_string());
}
t(["you".to_string(), "know".to_string(), "I'm".to_string(),
"no".to_string(), "good".to_string()], "youknowI'mnogood");
#[test]
fn test_connect() {
fn t(v: &[String], sep: &str, s: &str) {
- assert_eq!(v.connect(sep), s.to_str().into_owned());
+ assert_eq!(v.connect(sep), s.to_str().into_string());
}
t(["you".to_string(), "know".to_string(), "I'm".to_string(),
"no".to_string(), "good".to_string()],
#[test]
fn test_concat_slices() {
fn t(v: &[&str], s: &str) {
- assert_eq!(v.concat(), s.to_str().into_owned());
+ assert_eq!(v.concat(), s.to_str().into_string());
}
t(["you", "know", "I'm", "no", "good"], "youknowI'mnogood");
let v: &[&str] = [];
#[test]
fn test_connect_slices() {
fn t(v: &[&str], sep: &str, s: &str) {
- assert_eq!(v.connect(sep), s.to_str().into_owned());
+ assert_eq!(v.connect(sep), s.to_str().into_string());
}
t(["you", "know", "I'm", "no", "good"],
" ", "you know I'm no good");
assert_eq!(s.len(), 5);
assert_eq!(s.as_slice(), "abcde");
assert_eq!(s.to_str(), "abcde".to_string());
- assert_eq!(format_strbuf!("{}", s), "abcde".to_string());
+ assert_eq!(format!("{}", s), "abcde".to_string());
assert!(s.lt(&Owned("bcdef".to_string())));
assert_eq!(Slice(""), Default::default());
assert_eq!(o.len(), 5);
assert_eq!(o.as_slice(), "abcde");
assert_eq!(o.to_str(), "abcde".to_string());
- assert_eq!(format_strbuf!("{}", o), "abcde".to_string());
+ assert_eq!(format!("{}", o), "abcde".to_string());
assert!(o.lt(&Slice("bcdef")));
assert_eq!(Owned("".to_string()), Default::default());
}
#[test]
- fn test_maybe_owned_into_owned() {
- assert_eq!(Slice("abcde").into_owned(), "abcde".to_string());
- assert_eq!(Owned("abcde".to_string()).into_owned(), "abcde".to_string());
+ fn test_maybe_owned_into_string() {
+ assert_eq!(Slice("abcde").into_string(), "abcde".to_string());
+ assert_eq!(Owned("abcde".to_string()).into_string(), "abcde".to_string());
}
#[test]