diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-05-19 00:10:22 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-05-19 00:11:03 +0900 |
| commit | c839244d8d09f3036ebfee8eef7eb6b147e593ab (patch) | |
| tree | fe48c94f2c2e62468beef5ff1a8f3cff6adeef4f /crates/shirabe/src/util/platform.rs | |
| parent | 48839250146b217e2756ed3c0e624fd341b54d6c (diff) | |
| download | php-shirabe-c839244d8d09f3036ebfee8eef7eb6b147e593ab.tar.gz php-shirabe-c839244d8d09f3036ebfee8eef7eb6b147e593ab.tar.zst php-shirabe-c839244d8d09f3036ebfee8eef7eb6b147e593ab.zip | |
fix(compile): fix various compile errors
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/util/platform.rs')
| -rw-r--r-- | crates/shirabe/src/util/platform.rs | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/crates/shirabe/src/util/platform.rs b/crates/shirabe/src/util/platform.rs index 96e564f..1f684d8 100644 --- a/crates/shirabe/src/util/platform.rs +++ b/crates/shirabe/src/util/platform.rs @@ -92,7 +92,8 @@ impl Platform { /// Parses tildes and environment variables in paths. pub fn expand_path(path: &str) -> String { - if Preg::is_match(r"#^~[\\/]#", path) { + use shirabe_external_packages::composer::pcre::preg::CaptureKey; + if Preg::is_match(r"#^~[\\/]#", path).unwrap_or(false) { return format!( "{}{}", Self::get_user_directory().unwrap(), @@ -102,35 +103,41 @@ impl Platform { Preg::replace_callback( r"#^(\$|(?P<percent>%))(?P<var>\w++)(?(percent)%)(?P<path>.*)#", - |matches| -> String { + |matches: &indexmap::IndexMap<CaptureKey, String>| -> String { + let var = matches + .get(&CaptureKey::ByName("var".to_string())) + .map(|s| s.as_str()) + .unwrap_or(""); + let path_part = matches + .get(&CaptureKey::ByName("path".to_string())) + .map(|s| s.as_str()) + .unwrap_or(""); // Treat HOME as an alias for USERPROFILE on Windows for legacy reasons - if Platform::is_windows() - && matches.get("var").map(|s| s.as_str()).unwrap_or("") == "HOME" - { + if Platform::is_windows() && var == "HOME" { if Platform::get_env("HOME").is_some() { return format!( "{}{}", Platform::get_env("HOME").unwrap_or_default(), - matches.get("path").map(|s| s.as_str()).unwrap_or(""), + path_part, ); } return format!( "{}{}", Platform::get_env("USERPROFILE").unwrap_or_default(), - matches.get("path").map(|s| s.as_str()).unwrap_or(""), + path_part, ); } format!( "{}{}", - Platform::get_env(matches.get("var").map(|s| s.as_str()).unwrap_or("")) - .unwrap_or_default(), - matches.get("path").map(|s| s.as_str()).unwrap_or(""), + Platform::get_env(var).unwrap_or_default(), + path_part, ) }, path, ) + .unwrap_or_default() } /// @throws \RuntimeException If the user home could not reliably be determined |
