Skip to main content

normalize_path

Function normalize_path 

Source
pub fn normalize_path(path: &str) -> String
Expand description

Normalize a path from a diff header to repo-relative format.

  • Strips b/ prefix (git diff convention)
  • Strips a/ prefix
  • Converts backslashes to forward slashes
  • Removes leading ./

ยงExamples

use covguard_adapters_diff::normalize_path;

assert_eq!(normalize_path("b/src/lib.rs"), "src/lib.rs");
assert_eq!(normalize_path("a/src/lib.rs"), "src/lib.rs");
assert_eq!(normalize_path("./src/lib.rs"), "src/lib.rs");
assert_eq!(normalize_path("src\\lib.rs"), "src/lib.rs");