src/basename.rs in faster_path-0.1.1 vs src/basename.rs in faster_path-0.1.2

- old
+ new

@@ -1,15 +1,22 @@ #[no_mangle] -pub extern fn basename(string: *const c_char) -> *const c_char { - let c_str = unsafe { +pub extern fn basename(string: *const c_char, comp_ext: *const c_char) -> *const c_char { + let c_str1 = unsafe { assert!(!string.is_null()); - CStr::from_ptr(string) }; + let c_str2 = unsafe { + assert!(!comp_ext.is_null()); + CStr::from_ptr(comp_ext) + }; + let r_str = str::from_utf8(c_str1.to_bytes()).unwrap(); + let r_str_chomp = str::from_utf8(c_str2.to_bytes()).unwrap(); - let r_str = str::from_utf8(c_str.to_bytes()).unwrap(); + let r_str = if !r_str_chomp.is_empty() { + chomp_pathish_regex(r_str, r_str_chomp) + } else { r_str.to_string() }; - let part = Path::new(r_str).file_name().unwrap_or(OsStr::new("")).to_str(); + let part = Path::new(&r_str[..]).file_name().unwrap_or(OsStr::new("")).to_str(); let output = CString::new(format!("{}", part.unwrap())).unwrap(); output.into_raw() }