How do I add UTF-8 support for sorting in Ruby (including the ł character without affecting portability)?

Ruby string functions do not support UTF-8.

For example ['l', 'ł', 'm'].sort

returns ["l", "m", "ł"]

instead of ["l", "ł", "m"]

.

How should I sort UTF-8 strings in Ruby?

Sorting UTF-8 strings to RoR - The accepted answer does not support the ł character ( release opened since 2015 , blocked PR pending opened in 2014 ), pending failed since 2017-10-08.

ffi-icu's answer works for systems that have libicu installed, which AFAIK is not very portable.

+3


source to share


1 answer


A 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"]

      

+1


source







All Articles