I sent you a personal message with a link to an archive.
You will be able to check what I posted here.
A sort code compare the passed object to determine which one is greater than the other.
In an alphabetical sort the strings are sorted smaller first, greater last.
Here is a script showing different sorting rules at work upon my original list.
(*
https://forum.latenightsw.com/t/bridge-plus-question/1451/3
Sort comparison
*)
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
(* Tests with punctuation, digits, and Latin characters. Results best viewed in Script Debugger's "Desc" mode. *)
set anArray to current application's class "NSArray"'s arrayWithArray:({"Doc 2.numbers", "doc 01.numbers", "doc 02.numbers", "doc 04.numbers", "doc 1.numbers", "doc 2 .numbers", "doc 20.numbers", "doc 3.numbers", "doc 30.numbers", "doc 4.numbers"})
anArray's sortedArrayUsingSelector:("compare:")
log result as list (*Doc 2.numbers, doc 01.numbers, doc 02.numbers, doc 04.numbers, doc 1.numbers, doc 2 .numbers, doc 20.numbers, doc 3.numbers, doc 30.numbers, doc 4.numbers*)
--> Sorted by Unicode number. ("(" < "-" < digits < upper < "[" < "_" < lower < "{".)
anArray's sortedArrayUsingSelector:("caseInsensitiveCompare:")
log result as list (*doc 01.numbers, doc 02.numbers, doc 04.numbers, doc 1.numbers, doc 2 .numbers, Doc 2.numbers, doc 20.numbers, doc 3.numbers, doc 30.numbers, doc 4.numbers*)
--> Simile, but case-insensitively. Diacriticals still considered. ("(" < "-" < digits < "[" < "_" < letters < "{".)
-- Where strings are identical apart from case, it's apparent that the sort is stable.
anArray's sortedArrayUsingSelector:("localizedCompare:")
log result as list (*doc 01.numbers, doc 02.numbers, doc 04.numbers, doc 1.numbers, doc 2 .numbers, Doc 2.numbers, doc 20.numbers, doc 3.numbers, doc 30.numbers, doc 4.numbers*)
--> (en_GB) Case-insensitive and diacriticals ignored! Punctuation < digits. ("_" < "-" "(" < "[" < "{" < digits < letters.)
-- Where strings are identical apart from case or diacriticals, diacriticals are considered first, then lower < upper.
anArray's sortedArrayUsingSelector:("localizedCaseInsensitiveCompare:")
log result as list (*doc 01.numbers, doc 02.numbers, doc 04.numbers, doc 1.numbers, doc 2 .numbers, Doc 2.numbers, doc 20.numbers, doc 3.numbers, doc 30.numbers, doc 4.numbers*)
--> (en_GB) As "localisedCompare:" except that case is ignored in otherwise identical strings, which are sorted stably.
anArray's sortedArrayUsingSelector:("localizedStandardCompare:") -- the Finder's rule
log result as list (*doc 1.numbers, doc 01.numbers, doc 2 .numbers, doc 02.numbers, Doc 2.numbers, doc 3.numbers, doc 4.numbers, doc 04.numbers, doc 20.numbers, doc 30.numbers*)
--> (en_GB) As "localizedCompare:" except that numeric sequences are sorted by the number values represented.
Is it clear now ?
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 5 mai 2020 16:36:09
added a simple and inefficient way to sort
set aList to {"Doc 2.numbers", "doc 01.numbers", "doc 02.numbers", "doc 04.numbers", "doc 1.numbers", "doc 2 .numbers", "doc 20.numbers", "doc 3.numbers", "doc 30.numbers", "doc 4.numbers"}
repeat 2 times
repeat with i from 1 to (count aList) - 1
if item i of aList > item (i + 1) of aList then
set bof to item i of aList
set item i of aList to item (i + 1) of aList
set item (i + 1) of aList to bof
end if
end repeat
end repeat
aList
The comment (* Tests with punctuation, digits, and Latin characters. Results best viewed in Script Debuggerās āDescā mode. *) is a relief of the original script borrowed from Late Nightās forum.
With the strings passed, localization has no impact because no diacritical are used.