mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
embedding: replace all occurrences of slicing to &str with slice_to_str()
This commit is contained in:
parent
7ba1150943
commit
19c80b1741
2 changed files with 19 additions and 39 deletions
|
@ -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::<Vec<u16>>();
|
||||
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::<Vec<u16>>();
|
||||
cef_string_utf16_set(conv.as_ptr(), conv.len() as size_t, output, 1);
|
||||
1
|
||||
})
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
|
|
@ -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
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue