File tree 1 file changed +20
-0
lines changed
1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -1869,6 +1869,11 @@ pub pure fn escape_unicode(s: &str) -> ~str {
1869
1869
move out
1870
1870
}
1871
1871
1872
+ extern mod rustrt {
1873
+ #[ rust_stack]
1874
+ pure fn upcall_str_new_shared ( cstr : * libc:: c_char , len : size_t ) -> @str ;
1875
+ }
1876
+
1872
1877
/// Unsafe operations
1873
1878
pub mod raw {
1874
1879
@@ -2090,6 +2095,7 @@ pub trait StrSlice {
2090
2095
pure fn trim_left ( ) -> ~str ;
2091
2096
pure fn trim_right ( ) -> ~str ;
2092
2097
pure fn to_unique ( ) -> ~str ;
2098
+ pure fn to_managed ( ) -> @str ;
2093
2099
pure fn char_at ( i : uint ) -> char ;
2094
2100
}
2095
2101
@@ -2213,6 +2219,14 @@ impl &str: StrSlice {
2213
2219
#[ inline]
2214
2220
pure fn to_unique ( ) -> ~str { self . slice ( 0 , self . len ( ) ) }
2215
2221
2222
+ #[ inline]
2223
+ pure fn to_managed ( ) -> @str {
2224
+ do str:: as_buf ( self ) |p, _len| {
2225
+ rustrt:: upcall_str_new_shared ( p as * libc:: c_char ,
2226
+ self . len ( ) as size_t )
2227
+ }
2228
+ }
2229
+
2216
2230
#[ inline]
2217
2231
pure fn char_at ( i : uint ) -> char { char_at ( self , i) }
2218
2232
}
@@ -3190,4 +3204,10 @@ mod tests {
3190
3204
assert escape_default(~"\U 0001d4ea\r " ) == ~"\\ U0001d4ea \\ r";
3191
3205
}
3192
3206
3207
+ #[test]
3208
+ fn test_to_managed() {
3209
+ assert (~" abc").to_managed() == @" abc";
3210
+ assert view(" abcdef", 1, 5).to_managed() == @" bcde" ;
3211
+ }
3212
+
3193
3213
}
You can’t perform that action at this time.
0 commit comments