diff options
-rw-r--r-- | ports/cef/lib.rs | 1 | ||||
-rw-r--r-- | ports/cef/string.rs | 15 | ||||
-rw-r--r-- | ports/cef/string_list.rs | 87 |
3 files changed, 103 insertions, 0 deletions
diff --git a/ports/cef/lib.rs b/ports/cef/lib.rs index bf7aeec80e6..a4e12301137 100644 --- a/ports/cef/lib.rs +++ b/ports/cef/lib.rs @@ -50,6 +50,7 @@ pub mod eutil; pub mod mem; pub mod request; pub mod string; +pub mod string_list; pub mod task; pub mod types; pub mod urlrequest; diff --git a/ports/cef/string.rs b/ports/cef/string.rs index 855fa1226ec..d8cf7d97531 100644 --- a/ports/cef/string.rs +++ b/ports/cef/string.rs @@ -168,6 +168,21 @@ pub extern "C" fn cef_string_utf16_set(src: *const c_ushort, src_len: size_t, ou } #[no_mangle] +pub extern "C" fn cef_string_utf16_cmp(a: *const cef_string_utf16_t, b: *const cef_string_utf16_t) -> c_int { + unsafe { + slice::raw::buf_as_slice(mem::transmute((*a).str), (*a).length as uint, |astr:&[u16]| { + slice::raw::buf_as_slice(mem::transmute((*b).str), (*b).length as uint, |bstr:&[u16]| { + match astr.cmp(&bstr) { + Less => -1, + Equal => 0, + Greater => 1 + } + }) + }) + } +} + +#[no_mangle] pub extern "C" fn cef_string_wide_clear(cs: *mut cef_string_wide_t) { unsafe { if !fptr_is_null(mem::transmute((*cs).dtor)) { diff --git a/ports/cef/string_list.rs b/ports/cef/string_list.rs new file mode 100644 index 00000000000..fdf7e6ddbd2 --- /dev/null +++ b/ports/cef/string_list.rs @@ -0,0 +1,87 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +use eutil::fptr_is_null; +use libc::{c_int}; +use std::mem; +use string::{cef_string_userfree_utf8_alloc,cef_string_userfree_utf8_free,cef_string_utf8_set}; +use types::{cef_string_list_t,cef_string_t}; + +//cef_string_list + +#[no_mangle] +extern "C" fn cef_string_list_alloc() -> *mut cef_string_list_t { + unsafe { + let lt: Box<Vec<*mut cef_string_t>> = box vec!(); + mem::transmute(lt) + } +} + +#[no_mangle] +extern "C" fn cef_string_list_size(lt: *const cef_string_list_t) -> c_int { + unsafe { + if fptr_is_null(mem::transmute(lt)) { return 0; } + let v: Box<Vec<*mut cef_string_t>> = mem::transmute(lt); + v.len() as c_int + } +} + +#[no_mangle] +extern "C" fn cef_string_list_append(lt: *mut cef_string_list_t, value: *const cef_string_t) { + unsafe { + if fptr_is_null(mem::transmute(lt)) { return; } + let mut v: Box<Vec<*mut cef_string_t>> = mem::transmute(lt); + let cs = cef_string_userfree_utf8_alloc(); + cef_string_utf8_set(mem::transmute((*value).str), (*value).length, cs, 1); + v.push(cs); + } +} + +#[no_mangle] +extern "C" fn cef_string_list_value(lt: *mut cef_string_list_t, index: c_int, value: *mut cef_string_t) -> c_int { + unsafe { + if index < 0 || fptr_is_null(mem::transmute(lt)) { return 0; } + let v: Box<Vec<*mut cef_string_t>> = mem::transmute(lt); + if index as uint > v.len() - 1 { return 0; } + let cs = v.get(index as uint); + cef_string_utf8_set(mem::transmute((**cs).str), (**cs).length, value, 1) + } +} + +#[no_mangle] +extern "C" fn cef_string_list_clear(lt: *mut cef_string_list_t) { + unsafe { + if fptr_is_null(mem::transmute(lt)) { return; } + let mut v: Box<Vec<*mut cef_string_t>> = mem::transmute(lt); + if v.len() == 0 { return; } + let mut cs; + while v.len() != 0 { + cs = v.pop(); + cef_string_userfree_utf8_free(cs.unwrap()); + } + } +} + +#[no_mangle] +extern "C" fn cef_string_list_free(lt: *mut cef_string_list_t) { + unsafe { + if fptr_is_null(mem::transmute(lt)) { return; } + let mut v: Box<Vec<*mut cef_string_t>> = mem::transmute(lt); + cef_string_list_clear(lt); + drop(v); + } +} + +#[no_mangle] +extern "C" fn cef_string_list_copy(lt: *mut cef_string_list_t) -> *mut cef_string_list_t { + unsafe { + if fptr_is_null(mem::transmute(lt)) { return 0 as *mut cef_string_list_t; } + let v: Box<Vec<*mut cef_string_t>> = mem::transmute(lt); + let lt2 = cef_string_list_alloc(); + for cs in v.iter() { + cef_string_list_append(lt2, mem::transmute((*cs))); + } + lt2 + } +} |