maclarian 0.1.3

Larian file format library for Baldur's Gate 3 - PAK, LSF, LSX, GR2, DDS, and more
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//! Path utilities

use std::path::Path;

/// Normalize path separators to forward slashes (for PAK files)
pub fn normalize_path<P: AsRef<Path>>(path: P) -> String {
    path.as_ref().to_string_lossy().replace('\\', "/")
}

/// Get relative path and normalize separators
pub fn relative_path<P: AsRef<Path>>(path: P, base: P) -> Option<String> {
    path.as_ref()
        .strip_prefix(base.as_ref())
        .ok()
        .map(normalize_path)
}