Sha256: 10ca699a2c3e830d0f6e081bbd4a4ebdfa3bf5b129682fd49bd6a66123bca26b
Contents?: true
Size: 831 Bytes
Versions: 2
Compression:
Stored size: 831 Bytes
Contents
use std::path::MAIN_SEPARATOR; use libc::c_char; use std::ffi::{CStr,CString}; use std::str; #[no_mangle] pub extern fn dirname_for_chop(string: *const c_char) -> *const c_char { let c_str = unsafe { assert!(!string.is_null()); CStr::from_ptr(string) }; let r_str = str::from_utf8(c_str.to_bytes()).unwrap(); if r_str.is_empty() { return string } let mut offset = 0; let mut trailing_slashes = r_str.chars().rev(); loop { match trailing_slashes.next() { Some(MAIN_SEPARATOR) => { offset = offset + 1 }, _ => { break }, } } let r_str = &r_str[0..r_str.len()-offset]; let base = r_str.rsplit_terminator(MAIN_SEPARATOR).nth(0).unwrap_or(""); let output = CString::new(&r_str[0..r_str.len()-base.len()]).unwrap(); output.into_raw() }
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
faster_path-0.1.7 | src/dirname_for_chop.rs |
faster_path-0.1.6 | src/dirname_for_chop.rs |