From ea7197e2cf921211fb3b82ad45452c2095f5a589 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 16 Mar 2011 18:40:51 -0700 Subject: rustc: Add str_from_cstr() and str_from_buf() functions to the standard library, as well as a test case --- src/lib/_str.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/lib') diff --git a/src/lib/_str.rs b/src/lib/_str.rs index db9413b9..93d0a9f2 100644 --- a/src/lib/_str.rs +++ b/src/lib/_str.rs @@ -8,6 +8,8 @@ native "rust" mod rustrt { fn str_byte_len(str s) -> uint; fn str_alloc(uint n_bytes) -> str; fn str_from_vec(vec[u8] b) -> str; + fn str_from_cstr(sbuf cstr) -> str; + fn str_from_buf(sbuf buf, uint len) -> str; fn refcount[T](str s) -> uint; } @@ -115,6 +117,14 @@ fn unsafe_from_byte(u8 u) -> str { ret rustrt.str_from_vec(vec(u)); } +unsafe fn str_from_cstr(sbuf cstr) -> str { + ret rustrt.str_from_cstr(cstr); +} + +unsafe fn str_from_buf(sbuf buf, uint len) -> str { + ret rustrt.str_from_buf(buf, len); +} + fn refcount(str s) -> uint { auto r = rustrt.refcount[u8](s); -- cgit v1.2.3