move out
}
+extern mod rustrt {
+ #[rust_stack]
+ pure fn upcall_str_new_shared(cstr: *libc::c_char, len: size_t) -> @str;
+}
+
/// Unsafe operations
pub mod raw {
pure fn trim_left() -> ~str;
pure fn trim_right() -> ~str;
pure fn to_unique() -> ~str;
+ pure fn to_managed() -> @str;
pure fn char_at(i: uint) -> char;
}
#[inline]
pure fn to_unique() -> ~str { self.slice(0, self.len()) }
+ #[inline]
+ pure fn to_managed() -> @str {
+ do str::as_buf(self) |p, _len| {
+ rustrt::upcall_str_new_shared(p as *libc::c_char,
+ self.len() as size_t)
+ }
+ }
+
#[inline]
pure fn char_at(i: uint) -> char { char_at(self, i) }
}
assert escape_default(~"\U0001d4ea\r") == ~"\\U0001d4ea\\r";
}
+ #[test]
+ fn test_to_managed() {
+ assert (~"abc").to_managed() == @"abc";
+ assert view("abcdef", 1, 5).to_managed() == @"bcde";
+ }
+
}