Sha256: ef72dd9474dc62d0e87f3bd037039f1c5d014d349498d3a1fae8396487ded16f

Contents?: true

Size: 521 Bytes

Versions: 3

Compression:

Stored size: 521 Bytes

Contents

extern crate array_tool;
use path_parsing::extract_last_path_segment;
use self::array_tool::string::Squeeze;

pub fn basename(pth: &str, ext: &str) -> String {
  // Known edge case
  match &pth.squeeze("/")[..] {
    "/" => { return "/".to_string() }
    _ => {}
  }

  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()
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
faster_path-0.2.2 src/basename.rs
faster_path-0.2.1 src/basename.rs
faster_path-0.2.0 src/basename.rs