mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
embedding: add eutil::slice_to_str() convenience function
converts a *u8+length to &str and returns c_int
This commit is contained in:
parent
c813df777e
commit
7ba1150943
1 changed files with 17 additions and 0 deletions
|
@ -2,6 +2,23 @@
|
|||
* 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 libc::c_int;
|
||||
use std::slice;
|
||||
use std::str;
|
||||
|
||||
pub fn fptr_is_null(fptr: *const u8) -> bool {
|
||||
fptr.is_null()
|
||||
}
|
||||
|
||||
pub fn slice_to_str(s: *const u8, l: uint, f: |&str| -> c_int) -> c_int {
|
||||
unsafe {
|
||||
slice::raw::buf_as_slice(s, l, |result| {
|
||||
match str::from_utf8(result) {
|
||||
Some(ruststr) => {
|
||||
f(ruststr)
|
||||
},
|
||||
None => 0
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue