如何将 UTF-8 支持添加到 Ruby 中的排序(包括 ł 字符,而不影响可移植性)?
How one should add UTF-8 support to sorting in Ruby (including ł character, without affecting portability)?
Ruby 字符串函数不支持 UTF-8。
例如 ['l', 'ł', 'm'].sort
returns ["l", "m", "ł"]
而不是 ["l", "ł", "m"]
.
如何在 Ruby 中对 UTF-8 字符串进行排序?
Sorting UTF-8 strings in RoR - accepted answer has no support for ł character (issue open since 2015, blocked by PR waiting opened in 2014),截至 2017 年 10 月 8 日等待未合并。
ffi-icu answer 适用于安装了 libicu 的系统,AFAIK 并不是真正可移植的。
好的解决方案是使用 gem https://github.com/twitter/twitter-cldr-rb
require 'twitter_cldr'
collator = TwitterCldr::Collation::Collator.new
collator.sort(['m', 'ł', 'l'])
=> ["l", "ł", "m"]
Ruby 字符串函数不支持 UTF-8。
例如 ['l', 'ł', 'm'].sort
returns ["l", "m", "ł"]
而不是 ["l", "ł", "m"]
.
如何在 Ruby 中对 UTF-8 字符串进行排序?
Sorting UTF-8 strings in RoR - accepted answer has no support for ł character (issue open since 2015, blocked by PR waiting opened in 2014),截至 2017 年 10 月 8 日等待未合并。
ffi-icu answer 适用于安装了 libicu 的系统,AFAIK 并不是真正可移植的。
好的解决方案是使用 gem https://github.com/twitter/twitter-cldr-rb
require 'twitter_cldr'
collator = TwitterCldr::Collation::Collator.new
collator.sort(['m', 'ł', 'l'])
=> ["l", "ł", "m"]