From 852bfdd859e653384eeded2115ce2f0a877e568b Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Sun, 9 Nov 2014 20:12:23 -0500 Subject: [PATCH] embedding: cef_string_utf8_cmp() --- ports/cef/string.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ports/cef/string.rs b/ports/cef/string.rs index d8cf7d97531..f0a58ca7478 100644 --- a/ports/cef/string.rs +++ b/ports/cef/string.rs @@ -93,6 +93,21 @@ pub extern "C" fn cef_string_utf8_set(src: *const u8, src_len: size_t, output: * return 1; } +#[no_mangle] +pub extern "C" fn cef_string_utf8_cmp(a: *const cef_string_utf8_t, b: *const cef_string_utf8_t) -> c_int { + unsafe { + slice::raw::buf_as_slice(mem::transmute((*a).str), (*a).length as uint, |astr:&[u8]| { + slice::raw::buf_as_slice(mem::transmute((*b).str), (*b).length as uint, |bstr:&[u8]| { + match astr.cmp(&bstr) { + Less => -1, + Equal => 0, + Greater => 1 + } + }) + }) + } +} + #[no_mangle] 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 {