1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//! Path manipulation utilities.
//!
//! This module provides utility functions for manipulating file paths,
//! such as removing prefixes, normalizing paths, and other common operations.
use ;
/// Removes a prefix from a path if it exists.
///
/// This function checks if `path` starts with the given `prefix` and removes
/// the prefix if it does. If the path doesn't start with the prefix,
/// the original path is returned unchanged.
///
/// # Arguments
///
/// * `path` - The path to process
/// * `prefix` - The prefix to remove
///
/// # Returns
///
/// A new `PathBuf` with the prefix removed if it was present, or the original path otherwise.
///
/// # Examples
///
/// ```
/// use std::path::{Path, PathBuf};
/// use lumin::paths::remove_path_prefix;
///
/// let path = Path::new("/home/user/projects/myrepo/src/main.rs");
/// let prefix = Path::new("/home/user/projects/myrepo");
///
/// let result = remove_path_prefix(path, prefix);
/// assert_eq!(result, PathBuf::from("src/main.rs"));
///
/// // If the prefix doesn't match, the original path is returned
/// let other_prefix = Path::new("/tmp");
/// let unchanged = remove_path_prefix(path, other_prefix);
/// assert_eq!(unchanged, path);
/// ```