Reputation: 2254
Ruby string functions are not supporting UTF-8.
For example ['l', 'ł', 'm'].sort
returns ["l", "m", "ł"]
rather than ["l", "ł", "m"]
.
How one should sort UTF-8 strings in Ruby?
Sorting UTF-8 strings in RoR - accepted answer has no support for ł character (issue open since 2015, blocked by PR waiting opened in 2014), waiting unmerged as of 2017-10-08.
ffi-icu answer works for systems that have libicu installed what AFAIK is not really portable.
Upvotes: 3
Views: 276
Reputation: 46
good solution is using gem https://github.com/twitter/twitter-cldr-rb
require 'twitter_cldr'
collator = TwitterCldr::Collation::Collator.new
collator.sort(['m', 'ł', 'l'])
=> ["l", "ł", "m"]
Upvotes: 2