mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-14 00:47:30 +00:00
common.rs: helper to convert from C-string of unknown length to wide
On the C++ side we have an overload that called std::wcslen(), this is the equivalent one.
This commit is contained in:
parent
3163efb87f
commit
bfe68e6a83
1 changed files with 13 additions and 0 deletions
|
@ -1110,6 +1110,19 @@ pub fn str2wcstring(inp: &[u8]) -> WString {
|
|||
result
|
||||
}
|
||||
|
||||
pub fn cstr2wcstring(input: &[u8]) -> WString {
|
||||
let strlen = input.iter().position(|c| *c == b'\0').unwrap();
|
||||
str2wcstring(&input[0..strlen])
|
||||
}
|
||||
|
||||
pub fn charptr2wcstring(input: *const libc::c_char) -> WString {
|
||||
let input: &[u8] = unsafe {
|
||||
let strlen = libc::strlen(input);
|
||||
slice::from_raw_parts(input.cast(), strlen)
|
||||
};
|
||||
str2wcstring(input)
|
||||
}
|
||||
|
||||
/// Returns a newly allocated multibyte character string equivalent of the specified wide character
|
||||
/// string.
|
||||
///
|
||||
|
|
Loading…
Reference in a new issue