50 lines
1.3 KiB
C#
50 lines
1.3 KiB
C#
namespace StellaOps.Scanner.Analyzers.Lang;
|
|
|
|
public sealed class LanguageUsageHints
|
|
{
|
|
private static readonly StringComparer Comparer = OperatingSystem.IsWindows()
|
|
? StringComparer.OrdinalIgnoreCase
|
|
: StringComparer.Ordinal;
|
|
|
|
private readonly ImmutableHashSet<string> _usedPaths;
|
|
|
|
public static LanguageUsageHints Empty { get; } = new(Array.Empty<string>());
|
|
|
|
public LanguageUsageHints(IEnumerable<string> usedPaths)
|
|
{
|
|
if (usedPaths is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(usedPaths));
|
|
}
|
|
|
|
_usedPaths = usedPaths
|
|
.Select(Normalize)
|
|
.Where(static path => path.Length > 0)
|
|
.ToImmutableHashSet(Comparer);
|
|
}
|
|
|
|
public bool IsPathUsed(string path)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(path))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var normalized = Normalize(path);
|
|
return _usedPaths.Contains(normalized);
|
|
}
|
|
|
|
private static string Normalize(string path)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(path))
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
var full = Path.GetFullPath(path);
|
|
return OperatingSystem.IsWindows()
|
|
? full.Replace('\\', '/').TrimEnd('/')
|
|
: full;
|
|
}
|
|
}
|