src/basename.rs in faster_path-0.1.3 vs src/basename.rs in faster_path-0.1.4
- old
+ new
@@ -1,20 +1,12 @@
#[allow(dead_code)]
fn rubyish_basename(string: &str, globish_string: &str) -> String {
- let result = if globish_string.chars().next().unwrap_or("muffins".chars().next().unwrap()).eq(&".".chars().next().unwrap()) {
- if globish_string == ".*" {
- let base = string.rsplit_terminator(MAIN_SEPARATOR).nth(0).unwrap_or("");
- let index = base.rfind(".");
- let (first, _) = base.split_at(index.unwrap());
- first
- } else {
- if &string[string.len()-globish_string.len()..] == globish_string {
- &string[0..string.len()-globish_string.len()]
- } else {
- string
- }.rsplit_terminator(MAIN_SEPARATOR).nth(0).unwrap_or("")
- }
+ let result = if globish_string == ".*" {
+ let base = string.rsplit_terminator(MAIN_SEPARATOR).nth(0).unwrap_or("");
+ let index = base.rfind(".");
+ let (first, _) = base.split_at(index.unwrap());
+ first
} else {
if &string[string.len()-globish_string.len()..] == globish_string {
&string[0..string.len()-globish_string.len()]
} else {
string
@@ -67,22 +59,14 @@
CStr::from_ptr(comp_ext)
};
let string = str::from_utf8(c_str1.to_bytes()).unwrap();
let globish_string = str::from_utf8(c_str2.to_bytes()).unwrap();
- let result = if globish_string.chars().next().unwrap_or("muffins".chars().next().unwrap()).eq(&".".chars().next().unwrap()) {
- if globish_string == ".*" {
- let base = string.rsplit_terminator(MAIN_SEPARATOR).nth(0).unwrap_or("");
- let index = base.rfind(".");
- let (first, _) = base.split_at(index.unwrap());
- first
- } else {
- if &string[string.len()-globish_string.len()..] == globish_string {
- &string[0..string.len()-globish_string.len()]
- } else {
- string
- }.rsplit_terminator(MAIN_SEPARATOR).nth(0).unwrap_or("")
- }
+ let result = if globish_string == ".*" {
+ let base = string.rsplit_terminator(MAIN_SEPARATOR).nth(0).unwrap_or("");
+ let index = base.rfind(".");
+ let (first, _) = base.split_at(index.unwrap());
+ first
} else {
if &string[string.len()-globish_string.len()..] == globish_string {
&string[0..string.len()-globish_string.len()]
} else {
string