[NaturalComparer] Use CompareNumeric instead of Compare, where possible

This commit is contained in:
Matt Nadareski
2016-10-28 12:59:52 -07:00
parent 1868aa17c5
commit 12ba858825
6 changed files with 29 additions and 21 deletions

View File

@@ -11,8 +11,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using SabreTools.Helper.Tools;
namespace NaturalSort
{
public class NaturalReversedComparer : Comparer<string>, IDisposable
@@ -40,13 +43,13 @@ namespace NaturalSort
if (!table.TryGetValue(x, out x1))
{
//x1 = Regex.Split(x.Replace(" ", ""), "([0-9]+)");
x1 = Regex.Split(x, "([0-9]+)");
x1 = Regex.Split(x, "([0-9]+)").Where(s => s != "").ToArray();
table.Add(x, x1);
}
if (!table.TryGetValue(y, out y1))
{
//y1 = Regex.Split(y.Replace(" ", ""), "([0-9]+)");
y1 = Regex.Split(y, "([0-9]+)");
y1 = Regex.Split(y, "([0-9]+)").Where(s => s != "").ToArray();
table.Add(y, y1);
}
@@ -76,12 +79,12 @@ namespace NaturalSort
int x, y;
if (!int.TryParse(left, out x))
{
return right.CompareTo(left);
return Style.CompareNumeric(right, left);
}
if (!int.TryParse(right, out y))
{
return right.CompareTo(left);
return Style.CompareNumeric(right, left);
}
return -x.CompareTo(y);