I did this experiment in the REPL:
(sort ["maa" "ácw" "ijl" "aez" "jkl"])
I got this:
("aez" "ijl" "jkl" "maa" "ácw")
The right answer is this:
("ácw" "aez" "ijl" "jkl" "maa")
Is there a way to sort Latin strings in Clojure natively? If not why not?
Look I didn't ask how to sort this, I know I can pass the seq through a pipe and substitute the non ANSI chars.
You can use the Collator class, on the REPL:
=> (import java.util.Locale)
java.util.Locale
=> (import java.text.Collator)
java.text.Collator
=> (def collator (Collator/getInstance (Locale. "pt_BR")))
#'user/collator
=> (sort collator ["maa" "ácw" "ijl" "aez" "jkl"])
("ácw" "aez" "ijl" "jkl" "maa")
In this example I'm using the Brazilian Locale. You need to change this locale to the one you want to use. There is a list of supported locales here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With