From 19c80b17410b7727c86455534405c6e2546bcb2b Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Thu, 13 Nov 2014 14:41:13 -0500 Subject: [PATCH] embedding: replace all occurrences of slicing to &str with slice_to_str() --- ports/cef/string.rs | 20 ++++++-------------- ports/cef/string_map.rs | 38 +++++++++++++------------------------- 2 files changed, 19 insertions(+), 39 deletions(-) diff --git a/ports/cef/string.rs b/ports/cef/string.rs index d8cf7d97531..81fd7087d9c 100644 --- a/ports/cef/string.rs +++ b/ports/cef/string.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use eutil::fptr_is_null; +use eutil::{fptr_is_null, slice_to_str}; use libc::{size_t, c_int, c_ushort,c_void}; use libc::types::os::arch::c95::wchar_t; use mem::{new0,newarray0,delete,deletearray}; @@ -11,7 +11,6 @@ use std::mem; use std::ptr; use std::slice; use std::string; -use std::str; 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}; @@ -95,18 +94,11 @@ pub extern "C" fn cef_string_utf8_set(src: *const u8, src_len: size_t, output: * #[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 { - slice::raw::buf_as_slice(src, src_len as uint, |result| { - match str::from_utf8(result) { - Some(enc) => { - let conv = enc.utf16_units().collect::>(); - cef_string_utf16_set(conv.as_ptr(), conv.len() as size_t, output, 1); - 1 - }, - None => 0 - } - }) - } + slice_to_str(src, src_len as uint, |result| { + let conv = result.utf16_units().collect::>(); + cef_string_utf16_set(conv.as_ptr(), conv.len() as size_t, output, 1); + 1 + }) } #[no_mangle] diff --git a/ports/cef/string_map.rs b/ports/cef/string_map.rs index 91fb0459ded..67469700957 100644 --- a/ports/cef/string_map.rs +++ b/ports/cef/string_map.rs @@ -2,12 +2,10 @@ * 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 eutil::{fptr_is_null, slice_to_str}; use libc::{c_int}; use std::collections::TreeMap; use std::mem; -use std::slice; -use std::str; use std::string::String; use string::{cef_string_userfree_utf8_alloc,cef_string_userfree_utf8_free,cef_string_utf8_set}; use types::{cef_string_map_t, cef_string_t}; @@ -40,17 +38,12 @@ pub extern "C" fn cef_string_map_append(sm: *mut cef_string_map_t, key: *const c unsafe { if fptr_is_null(mem::transmute(sm)) { return 0; } let v = string_map_to_treemap(sm); - slice::raw::buf_as_slice(mem::transmute((*key).str), (*key).length as uint, |result| { - match str::from_utf8(result) { - Some(k) => { - let s = String::from_str(k); - let csv = cef_string_userfree_utf8_alloc(); - cef_string_utf8_set(mem::transmute((*value).str), (*value).length, csv, 1); - (*v).insert(s, csv); - 1 - }, - None => 0 - } + slice_to_str((*key).str as *const u8, (*key).length as uint, |result| { + let s = String::from_str(result); + let csv = cef_string_userfree_utf8_alloc(); + cef_string_utf8_set((*value).str as *const u8, (*value).length, csv, 1); + (*v).insert(s, csv); + 1 }) } } @@ -60,17 +53,12 @@ pub extern "C" fn cef_string_map_find(sm: *mut cef_string_map_t, key: *const cef unsafe { if fptr_is_null(mem::transmute(sm)) { return 0; } let v = string_map_to_treemap(sm); - slice::raw::buf_as_slice(mem::transmute((*key).str), (*key).length as uint, |result| { - match str::from_utf8(result) { - Some(k) => { - match (*v).find(&String::from_str(k)) { - Some(s) => { - cef_string_utf8_set(mem::transmute((**s).str), (**s).length, value, 1); - 1 - } - None => 0 - } - }, + slice_to_str((*key).str as *const u8, (*key).length as uint, |result| { + match (*v).find(&String::from_str(result)) { + Some(s) => { + cef_string_utf8_set((**s).str as *const u8, (**s).length, value, 1); + 1 + } None => 0 } })