[Style] Remove CompareNumeric

This commit is contained in:
Matt Nadareski
2016-09-26 12:14:18 -07:00
parent a3e32631fc
commit 70e36de17c

View File

@@ -436,107 +436,6 @@ namespace SabreTools.Helper
return bytes; return bytes;
} }
/// <summary>
/// https://psycodedeveloper.wordpress.com/2013/04/12/c-numeric-sorting-revisited/
/// </summary>
public static int CompareNumeric(string s, string other)
{
if ((s == null || s.Replace(" ", string.Empty).Length == 0)
&& (other != null && other.Replace(" ", string.Empty).Length > 0))
{
return -1;
}
if ((s != null && s.Replace(" ", string.Empty).Length > 0)
&& (other == null || other.Replace(" ", string.Empty).Length == 0))
{
return 1;
}
if (s != null && other != null &&
(s = s.Replace(" ", string.Empty)).Length > 0 &&
(other = other.Replace(" ", string.Empty)).Length > 0)
{
int sIndex = 0, otherIndex = 0;
while (sIndex < s.Length)
{
if (otherIndex >= other.Length)
{
return 1;
}
if (char.IsDigit(s[sIndex]))
{
if (!char.IsDigit(other[otherIndex]))
{
return -1;
}
// Compare the numbers
StringBuilder sBuilder = new StringBuilder(), otherBuilder = new StringBuilder();
while (sIndex < s.Length && char.IsDigit(s[sIndex]))
{
sBuilder.Append(s[sIndex++]);
}
while (otherIndex < other.Length && char.IsDigit(other[otherIndex]))
{
otherBuilder.Append(other[otherIndex++]);
}
long sValue = 0L, otherValue = 0L;
if (!Int64.TryParse(sBuilder.ToString(), out sValue))
{
sValue = Int64.MaxValue;
}
if (!Int64.TryParse(otherBuilder.ToString(), out otherValue))
{
otherValue = Int64.MaxValue;
}
if (sValue < otherValue)
{
return -1;
}
else if (sValue > otherValue)
{
return 1;
}
}
else if (char.IsDigit(other[otherIndex]))
{
return 1;
}
else
{
int difference = string.Compare(s[sIndex].ToString(), other[otherIndex].ToString(), StringComparison.InvariantCultureIgnoreCase);
if (difference > 0)
{
return 1;
}
else if (difference < 0)
{
return -1;
}
sIndex++;
otherIndex++;
}
}
if (otherIndex < other.Length)
{
return -1;
}
}
return 0;
}
/// <summary> /// <summary>
/// http://stackoverflow.com/questions/146134/how-to-remove-illegal-characters-from-path-and-filenames /// http://stackoverflow.com/questions/146134/how-to-remove-illegal-characters-from-path-and-filenames
/// </summary> /// </summary>