aboutsummaryrefslogtreecommitdiff
path: root/src/Costasdev.Busurbano.Backend/Helpers/SortingHelper.cs
diff options
context:
space:
mode:
authorAriel Costas Guerrero <ariel@costas.dev>2025-12-19 13:06:27 +0100
committerAriel Costas Guerrero <ariel@costas.dev>2025-12-19 13:06:27 +0100
commit2a9aca302485bc08f5b2dd2a54987de6f80fc338 (patch)
tree38171abad21b2952eca6ff9e8534545b4c28ed12 /src/Costasdev.Busurbano.Backend/Helpers/SortingHelper.cs
parent37cdb0c418a7f2b47e40ae9db7ad86e1fddc86fe (diff)
Implement loading stops as tiles from OTP
Diffstat (limited to 'src/Costasdev.Busurbano.Backend/Helpers/SortingHelper.cs')
-rw-r--r--src/Costasdev.Busurbano.Backend/Helpers/SortingHelper.cs35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/Costasdev.Busurbano.Backend/Helpers/SortingHelper.cs b/src/Costasdev.Busurbano.Backend/Helpers/SortingHelper.cs
new file mode 100644
index 0000000..472a56f
--- /dev/null
+++ b/src/Costasdev.Busurbano.Backend/Helpers/SortingHelper.cs
@@ -0,0 +1,35 @@
+namespace Costasdev.Busurbano.Backend.Helpers;
+
+public class SortingHelper
+{
+ public static int SortRouteShortNames(string? a, string? b)
+ {
+ if (a == null && b == null) return 0;
+ if (a == null) return 1;
+ if (b == null) return -1;
+
+ var aDigits = new string(a.Where(char.IsDigit).ToArray());
+ var bDigits = new string(b.Where(char.IsDigit).ToArray());
+
+ bool aHasDigits = int.TryParse(aDigits, out int aNumber);
+ bool bHasDigits = int.TryParse(bDigits, out int bNumber);
+
+ if (aHasDigits != bHasDigits)
+ {
+ // Non-numeric routes (like "A" or "-") go to the beginning
+ return aHasDigits ? 1 : -1;
+ }
+
+ if (aHasDigits && bHasDigits)
+ {
+ if (aNumber != bNumber)
+ {
+ return aNumber.CompareTo(bNumber);
+ }
+ }
+
+ // If both are non-numeric, or numeric parts are equal, use alphabetical
+ return string.Compare(a, b, StringComparison.OrdinalIgnoreCase);
+ }
+
+}