mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
handle str::from_utf8() failure, improve return calls
This commit is contained in:
parent
62deac9346
commit
5bbce40efe
1 changed files with 12 additions and 10 deletions
|
@ -97,11 +97,16 @@ pub extern "C" fn cef_string_utf8_set(src: *const u8, src_len: size_t, output: *
|
||||||
pub extern "C" fn cef_string_utf8_to_utf16(src: *const u8, src_len: size_t, output: *mut cef_string_utf16_t) -> c_int {
|
pub extern "C" fn cef_string_utf8_to_utf16(src: *const u8, src_len: size_t, output: *mut cef_string_utf16_t) -> c_int {
|
||||||
unsafe {
|
unsafe {
|
||||||
slice::raw::buf_as_slice(src, src_len as uint, |result| {
|
slice::raw::buf_as_slice(src, src_len as uint, |result| {
|
||||||
let enc = str::from_utf8(result).unwrap().utf16_units().collect::<Vec<u16>>();
|
match str::from_utf8(result) {
|
||||||
cef_string_utf16_set(enc.as_ptr(), enc.len() as size_t, output, 1);
|
Some(enc) => {
|
||||||
});
|
let conv = enc.utf16_units().collect::<Vec<u16>>();
|
||||||
|
cef_string_utf16_set(conv.as_ptr(), conv.len() as size_t, output, 1);
|
||||||
|
1
|
||||||
|
},
|
||||||
|
None => 0
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -111,15 +116,12 @@ pub extern "C" fn cef_string_utf16_to_utf8(src: *const u16, src_len: size_t, out
|
||||||
match string::String::from_utf16(ustr) {
|
match string::String::from_utf16(ustr) {
|
||||||
Some(str) => {
|
Some(str) => {
|
||||||
cef_string_utf8_set(str.as_bytes().as_ptr(), str.len() as size_t, output, 1);
|
cef_string_utf8_set(str.as_bytes().as_ptr(), str.len() as size_t, output, 1);
|
||||||
return 1 as c_int;
|
1 as c_int
|
||||||
},
|
},
|
||||||
None => {
|
None => 0 as c_int
|
||||||
return 0 as c_int;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue