Implement core::str::from_cstr_len, close #1666
This commit is contained in:
parent
005a3efb8b
commit
6408d54c13
1 changed files with 19 additions and 0 deletions
|
@ -17,6 +17,7 @@ export
|
||||||
from_char,
|
from_char,
|
||||||
from_chars,
|
from_chars,
|
||||||
from_cstr,
|
from_cstr,
|
||||||
|
from_cstr_len,
|
||||||
concat,
|
concat,
|
||||||
connect,
|
connect,
|
||||||
|
|
||||||
|
@ -210,6 +211,24 @@ unsafe fn from_cstr(cstr: sbuf) -> str {
|
||||||
ret from_bytes(res);
|
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
|
Function: concat
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue