mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
implement cef_string_utf16_to_utf8()
This commit is contained in:
parent
e794f856cf
commit
f657e76e13
1 changed files with 19 additions and 0 deletions
|
@ -11,6 +11,7 @@ use libc::types::os::arch::c95::wchar_t;
|
|||
use mem::{new0,newarray0,delete,deletearray};
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
use std::slice;
|
||||
use std::string;
|
||||
use types::{cef_string_utf16_t, cef_string_utf8_t, cef_string_wide_t};
|
||||
use types::{cef_string_userfree_utf16_t, cef_string_userfree_utf8_t, cef_string_userfree_wide_t};
|
||||
|
@ -103,6 +104,24 @@ pub extern "C" fn cef_string_utf8_to_utf16(src: *const u8, src_len: size_t, outp
|
|||
1
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn cef_string_utf16_to_utf8(src: *const u16, src_len: size_t, output: *mut cef_string_utf8_t) -> c_int {
|
||||
unsafe {
|
||||
slice::raw::buf_as_slice(src, src_len as uint, |ustr| {
|
||||
match string::String::from_utf16(ustr) {
|
||||
Some(str) => {
|
||||
cef_string_utf8_set(str.as_bytes().as_ptr(), str.len() as size_t, output, 1);
|
||||
return 1 as c_int;
|
||||
},
|
||||
None => {
|
||||
return 0 as c_int;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
1
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn cef_string_utf16_clear(cs: *mut cef_string_utf16_t) {
|
||||
unsafe {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue