Implement core::str::from_cstr_len, close #1666

This commit is contained in:
Tomoki Aonuma 2012-02-12 13:21:50 +09:00
parent 005a3efb8b
commit 6408d54c13

View file

@ -17,6 +17,7 @@ export
from_char,
from_chars,
from_cstr,
from_cstr_len,
concat,
connect,
@ -210,6 +211,24 @@ unsafe fn from_cstr(cstr: sbuf) -> str {
ret from_bytes(res);
}
/*
Function: from_cstr_len
Create a Rust string from a C string of the given length
*/
unsafe fn from_cstr_len(cstr: sbuf, len: uint) -> str {
let res = [];
let start = cstr;
let curr = start;
let i = 0u;
while i < len {
vec::push(res, *curr);
i += 1u;
curr = ptr::offset(start, i);
}
ret from_bytes(res);
}
/*
Function: concat