-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fin rewriting to ruru & dropped libc
- Loading branch information
1 parent
b4fe3c0
commit 4f18c3b
Showing
21 changed files
with
162 additions
and
410 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,23 @@ | ||
use libc::c_char; | ||
use std::ffi::{CStr, CString}; | ||
extern crate array_tool; | ||
use path_parsing::extract_last_path_segment; | ||
use self::array_tool::string::Squeeze; | ||
|
||
#[no_mangle] | ||
pub extern "C" fn basename(c_pth: *const c_char, c_ext: *const c_char) -> *const c_char { | ||
if c_pth.is_null() || c_ext.is_null() { | ||
return c_pth; | ||
pub fn basename(pth: &str, ext: &str) -> String { | ||
// Known edge case | ||
match &pth.squeeze("/")[..] { | ||
"/" => { return "/".to_string() } | ||
_ => {} | ||
} | ||
let pth = unsafe { CStr::from_ptr(c_pth) }.to_str().unwrap(); | ||
let ext = unsafe { CStr::from_ptr(c_ext) }.to_str().unwrap(); | ||
|
||
let name = rust::basename(pth, ext); | ||
|
||
CString::new(name).unwrap().into_raw() | ||
} | ||
|
||
pub mod rust { | ||
extern crate array_tool; | ||
use path_parsing::extract_last_path_segment; | ||
use self::array_tool::string::Squeeze; | ||
let mut name = extract_last_path_segment(pth); | ||
|
||
pub fn basename(pth: &str, ext: &str) -> String { | ||
// Known edge case | ||
match &pth.squeeze("/")[..] { | ||
"/" => { return "/".to_string() } | ||
_ => {} | ||
if ext == ".*" { | ||
if let Some(dot_i) = name.rfind('.') { | ||
name = &name[0..dot_i]; | ||
} | ||
|
||
let mut name = extract_last_path_segment(pth); | ||
|
||
if ext == ".*" { | ||
if let Some(dot_i) = name.rfind('.') { | ||
name = &name[0..dot_i]; | ||
} | ||
} else if name.ends_with(ext) { | ||
name = &name[..name.len() - ext.len()]; | ||
}; | ||
name.to_string() | ||
} | ||
} else if name.ends_with(ext) { | ||
name = &name[..name.len() - ext.len()]; | ||
}; | ||
name.to_string() | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.