MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / paths_match

Function paths_match

src/phpcs.rs:348–361  ·  view source on GitHub ↗

Check whether two file paths refer to the same file. PHPCS may use the `--stdin-path` value as the key. We compare by checking suffix matches (one path ends with the other) to handle cases where one path is relative and the other is absolute, or where symlinks produce different prefixes.

(a: &str, b: &str)

Source from the content-addressed store, hash-verified

346/// cases where one path is relative and the other is absolute, or
347/// where symlinks produce different prefixes.
348fn paths_match(a: &str, b: &str) -> bool {
349 if a == b {
350 return true;
351 }
352 // Normalize separators for comparison.
353 let a_norm = a.replace('\\', "/");
354 let b_norm = b.replace('\\', "/");
355 if a_norm == b_norm {
356 return true;
357 }
358 // Check suffix match (one is a suffix of the other), requiring a
359 // path separator boundary so that e.g. "AFoo.php" does not match "Foo.php".
360 a_norm.ends_with(&format!("/{}", b_norm)) || b_norm.ends_with(&format!("/{}", a_norm))
361}
362
363// ── Helpers ─────────────────────────────────────────────────────────
364

Callers 1

parse_phpcs_jsonFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected