aboutsummaryrefslogtreecommitdiff
path: root/src/Jellyfin.Extensions/AlphanumericComparator.cs
diff options
context:
space:
mode:
authorDominik <git@secnd.me>2023-06-15 19:38:42 +0200
committerGitHub <noreply@github.com>2023-06-15 19:38:42 +0200
commit17f1e8d19b1fd693893d66d2275ed8ae2476344e (patch)
tree7f48be975faa92042769870957587b3c7864f631 /src/Jellyfin.Extensions/AlphanumericComparator.cs
parente8ae7e5c38e28f13fa8de295e26c930cb46d9b79 (diff)
parent6771b5cabe96b4b3cbd1cd0c998d564f3dd17ed4 (diff)
Merge branch 'master' into segment-deletion
Diffstat (limited to 'src/Jellyfin.Extensions/AlphanumericComparator.cs')
-rw-r--r--src/Jellyfin.Extensions/AlphanumericComparator.cs60
1 files changed, 14 insertions, 46 deletions
diff --git a/src/Jellyfin.Extensions/AlphanumericComparator.cs b/src/Jellyfin.Extensions/AlphanumericComparator.cs
index e3c81eba8..299e2f94a 100644
--- a/src/Jellyfin.Extensions/AlphanumericComparator.cs
+++ b/src/Jellyfin.Extensions/AlphanumericComparator.cs
@@ -16,15 +16,17 @@ namespace Jellyfin.Extensions
/// <returns>A signed integer that indicates the relative values of <c>x</c> and <c>y</c>.</returns>
public static int CompareValues(string? s1, string? s2)
{
- if (s1 == null && s2 == null)
+ if (s1 is null && s2 is null)
{
return 0;
}
- else if (s1 == null)
+
+ if (s1 is null)
{
return -1;
}
- else if (s2 == null)
+
+ if (s2 is null)
{
return 1;
}
@@ -37,11 +39,13 @@ namespace Jellyfin.Extensions
{
return 0;
}
- else if (len1 == 0)
+
+ if (len1 == 0)
{
return -1;
}
- else if (len2 == 0)
+
+ if (len2 == 0)
{
return 1;
}
@@ -82,55 +86,19 @@ namespace Jellyfin.Extensions
{
return -1;
}
- else if (span1Len > span2Len)
- {
- return 1;
- }
- else if (span1Len >= 20) // Number is probably too big for a ulong
- {
- // Trim all the first digits that are the same
- int i = 0;
- while (i < span1Len && span1[i] == span2[i])
- {
- i++;
- }
-
- // If there are no more digits it's the same number
- if (i == span1Len)
- {
- continue;
- }
-
- // Only need to compare the most significant digit
- span1 = span1.Slice(i, 1);
- span2 = span2.Slice(i, 1);
- }
- if (!ulong.TryParse(span1, out var num1)
- || !ulong.TryParse(span2, out var num2))
- {
- return 0;
- }
- else if (num1 < num2)
- {
- return -1;
- }
- else if (num1 > num2)
+ if (span1Len > span2Len)
{
return 1;
}
}
- else
+
+ int result = span1.CompareTo(span2, StringComparison.InvariantCulture);
+ if (result != 0)
{
- int result = span1.CompareTo(span2, StringComparison.InvariantCulture);
- if (result != 0)
- {
- return result;
- }
+ return result;
}
-#pragma warning disable SA1500 // TODO remove with StyleCop.Analyzers v1.2.0 https://github.com/DotNetAnalyzers/StyleCopAnalyzers/pull/3196
} while (pos1 < len1 && pos2 < len2);
-#pragma warning restore SA1500
return len1 - len2;
}