From 7763e9df54962c2511e7fb3f3380db9579a4775d Mon Sep 17 00:00:00 2001 From: Alex Jordan Date: Mon, 22 Jul 2024 00:43:21 -0700 Subject: [PATCH] case insensitive sorting by name --- lib/WeBWorK/Utils.pm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/WeBWorK/Utils.pm b/lib/WeBWorK/Utils.pm index 23de73bfa4..c1bb520c2f 100644 --- a/lib/WeBWorK/Utils.pm +++ b/lib/WeBWorK/Utils.pm @@ -177,6 +177,8 @@ sub sortByName ($field, @items) { } my @sKeys = sort { + return $a cmp $b if (uc($a) eq uc($b)); + my @aParts = split m/(?<=\D)(?=\d)|(?<=\d)(?=\D)/, $a; my @bParts = split m/(?<=\D)(?=\d)|(?<=\d)(?=\D)/, $b; @@ -195,8 +197,8 @@ sub sortByName ($field, @items) { next if $aPart == $bPart; # check next pair return $aPart <=> $bPart; # compare numerically } else { - next if $aPart eq $bPart; # check next pair - return $aPart cmp $bPart; # compare lexicographically + next if uc($aPart) eq uc($bPart); # check next pair + return uc($aPart) cmp uc($bPart); # compare alphabetically } } return +1 if @aParts; # a has more sections, should go second