Skip to content

Commit a9159a1

Browse files
Dretchnikomatsakis
authored andcommitted
---
yaml --- r: 35945 b: refs/heads/try2 c: e9caa3f h: refs/heads/master i: 35943: 725e22f v: v3
1 parent 807a288 commit a9159a1

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: eb8fd119c65c67f3b1b8268cc7341c22d39b7b61
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 9406f8101dd32b4458b8c042a1bfb1bb150a2276
8+
refs/heads/try2: e9caa3fe2e291b7f2cea624bfd0dc879e95fe382
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
1010
refs/heads/dist-snap: 22efa39382d41b084fde1719df7ae8ce5697d8c9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try2/src/libcore/str.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,6 +1869,11 @@ pub pure fn escape_unicode(s: &str) -> ~str {
18691869
move out
18701870
}
18711871

1872+
extern mod rustrt {
1873+
#[rust_stack]
1874+
pure fn upcall_str_new_shared(cstr: *libc::c_char, len: size_t) -> @str;
1875+
}
1876+
18721877
/// Unsafe operations
18731878
pub mod raw {
18741879

@@ -2090,6 +2095,7 @@ pub trait StrSlice {
20902095
pure fn trim_left() -> ~str;
20912096
pure fn trim_right() -> ~str;
20922097
pure fn to_unique() -> ~str;
2098+
pure fn to_managed() -> @str;
20932099
pure fn char_at(i: uint) -> char;
20942100
}
20952101

@@ -2213,6 +2219,14 @@ impl &str: StrSlice {
22132219
#[inline]
22142220
pure fn to_unique() -> ~str { self.slice(0, self.len()) }
22152221

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+
22162230
#[inline]
22172231
pure fn char_at(i: uint) -> char { char_at(self, i) }
22182232
}
@@ -3190,4 +3204,10 @@ mod tests {
31903204
assert escape_default(~"\U0001d4ea\r") == ~"\\U0001d4ea\\r";
31913205
}
31923206
3207+
#[test]
3208+
fn test_to_managed() {
3209+
assert (~"abc").to_managed() == @"abc";
3210+
assert view("abcdef", 1, 5).to_managed() == @"bcde";
3211+
}
3212+
31933213
}

0 commit comments

Comments
 (0)