mirror of
https://github.com/chatmail/core.git
synced 2026-04-21 23:46:31 +03:00
fix some string issues, introduce to_string_lossy such that to_string() continues to panic on non-utf8
This commit is contained in:
@@ -1561,9 +1561,20 @@ pub fn to_string(s: *const libc::c_char) -> String {
|
||||
let cstr = unsafe { CStr::from_ptr(s) };
|
||||
|
||||
cstr.to_str().map(|s| s.to_string()).unwrap_or_else(|err| {
|
||||
let lossy = cstr.to_string_lossy();
|
||||
eprintln!("Non utf8 string: '{:?}' ({:?})", lossy, err);
|
||||
lossy.to_string()
|
||||
panic!("Non utf8 string: '{:?}' ({:?})", cstr.to_string_lossy(), err);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
pub fn to_string_lossy(s: *const libc::c_char) -> String {
|
||||
if s.is_null() {
|
||||
return "".into();
|
||||
}
|
||||
|
||||
let cstr = unsafe { CStr::from_ptr(s) };
|
||||
|
||||
cstr.to_str().map(|s| s.to_string()).unwrap_or_else(|_| {
|
||||
cstr.to_string_lossy().to_string()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user