Feature/tech debt (#199)
* Added an icon for building the exe * Technical debt
This commit is contained in:
parent
d92e9e7602
commit
f694145cd9
26 changed files with 76 additions and 112 deletions
|
@ -6,10 +6,13 @@ using static System.String;
|
|||
|
||||
namespace API.Comparators
|
||||
{
|
||||
public class NaturalSortComparer : IComparer<string>, IDisposable
|
||||
public sealed class NaturalSortComparer : IComparer<string>, IDisposable
|
||||
{
|
||||
private readonly bool _isAscending;
|
||||
private Dictionary<string, string[]> _table = new();
|
||||
|
||||
private bool _disposed;
|
||||
|
||||
|
||||
public NaturalSortComparer(bool inAscendingOrder = true)
|
||||
{
|
||||
|
@ -20,17 +23,17 @@ namespace API.Comparators
|
|||
{
|
||||
if (x == y) return 0;
|
||||
|
||||
if (!_table.TryGetValue(x, out var x1))
|
||||
if (!_table.TryGetValue(x ?? Empty, out var x1))
|
||||
{
|
||||
// .Replace(" ", Empty)
|
||||
x1 = Regex.Split(x, "([0-9]+)");
|
||||
_table.Add(x, x1);
|
||||
x1 = Regex.Split(x ?? Empty, "([0-9]+)");
|
||||
_table.Add(x ?? Empty, x1);
|
||||
}
|
||||
|
||||
if (!_table.TryGetValue(y, out var y1))
|
||||
if (!_table.TryGetValue(y ?? Empty, out var y1))
|
||||
{
|
||||
y1 = Regex.Split(y, "([0-9]+)");
|
||||
_table.Add(y, y1);
|
||||
y1 = Regex.Split(y ?? Empty, "([0-9]+)");
|
||||
_table.Add(y ?? Empty, y1);
|
||||
}
|
||||
|
||||
int returnVal;
|
||||
|
@ -69,11 +72,31 @@ namespace API.Comparators
|
|||
return x.CompareTo(y);
|
||||
}
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (!_disposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
// called via myClass.Dispose().
|
||||
_table.Clear();
|
||||
_table = null;
|
||||
}
|
||||
// Release unmanaged resources.
|
||||
// Set large fields to null.
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
SuppressFinalize(this);
|
||||
_table.Clear();
|
||||
_table = null;
|
||||
}
|
||||
|
||||
~NaturalSortComparer() // the finalizer
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue