forked from mirrors/NBTExplorer
Change string compare to natural compare
This commit is contained in:
parent
5c32832281
commit
db5d2a05c0
6 changed files with 150 additions and 77 deletions
|
@ -3,7 +3,7 @@
|
|||
<Product Id="*"
|
||||
Name="NBTExplorer"
|
||||
Language="1033"
|
||||
Version="2.7.5.0"
|
||||
Version="2.7.6.0"
|
||||
Manufacturer="Justin Aquadro"
|
||||
UpgradeCode="0bfb1026-21f2-4552-ad71-ca90aae10a25">
|
||||
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
|
||||
|
|
|
@ -7,6 +7,7 @@ using NBTExplorer.Vendor.MultiSelectTreeView;
|
|||
using NBTExplorer.Windows;
|
||||
using Substrate.Nbt;
|
||||
using System.Collections;
|
||||
using NBTExplorer.Utility;
|
||||
|
||||
namespace NBTExplorer.Controllers
|
||||
{
|
||||
|
@ -23,6 +24,8 @@ namespace NBTExplorer.Controllers
|
|||
|
||||
public class NodeTreeComparer : IComparer
|
||||
{
|
||||
private NaturalComparer _comparer = new NaturalComparer();
|
||||
|
||||
public int OrderForTag(TagType tagID)
|
||||
{
|
||||
switch (tagID)
|
||||
|
@ -72,7 +75,7 @@ namespace NBTExplorer.Controllers
|
|||
}
|
||||
else
|
||||
{
|
||||
return tx.Text.CompareTo(ty.Text);
|
||||
return _comparer.Compare(tx.Text, ty.Text);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,9 +88,8 @@ namespace NBTExplorer.Controllers
|
|||
}
|
||||
else
|
||||
{
|
||||
return dx.NodeDisplay.CompareTo(dy.NodeDisplay);
|
||||
return _comparer.Compare(dx.NodeDisplay, dy.NodeDisplay);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("2.7.5.0")]
|
||||
[assembly: AssemblyFileVersion("2.7.5.0")]
|
||||
[assembly: AssemblyVersion("2.7.6.0")]
|
||||
[assembly: AssemblyFileVersion("2.7.6.0")]
|
||||
|
|
|
@ -72,6 +72,7 @@
|
|||
<Compile Include="Data\Nodes\TagLongDataNode.cs" />
|
||||
<Compile Include="Data\Nodes\TagShortDataNode.cs" />
|
||||
<Compile Include="Data\Nodes\TagStringDataNode.cs" />
|
||||
<Compile Include="Utility\NaturalComparer.cs" />
|
||||
<Compile Include="Utility\SnapshotList.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
|
|
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.3.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.3.0")]
|
||||
[assembly: AssemblyVersion("1.0.4.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.4.0")]
|
||||
|
|
70
NBTModel/Utility/NaturalComparer.cs
Normal file
70
NBTModel/Utility/NaturalComparer.cs
Normal file
|
@ -0,0 +1,70 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace NBTExplorer.Utility
|
||||
{
|
||||
// NaturalComparer implementation by Justin.Jones
|
||||
// Licensed under The Code Project Open License (CPOL) (http://www.codeproject.com/info/cpol10.aspx)
|
||||
|
||||
public class NaturalComparer : Comparer<string>, IDisposable
|
||||
{
|
||||
private Dictionary<string, string[]> table;
|
||||
|
||||
public NaturalComparer ()
|
||||
{
|
||||
table = new Dictionary<string, string[]>();
|
||||
}
|
||||
|
||||
public void Dispose ()
|
||||
{
|
||||
table.Clear();
|
||||
table = null;
|
||||
}
|
||||
|
||||
public override int Compare (string x, string y)
|
||||
{
|
||||
if (x == y) {
|
||||
return 0;
|
||||
}
|
||||
string[] x1, y1;
|
||||
if (!table.TryGetValue(x, out x1)) {
|
||||
x1 = Regex.Split(x.Replace(" ", ""), "([0-9]+)");
|
||||
table.Add(x, x1);
|
||||
}
|
||||
if (!table.TryGetValue(y, out y1)) {
|
||||
y1 = Regex.Split(y.Replace(" ", ""), "([0-9]+)");
|
||||
table.Add(y, y1);
|
||||
}
|
||||
|
||||
for (int i = 0; i < x1.Length && i < y1.Length; i++) {
|
||||
if (x1[i] != y1[i]) {
|
||||
return PartCompare(x1[i], y1[i]);
|
||||
}
|
||||
}
|
||||
if (y1.Length > x1.Length) {
|
||||
return 1;
|
||||
}
|
||||
else if (x1.Length > y1.Length) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static int PartCompare (string left, string right)
|
||||
{
|
||||
int x, y;
|
||||
if (!int.TryParse(left, out x)) {
|
||||
return left.CompareTo(right);
|
||||
}
|
||||
|
||||
if (!int.TryParse(right, out y)) {
|
||||
return left.CompareTo(right);
|
||||
}
|
||||
|
||||
return x.CompareTo(y);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue