From: dseverin Date: 2006-01-12T23:40:03+09:00 Subject: Re: Ruby, Unicode - ever? Levin Alexander wrote: > On 1/11/06, Bruce D'Arcus wrote: > >> I''d like to be able to do this and have it just work: >> >> x = ["z", "a", "ó", "o", "b"] >> puts x.sort.inspect > > Correct sorting of text is a quite tricky problem, because the correct > sort order will probably be language or application specific. > >> Maybe I'm missing something (and if I am, please tell me), but even >> when using jcode, the multi-byte character always is last. > > > > -Levin I've just found fresh ICU4R project on ruby-forge (and currently play with it), which seems to take care about Unicode issues including collation. Maybe it's what I need, need to play more :) Some sorting fun: require 'ustring' ["z", "a", "ó", "o", "b", "y"].collect {|s| s.to_u}.sort {|a,b| UString::strcoll(a,b, "lv")}.collect {|v| v.to_s} => ["a", "b", "y", "o", "\303\263", "z"] UString::strcoll("ÆSS".u, "aeß".u, "de", 0) => 0 "Iñtërnâtiônàlizætiøn".u.chars("").sort{|a,b| UString::strcoll(a, b)}.uniq.join("|") => à|â|æ|ë|i|I|l|n|ñ|ô|ø|r|t|z puts a = "Iñtërnâtiônàlizætiøn".u.upcase! => IÑTËRNÂTIÔNÀLIZÆTIØN v = a.search("national".u, "en", 0, nil, nil) => [5..12] puts a[v[0]] => NÂTIÔNÀL -- Posted via http://www.ruby-forum.com/.