-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#20) Comparers: upgrade docs and naming, move to separate namespace
- Loading branch information
Showing
9 changed files
with
88 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-FileCopyrightText: 2024 TruePath contributors <https://github.com/ForNeVeR/TruePath> | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
using System.Runtime.InteropServices; | ||
|
||
namespace TruePath.Comparers; | ||
|
||
/// <summary> | ||
/// <para>Provides a default comparer for comparing file paths, aware of the current platform.</para> | ||
/// <para> | ||
/// On <b>Windows</b> and <b>macOS</b>, this will perform <b>case-insensitive</b> comparison, since the file | ||
/// systems are case-insensitive on these operating systems by default. | ||
/// </para> | ||
/// <para>On <b>Linux</b>, the comparison will be <b>case-sensitive</b>.</para> | ||
/// </summary> | ||
/// <remarks> | ||
/// Note that this comparison <b>does not guarantee correctness</b>: in practice, on any platform to control | ||
/// case-sensitiveness of either the whole file system or a part of it. This class does not take this into account, | ||
/// having a benefit of no accessing the file system for any of the comparisons. | ||
/// </remarks> | ||
public class PlatformDefaultPathComparer : IComparer<string> | ||
{ | ||
/// <summary> | ||
/// Gets the singleton instance of the <see cref="PlatformDefaultPathComparer"/> class. | ||
/// </summary> | ||
public static readonly PlatformDefaultPathComparer Instance = new(); | ||
|
||
private readonly StringComparer _comparisonType; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PlatformDefaultPathComparer"/> class. | ||
/// </summary> | ||
private PlatformDefaultPathComparer() | ||
{ | ||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) | ||
{ | ||
_comparisonType = StringComparer.OrdinalIgnoreCase; | ||
} | ||
else | ||
{ | ||
_comparisonType = StringComparer.Ordinal; | ||
} | ||
} | ||
|
||
/// <inheritdoc cref="IComparer{T}.Compare"/> | ||
public int Compare(string? x, string? y) | ||
{ | ||
return _comparisonType.Compare(x, y); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// SPDX-FileCopyrightText: 2024 TruePath contributors <https://github.com/ForNeVeR/TruePath> | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
namespace TruePath.Comparers; | ||
|
||
/// <summary>A strict comparer for comparing file paths using ordinal comparison.</summary> | ||
public class StrictPathComparer : IComparer<string> | ||
{ | ||
/// <summary> | ||
/// Gets the singleton instance of the <see cref="StrictPathComparer"/> class. | ||
/// </summary> | ||
public static readonly StrictPathComparer Instance = new(); | ||
|
||
/// <inheritdoc cref="IComparer{T}.Compare"/> | ||
public int Compare(string? x, string? y) | ||
{ | ||
return StringComparer.Ordinal.Compare(x, y); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.